btrfs-progs: close all fs_devices before exit in some commands
authorZhao Lei <zhaolei@cn.fujitsu.com>
Mon, 24 Aug 2015 08:45:03 +0000 (16:45 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 31 Aug 2015 17:25:13 +0000 (19:25 +0200)
mkfs creates more than one fs_devices in fs_uuids.
1: one is for file system being created
2: others are created in test_dev_for_mkfs in order to check mount point
   test_dev_for_mkfs()-> ... -> btrfs_scan_one_device()

Current code only closes 1, and this patch also closes in case 2.

Similar problem exist in other tools, eg.::

 cmd-check.c: the function is:
 cmd_check()->check_mounted()-> ... -> btrfs_scan_one_device()
 ...

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c
cmds-device.c
cmds-replace.c
mkfs.c

index 1b3bc17..0f91260 100644 (file)
@@ -9588,6 +9588,7 @@ out:
        free_root_recs_tree(&root_cache);
 close_out:
        close_ctree(root);
+       btrfs_close_all_devices();
 err_out:
        return ret;
 }
index cbb6b61..8e69b88 100644 (file)
@@ -28,6 +28,7 @@
 #include "ctree.h"
 #include "ioctl.h"
 #include "utils.h"
+#include "volumes.h"
 #include "cmds-fi-usage.h"
 
 #include "commands.h"
@@ -140,6 +141,7 @@ static int cmd_device_add(int argc, char **argv)
 
 error_out:
        close_file_or_dir(fdmnt, dirstream);
+       btrfs_close_all_devices();
        return !!ret;
 }
 
@@ -290,6 +292,7 @@ static int cmd_device_scan(int argc, char **argv)
        }
 
 out:
+       btrfs_close_all_devices();
        return !!ret;
 }
 
@@ -467,6 +470,7 @@ static int cmd_device_stats(int argc, char **argv)
 out:
        free(di_args);
        close_file_or_dir(fdmnt, dirstream);
+       btrfs_close_all_devices();
 
        return err;
 }
index c777f1c..a980305 100644 (file)
@@ -330,6 +330,7 @@ static int cmd_replace_start(int argc, char **argv)
                }
        }
        close_file_or_dir(fdmnt, dirstream);
+       btrfs_close_all_devices();
        return 0;
 
 leave_with_error:
@@ -339,6 +340,7 @@ leave_with_error:
                close(fdmnt);
        if (fddstdev != -1)
                close(fddstdev);
+       btrfs_close_all_devices();
        return 1;
 }
 
diff --git a/mkfs.c b/mkfs.c
index 7d635dc..3e60965 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1843,6 +1843,7 @@ raid_groups:
 out:
        ret = close_ctree(root);
        BUG_ON(ret);
+       btrfs_close_all_devices();
        free(label);
        return 0;
 }