summaryrefslogtreecommitdiff
path: root/cmds-replace.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2013-07-26 01:35:27 +0800
committerDavid Sterba <dsterba@suse.cz>2013-09-03 19:40:51 +0200
commit689ad3e362c1e6d54ef7b6876dbb64e1e51b8cf1 (patch)
tree2aafcf343e9de147cf42d92d8dbb07a85a0816e8 /cmds-replace.c
parentbbe9df154b2c9bc122e1099382d1658c8cf0e904 (diff)
btrfs-progs: cmd_start_replace() to use test_dev_for_mkfs()
test_dev_for_mkfs() is a common place where we check if a device is fit for the btrfs use. cmd_start_replace() should make use of test_dev_for_mkfs(), and here the test_dev_for_mkfs() is further enhanced to fit the cmd_start_replace() needs. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'cmds-replace.c')
-rw-r--r--cmds-replace.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/cmds-replace.c b/cmds-replace.c
index 25e8c7fa..8ed92c44 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -137,13 +137,12 @@ static int cmd_start_replace(int argc, char **argv)
char *dstdev;
int avoid_reading_from_srcdev = 0;
int force_using_targetdev = 0;
- u64 total_devs = 1;
- struct btrfs_fs_devices *fs_devices_mnt = NULL;
struct stat st;
u64 dstdev_block_count;
int do_not_background = 0;
int mixed = 0;
DIR *dirstream = NULL;
+ char estr[100]; /* check test_dev_for_mkfs() for error string size*/
while ((c = getopt(argc, argv, "Brf")) != -1) {
switch (c) {
@@ -265,15 +264,9 @@ static int cmd_start_replace(int argc, char **argv)
start_args.start.srcdevid = 0;
}
- ret = check_mounted(dstdev);
- if (ret < 0) {
- fprintf(stderr, "Error checking %s mount status\n", dstdev);
- goto leave_with_error;
- }
- if (ret == 1) {
- fprintf(stderr,
- "Error, target device %s is in use and currently mounted!\n",
- dstdev);
+ ret = test_dev_for_mkfs(dstdev, force_using_targetdev, estr);
+ if (ret) {
+ fprintf(stderr, "%s", estr);
goto leave_with_error;
}
fddstdev = open(dstdev, O_RDWR);
@@ -281,23 +274,6 @@ static int cmd_start_replace(int argc, char **argv)
fprintf(stderr, "Unable to open %s\n", dstdev);
goto leave_with_error;
}
- ret = btrfs_scan_one_device(fddstdev, dstdev, &fs_devices_mnt,
- &total_devs, BTRFS_SUPER_INFO_OFFSET);
- if (ret >= 0 && !force_using_targetdev) {
- fprintf(stderr,
- "Error, target device %s contains filesystem, use '-f' to force overwriting.\n",
- dstdev);
- goto leave_with_error;
- }
- ret = fstat(fddstdev, &st);
- if (ret) {
- fprintf(stderr, "Error: Unable to stat '%s'\n", dstdev);
- goto leave_with_error;
- }
- if (!S_ISBLK(st.st_mode)) {
- fprintf(stderr, "Error: '%s' is not a block device\n", dstdev);
- goto leave_with_error;
- }
strncpy((char *)start_args.start.tgtdev_name, dstdev,
BTRFS_DEVICE_PATH_NAME_MAX);
if (btrfs_prepare_device(fddstdev, dstdev, 1, &dstdev_block_count, 0,