Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

md: support disabling of create-on-open semantics.

md allows a new array device to be created by simply
opening a device file. This make it difficult to
remove the device and udev is likely to open the device file
as part of processing the REMOVE event.

There is an alternate mechanism for creating arrays
by writing to the new_array module parameter.
When using tools that work with this parameter, it is
best to disable the old semantics.
This new module parameter allows that.

Signed-off-by: NeilBrown <neilb@suse.com>
Acted-by: Coly Li <colyli@suse.de>
Signed-off-by: Shaohua Li <shli@fb.com>

authored by

NeilBrown and committed by
Shaohua Li
78b6350d 039b7225

+13 -1
+13 -1
drivers/md/md.c
··· 174 174 175 175 static int start_readonly; 176 176 177 + /* 178 + * The original mechanism for creating an md device is to create 179 + * a device node in /dev and to open it. This causes races with device-close. 180 + * The preferred method is to write to the "new_array" module parameter. 181 + * This can avoid races. 182 + * Setting create_on_open to false disables the original mechanism 183 + * so all the races disappear. 184 + */ 185 + static bool create_on_open = true; 186 + 177 187 /* bio_clone_mddev 178 188 * like bio_clone, but with a local bio set 179 189 */ ··· 5295 5285 5296 5286 static struct kobject *md_probe(dev_t dev, int *part, void *data) 5297 5287 { 5298 - md_alloc(dev, NULL); 5288 + if (create_on_open) 5289 + md_alloc(dev, NULL); 5299 5290 return NULL; 5300 5291 } 5301 5292 ··· 9211 9200 module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); 9212 9201 module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); 9213 9202 module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); 9203 + module_param(create_on_open, bool, S_IRUSR|S_IWUSR); 9214 9204 9215 9205 MODULE_LICENSE("GPL"); 9216 9206 MODULE_DESCRIPTION("MD RAID framework");