aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Marowsky-Bree <lmb@suse.de>2005-05-01 11:59:07 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-01 11:59:07 -0400
commit40be0c28b33ff0821594a3fa7126354dfe6eccd1 (patch)
treea62e93e866a2c7fdbe732adb634a6bba294beded
parent4750e2c0c59e0c84c6c036b3d96ebd88365ae7ee (diff)
[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: Lars Marowsky-Bree <lmb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/block/nbd.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index efdf04450bf7..9e268ddedfbd 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -78,6 +78,7 @@
78#define DBG_RX 0x0200 78#define DBG_RX 0x0200
79#define DBG_TX 0x0400 79#define DBG_TX 0x0400
80static unsigned int debugflags; 80static unsigned int debugflags;
81static unsigned int nbds_max = 16;
81#endif /* NDEBUG */ 82#endif /* NDEBUG */
82 83
83static struct nbd_device nbd_dev[MAX_NBD]; 84static struct nbd_device nbd_dev[MAX_NBD];
@@ -647,7 +648,13 @@ static int __init nbd_init(void)
647 return -EIO; 648 return -EIO;
648 } 649 }
649 650
650 for (i = 0; i < MAX_NBD; i++) { 651 if (nbds_max > MAX_NBD) {
652 printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD,
653 nbds_max);
654 return -EINVAL;
655 }
656
657 for (i = 0; i < nbds_max; i++) {
651 struct gendisk *disk = alloc_disk(1); 658 struct gendisk *disk = alloc_disk(1);
652 if (!disk) 659 if (!disk)
653 goto out; 660 goto out;
@@ -673,7 +680,7 @@ static int __init nbd_init(void)
673 dprintk(DBG_INIT, "nbd: debugflags=0x%x\n", debugflags); 680 dprintk(DBG_INIT, "nbd: debugflags=0x%x\n", debugflags);
674 681
675 devfs_mk_dir("nbd"); 682 devfs_mk_dir("nbd");
676 for (i = 0; i < MAX_NBD; i++) { 683 for (i = 0; i < nbds_max; i++) {
677 struct gendisk *disk = nbd_dev[i].disk; 684 struct gendisk *disk = nbd_dev[i].disk;
678 nbd_dev[i].file = NULL; 685 nbd_dev[i].file = NULL;
679 nbd_dev[i].magic = LO_MAGIC; 686 nbd_dev[i].magic = LO_MAGIC;
@@ -706,8 +713,9 @@ out:
706static void __exit nbd_cleanup(void) 713static void __exit nbd_cleanup(void)
707{ 714{
708 int i; 715 int i;
709 for (i = 0; i < MAX_NBD; i++) { 716 for (i = 0; i < nbds_max; i++) {
710 struct gendisk *disk = nbd_dev[i].disk; 717 struct gendisk *disk = nbd_dev[i].disk;
718 nbd_dev[i].magic = 0;
711 if (disk) { 719 if (disk) {
712 del_gendisk(disk); 720 del_gendisk(disk);
713 blk_cleanup_queue(disk->queue); 721 blk_cleanup_queue(disk->queue);
@@ -725,6 +733,8 @@ module_exit(nbd_cleanup);
725MODULE_DESCRIPTION("Network Block Device"); 733MODULE_DESCRIPTION("Network Block Device");
726MODULE_LICENSE("GPL"); 734MODULE_LICENSE("GPL");
727 735
736module_param(nbds_max, int, 0444);
737MODULE_PARM_DESC(nbds_max, "How many network block devices to initialize.");
728#ifndef NDEBUG 738#ifndef NDEBUG
729module_param(debugflags, int, 0644); 739module_param(debugflags, int, 0644);
730MODULE_PARM_DESC(debugflags, "flags for controlling debug output"); 740MODULE_PARM_DESC(debugflags, "flags for controlling debug output");