[Ocfs2-commits] jlbec commits r1956 - trunk/fs/usysfs

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Mar 7 16:51:28 CST 2005


Author: jlbec
Signed-off-by: manish
Date: 2005-03-07 16:51:26 -0600 (Mon, 07 Mar 2005)
New Revision: 1956

Removed:
   trunk/fs/usysfs/group.c
Modified:
   trunk/fs/usysfs/dir.c
   trunk/fs/usysfs/usysfs.h
Log:

o Move attr creation about to prepare for default_sets.

Signed-off-by: manish



Modified: trunk/fs/usysfs/dir.c
===================================================================
--- trunk/fs/usysfs/dir.c	2005-03-07 22:51:19 UTC (rev 1955)
+++ trunk/fs/usysfs/dir.c	2005-03-07 22:51:26 UTC (rev 1956)
@@ -146,6 +146,47 @@
 	return error;
 }
 
+static void remove_dir(struct dentry * d)
+{
+	struct dentry * parent = dget(d->d_parent);
+	struct usysfs_dirent * sd;
+
+	sd = d->d_fsdata;
+ 	list_del_init(&sd->s_sibling);
+	usysfs_put(sd);
+	if (d->d_inode)
+		simple_rmdir(parent->d_inode,d);
+
+	pr_debug(" o %s removing done (%d)\n",d->d_name.name,
+		 atomic_read(&d->d_count));
+
+	dput(parent);
+}
+
+/**
+ *	usysfs_remove_dir - remove an object's directory.
+ *	@kobj:	object. 
+ *
+ *	The only thing special about this is that we remove any files in 
+ *	the directory before we remove the directory, and we've inlined
+ *	what used to be usysfs_rmdir() below, instead of calling separately.
+ */
+
+static void usysfs_remove_dir(struct kobject * kobj)
+{
+	struct dentry * dentry = dget(kobj->dentry);
+
+	if (!dentry)
+		return;
+
+	remove_dir(dentry);
+	/**
+	 * Drop reference from dget() on entrance.
+	 */
+	dput(dentry);
+}
+
+
 /* attaches attribute's usysfs_dirent to the dentry corresponding to the
  * attribute file
  */
@@ -239,7 +280,8 @@
 	struct usysfs_dirent *sd;
 
 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
-		if (sd->s_type & USYSFS_NOT_PINNED)
+		if (sd->s_type & (USYSFS_NOT_PINNED |
+				  USYSFS_DEFAULT_DIR))
 			continue;
 		return 0;
 	}
@@ -247,8 +289,35 @@
 	return 1;
 }
 
-static int populate_dir(struct kobject *kobj)
+static void drop_attrs(struct kobject * kobj)
 {
+	struct dentry * dentry = dget(kobj->dentry);
+	struct usysfs_dirent * parent_sd;
+	struct usysfs_dirent * sd, * tmp;
+
+	if (!dentry)
+		return;
+
+	pr_debug("usysfs %s: dropping attrs for  dir\n",
+		 dentry->d_name.name);
+
+	parent_sd = dentry->d_fsdata;
+	list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
+		if (!sd->s_element || !(sd->s_type & USYSFS_NOT_PINNED))
+			continue;
+		list_del_init(&sd->s_sibling);
+		usysfs_drop_dentry(sd, dentry);
+		usysfs_put(sd);
+	}
+
+	/**
+	 * Drop reference from dget() on entrance.
+	 */
+	dput(dentry);
+}
+
+static int populate_attrs(struct kobject *kobj)
+{
 	struct kobj_type *t = get_ktype(kobj);
 	struct attribute *attr;
 	int error = 0;
@@ -263,6 +332,9 @@
 		}
 	}
 
+	if (error)
+		drop_attrs(kobj);
+
 	return error;
 }
 
@@ -270,7 +342,7 @@
  * Remove an object from its kset and decrement the refcount.
  * This is used by both rmdir() and by mkdir() on error.
  */
-static void unlink(struct kobject *kobj)
+static void unlink_obj(struct kobject *kobj)
 {
 	struct ukobj_type *uktype;
 	struct module *owner = NULL;
@@ -279,15 +351,61 @@
 		down(&usysfs_linkage_sem);
 		list_del_init(&kobj->entry);
 		up(&usysfs_linkage_sem);
+		kobj->kset = NULL;
+		kobj->parent = NULL;
 	}
 	uktype = to_uktype(kobj->ktype);
 	if (uktype)
 		owner = uktype->owner;
 
+	/* kobject_cleanup() drops the parent ref from link_obj() */
 	kobject_put(kobj);
 	module_put(owner);
 }
 
+static int link_obj(struct kobject *parent_kobj, struct kobject *kobj)
+{
+	struct ukobj_type *uktype;
+	struct module *owner = NULL;
+	int rc = 1;
+
+	uktype = to_uktype(kobj->ktype);
+	if (uktype) {
+		owner = uktype->owner;
+		if (try_module_get(owner)) {
+			kobj->kset = kset_get(to_kset(parent_kobj));
+
+			down(&usysfs_linkage_sem);
+			list_add_tail(&kobj->entry, &kobj->kset->list);
+			up(&usysfs_linkage_sem);
+
+			kobj->parent = parent_kobj;
+			kobject_get(kobj);
+			rc = 0;
+		}
+	}
+
+	return rc;
+}
+
+static int usysfs_instantiate_object(struct kobject *kobj,
+				     struct dentry *dentry)
+{
+	int ret;
+
+	ret = usysfs_create_dir(kobj, dentry);
+	if (!ret) {
+		ret = populate_attrs(kobj);
+		if (ret) {
+			usysfs_remove_dir(kobj);
+			d_delete(dentry);
+		}
+	}
+
+	return ret;
+}
+
+
 static int usysfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 {
 	int ret;
@@ -326,34 +444,19 @@
 		return -ENOMEM;
 	}
 
-	uktype = to_uktype(kobj->ktype);
-	if (!uktype || !try_module_get(uktype->owner)) {
+	if (link_obj(parent_kobj, kobj)) {
 		kobject_put(kobj);
 		kobject_put(parent_kobj);
 		return -ENOENT;
 	}
 
-	kobj->kset = kset_get(to_kset(parent_kobj));
-	down(&usysfs_linkage_sem);
-	list_add_tail(&kobj->entry, &kobj->kset->list);
-	up(&usysfs_linkage_sem);
-	kobj->parent = parent_kobj;
-
-	ret = usysfs_create_dir(kobj, dentry);
+	ret = usysfs_instantiate_object(kobj, dentry);
 	if (ret) {
-		unlink(kobj);
+		unlink_obj(kobj);
 		kobject_put(parent_kobj);
 		return ret;
 	}
 
-	ret = populate_dir(kobj);
-	if (ret) {
-		usysfs_remove_dir(kobj);
-		d_delete(dentry);
-		unlink(kobj);
-		kobject_put(parent_kobj);
-	}
-
 	return ret;
 }
 
@@ -385,6 +488,7 @@
 	/* Drop reference from above, kobj already holds one. */
 	kobject_put(parent_kobj); 
 
+	drop_attrs(kobj);
 	usysfs_remove_dir(kobj);
 
 	if (uktype->drop_object)
@@ -392,7 +496,7 @@
 	else 
 		kobject_put(kobj);
 
-	unlink(kobj);
+	unlink_obj(kobj);
 
 	return 0;
 }
@@ -413,65 +517,6 @@
 	.lookup		= usysfs_lookup_compat,
 #endif
 };
-
-static void remove_dir(struct dentry * d)
-{
-	struct dentry * parent = dget(d->d_parent);
-	struct usysfs_dirent * sd;
-
-	sd = d->d_fsdata;
- 	list_del_init(&sd->s_sibling);
-	usysfs_put(sd);
-	if (d->d_inode)
-		simple_rmdir(parent->d_inode,d);
-
-	pr_debug(" o %s removing done (%d)\n",d->d_name.name,
-		 atomic_read(&d->d_count));
-
-	dput(parent);
-}
-
-void usysfs_remove_subdir(struct dentry * d)
-{
-	remove_dir(d);
-}
-
-
-/**
- *	usysfs_remove_dir - remove an object's directory.
- *	@kobj:	object. 
- *
- *	The only thing special about this is that we remove any files in 
- *	the directory before we remove the directory, and we've inlined
- *	what used to be usysfs_rmdir() below, instead of calling separately.
- */
-
-void usysfs_remove_dir(struct kobject * kobj)
-{
-	struct dentry * dentry = dget(kobj->dentry);
-	struct usysfs_dirent * parent_sd;
-	struct usysfs_dirent * sd, * tmp;
-
-	if (!dentry)
-		return;
-
-	pr_debug("usysfs %s: removing dir\n",dentry->d_name.name);
-	parent_sd = dentry->d_fsdata;
-	list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
-		if (!sd->s_element || !(sd->s_type & USYSFS_NOT_PINNED))
-			continue;
-		list_del_init(&sd->s_sibling);
-		usysfs_drop_dentry(sd, dentry);
-		usysfs_put(sd);
-	}
-
-	remove_dir(dentry);
-	/**
-	 * Drop reference from dget() on entrance.
-	 */
-	dput(dentry);
-}
-
 int usysfs_rename_dir(struct kobject * kobj, const char *new_name)
 {
 	int error = 0;
@@ -675,16 +720,11 @@
 	
 	d_add(dentry, NULL);
 
-	err = usysfs_create_dir(&k->kobj, dentry);
-	if (!err) {
-		err = populate_dir(&k->kobj);
-		if (!err)
-			dentry = NULL;
-		else {
-			usysfs_remove_dir(&k->kobj);
-			d_delete(dentry);
-		}
-	}
+	err = usysfs_instantiate_object(&k->kobj, dentry);
+	if (!err)
+		dentry = NULL;
+	else
+		d_delete(dentry);
 
 	up(&usysfs_sb->s_root->d_inode->i_sem);
 
@@ -712,8 +752,10 @@
 	if (!usysfs_empty_dir(k->kobj.dentry)) {
 		printk(KERN_ERR "usysfs: Tried to unregister non-empty subsystem!\n");
 	}
+	drop_attrs(&k->kobj);
 	usysfs_remove_dir(&k->kobj);
 	up(&usysfs_sb->s_root->d_inode->i_sem);
+
 	d_delete(k->kobj.dentry);
 	dput(k->kobj.dentry);
 	usysfs_release_fs();
@@ -721,8 +763,3 @@
 
 EXPORT_SYMBOL_GPL(usysfs_register_subsystem);
 EXPORT_SYMBOL_GPL(usysfs_unregister_subsystem);
-#if 0
-EXPORT_SYMBOL_GPL(usysfs_create_dir);
-EXPORT_SYMBOL_GPL(usysfs_remove_dir);
-EXPORT_SYMBOL_GPL(usysfs_rename_dir);
-#endif

Deleted: trunk/fs/usysfs/group.c
===================================================================
--- trunk/fs/usysfs/group.c	2005-03-07 22:51:19 UTC (rev 1955)
+++ trunk/fs/usysfs/group.c	2005-03-07 22:51:26 UTC (rev 1956)
@@ -1,85 +0,0 @@
-/*
- * fs/usysfs/group.c - Operations for adding/removing multiple files at once.
- *
- * Copyright (c) 2003 Patrick Mochel
- * Copyright (c) 2003 Open Source Development Lab
- *
- * This file is released undert the GPL v2. 
- *
- */
-
-#include <linux/kobject.h>
-#include <linux/module.h>
-#include <linux/dcache.h>
-#include <linux/err.h>
-#include "usysfs.h"
-#include "usysfs_internal.h"
-
-
-static void remove_files(struct dentry * dir, 
-			 const struct attribute_group * grp)
-{
-	struct attribute *const* attr;
-
-	for (attr = grp->attrs; *attr; attr++)
-		usysfs_hash_and_remove(dir,(*attr)->name);
-}
-
-static int create_files(struct dentry * dir,
-			const struct attribute_group * grp)
-{
-	struct attribute *const* attr;
-	int error = 0;
-
-	for (attr = grp->attrs; *attr && !error; attr++) {
-		error = usysfs_add_file(dir, *attr, USYSFS_KOBJ_ATTR);
-	}
-	if (error)
-		remove_files(dir,grp);
-	return error;
-}
-
-
-int usysfs_create_group(struct kobject * kobj, 
-		       const struct attribute_group * grp)
-{
-	struct dentry * dir;
-	int error;
-
-	BUG_ON(!kobj || !kobj->dentry);
-
-	if (grp->name) {
-		error = usysfs_create_subdir(kobj,grp->name,&dir);
-		if (error)
-			return error;
-	} else
-		dir = kobj->dentry;
-	dir = dget(dir);
-	if ((error = create_files(dir,grp))) {
-		if (grp->name)
-			usysfs_remove_subdir(dir);
-	}
-	dput(dir);
-	return error;
-}
-
-void usysfs_remove_group(struct kobject * kobj, 
-			const struct attribute_group * grp)
-{
-	struct dentry * dir;
-
-	if (grp->name)
-		dir = usysfs_get_dentry(kobj->dentry,grp->name);
-	else
-		dir = dget(kobj->dentry);
-
-	remove_files(dir,grp);
-	if (grp->name)
-		usysfs_remove_subdir(dir);
-	/* release the ref. taken in this routine */
-	dput(dir);
-}
-
-
-EXPORT_SYMBOL_GPL(usysfs_create_group);
-EXPORT_SYMBOL_GPL(usysfs_remove_group);

Modified: trunk/fs/usysfs/usysfs.h
===================================================================
--- trunk/fs/usysfs/usysfs.h	2005-03-07 22:51:19 UTC (rev 1955)
+++ trunk/fs/usysfs/usysfs.h	2005-03-07 22:51:26 UTC (rev 1956)
@@ -35,14 +35,19 @@
 /*
  * Usysfs objects must have a ->ktype of type ukobj_type.
  * If allow_link() exists, the object can symlink(2) out to other
- * objects.  If the object is a kset, it supports mkdir(2).  The object
- * either supports make_kset() if its children are ksets or
- * make_object() if its children are mere objects.  If the kset has
- * commit(), it supports pending and commited (active) objects.
+ * objects.  If the object is a kset, it may support mkdir(2).  If the
+ * object supports make_kset(), one can create kset children.  If it
+ * supports make_object(), one can create kobject children.  If it has
+ * default_sets, it has automatically created kset children.
+ * default_sets may coexist alongsize make_kset() or make_object(), but
+ * an object can only have one or zero of mkae_kset() and make_object().
+ * If the kset has commit(), it supports pending and commited (active)
+ * objects.
  */
 struct ukobj_type {
 	struct kobj_type ktype;
 	struct module *owner;
+	struct kset **default_sets;
 	int (*allow_link)(struct kobject *src, struct kobject *target);
 	struct kobject *(*make_object)(struct kset *kset, const char *name);
 	struct kset *(*make_kset)(struct kset *kset, const char *name);
@@ -108,14 +113,12 @@
 #define USYSFS_KOBJ_ATTR 	0x0004
 #define USYSFS_KOBJ_BIN_ATTR	0x0008
 #define USYSFS_KOBJ_LINK 	0x0020
-#define USYSFS_NOT_PINNED	(USYSFS_KOBJ_ATTR | USYSFS_KOBJ_BIN_ATTR | USYSFS_KOBJ_LINK)
+#define USYSFS_DEFAULT_DIR	0x0040
+#define USYSFS_NOT_PINNED	(USYSFS_KOBJ_ATTR | USYSFS_KOBJ_BIN_ATTR)
 
 #define CONFIG_USYSFS
 #ifdef CONFIG_USYSFS
 
-extern void
-usysfs_remove_dir(struct kobject *);
-
 extern int
 usysfs_rename_dir(struct kobject *, const char *new_name);
 
@@ -137,23 +140,10 @@
 int usysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
 int usysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
 
-int usysfs_create_group(struct kobject *, const struct attribute_group *);
-void usysfs_remove_group(struct kobject *, const struct attribute_group *);
-
 int usysfs_register_subsystem(struct kset *k);
 void usysfs_unregister_subsystem(struct kset *k);
 #else /* CONFIG_SYSFS */
 
-static inline int usysfs_create_dir(struct kobject * k)
-{
-	return 0;
-}
-
-static inline void usysfs_remove_dir(struct kobject * k)
-{
-	;
-}
-
 static inline int usysfs_rename_dir(struct kobject * k, const char *new_name)
 {
 	return 0;
@@ -195,16 +185,7 @@
 	return 0;
 }
 
-static inline int usysfs_create_group(struct kobject * k, const struct attribute_group *g)
-{
-	return 0;
-}
 
-static inline void usysfs_remove_group(struct kobject * k, const struct attribute_group * g)
-{
-	;
-}
-
 #endif /* CONFIG_USYSFS */
 
 #endif /* _USYSFS_H_ */



More information about the Ocfs2-commits mailing list