projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
btrfs-progs: check/original: Remove unused variable first_key
[platform/upstream/btrfs-progs.git]
/
cmds-replace.c
diff --git
a/cmds-replace.c
b/cmds-replace.c
index
385b764
..
032a44f
100644
(file)
--- a/
cmds-replace.c
+++ b/
cmds-replace.c
@@
-37,7
+37,8
@@
#include "disk-io.h"
#include "commands.h"
#include "disk-io.h"
#include "commands.h"
-
+#include "help.h"
+#include "mkfs/common.h"
static int print_replace_status(int fd, const char *path, int once);
static char *time2string(char *buf, size_t s, __u64 t);
static int print_replace_status(int fd, const char *path, int once);
static char *time2string(char *buf, size_t s, __u64 t);
@@
-65,17
+66,6
@@
static const char * const replace_cmd_group_usage[] = {
NULL
};
NULL
};
-static int is_numerical(const char *str)
-{
- if (!(*str >= '0' && *str <= '9'))
- return 0;
- while (*str >= '0' && *str <= '9')
- str++;
- if (*str != '\0')
- return 0;
- return 1;
-}
-
static int dev_replace_cancel_fd = -1;
static void dev_replace_sigint_handler(int signal)
{
static int dev_replace_cancel_fd = -1;
static void dev_replace_sigint_handler(int signal)
{
@@
-140,7
+130,6
@@
static int cmd_replace_start(int argc, char **argv)
int force_using_targetdev = 0;
u64 dstdev_block_count;
int do_not_background = 0;
int force_using_targetdev = 0;
u64 dstdev_block_count;
int do_not_background = 0;
- int mixed = 0;
DIR *dirstream = NULL;
u64 srcdev_size;
u64 dstdev_size;
DIR *dirstream = NULL;
u64 srcdev_size;
u64 dstdev_size;
@@
-178,10
+167,10
@@
static int cmd_replace_start(int argc, char **argv)
status_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
status_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &status_args);
status_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
status_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &status_args);
- if (ret) {
+ if (ret
< 0
) {
fprintf(stderr,
fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %
s
",
- path
, strerror(errno)
);
+ "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %
m
",
+ path);
if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(status_args.result));
if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(status_args.result));
@@
-191,30
+180,26
@@
static int cmd_replace_start(int argc, char **argv)
}
if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
}
if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
- fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" returns error: %s\n",
+ error("ioctl(DEV_REPLACE_STATUS) on '%s' returns error: %s",
path, replace_dev_result2string(status_args.result));
goto leave_with_error;
}
if (status_args.status.replace_state ==
BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED) {
path, replace_dev_result2string(status_args.result));
goto leave_with_error;
}
if (status_args.status.replace_state ==
BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED) {
- fprintf(stderr,
- "ERROR: btrfs replace on \"%s\" already started!\n",
- path);
+ error("device replace on '%s' already started", path);
goto leave_with_error;
}
srcdev = argv[optind];
dstdev = canonicalize_path(argv[optind + 1]);
if (!dstdev) {
goto leave_with_error;
}
srcdev = argv[optind];
dstdev = canonicalize_path(argv[optind + 1]);
if (!dstdev) {
- fprintf(stderr,
- "ERROR: Could not canonicalize path '%s': %s\n",
- argv[optind + 1], strerror(errno));
+ error("cannot canonicalize path '%s': %m",
+ argv[optind + 1]);
goto leave_with_error;
}
goto leave_with_error;
}
- if (is_numerical(srcdev)) {
+ if (
string_
is_numerical(srcdev)) {
struct btrfs_ioctl_fs_info_args fi_args;
struct btrfs_ioctl_dev_info_args *di_args = NULL;
struct btrfs_ioctl_fs_info_args fi_args;
struct btrfs_ioctl_dev_info_args *di_args = NULL;
@@
-222,13
+207,12
@@
static int cmd_replace_start(int argc, char **argv)
ret = get_fs_info(path, &fi_args, &di_args);
if (ret) {
ret = get_fs_info(path, &fi_args, &di_args);
if (ret) {
- fprintf(stderr, "ERROR: getting dev info for devstats failed: "
- "%s\n", strerror(-ret));
+ error("failed to get device info: %s", strerror(-ret));
free(di_args);
goto leave_with_error;
}
if (!fi_args.num_devices) {
free(di_args);
goto leave_with_error;
}
if (!fi_args.num_devices) {
-
fprintf(stderr, "ERROR: no devices found\n
");
+
error("no devices found
");
free(di_args);
goto leave_with_error;
}
free(di_args);
goto leave_with_error;
}
@@
-239,7
+223,7
@@
static int cmd_replace_start(int argc, char **argv)
srcdev_size = di_args[i].total_bytes;
free(di_args);
if (i == fi_args.num_devices) {
srcdev_size = di_args[i].total_bytes;
free(di_args);
if (i == fi_args.num_devices) {
-
fprintf(stderr, "Error: '%s' is not a valid devid for filesystem '%s'\n
",
+
error("'%s' is not a valid devid for filesystem '%s'
",
srcdev, path);
goto leave_with_error;
}
srcdev, path);
goto leave_with_error;
}
@@
-249,7
+233,7
@@
static int cmd_replace_start(int argc, char **argv)
start_args.start.srcdevid = 0;
srcdev_size = get_partition_size(srcdev);
} else {
start_args.start.srcdevid = 0;
srcdev_size = get_partition_size(srcdev);
} else {
-
fprintf(stderr, "ERROR: source device must be a block device or a devid\n
");
+
error("source device must be a block device or a devid
");
goto leave_with_error;
}
goto leave_with_error;
}
@@
-259,20
+243,20
@@
static int cmd_replace_start(int argc, char **argv)
dstdev_size = get_partition_size(dstdev);
if (srcdev_size > dstdev_size) {
dstdev_size = get_partition_size(dstdev);
if (srcdev_size > dstdev_size) {
-
fprintf(stderr, "ERROR: target device smaller than source device (required %llu bytes)\n
",
+
error("target device smaller than source device (required %llu bytes)
",
srcdev_size);
goto leave_with_error;
}
fddstdev = open(dstdev, O_RDWR);
if (fddstdev < 0) {
srcdev_size);
goto leave_with_error;
}
fddstdev = open(dstdev, O_RDWR);
if (fddstdev < 0) {
-
fprintf(stderr, "Unable to open %s\n
", dstdev);
+
error("unable to open %s: %m
", dstdev);
goto leave_with_error;
}
strncpy((char *)start_args.start.tgtdev_name, dstdev,
BTRFS_DEVICE_PATH_NAME_MAX);
goto leave_with_error;
}
strncpy((char *)start_args.start.tgtdev_name, dstdev,
BTRFS_DEVICE_PATH_NAME_MAX);
- ret = btrfs_prepare_device(fddstdev, dstdev,
1,
&dstdev_block_count, 0,
-
&mixed, 0
);
+ ret = btrfs_prepare_device(fddstdev, dstdev, &dstdev_block_count, 0,
+
PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE
);
if (ret)
goto leave_with_error;
if (ret)
goto leave_with_error;
@@
-284,8
+268,7
@@
static int cmd_replace_start(int argc, char **argv)
dev_replace_handle_sigint(fdmnt);
if (!do_not_background) {
if (daemon(0, 0) < 0) {
dev_replace_handle_sigint(fdmnt);
if (!do_not_background) {
if (daemon(0, 0) < 0) {
- fprintf(stderr, "ERROR, backgrounding failed: %s\n",
- strerror(errno));
+ error("backgrounding failed: %m");
goto leave_with_error;
}
}
goto leave_with_error;
}
}
@@
-294,10
+277,10
@@
static int cmd_replace_start(int argc, char **argv)
start_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
if (do_not_background) {
start_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
if (do_not_background) {
- if (ret) {
+ if (ret
< 0
) {
fprintf(stderr,
fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %
s
",
- path
, strerror(errno)
);
+ "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %
m
",
+ path);
if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(start_args.result));
if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(start_args.result));
@@
-305,23
+288,20
@@
static int cmd_replace_start(int argc, char **argv)
fprintf(stderr, "\n");
if (errno == EOPNOTSUPP)
fprintf(stderr, "\n");
if (errno == EOPNOTSUPP)
- fprintf(stderr,
- "WARNING: dev_replace does not yet handle RAID5/6\n");
+ warning("device replace of RAID5/6 not supported with this kernel");
goto leave_with_error;
}
if (start_args.result !=
BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
goto leave_with_error;
}
if (start_args.result !=
BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
- fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_START) on \"%s\" returns error: %s\n",
+ error("ioctl(DEV_REPLACE_START) on '%s' returns error: %s",
path,
replace_dev_result2string(start_args.result));
goto leave_with_error;
}
}
close_file_or_dir(fdmnt, dirstream);
path,
replace_dev_result2string(start_args.result));
goto leave_with_error;
}
}
close_file_or_dir(fdmnt, dirstream);
- btrfs_close_all_devices();
return 0;
leave_with_error:
return 0;
leave_with_error:
@@
-331,7
+311,6
@@
leave_with_error:
close(fdmnt);
if (fddstdev != -1)
close(fddstdev);
close(fdmnt);
if (fddstdev != -1)
close(fddstdev);
- btrfs_close_all_devices();
return 1;
}
return 1;
}
@@
-348,7
+327,6
@@
static const char *const cmd_replace_status_usage[] = {
static int cmd_replace_status(int argc, char **argv)
{
int fd;
static int cmd_replace_status(int argc, char **argv)
{
int fd;
- int e;
int c;
char *path;
int once = 0;
int c;
char *path;
int once = 0;
@@
-370,13
+348,9
@@
static int cmd_replace_status(int argc, char **argv)
usage(cmd_replace_status_usage);
path = argv[optind];
usage(cmd_replace_status_usage);
path = argv[optind];
- fd = open_file_or_dir(path, &dirstream);
- e = errno;
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
- path, strerror(e));
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
return 1;
return 1;
- }
ret = print_replace_status(fd, path, once);
close_file_or_dir(fd, dirstream);
ret = print_replace_status(fd, path, once);
close_file_or_dir(fd, dirstream);
@@
-399,9
+373,9
@@
static int print_replace_status(int fd, const char *path, int once)
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
- if (ret) {
- fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %
s
",
- path
, strerror(errno)
);
+ if (ret
< 0
) {
+ fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %
m
",
+ path);
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));
@@
-411,7
+385,7
@@
static int print_replace_status(int fd, const char *path, int once)
}
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
}
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
-
fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" returns error: %s\n
",
+
error("ioctl(DEV_REPLACE_STATUS) on '%s' returns error: %s
",
path,
replace_dev_result2string(args.result));
return -1;
path,
replace_dev_result2string(args.result));
return -1;
@@
-463,8
+437,7
@@
static int print_replace_status(int fd, const char *path, int once)
printf("Never started");
break;
default:
printf("Never started");
break;
default:
- fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" got unknown status: %llu\n",
+ error("unknown status from ioctl DEV_REPLACE_STATUS on '%s': %llu",
path, status->replace_state);
return -EINVAL;
}
path, status->replace_state);
return -EINVAL;
}
@@
-525,7
+498,6
@@
static int cmd_replace_cancel(int argc, char **argv)
int ret;
int c;
int fd;
int ret;
int c;
int fd;
- int e;
char *path;
DIR *dirstream = NULL;
char *path;
DIR *dirstream = NULL;
@@
-541,21
+513,17
@@
static int cmd_replace_cancel(int argc, char **argv)
usage(cmd_replace_cancel_usage);
path = argv[optind];
usage(cmd_replace_cancel_usage);
path = argv[optind];
- fd = open_file_or_dir(path, &dirstream);
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
- path, strerror(errno));
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
return 1;
return 1;
- }
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
- e = errno;
close_file_or_dir(fd, dirstream);
close_file_or_dir(fd, dirstream);
- if (ret) {
- fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %
s
",
- path
, strerror(e)
);
+ if (ret
< 0
) {
+ fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %
m
",
+ path);
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));