public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Kay Sievers <kay.sievers@vrfy.org>,
	Dhaval Giani <dhaval@linux.vnet.ibm.com>,
	Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 36/54] fix struct user_info export's sysfs interaction
Date: Fri,  2 Nov 2007 16:59:14 -0700	[thread overview]
Message-ID: <1194047972-9850-36-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20071102235758.GA9803@kroah.com>

From: Kay Sievers <kay.sievers@vrfy.org>

Clean up the use of ksets and kobjects. Kobjects are instances of
objects (like struct user_info), ksets are collections of objects of a
similar type (like the uids directory containing the user_info directories).
So, use kobjects for the user_info directories, and a kset for the "uids"
directory.

On object cleanup, the final kobject_put() was missing.

Cc: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Cc: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 include/linux/sched.h |    9 +---
 kernel/ksysfs.c       |    7 +--
 kernel/user.c         |  104 ++++++++++++++++++++++++-------------------------
 3 files changed, 55 insertions(+), 65 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 155d743..e8033c1 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -547,18 +547,13 @@ struct user_struct {
 #ifdef CONFIG_FAIR_USER_SCHED
 	struct task_group *tg;
 #ifdef CONFIG_SYSFS
-	struct kset kset;
-	struct subsys_attribute user_attr;
+	struct kobject kobj;
 	struct work_struct work;
 #endif
 #endif
 };
 
-#ifdef CONFIG_FAIR_USER_SCHED
-extern int uids_kobject_init(void);
-#else
-static inline int uids_kobject_init(void) { return 0; }
-#endif
+extern int uids_sysfs_init(void);
 
 extern struct user_struct *find_user(uid_t);
 
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index ea07bcf..e3293e7 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -142,11 +142,8 @@ static int __init ksysfs_init(void)
 			goto group_exit;
 	}
 
-	/*
-	 * Create "/sys/kernel/uids" directory and corresponding root user's
-	 * directory under it.
-	 */
-	error = uids_kobject_init();
+	/* create the /sys/kernel/uids/ directory */
+	error = uids_sysfs_init();
 	if (error)
 		goto notes_exit;
 
diff --git a/kernel/user.c b/kernel/user.c
index 75d9f9b..c9fffa1 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -115,7 +115,7 @@ static void sched_switch_user(struct task_struct *p) { }
 
 #if defined(CONFIG_FAIR_USER_SCHED) && defined(CONFIG_SYSFS)
 
-static struct kobject uids_kobject; /* represents /sys/kernel/uids directory */
+static struct kset *uids_kset; /* represents the /sys/kernel/uids/ directory */
 static DEFINE_MUTEX(uids_mutex);
 
 static inline void uids_mutex_lock(void)
@@ -128,86 +128,84 @@ static inline void uids_mutex_unlock(void)
 	mutex_unlock(&uids_mutex);
 }
 
-/* return cpu shares held by the user */
-static ssize_t cpu_shares_show(struct kset *kset, char *buffer)
+/* uid directory attributes */
+static ssize_t cpu_shares_show(struct kobject *kobj,
+			       struct kobj_attribute *attr,
+			       char *buf)
 {
-	struct user_struct *up = container_of(kset, struct user_struct, kset);
+	struct user_struct *up = container_of(kobj, struct user_struct, kobj);
 
-	return sprintf(buffer, "%lu\n", sched_group_shares(up->tg));
+	return sprintf(buf, "%lu\n", sched_group_shares(up->tg));
 }
 
-/* modify cpu shares held by the user */
-static ssize_t cpu_shares_store(struct kset *kset, const char *buffer,
-				size_t size)
+static ssize_t cpu_shares_store(struct kobject *kobj,
+				struct kobj_attribute *attr,
+				const char *buf, size_t size)
 {
-	struct user_struct *up = container_of(kset, struct user_struct, kset);
+	struct user_struct *up = container_of(kobj, struct user_struct, kobj);
 	unsigned long shares;
 	int rc;
 
-	sscanf(buffer, "%lu", &shares);
+	sscanf(buf, "%lu", &shares);
 
 	rc = sched_group_set_shares(up->tg, shares);
 
 	return (rc ? rc : size);
 }
 
-static void user_attr_init(struct subsys_attribute *sa, char *name, int mode)
+static struct kobj_attribute cpu_share_attr =
+	__ATTR(cpu_share, 0644, cpu_shares_show, cpu_shares_store);
+
+/* default attributes per uid directory */
+static struct attribute *uids_attributes[] = {
+	&cpu_share_attr.attr,
+	NULL
+};
+
+/* the lifetime of user_struct is not managed by the core (now) */
+static void uids_release(struct kobject *kobj)
 {
-	sa->attr.name = name;
-	sa->attr.mode = mode;
-	sa->show = cpu_shares_show;
-	sa->store = cpu_shares_store;
+	return;
 }
 
-/* Create "/sys/kernel/uids/<uid>" directory and
- *  "/sys/kernel/uids/<uid>/cpu_share" file for this user.
- */
-static int user_kobject_create(struct user_struct *up)
+static struct kobj_type uids_ktype = {
+	.sysfs_ops = &kobj_sysfs_ops,
+	.default_attrs = uids_attributes,
+	.release = uids_release,
+};
+
+/* create /sys/kernel/uids/<uid>/cpu_share file for this user */
+static int uids_user_create(struct user_struct *up)
 {
-	struct kset *kset = &up->kset;
-	struct kobject *kobj = &kset->kobj;
+	struct kobject *kobj = &up->kobj;
 	int error;
 
-	memset(kset, 0, sizeof(struct kset));
-	kobj->parent = &uids_kobject;	/* create under /sys/kernel/uids dir */
-	kobject_set_name(kobj, "%d", up->uid);
-	kset_init(kset);
-	user_attr_init(&up->user_attr, "cpu_share", 0644);
-
+	memset(kobj, 0, sizeof(struct kobject));
+	kobject_init(kobj);
+	kobj->ktype = &uids_ktype;
+	kobj->kset = uids_kset;
+	kobject_set_name(&up->kobj, "%d", up->uid);
 	error = kobject_add(kobj);
 	if (error)
 		goto done;
 
-	error = sysfs_create_file(kobj, &up->user_attr.attr);
-	if (error)
-		kobject_del(kobj);
-
 	kobject_uevent(kobj, KOBJ_ADD);
-
 done:
 	return error;
 }
 
-/* create these in sysfs filesystem:
+/* create these entries in sysfs:
  * 	"/sys/kernel/uids" directory
  * 	"/sys/kernel/uids/0" directory (for root user)
  * 	"/sys/kernel/uids/0/cpu_share" file (for root user)
  */
-int __init uids_kobject_init(void)
+int __init uids_sysfs_init(void)
 {
-	int error;
+	uids_kset = kset_create_and_register("uids", NULL, NULL, kernel_kset);
+	if (IS_ERR(uids_kset))
+		return PTR_ERR(uids_kset);
 
-	/* create under /sys/kernel dir */
-	uids_kobject.parent = &kernel_kset->kobj;
-	uids_kobject.kset = kernel_kset;
-	kobject_set_name(&uids_kobject, "uids");
-	kobject_init(&uids_kobject);
-
-	error = kobject_add(&uids_kobject);
-	if (!error)
-		error = user_kobject_create(&root_user);
-
-	return error;
+	return uids_user_create(&root_user);
 }
 
 /* work function to remove sysfs directory for a user and free up
@@ -216,7 +214,6 @@ int __init uids_kobject_init(void)
 static void remove_user_sysfs_dir(struct work_struct *w)
 {
 	struct user_struct *up = container_of(w, struct user_struct, work);
-	struct kobject *kobj = &up->kset.kobj;
 	unsigned long flags;
 	int remove_user = 0;
 
@@ -238,9 +235,9 @@ static void remove_user_sysfs_dir(struct work_struct *w)
 	if (!remove_user)
 		goto done;
 
-	sysfs_remove_file(kobj, &up->user_attr.attr);
-	kobject_uevent(kobj, KOBJ_REMOVE);
-	kobject_del(kobj);
+	kobject_uevent(&up->kobj, KOBJ_REMOVE);
+	kobject_del(&up->kobj);
+	kobject_put(&up->kobj);
 
 	sched_destroy_user(up);
 	key_put(up->uid_keyring);
@@ -267,7 +264,8 @@ static inline void free_user(struct user_struct *up, unsigned long flags)
 
 #else	/* CONFIG_FAIR_USER_SCHED && CONFIG_SYSFS */
 
-static inline int user_kobject_create(struct user_struct *up) { return 0; }
+int uids_sysfs_init(void) { return 0; }
+static inline int uids_user_create(struct user_struct *up) { return 0; }
 static inline void uids_mutex_lock(void) { }
 static inline void uids_mutex_unlock(void) { }
 
@@ -324,7 +322,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
 	struct hlist_head *hashent = uidhashentry(ns, uid);
 	struct user_struct *up;
 
-	/* Make uid_hash_find() + user_kobject_create() + uid_hash_insert()
+	/* Make uid_hash_find() + uids_user_create() + uid_hash_insert()
 	 * atomic.
 	 */
 	uids_mutex_lock();
@@ -365,7 +363,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
 			return NULL;
 		}
 
-		if (user_kobject_create(new)) {
+		if (uids_user_create(new)) {
 			sched_destroy_user(new);
 			key_put(new->uid_keyring);
 			key_put(new->session_keyring);
-- 
1.5.3.4


  parent reply	other threads:[~2007-11-03  0:12 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02 23:57 [RFC] kobject and kset core changes and cleanups Greg KH
2007-11-02 23:58 ` [PATCH 01/54] ecryptfs: clean up attribute mess Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 02/54] KOBJECT: remove struct kobj_type from struct kset Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 03/54] KOBJECT: remove kobj_set_kset_s as no one is using it anymore Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 04/54] kset: add kset_create_and_register function Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 05/54] kset: convert fuse to use kset_create Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 06/54] kset: convert securityfs " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 07/54] kset: convert debugfs " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 08/54] kset: convert configfs " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 09/54] kset: convert ecryptfs " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 10/54] kset: convert main fs kset " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 11/54] kset: convert gfs2 " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 12/54] kset: convert gfs2 dlm " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 13/54] kset: convert " Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 14/54] kset: convert pci hotplug to use kset_create_and_register Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 15/54] kset: remove decl_subsys_name Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 16/54] kset: convert kernel_subsys to use kset_create Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 17/54] kset: convert drivers/base/bus.c kset_create_and_register Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 18/54] kset: convert drivers/base/class.c kset_create_and_register Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 19/54] kset: convert drivers/base/firmware.c kset_create_and_register Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 20/54] kset: convert /sys/devices to use kset_create Greg Kroah-Hartman
2007-11-02 23:58 ` [PATCH 21/54] kset: convert /sys/hypervisor " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 22/54] kset: convert /sys/devices/system " Greg Kroah-Hartman
2007-11-05 18:11   ` Cornelia Huck
2007-11-05 18:58     ` Greg KH
2007-11-05 19:11       ` Cornelia Huck
2007-11-05 20:03         ` Greg KH
2007-11-13 23:14           ` Andrew Morton
2007-11-14  0:01             ` Andrew Morton
2007-11-14  0:35               ` Greg KH
2007-11-14  7:35                 ` Andrew Morton
2007-11-02 23:59 ` [PATCH 23/54] kset: convert slub " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 24/54] kset: move /sys/slab to /sys/kernel/slab Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 25/54] kset: convert /sys/module to use kset_create Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 26/54] kset: convert /sys/power " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 27/54] kset: convert s390 hypervisor kset " Greg Kroah-Hartman
2007-11-05 13:18   ` Cornelia Huck
2007-11-05 17:06     ` Greg KH
2007-11-02 23:59 ` [PATCH 28/54] kset: convert struct bus_device->devices " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 29/54] kset: convert struct bus_device->drivers " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 30/54] driver core: remove owner field from struct bus_type Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 31/54] driver core: add way to get to bus kset Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 32/54] driver core: add way to get to bus device klist Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 33/54] driver core: remove fields from struct bus_type Greg Kroah-Hartman
2007-11-05 10:33   ` Cornelia Huck
2007-11-05 17:00     ` Greg KH
2007-11-02 23:59 ` [PATCH 34/54] Driver Core: add kobj_attribute handling Greg Kroah-Hartman
2007-11-05 12:42   ` Cornelia Huck
2007-11-05 16:23     ` Kay Sievers
2007-11-05 17:11       ` Greg KH
2007-11-05 17:25         ` Kay Sievers
2007-11-05 17:43           ` Cornelia Huck
2007-11-05 18:07             ` Kay Sievers
2007-11-05 18:17               ` Cornelia Huck
2007-11-05 18:39                 ` Kay Sievers
2007-11-05 18:46                   ` Greg KH
2007-11-05 18:59                   ` Cornelia Huck
2007-11-05 20:01                     ` Greg KH
2007-11-02 23:59 ` [PATCH 35/54] Driver Core: switch all dynamic ksets to kobj_sysfs_ops Greg Kroah-Hartman
2007-11-02 23:59 ` Greg Kroah-Hartman [this message]
2007-11-02 23:59 ` [PATCH 37/54] ecryptfs: remove version_str file from sysfs Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 38/54] efivars: remove new_var and del_var files " Greg Kroah-Hartman
2007-11-16 15:01   ` Matt Domsch
2007-11-27  5:47     ` Greg KH
2007-11-02 23:59 ` [PATCH 39/54] kobject: convert efivars to kobj_attr interface Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 40/54] firmware: export firmware_kset so that people can use that instead of the braindead firmware_register interface Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 41/54] kset: convert efivars to use kset_create for the efi subsystem Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 42/54] kset: convert efivars to use kset_create for the vars sub-subsystem Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 43/54] kobject: convert arm/mach-omap1/pm.c to kobj_attr interface Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 44/54] kobject: convert pseries/power.c " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 45/54] kobject: convert s390 ipl.c " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 46/54] kset: convert s390 ipl.c to use kset_create Greg Kroah-Hartman
2007-11-05 10:27   ` Cornelia Huck
2007-11-05 17:05     ` Greg KH
2007-11-02 23:59 ` [PATCH 47/54] kobject: convert parisc/pdc_stable to kobj_attr interface Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 48/54] kset: convert parisc/pdc_stable.c to use kset_create Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 49/54] Driver Core: kill subsys_attribute and default sysfs ops Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 50/54] kset: convert edd to use kset_create Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 51/54] kset: convert acpi " Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 52/54] firmware: remove firmware_(un)register() Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 53/54] kset: convert ocfs2 to use kset_create Greg Kroah-Hartman
2007-11-02 23:59 ` [PATCH 54/54] kset: remove decl_subsys macro Greg Kroah-Hartman
2007-11-06  6:25 ` [RFC] kobject and kset core changes and cleanups Andrew Morton
2007-11-06  7:11 ` Andrew Morton
2007-11-06  8:14   ` Stephane Eranian
2007-11-06 21:15     ` Greg KH
2007-11-06 21:33       ` Stephane Eranian
2007-11-06  8:04 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1194047972-9850-36-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=dhaval@linux.vnet.ibm.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vatsa@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox