nobase_include_HEADERS = libcgroup.h libcgroup/error.h libcgroup/init.h \
libcgroup/groups.h libcgroup/tasks.h \
libcgroup/iterators.h libcgroup/config.h \
- libcgroup/log.h
+ libcgroup/log.h libcgroup/tools.h
#include <libcgroup/tasks.h>
#include <libcgroup/config.h>
#include <libcgroup/log.h>
+#include <libcgroup/tools.h>
#undef _LIBCGROUP_H_INSIDE
--- /dev/null
+/**
+ * Libcgroup tools header file
+ *
+ * Copyright (c) 2021-2022 Oracle and/or its affiliates.
+ * Author: Tom Hromatka <tom.hromatka@oracle.com>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+#ifndef _LIBCGROUP_TOOLS_H
+#define _LIBCGROUP_TOOLS_H
+
+#ifndef _LIBCGROUP_H_INSIDE
+#error "Only <libcgroup.h> should be included directly."
+#endif
+
+#ifndef SWIG
+#include <features.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Read the setting-value pairs in the cgroup sysfs for param cg.
+ * cgroup_cgxget() will perform the necessary conversions to match
+ * the "on-disk" format and then convert the data back to the
+ * requested version. If successful, cg will be populated with
+ * the setting-value pairs.
+ *
+ * @param cg Input/Output cgroup. Must be initialized and freed by the caller
+ * @param version Cgroup version of cg If set to CGROUP_UNK, the versions
+ * stored within each controller will be used. Otherwise this
+ * value will be used to override the cg param's controller
+ * versions
+ * @param ignore_unmappable Ignore failures due to settings that cannot be
+ * converted from one cgroup version to another
+ */
+int cgroup_cgxget(struct cgroup ** cg,
+ enum cg_version_t version, bool ignore_unmappable);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _LIBCGROUP_TOOLS_H */
libcgroup-internal.h libcgroup.map wrapper.c log.c \
abstraction-common.c abstraction-common.h \
abstraction-map.c abstraction-map.h \
- abstraction-cpu.c abstraction-cpuset.c
+ abstraction-cpu.c abstraction-cpuset.c \
+ tools/cgxget.c
libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS)
-libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static
+libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static -DLIBCG_LIB \
+ -fPIC
libcgroup_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libcgroup.map \
-version-number $(VERSION_NUMBER)
noinst_LTLIBRARIES = libcgroupfortesting.la
-libcgroupfortesting_la_SOURCES = $(libcgroup_la_SOURCES)
+libcgroupfortesting_la_SOURCES = parse.h parse.y lex.l api.c config.c \
+ libcgroup-internal.h libcgroup.map wrapper.c log.c \
+ abstraction-common.c abstraction-common.h \
+ abstraction-map.c abstraction-map.h \
+ abstraction-cpu.c abstraction-cpuset.c
libcgroupfortesting_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS)
libcgroupfortesting_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC= -DUNIT_TEST
libcgroupfortesting_la_LDFLAGS = -Wl,--version-script,$(TESTING_MAP_FILE) \
CGROUP_3.0 {
cgroup_convert_cgroup;
+ cgroup_cgxget;
} CGROUP_2.0;
#define LL_MAX 100
+#ifndef LIBCG_LIB
static struct option const long_options[] =
{
{"v1", no_argument, NULL, '1'},
err:
return ret;
}
+#endif /* !LIBCG_LIB */
static int get_cv_value(struct control_value * const cv,
const char * const cg_name,
return ret;
}
+#ifndef LIBCG_LIB
static int get_values(struct cgroup *cg_list[], int cg_list_len)
{
int ret = 0;
return ret;
}
-void print_control_values(const struct control_value * const cv, int mode)
+static void print_control_values(const struct control_value * const cv,
+ int mode)
{
if (mode & MODE_SHOW_NAMES)
printf("%s: ", cv->name);
printf("%s\n", cv->value);
}
-void print_controller(const struct cgroup_controller * const cgc, int mode)
+static void print_controller(const struct cgroup_controller * const cgc,
+ int mode)
{
int i;
}
}
-int convert_cgroups(struct cgroup **cg_list[], int cg_list_len,
- enum cg_version_t in_version,
- enum cg_version_t out_version)
+static int convert_cgroups(struct cgroup **cg_list[], int cg_list_len,
+ enum cg_version_t in_version,
+ enum cg_version_t out_version)
{
struct cgroup **cg_converted_list;
int i = 0, j, ret = 0;
return ret;
}
+#endif /* !LIBCG_LIB */
+
+#ifdef LIBCG_LIB
+int cgroup_cgxget(struct cgroup **cg,
+ enum cg_version_t version, bool ignore_unmappable)
+{
+ struct cgroup *disk_cg, *out_cg;
+ int ret;
+
+ if (!cg || !(*cg)) {
+ ret = ECGINVAL;
+ goto out;
+ }
+
+ disk_cg = cgroup_new_cgroup((*cg)->name);
+ if (!disk_cg) {
+ ret = ECGCONTROLLERCREATEFAILED;
+ goto out;
+ }
+
+ ret = cgroup_convert_cgroup(disk_cg, CGROUP_DISK, *cg, version);
+ if (ret == ECGNOVERSIONCONVERT && ignore_unmappable)
+ ret = 0;
+ else if (ret)
+ goto out;
+
+ ret = get_cgroup_values(disk_cg);
+ if (ret)
+ goto out;
+
+ out_cg = cgroup_new_cgroup((*cg)->name);
+ if (!out_cg) {
+ ret = ECGCONTROLLERCREATEFAILED;
+ goto out;
+ }
+
+ ret = cgroup_convert_cgroup(out_cg, version, disk_cg, CGROUP_DISK);
+ if (ret) {
+ cgroup_free(&out_cg);
+ goto out;
+ }
+
+ cgroup_free(cg);
+ *cg = out_cg;
+
+out:
+ if (disk_cg)
+ cgroup_free(&disk_cg);
+ return ret;
+}
+#endif /* LIBCG_LIB */