All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jgarzik@pobox.com>
To: rusty@rustcorp.com.au
Cc: linux-kernel@vger.kernel.org, akpm@digeo.com
Subject: [PATCH] fixup loop blkdev, add module_get
Date: Sat, 11 Jan 2003 22:56:20 -0500	[thread overview]
Message-ID: <20030112035620.GA25648@gtf.org> (raw)

Sometimes, we are absolutely certain that we have at least one module
reference "locked open" for us.  Loop is an example of such a case:  the
set-fd and clear-fd struct block_device_operations ioctls already have a
module reference from simply the block device being opened.

Therefore, we can just unconditionally increment the module refcount.
I added module_get to do this.

Implementing try_module_get in terms of module_get is left as an
exercise for the maintainer :)  I am too lazy to investigate whether it
is ok for try_module_get to call module_is_live outside of the
get_cpu/put_cpu pair, which is a prereq for try_module_get using
module_get.

Patch against latest Linus BK tree follows...  this also eliminates the
"deprecated" warnings for the loop device.



===== drivers/block/loop.c 1.78 vs edited =====
--- 1.78/drivers/block/loop.c	Thu Dec  5 10:52:06 2002
+++ edited/drivers/block/loop.c	Sat Jan 11 22:45:54 2003
@@ -642,7 +642,7 @@
 	int		lo_flags = 0;
 	int		error;
 
-	MOD_INC_USE_COUNT;
+	module_get(THIS_MODULE);
 
 	error = -EBUSY;
 	if (lo->lo_state != Lo_unbound)
@@ -742,7 +742,7 @@
  out_putf:
 	fput(file);
  out:
-	MOD_DEC_USE_COUNT;
+	module_put(THIS_MODULE);
 	return error;
 }
 
@@ -814,7 +814,7 @@
 	filp->f_dentry->d_inode->i_mapping->gfp_mask = gfp;
 	lo->lo_state = Lo_unbound;
 	fput(filp);
-	MOD_DEC_USE_COUNT;
+	module_put(THIS_MODULE);
 	return 0;
 }
 
===== include/linux/module.h 1.38 vs edited =====
--- 1.38/include/linux/module.h	Wed Jan  8 08:19:44 2003
+++ edited/include/linux/module.h	Sat Jan 11 22:43:20 2003
@@ -249,6 +249,20 @@
 #define local_dec(x) atomic_dec(x)
 #endif
 
+/* bump a module's refcount.
+ *
+ * called only when we are absolutely certain that
+ * module != NULL, and the locking / call chain
+ * guarantees that the module won't disappear out
+ * from underneath us.
+ */
+static inline void module_get(struct module *module)
+{
+	unsigned int cpu = get_cpu();
+	local_inc(&module->ref[cpu].count);
+	put_cpu();
+}
+
 static inline int try_module_get(struct module *module)
 {
 	int ret = 1;
@@ -277,6 +291,7 @@
 }
 
 #else /*!CONFIG_MODULE_UNLOAD*/
+static inline void module_get(struct module *module) {}
 static inline int try_module_get(struct module *module)
 {
 	return !module || module_is_live(module);

             reply	other threads:[~2003-01-12  3:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-12  3:56 Jeff Garzik [this message]
2003-01-13  0:55 ` [PATCH] fixup loop blkdev, add module_get Rusty Russell
2003-01-13  2:03   ` Jeff Garzik
2003-01-13  4:08     ` Rusty Russell
2003-01-13 22:20       ` Roman Zippel

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=20030112035620.GA25648@gtf.org \
    --to=jgarzik@pobox.com \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.