btrfs-progs: mkfs: do not try to register non-block-devices
authorDavid Sterba <dsterba@suse.cz>
Sat, 6 Jun 2015 00:17:13 +0000 (02:17 +0200)
committerDavid Sterba <dsterba@suse.cz>
Mon, 8 Jun 2015 15:50:46 +0000 (17:50 +0200)
A mkfs on a regular file will try to call the DEV_SCAN ioctl that will
take the loop through the kernel and fail:

 ERROR: device scan failed './test.img' - Block device required

If a user without permission to open the control device tries to mkfs a
regular file, an error message is printed:

 failed to open /dev/btrfs-control skipping device registration: Permission denied

So we should not try to pass a non-block-device besides that this makes
the --quiet option more quiet.

Signed-off-by: David Sterba <dsterba@suse.cz>
mkfs.c

diff --git a/mkfs.c b/mkfs.c
index 0825765..c069d36 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1482,7 +1482,8 @@ int main(int ac, char **av)
 
        trans = btrfs_start_transaction(root, 1);
 
-       btrfs_register_one_device(file);
+       if (is_block_device(file))
+               btrfs_register_one_device(file);
 
        if (dev_cnt == 0)
                goto raid_groups;
@@ -1531,7 +1532,8 @@ int main(int ac, char **av)
                                (unsigned long long)device->devid);
                }
 
-               btrfs_register_one_device(file);
+               if (is_block_device(file))
+                       btrfs_register_one_device(file);
        }
 
 raid_groups: