Skip to content

Commit 85c5019

Browse files
Isaac J. Manjarresaxboe
authored andcommitted
loop: Fix the max_loop commandline argument treatment when it is set to 0
Currently, the max_loop commandline argument can be used to specify how many loop block devices are created at init time. If it is not specified on the commandline, CONFIG_BLK_DEV_LOOP_MIN_COUNT loop block devices will be created. The max_loop commandline argument can be used to override the value of CONFIG_BLK_DEV_LOOP_MIN_COUNT. However, when max_loop is set to 0 through the commandline, the current logic treats it as if it had not been set, and creates CONFIG_BLK_DEV_LOOP_MIN_COUNT devices anyway. Fix this by starting max_loop off as set to CONFIG_BLK_DEV_LOOP_MIN_COUNT. This preserves the intended behavior of creating CONFIG_BLK_DEV_LOOP_MIN_COUNT loop block devices if the max_loop commandline parameter is not specified, and allowing max_loop to be respected for all values, including 0. This allows environments that can create all of their required loop block devices on demand to not have to unnecessarily preallocate loop block devices. Fixes: 7328508 ("remove artificial software max_loop limit") Cc: [email protected] Cc: Ken Chen <[email protected]> Signed-off-by: Isaac J. Manjarres <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ff1cc97 commit 85c5019

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

drivers/block/loop.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,16 @@ static const struct block_device_operations lo_fops = {
17731773
/*
17741774
* And now the modules code and kernel interface.
17751775
*/
1776-
static int max_loop;
1776+
1777+
/*
1778+
* If max_loop is specified, create that many devices upfront.
1779+
* This also becomes a hard limit. If max_loop is not specified,
1780+
* create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
1781+
* init time. Loop devices can be requested on-demand with the
1782+
* /dev/loop-control interface, or be instantiated by accessing
1783+
* a 'dead' device node.
1784+
*/
1785+
static int max_loop = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
17771786
module_param(max_loop, int, 0444);
17781787
MODULE_PARM_DESC(max_loop, "Maximum number of loop devices");
17791788
module_param(max_part, int, 0444);
@@ -2181,7 +2190,7 @@ MODULE_ALIAS("devname:loop-control");
21812190

21822191
static int __init loop_init(void)
21832192
{
2184-
int i, nr;
2193+
int i;
21852194
int err;
21862195

21872196
part_shift = 0;
@@ -2209,19 +2218,6 @@ static int __init loop_init(void)
22092218
goto err_out;
22102219
}
22112220

2212-
/*
2213-
* If max_loop is specified, create that many devices upfront.
2214-
* This also becomes a hard limit. If max_loop is not specified,
2215-
* create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
2216-
* init time. Loop devices can be requested on-demand with the
2217-
* /dev/loop-control interface, or be instantiated by accessing
2218-
* a 'dead' device node.
2219-
*/
2220-
if (max_loop)
2221-
nr = max_loop;
2222-
else
2223-
nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
2224-
22252221
err = misc_register(&loop_misc);
22262222
if (err < 0)
22272223
goto err_out;
@@ -2233,7 +2229,7 @@ static int __init loop_init(void)
22332229
}
22342230

22352231
/* pre-create number of devices given by config or max_loop */
2236-
for (i = 0; i < nr; i++)
2232+
for (i = 0; i < max_loop; i++)
22372233
loop_add(i);
22382234

22392235
printk(KERN_INFO "loop: module loaded\n");

0 commit comments

Comments
 (0)