[Ocfs2-commits] jlbec commits r1850 - in trunk: . fs fs/usysfs fs/usysfs/compatinclude fs/usysfs/compatinclude/linux

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jan 25 17:23:59 CST 2005


Author: jlbec
Date: 2005-01-25 17:23:57 -0600 (Tue, 25 Jan 2005)
New Revision: 1850

Added:
   trunk/fs/usysfs/compat_kobject.c
   trunk/fs/usysfs/compat_libfs.c
   trunk/fs/usysfs/compatinclude/
   trunk/fs/usysfs/compatinclude/linux/
   trunk/fs/usysfs/compatinclude/linux/backing-dev.h
   trunk/fs/usysfs/compatinclude/linux/compat.h
   trunk/fs/usysfs/compatinclude/linux/compat_libfs.h
   trunk/fs/usysfs/compatinclude/linux/kobject.h
   trunk/fs/usysfs/compatinclude/linux/kref.h
   trunk/fs/usysfs/compatinclude/linux/namei.h
   trunk/fs/usysfs/compatinclude/linux/sysfs.h
Modified:
   trunk/
   trunk/fs/Makefile
   trunk/fs/usysfs/Makefile
   trunk/fs/usysfs/bin.c
   trunk/fs/usysfs/bobtest.c
   trunk/fs/usysfs/dir.c
   trunk/fs/usysfs/file.c
   trunk/fs/usysfs/group.c
   trunk/fs/usysfs/inode.c
   trunk/fs/usysfs/mount.c
   trunk/fs/usysfs/symlink.c
   trunk/fs/usysfs/usysfs.h
   trunk/fs/usysfs/usysfs_internal.h
Log:

o Make compilation on 2.4 work.




Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
   - configure
Config.make
config.cache
config.log
config.status
autom4te.cache
*.rpm
*.tar.gz

   + configure
Config.make
config.cache
config.log
config.status
autom4te.cache
*.rpm
*.tar.gz
.*.sw?


Modified: trunk/fs/Makefile
===================================================================
--- trunk/fs/Makefile	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/Makefile	2005-01-25 23:23:57 UTC (rev 1850)
@@ -64,8 +64,7 @@
 
 # WARNING WARNING WARNING HACK HACK HACK
 # 2.4 doesn't build usysfs yet
-#SUBDIRS = $(SAFE_SUBDIRS)
-SUBDIRS = $(filter-out usysfs,$(SAFE_SUBDIRS))
+SUBDIRS = $(SAFE_SUBDIRS)
 
 endif
 

Modified: trunk/fs/usysfs/Makefile
===================================================================
--- trunk/fs/usysfs/Makefile	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/Makefile	2005-01-25 23:23:57 UTC (rev 1850)
@@ -16,10 +16,30 @@
 # Called from a regular "make".
 #
 
-HEADERS = usysfs.h usysfs_internal.h
-USYSFS_SOURCES = bin.c dir.c file.c inode.c mount.c symlink.c
+HEADERS =					\
+	usysfs.h				\
+	usysfs_internal.h			\
+	compatinclude/linux/compat.h		\
+	compatinclude/linux/kref.h		\
+	compatinclude/linux/kobject.h		\
+	compatinclude/linux/sysfs.h		\
+	compatinclude/linux/compat_libfs.h
+
+# Get the kobject includes, as this is a 2.4 build
+EXTRA_CFLAGS += -I$(TOPDIR)/fs/usysfs/compatinclude
+
+USYSFS_SOURCES = 		\
+	bin.c 			\
+	dir.c			\
+	file.c			\
+	inode.c			\
+	mount.c			\
+	symlink.c		\
+	compat_kobject.c	\
+	compat_libfs.c
+USYSFS_OBJECTS = $(subst .c,.o,$(USYSFS_SOURCES))
+
 BOBTEST_SOURCES = bobtest.c
-USYSFS_OBJECTS = $(subst .c,.o,$(USYSFS_SOURCES))
 BOBTEST_OBJECTS = $(subst .c,.o,$(BOBTEST_SOURCES))
 
 DIST_FILES = $(USYSFS_SOURCES) $(BOBTEST_SOURCES) $(HEADERS) Kbuild
@@ -35,28 +55,31 @@
 
 INSTALL_RULES = install-modules
 
+DIST_RULES = dist-subdircreate
 
+dist-subdircreate:
+	$(TOPDIR)/mkinstalldirs $(DIST_DIR)/compatinclude/linux
+
+
 ifneq ($(KERNEL_26),)
 #
 # This is a 2.6 kernel. Just forward to kbuild.
 #
 
 build-modules:
-	$(MAKE) -C $(KERNELDIR) M=$(CURDIR) modules
+	$(MAKE) -C $(TOPDIR)/fs build-modules
 
 install-modules:
-	$(MAKE) -C $(KERNELDIR) M=$(CURDIR) modules_install
+	$(MAKE) -C $(TOPDIR)/fs install-modules
 
 clean-modules:
-	$(MAKE) -C $(KERNELDIR) M=$(CURDIR) clean
+	$(MAKE) -C $(TOPDIR)/fs clean-modules
 else
 #
 # This is a 2.4 kernel.  Because Red Hat's source tree is whack, do
 # everything by hand.
 #
 
-INSTALL_DIR = usysfs
-
 include $(TOPDIR)/Kbuild-24.make
 
 endif

Modified: trunk/fs/usysfs/bin.c
===================================================================
--- trunk/fs/usysfs/bin.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/bin.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -161,7 +161,7 @@
 {
 	BUG_ON(!kobj || !kobj->dentry || !attr);
 
-	return usysfs_add_file(kobj->dentry, &attr->attr, SYSFS_KOBJ_BIN_ATTR);
+	return usysfs_add_file(kobj->dentry, &attr->attr, USYSFS_KOBJ_BIN_ATTR);
 }
 
 

Modified: trunk/fs/usysfs/bobtest.c
===================================================================
--- trunk/fs/usysfs/bobtest.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/bobtest.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -3,8 +3,10 @@
  */
 
 #include <linux/init.h>
+#include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/kobject.h>
+#include <linux/slab.h>
 #include "usysfs.h"
 
 

Added: trunk/fs/usysfs/compat_kobject.c
===================================================================
--- trunk/fs/usysfs/compat_kobject.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compat_kobject.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,200 @@
+/*
+ * kobject.c - library routines for handling generic kernel objects
+ *
+ * Copyright (c) 2002-2003 Patrick Mochel <mochel at osdl.org>
+ *
+ * This file is released under the GPLv2.
+ *
+ *
+ * Please see the file Documentation/kobject.txt for critical information
+ * about using the kobject interface.
+ *
+ * 2005.01.24
+ *      Stripped down for 2.4 compat in usysfs.
+ *      Joel Becker <joel.becker at oracle.com>
+ */
+
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/module.h>
+#include <linux/stat.h>
+#include <linux/slab.h>
+
+
+static inline struct kobject * to_kobj(struct list_head * entry)
+{
+	return container_of(entry,struct kobject,entry);
+}
+
+
+/**
+ *	kobject_init - initialize object.
+ *	@kobj:	object in question.
+ */
+void kobject_init(struct kobject * kobj)
+{
+	kref_init(&kobj->kref);
+	INIT_LIST_HEAD(&kobj->entry);
+	kobj->kset = kset_get(kobj->kset);
+}
+
+/**
+ *	kobject_set_name - Set the name of an object
+ *	@kobj:	object.
+ *	@name:	name. 
+ *
+ *	If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
+ *	string that @kobj->k_name points to. Otherwise, use the static 
+ *	@kobj->name array.
+ */
+
+int kobject_set_name(struct kobject * kobj, const char * fmt, ...)
+{
+	int error = 0;
+	int limit = KOBJ_NAME_LEN;
+	int need;
+	va_list args;
+	char * name;
+
+	/* 
+	 * First, try the static array 
+	 */
+	va_start(args,fmt);
+	need = vsnprintf(kobj->name,limit,fmt,args);
+	va_end(args);
+	if (need < limit) 
+		name = kobj->name;
+	else {
+		/* 
+		 * Need more space? Allocate it and try again 
+		 */
+		limit = need + 1;
+		name = kmalloc(limit,GFP_KERNEL);
+		if (!name) {
+			error = -ENOMEM;
+			goto Done;
+		}
+		va_start(args,fmt);
+		need = vsnprintf(name,limit,fmt,args);
+		va_end(args);
+
+		/* Still? Give up. */
+		if (need >= limit) {
+			kfree(name);
+			error = -EFAULT;
+			goto Done;
+		}
+	}
+
+	/* Free the old name, if necessary. */
+	if (kobj->k_name && kobj->k_name != kobj->name)
+		kfree(kobj->k_name);
+
+	/* Now, set the new name */
+	kobj->k_name = name;
+ Done:
+	return error;
+}
+
+EXPORT_SYMBOL(kobject_set_name);
+
+struct kobject * kobject_get(struct kobject * kobj)
+{
+	if (kobj)
+		kref_get(&kobj->kref);
+	return kobj;
+}
+
+/**
+ *	kobject_cleanup - free kobject resources. 
+ *	@kobj:	object.
+ */
+
+void kobject_cleanup(struct kobject * kobj)
+{
+	struct kobj_type * t = get_ktype(kobj);
+	struct kset * s = kobj->kset;
+	struct kobject * parent = kobj->parent;
+
+	pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
+	if (kobj->k_name != kobj->name)
+		kfree(kobj->k_name);
+	kobj->k_name = NULL;
+	if (t && t->release)
+		t->release(kobj);
+	if (s)
+		kset_put(s);
+	if (parent) 
+		kobject_put(parent);
+}
+
+static void kobject_release(struct kref *kref)
+{
+	kobject_cleanup(container_of(kref, struct kobject, kref));
+}
+
+/**
+ *	kobject_put - decrement refcount for object.
+ *	@kobj:	object.
+ *
+ *	Decrement the refcount, and if 0, call kobject_cleanup().
+ */
+void kobject_put(struct kobject * kobj)
+{
+	if (kobj)
+		kref_put(&kobj->kref, kobject_release);
+}
+
+
+/**
+ *	kset_init - initialize a kset for use
+ *	@k:	kset 
+ */
+
+void kset_init(struct kset * k)
+{
+	kobject_init(&k->kobj);
+	INIT_LIST_HEAD(&k->list);
+}
+
+
+/**
+ *	kset_find_obj - search for object in kset.
+ *	@kset:	kset we're looking in.
+ *	@name:	object's name.
+ *
+ *	Lock kset via @kset->subsys, and iterate over @kset->list,
+ *	looking for a matching kobject. If matching object is found
+ *	take a reference and return the object.
+ */
+
+struct kobject * kset_find_obj(struct kset * kset, const char * name)
+{
+	struct list_head * entry;
+	struct kobject * ret = NULL;
+
+	down_read(&kset->subsys->rwsem);
+	list_for_each(entry,&kset->list) {
+		struct kobject * k = to_kobj(entry);
+		if (kobject_name(k) && !strcmp(kobject_name(k),name)) {
+			ret = kobject_get(k);
+			break;
+		}
+	}
+	up_read(&kset->subsys->rwsem);
+	return ret;
+}
+
+
+void subsystem_init(struct subsystem * s)
+{
+	init_rwsem(&s->rwsem);
+	kset_init(&s->kset);
+}
+
+
+EXPORT_SYMBOL(kobject_init);
+EXPORT_SYMBOL(kobject_get);
+EXPORT_SYMBOL(kobject_put);
+
+EXPORT_SYMBOL(subsystem_init);

Added: trunk/fs/usysfs/compat_libfs.c
===================================================================
--- trunk/fs/usysfs/compat_libfs.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compat_libfs.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,184 @@
+#include <linux/module.h>
+#include <linux/pagemap.h>
+#include <linux/mount.h>
+#include <linux/fs.h>
+
+#include "linux/compat.h"
+#include "linux/compat_libfs.h"
+
+
+static inline int simple_positive(struct dentry *dentry)
+{
+	return dentry->d_inode && !d_unhashed(dentry);
+}
+
+/*
+ * Check that a directory is empty (this works
+ * for regular files too, they'll just always be
+ * considered empty..).
+ *
+ * Note that an empty directory can still have
+ * children, they just all have to be negative..
+ */
+static int simple_empty(struct dentry *dentry)
+{
+	struct list_head *list;
+
+	spin_lock(&dcache_lock);
+	list = dentry->d_subdirs.next;
+
+	while (list != &dentry->d_subdirs) {
+		struct dentry *de = list_entry(list, struct dentry, d_child);
+
+		if (simple_positive(de)) {
+			spin_unlock(&dcache_lock);
+			return 0;
+		}
+		list = list->next;
+	}
+	spin_unlock(&dcache_lock);
+	return 1;
+}
+
+/*
+ * This works for both directories and regular files.
+ * (non-directories will always have empty subdirs)
+ */
+int simple_unlink(struct inode * dir, struct dentry *dentry)
+{
+	int retval = -ENOTEMPTY;
+
+	if (simple_empty(dentry)) {
+		struct inode *inode = dentry->d_inode;
+
+		inode->i_nlink--;
+		dput(dentry);			/* Undo the count from "create" - this does all the work */
+		retval = 0;
+	}
+	return retval;
+}
+
+/*
+ * Lookup the data. This is trivial - if the dentry didn't already
+ * exist, we know it is negative.
+ */
+struct dentry * simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
+{
+	d_add(dentry, NULL);
+	return NULL;
+}
+
+int simple_statfs(struct super_block *sb, struct statfs *buf)
+{
+	buf->f_type = sb->s_magic;
+	buf->f_bsize = PAGE_CACHE_SIZE;
+	buf->f_namelen = 255;
+	return 0;
+}
+
+int simple_readpage(struct file *file, struct page *page)
+{
+	void *kaddr;
+
+	if (Page_Uptodate(page))
+		goto out;
+
+	kaddr = kmap_atomic(page, KM_USER0);
+	memset(kaddr, 0, PAGE_CACHE_SIZE);
+	kunmap_atomic(kaddr, KM_USER0);
+	flush_dcache_page(page);
+	SetPageUptodate(page);
+out:
+	unlock_page(page);
+	return 0;
+}
+
+int simple_prepare_write(struct file *file, struct page *page,
+			unsigned from, unsigned to)
+{
+	if (!Page_Uptodate(page)) {
+		if (to - from != PAGE_CACHE_SIZE) {
+			void *kaddr = kmap_atomic(page, KM_USER0);
+			memset(kaddr, 0, from);
+			memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
+			flush_dcache_page(page);
+			kunmap_atomic(kaddr, KM_USER0);
+		}
+		SetPageUptodate(page);
+	}
+	return 0;
+}
+
+int simple_commit_write(struct file *file, struct page *page,
+			unsigned offset, unsigned to)
+{
+	struct inode *inode = page->mapping->host;
+	loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
+
+	/*
+	 * No need to use i_size_read() here, the i_size
+	 * cannot change under us because we hold the i_sem.
+	 */
+	if (pos > inode->i_size)
+		i_size_write(inode, pos);
+	set_page_dirty(page);
+	return 0;
+}
+
+static void put_filesystem(struct file_system_type *fs)
+{
+    if (fs->owner)
+        __MOD_DEC_USE_COUNT(fs->owner);
+}
+
+/*
+ * Wow, this is ugly.  We go from name -> fstype so we can
+ * call 2.4's kern_mount, which goes from type to name and then
+ * calls the unexported do_kern_mount from 2.4, which goes from
+ * name -> fstype again.
+ */
+static struct vfsmount *
+do_kern_mount(const char *fstype, int flags, char *name, void *data)
+{
+    struct file_system_type *type = get_fs_type(fstype);
+    struct vfsmount *mnt;
+
+    if (!type)
+        return ERR_PTR(-ENODEV);
+    mnt = kern_mount(type);
+    put_filesystem(type);
+    return mnt;
+}
+
+static spinlock_t pin_fs_lock = SPIN_LOCK_UNLOCKED;
+
+int simple_pin_fs(char *name, struct vfsmount **mount, int *count)
+{
+	struct vfsmount *mnt = NULL;
+	spin_lock(&pin_fs_lock);
+	if (unlikely(!*mount)) {
+		spin_unlock(&pin_fs_lock);
+		mnt = do_kern_mount(name, 0, name, NULL);
+		if (IS_ERR(mnt))
+			return PTR_ERR(mnt);
+		spin_lock(&pin_fs_lock);
+		if (!*mount)
+			*mount = mnt;
+	}
+	mntget(*mount);
+	++*count;
+	spin_unlock(&pin_fs_lock);
+	mntput(mnt);
+	return 0;
+}
+
+void simple_release_fs(struct vfsmount **mount, int *count)
+{
+	struct vfsmount *mnt;
+	spin_lock(&pin_fs_lock);
+	mnt = *mount;
+	if (!--*count)
+		*mount = NULL;
+	spin_unlock(&pin_fs_lock);
+	mntput(mnt);
+}

Added: trunk/fs/usysfs/compatinclude/linux/backing-dev.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/backing-dev.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/backing-dev.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,9 @@
+/*
+ * backing-dev.h - compatibility header for 2.4 compiling
+ */
+
+
+struct backing_dev_info {
+	unsigned long ra_pages;
+	int memory_backed;
+};

Added: trunk/fs/usysfs/compatinclude/linux/compat.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/compat.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/compat.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,77 @@
+/*
+ * compat.h - Doing anything and everything to keep LINUX_VERSION_CODE
+ * checks out of the regular .c files.
+ */
+#ifndef _COMPAT_H
+#define _COMPAT_H
+
+#include <linux/fs.h>
+#include <linux/compiler.h>
+
+#ifndef container_of
+#define container_of(ptr, type, member) ({			\
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (char *)__mptr - offsetof(type, member) );})
+#endif
+
+#ifndef __user
+#define __user
+#endif
+
+#ifndef BUG_ON
+#define BUG_ON(condition) do { if (unlikely((condition) != 0)) BUG(); } while (0)
+#endif
+
+#ifndef WARN_ON
+#define WARN_ON(condition) do { \
+	if (unlikely((condition) != 0)) { \
+		printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
+		dump_stack(); \
+	} \
+} while (0)
+#endif
+
+#define try_module_get(mod) try_inc_mod_count(mod)
+#define module_put(mod) __MOD_DEC_USE_COUNT(mod)
+
+#ifndef list_for_each_entry_safe
+#define list_for_each_entry_safe(pos, n, head, member)			\
+	for (pos = list_entry((head)->next, typeof(*pos), member),	\
+		n = list_entry(pos->member.next, typeof(*pos), member);	\
+	     &pos->member != (head); 					\
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#endif
+
+static inline ino_t parent_ino(struct dentry *dentry)
+{
+	ino_t res;
+
+	spin_lock(&dcache_lock);
+	res = dentry->d_parent->d_inode->i_ino;
+	spin_unlock(&dcache_lock);
+	return res;
+}
+
+static inline void __d_drop(struct dentry *dentry)
+{
+	list_del(&dentry->d_hash);
+	INIT_LIST_HEAD(&dentry->d_hash);
+}
+
+static inline loff_t i_size_read(struct inode *inode)
+{
+	return inode->i_size;
+}
+
+static inline void i_size_write(struct inode *inode, loff_t i_size)
+{
+	inode->i_size = i_size;
+}
+
+#ifndef MODULE_VERSION
+#define MODULE_VERSION(_version)	\
+static const char __module_version[] __attribute__((section(".modinfo"))) =	\
+"version=" _version
+#endif
+
+#endif  /* _COMPAT_H */

Added: trunk/fs/usysfs/compatinclude/linux/compat_libfs.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/compat_libfs.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/compat_libfs.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,28 @@
+#ifndef DLMFS_COMPAT_H
+#define DLMFS_COMPAT_H
+
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+
+#include <linux/fs.h>
+
+#define simple_dir_operations dcache_dir_ops
+#define simple_rmdir simple_unlink
+#define SLAB_RECLAIM_ACCOUNT 0
+
+int simple_unlink(struct inode *dir, struct dentry *dentry);
+struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd);
+int simple_statfs(struct super_block *sb, struct statfs *buf);
+int simple_readpage(struct file *file, struct page *page);
+int simple_prepare_write(struct file *file, struct page *page,
+			 unsigned from, unsigned to);
+int simple_commit_write(struct file *file, struct page *page,
+			unsigned offset, unsigned to);
+int simple_pin_fs(char *name, struct vfsmount **mount, int *count);
+void simple_release_fs(struct vfsmount **mount, int *count);
+
+
+#endif
+
+#endif /* DLMFS_COMPAT_H */

Added: trunk/fs/usysfs/compatinclude/linux/kobject.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/kobject.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/kobject.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,223 @@
+/*
+ * kobject.h - generic kernel object infrastructure.
+ *
+ * Copyright (c) 2002-2003	Patrick Mochel
+ * Copyright (c) 2002-2003	Open Source Development Labs
+ *
+ * This file is released under the GPLv2.
+ *
+ * 
+ * Please read Documentation/kobject.txt before using the kobject
+ * interface, ESPECIALLY the parts about reference counts and object
+ * destructors. 
+ *
+ * 2005.01.24
+ * 	Stripped down for compatibilty with 2.4 usysfs.
+ * 	Joel Becker <joel.becker at oracle.com>
+ */
+
+#ifndef _KOBJECT_H_
+#define _KOBJECT_H_
+
+#ifdef __KERNEL__
+
+#include "compat.h"
+
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/sysfs.h>
+#include <linux/rwsem.h>
+#include <linux/kref.h>
+#include <asm/atomic.h>
+
+#define KOBJ_NAME_LEN	20
+
+struct kobject {
+	char			* k_name;
+	char			name[KOBJ_NAME_LEN];
+	struct kref		kref;
+	struct list_head	entry;
+	struct kobject		* parent;
+	struct kset		* kset;
+	struct kobj_type	* ktype;
+	struct dentry		* dentry;
+};
+
+extern int kobject_set_name(struct kobject *, const char *, ...);
+
+static inline char * kobject_name(struct kobject * kobj)
+{
+	return kobj->k_name;
+}
+
+extern void kobject_init(struct kobject *);
+extern void kobject_cleanup(struct kobject *);
+
+extern struct kobject * kobject_get(struct kobject *);
+extern void kobject_put(struct kobject *);
+
+struct kobj_type {
+	void (*release)(struct kobject *);
+	struct sysfs_ops	* sysfs_ops;
+	struct attribute	** default_attrs;
+};
+
+
+/**
+ *	kset - a set of kobjects of a specific type, belonging
+ *	to a specific subsystem.
+ *
+ *	All kobjects of a kset should be embedded in an identical 
+ *	type. This type may have a descriptor, which the kset points
+ *	to. This allows there to exist sets of objects of the same
+ *	type in different subsystems.
+ *
+ *	A subsystem does not have to be a list of only one type 
+ *	of object; multiple ksets can belong to one subsystem. All 
+ *	ksets of a subsystem share the subsystem's lock.
+ *
+ *      Each kset can support hotplugging; if it does, it will be given
+ *      the opportunity to filter out specific kobjects from being
+ *      reported, as well as to add its own "data" elements to the
+ *      environment being passed to the hotplug helper.
+ */
+struct kset_hotplug_ops {
+	int (*filter)(struct kset *kset, struct kobject *kobj);
+	char *(*name)(struct kset *kset, struct kobject *kobj);
+	int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp,
+			int num_envp, char *buffer, int buffer_size);
+};
+
+struct kset {
+	struct subsystem	* subsys;
+	struct kobj_type	* ktype;
+	struct list_head	list;
+	struct kobject		kobj;
+	struct kset_hotplug_ops	* hotplug_ops;
+};
+
+
+extern void kset_init(struct kset * k);
+
+static inline struct kset * to_kset(struct kobject * kobj)
+{
+	return kobj ? container_of(kobj,struct kset,kobj) : NULL;
+}
+
+static inline struct kset * kset_get(struct kset * k)
+{
+	return k ? to_kset(kobject_get(&k->kobj)) : NULL;
+}
+
+static inline void kset_put(struct kset * k)
+{
+	kobject_put(&k->kobj);
+}
+
+static inline struct kobj_type * get_ktype(struct kobject * k)
+{
+	if (k->kset && k->kset->ktype)
+		return k->kset->ktype;
+	else 
+		return k->ktype;
+}
+
+extern struct kobject * kset_find_obj(struct kset *, const char *);
+
+
+/**
+ * Use this when initializing an embedded kset with no other 
+ * fields to initialize.
+ */
+#define set_kset_name(str)	.kset = { .kobj = { .name = str } }
+
+
+
+struct subsystem {
+	struct kset		kset;
+	struct rw_semaphore	rwsem;
+};
+
+#define decl_subsys(_name,_type,_hotplug_ops) \
+struct subsystem _name##_subsys = { \
+	.kset = { \
+		.kobj = { .name = __stringify(_name) }, \
+		.ktype = _type, \
+		.hotplug_ops =_hotplug_ops, \
+	} \
+}
+#define decl_subsys_name(_varname,_name,_type,_hotplug_ops) \
+struct subsystem _varname##_subsys = { \
+	.kset = { \
+		.kobj = { .name = __stringify(_name) }, \
+		.ktype = _type, \
+		.hotplug_ops =_hotplug_ops, \
+	} \
+}
+
+
+/**
+ * Helpers for setting the kset of registered objects.
+ * Often, a registered object belongs to a kset embedded in a 
+ * subsystem. These do no magic, just make the resulting code
+ * easier to follow. 
+ */
+
+/**
+ *	kobj_set_kset_s(obj,subsys) - set kset for embedded kobject.
+ *	@obj:		ptr to some object type.
+ *	@subsys:	a subsystem object (not a ptr).
+ *
+ *	Can be used for any object type with an embedded ->kobj.
+ */
+
+#define kobj_set_kset_s(obj,subsys) \
+	(obj)->kobj.kset = &(subsys).kset
+
+/**
+ *	kset_set_kset_s(obj,subsys) - set kset for embedded kset.
+ *	@obj:		ptr to some object type.
+ *	@subsys:	a subsystem object (not a ptr).
+ *
+ *	Can be used for any object type with an embedded ->kset.
+ *	Sets the kset of @obj's  embedded kobject (via its embedded
+ *	kset) to @subsys.kset. This makes @obj a member of that 
+ *	kset.
+ */
+
+#define kset_set_kset_s(obj,subsys) \
+	(obj)->kset.kobj.kset = &(subsys).kset
+
+/**
+ *	subsys_set_kset(obj,subsys) - set kset for subsystem
+ *	@obj:		ptr to some object type.
+ *	@subsys:	a subsystem object (not a ptr).
+ *
+ *	Can be used for any object type with an embedded ->subsys.
+ *	Sets the kset of @obj's kobject to @subsys.kset. This makes
+ *	the object a member of that kset.
+ */
+
+#define subsys_set_kset(obj,_subsys) \
+	(obj)->subsys.kset.kobj.kset = &(_subsys).kset
+
+extern void subsystem_init(struct subsystem *);
+
+static inline struct subsystem * subsys_get(struct subsystem * s)
+{
+	return s ? container_of(kset_get(&s->kset),struct subsystem,kset) : NULL;
+}
+
+static inline void subsys_put(struct subsystem * s)
+{
+	kset_put(&s->kset);
+}
+
+struct subsys_attribute {
+	struct attribute attr;
+	ssize_t (*show)(struct subsystem *, char *);
+	ssize_t (*store)(struct subsystem *, const char *, size_t); 
+};
+
+#endif /* __KERNEL__ */
+#endif /* _KOBJECT_H_ */

Added: trunk/fs/usysfs/compatinclude/linux/kref.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/kref.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/kref.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,31 @@
+/*
+ * kref.c - library routines for handling generic reference counted objects
+ *
+ * Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * based on kobject.h which was:
+ * Copyright (C) 2002-2003 Patrick Mochel <mochel at osdl.org>
+ * Copyright (C) 2002-2003 Open Source Development Labs
+ *
+ * This file is released under the GPLv2.
+ */
+
+#ifndef _KREF_H_
+#define _KREF_H_
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include <asm/atomic.h>
+
+struct kref {
+	atomic_t refcount;
+};
+
+void kref_init(struct kref *kref);
+void kref_get(struct kref *kref);
+void kref_put(struct kref *kref, void (*release) (struct kref *kref));
+
+#endif /* __KERNEL__ */
+#endif /* _KREF_H_ */

Added: trunk/fs/usysfs/compatinclude/linux/namei.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/namei.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/namei.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,5 @@
+/*
+ * namei.h - compatibility header for 2.4 compiling
+ */
+
+/* Empty! */

Added: trunk/fs/usysfs/compatinclude/linux/sysfs.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/sysfs.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/compatinclude/linux/sysfs.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -0,0 +1,66 @@
+/*
+ * sysfs.h - definitions for the device driver filesystem
+ *
+ * Copyright (c) 2001,2002 Patrick Mochel
+ *
+ * Please see Documentation/filesystems/sysfs.txt for more information.
+ *
+ * 2005.01.24
+ * 	Stripped down for 2.4 usysfs compatibility.
+ * 	Joel Becker <joel.becker at oracle.com>
+ */
+
+#ifndef _SYSFS_H_
+#define _SYSFS_H_
+
+#include <asm/atomic.h>
+
+struct kobject;
+struct module;
+
+struct attribute {
+	char			* name;
+	struct module 		* owner;
+	mode_t			mode;
+};
+
+struct attribute_group {
+	char			* name;
+	struct attribute	** attrs;
+};
+
+
+
+/**
+ * Use these macros to make defining attributes easier. See include/linux/device.h
+ * for examples..
+ */
+
+#define __ATTR(_name,_mode,_show,_store) { \
+	.attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },	\
+	.show	= _show,					\
+	.store	= _store,					\
+}
+
+#define __ATTR_RO(_name) { \
+	.attr	= { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE },	\
+	.show	= _name##_show,	\
+}
+
+#define __ATTR_NULL { .attr = { .name = NULL } }
+
+#define attr_name(_attr) (_attr).attr.name
+
+struct bin_attribute {
+	struct attribute	attr;
+	size_t			size;
+	ssize_t (*read)(struct kobject *, char *, loff_t, size_t);
+	ssize_t (*write)(struct kobject *, char *, loff_t, size_t);
+};
+
+struct sysfs_ops {
+	ssize_t	(*show)(struct kobject *, struct attribute *,char *);
+	ssize_t	(*store)(struct kobject *,struct attribute *,const char *, size_t);
+};
+
+#endif /* _SYSFS_H_ */

Modified: trunk/fs/usysfs/dir.c
===================================================================
--- trunk/fs/usysfs/dir.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/dir.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -8,10 +8,13 @@
 
 #undef DEBUG
 
+#include <linux/version.h>
+
 #include <linux/fs.h>
 #include <linux/mount.h>
 #include <linux/module.h>
 #include <linux/kobject.h>
+#include <linux/slab.h>
 #include "usysfs.h"
 #include "usysfs_internal.h"
 
@@ -107,7 +110,7 @@
 	error = usysfs_create(d, mode, init_dir);
 	if (!error) {
 		error = usysfs_make_dirent(p->d_fsdata, d, k, mode,
-					   SYSFS_DIR);
+					   USYSFS_DIR);
 		if (!error) {
 			p->d_inode->i_nlink++;
 			(d)->d_op = &usysfs_dentry_ops;
@@ -153,7 +156,7 @@
 	int (* init) (struct inode *) = NULL;
 	int error = 0;
 
-	if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) {
+	if (sd->s_type & USYSFS_KOBJ_BIN_ATTR) {
 		bin_attr = sd->s_element;
 		attr = &bin_attr->attr;
 	} else {
@@ -200,14 +203,14 @@
 	int err = 0;
 
 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
-		if (sd->s_type & SYSFS_NOT_PINNED) {
+		if (sd->s_type & USYSFS_NOT_PINNED) {
 			const unsigned char * name = usysfs_get_name(sd);
 
 			if (strcmp(name, dentry->d_name.name))
 				continue;
 
 			found = 1;
-			if (sd->s_type & SYSFS_KOBJ_LINK)
+			if (sd->s_type & USYSFS_KOBJ_LINK)
 				err = usysfs_attach_link(sd, dentry);
 			else
 				err = usysfs_attach_attr(sd, dentry);
@@ -227,7 +230,7 @@
 }
 
 /*
- * Only subdirectories count here.  Files (SYSFS_NOT_PINNED) are
+ * Only subdirectories count here.  Files (USYSFS_NOT_PINNED) are
  * attributes and are removed by rmdir().
  */
 static int usysfs_empty_dir(struct dentry *dentry)
@@ -236,7 +239,7 @@
 	struct usysfs_dirent *sd;
 
 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
-		if (sd->s_type & SYSFS_NOT_PINNED)
+		if (sd->s_type & USYSFS_NOT_PINNED)
 			continue;
 		return 0;
 	}
@@ -394,10 +397,21 @@
 	return 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+static inline struct dentry *usysfs_lookup_compat(struct inode *dir, struct dentry *dentry)
+{
+	return usysfs_lookup(dir, dentry, NULL);
+}
+#endif
+
 struct inode_operations usysfs_dir_inode_operations = {
 	.mkdir		= usysfs_mkdir,
 	.rmdir		= usysfs_rmdir,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 	.lookup		= usysfs_lookup,
+#else
+	.lookup		= usysfs_lookup_compat,
+#endif
 };
 
 static void remove_dir(struct dentry * d)
@@ -444,7 +458,7 @@
 	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 & SYSFS_NOT_PINNED))
+		if (!sd->s_element || !(sd->s_type & USYSFS_NOT_PINNED))
 			continue;
 		list_del_init(&sd->s_sibling);
 		usysfs_drop_dentry(sd, dentry);

Modified: trunk/fs/usysfs/file.c
===================================================================
--- trunk/fs/usysfs/file.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/file.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -5,9 +5,11 @@
  * Changes for usysfs Copyright (c) 2005 Oracle Corporation
  */
 
+#include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/dnotify.h>
 #include <linux/kobject.h>
+#include <linux/slab.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 
@@ -383,7 +385,7 @@
 {
 	BUG_ON(!kobj || !kobj->dentry || !attr);
 
-	return usysfs_add_file(kobj->dentry, attr, SYSFS_KOBJ_ATTR);
+	return usysfs_add_file(kobj->dentry, attr, USYSFS_KOBJ_ATTR);
 
 }
 

Modified: trunk/fs/usysfs/group.c
===================================================================
--- trunk/fs/usysfs/group.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/group.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -32,7 +32,7 @@
 	int error = 0;
 
 	for (attr = grp->attrs; *attr && !error; attr++) {
-		error = usysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
+		error = usysfs_add_file(dir, *attr, USYSFS_KOBJ_ATTR);
 	}
 	if (error)
 		remove_files(dir,grp);

Modified: trunk/fs/usysfs/inode.c
===================================================================
--- trunk/fs/usysfs/inode.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/inode.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -10,6 +10,7 @@
 
 #include <linux/pagemap.h>
 #include <linux/namei.h>
+#include <linux/kobject.h>
 #include <linux/backing-dev.h>
 #include "usysfs.h"
 #include "usysfs_internal.h"
@@ -38,7 +39,9 @@
 		inode->i_blocks = 0;
 		inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 		inode->i_mapping->a_ops = &usysfs_aops;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 		inode->i_mapping->backing_dev_info = &usysfs_backing_dev_info;
+#endif
 	}
 	return inode;
 }
@@ -100,19 +103,19 @@
 		BUG();
 
 	switch (sd->s_type) {
-		case SYSFS_DIR:
+		case USYSFS_DIR:
 			/* Always have a dentry so use that */
 			return sd->s_dentry->d_name.name;
 
-		case SYSFS_KOBJ_ATTR:
+		case USYSFS_KOBJ_ATTR:
 			attr = sd->s_element;
 			return attr->name;
 
-		case SYSFS_KOBJ_BIN_ATTR:
+		case USYSFS_KOBJ_BIN_ATTR:
 			bin_attr = sd->s_element;
 			return bin_attr->attr.name;
 
-		case SYSFS_KOBJ_LINK:
+		case USYSFS_KOBJ_LINK:
 			sl = sd->s_element;
 			return sl->link_name;
 	}

Modified: trunk/fs/usysfs/mount.c
===================================================================
--- trunk/fs/usysfs/mount.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/mount.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -6,19 +6,20 @@
  * Changes for usysfs Copyright (c) 2004 Oracle Corporation.
  */
 
-#define DEBUG 
+#define DEBUG 1
 
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/mount.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
+#include <linux/kobject.h>
 
 #include "usysfs.h"
 #include "usysfs_internal.h"
 
 /* Random magic number */
-#define USYSFS_MAGIC 0x62656570
+#define UUSYSFS_MAGIC 0x62656570
 
 struct vfsmount * usysfs_mount = NULL;
 struct super_block * usysfs_sb = NULL;
@@ -26,14 +27,18 @@
 
 static struct super_operations usysfs_ops = {
 	.statfs		= simple_statfs,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 	.drop_inode	= generic_delete_inode,
+#else
+	.put_inode	= force_delete
+#endif
 };
 
 static struct usysfs_dirent usysfs_root = {
 	.s_sibling	= LIST_HEAD_INIT(usysfs_root.s_sibling),
 	.s_children	= LIST_HEAD_INIT(usysfs_root.s_children),
 	.s_element	= NULL,
-	.s_type		= SYSFS_ROOT,
+	.s_type		= USYSFS_ROOT,
 };
 
 static int usysfs_fill_super(struct super_block *sb, void *data, int silent)
@@ -43,7 +48,7 @@
 
 	sb->s_blocksize = PAGE_CACHE_SIZE;
 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
-	sb->s_magic = USYSFS_MAGIC;
+	sb->s_magic = UUSYSFS_MAGIC;
 	sb->s_op = &usysfs_ops;
 	usysfs_sb = sb;
 
@@ -69,6 +74,7 @@
 	return 0;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static struct super_block *usysfs_get_sb(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data)
 {
@@ -81,7 +87,15 @@
 	.get_sb		= usysfs_get_sb,
 	.kill_sb	= kill_litter_super,
 };
+#else
+static struct super_block *usysfs_read_super(struct super_block *sb, void *data, int silent)
+{
+	return (usysfs_fill_super(sb, data, silent) < 0) ? NULL : sb;
+}
 
+static DECLARE_FSTYPE(usysfs_fs_type, "usysfs", usysfs_read_super, FS_SINGLE);
+#endif
+
 int usysfs_pin_fs(void)
 {
 	return simple_pin_fs("usysfs", &usysfs_mount,

Modified: trunk/fs/usysfs/symlink.c
===================================================================
--- trunk/fs/usysfs/symlink.c	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/symlink.c	2005-01-25 23:23:57 UTC (rev 1850)
@@ -64,7 +64,7 @@
 	sl->target_kobj = kobject_get(target);
 
 	error = usysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO,
-				SYSFS_KOBJ_LINK);
+				USYSFS_KOBJ_LINK);
 	if (!error)
 		return 0;
 

Modified: trunk/fs/usysfs/usysfs.h
===================================================================
--- trunk/fs/usysfs/usysfs.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/usysfs.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -103,12 +103,12 @@
 	struct dentry		* s_dentry;
 };
 
-#define SYSFS_ROOT		0x0001
-#define SYSFS_DIR		0x0002
-#define SYSFS_KOBJ_ATTR 	0x0004
-#define SYSFS_KOBJ_BIN_ATTR	0x0008
-#define SYSFS_KOBJ_LINK 	0x0020
-#define SYSFS_NOT_PINNED	(SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
+#define USYSFS_ROOT		0x0001
+#define USYSFS_DIR		0x0002
+#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 CONFIG_USYSFS
 #ifdef CONFIG_USYSFS

Modified: trunk/fs/usysfs/usysfs_internal.h
===================================================================
--- trunk/fs/usysfs/usysfs_internal.h	2005-01-25 07:56:49 UTC (rev 1849)
+++ trunk/fs/usysfs/usysfs_internal.h	2005-01-25 23:23:57 UTC (rev 1850)
@@ -1,3 +1,8 @@
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#include "linux/compat_libfs.h"
+#endif
+#include <linux/slab.h>
 
 extern struct vfsmount * usysfs_mount;
 
@@ -58,7 +63,7 @@
 	spin_lock(&dcache_lock);
 	if (!d_unhashed(dentry)) {
 		struct usysfs_dirent * sd = dentry->d_fsdata;
-		if (sd->s_type & SYSFS_KOBJ_LINK) {
+		if (sd->s_type & USYSFS_KOBJ_LINK) {
 			struct usysfs_symlink * sl = sd->s_element;
 			kobj = kobject_get(sl->target_kobj);
 		} else
@@ -71,7 +76,7 @@
 
 static inline void release_usysfs_dirent(struct usysfs_dirent * sd)
 {
-	if (sd->s_type & SYSFS_KOBJ_LINK) {
+	if (sd->s_type & USYSFS_KOBJ_LINK) {
 		struct usysfs_symlink * sl = sd->s_element;
 		kfree(sl->link_name);
 		kobject_put(sl->target_kobj);



More information about the Ocfs2-commits mailing list