uml: handle block device hotplug errors
authorJeff Dike <jdike@addtoit.com>
Sun, 6 May 2007 21:51:01 +0000 (14:51 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Mon, 7 May 2007 19:13:00 +0000 (12:13 -0700)
If a disk fails to open, i.e.  its host file doesn't exist, it won't be
removable because the hot-unplug code checks the existence of its gendisk.
This won't exist because it is only allocated for successfully opened disks.
Thus, a typo on the command line can result in a unusable and unfixable disk.

This is fixed by freeing the gendisk if it's there, but not letting that
affect the removal.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/um/drivers/ubd_kern.c

index 8bd9204ac1abcaee1be42dc73450b2ee66f99116..53c36d1770c5df94167433c29726dee9cafca105 100644 (file)
@@ -788,14 +788,12 @@ static int ubd_id(char **str, int *start_out, int *end_out)
 
 static int ubd_remove(int n, char **error_out)
 {
+       struct gendisk *disk;
        struct ubd *ubd_dev;
        int err = -ENODEV;
 
        mutex_lock(&ubd_lock);
 
-       if(ubd_gendisk[n] == NULL)
-               goto out;
-
        ubd_dev = &ubd_devs[n];
 
        if(ubd_dev->file == NULL)
@@ -806,9 +804,12 @@ static int ubd_remove(int n, char **error_out)
        if(ubd_dev->count > 0)
                goto out;
 
-       del_gendisk(ubd_gendisk[n]);
-       put_disk(ubd_gendisk[n]);
-       ubd_gendisk[n] = NULL;
+       disk = ubd_gendisk[n];
+       ubd_gendisk[n] = NULL;
+       if(disk != NULL){
+               del_gendisk(disk);
+               put_disk(disk);
+       }
 
        if(fake_gendisk[n] != NULL){
                del_gendisk(fake_gendisk[n]);