summaryrefslogtreecommitdiff
path: root/cmds-replace.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmds-replace.c')
-rw-r--r--cmds-replace.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/cmds-replace.c b/cmds-replace.c
index 63d34f9..85365e3 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -132,19 +132,16 @@ static int cmd_start_replace(int argc, char **argv)
int i;
int c;
int fdmnt = -1;
- int fdsrcdev = -1;
int fddstdev = -1;
char *path;
char *srcdev;
char *dstdev = NULL;
int avoid_reading_from_srcdev = 0;
int force_using_targetdev = 0;
- 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) {
@@ -252,36 +249,16 @@ static int cmd_start_replace(int argc, char **argv)
srcdev, path);
goto leave_with_error;
}
- } else {
- fdsrcdev = open(srcdev, O_RDWR);
- if (fdsrcdev < 0) {
- fprintf(stderr, "Error: Unable to open device '%s'\n",
- srcdev);
- fprintf(stderr, "\tTry using the devid instead of the path\n");
- goto leave_with_error;
- }
- ret = fstat(fdsrcdev, &st);
- if (ret) {
- fprintf(stderr, "Error: Unable to stat '%s'\n", srcdev);
- goto leave_with_error;
- }
- if (!S_ISBLK(st.st_mode)) {
- fprintf(stderr, "Error: '%s' is not a block device\n",
- srcdev);
- goto leave_with_error;
- }
+ } else if (is_block_device(srcdev)) {
strncpy((char *)start_args.start.srcdev_name, srcdev,
BTRFS_DEVICE_PATH_NAME_MAX);
- close(fdsrcdev);
- fdsrcdev = -1;
start_args.start.srcdevid = 0;
}
- ret = test_dev_for_mkfs(dstdev, force_using_targetdev, estr);
- if (ret) {
- fprintf(stderr, "%s", estr);
+ ret = test_dev_for_mkfs(dstdev, force_using_targetdev);
+ if (ret)
goto leave_with_error;
- }
+
fddstdev = open(dstdev, O_RDWR);
if (fddstdev < 0) {
fprintf(stderr, "Unable to open %s\n", dstdev);
@@ -346,8 +323,6 @@ leave_with_error:
free(dstdev);
if (fdmnt != -1)
close(fdmnt);
- if (fdsrcdev != -1)
- close(fdsrcdev);
if (fddstdev != -1)
close(fddstdev);
return 1;
@@ -590,8 +565,11 @@ static int cmd_cancel_replace(int argc, char **argv)
return 0;
}
+static const char replace_cmd_group_info[] =
+"replace a device in the filesystem";
+
const struct cmd_group replace_cmd_group = {
- replace_cmd_group_usage, NULL, {
+ replace_cmd_group_usage, replace_cmd_group_info, {
{ "start", cmd_start_replace, cmd_start_replace_usage, NULL,
0 },
{ "status", cmd_status_replace, cmd_status_replace_usage, NULL,