mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-10 16:00:17 +00:00
btrfs-progs: use function is_block_device() instead
Here the delete code as below, is trying to check if the provided device is a block device, there is a function for it. Use it. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
fbb356632c
commit
d2d22a4f7b
@ -132,14 +132,12 @@ static int cmd_start_replace(int argc, char **argv)
|
|||||||
int i;
|
int i;
|
||||||
int c;
|
int c;
|
||||||
int fdmnt = -1;
|
int fdmnt = -1;
|
||||||
int fdsrcdev = -1;
|
|
||||||
int fddstdev = -1;
|
int fddstdev = -1;
|
||||||
char *path;
|
char *path;
|
||||||
char *srcdev;
|
char *srcdev;
|
||||||
char *dstdev = NULL;
|
char *dstdev = NULL;
|
||||||
int avoid_reading_from_srcdev = 0;
|
int avoid_reading_from_srcdev = 0;
|
||||||
int force_using_targetdev = 0;
|
int force_using_targetdev = 0;
|
||||||
struct stat st;
|
|
||||||
u64 dstdev_block_count;
|
u64 dstdev_block_count;
|
||||||
int do_not_background = 0;
|
int do_not_background = 0;
|
||||||
int mixed = 0;
|
int mixed = 0;
|
||||||
@ -252,28 +250,9 @@ static int cmd_start_replace(int argc, char **argv)
|
|||||||
srcdev, path);
|
srcdev, path);
|
||||||
goto leave_with_error;
|
goto leave_with_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (is_block_device(srcdev)) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
strncpy((char *)start_args.start.srcdev_name, srcdev,
|
strncpy((char *)start_args.start.srcdev_name, srcdev,
|
||||||
BTRFS_DEVICE_PATH_NAME_MAX);
|
BTRFS_DEVICE_PATH_NAME_MAX);
|
||||||
close(fdsrcdev);
|
|
||||||
fdsrcdev = -1;
|
|
||||||
start_args.start.srcdevid = 0;
|
start_args.start.srcdevid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,8 +325,6 @@ leave_with_error:
|
|||||||
free(dstdev);
|
free(dstdev);
|
||||||
if (fdmnt != -1)
|
if (fdmnt != -1)
|
||||||
close(fdmnt);
|
close(fdmnt);
|
||||||
if (fdsrcdev != -1)
|
|
||||||
close(fdsrcdev);
|
|
||||||
if (fddstdev != -1)
|
if (fddstdev != -1)
|
||||||
close(fddstdev);
|
close(fddstdev);
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user