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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jan 25 20:10:04 CST 2005


Author: jlbec
Date: 2005-01-25 20:10:03 -0600 (Tue, 25 Jan 2005)
New Revision: 1853

Added:
   trunk/fs/usysfs/compat_kref.c
Modified:
   trunk/fs/usysfs/Makefile
   trunk/fs/usysfs/compatinclude/linux/compat.h
Log:

o Add compat_kref.c, heh.
o Fix module get/put compat.
o usysfs now works on 2.4



Modified: trunk/fs/usysfs/Makefile
===================================================================
--- trunk/fs/usysfs/Makefile	2005-01-26 01:31:26 UTC (rev 1852)
+++ trunk/fs/usysfs/Makefile	2005-01-26 02:10:03 UTC (rev 1853)
@@ -35,6 +35,7 @@
 	inode.c			\
 	mount.c			\
 	symlink.c		\
+	compat_kref.c		\
 	compat_kobject.c	\
 	compat_libfs.c
 USYSFS_OBJECTS = $(subst .c,.o,$(USYSFS_SOURCES))

Added: trunk/fs/usysfs/compat_kref.c
===================================================================
--- trunk/fs/usysfs/compat_kref.c	2005-01-26 01:31:26 UTC (rev 1852)
+++ trunk/fs/usysfs/compat_kref.c	2005-01-26 02:10:03 UTC (rev 1853)
@@ -0,0 +1,59 @@
+/*
+ * 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 lib/kobject.c which was:
+ * Copyright (C) 2002-2003 Patrick Mochel <mochel at osdl.org>
+ *
+ * This file is released under the GPLv2.
+ *
+ */
+
+#include "linux/compat.h"
+#include <linux/kref.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+/**
+ * kref_init - initialize object.
+ * @kref: object in question.
+ */
+void kref_init(struct kref *kref)
+{
+	atomic_set(&kref->refcount,1);
+}
+
+/**
+ * kref_get - increment refcount for object.
+ * @kref: object.
+ */
+void kref_get(struct kref *kref)
+{
+	WARN_ON(!atomic_read(&kref->refcount));
+	atomic_inc(&kref->refcount);
+}
+
+/**
+ * kref_put - decrement refcount for object.
+ * @kref: object.
+ * @release: pointer to the function that will clean up the object when the
+ *	     last reference to the object is released.
+ *	     This pointer is required, and it is not acceptable to pass kfree
+ *	     in as this function.
+ *
+ * Decrement the refcount, and if 0, call release().
+ */
+void kref_put(struct kref *kref, void (*release) (struct kref *kref))
+{
+	WARN_ON(release == NULL);
+	WARN_ON(release == (void (*)(struct kref *))kfree);
+
+	if (atomic_dec_and_test(&kref->refcount))
+		release(kref);
+}
+
+EXPORT_SYMBOL(kref_init);
+EXPORT_SYMBOL(kref_get);
+EXPORT_SYMBOL(kref_put);

Modified: trunk/fs/usysfs/compatinclude/linux/compat.h
===================================================================
--- trunk/fs/usysfs/compatinclude/linux/compat.h	2005-01-26 01:31:26 UTC (rev 1852)
+++ trunk/fs/usysfs/compatinclude/linux/compat.h	2005-01-26 02:10:03 UTC (rev 1853)
@@ -6,6 +6,7 @@
 #define _COMPAT_H
 
 #include <linux/fs.h>
+#include <linux/module.h>
 #include <linux/compiler.h>
 
 #ifndef container_of
@@ -31,9 +32,17 @@
 } while (0)
 #endif
 
-#define try_module_get(mod) try_inc_mod_count(mod)
-#define module_put(mod) __MOD_DEC_USE_COUNT(mod)
+static inline int try_module_get(struct module *module)
+{
+	return try_inc_mod_count(module);
+}
 
+static inline void module_put(struct module *module)
+{
+	if (module)
+		__MOD_DEC_USE_COUNT(module);
+}
+
 #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),	\



More information about the Ocfs2-commits mailing list