Add cgroup_cgxset() to libcgroup.so.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
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
abstraction-common.c abstraction-common.h \
abstraction-map.c abstraction-map.h \
abstraction-cpu.c abstraction-cpuset.c \
- tools/cgxget.c
+ tools/cgxget.c tools/cgxset.c
libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS)
libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static -DLIBCG_LIB \
-fPIC
CGROUP_3.0 {
cgroup_convert_cgroup;
cgroup_cgxget;
+ cgroup_cgxset;
} CGROUP_2.0;
return ret;
}
#endif /* !UNIT_TEST */
+
+#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) {
+ goto err;
+ }
+
+err:
+ if (converted_cgroup)
+ cgroup_free(&converted_cgroup);
+
+ return ret;
+}
+#endif /* LIBCG_LIB */