cgroup macros refactoring, part 1

- Introduce VIR_CGROUP_SUPPORTED conditional
- Convert virCgroupKill* to use it
- Convert virCgroupIsolateMount() to use it
- Convert virCgroupRemoveRecursively to VIR_CGROUP_SUPPORTED

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Roman Bogorodskiy 2013-08-12 14:02:26 -06:00 committed by Eric Blake
parent 2ff9e54cbf
commit 02f1fd41f6
1 changed files with 51 additions and 44 deletions

View File

@ -56,6 +56,11 @@
#define VIR_FROM_THIS VIR_FROM_CGROUP #define VIR_FROM_THIS VIR_FROM_CGROUP
#if defined(__linux__) && defined(HAVE_GETMNTENT_R) && \
defined(_DIRENT_HAVE_D_TYPE)
# define VIR_CGROUP_SUPPORTED
#endif
VIR_ENUM_IMPL(virCgroupController, VIR_CGROUP_CONTROLLER_LAST, VIR_ENUM_IMPL(virCgroupController, VIR_CGROUP_CONTROLLER_LAST,
"cpu", "cpuacct", "cpuset", "memory", "devices", "cpu", "cpuacct", "cpuset", "memory", "devices",
"freezer", "blkio", "net_cls", "perf_event", "freezer", "blkio", "net_cls", "perf_event",
@ -2714,7 +2719,8 @@ virCgroupGetFreezerState(virCgroupPtr group, char **state)
} }
#if defined _DIRENT_HAVE_D_TYPE #ifdef VIR_CGROUP_SUPPORTED
int int
virCgroupRemoveRecursively(char *grppath) virCgroupRemoveRecursively(char *grppath)
{ {
@ -2764,15 +2770,6 @@ virCgroupRemoveRecursively(char *grppath)
return rc; return rc;
} }
#else
int
virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED)
{
virReportSystemError(ENXIO, "%s",
_("Control groups not supported on this platform"));
return -1;
}
#endif
/** /**
@ -2825,7 +2822,6 @@ virCgroupRemove(virCgroupPtr group)
} }
#if defined HAVE_KILL && defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
/* /*
* Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error
*/ */
@ -3073,38 +3069,7 @@ virCgroupKillPainfully(virCgroupPtr group)
return ret; return ret;
} }
#else /* !(HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R) */
int
virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED,
int signum ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int
virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED,
int signum ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int
virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
#endif /* HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R */
#ifdef __linux__
static char * static char *
virCgroupIdentifyRoot(virCgroupPtr group) virCgroupIdentifyRoot(virCgroupPtr group)
{ {
@ -3221,7 +3186,48 @@ cleanup:
VIR_FREE(opts); VIR_FREE(opts);
return ret; return ret;
} }
#else /* __linux__ */
#else /* !VIR_CGROUP_SUPPORTED */
int
virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED)
{
virReportSystemError(ENXIO, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int
virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED,
int signum ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int
virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED,
int signum ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int
virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
int int
virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED,
const char *oldroot ATTRIBUTE_UNUSED, const char *oldroot ATTRIBUTE_UNUSED,
@ -3231,4 +3237,5 @@ virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED,
_("Control groups not supported on this platform")); _("Control groups not supported on this platform"));
return -1; return -1;
} }
#endif /* __linux__ */
#endif /* !VIR_CGROUP_SUPPORTED */