Add cgroup_cgxset() to libcgroup.so. Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> --- include/libcgroup/tools.h | 13 +++++++++++++ src/Makefile.am | 2 +- src/libcgroup.map | 1 + src/tools/cgset.c | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/include/libcgroup/tools.h b/include/libcgroup/tools.h index cc0918c14fa7..ab23fdac86e8 100644 --- a/include/libcgroup/tools.h +++ b/include/libcgroup/tools.h @@ -50,6 +50,19 @@ extern "C" { int cgroup_cgxget(struct cgroup ** cg, enum cg_version_t version, bool ignore_unmappable); +/** + * Write the setting-value pairs in *cg to the cgroup sysfs. + * cgroup_cgxset() will perform the necessary conversions to match the + * "on-disk" format prior to writing to the cgroup sysfs. + * + * @param cg cgroup instance that will be written to the cgroup sysfs + * @param version Cgroup version of *cg + * @param ignore_unmappable Ignore failures due to settings that cannot be + * converted from one cgroup version to another + */ +int cgroup_cgxset(const struct cgroup * const cg, + enum cg_version_t version, bool ignore_unmappable); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/Makefile.am b/src/Makefile.am index d7716aa80b19..5227a0366072 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ libcgroup_la_SOURCES = parse.h parse.y lex.l api.c config.c \ abstraction-common.c abstraction-common.h \ abstraction-map.c abstraction-map.h \ abstraction-cpu.c abstraction-cpuset.c \ - tools/cgget.c + tools/cgget.c tools/cgset.c libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS) libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static -DLIBCG_LIB \ -fPIC diff --git a/src/libcgroup.map b/src/libcgroup.map index fb161daeecf2..3ce7e1b00c58 100644 --- a/src/libcgroup.map +++ b/src/libcgroup.map @@ -143,4 +143,5 @@ CGROUP_2.0 { CGROUP_3.0 { cgroup_convert_cgroup; cgroup_cgxget; + cgroup_cgxset; } CGROUP_2.0; diff --git a/src/tools/cgset.c b/src/tools/cgset.c index db4645c86c63..fff96a0474bb 100644 --- a/src/tools/cgset.c +++ b/src/tools/cgset.c @@ -338,3 +338,43 @@ err: free(name_value); return ret; } + +#ifdef LIBCG_LIB +int cgroup_cgxset(const struct cgroup * const cgroup, + enum cg_version_t version, bool ignore_unmappable) +{ + struct cgroup *converted_cgroup; + int ret; + + converted_cgroup = cgroup_new_cgroup(cgroup->name); + if (converted_cgroup == NULL) { + ret = ECGCONTROLLERCREATEFAILED; + goto err; + } + + ret = cgroup_convert_cgroup(converted_cgroup, CGROUP_DISK, + cgroup, version); + if (ret == ECGNOVERSIONCONVERT && ignore_unmappable) + /* The user has specified that we should ignore + * any errors due to being unable to map from v1 to + * v2 or vice versa + */ + ret = 0; + else if (ret) + goto err; + + /* modify cgroup based on values of the new one */ + ret = cgroup_modify_cgroup(converted_cgroup); + if (ret) { + fprintf(stderr, "cgroup modify error: %s \n", + cgroup_strerror(ret)); + goto err; + } + +err: + if (converted_cgroup) + cgroup_free(&converted_cgroup); + + return ret; +} +#endif /* LIBCG_LIB */ -- 2.31.1 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel