summaryrefslogtreecommitdiffstats
path: root/tests/libcg_ba.cpp
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-08-22 16:44:17 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-08-22 16:44:17 +0000
commit2124f1ea16bcc12482928c45689c1fa4d92a74a1 (patch)
treee5e51d88f8907e8d38b70b327f4d7a387b74b4b7 /tests/libcg_ba.cpp
parent3efa319b43fb1f66a96e5001c9e5cba51f854370 (diff)
downloadlibcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.tar.gz
libcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.tar.xz
libcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.zip
This patch adds cgroup_create_cgroup_from_parent() API. I've tested it
with a modified version of libcg_ba (basic acceptance tests), that I'll send out later. I've also fixed a couple of bugs, I'll list them in order and if desired, I'll split out the patches so that the enhancements can be separate from the bug fixes 1. Fix cg_create_control_group() to succeed if the directory already exists 2. We can't always append a control_file, we need to open it "r+" 3. It's OK for writing values to a control_file to fail, since some of them are read-only and some may not exist in hierarchies below the root 4. Skip over directories while trying to read control file's name value pairs 5. In cg_rd_ctlr_file we don't allocate any memory to value, directly fscanf into it, that's been fixed 6. There might be more fixes that might already be present in trunk, since I hope I've not redone a lot of the fixes, I had branched of trunk very recently Changelog v2 ------------ 1. Refactor cgroup_free_controllers() and use it in cgroup_create_cgroup_from_parent() 2. Check for strdup failure 3. Check if dst == src TODO: 1. Use cg_add_controller() API 2. Use cg_add_value_string() API I'll send out patches for the TODOs later. I've also updated the basic acceptance test (libcg_ba.cpp) Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@165 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcg_ba.cpp')
-rw-r--r--tests/libcg_ba.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/tests/libcg_ba.cpp b/tests/libcg_ba.cpp
index f06ba9b..99a9184 100644
--- a/tests/libcg_ba.cpp
+++ b/tests/libcg_ba.cpp
@@ -36,6 +36,7 @@ public:
struct cgroup *makenode(const string &name, const string &task_uid,
const string &task_gid, const string &control_uid,
const string &control_gid);
+ struct cgroup *makenodefromparent(const string &name);
};
cg::cg(void)
@@ -57,7 +58,7 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
gid_t tgid, cgid;
char *cgroup_name;
struct cgroup *ccg;
- struct cgroup_controller *cpu, *memory, *cpuacct;
+ struct cgroup_controller *cpu, *cpuacct;
struct passwd *passwd;
struct group *grp;
int ret;
@@ -88,11 +89,10 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
memset(cgroup_name, '\0', name.length());
strncpy(cgroup_name, name.c_str(), name.length());
- ccg = cgroup_new_cgroup(cgroup_name, tuid, tgid, cuid, cgid);
+ ccg = cgroup_new_cgroup(cgroup_name);
+ cgroup_set_uid_gid(ccg, tuid, tgid, cuid, cgid);
cpu = cgroup_add_controller(ccg, "cpu");
cgroup_add_value_uint64(cpu, "cpu.shares", 2048);
- memory = cgroup_add_controller(ccg, "memory");
- cgroup_add_value_uint64(memory, "memory.limit_in_bytes", 102400);
cpuacct = cgroup_add_controller(ccg, "cpuacct");
cgroup_add_value_uint64(cpuacct, "cpuacct.usage", 0);
@@ -107,6 +107,27 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
return ccg;
}
+struct cgroup *cg::makenodefromparent(const string &name)
+{
+ char *cgroup_name;
+ struct cgroup *ccg;
+ int ret;
+
+ cgroup_name = (char *) malloc(name.length());
+ memset(cgroup_name, '\0', name.length());
+ strcpy(cgroup_name, name.c_str());
+
+ ccg = cgroup_new_cgroup(cgroup_name);
+ ret = cgroup_create_cgroup_from_parent(ccg, 1);
+ if (ret) {
+ cout << "cg create group failed " << errno << endl;
+ ret = cgroup_delete_cgroup(ccg, 1);
+ if (ret)
+ cout << "cg delete group failed " << errno << endl;
+ }
+ return ccg;
+}
+
} // namespace
using namespace cgtest;
@@ -114,10 +135,12 @@ int main(int argc, char *argv[])
{
try {
cg *app = new cg();
- struct cgroup *ccg;
+ struct cgroup *ccg, *ccg_child;
ccg = app->makenode("database", "root", "root", "balbir",
"balbir");
+ ccg_child = app->makenodefromparent("mysql");
cgroup_free(&ccg);
+ cgroup_free(&ccg_child);
delete app;
} catch (exception &e) {
cout << e.what() << endl;