From: Lou Langholtz <ldl@aros.net>
To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@digeo.com>,
Pavel Machek <pavel@ucw.cz>,
Steven Whitehouse <steve@chygwyn.com>,
viro@parcelfarce.linux.theplanet.co.uk
Subject: [PATCH] nbd driver for 2.5+: fix for module removal & new block device layer
Date: Sat, 21 Jun 2003 15:48:56 -0600 [thread overview]
Message-ID: <3EF4D2C8.6060608@aros.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 711 bytes --]
This patch prevents memory corruption from "rmmod nbd" with the existing
2.5.72 (and earlier) nbd driver. It does this by updating the nbd driver
to the new block layer requirement that every disk has its own
request_queue structure. This is the first of a series of patchlets
designed to break down the essential changes I proposed in my last
"enormous" patch. Note that another patchlet will make the whole
allocation of per nbd_device memory be dynamic (rather than staticly
tied to MAX_NBD). Please try out this patch and let me know how nbd is
working for you before versus after. With any luck, some of these
smaller patch breakdowns can actually see there way into new kernel
releases. Thanks.
[-- Attachment #2: nbd-patch1 --]
[-- Type: text/plain, Size: 2631 bytes --]
diff -urN linux-2.5.72/drivers/block/nbd.c linux-2.5.72-patched/drivers/block/nbd.c
--- linux-2.5.72/drivers/block/nbd.c 2003-06-16 22:19:44.000000000 -0600
+++ linux-2.5.72-patched/drivers/block/nbd.c 2003-06-21 15:30:17.860967573 -0600
@@ -28,6 +28,7 @@
* the transmit lock. <steve@chygwyn.com>
* 02-10-11 Allow hung xmit to be aborted via SIGKILL & various fixes.
* <Paul.Clements@SteelEye.com> <James.Bottomley@SteelEye.com>
+ * 03-06-21 Fix memory corruption from module removal. <ldl@aros.net>
*
* possible FIXME: make set_sock / set_blksize / set_size / do_it one syscall
* why not: would need verify_area and friends, would share yet another
@@ -63,7 +64,18 @@
static struct nbd_device nbd_dev[MAX_NBD];
-static spinlock_t nbd_lock = SPIN_LOCK_UNLOCKED;
+/*
+ * Have these per nbd_device as is now required by the new block layer.
+ * This also helps prevent I/O bottle necks between multiple nbd_devices
+ * resulting in better overall response times!
+ *
+ * ldl: Keep these out from nbd_device for now till the whole 2.5 blockdev
+ * reworking shakes out. Who knows... maybe struct request_queue's
+ * queue_lock field will someday actually be the spinlock instead of just
+ * being a pointer to it!
+ */
+static struct request_queue nbd_queue[MAX_NBD];
+static spinlock_t nbd_lock[MAX_NBD];
#define DEBUG( s )
/* #define DEBUG( s ) printk( s )
@@ -538,8 +550,6 @@
* (Just smiley confuses emacs :-)
*/
-static struct request_queue nbd_queue;
-
static int __init nbd_init(void)
{
int err = -ENOMEM;
@@ -551,6 +561,11 @@
}
for (i = 0; i < MAX_NBD; i++) {
+ nbd_lock[i] = SPIN_LOCK_UNLOCKED;
+ blk_init_queue(&nbd_queue[i], do_nbd_request, &nbd_lock[i]);
+ }
+
+ for (i = 0; i < MAX_NBD; i++) {
struct gendisk *disk = alloc_disk(1);
if (!disk)
goto out;
@@ -564,7 +579,6 @@
#ifdef MODULE
printk("nbd: registered device at major %d\n", NBD_MAJOR);
#endif
- blk_init_queue(&nbd_queue, do_nbd_request, &nbd_lock);
devfs_mk_dir("nbd");
for (i = 0; i < MAX_NBD; i++) {
struct gendisk *disk = nbd_dev[i].disk;
@@ -582,7 +596,7 @@
disk->first_minor = i;
disk->fops = &nbd_fops;
disk->private_data = &nbd_dev[i];
- disk->queue = &nbd_queue;
+ disk->queue = &nbd_queue[i];
sprintf(disk->disk_name, "nbd%d", i);
sprintf(disk->devfs_name, "nbd/%d", i);
set_capacity(disk, 0x3ffffe);
@@ -602,9 +616,9 @@
for (i = 0; i < MAX_NBD; i++) {
del_gendisk(nbd_dev[i].disk);
put_disk(nbd_dev[i].disk);
+ blk_cleanup_queue(&nbd_queue[i]);
}
devfs_remove("nbd");
- blk_cleanup_queue(&nbd_queue);
unregister_blkdev(NBD_MAJOR, "nbd");
}
next reply other threads:[~2003-06-21 21:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-21 21:48 Lou Langholtz [this message]
2003-06-21 22:55 ` [PATCH] nbd driver for 2.5+: fix for module removal & new block device layer viro
2003-06-21 23:16 ` Lou Langholtz
2003-06-22 10:03 ` Jens Axboe
[not found] ` <20030621151818.081139fc.akpm@digeo.com>
2003-06-21 23:09 ` [PATCH] nbd driver 2.5+: fix for incorrect struct bio usage Lou Langholtz
2003-06-22 8:50 ` Jens Axboe
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=3EF4D2C8.6060608@aros.net \
--to=ldl@aros.net \
--cc=akpm@digeo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=steve@chygwyn.com \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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