static int dev_replace_cancel_fd = -1;
static void dev_replace_sigint_handler(int signal)
{
+ int ret;
struct btrfs_ioctl_dev_replace_args args = {0};
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
- ioctl(dev_replace_cancel_fd, BTRFS_IOC_DEV_REPLACE, &args);
+ ret = ioctl(dev_replace_cancel_fd, BTRFS_IOC_DEV_REPLACE, &args);
+ if (ret < 0)
+ perror("Device replace cancel failed");
}
static int dev_replace_handle_sigint(int fd)
u64 dstdev_block_count;
int do_not_background = 0;
int mixed = 0;
+ DIR *dirstream = NULL;
while ((c = getopt(argc, argv, "Brf")) != -1) {
switch (c) {
if (check_argc_exact(argc - optind, 3))
usage(cmd_start_replace_usage);
path = argv[optind + 2];
- fdmnt = open_file_or_dir(path);
+
+ fdmnt = open_path_or_dev_mnt(path, &dirstream);
+
if (fdmnt < 0) {
fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
path, strerror(errno));
}
start_args.start.srcdevid = (__u64)atoi(srcdev);
- ret = get_fs_info(fdmnt, path, &fi_args, &di_args);
+ ret = get_fs_info(path, &fi_args, &di_args);
if (ret) {
fprintf(stderr, "ERROR: getting dev info for devstats failed: "
"%s\n", strerror(-ret));
for (i = 0; i < fi_args.num_devices; i++)
if (start_args.start.srcdevid == di_args[i].devid)
break;
+ free(di_args);
if (i == fi_args.num_devices) {
fprintf(stderr, "Error: '%s' is not a valid devid for filesystem '%s'\n",
srcdev, path);
}
} else {
fdsrcdev = open(srcdev, O_RDWR);
- if (!fdsrcdev) {
+ if (fdsrcdev < 0) {
fprintf(stderr, "Error: Unable to open device '%s'\n",
srcdev);
goto leave_with_error;
goto leave_with_error;
}
}
- close(fdmnt);
+ close_file_or_dir(fdmnt, dirstream);
return 0;
leave_with_error:
char *path;
int once = 0;
int ret;
+ DIR *dirstream = NULL;
while ((c = getopt(argc, argv, "1")) != -1) {
switch (c) {
usage(cmd_status_replace_usage);
path = argv[optind];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
e = errno;
if (fd < 0) {
fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
}
ret = print_replace_status(fd, path, once);
- close(fd);
+ close_file_or_dir(fd, dirstream);
return ret;
}
int fd;
int e;
char *path;
+ DIR *dirstream = NULL;
while ((c = getopt(argc, argv, "")) != -1) {
switch (c) {
usage(cmd_cancel_replace_usage);
path = argv[optind];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
path, strerror(errno));
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret) {
fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %s, %s\n",
path, strerror(e),