Commit 40be0c28 authored by Lars Marowsky-Bree's avatar Lars Marowsky-Bree Committed by Linus Torvalds

[PATCH] nbd: Don't create all MAX_NBD devices by default all the time

This patches adds the "nbds_max" parameter to the nbd kernel module, which
limits the number of nbds allocated.  Previously, always all 128 entries
were allocated unconditionally, which used to waste resources and
needlessly flood the hotplug system with events.  (Defaults to 16 now.)
Signed-off-by: default avatarLars Marowsky-Bree <lmb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4750e2c0
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
#define DBG_RX 0x0200 #define DBG_RX 0x0200
#define DBG_TX 0x0400 #define DBG_TX 0x0400
static unsigned int debugflags; static unsigned int debugflags;
static unsigned int nbds_max = 16;
#endif /* NDEBUG */ #endif /* NDEBUG */
static struct nbd_device nbd_dev[MAX_NBD]; static struct nbd_device nbd_dev[MAX_NBD];
...@@ -647,7 +648,13 @@ static int __init nbd_init(void) ...@@ -647,7 +648,13 @@ static int __init nbd_init(void)
return -EIO; return -EIO;
} }
for (i = 0; i < MAX_NBD; i++) { if (nbds_max > MAX_NBD) {
printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD,
nbds_max);
return -EINVAL;
}
for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1); struct gendisk *disk = alloc_disk(1);
if (!disk) if (!disk)
goto out; goto out;
...@@ -673,7 +680,7 @@ static int __init nbd_init(void) ...@@ -673,7 +680,7 @@ static int __init nbd_init(void)
dprintk(DBG_INIT, "nbd: debugflags=0x%x\n", debugflags); dprintk(DBG_INIT, "nbd: debugflags=0x%x\n", debugflags);
devfs_mk_dir("nbd"); devfs_mk_dir("nbd");
for (i = 0; i < MAX_NBD; i++) { for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = nbd_dev[i].disk; struct gendisk *disk = nbd_dev[i].disk;
nbd_dev[i].file = NULL; nbd_dev[i].file = NULL;
nbd_dev[i].magic = LO_MAGIC; nbd_dev[i].magic = LO_MAGIC;
...@@ -706,8 +713,9 @@ out: ...@@ -706,8 +713,9 @@ out:
static void __exit nbd_cleanup(void) static void __exit nbd_cleanup(void)
{ {
int i; int i;
for (i = 0; i < MAX_NBD; i++) { for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = nbd_dev[i].disk; struct gendisk *disk = nbd_dev[i].disk;
nbd_dev[i].magic = 0;
if (disk) { if (disk) {
del_gendisk(disk); del_gendisk(disk);
blk_cleanup_queue(disk->queue); blk_cleanup_queue(disk->queue);
...@@ -725,6 +733,8 @@ module_exit(nbd_cleanup); ...@@ -725,6 +733,8 @@ module_exit(nbd_cleanup);
MODULE_DESCRIPTION("Network Block Device"); MODULE_DESCRIPTION("Network Block Device");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_param(nbds_max, int, 0444);
MODULE_PARM_DESC(nbds_max, "How many network block devices to initialize.");
#ifndef NDEBUG #ifndef NDEBUG
module_param(debugflags, int, 0644); module_param(debugflags, int, 0644);
MODULE_PARM_DESC(debugflags, "flags for controlling debug output"); MODULE_PARM_DESC(debugflags, "flags for controlling debug output");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment