[libvirt] [PATCH v2 1/5] cgroup macros refactoring

- Introduce VIR_CGROUP_SUPPORTED conditional - Convert virCgroupKill* to use it - Convert virCgroupIsolateMount() to use it --- src/util/vircgroup.c | 59 ++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cfb4b3f..5f656b1 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -56,6 +56,11 @@ #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, "cpu", "cpuacct", "cpuset", "memory", "devices", "freezer", "blkio", "net_cls", "perf_event", @@ -2682,7 +2687,7 @@ int virCgroupGetFreezerState(virCgroupPtr group, char **state) } -#if defined HAVE_KILL && defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R +#ifdef VIR_CGROUP_SUPPORTED /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ @@ -2866,6 +2871,7 @@ cleanup: return ret; } + int virCgroupKillRecursive(virCgroupPtr group, int signum) { int ret; @@ -2911,31 +2917,7 @@ int virCgroupKillPainfully(virCgroupPtr group) 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 *virCgroupIdentifyRoot(virCgroupPtr group) { char *ret = NULL; @@ -3048,7 +3030,30 @@ cleanup: VIR_FREE(opts); return ret; } -#else /* __linux__ */ +#else /* VIR_CGROUP_SUPPORTED */ +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 virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, const char *oldroot ATTRIBUTE_UNUSED, const char *mountopts ATTRIBUTE_UNUSED) @@ -3057,4 +3062,4 @@ int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, _("Control groups not supported on this platform")); return -1; } -#endif /* __linux__ */ +#endif /* VIR_CGROUP_SUPPORTED */ -- 1.8.2.3

- Convert virCgroupGet* to VIR_CGROUP_SUPPORTED - Convert virCgroup(Get|Set)FreezerState to VIR_CGROUP_SUPPORTED - Convert virCgroupRemoveRecursively to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 363 +++++++++++++++++++++++++++++---------------------- 1 file changed, 204 insertions(+), 159 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5f656b1..3640fbd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -57,7 +57,7 @@ #define VIR_FROM_THIS VIR_FROM_CGROUP #if defined(__linux__) && defined(HAVE_GETMNTENT_R) \ - && defined(_DIRENT_HAVE_D_TYPE) + && defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK) # define VIR_CGROUP_SUPPORTED #endif @@ -1000,63 +1000,6 @@ error: } #endif -#if defined _DIRENT_HAVE_D_TYPE -int virCgroupRemoveRecursively(char *grppath) -{ - DIR *grpdir; - struct dirent *ent; - int rc = 0; - - grpdir = opendir(grppath); - if (grpdir == NULL) { - if (errno == ENOENT) - return 0; - rc = -errno; - VIR_ERROR(_("Unable to open %s (%d)"), grppath, errno); - return rc; - } - - for (;;) { - char *path; - - errno = 0; - ent = readdir(grpdir); - if (ent == NULL) { - if ((rc = -errno)) - VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno); - break; - } - - if (ent->d_name[0] == '.') continue; - if (ent->d_type != DT_DIR) continue; - - if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) { - rc = -ENOMEM; - break; - } - rc = virCgroupRemoveRecursively(path); - VIR_FREE(path); - if (rc != 0) - break; - } - closedir(grpdir); - - VIR_DEBUG("Removing cgroup %s", grppath); - if (rmdir(grppath) != 0 && errno != ENOENT) { - rc = -errno; - VIR_ERROR(_("Unable to remove %s (%d)"), grppath, errno); - } - - return rc; -} -#else -int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** * virCgroupRemove: @@ -2585,109 +2528,58 @@ int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) "cpu.cfs_quota_us", cfs_quota); } -/** - * virCgroupGetCpuCfsQuota: - * - * @group: The cgroup to get cpu.cfs_quota_us for - * @cfs_quota: Pointer to the returned cpu bandwidth (in usecs) that this tg - * will be allowed to consume over period - * - * Returns: 0 on success - */ -int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) -{ - return virCgroupGetValueI64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_quota_us", cfs_quota); -} - -int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) -{ - return virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage", usage); -} - -int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) -{ - return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage_percpu", usage); -} - -#ifdef _SC_CLK_TCK -int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, - unsigned long long *sys) -{ - char *str; - char *p; - int ret = -1; - static double scale = -1.0; - - if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.stat", &str) < 0) - return -1; - - if (!(p = STRSKIP(str, "user ")) || - virStrToLong_ull(p, &p, 10, user) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse user stat '%s'"), - p); - goto cleanup; - } - if (!(p = STRSKIP(p, "\nsystem ")) || - virStrToLong_ull(p, NULL, 10, sys) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse sys stat '%s'"), - p); - goto cleanup; - } - /* times reported are in system ticks (generally 100 Hz), but that - * rate can theoretically vary between machines. Scale things - * into approximate nanoseconds. */ - if (scale < 0) { - long ticks_per_sec = sysconf(_SC_CLK_TCK); - if (ticks_per_sec == -1) { - virReportSystemError(errno, "%s", - _("Cannot determine system clock HZ")); - goto cleanup; - } - scale = 1000000000.0 / ticks_per_sec; - } - *user *= scale; - *sys *= scale; - - ret = 0; -cleanup: - VIR_FREE(str); - return ret; -} -#else -int virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, - unsigned long long *user ATTRIBUTE_UNUSED, - unsigned long long *sys ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif - -int virCgroupSetFreezerState(virCgroupPtr group, const char *state) -{ - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); -} - -int virCgroupGetFreezerState(virCgroupPtr group, char **state) -{ - return virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); -} - #ifdef VIR_CGROUP_SUPPORTED +int virCgroupRemoveRecursively(char *grppath) +{ + DIR *grpdir; + struct dirent *ent; + int rc = 0; + + grpdir = opendir(grppath); + if (grpdir == NULL) { + if (errno == ENOENT) + return 0; + rc = -errno; + VIR_ERROR(_("Unable to open %s (%d)"), grppath, errno); + return rc; + } + + for (;;) { + char *path; + + errno = 0; + ent = readdir(grpdir); + if (ent == NULL) { + if ((rc = -errno)) + VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno); + break; + } + + if (ent->d_name[0] == '.') continue; + if (ent->d_type != DT_DIR) continue; + + if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) { + rc = -ENOMEM; + break; + } + rc = virCgroupRemoveRecursively(path); + VIR_FREE(path); + if (rc != 0) + break; + } + closedir(grpdir); + + VIR_DEBUG("Removing cgroup %s", grppath); + if (rmdir(grppath) != 0 && errno != ENOENT) { + rc = -errno; + VIR_ERROR(_("Unable to remove %s (%d)"), grppath, errno); + } + + return rc; +} + + /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ @@ -2946,6 +2838,99 @@ static char *virCgroupIdentifyRoot(virCgroupPtr group) } +/** + * virCgroupGetCpuCfsQuota: + * + * @group: The cgroup to get cpu.cfs_quota_us for + * @cfs_quota: Pointer to the returned cpu bandwidth (in usecs) that this tg + * will be allowed to consume over period + * + * Returns: 0 on success + */ +int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) +{ + return virCgroupGetValueI64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_quota_us", cfs_quota); +} + +int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.usage", usage); +} + +int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) +{ + return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.usage_percpu", usage); +} + + +int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, + unsigned long long *sys) +{ + char *str; + char *p; + int ret = -1; + static double scale = -1.0; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.stat", &str) < 0) + return -1; + + if (!(p = STRSKIP(str, "user ")) || + virStrToLong_ull(p, &p, 10, user) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse user stat '%s'"), + p); + goto cleanup; + } + if (!(p = STRSKIP(p, "\nsystem ")) || + virStrToLong_ull(p, NULL, 10, sys) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse sys stat '%s'"), + p); + goto cleanup; + } + /* times reported are in system ticks (generally 100 Hz), but that + * rate can theoretically vary between machines. Scale things + * into approximate nanoseconds. */ + if (scale < 0) { + long ticks_per_sec = sysconf(_SC_CLK_TCK); + if (ticks_per_sec == -1) { + virReportSystemError(errno, "%s", + _("Cannot determine system clock HZ")); + goto cleanup; + } + scale = 1000000000.0 / ticks_per_sec; + } + *user *= scale; + *sys *= scale; + + ret = 0; +cleanup: + VIR_FREE(str); + return ret; +} + + +int virCgroupSetFreezerState(virCgroupPtr group, const char *state) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + +int virCgroupGetFreezerState(virCgroupPtr group, char **state) +{ + return virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + + int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, const char *mountopts) { @@ -3031,6 +3016,14 @@ cleanup: return ret; } #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) { @@ -3039,6 +3032,7 @@ int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED, return -1; } + int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED, int signum ATTRIBUTE_UNUSED) { @@ -3047,6 +3041,7 @@ int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED, return -1; } + int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", @@ -3054,6 +3049,56 @@ int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) return -1; } + +int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *user ATTRIBUTE_UNUSED, + unsigned long long *sys ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetFreezerState(virCgroupPtr group, const char *state) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + +int virCgroupGetFreezerState(virCgroupPtr group, char **state) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, const char *oldroot ATTRIBUTE_UNUSED, const char *mountopts ATTRIBUTE_UNUSED) -- 1.8.2.3

On 08/11/2013 06:04 AM, Roman Bogorodskiy wrote:
- Convert virCgroupGet* to VIR_CGROUP_SUPPORTED - Convert virCgroup(Get|Set)FreezerState to VIR_CGROUP_SUPPORTED - Convert virCgroupRemoveRecursively to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 363 +++++++++++++++++++++++++++++---------------------- 1 file changed, 204 insertions(+), 159 deletions(-)
Hmm - 5 identical subject lines (after the [] gets stripped) makes reviewing git history a bit harder. Also, when sending a series, it helps to send a cover letter (git send-email --cover-letter adds a 0/5 message, and makes all the other messages a reply to that one). But don't worry about that; I can touch it up as part of testing the series.
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5f656b1..3640fbd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -57,7 +57,7 @@ #define VIR_FROM_THIS VIR_FROM_CGROUP
#if defined(__linux__) && defined(HAVE_GETMNTENT_R) \ - && defined(_DIRENT_HAVE_D_TYPE) + && defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK)
Hmm, I'm wondering whether this changes behavior on any version of Linux old enough to lack _SC_CLK_TCK (that is, changing from partial cgroup support to no cgroup support)... /me checks RHEL 5... phew - _SC_CLK_TCK has existed for a long time, and as RHEL 5 is really the oldest kernel we care about supporting, this is just fine.
@@ -3039,6 +3032,7 @@ int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED, return -1; }
+ int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED, int signum ATTRIBUTE_UNUSED) { @@ -3047,6 +3041,7 @@ int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED, return -1; }
+ int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED)
I squashed these hunks into 1/5. ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Continue converting to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 378 +++++++++++++++++++++++++++------------------------ 1 file changed, 202 insertions(+), 176 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 3640fbd..795897b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -74,157 +74,6 @@ typedef enum { */ } virCgroupFlags; -bool virCgroupAvailable(void) -{ - bool ret = false; -#ifdef HAVE_GETMNTENT_R - FILE *mounts = NULL; - struct mntent entry; - char buf[CGROUP_MAX_VAL]; - - if (!virFileExists("/proc/cgroups")) - return false; - - if (!(mounts = fopen("/proc/mounts", "r"))) - return false; - - while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) { - if (STREQ(entry.mnt_type, "cgroup")) { - ret = true; - break; - } - } - - VIR_FORCE_FCLOSE(mounts); -#endif - return ret; -} - -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R - -static int virCgroupPartitionEscape(char **path); - -static bool -virCgroupValidateMachineGroup(virCgroupPtr group, - const char *name, - const char *drivername, - const char *partition, - bool stripEmulatorSuffix) -{ - size_t i; - bool valid = false; - char *partname; - char *scopename; - - if (virAsprintf(&partname, "%s.libvirt-%s", - name, drivername) < 0) - goto cleanup; - - if (virCgroupPartitionEscape(&partname) < 0) - goto cleanup; - - if (!partition) - partition = "/machine"; - - if (!(scopename = virSystemdMakeScopeName(name, drivername, partition))) - goto cleanup; - - if (virCgroupPartitionEscape(&scopename) < 0) - goto cleanup; - - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *tmp; - - if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - if (!group->controllers[i].placement) - continue; - - tmp = strrchr(group->controllers[i].placement, '/'); - if (!tmp) - goto cleanup; - - if (stripEmulatorSuffix && - (i == VIR_CGROUP_CONTROLLER_CPU || - i == VIR_CGROUP_CONTROLLER_CPUACCT || - i == VIR_CGROUP_CONTROLLER_CPUSET)) { - if (STREQ(tmp, "/emulator")) - *tmp = '\0'; - tmp = strrchr(group->controllers[i].placement, '/'); - if (!tmp) - goto cleanup; - } - - tmp++; - - if (STRNEQ(tmp, name) && - STRNEQ(tmp, partname) && - STRNEQ(tmp, scopename)) { - VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", - tmp, virCgroupControllerTypeToString(i), name, partname, scopename); - goto cleanup; - } - } - - valid = true; - - cleanup: - VIR_FREE(partname); - VIR_FREE(scopename); - return valid; -} -#else -static bool -virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *name ATTRIBUTE_UNUSED, - const char *drivername ATTRIBUTE_UNUSED, - bool stripEmulatorSuffix ATTRIBUTE_UNUSED) -{ - return true; -} -#endif - -/** - * virCgroupFree: - * - * @group: The group structure to free - */ -void virCgroupFree(virCgroupPtr *group) -{ - size_t i; - - if (*group == NULL) - return; - - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_FREE((*group)->controllers[i].mountPoint); - VIR_FREE((*group)->controllers[i].linkPoint); - VIR_FREE((*group)->controllers[i].placement); - } - - VIR_FREE((*group)->path); - VIR_FREE(*group); -} - -/** - * virCgroupHasController: query whether a cgroup controller is present - * - * @cgroup: The group structure to be queried, or NULL - * @controller: cgroup subsystem id - * - * Returns true if a cgroup controller is mounted and is associated - * with this cgroup object. - */ -bool virCgroupHasController(virCgroupPtr cgroup, int controller) -{ - if (!cgroup) - return false; - if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) - return false; - return cgroup->controllers[controller].mountPoint != NULL; -} - #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupCopyMounts(virCgroupPtr group, virCgroupPtr parent) @@ -1605,31 +1454,6 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, } #endif -/* - * Returns 0 on success (but @group may be NULL), -1 on fatal error - */ -int virCgroupNewDetectMachine(const char *name, - const char *drivername, - pid_t pid, - const char *partition, - int controllers, - virCgroupPtr *group) -{ - if (virCgroupNewDetect(pid, controllers, group) < 0) { - if (virCgroupNewIgnoreError()) - return 0; - return -1; - } - - if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, true)) { - VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", - name, drivername); - virCgroupFree(group); - return 0; - } - - return 0; -} /* * Returns 0 on success, -1 on fatal error, -2 on systemd not available @@ -2530,6 +2354,173 @@ int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) #ifdef VIR_CGROUP_SUPPORTED +bool virCgroupAvailable(void) +{ + bool ret = false; + FILE *mounts = NULL; + struct mntent entry; + char buf[CGROUP_MAX_VAL]; + + if (!virFileExists("/proc/cgroups")) + return false; + + if (!(mounts = fopen("/proc/mounts", "r"))) + return false; + + while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) { + if (STREQ(entry.mnt_type, "cgroup")) { + ret = true; + break; + } + } + + VIR_FORCE_FCLOSE(mounts); + return ret; +} + + +static int virCgroupPartitionEscape(char **path); + +static bool +virCgroupValidateMachineGroup(virCgroupPtr group, + const char *name, + const char *drivername, + const char *partition, + bool stripEmulatorSuffix) +{ + size_t i; + bool valid = false; + char *partname; + char *scopename; + + if (virAsprintf(&partname, "%s.libvirt-%s", + name, drivername) < 0) + goto cleanup; + + if (virCgroupPartitionEscape(&partname) < 0) + goto cleanup; + + if (!partition) + partition = "/machine"; + + if (!(scopename = virSystemdMakeScopeName(name, drivername, partition))) + goto cleanup; + + if (virCgroupPartitionEscape(&scopename) < 0) + goto cleanup; + + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + char *tmp; + + if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (!group->controllers[i].placement) + continue; + + tmp = strrchr(group->controllers[i].placement, '/'); + if (!tmp) + goto cleanup; + + if (stripEmulatorSuffix && + (i == VIR_CGROUP_CONTROLLER_CPU || + i == VIR_CGROUP_CONTROLLER_CPUACCT || + i == VIR_CGROUP_CONTROLLER_CPUSET)) { + if (STREQ(tmp, "/emulator")) + *tmp = '\0'; + tmp = strrchr(group->controllers[i].placement, '/'); + if (!tmp) + goto cleanup; + } + + tmp++; + + if (STRNEQ(tmp, name) && + STRNEQ(tmp, partname) && + STRNEQ(tmp, scopename)) { + VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", + tmp, virCgroupControllerTypeToString(i), name, partname, scopename); + goto cleanup; + } + } + + valid = true; + + cleanup: + VIR_FREE(partname); + VIR_FREE(scopename); + return valid; +} + + +/* + * Returns 0 on success (but @group may be NULL), -1 on fatal error + */ +int virCgroupNewDetectMachine(const char *name, + const char *drivername, + pid_t pid, + const char *partition, + int controllers, + virCgroupPtr *group) +{ + if (virCgroupNewDetect(pid, controllers, group) < 0) { + if (virCgroupNewIgnoreError()) + return 0; + return -1; + } + + if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, true)) { + VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", + name, drivername); + virCgroupFree(group); + return 0; + } + + return 0; +} + + +/** + * virCgroupFree: + * + * @group: The group structure to free + */ +void virCgroupFree(virCgroupPtr *group) +{ + size_t i; + + if (*group == NULL) + return; + + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_FREE((*group)->controllers[i].mountPoint); + VIR_FREE((*group)->controllers[i].linkPoint); + VIR_FREE((*group)->controllers[i].placement); + } + + VIR_FREE((*group)->path); + VIR_FREE(*group); +} + + +/** + * virCgroupHasController: query whether a cgroup controller is present + * + * @cgroup: The group structure to be queried, or NULL + * @controller: cgroup subsystem id + * + * Returns true if a cgroup controller is mounted and is associated + * with this cgroup object. + */ +bool virCgroupHasController(virCgroupPtr cgroup, int controller) +{ + if (!cgroup) + return false; + if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) + return false; + return cgroup->controllers[controller].mountPoint != NULL; +} + int virCgroupRemoveRecursively(char *grppath) { DIR *grpdir; @@ -3016,6 +3007,41 @@ cleanup: return ret; } #else /* VIR_CGROUP_SUPPORTED */ +bool virCgroupAvailable(void) +{ + return false; +} + + +int virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED, + const char *partition ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +void virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); +} + + +bool virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return false; +} + + int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", -- 1.8.2.3

On 08/11/2013 06:04 AM, Roman Bogorodskiy wrote:
Continue converting to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 378 +++++++++++++++++++++++++++------------------------ 1 file changed, 202 insertions(+), 176 deletions(-)
- if (STRNEQ(tmp, name) && - STRNEQ(tmp, partname) && - STRNEQ(tmp, scopename)) { - VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", - tmp, virCgroupControllerTypeToString(i), name, partname, scopename);
I'm using this opportunity to fold some long lines.
- */ -bool virCgroupHasController(virCgroupPtr cgroup, int controller) -{ - if (!cgroup) - return false; - if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) - return false; - return cgroup->controllers[controller].mountPoint != NULL; -}
This function was silent on failure beforehand...
+ + +static int virCgroupPartitionEscape(char **path); + +static bool +virCgroupValidateMachineGroup(virCgroupPtr group,
Rather than needing a forward declaration for virCgroupPartitionEscape, we can use this opportunity to topologically sort the static helper functions in the first place :)
#else /* VIR_CGROUP_SUPPORTED */
+ +bool virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return false;
...therefore this shouldn't raise an error. ACK with those things fixed (and I'm making the fixes locally before pushing). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Complete moving to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 497 ++++++++++++++++++++++++++++----------------------- 1 file changed, 272 insertions(+), 225 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 795897b..e5625f8 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -74,7 +74,134 @@ typedef enum { */ } virCgroupFlags; -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R + +#ifdef VIR_CGROUP_SUPPORTED +bool virCgroupAvailable(void) +{ + bool ret = false; + FILE *mounts = NULL; + struct mntent entry; + char buf[CGROUP_MAX_VAL]; + + if (!virFileExists("/proc/cgroups")) + return false; + + if (!(mounts = fopen("/proc/mounts", "r"))) + return false; + + while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) { + if (STREQ(entry.mnt_type, "cgroup")) { + ret = true; + break; + } + } + + VIR_FORCE_FCLOSE(mounts); + return ret; +} + + +static int virCgroupPartitionEscape(char **path); + +static bool +virCgroupValidateMachineGroup(virCgroupPtr group, + const char *name, + const char *drivername, + const char *partition, + bool stripEmulatorSuffix) +{ + size_t i; + bool valid = false; + char *partname; + char *scopename; + + if (virAsprintf(&partname, "%s.libvirt-%s", + name, drivername) < 0) + goto cleanup; + + if (virCgroupPartitionEscape(&partname) < 0) + goto cleanup; + + if (!partition) + partition = "/machine"; + + if (!(scopename = virSystemdMakeScopeName(name, drivername, partition))) + goto cleanup; + + if (virCgroupPartitionEscape(&scopename) < 0) + goto cleanup; + + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + char *tmp; + + if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (!group->controllers[i].placement) + continue; + + tmp = strrchr(group->controllers[i].placement, '/'); + if (!tmp) + goto cleanup; + + if (stripEmulatorSuffix && + (i == VIR_CGROUP_CONTROLLER_CPU || + i == VIR_CGROUP_CONTROLLER_CPUACCT || + i == VIR_CGROUP_CONTROLLER_CPUSET)) { + if (STREQ(tmp, "/emulator")) + *tmp = '\0'; + tmp = strrchr(group->controllers[i].placement, '/'); + if (!tmp) + goto cleanup; + } + + tmp++; + + if (STRNEQ(tmp, name) && + STRNEQ(tmp, partname) && + STRNEQ(tmp, scopename)) { + VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", + tmp, virCgroupControllerTypeToString(i), name, partname, scopename); + goto cleanup; + } + } + + valid = true; + + cleanup: + VIR_FREE(partname); + VIR_FREE(scopename); + return valid; +} + + +/* + * Returns 0 on success (but @group may be NULL), -1 on fatal error + */ +int virCgroupNewDetectMachine(const char *name, + const char *drivername, + pid_t pid, + const char *partition, + int controllers, + virCgroupPtr *group) +{ + if (virCgroupNewDetect(pid, controllers, group) < 0) { + if (virCgroupNewIgnoreError()) + return 0; + return -1; + } + + if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, true)) { + VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", + name, drivername); + virCgroupFree(group); + return 0; + } + + return 0; +} + + static int virCgroupCopyMounts(virCgroupPtr group, virCgroupPtr parent) { @@ -346,6 +473,7 @@ cleanup: return ret; } + static int virCgroupDetect(virCgroupPtr group, pid_t pid, int controllers, @@ -453,7 +581,6 @@ static int virCgroupDetect(virCgroupPtr group, return 0; } -#endif int virCgroupPathOfController(virCgroupPtr group, @@ -531,6 +658,7 @@ cleanup: return ret; } + static int virCgroupGetValueStr(virCgroupPtr group, int controller, const char *key, @@ -563,6 +691,7 @@ cleanup: return ret; } + static int virCgroupSetValueU64(virCgroupPtr group, int controller, const char *key, @@ -582,7 +711,6 @@ static int virCgroupSetValueU64(virCgroupPtr group, } - static int virCgroupSetValueI64(virCgroupPtr group, int controller, const char *key, @@ -601,6 +729,7 @@ static int virCgroupSetValueI64(virCgroupPtr group, return ret; } + static int virCgroupGetValueI64(virCgroupPtr group, int controller, const char *key, @@ -626,6 +755,7 @@ cleanup: return ret; } + static int virCgroupGetValueU64(virCgroupPtr group, int controller, const char *key, @@ -652,7 +782,6 @@ cleanup: } -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) { size_t i; @@ -686,6 +815,7 @@ static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) return 0; } + static int virCgroupSetMemoryUseHierarchy(virCgroupPtr group) { unsigned long long value; @@ -709,6 +839,7 @@ static int virCgroupSetMemoryUseHierarchy(virCgroupPtr group) return 0; } + static int virCgroupMakeGroup(virCgroupPtr parent, virCgroupPtr group, bool create, @@ -847,7 +978,6 @@ error: return -1; } -#endif /** @@ -930,6 +1060,7 @@ cleanup: return ret; } + /** * virCgroupAddTaskController: * @@ -1002,6 +1133,7 @@ cleanup: return rc; } + /** * virCgroupMoveTask: * @@ -1050,7 +1182,6 @@ cleanup: } -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupPartitionNeedsEscaping(const char *path) { FILE *fp = NULL; @@ -1120,6 +1251,7 @@ cleanup: return ret; } + static int virCgroupPartitionEscape(char **path) { size_t len = strlen(*path) + 1; @@ -1135,6 +1267,7 @@ static int virCgroupPartitionEscape(char **path) return 0; } + static int virCgroupSetPartitionSuffix(const char *path, char **res) { char **tokens; @@ -1179,6 +1312,7 @@ cleanup: return ret; } + /** * virCgroupNewPartition: * @path: path for the partition @@ -1242,17 +1376,6 @@ cleanup: VIR_FREE(newpath); return ret; } -#else -int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -1281,7 +1404,6 @@ int virCgroupNewSelf(virCgroupPtr *group) * * Returns 0 on success, or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewDomainPartition(virCgroupPtr partition, const char *driver, const char *name, @@ -1323,18 +1445,7 @@ cleanup: VIR_FREE(grpname); return ret; } -#else -int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, - const char *driver ATTRIBUTE_UNUSED, - const char *name ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif + /** * virCgroupNewVcpu: @@ -1346,7 +1457,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, * * Returns 0 on success, or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewVcpu(virCgroupPtr domain, int vcpuid, bool create, @@ -1377,17 +1487,7 @@ cleanup: VIR_FREE(name); return ret; } -#else -int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, - int vcpuid ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif + /** * virCgroupNewEmulator: @@ -1398,7 +1498,6 @@ int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, * * Returns: 0 on success or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewEmulator(virCgroupPtr domain, bool create, virCgroupPtr *group) @@ -1423,36 +1522,14 @@ int virCgroupNewEmulator(virCgroupPtr domain, cleanup: return ret; } -#else -int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif - -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewDetect(pid_t pid, int controllers, virCgroupPtr *group) { return virCgroupNew(pid, "", NULL, controllers, group); } -#else -int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /* @@ -1561,6 +1638,7 @@ virCgroupNewMachineSystemd(const char *name, return ret; } + static int virCgroupNewMachineManual(const char *name, const char *drivername, @@ -1608,6 +1686,7 @@ cleanup: return ret; } + int virCgroupNewMachine(const char *name, const char *drivername, bool privileged, @@ -1646,6 +1725,7 @@ int virCgroupNewMachine(const char *name, group); } + bool virCgroupNewIgnoreError(void) { if (virLastErrorIsSystemErrno(ENXIO) || @@ -1658,6 +1738,7 @@ bool virCgroupNewIgnoreError(void) return false; } + /** * virCgroupSetBlkioWeight: * @@ -1681,6 +1762,7 @@ int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) weight); } + /** * virCgroupGetBlkioWeight: * @@ -1701,6 +1783,7 @@ int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) return ret; } + /** * virCgroupSetBlkioDeviceWeight: * @@ -1713,7 +1796,6 @@ int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) * * Returns: 0 on success, -1 on error */ -#if defined(major) && defined(minor) int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) @@ -1754,17 +1836,7 @@ int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, VIR_FREE(str); return ret; } -#else -int -virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - unsigned int weight ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif + /** * virCgroupSetMemory: @@ -1797,6 +1869,7 @@ int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) kb << 10); } + /** * virCgroupGetMemoryUsage: * @@ -1817,6 +1890,7 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) return ret; } + /** * virCgroupSetMemoryHardLimit: * @@ -1830,6 +1904,7 @@ int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) return virCgroupSetMemory(group, kb); } + /** * virCgroupGetMemoryHardLimit: * @@ -1850,6 +1925,7 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetMemorySoftLimit: * @@ -1902,6 +1978,7 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetMemSwapHardLimit: * @@ -1933,6 +2010,7 @@ int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) kb << 10); } + /** * virCgroupGetMemSwapHardLimit: * @@ -1953,6 +2031,7 @@ int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupGetMemSwapUsage: * @@ -1973,6 +2052,7 @@ int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetCpusetMems: * @@ -1989,6 +2069,7 @@ int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) mems); } + /** * virCgroupGetCpusetMems: * @@ -2005,6 +2086,7 @@ int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) mems); } + /** * virCgroupSetCpusetCpus: * @@ -2021,6 +2103,7 @@ int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) cpus); } + /** * virCgroupGetCpusetCpus: * @@ -2037,6 +2120,7 @@ int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) cpus); } + /** * virCgroupDenyAllDevices: * @@ -2052,6 +2136,7 @@ int virCgroupDenyAllDevices(virCgroupPtr group) "a"); } + /** * virCgroupAllowDevice: * @@ -2088,6 +2173,7 @@ cleanup: return ret; } + /** * virCgroupAllowDeviceMajor: * @@ -2123,6 +2209,7 @@ cleanup: return ret; } + /** * virCgroupAllowDevicePath: * @@ -2136,7 +2223,6 @@ cleanup: * Returns: 0 on success, 1 if path exists but is not a device, or * -1 on error */ -#if defined(major) && defined(minor) int virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) { struct stat sb; @@ -2157,16 +2243,6 @@ int virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) minor(sb.st_rdev), perms); } -#else -int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -2205,6 +2281,7 @@ cleanup: return ret; } + /** * virCgroupDenyDeviceMajor: * @@ -2240,7 +2317,7 @@ cleanup: return ret; } -#if defined(major) && defined(minor) + int virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) { struct stat sb; @@ -2261,16 +2338,7 @@ int virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) minor(sb.st_rdev), perms); } -#else -int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif + int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { @@ -2279,6 +2347,7 @@ int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) "cpu.shares", shares); } + int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) { return virCgroupGetValueU64(group, @@ -2286,6 +2355,7 @@ int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) "cpu.shares", shares); } + /** * virCgroupSetCpuCfsPeriod: * @@ -2353,132 +2423,6 @@ int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) } -#ifdef VIR_CGROUP_SUPPORTED -bool virCgroupAvailable(void) -{ - bool ret = false; - FILE *mounts = NULL; - struct mntent entry; - char buf[CGROUP_MAX_VAL]; - - if (!virFileExists("/proc/cgroups")) - return false; - - if (!(mounts = fopen("/proc/mounts", "r"))) - return false; - - while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) { - if (STREQ(entry.mnt_type, "cgroup")) { - ret = true; - break; - } - } - - VIR_FORCE_FCLOSE(mounts); - return ret; -} - - -static int virCgroupPartitionEscape(char **path); - -static bool -virCgroupValidateMachineGroup(virCgroupPtr group, - const char *name, - const char *drivername, - const char *partition, - bool stripEmulatorSuffix) -{ - size_t i; - bool valid = false; - char *partname; - char *scopename; - - if (virAsprintf(&partname, "%s.libvirt-%s", - name, drivername) < 0) - goto cleanup; - - if (virCgroupPartitionEscape(&partname) < 0) - goto cleanup; - - if (!partition) - partition = "/machine"; - - if (!(scopename = virSystemdMakeScopeName(name, drivername, partition))) - goto cleanup; - - if (virCgroupPartitionEscape(&scopename) < 0) - goto cleanup; - - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *tmp; - - if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - if (!group->controllers[i].placement) - continue; - - tmp = strrchr(group->controllers[i].placement, '/'); - if (!tmp) - goto cleanup; - - if (stripEmulatorSuffix && - (i == VIR_CGROUP_CONTROLLER_CPU || - i == VIR_CGROUP_CONTROLLER_CPUACCT || - i == VIR_CGROUP_CONTROLLER_CPUSET)) { - if (STREQ(tmp, "/emulator")) - *tmp = '\0'; - tmp = strrchr(group->controllers[i].placement, '/'); - if (!tmp) - goto cleanup; - } - - tmp++; - - if (STRNEQ(tmp, name) && - STRNEQ(tmp, partname) && - STRNEQ(tmp, scopename)) { - VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", - tmp, virCgroupControllerTypeToString(i), name, partname, scopename); - goto cleanup; - } - } - - valid = true; - - cleanup: - VIR_FREE(partname); - VIR_FREE(scopename); - return valid; -} - - -/* - * Returns 0 on success (but @group may be NULL), -1 on fatal error - */ -int virCgroupNewDetectMachine(const char *name, - const char *drivername, - pid_t pid, - const char *partition, - int controllers, - virCgroupPtr *group) -{ - if (virCgroupNewDetect(pid, controllers, group) < 0) { - if (virCgroupNewIgnoreError()) - return 0; - return -1; - } - - if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, true)) { - VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", - name, drivername); - virCgroupFree(group); - return 0; - } - - return 0; -} - /** * virCgroupFree: @@ -3026,6 +2970,109 @@ int virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED, } +int virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED, + const char *key ATTRIBUTE_UNUSED, + char **path ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewSelf(virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, + const char *driver ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, + int vcpuid ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + +int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + unsigned int weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + void virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", -- 1.8.2.3

On 08/11/2013 06:04 AM, Roman Bogorodskiy wrote:
Complete moving to VIR_CGROUP_SUPPORTED --- src/util/vircgroup.c | 497 ++++++++++++++++++++++++++++----------------------- 1 file changed, 272 insertions(+), 225 deletions(-)
This one felt a bit big...
-#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R + +#ifdef VIR_CGROUP_SUPPORTED +bool virCgroupAvailable(void)
You're rearranging functions,...
@@ -346,6 +473,7 @@ cleanup: return ret; }
+ static int virCgroupDetect(virCgroupPtr group,
...fixing whitespace...
@@ -1242,17 +1376,6 @@ cleanup: VIR_FREE(newpath); return ret; } -#else -int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED)
...and moving #else clauses, all in one patch. I'm probably going to split this up a bit. But it still looks reasonable; ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Complete the refactoring by adding missing stubs so it compiles on platform without cgroup support. --- src/util/vircgroup.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 306 insertions(+), 5 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e5625f8..2e7cbfa 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2981,6 +2981,42 @@ int virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, } +int virCgroupRemove(virCgroupPtr group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAddTask(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAddTaskController(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupMoveTask(virCgroupPtr src_group ATTRIBUTE_UNUSED, + virCgroupPtr dest_group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, bool create ATTRIBUTE_UNUSED, int controllers ATTRIBUTE_UNUSED, @@ -3032,6 +3068,7 @@ int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, return -1; } + int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, int controllers ATTRIBUTE_UNUSED, virCgroupPtr *group ATTRIBUTE_UNUSED) @@ -3042,6 +3079,49 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, } +int virCgroupNewMachine(const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool privileged ATTRIBUTE_UNUSED, + const unsigned char *uuid ATTRIBUTE_UNUSED, + const char *rootdir ATTRIBUTE_UNUSED, + pid_t pidleader ATTRIBUTE_UNUSED, + bool isContainer ATTRIBUTE_UNUSED, + const char *partition ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +bool virCgroupNewIgnoreError(void) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return false; +} + + +int virCgroupSetBlkioWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned int weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetBlkioWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned int *weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + int virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, @@ -3053,6 +3133,154 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, } +int virCgroupSetMemory(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetMemoryUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetMemoryHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetMemoryHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetMemorySoftLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetMemorySoftLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetMemSwapHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetMemSwapHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetMemSwapUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetCpusetMems(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *mems ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpusetMems(virCgroupPtr group ATTRIBUTE_UNUSED, + char **mems ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetCpusetCpus(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *cpus ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpusetCpus(virCgroupPtr group ATTRIBUTE_UNUSED, + char **cpus ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupDenyAllDevices(virCgroupPtr group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAllowDevice(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int minor ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAllowDeviceMajor(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, int perms ATTRIBUTE_UNUSED) @@ -3063,6 +3291,29 @@ int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, } +int virCgroupDenyDevice(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int minor ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupDenyDeviceMajor(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, int perms ATTRIBUTE_UNUSED) @@ -3073,6 +3324,51 @@ int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, } +int virCgroupSetCpuShares(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long shares ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpuShares(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *shares ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetCpuCfsPeriod(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long cfs_period ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupGetCpuCfsPeriod(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *cfs_period ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetCpuCfsQuota(virCgroupPtr group ATTRIBUTE_UNUSED, + long long cfs_quota ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + void virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", @@ -3123,7 +3419,8 @@ int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) } -int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) +int virCgroupGetCpuCfsQuota(virCgroupPtr group ATTRIBUTE_UNUSED, + long long *cfs_quota ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -3131,7 +3428,8 @@ int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) } -int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) +int virCgroupGetCpuacctUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *usage ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -3139,7 +3437,8 @@ int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) } -int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) +int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + char **usage ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -3157,14 +3456,16 @@ int virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, } -int virCgroupSetFreezerState(virCgroupPtr group, const char *state) +int virCgroupSetFreezerState(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *state ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); return -1; } -int virCgroupGetFreezerState(virCgroupPtr group, char **state) +int virCgroupGetFreezerState(virCgroupPtr group ATTRIBUTE_UNUSED, + char **state ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); -- 1.8.2.3

On 08/11/2013 06:04 AM, Roman Bogorodskiy wrote:
Complete the refactoring by adding missing stubs so it compiles on platform without cgroup support. --- src/util/vircgroup.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 306 insertions(+), 5 deletions(-)
ACK.
@@ -3032,6 +3068,7 @@ int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, return -1; }
+ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
Should be squashed earlier.
+ +bool virCgroupNewIgnoreError(void) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return false;
Not sure if this one should be silent. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 08/11/2013 06:04 AM, Roman Bogorodskiy wrote:
- Introduce VIR_CGROUP_SUPPORTED conditional - Convert virCgroupKill* to use it - Convert virCgroupIsolateMount() to use it --- src/util/vircgroup.c | 59 ++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 27 deletions(-)
+#if defined(__linux__) && defined(HAVE_GETMNTENT_R) \ + && defined(_DIRENT_HAVE_D_TYPE)
Our coding style tends to leave && at the end of the previous line when wrapping. ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Reposting to show how I touched up the series. By doing a bit more shuffling and splitting of the patches, I was able to come up with a series that was easier to review. My lead-in patches are really just pulling parts of Roman's patches out into earlier commits, so that the remainder of Roman's patches are much smaller in size. Since I already acked Roman's work, and since I tested that this fixes a build failure on FreeBSD, I've gone ahead and pushed the series. Eric Blake (3): cgroup: use consistent formatting cgroup: topological sort cgroup: functional sort Roman Bogorodskiy (5): cgroup macros refactoring, part 1 cgroup macros refactoring, part 2 cgroup macros refactoring, part 3 cgroup macros refactoring, part 4 cgroup macros refactoring, part 5 src/util/vircgroup.c | 1947 ++++++++++++++++++++++++++++++++------------------ src/util/vircgroup.h | 6 +- 2 files changed, 1269 insertions(+), 684 deletions(-) -- 1.8.3.1

Format all functions with two blank lines between, and return type on separate line from function name. Also break some lines longer than 80 columns. This makes the subsequent macro refactoring less noisy. * src/util/vircgroup.c: Match prevailing style. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 585 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 379 insertions(+), 206 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cfb4b3f..0925078 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -69,7 +69,9 @@ typedef enum { */ } virCgroupFlags; -bool virCgroupAvailable(void) + +bool +virCgroupAvailable(void) { bool ret = false; #ifdef HAVE_GETMNTENT_R @@ -156,8 +158,10 @@ virCgroupValidateMachineGroup(virCgroupPtr group, if (STRNEQ(tmp, name) && STRNEQ(tmp, partname) && STRNEQ(tmp, scopename)) { - VIR_DEBUG("Name '%s' for controller '%s' does not match '%s', '%s' or '%s'", - tmp, virCgroupControllerTypeToString(i), name, partname, scopename); + VIR_DEBUG("Name '%s' for controller '%s' does not match " + "'%s', '%s' or '%s'", + tmp, virCgroupControllerTypeToString(i), + name, partname, scopename); goto cleanup; } } @@ -180,12 +184,14 @@ virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, } #endif + /** * virCgroupFree: * * @group: The group structure to free */ -void virCgroupFree(virCgroupPtr *group) +void +virCgroupFree(virCgroupPtr *group) { size_t i; @@ -202,6 +208,7 @@ void virCgroupFree(virCgroupPtr *group) VIR_FREE(*group); } + /** * virCgroupHasController: query whether a cgroup controller is present * @@ -211,7 +218,8 @@ void virCgroupFree(virCgroupPtr *group) * Returns true if a cgroup controller is mounted and is associated * with this cgroup object. */ -bool virCgroupHasController(virCgroupPtr cgroup, int controller) +bool +virCgroupHasController(virCgroupPtr cgroup, int controller) { if (!cgroup) return false; @@ -221,8 +229,9 @@ bool virCgroupHasController(virCgroupPtr cgroup, int controller) } #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -static int virCgroupCopyMounts(virCgroupPtr group, - virCgroupPtr parent) +static int +virCgroupCopyMounts(virCgroupPtr group, + virCgroupPtr parent) { size_t i; for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -240,11 +249,13 @@ static int virCgroupCopyMounts(virCgroupPtr group, return 0; } + /* * Process /proc/mounts figuring out what controllers are * mounted and where */ -static int virCgroupDetectMounts(virCgroupPtr group) +static int +virCgroupDetectMounts(virCgroupPtr group) { size_t i; FILE *mounts = NULL; @@ -312,7 +323,8 @@ static int virCgroupDetectMounts(virCgroupPtr group) VIR_FREE(linksrc); } else { virReportSystemError(errno, - _("Cannot stat %s"), linksrc); + _("Cannot stat %s"), + linksrc); goto error; } } else { @@ -340,9 +352,10 @@ error: } -static int virCgroupCopyPlacement(virCgroupPtr group, - const char *path, - virCgroupPtr parent) +static int +virCgroupCopyPlacement(virCgroupPtr group, + const char *path, + virCgroupPtr parent) { size_t i; for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -397,9 +410,10 @@ static int virCgroupCopyPlacement(virCgroupPtr group, * * It then appends @path to each detected path. */ -static int virCgroupDetectPlacement(virCgroupPtr group, - pid_t pid, - const char *path) +static int +virCgroupDetectPlacement(virCgroupPtr group, + pid_t pid, + const char *path) { size_t i; FILE *mapping = NULL; @@ -492,11 +506,13 @@ cleanup: return ret; } -static int virCgroupDetect(virCgroupPtr group, - pid_t pid, - int controllers, - const char *path, - virCgroupPtr parent) + +static int +virCgroupDetect(virCgroupPtr group, + pid_t pid, + int controllers, + const char *path, + virCgroupPtr parent) { size_t i; size_t j; @@ -602,10 +618,11 @@ static int virCgroupDetect(virCgroupPtr group, #endif -int virCgroupPathOfController(virCgroupPtr group, - int controller, - const char *key, - char **path) +int +virCgroupPathOfController(virCgroupPtr group, + int controller, + const char *key, + char **path) { if (controller == -1) { size_t i; @@ -652,10 +669,11 @@ int virCgroupPathOfController(virCgroupPtr group, } -static int virCgroupSetValueStr(virCgroupPtr group, - int controller, - const char *key, - const char *value) +static int +virCgroupSetValueStr(virCgroupPtr group, + int controller, + const char *key, + const char *value) { int ret = -1; char *keypath = NULL; @@ -677,10 +695,12 @@ cleanup: return ret; } -static int virCgroupGetValueStr(virCgroupPtr group, - int controller, - const char *key, - char **value) + +static int +virCgroupGetValueStr(virCgroupPtr group, + int controller, + const char *key, + char **value) { char *keypath = NULL; int ret = -1, rc; @@ -709,10 +729,12 @@ cleanup: return ret; } -static int virCgroupSetValueU64(virCgroupPtr group, - int controller, - const char *key, - unsigned long long int value) + +static int +virCgroupSetValueU64(virCgroupPtr group, + int controller, + const char *key, + unsigned long long int value) { char *strval = NULL; int ret; @@ -728,11 +750,11 @@ static int virCgroupSetValueU64(virCgroupPtr group, } - -static int virCgroupSetValueI64(virCgroupPtr group, - int controller, - const char *key, - long long int value) +static int +virCgroupSetValueI64(virCgroupPtr group, + int controller, + const char *key, + long long int value) { char *strval = NULL; int ret; @@ -747,10 +769,12 @@ static int virCgroupSetValueI64(virCgroupPtr group, return ret; } -static int virCgroupGetValueI64(virCgroupPtr group, - int controller, - const char *key, - long long int *value) + +static int +virCgroupGetValueI64(virCgroupPtr group, + int controller, + const char *key, + long long int *value) { char *strval = NULL; int ret = -1; @@ -772,10 +796,12 @@ cleanup: return ret; } -static int virCgroupGetValueU64(virCgroupPtr group, - int controller, - const char *key, - unsigned long long int *value) + +static int +virCgroupGetValueU64(virCgroupPtr group, + int controller, + const char *key, + unsigned long long int *value) { char *strval = NULL; int ret = -1; @@ -799,7 +825,8 @@ cleanup: #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) +static int +virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) { size_t i; const char *inherit_values[] = { @@ -832,7 +859,9 @@ static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) return 0; } -static int virCgroupSetMemoryUseHierarchy(virCgroupPtr group) + +static int +virCgroupSetMemoryUseHierarchy(virCgroupPtr group) { unsigned long long value; const char *filename = "memory.use_hierarchy"; @@ -855,10 +884,12 @@ static int virCgroupSetMemoryUseHierarchy(virCgroupPtr group) return 0; } -static int virCgroupMakeGroup(virCgroupPtr parent, - virCgroupPtr group, - bool create, - unsigned int flags) + +static int +virCgroupMakeGroup(virCgroupPtr parent, + virCgroupPtr group, + bool create, + unsigned int flags) { size_t i; int ret = -1; @@ -910,7 +941,8 @@ static int virCgroupMakeGroup(virCgroupPtr parent, } if (group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoint != NULL && (i == VIR_CGROUP_CONTROLLER_CPUSET || - STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoint))) { + STREQ(group->controllers[i].mountPoint, + group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoint))) { if (virCgroupCpuSetInherit(parent, group) < 0) { VIR_FREE(path); goto cleanup; @@ -923,7 +955,8 @@ static int virCgroupMakeGroup(virCgroupPtr parent, if ((flags & VIR_CGROUP_MEM_HIERACHY) && (group->controllers[VIR_CGROUP_CONTROLLER_MEMORY].mountPoint != NULL) && (i == VIR_CGROUP_CONTROLLER_MEMORY || - STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_MEMORY].mountPoint))) { + STREQ(group->controllers[i].mountPoint, + group->controllers[VIR_CGROUP_CONTROLLER_MEMORY].mountPoint))) { if (virCgroupSetMemoryUseHierarchy(group) < 0) { VIR_FREE(path); goto cleanup; @@ -958,11 +991,12 @@ cleanup: * * Returns 0 on success, -1 on error */ -static int virCgroupNew(pid_t pid, - const char *path, - virCgroupPtr parent, - int controllers, - virCgroupPtr *group) +static int +virCgroupNew(pid_t pid, + const char *path, + virCgroupPtr parent, + int controllers, + virCgroupPtr *group) { VIR_DEBUG("parent=%p path=%s controllers=%d", parent, path, controllers); @@ -996,7 +1030,8 @@ error: #endif #if defined _DIRENT_HAVE_D_TYPE -int virCgroupRemoveRecursively(char *grppath) +int +virCgroupRemoveRecursively(char *grppath) { DIR *grpdir; struct dirent *ent; @@ -1045,7 +1080,8 @@ int virCgroupRemoveRecursively(char *grppath) return rc; } #else -int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) +int +virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1053,6 +1089,7 @@ int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) } #endif + /** * virCgroupRemove: * @@ -1065,7 +1102,8 @@ int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) * * Returns: 0 on success */ -int virCgroupRemove(virCgroupPtr group) +int +virCgroupRemove(virCgroupPtr group) { int rc = 0; size_t i; @@ -1110,7 +1148,8 @@ int virCgroupRemove(virCgroupPtr group) * * Returns: 0 on success, -1 on error */ -int virCgroupAddTask(virCgroupPtr group, pid_t pid) +int +virCgroupAddTask(virCgroupPtr group, pid_t pid) { int ret = -1; size_t i; @@ -1124,7 +1163,7 @@ int virCgroupAddTask(virCgroupPtr group, pid_t pid) if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) continue; - if (virCgroupSetValueU64(group, i, "tasks", (unsigned long long)pid) < 0) + if (virCgroupSetValueU64(group, i, "tasks", pid) < 0) goto cleanup; } @@ -1133,6 +1172,7 @@ cleanup: return ret; } + /** * virCgroupAddTaskController: * @@ -1142,7 +1182,8 @@ cleanup: * * Returns: 0 on success or -1 on error */ -int virCgroupAddTaskController(virCgroupPtr group, pid_t pid, int controller) +int +virCgroupAddTaskController(virCgroupPtr group, pid_t pid, int controller) { if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1162,9 +1203,10 @@ int virCgroupAddTaskController(virCgroupPtr group, pid_t pid, int controller) } -static int virCgroupAddTaskStrController(virCgroupPtr group, - const char *pidstr, - int controller) +static int +virCgroupAddTaskStrController(virCgroupPtr group, + const char *pidstr, + int controller) { char *str = NULL, *cur = NULL, *next = NULL; unsigned long long p = 0; @@ -1205,6 +1247,7 @@ cleanup: return rc; } + /** * virCgroupMoveTask: * @@ -1214,7 +1257,8 @@ cleanup: * * Returns: 0 on success or -1 on failure */ -int virCgroupMoveTask(virCgroupPtr src_group, virCgroupPtr dest_group) +int +virCgroupMoveTask(virCgroupPtr src_group, virCgroupPtr dest_group) { int ret = -1; char *content = NULL; @@ -1254,7 +1298,8 @@ cleanup: #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -static int virCgroupPartitionNeedsEscaping(const char *path) +static int +virCgroupPartitionNeedsEscaping(const char *path) { FILE *fp = NULL; int ret = 0; @@ -1323,7 +1368,9 @@ cleanup: return ret; } -static int virCgroupPartitionEscape(char **path) + +static int +virCgroupPartitionEscape(char **path) { size_t len = strlen(*path) + 1; int rc; @@ -1338,7 +1385,9 @@ static int virCgroupPartitionEscape(char **path) return 0; } -static int virCgroupSetPartitionSuffix(const char *path, char **res) + +static int +virCgroupSetPartitionSuffix(const char *path, char **res) { char **tokens; size_t i; @@ -1382,6 +1431,7 @@ cleanup: return ret; } + /** * virCgroupNewPartition: * @path: path for the partition @@ -1393,10 +1443,11 @@ cleanup: * * Returns 0 on success, -1 on failure */ -int virCgroupNewPartition(const char *path, - bool create, - int controllers, - virCgroupPtr *group) +int +virCgroupNewPartition(const char *path, + bool create, + int controllers, + virCgroupPtr *group) { int ret = -1; char *parentPath = NULL; @@ -1446,10 +1497,11 @@ cleanup: return ret; } #else -int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) +int +virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1468,7 +1520,8 @@ int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, * * Returns 0 on success, or -1 on error */ -int virCgroupNewSelf(virCgroupPtr *group) +int +virCgroupNewSelf(virCgroupPtr *group) { return virCgroupNewDetect(-1, -1, group); } @@ -1485,11 +1538,12 @@ int virCgroupNewSelf(virCgroupPtr *group) * Returns 0 on success, or -1 on error */ #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -int virCgroupNewDomainPartition(virCgroupPtr partition, - const char *driver, - const char *name, - bool create, - virCgroupPtr *group) +int +virCgroupNewDomainPartition(virCgroupPtr partition, + const char *driver, + const char *name, + bool create, + virCgroupPtr *group) { int ret = -1; char *grpname = NULL; @@ -1514,7 +1568,8 @@ int virCgroupNewDomainPartition(virCgroupPtr partition, * a group for driver, is to avoid overhead to track * cumulative usage that we don't need. */ - if (virCgroupMakeGroup(partition, *group, create, VIR_CGROUP_MEM_HIERACHY) < 0) { + if (virCgroupMakeGroup(partition, *group, create, + VIR_CGROUP_MEM_HIERACHY) < 0) { virCgroupRemove(*group); virCgroupFree(group); goto cleanup; @@ -1527,11 +1582,12 @@ cleanup: return ret; } #else -int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, - const char *driver ATTRIBUTE_UNUSED, - const char *name ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) +int +virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, + const char *driver ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1539,6 +1595,7 @@ int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, } #endif + /** * virCgroupNewVcpu: * @@ -1550,10 +1607,11 @@ int virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, * Returns 0 on success, or -1 on error */ #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -int virCgroupNewVcpu(virCgroupPtr domain, - int vcpuid, - bool create, - virCgroupPtr *group) +int +virCgroupNewVcpu(virCgroupPtr domain, + int vcpuid, + bool create, + virCgroupPtr *group) { int ret = -1; char *name = NULL; @@ -1581,10 +1639,11 @@ cleanup: return ret; } #else -int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, - int vcpuid ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) +int +virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, + int vcpuid ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1592,6 +1651,7 @@ int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, } #endif + /** * virCgroupNewEmulator: * @@ -1602,9 +1662,10 @@ int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, * Returns: 0 on success or -1 on error */ #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -int virCgroupNewEmulator(virCgroupPtr domain, - bool create, - virCgroupPtr *group) +int +virCgroupNewEmulator(virCgroupPtr domain, + bool create, + virCgroupPtr *group) { int ret = -1; int controllers; @@ -1627,9 +1688,10 @@ cleanup: return ret; } #else -int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) +int +virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1640,16 +1702,18 @@ int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R -int virCgroupNewDetect(pid_t pid, - int controllers, - virCgroupPtr *group) +int +virCgroupNewDetect(pid_t pid, + int controllers, + virCgroupPtr *group) { return virCgroupNew(pid, "", NULL, controllers, group); } #else -int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) +int +virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform")); @@ -1657,15 +1721,17 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, } #endif + /* * Returns 0 on success (but @group may be NULL), -1 on fatal error */ -int virCgroupNewDetectMachine(const char *name, - const char *drivername, - pid_t pid, - const char *partition, - int controllers, - virCgroupPtr *group) +int +virCgroupNewDetectMachine(const char *name, + const char *drivername, + pid_t pid, + const char *partition, + int controllers, + virCgroupPtr *group) { if (virCgroupNewDetect(pid, controllers, group) < 0) { if (virCgroupNewIgnoreError()) @@ -1673,7 +1739,8 @@ int virCgroupNewDetectMachine(const char *name, return -1; } - if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, true)) { + if (!virCgroupValidateMachineGroup(*group, name, drivername, partition, + true)) { VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", name, drivername); virCgroupFree(group); @@ -1683,6 +1750,7 @@ int virCgroupNewDetectMachine(const char *name, return 0; } + /* * Returns 0 on success, -1 on fatal error, -2 on systemd not available */ @@ -1789,6 +1857,7 @@ virCgroupNewMachineSystemd(const char *name, return ret; } + static int virCgroupNewMachineManual(const char *name, const char *drivername, @@ -1836,16 +1905,18 @@ cleanup: return ret; } -int virCgroupNewMachine(const char *name, - const char *drivername, - bool privileged, - const unsigned char *uuid, - const char *rootdir, - pid_t pidleader, - bool isContainer, - const char *partition, - int controllers, - virCgroupPtr *group) + +int +virCgroupNewMachine(const char *name, + const char *drivername, + bool privileged, + const unsigned char *uuid, + const char *rootdir, + pid_t pidleader, + bool isContainer, + const char *partition, + int controllers, + virCgroupPtr *group) { int rv; @@ -1874,7 +1945,9 @@ int virCgroupNewMachine(const char *name, group); } -bool virCgroupNewIgnoreError(void) + +bool +virCgroupNewIgnoreError(void) { if (virLastErrorIsSystemErrno(ENXIO) || virLastErrorIsSystemErrno(EPERM) || @@ -1886,6 +1959,7 @@ bool virCgroupNewIgnoreError(void) return false; } + /** * virCgroupSetBlkioWeight: * @@ -1894,7 +1968,8 @@ bool virCgroupNewIgnoreError(void) * * Returns: 0 on success, -1 on error */ -int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) +int +virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) { if (weight > 1000 || weight < 100) { virReportError(VIR_ERR_INVALID_ARG, @@ -1909,6 +1984,7 @@ int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) weight); } + /** * virCgroupGetBlkioWeight: * @@ -1917,7 +1993,8 @@ int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) * * Returns: 0 on success, -1 on error */ -int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) +int +virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) { unsigned long long tmp; int ret; @@ -1929,6 +2006,7 @@ int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) return ret; } + /** * virCgroupSetBlkioDeviceWeight: * @@ -1942,9 +2020,10 @@ int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) * Returns: 0 on success, -1 on error */ #if defined(major) && defined(minor) -int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, - const char *path, - unsigned int weight) +int +virCgroupSetBlkioDeviceWeight(virCgroupPtr group, + const char *path, + unsigned int weight) { char *str; struct stat sb; @@ -1994,6 +2073,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, } #endif + /** * virCgroupSetMemory: * @@ -2002,7 +2082,8 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, * * Returns: 0 on success */ -int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) +int +virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) { unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; @@ -2025,6 +2106,7 @@ int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) kb << 10); } + /** * virCgroupGetMemoryUsage: * @@ -2033,7 +2115,8 @@ int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) * * Returns: 0 on success */ -int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) +int +virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) { long long unsigned int usage_in_bytes; int ret; @@ -2045,6 +2128,7 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) return ret; } + /** * virCgroupSetMemoryHardLimit: * @@ -2053,11 +2137,13 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) * * Returns: 0 on success */ -int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) +int +virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { return virCgroupSetMemory(group, kb); } + /** * virCgroupGetMemoryHardLimit: * @@ -2066,7 +2152,8 @@ int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) * * Returns: 0 on success */ -int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) +int +virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) { long long unsigned int limit_in_bytes; int ret; @@ -2078,6 +2165,7 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetMemorySoftLimit: * @@ -2086,7 +2174,8 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) +int +virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; @@ -2118,7 +2207,8 @@ int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) * * Returns: 0 on success */ -int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) +int +virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) { long long unsigned int limit_in_bytes; int ret; @@ -2130,6 +2220,7 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetMemSwapHardLimit: * @@ -2138,7 +2229,8 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) +int +virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; @@ -2161,6 +2253,7 @@ int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) kb << 10); } + /** * virCgroupGetMemSwapHardLimit: * @@ -2169,7 +2262,8 @@ int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) * * Returns: 0 on success */ -int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) +int +virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) { long long unsigned int limit_in_bytes; int ret; @@ -2181,6 +2275,7 @@ int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupGetMemSwapUsage: * @@ -2189,7 +2284,8 @@ int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) +int +virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) { long long unsigned int usage_in_bytes; int ret; @@ -2201,6 +2297,7 @@ int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) return ret; } + /** * virCgroupSetCpusetMems: * @@ -2209,7 +2306,8 @@ int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) +int +virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) { return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -2217,6 +2315,7 @@ int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) mems); } + /** * virCgroupGetCpusetMems: * @@ -2225,7 +2324,8 @@ int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) * * Returns: 0 on success */ -int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) +int +virCgroupGetCpusetMems(virCgroupPtr group, char **mems) { return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -2233,6 +2333,7 @@ int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) mems); } + /** * virCgroupSetCpusetCpus: * @@ -2241,7 +2342,8 @@ int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) * * Retuens: 0 on success */ -int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) +int +virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -2249,6 +2351,7 @@ int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) cpus); } + /** * virCgroupGetCpusetCpus: * @@ -2257,7 +2360,8 @@ int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) * * Retuens: 0 on success */ -int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) +int +virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) { return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -2265,6 +2369,7 @@ int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) cpus); } + /** * virCgroupDenyAllDevices: * @@ -2272,7 +2377,8 @@ int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) * * Returns: 0 on success */ -int virCgroupDenyAllDevices(virCgroupPtr group) +int +virCgroupDenyAllDevices(virCgroupPtr group) { return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, @@ -2280,6 +2386,7 @@ int virCgroupDenyAllDevices(virCgroupPtr group) "a"); } + /** * virCgroupAllowDevice: * @@ -2291,8 +2398,9 @@ int virCgroupDenyAllDevices(virCgroupPtr group) * * Returns: 0 on success */ -int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, - int perms) +int +virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, + int perms) { int ret = -1; char *devstr = NULL; @@ -2316,6 +2424,7 @@ cleanup: return ret; } + /** * virCgroupAllowDeviceMajor: * @@ -2326,8 +2435,9 @@ cleanup: * * Returns: 0 on success */ -int virCgroupAllowDeviceMajor(virCgroupPtr group, char type, int major, - int perms) +int +virCgroupAllowDeviceMajor(virCgroupPtr group, char type, int major, + int perms) { int ret = -1; char *devstr = NULL; @@ -2351,6 +2461,7 @@ cleanup: return ret; } + /** * virCgroupAllowDevicePath: * @@ -2365,7 +2476,8 @@ cleanup: * -1 on error */ #if defined(major) && defined(minor) -int virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) +int +virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) { struct stat sb; @@ -2386,9 +2498,10 @@ int virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) perms); } #else -int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) +int +virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -2408,8 +2521,9 @@ int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, * * Returns: 0 on success */ -int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, - int perms) +int +virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, + int perms) { int ret = -1; char *devstr = NULL; @@ -2433,6 +2547,7 @@ cleanup: return ret; } + /** * virCgroupDenyDeviceMajor: * @@ -2443,8 +2558,9 @@ cleanup: * * Returns: 0 on success */ -int virCgroupDenyDeviceMajor(virCgroupPtr group, char type, int major, - int perms) +int +virCgroupDenyDeviceMajor(virCgroupPtr group, char type, int major, + int perms) { int ret = -1; char *devstr = NULL; @@ -2468,8 +2584,10 @@ cleanup: return ret; } + #if defined(major) && defined(minor) -int virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) +int +virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) { struct stat sb; @@ -2490,9 +2608,10 @@ int virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) perms); } #else -int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) +int +virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -2500,20 +2619,25 @@ int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, } #endif -int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) + +int +virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { return virCgroupSetValueU64(group, VIR_CGROUP_CONTROLLER_CPU, "cpu.shares", shares); } -int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) + +int +virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) { return virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_CPU, "cpu.shares", shares); } + /** * virCgroupSetCpuCfsPeriod: * @@ -2522,7 +2646,8 @@ int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) * * Returns: 0 on success */ -int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) +int +virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { /* The cfs_period shoule be greater or equal than 1ms, and less or equal * than 1s. @@ -2539,6 +2664,7 @@ int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) "cpu.cfs_period_us", cfs_period); } + /** * virCgroupGetCpuCfsPeriod: * @@ -2547,13 +2673,15 @@ int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) * * Returns: 0 on success */ -int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) +int +virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) { return virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_CPU, "cpu.cfs_period_us", cfs_period); } + /** * virCgroupSetCpuCfsQuota: * @@ -2563,7 +2691,8 @@ int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) * * Returns: 0 on success */ -int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) +int +virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { /* The cfs_quota should be greater or equal than 1ms */ if (cfs_quota >= 0 && @@ -2580,6 +2709,7 @@ int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) "cpu.cfs_quota_us", cfs_quota); } + /** * virCgroupGetCpuCfsQuota: * @@ -2589,29 +2719,36 @@ int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) * * Returns: 0 on success */ -int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) +int +virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { return virCgroupGetValueI64(group, VIR_CGROUP_CONTROLLER_CPU, "cpu.cfs_quota_us", cfs_quota); } -int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) + +int +virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) { return virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_CPUACCT, "cpuacct.usage", usage); } -int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) + +int +virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) { return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, "cpuacct.usage_percpu", usage); } + #ifdef _SC_CLK_TCK -int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, - unsigned long long *sys) +int +virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, + unsigned long long *sys) { char *str; char *p; @@ -2657,9 +2794,10 @@ cleanup: return ret; } #else -int virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, - unsigned long long *user ATTRIBUTE_UNUSED, - unsigned long long *sys ATTRIBUTE_UNUSED) +int +virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *user ATTRIBUTE_UNUSED, + unsigned long long *sys ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -2667,14 +2805,18 @@ int virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, } #endif -int virCgroupSetFreezerState(virCgroupPtr group, const char *state) + +int +virCgroupSetFreezerState(virCgroupPtr group, const char *state) { return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_FREEZER, "freezer.state", state); } -int virCgroupGetFreezerState(virCgroupPtr group, char **state) + +int +virCgroupGetFreezerState(virCgroupPtr group, char **state) { return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_FREEZER, @@ -2686,7 +2828,8 @@ int virCgroupGetFreezerState(virCgroupPtr group, char **state) /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ -static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr pids) +static int +virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr pids) { int ret = -1; bool killedAny = false; @@ -2761,24 +2904,33 @@ cleanup: } -static uint32_t virCgroupPidCode(const void *name, uint32_t seed) +static uint32_t +virCgroupPidCode(const void *name, uint32_t seed) { unsigned long pid_value = (unsigned long)(intptr_t)name; return virHashCodeGen(&pid_value, sizeof(pid_value), seed); } -static bool virCgroupPidEqual(const void *namea, const void *nameb) + + +static bool +virCgroupPidEqual(const void *namea, const void *nameb) { return namea == nameb; } -static void *virCgroupPidCopy(const void *name) + + +static void * +virCgroupPidCopy(const void *name) { return (void*)name; } + /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ -int virCgroupKill(virCgroupPtr group, int signum) +int +virCgroupKill(virCgroupPtr group, int signum) { VIR_DEBUG("group=%p path=%s signum=%d", group, group->path, signum); int ret; @@ -2801,7 +2953,11 @@ int virCgroupKill(virCgroupPtr group, int signum) } -static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHashTablePtr pids, bool dormdir) +static int +virCgroupKillRecursiveInternal(virCgroupPtr group, + int signum, + virHashTablePtr pids, + bool dormdir) { int ret = -1; int rc; @@ -2810,7 +2966,8 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas DIR *dp; virCgroupPtr subgroup = NULL; struct dirent *ent; - VIR_DEBUG("group=%p path=%s signum=%d pids=%p", group, group->path, signum, pids); + VIR_DEBUG("group=%p path=%s signum=%d pids=%p", + group, group->path, signum, pids); if (virCgroupPathOfController(group, -1, "", &keypath) < 0) return -1; @@ -2845,7 +3002,8 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas if (virCgroupNew(-1, ent->d_name, group, -1, &subgroup) < 0) goto cleanup; - if ((rc = virCgroupKillRecursiveInternal(subgroup, signum, pids, true)) < 0) + if ((rc = virCgroupKillRecursiveInternal(subgroup, signum, pids, + true)) < 0) goto cleanup; if (rc == 1) killedAny = true; @@ -2866,7 +3024,9 @@ cleanup: return ret; } -int virCgroupKillRecursive(virCgroupPtr group, int signum) + +int +virCgroupKillRecursive(virCgroupPtr group, int signum) { int ret; VIR_DEBUG("group=%p path=%s signum=%d", group, group->path, signum); @@ -2885,7 +3045,8 @@ int virCgroupKillRecursive(virCgroupPtr group, int signum) } -int virCgroupKillPainfully(virCgroupPtr group) +int +virCgroupKillPainfully(virCgroupPtr group) { size_t i; int ret; @@ -2912,22 +3073,28 @@ int virCgroupKillPainfully(virCgroupPtr group) } #else /* !(HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R) */ -int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED, - int signum ATTRIBUTE_UNUSED) +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) + + +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) + +int +virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); @@ -2935,8 +3102,10 @@ int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) } #endif /* HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R */ + #ifdef __linux__ -static char *virCgroupIdentifyRoot(virCgroupPtr group) +static char * +virCgroupIdentifyRoot(virCgroupPtr group) { char *ret = NULL; size_t i; @@ -2964,8 +3133,9 @@ static char *virCgroupIdentifyRoot(virCgroupPtr group) } -int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, - const char *mountopts) +int +virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, + const char *mountopts) { int ret = -1; size_t i; @@ -3007,7 +3177,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, group->controllers[i].placement) < 0) goto cleanup; - VIR_DEBUG("Create mount point '%s'", group->controllers[i].mountPoint); + VIR_DEBUG("Create mount point '%s'", + group->controllers[i].mountPoint); if (virFileMakePath(group->controllers[i].mountPoint) < 0) { virReportSystemError(errno, _("Unable to create directory %s"), @@ -3016,7 +3187,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, goto cleanup; } - if (mount(src, group->controllers[i].mountPoint, NULL, MS_BIND, NULL) < 0) { + if (mount(src, group->controllers[i].mountPoint, NULL, MS_BIND, + NULL) < 0) { virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"), src, group->controllers[i].mountPoint); @@ -3049,9 +3221,10 @@ cleanup: return ret; } #else /* __linux__ */ -int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *oldroot ATTRIBUTE_UNUSED, - const char *mountopts ATTRIBUTE_UNUSED) +int +virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *oldroot ATTRIBUTE_UNUSED, + const char *mountopts ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Control groups not supported on this platform")); -- 1.8.3.1

Avoid a forward declaration of a static function. * src/util/vircgroup.c (virCgroupPartitionNeedsEscaping) (virCgroupParticionEscape): Move up. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 176 +++++++++++++++++++++++++-------------------------- 1 file changed, 87 insertions(+), 89 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0925078..dc3b036 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -97,9 +97,95 @@ virCgroupAvailable(void) return ret; } + #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R +static int +virCgroupPartitionNeedsEscaping(const char *path) +{ + FILE *fp = NULL; + int ret = 0; + char *line = NULL; + size_t buflen; + + /* If it starts with 'cgroup.' or a '_' of any + * of the controller names from /proc/cgroups, + * then we must prefix a '_' + */ + if (STRPREFIX(path, "cgroup.")) + return 1; + + if (path[0] == '_' || + path[0] == '.') + return 1; + + if (!(fp = fopen("/proc/cgroups", "r"))) { + /* The API contract is that we return ENXIO + * if cgroups are not available on a host */ + if (errno == ENOENT) + errno = ENXIO; + virReportSystemError(errno, "%s", + _("Cannot open /proc/cgroups")); + return -1; + } + + /* + * Data looks like this: + * #subsys_name hierarchy num_cgroups enabled + * cpuset 2 4 1 + * cpu 3 48 1 + * cpuacct 3 48 1 + * memory 4 4 1 + * devices 5 4 1 + * freezer 6 4 1 + * net_cls 7 1 1 + */ + while (getline(&line, &buflen, fp) > 0) { + char *tmp; + size_t len; + + if (STRPREFIX(line, "#subsys_name")) + continue; + + tmp = strchrnul(line, ' '); + *tmp = '\0'; + len = tmp - line; + + if (STRPREFIX(path, line) && + path[len] == '.') { + ret = 1; + goto cleanup; + } + } + + if (ferror(fp)) { + virReportSystemError(errno, "%s", + _("Error while reading /proc/cgroups")); + goto cleanup; + } + +cleanup: + VIR_FREE(line); + VIR_FORCE_FCLOSE(fp); + return ret; +} + + +static int +virCgroupPartitionEscape(char **path) +{ + size_t len = strlen(*path) + 1; + int rc; + char escape = '_'; + + if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0) + return rc; + + if (VIR_INSERT_ELEMENT(*path, 0, len, escape) < 0) + return -1; + + return 0; +} -static int virCgroupPartitionEscape(char **path); static bool virCgroupValidateMachineGroup(virCgroupPtr group, @@ -1299,94 +1385,6 @@ cleanup: #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int -virCgroupPartitionNeedsEscaping(const char *path) -{ - FILE *fp = NULL; - int ret = 0; - char *line = NULL; - size_t buflen; - - /* If it starts with 'cgroup.' or a '_' of any - * of the controller names from /proc/cgroups, - * then we must prefix a '_' - */ - if (STRPREFIX(path, "cgroup.")) - return 1; - - if (path[0] == '_' || - path[0] == '.') - return 1; - - if (!(fp = fopen("/proc/cgroups", "r"))) { - /* The API contract is that we return ENXIO - * if cgroups are not available on a host */ - if (errno == ENOENT) - errno = ENXIO; - virReportSystemError(errno, "%s", - _("Cannot open /proc/cgroups")); - return -1; - } - - /* - * Data looks like this: - * #subsys_name hierarchy num_cgroups enabled - * cpuset 2 4 1 - * cpu 3 48 1 - * cpuacct 3 48 1 - * memory 4 4 1 - * devices 5 4 1 - * freezer 6 4 1 - * net_cls 7 1 1 - */ - while (getline(&line, &buflen, fp) > 0) { - char *tmp; - size_t len; - - if (STRPREFIX(line, "#subsys_name")) - continue; - - tmp = strchrnul(line, ' '); - *tmp = '\0'; - len = tmp - line; - - if (STRPREFIX(path, line) && - path[len] == '.') { - ret = 1; - goto cleanup; - } - } - - if (ferror(fp)) { - virReportSystemError(errno, "%s", - _("Error while reading /proc/cgroups")); - goto cleanup; - } - -cleanup: - VIR_FREE(line); - VIR_FORCE_FCLOSE(fp); - return ret; -} - - -static int -virCgroupPartitionEscape(char **path) -{ - size_t len = strlen(*path) + 1; - int rc; - char escape = '_'; - - if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0) - return rc; - - if (VIR_INSERT_ELEMENT(*path, 0, len, escape) < 0) - return -1; - - return 0; -} - - -static int virCgroupSetPartitionSuffix(const char *path, char **res) { char **tokens; -- 1.8.3.1

Make future patches smaller by matching a sane header listing in the first place. No semantic change. * src/util/vircgroup.h: Move free next to new, and controller functions next to each other. * src/util/vircgroup.c (virCgroupFree, virCgroupHasController) (virCgroupPathOfController, virCgroupRemoveRecursively) (virCgroupRemove): Sort implementation to be closer to header. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 409 ++++++++++++++++++++++++++------------------------- src/util/vircgroup.h | 6 +- 2 files changed, 209 insertions(+), 206 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dc3b036..c392ffe 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -271,48 +271,6 @@ virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, #endif -/** - * virCgroupFree: - * - * @group: The group structure to free - */ -void -virCgroupFree(virCgroupPtr *group) -{ - size_t i; - - if (*group == NULL) - return; - - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_FREE((*group)->controllers[i].mountPoint); - VIR_FREE((*group)->controllers[i].linkPoint); - VIR_FREE((*group)->controllers[i].placement); - } - - VIR_FREE((*group)->path); - VIR_FREE(*group); -} - - -/** - * virCgroupHasController: query whether a cgroup controller is present - * - * @cgroup: The group structure to be queried, or NULL - * @controller: cgroup subsystem id - * - * Returns true if a cgroup controller is mounted and is associated - * with this cgroup object. - */ -bool -virCgroupHasController(virCgroupPtr cgroup, int controller) -{ - if (!cgroup) - return false; - if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) - return false; - return cgroup->controllers[controller].mountPoint != NULL; -} #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int @@ -704,57 +662,6 @@ virCgroupDetect(virCgroupPtr group, #endif -int -virCgroupPathOfController(virCgroupPtr group, - int controller, - const char *key, - char **path) -{ - if (controller == -1) { - size_t i; - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - /* Reject any controller with a placement - * of '/' to avoid doing bad stuff to the root - * cgroup - */ - if (group->controllers[i].mountPoint && - group->controllers[i].placement && - STRNEQ(group->controllers[i].placement, "/")) { - controller = i; - break; - } - } - } - if (controller == -1) { - virReportSystemError(ENOSYS, "%s", - _("No controllers are mounted")); - return -1; - } - - if (group->controllers[controller].mountPoint == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not mounted"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (group->controllers[controller].placement == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not enabled for group"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (virAsprintf(path, "%s%s/%s", - group->controllers[controller].mountPoint, - group->controllers[controller].placement, - key ? key : "") < 0) - return -1; - - return 0; -} - - static int virCgroupSetValueStr(virCgroupPtr group, int controller, @@ -1115,116 +1022,6 @@ error: } #endif -#if defined _DIRENT_HAVE_D_TYPE -int -virCgroupRemoveRecursively(char *grppath) -{ - DIR *grpdir; - struct dirent *ent; - int rc = 0; - - grpdir = opendir(grppath); - if (grpdir == NULL) { - if (errno == ENOENT) - return 0; - rc = -errno; - VIR_ERROR(_("Unable to open %s (%d)"), grppath, errno); - return rc; - } - - for (;;) { - char *path; - - errno = 0; - ent = readdir(grpdir); - if (ent == NULL) { - if ((rc = -errno)) - VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno); - break; - } - - if (ent->d_name[0] == '.') continue; - if (ent->d_type != DT_DIR) continue; - - if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) { - rc = -ENOMEM; - break; - } - rc = virCgroupRemoveRecursively(path); - VIR_FREE(path); - if (rc != 0) - break; - } - closedir(grpdir); - - VIR_DEBUG("Removing cgroup %s", grppath); - if (rmdir(grppath) != 0 && errno != ENOENT) { - rc = -errno; - VIR_ERROR(_("Unable to remove %s (%d)"), grppath, errno); - } - - return rc; -} -#else -int -virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif - - -/** - * virCgroupRemove: - * - * @group: The group to be removed - * - * It first removes all child groups recursively - * in depth first order and then removes @group - * because the presence of the child groups - * prevents removing @group. - * - * Returns: 0 on success - */ -int -virCgroupRemove(virCgroupPtr group) -{ - int rc = 0; - size_t i; - char *grppath = NULL; - - VIR_DEBUG("Removing cgroup %s", group->path); - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) - continue; - - /* We must never rmdir() in systemd's hierarchy */ - if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - /* Don't delete the root group, if we accidentally - ended up in it for some reason */ - if (STREQ(group->controllers[i].placement, "/")) - continue; - - if (virCgroupPathOfController(group, - i, - NULL, - &grppath) != 0) - continue; - - VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); - rc = virCgroupRemoveRecursively(grppath); - VIR_FREE(grppath); - } - VIR_DEBUG("Done removing cgroup %s", group->path); - - return rc; -} - /** * virCgroupAddTask: @@ -1959,6 +1756,101 @@ virCgroupNewIgnoreError(void) /** + * virCgroupFree: + * + * @group: The group structure to free + */ +void +virCgroupFree(virCgroupPtr *group) +{ + size_t i; + + if (*group == NULL) + return; + + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_FREE((*group)->controllers[i].mountPoint); + VIR_FREE((*group)->controllers[i].linkPoint); + VIR_FREE((*group)->controllers[i].placement); + } + + VIR_FREE((*group)->path); + VIR_FREE(*group); +} + + +/** + * virCgroupHasController: query whether a cgroup controller is present + * + * @cgroup: The group structure to be queried, or NULL + * @controller: cgroup subsystem id + * + * Returns true if a cgroup controller is mounted and is associated + * with this cgroup object. + */ +bool +virCgroupHasController(virCgroupPtr cgroup, int controller) +{ + if (!cgroup) + return false; + if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST) + return false; + return cgroup->controllers[controller].mountPoint != NULL; +} + + +int +virCgroupPathOfController(virCgroupPtr group, + int controller, + const char *key, + char **path) +{ + if (controller == -1) { + size_t i; + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + /* Reject any controller with a placement + * of '/' to avoid doing bad stuff to the root + * cgroup + */ + if (group->controllers[i].mountPoint && + group->controllers[i].placement && + STRNEQ(group->controllers[i].placement, "/")) { + controller = i; + break; + } + } + } + if (controller == -1) { + virReportSystemError(ENOSYS, "%s", + _("No controllers are mounted")); + return -1; + } + + if (group->controllers[controller].mountPoint == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Controller '%s' is not mounted"), + virCgroupControllerTypeToString(controller)); + return -1; + } + + if (group->controllers[controller].placement == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Controller '%s' is not enabled for group"), + virCgroupControllerTypeToString(controller)); + return -1; + } + + if (virAsprintf(path, "%s%s/%s", + group->controllers[controller].mountPoint, + group->controllers[controller].placement, + key ? key : "") < 0) + return -1; + + return 0; +} + + +/** * virCgroupSetBlkioWeight: * * @group: The cgroup to change io weight for @@ -2822,6 +2714,117 @@ virCgroupGetFreezerState(virCgroupPtr group, char **state) } +#if defined _DIRENT_HAVE_D_TYPE +int +virCgroupRemoveRecursively(char *grppath) +{ + DIR *grpdir; + struct dirent *ent; + int rc = 0; + + grpdir = opendir(grppath); + if (grpdir == NULL) { + if (errno == ENOENT) + return 0; + rc = -errno; + VIR_ERROR(_("Unable to open %s (%d)"), grppath, errno); + return rc; + } + + for (;;) { + char *path; + + errno = 0; + ent = readdir(grpdir); + if (ent == NULL) { + if ((rc = -errno)) + VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno); + break; + } + + if (ent->d_name[0] == '.') continue; + if (ent->d_type != DT_DIR) continue; + + if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) { + rc = -ENOMEM; + break; + } + rc = virCgroupRemoveRecursively(path); + VIR_FREE(path); + if (rc != 0) + break; + } + closedir(grpdir); + + VIR_DEBUG("Removing cgroup %s", grppath); + if (rmdir(grppath) != 0 && errno != ENOENT) { + rc = -errno; + VIR_ERROR(_("Unable to remove %s (%d)"), grppath, errno); + } + + return rc; +} +#else +int +virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} +#endif + + +/** + * virCgroupRemove: + * + * @group: The group to be removed + * + * It first removes all child groups recursively + * in depth first order and then removes @group + * because the presence of the child groups + * prevents removing @group. + * + * Returns: 0 on success + */ +int +virCgroupRemove(virCgroupPtr group) +{ + int rc = 0; + size_t i; + char *grppath = NULL; + + VIR_DEBUG("Removing cgroup %s", group->path); + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + /* Skip over controllers not mounted */ + if (!group->controllers[i].mountPoint) + continue; + + /* We must never rmdir() in systemd's hierarchy */ + if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + /* Don't delete the root group, if we accidentally + ended up in it for some reason */ + if (STREQ(group->controllers[i].placement, "/")) + continue; + + if (virCgroupPathOfController(group, + i, + NULL, + &grppath) != 0) + continue; + + VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); + rc = virCgroupRemoveRecursively(grppath); + VIR_FREE(grppath); + } + VIR_DEBUG("Done removing cgroup %s", group->path); + + return rc; +} + + #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 diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index d7ce892..7bb4b2a 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -102,6 +102,9 @@ int virCgroupNewMachine(const char *name, bool virCgroupNewIgnoreError(void); +void virCgroupFree(virCgroupPtr *group); + +bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, int controller, const char *key, @@ -196,9 +199,6 @@ int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus); int virCgroupRemoveRecursively(char *grppath); int virCgroupRemove(virCgroupPtr group); -void virCgroupFree(virCgroupPtr *group); -bool virCgroupHasController(virCgroupPtr cgroup, int controller); - int virCgroupKill(virCgroupPtr group, int signum); int virCgroupKillRecursive(virCgroupPtr group, int signum); int virCgroupKillPainfully(virCgroupPtr group); -- 1.8.3.1

From: Roman Bogorodskiy <bogorodskiy@gmail.com> - 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> --- src/util/vircgroup.c | 95 ++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index c392ffe..cb388a1 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -56,6 +56,11 @@ #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, "cpu", "cpuacct", "cpuset", "memory", "devices", "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 virCgroupRemoveRecursively(char *grppath) { @@ -2764,15 +2770,6 @@ virCgroupRemoveRecursively(char *grppath) 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 */ @@ -3073,38 +3069,7 @@ virCgroupKillPainfully(virCgroupPtr group) 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 * virCgroupIdentifyRoot(virCgroupPtr group) { @@ -3221,7 +3186,48 @@ cleanup: VIR_FREE(opts); 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 virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, const char *oldroot ATTRIBUTE_UNUSED, @@ -3231,4 +3237,5 @@ virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, _("Control groups not supported on this platform")); return -1; } -#endif /* __linux__ */ + +#endif /* !VIR_CGROUP_SUPPORTED */ -- 1.8.3.1

From: Roman Bogorodskiy <bogorodskiy@gmail.com> - Convert virCgroupGet* to VIR_CGROUP_SUPPORTED - Convert virCgroup(Get|Set)FreezerState to VIR_CGROUP_SUPPORTED Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 263 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 156 insertions(+), 107 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cb388a1..64a6ceb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -57,7 +57,7 @@ #define VIR_FROM_THIS VIR_FROM_CGROUP #if defined(__linux__) && defined(HAVE_GETMNTENT_R) && \ - defined(_DIRENT_HAVE_D_TYPE) + defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK) # define VIR_CGROUP_SUPPORTED #endif @@ -2605,33 +2605,6 @@ virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) } -/** - * virCgroupGetCpuCfsQuota: - * - * @group: The cgroup to get cpu.cfs_quota_us for - * @cfs_quota: Pointer to the returned cpu bandwidth (in usecs) that this tg - * will be allowed to consume over period - * - * Returns: 0 on success - */ -int -virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) -{ - return virCgroupGetValueI64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_quota_us", cfs_quota); -} - - -int -virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) -{ - return virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage", usage); -} - - int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) { @@ -2640,85 +2613,6 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) } -#ifdef _SC_CLK_TCK -int -virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, - unsigned long long *sys) -{ - char *str; - char *p; - int ret = -1; - static double scale = -1.0; - - if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.stat", &str) < 0) - return -1; - - if (!(p = STRSKIP(str, "user ")) || - virStrToLong_ull(p, &p, 10, user) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse user stat '%s'"), - p); - goto cleanup; - } - if (!(p = STRSKIP(p, "\nsystem ")) || - virStrToLong_ull(p, NULL, 10, sys) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse sys stat '%s'"), - p); - goto cleanup; - } - /* times reported are in system ticks (generally 100 Hz), but that - * rate can theoretically vary between machines. Scale things - * into approximate nanoseconds. */ - if (scale < 0) { - long ticks_per_sec = sysconf(_SC_CLK_TCK); - if (ticks_per_sec == -1) { - virReportSystemError(errno, "%s", - _("Cannot determine system clock HZ")); - goto cleanup; - } - scale = 1000000000.0 / ticks_per_sec; - } - *user *= scale; - *sys *= scale; - - ret = 0; -cleanup: - VIR_FREE(str); - return ret; -} -#else -int -virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, - unsigned long long *user ATTRIBUTE_UNUSED, - unsigned long long *sys ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif - - -int -virCgroupSetFreezerState(virCgroupPtr group, const char *state) -{ - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); -} - - -int -virCgroupGetFreezerState(virCgroupPtr group, char **state) -{ - return virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); -} - - #ifdef VIR_CGROUP_SUPPORTED int @@ -3099,6 +2993,100 @@ virCgroupIdentifyRoot(virCgroupPtr group) } +/** + * virCgroupGetCpuCfsQuota: + * + * @group: The cgroup to get cpu.cfs_quota_us for + * @cfs_quota: Pointer to the returned cpu bandwidth (in usecs) that this tg + * will be allowed to consume over period + * + * Returns: 0 on success + */ +int +virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) +{ + return virCgroupGetValueI64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_quota_us", cfs_quota); +} + + +int +virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.usage", usage); +} + + +int +virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, + unsigned long long *sys) +{ + char *str; + char *p; + int ret = -1; + static double scale = -1.0; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.stat", &str) < 0) + return -1; + + if (!(p = STRSKIP(str, "user ")) || + virStrToLong_ull(p, &p, 10, user) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse user stat '%s'"), + p); + goto cleanup; + } + if (!(p = STRSKIP(p, "\nsystem ")) || + virStrToLong_ull(p, NULL, 10, sys) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse sys stat '%s'"), + p); + goto cleanup; + } + /* times reported are in system ticks (generally 100 Hz), but that + * rate can theoretically vary between machines. Scale things + * into approximate nanoseconds. */ + if (scale < 0) { + long ticks_per_sec = sysconf(_SC_CLK_TCK); + if (ticks_per_sec == -1) { + virReportSystemError(errno, "%s", + _("Cannot determine system clock HZ")); + goto cleanup; + } + scale = 1000000000.0 / ticks_per_sec; + } + *user *= scale; + *sys *= scale; + + ret = 0; +cleanup: + VIR_FREE(str); + return ret; +} + + +int +virCgroupSetFreezerState(virCgroupPtr group, const char *state) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + + +int +virCgroupGetFreezerState(virCgroupPtr group, char **state) +{ + return virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + + int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, const char *mountopts) @@ -3229,6 +3217,67 @@ virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED) int +virCgroupGetCpuCfsQuota(virCgroupPtr group ATTRIBUTE_UNUSED, + long long *cfs_quota ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpuacctUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *usage ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpuacctPercpuUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + char **usage ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpuacctStat(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *user ATTRIBUTE_UNUSED, + unsigned long long *sys ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetFreezerState(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *state ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetFreezerState(virCgroupPtr group ATTRIBUTE_UNUSED, + char **state ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED, const char *oldroot ATTRIBUTE_UNUSED, const char *mountopts ATTRIBUTE_UNUSED) -- 1.8.3.1

From: Roman Bogorodskiy <bogorodskiy@gmail.com> Continue converting to VIR_CGROUP_SUPPORTED Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 57 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 64a6ceb..233fabf 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -75,11 +75,11 @@ typedef enum { } virCgroupFlags; +#ifdef VIR_CGROUP_SUPPORTED bool virCgroupAvailable(void) { bool ret = false; -#ifdef HAVE_GETMNTENT_R FILE *mounts = NULL; struct mntent entry; char buf[CGROUP_MAX_VAL]; @@ -98,12 +98,10 @@ virCgroupAvailable(void) } VIR_FORCE_FCLOSE(mounts); -#endif return ret; } -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupPartitionNeedsEscaping(const char *path) { @@ -264,17 +262,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(scopename); return valid; } -#else -static bool -virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *name ATTRIBUTE_UNUSED, - const char *drivername ATTRIBUTE_UNUSED, - bool stripEmulatorSuffix ATTRIBUTE_UNUSED) -{ - return true; -} -#endif - +#endif /* VIR_CGROUP_SUPPORTED */ #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R @@ -1522,6 +1510,7 @@ virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, #endif +#ifdef VIR_CGROUP_SUPPORTED /* * Returns 0 on success (but @group may be NULL), -1 on fatal error */ @@ -1549,6 +1538,7 @@ virCgroupNewDetectMachine(const char *name, return 0; } +#endif /* VIR_CGROUP_SUPPORTED */ /* @@ -1760,6 +1750,7 @@ virCgroupNewIgnoreError(void) } +#ifdef VIR_CGROUP_SUPPORTED /** * virCgroupFree: * @@ -1802,6 +1793,7 @@ virCgroupHasController(virCgroupPtr cgroup, int controller) return false; return cgroup->controllers[controller].mountPoint != NULL; } +#endif /* VIR_CGROUP_SUPPORTED */ int @@ -3178,6 +3170,43 @@ cleanup: #else /* !VIR_CGROUP_SUPPORTED */ +bool +virCgroupAvailable(void) +{ + return false; +} + + +int +virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED, + const char *partition ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +void +virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); +} + + +bool +virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED) +{ + return false; +} + + int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) { -- 1.8.3.1

From: Roman Bogorodskiy <bogorodskiy@gmail.com> Complete moving to VIR_CGROUP_SUPPORTED Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 226 ++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 112 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 233fabf..07a0f30 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -262,10 +262,8 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(scopename); return valid; } -#endif /* VIR_CGROUP_SUPPORTED */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupCopyMounts(virCgroupPtr group, virCgroupPtr parent) @@ -652,7 +650,6 @@ virCgroupDetect(virCgroupPtr group, return 0; } -#endif static int @@ -810,7 +807,6 @@ cleanup: } -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) { @@ -1013,7 +1009,6 @@ error: return -1; } -#endif /** @@ -1173,7 +1168,6 @@ cleanup: } -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static int virCgroupSetPartitionSuffix(const char *path, char **res) { @@ -1284,18 +1278,6 @@ cleanup: VIR_FREE(newpath); return ret; } -#else -int -virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -1325,7 +1307,6 @@ virCgroupNewSelf(virCgroupPtr *group) * * Returns 0 on success, or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewDomainPartition(virCgroupPtr partition, const char *driver, @@ -1369,19 +1350,6 @@ cleanup: VIR_FREE(grpname); return ret; } -#else -int -virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, - const char *driver ATTRIBUTE_UNUSED, - const char *name ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -1394,7 +1362,6 @@ virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, * * Returns 0 on success, or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewVcpu(virCgroupPtr domain, int vcpuid, @@ -1426,18 +1393,6 @@ cleanup: VIR_FREE(name); return ret; } -#else -int -virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, - int vcpuid ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -1449,7 +1404,6 @@ virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, * * Returns: 0 on success or -1 on error */ -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewEmulator(virCgroupPtr domain, bool create, @@ -1475,21 +1429,8 @@ virCgroupNewEmulator(virCgroupPtr domain, cleanup: return ret; } -#else -int -virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, - bool create ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} - -#endif -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R int virCgroupNewDetect(pid_t pid, int controllers, @@ -1497,20 +1438,8 @@ virCgroupNewDetect(pid_t pid, { return virCgroupNew(pid, "", NULL, controllers, group); } -#else -int -virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, - int controllers ATTRIBUTE_UNUSED, - virCgroupPtr *group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif -#ifdef VIR_CGROUP_SUPPORTED /* * Returns 0 on success (but @group may be NULL), -1 on fatal error */ @@ -1538,7 +1467,6 @@ virCgroupNewDetectMachine(const char *name, return 0; } -#endif /* VIR_CGROUP_SUPPORTED */ /* @@ -1750,7 +1678,6 @@ virCgroupNewIgnoreError(void) } -#ifdef VIR_CGROUP_SUPPORTED /** * virCgroupFree: * @@ -1793,7 +1720,6 @@ virCgroupHasController(virCgroupPtr cgroup, int controller) return false; return cgroup->controllers[controller].mountPoint != NULL; } -#endif /* VIR_CGROUP_SUPPORTED */ int @@ -1906,7 +1832,6 @@ virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) * * Returns: 0 on success, -1 on error */ -#if defined(major) && defined(minor) int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, @@ -1948,17 +1873,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, VIR_FREE(str); return ret; } -#else -int -virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - unsigned int weight ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif + /** @@ -2362,7 +2277,6 @@ cleanup: * Returns: 0 on success, 1 if path exists but is not a device, or * -1 on error */ -#if defined(major) && defined(minor) int virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) { @@ -2384,17 +2298,6 @@ virCgroupAllowDevicePath(virCgroupPtr group, const char *path, int perms) minor(sb.st_rdev), perms); } -#else -int -virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif /** @@ -2472,7 +2375,6 @@ cleanup: } -#if defined(major) && defined(minor) int virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) { @@ -2494,17 +2396,6 @@ virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms) minor(sb.st_rdev), perms); } -#else -int -virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - int perms ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Control groups not supported on this platform")); - return -1; -} -#endif int @@ -2605,8 +2496,6 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) } -#ifdef VIR_CGROUP_SUPPORTED - int virCgroupRemoveRecursively(char *grppath) { @@ -3178,6 +3067,74 @@ virCgroupAvailable(void) int +virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupNewSelf(virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED, + const char *driver ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED, + int vcpuid ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED, + bool create ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED, const char *drivername ATTRIBUTE_UNUSED, pid_t pid ATTRIBUTE_UNUSED, @@ -3208,6 +3165,51 @@ virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED, int +virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED, + const char *key ATTRIBUTE_UNUSED, + char **path ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + unsigned int weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", -- 1.8.3.1

From: Roman Bogorodskiy <bogorodskiy@gmail.com> Complete the refactoring by adding missing stubs so it compiles on platform without cgroup support. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 324 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 07a0f30..16458a3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3147,6 +3147,31 @@ virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED, return -1; } +int +virCgroupNewMachine(const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool privileged ATTRIBUTE_UNUSED, + const unsigned char *uuid ATTRIBUTE_UNUSED, + const char *rootdir ATTRIBUTE_UNUSED, + pid_t pidleader ATTRIBUTE_UNUSED, + bool isContainer ATTRIBUTE_UNUSED, + const char *partition ATTRIBUTE_UNUSED, + int controllers ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +bool +virCgroupNewIgnoreError(void) +{ + VIR_DEBUG("No cgroups present/configured/accessible, ignoring error"); + return true; +} + void virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) @@ -3177,6 +3202,57 @@ virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, int +virCgroupAddTask(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupAddTaskController(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED, + int controller ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupMoveTask(virCgroupPtr src_group ATTRIBUTE_UNUSED, + virCgroupPtr dest_group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetBlkioWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned int weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetBlkioWeight(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned int *weight ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, unsigned int weight ATTRIBUTE_UNUSED) @@ -3188,6 +3264,170 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED, int +virCgroupSetMemory(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetMemoryUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetMemoryHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetMemoryHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetMemorySoftLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetMemorySoftLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetMemSwapHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetMemSwapHardLimit(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetMemSwapUsage(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *kb ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetCpusetMems(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *mems ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpusetMems(virCgroupPtr group ATTRIBUTE_UNUSED, + char **mems ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetCpusetCpus(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *cpus ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpusetCpus(virCgroupPtr group ATTRIBUTE_UNUSED, + char **cpus ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupDenyAllDevices(virCgroupPtr group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupAllowDevice(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int minor ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupAllowDeviceMajor(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, int perms ATTRIBUTE_UNUSED) @@ -3199,6 +3439,31 @@ virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, int +virCgroupDenyDevice(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int minor ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupDenyDeviceMajor(virCgroupPtr group ATTRIBUTE_UNUSED, + char type ATTRIBUTE_UNUSED, + int major ATTRIBUTE_UNUSED, + int perms ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, int perms ATTRIBUTE_UNUSED) @@ -3210,6 +3475,56 @@ virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, int +virCgroupSetCpuShares(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long shares ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpuShares(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *shares ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetCpuCfsPeriod(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long cfs_period ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupGetCpuCfsPeriod(virCgroupPtr group ATTRIBUTE_UNUSED, + unsigned long long *cfs_period ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int +virCgroupSetCpuCfsQuota(virCgroupPtr group ATTRIBUTE_UNUSED, + long long cfs_quota ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", @@ -3219,6 +3534,15 @@ virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED) int +virCgroupRemove(virCgroupPtr group ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform")); + return -1; +} + + +int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED, int signum ATTRIBUTE_UNUSED) { -- 1.8.3.1
participants (2)
-
Eric Blake
-
Roman Bogorodskiy