btrfs-progs: close all fs_devices before exit in some commands

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>
master
Zhao Lei 2015-08-24 16:45:03 +08:00 committed by David Sterba
parent b0f760c91a
commit ec1fc69d39
4 changed files with 8 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

1
mkfs.c
View File

@ -1843,6 +1843,7 @@ raid_groups:
out:
ret = close_ctree(root);
BUG_ON(ret);
btrfs_close_all_devices();
free(label);
return 0;
}