static int create_tmp_cgroup(const struct example_opts * const opts)
{
- struct cgroup *cg;
+ struct cgroup *cgrp;
int ret = 0;
- cg = cgroup_new_cgroup(TMP_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(TMP_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
goto error;
}
- ret = cgroup_create_cgroup(cg, 1);
+ ret = cgroup_create_cgroup(cgrp, 1);
if (ret) {
printf("Failed to write the cgroup to /sys/fs/cgroup: %d: %s\n",
ret, cgroup_strerror(ret));
}
error:
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
return ret;
}
static int move_pids_to_tmp_cgroup(const struct example_opts * const opts)
{
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
int ret, pid_cnt, i;
pid_t *pids = NULL;
int saved_ret = 0;
goto error;
}
- cg = cgroup_new_cgroup(TMP_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(TMP_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
goto error;
}
for (i = 0; i < pid_cnt; i++) {
- ret = cgroup_attach_task_pid(cg, pids[i]);
+ ret = cgroup_attach_task_pid(cgrp, pids[i]);
if (ret) {
printf("Failed to attach pid %d to %s\n", pids[i], TMP_CGNAME);
/*
if (pids)
free(pids);
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
if (ret == 0 && saved_ret)
ret = saved_ret;
static int create_high_priority_cgroup(const struct example_opts * const opts)
{
struct cgroup_controller *ctrl;
- struct cgroup *cg;
+ struct cgroup *cgrp;
int ret = 0;
- cg = cgroup_new_cgroup(HIGH_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(HIGH_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
ret = ECGFAIL;
goto error;
}
- ctrl = cgroup_add_controller(cg, "cpu");
+ ctrl = cgroup_add_controller(cgrp, "cpu");
if (!ctrl) {
- printf("Failed to add the cpu controller to the %s cgroup struct\n",
- HIGH_CGNAME);
+ printf("Failed to add the cpu controller to the %s cgroup struct\n", HIGH_CGNAME);
ret = ECGFAIL;
goto error;
}
goto error;
}
- ctrl = cgroup_add_controller(cg, "memory");
+ ctrl = cgroup_add_controller(cgrp, "memory");
if (!ctrl) {
printf("Failed to add the memory controller to the %s cgroup struct\n",
HIGH_CGNAME);
goto error;
}
- ret = cgroup_create_cgroup(cg, 0);
+ ret = cgroup_create_cgroup(cgrp, 0);
if (ret) {
printf("Failed to write the %s cgroup to /sys/fs/cgroup: %d: %s\n",
HIGH_CGNAME, ret, cgroup_strerror(ret));
}
error:
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
return ret;
}
static int create_medium_priority_cgroup(const struct example_opts * const opts)
{
struct cgroup_controller *ctrl;
- struct cgroup *cg;
+ struct cgroup *cgrp;
int ret = 0;
- cg = cgroup_new_cgroup(MED_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(MED_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
ret = ECGFAIL;
goto error;
}
- ctrl = cgroup_add_controller(cg, "cpu");
+ ctrl = cgroup_add_controller(cgrp, "cpu");
if (!ctrl) {
- printf("Failed to add the cpu controller to the %s cgroup struct\n",
- MED_CGNAME);
+ printf("Failed to add the cpu controller to the %s cgroup struct\n", MED_CGNAME);
ret = ECGFAIL;
goto error;
}
goto error;
}
- ctrl = cgroup_add_controller(cg, "memory");
+ ctrl = cgroup_add_controller(cgrp, "memory");
if (!ctrl) {
printf("Failed to add the memory controller to the %s cgroup struct\n",
MED_CGNAME);
goto error;
}
- ret = cgroup_create_cgroup(cg, 0);
+ ret = cgroup_create_cgroup(cgrp, 0);
if (ret) {
printf("Failed to write the %s cgroup to /sys/fs/cgroup: %d: %s\n",
MED_CGNAME, ret, cgroup_strerror(ret));
}
error:
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
return ret;
}
static int create_low_priority_cgroup(const struct example_opts * const opts)
{
struct cgroup_controller *ctrl;
- struct cgroup *cg;
+ struct cgroup *cgrp;
int ret = 0;
- cg = cgroup_new_cgroup(LOW_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(LOW_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
ret = ECGFAIL;
goto error;
}
- ctrl = cgroup_add_controller(cg, "cpu");
+ ctrl = cgroup_add_controller(cgrp, "cpu");
if (!ctrl) {
- printf("Failed to add the cpu controller to the %s cgroup struct\n",
- LOW_CGNAME);
+ printf("Failed to add the cpu controller to the %s cgroup struct\n", LOW_CGNAME);
ret = ECGFAIL;
goto error;
}
goto error;
}
- ctrl = cgroup_add_controller(cg, "memory");
+ ctrl = cgroup_add_controller(cgrp, "memory");
if (!ctrl) {
printf("Failed to add the memory controller to the %s cgroup struct\n",
LOW_CGNAME);
goto error;
}
- ret = cgroup_create_cgroup(cg, 0);
+ ret = cgroup_create_cgroup(cgrp, 0);
if (ret) {
printf("Failed to write the %s cgroup to /sys/fs/cgroup: %d: %s\n",
LOW_CGNAME, ret, cgroup_strerror(ret));
}
error:
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
return ret;
}
-static int create_process(pid_t * const pid, const char * const cgname)
+static int create_process(pid_t * const pid, const char * const cgrp_name)
{
int ret = 0;
/*
* This is the child process. Move it to the requested cgroup
*/
- ret = cgroup_change_cgroup_path(cgname, getpid(), NULL);
+ ret = cgroup_change_cgroup_path(cgrp_name, getpid(), NULL);
if (ret)
exit(0);
static int delete_tmp_cgroup(void)
{
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
int ret, pid_cnt, i;
int saved_errno = 0;
pid_t *pids = NULL;
}
}
- cg = cgroup_new_cgroup(TMP_CGNAME);
- if (!cg) {
+ cgrp = cgroup_new_cgroup(TMP_CGNAME);
+ if (!cgrp) {
printf("Failed to allocate the cgroup struct. Are we out of memory?\n");
goto error;
}
- ret = cgroup_delete_cgroup(cg, 1);
+ ret = cgroup_delete_cgroup(cgrp, 1);
if (ret)
printf("Failed to delete the %s cgroup: %d: %s\n", TMP_CGNAME, ret,
cgroup_strerror(ret));
if (pids)
free(pids);
- if (cg)
- cgroup_free(&cg);
+ if (cgrp)
+ cgroup_free(&cgrp);
if (ret == 0 && saved_errno)
ret = ECGFAIL;
int main(int argc, char **argv)
{
- struct cgroup *cgroup = NULL;
+ struct cgroup *cgrp = NULL;
int ret = 0;
ret = cgroup_init();
exit(1);
}
- cgroup = cgroup_new_cgroup(CGRP_NAME);
- if (!cgroup) {
+ cgrp = cgroup_new_cgroup(CGRP_NAME);
+ if (!cgrp) {
fprintf(stderr, "Failed to allocate cgroup %s\n", CGRP_NAME);
exit(1);
}
- ret = cgroup_create_cgroup(cgroup, 0);
+ ret = cgroup_create_cgroup(cgrp, 0);
if (ret)
fprintf(stderr, "Failed to create cgroup %s\n", CGRP_NAME);
- cgroup_free(&cgroup);
+ cgroup_free(&cgrp);
return ret;
}
int main(int argc, char *argv[])
{
- struct cgroup_controller *group_controller = NULL;
- struct cgroup *group = NULL;
- char group_name[] = "/";
+ struct cgroup_controller *cgrp_controller = NULL;
+ struct cgroup *cgrp = NULL;
+ char cgrp_name[] = "/";
char *name;
int count;
int ret;
exit(1);
}
- group = cgroup_new_cgroup(group_name);
- if (group == NULL) {
- printf("cannot create group '%s'\n", group_name);
+ cgrp = cgroup_new_cgroup(cgrp_name);
+ if (cgrp == NULL) {
+ printf("cannot create cgrp '%s'\n", cgrp_name);
return -1;
}
- ret = cgroup_get_cgroup(group);
+ ret = cgroup_get_cgroup(cgrp);
if (ret != 0) {
printf("cannot read group '%s': %s\n",
- group_name, cgroup_strerror(ret));
+ cgrp_name, cgroup_strerror(ret));
}
for (i = 1; i < argc; i++) {
- group_controller = cgroup_get_controller(group, argv[i]);
- if (group_controller == NULL) {
+ cgrp_controller = cgroup_get_controller(cgrp, argv[i]);
+ if (cgrp_controller == NULL) {
printf("cannot find controller '%s' in group '%s'\n",
- argv[i], group_name);
+ argv[i], cgrp_name);
ret = -1;
continue;
}
- count = cgroup_get_value_name_count(group_controller);
+ count = cgroup_get_value_name_count(cgrp_controller);
for (j = 0; j < count; j++) {
- name = cgroup_get_value_name(group_controller, j);
+ name = cgroup_get_value_name(cgrp_controller, j);
if (name != NULL)
printf("%s\n", name);
}
printf("Stats for %s:\n", path);
printf("%s: %s", stat.name, stat.value);
- while ((ret = cgroup_read_stats_next(&handle, &stat)) !=
- ECGEOF) {
+ while ((ret = cgroup_read_stats_next(&handle, &stat)) != ECGEOF)
printf("%s: %s", stat.name, stat.value);
- }
cgroup_read_stats_end(&handle);
printf("\n");
int main(int argc, char *argv[])
{
struct cgroup_file_info info;
- char cgroup_path[FILENAME_MAX];
+ char cgrp_path[FILENAME_MAX];
char *controller;
int root_len;
void *handle;
int ret;
if (argc < 2) {
- fprintf(stderr, "Usage %s: <controller name>\n",
- argv[0]);
+ fprintf(stderr, "Usage %s: <controller name>\n", argv[0]);
exit(EXIT_FAILURE);
}
}
root_len = strlen(info.full_path) - 1;
- strncpy(cgroup_path, info.path, FILENAME_MAX - 1);
- ret = read_stats(cgroup_path, controller);
+ strncpy(cgrp_path, info.path, FILENAME_MAX - 1);
+ ret = read_stats(cgrp_path, controller);
if (ret < 0)
exit(EXIT_FAILURE);
ECGEOF) {
if (info.type != CGROUP_FILE_TYPE_DIR)
continue;
- strncpy(cgroup_path, info.full_path + root_len, FILENAME_MAX - 1);
- strcat(cgroup_path, "/");
- ret = read_stats(cgroup_path, controller);
+ strncpy(cgrp_path, info.full_path + root_len, FILENAME_MAX - 1);
+ strcat(cgrp_path, "/");
+ ret = read_stats(cgrp_path, controller);
if (ret < 0)
exit(EXIT_FAILURE);
}
* Tests the cgroup_attach_cgroup() api under different scenarios
* @param retcode error code in case any error is expected from api
* @param cgrp the group to assign the task to
- * @param group1 the name of the group under first (single) mountpoint
- * @param group2 the name of the group under 2nd moutpoint for multimount
+ * @param cgrp1 the name of the group under first (single) mountpoint
+ * @param cgrp2 the name of the group under 2nd moutpoint for multimount
* @param i the test number
* @param k the message enum number to print the useful message
*/
void test_cgroup_attach_task(int retcode, struct cgroup *cgrp,
- const char *group1, const char *group2, pid_t pid,
+ const char *cgrp1, const char *cgrp2, pid_t pid,
int k, int i)
{
char tasksfile[FILENAME_MAX], tasksfile2[FILENAME_MAX];
/* API returned success, so perform check */
if (retval == 0) {
- build_path(tasksfile, mountpoint, group1, "tasks");
+ build_path(tasksfile, mountpoint, cgrp1, "tasks");
if (check_task(tasksfile, 0)) {
if (fs_mounted == 2) {
/* multiple mounts */
build_path(tasksfile2, mountpoint2,
- group2, "tasks");
+ cgrp2, "tasks");
if (check_task(tasksfile2, 0)) {
message(i, PASS, "attach_task()",
retval, info[TASKINGRP]);
char controller_name[FILENAME_MAX], control_file[FILENAME_MAX];
char wr[SIZE], extra[] = "in cgroup_compare_cgroup";
- struct cgroup *cgroup1 = NULL, *cgroup2 = NULL;
+ struct cgroup *cgrp1 = NULL, *cgrp2 = NULL;
struct cgroup_controller *controller = NULL;
struct cntl_val_t cval;
else
message(i++, FAIL, "compare_cgroup()", retval, info[NULLGRP]);
- cgroup1 = cgroup_new_cgroup("testgroup");
- cgroup2 = cgroup_new_cgroup("testgroup");
- cgroup_set_uid_gid(cgroup1, 0, 0, 0, 0);
- cgroup_set_uid_gid(cgroup2, 0, 0, 0, 0);
+ cgrp1 = cgroup_new_cgroup("testgroup");
+ cgrp2 = cgroup_new_cgroup("testgroup");
+ cgroup_set_uid_gid(cgrp1, 0, 0, 0, 0);
+ cgroup_set_uid_gid(cgrp2, 0, 0, 0, 0);
retval = set_controller(ctl1, controller_name, control_file);
- controller = cgroup_add_controller(cgroup1, controller_name);
+ controller = cgroup_add_controller(cgrp1, controller_name);
if (controller) {
retval = add_control_value(controller,
control_file, wr, STRING, cval);
message(i++, FAIL, wr, retval, extra);
}
- controller = cgroup_add_controller(cgroup2, controller_name);
+ controller = cgroup_add_controller(cgrp2, controller_name);
if (controller) {
retval = add_control_value(controller,
control_file, wr, STRING, cval);
message(i++, FAIL, wr, retval, extra);
}
- retval = cgroup_compare_cgroup(cgroup1, cgroup2);
+ retval = cgroup_compare_cgroup(cgrp1, cgrp2);
if (retval)
message(i++, FAIL, "compare_cgroup()", retval, info[NOMESSAGE]);
else
/* Test the api by putting diff number of controllers in cgroups */
retval = set_controller(ctl2, controller_name, control_file);
- controller = cgroup_add_controller(cgroup2, controller_name);
+ controller = cgroup_add_controller(cgrp2, controller_name);
if (controller) {
retval = add_control_value(controller,
control_file, wr, STRING, cval);
message(i++, FAIL, wr, retval, extra);
}
- retval = cgroup_compare_cgroup(cgroup1, cgroup2);
+ retval = cgroup_compare_cgroup(cgrp1, cgrp2);
if (retval == ECGROUPNOTEQUAL)
message(i++, PASS, "compare_cgroup()", retval, info[NOMESSAGE]);
else
message(i++, FAIL, "compare_cgroup()", retval, info[NOMESSAGE]);
- cgroup_free(&cgroup1);
- cgroup_free(&cgroup2);
+ cgroup_free(&cgrp1);
+ cgroup_free(&cgrp2);
}
/**
cgroup_free(&cgroup_filled);
/* 3.
- * Test with name filled cgroup. Ensure the group group1 exists
+ * Test with name filled cgroup. Ensure the group cgrp1 exists
* in the filesystem before calling this test function
*/
- cgroup_filled = cgroup_new_cgroup("group1");
+ cgroup_filled = cgroup_new_cgroup("cgrp1");
if (!cgroup_filled)
message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
*/
void test_cgroup_add_free_controller(int i)
{
- struct cgroup *cgroup1 = NULL, *cgroup2 = NULL;
+ struct cgroup *cgrp1 = NULL, *cgrp2 = NULL;
struct cgroup_controller *cgctl1, *cgctl2;
/* Test with a Null cgroup */
- cgctl1 = cgroup_add_controller(cgroup1, "cpu");
+ cgctl1 = cgroup_add_controller(cgrp1, "cpu");
if (!cgctl1)
message(i++, PASS, "add_controller()", 0, info[NOMESSAGE]);
else
message(i++, FAIL, "add_controller()", -1, info[NOMESSAGE]);
- cgroup1 = cgroup_new_cgroup("testgroup");
- cgctl1 = cgroup_add_controller(cgroup1, "cpuset");
+ cgrp1 = cgroup_new_cgroup("testgroup");
+ cgctl1 = cgroup_add_controller(cgrp1, "cpuset");
if (cgctl1)
message(i++, PASS, "add_controller()", 0, info[NOMESSAGE]);
else
message(i++, FAIL, "add_controller()", -1, info[NOMESSAGE]);
- cgctl2 = cgroup_add_controller(cgroup1, "cpu");
+ cgctl2 = cgroup_add_controller(cgrp1, "cpu");
if (cgctl2)
message(i++, PASS, "add_controller()", 0, info[NOMESSAGE]);
else
message(i++, FAIL, "add_controller()", -1, info[NOMESSAGE]);
- cgroup_free(&cgroup1);
- cgroup_free_controllers(cgroup2);
+ cgroup_free(&cgrp1);
+ cgroup_free_controllers(cgrp2);
}
/**
int main(void)
{
struct cgroup_controller *cgc;
- struct cgroup *cgroup;
+ struct cgroup *cgrp;
int ret;
ret = cgroup_init();
if (ret) {
- printf("FAIL: cgroup_init failed with %s\n",
- cgroup_strerror(ret));
+ printf("FAIL: cgroup_init failed with %s\n", cgroup_strerror(ret));
exit(3);
}
- cgroup = cgroup_new_cgroup("test");
- if (!cgroup) {
+ cgrp = cgroup_new_cgroup("test");
+ if (!cgrp) {
printf("FAIL: cgroup_new_cgroup failed\n");
exit(3);
}
- cgc = cgroup_add_controller(cgroup, "name=test");
+ cgc = cgroup_add_controller(cgrp, "name=test");
if (!cgc) {
printf("FAIL: cgroup_add_controller failed\n");
exit(3);
}
- ret = cgroup_create_cgroup(cgroup, 1);
+ ret = cgroup_create_cgroup(cgrp, 1);
if (ret) {
- printf("FAIL: cgroup_create_cgroup failed with %s\n",
- cgroup_strerror(ret));
+ printf("FAIL: cgroup_create_cgroup failed with %s\n", cgroup_strerror(ret));
exit(3);
}
int main(int argc, char *argv[])
{
- char *group = NULL;
+ char *cgrp = NULL;
void *handle;
int ret, i;
if (argc < 2) {
- printf("No list of groups provided\n");
+ printf("No list of cgroups provided\n");
return -1;
}
for (i = 1; i < argc; i++) {
pid_t pid;
- group = strdup(argv[i]);
- printf("Printing the details of groups %s\n", group);
+ cgrp = strdup(argv[i]);
+ printf("Printing the details of cgroups %s\n", cgrp);
- ret = cgroup_get_task_begin(group, "cpu", &handle, &pid);
+ ret = cgroup_get_task_begin(cgrp, "cpu", &handle, &pid);
while (!ret) {
printf("Pid is %u\n", pid);
ret = cgroup_get_task_next(&handle, &pid);
printf("cgroup_get_task_next failed with %s\n",
cgroup_strerror(ret));
if (ret == ECGOTHER)
- printf("failure with %s\n",
- strerror(errno));
+ printf("failure with %s\n", strerror(errno));
return -1;
}
}
- free(group);
- group = NULL;
+ free(cgrp);
+ cgrp = NULL;
ret = cgroup_get_task_end(&handle);
}
int main(void)
{
- struct cgroup *cgroup;
struct cgroup_controller *cgc;
+ struct cgroup *cgrp;
int fail = 0;
- cgroup = cgroup_new_cgroup("test");
- cgc = cgroup_add_controller(cgroup, "cpu");
+ cgrp = cgroup_new_cgroup("test");
+ cgc = cgroup_add_controller(cgrp, "cpu");
cgroup_add_value_int64(cgc, "cpu.shares", 2048);
cgroup_add_value_uint64(cgc, "cpu.something", 1000);
cgroup_add_value_bool(cgc, "cpu.bool", 1);
- if (!strcmp(cgroup->controller[0]->values[0]->name, "cpu.shares")) {
- if (strcmp(cgroup->controller[0]->values[0]->value, "2048")) {
+ if (!strcmp(cgrp->controller[0]->values[0]->name, "cpu.shares")) {
+ if (strcmp(cgrp->controller[0]->values[0]->value, "2048")) {
printf("FAIL for add_value_int\n");
fail = 1;
}
}
- if (!strcmp(cgroup->controller[0]->values[1]->name, "cpu.something")) {
- if (strcmp(cgroup->controller[0]->values[1]->value, "1000")) {
+ if (!strcmp(cgrp->controller[0]->values[1]->name, "cpu.something")) {
+ if (strcmp(cgrp->controller[0]->values[1]->value, "1000")) {
printf("FAIL for add_value_uint\n");
fail = 1;
}
}
- if (!strcmp(cgroup->controller[0]->values[2]->name, "cpu.bool")) {
- if (strcmp(cgroup->controller[0]->values[2]->value, "1")) {
+ if (!strcmp(cgrp->controller[0]->values[2]->name, "cpu.bool")) {
+ if (strcmp(cgrp->controller[0]->values[2]->value, "1")) {
printf("FAIL for add_value_bool\n");
fail = 1;
}