11/12 - ckrm_configfs_rcfs_members
Adds attr_store and attr_show support for members file.
--
fs/rcfs/rcfs.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+)
Index: linux-2.6.16/fs/rcfs/rcfs.c
===================================================================
--- linux-2.6.16.orig/fs/rcfs/rcfs.c
+++ linux-2.6.16/fs/rcfs/rcfs.c
@@ -244,6 +244,64 @@ static ssize_t show_shares(struct ckrm_c
return rc;
}
+/*
+ * Given a buffer with a pid in it, add the task with that pid to the class.
+ * Ignores entire buffer after the first pid is parsed.
+ */
+static int add_member(struct ckrm_class *class, const char *str)
+{
+ pid_t pid;
+ int rc = 0;
+ struct task_struct *tsk;
+
+ pid = (pid_t) simple_strtol(str, NULL, 0);
+ if (pid <= 0)
+ return -EINVAL; /* Not a valid pid */
+
+ read_lock(&tasklist_lock);
+ tsk = find_task_by_pid(pid);
+ if (tsk == NULL) {
+ read_unlock(&tasklist_lock);
+ return -ESRCH; /* pid not found */
+ }
+ get_task_struct(tsk);
+ read_unlock(&tasklist_lock);
+
+ /* Check permissions */
+ if ((!capable(CAP_SYS_NICE)) &&
+ (!capable(CAP_SYS_RESOURCE)) && (current->user != tsk->user))
+ rc = -EPERM;
+ else {
+ kref_get(&class->ref);
+ ckrm_setclass(tsk, class);
+ }
+ put_task_struct(tsk);
+ return rc;
+}
+
+/*
+ * Lists pids of tasks that belong to the given class.
+ */
+static ssize_t show_members(struct ckrm_class *class, char *buf)
+{
+ ssize_t i, rc = 0, bufsize = PAGE_SIZE;
+ struct task_struct *tsk;
+
+ spin_lock(&class->class_lock);
+ list_for_each_entry(tsk, &class->task_list, member_list) {
+ if (bufsize <= 0) {
+ rc = -ENOSPC;
+ break;
+ }
+ if (!tsk->pid) /* Ignore swappers */
+ continue;
+ i = snprintf(buf, bufsize, "%ld\n", (long)tsk->pid);
+ buf += i; rc += i; bufsize -= i;
+ }
+ spin_unlock(&class->class_lock);
+ return rc;
+}
+
struct class_attribute {
struct configfs_attribute configfs_attr;
ssize_t (*show)(struct ckrm_class *, char *);
@@ -270,6 +328,17 @@ struct class_attribute shares_attr = {
.store = set_shares
};
+struct class_attribute members_attr = {
+ .configfs_attr = {
+ .ca_name = "members",
+ .ca_owner = THIS_MODULE,
+ .ca_mode = S_IRUGO | S_IWUSR
+ },
+ .show = show_members,
+ .store = add_member
+};
+
+
static struct configfs_subsystem rcfs_subsys;
static struct config_item_type rcfs_class_type;
@@ -415,6 +484,7 @@ static struct configfs_group_operations
static struct configfs_attribute *class_attrs[] = {
&stats_attr.configfs_attr,
&shares_attr.configfs_attr,
+ &members_attr.configfs_attr,
NULL
};
--
----------------------------------------------------------------------
Chandra Seetharaman | Be careful what you choose....
- [EMAIL PROTECTED] | .......you may get it.
----------------------------------------------------------------------
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
ckrm-tech mailing list
https://lists.sourceforge.net/lists/listinfo/ckrm-tech