summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-12 08:13:02 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-12 08:13:02 +0000
commit0bf95e05d806339a9a79fb2ed20e8a6703eb6cd4 (patch)
tree3c164e1f17937c271172499a270a25fa9247bc33
parentdd870c34dee9bcd93d543348bf497da22e6406c8 (diff)
downloadlibcg-0bf95e05d806339a9a79fb2ed20e8a6703eb6cd4.tar.gz
libcg-0bf95e05d806339a9a79fb2ed20e8a6703eb6cd4.tar.xz
libcg-0bf95e05d806339a9a79fb2ed20e8a6703eb6cd4.zip
libcgroup: Add an API to allow comparision of cgroups
Allows you to compare two cgroups. Their values need to be equal. NULL cgroups are invalid. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@124 4f4bb910-9a46-0410-90c8-c897d4f1cd53
-rw-r--r--libcgroup.h5
-rw-r--r--wrapper.c62
2 files changed, 67 insertions, 0 deletions
diff --git a/libcgroup.h b/libcgroup.h
index 89f923a..508fe48 100644
--- a/libcgroup.h
+++ b/libcgroup.h
@@ -122,6 +122,8 @@ enum cgroup_errors {
* users need to check errno upon encoutering ECGOTHER.
*/
ECGOTHER,
+ ECGROUPNOTEQUAL,
+ ECGCONTROLLERNOTEQUAL,
};
#define CG_MAX_MSG_SIZE 256
@@ -181,6 +183,9 @@ int cgroup_add_value_uint64(struct cgroup_controller *controller,
const char *name, u_int64_t value);
int cgroup_add_value_bool(struct cgroup_controller *controller,
const char *name, bool value);
+int cgroup_compare_cgroup(struct cgroup *cgroup_a, struct cgroup *cgroup_b);
+int cgroup_compare_controllers(struct cgroup_controller *cgca,
+ struct cgroup_controller *cgcb);
__END_DECLS
diff --git a/wrapper.c b/wrapper.c
index f79f58f..5aaabe7 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -229,3 +229,65 @@ int cgroup_add_value_bool(struct cgroup_controller *controller,
return 0;
}
+
+int cgroup_compare_controllers(struct cgroup_controller *cgca,
+ struct cgroup_controller *cgcb)
+{
+ int i;
+
+ if (!cgca || !cgcb)
+ return ECGINVAL;
+
+ if (strcmp(cgca->name, cgcb->name))
+ return ECGCONTROLLERNOTEQUAL;
+
+ if (cgca->index != cgcb->index)
+ return ECGCONTROLLERNOTEQUAL;
+
+ for (i = 0; i < cgca->index; i++) {
+ struct control_value *cva = cgca->values[i];
+ struct control_value *cvb = cgcb->values[i];
+
+ if (strcmp(cva->name, cvb->name))
+ return ECGCONTROLLERNOTEQUAL;
+
+ if (strcmp(cva->value, cvb->value))
+ return ECGCONTROLLERNOTEQUAL;
+ }
+ return 0;
+}
+
+int cgroup_compare_cgroup(struct cgroup *cgroup_a, struct cgroup *cgroup_b)
+{
+ int i;
+
+ if (!cgroup_a || !cgroup_b)
+ return ECGINVAL;
+
+ if (strcmp(cgroup_a->name, cgroup_b->name))
+ return ECGROUPNOTEQUAL;
+
+ if (cgroup_a->tasks_uid != cgroup_b->tasks_uid)
+ return ECGROUPNOTEQUAL;
+
+ if (cgroup_a->tasks_gid != cgroup_b->tasks_gid)
+ return ECGROUPNOTEQUAL;
+
+ if (cgroup_a->control_uid != cgroup_b->control_uid)
+ return ECGROUPNOTEQUAL;
+
+ if (cgroup_a->control_gid != cgroup_b->control_gid)
+ return ECGROUPNOTEQUAL;
+
+ if (cgroup_a->index != cgroup_b->index)
+ return ECGROUPNOTEQUAL;
+
+ for (i = 0; i < cgroup_a->index; i++) {
+ struct cgroup_controller *cgca = cgroup_a->controller[i];
+ struct cgroup_controller *cgcb = cgroup_b->controller[i];
+
+ if (cgroup_compare_controllers(cgca, cgcb))
+ return ECGCONTROLLERNOTEQUAL;
+ }
+ return 0;
+}