int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
}
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
if (e != EINPROGRESS)
fprintf(stderr, "There may be more info in "
"syslog - try dmesg | tail\n");
- ret = 19;
+ ret = 1;
}
} else {
printf("Done, had to relocate %llu out of %llu chunks\n",
}
out:
- close(fd);
+ close_file_or_dir(fd, dirstream);
return ret;
}
{ "system", optional_argument, NULL, 's' },
{ "force", no_argument, NULL, 'f' },
{ "verbose", no_argument, NULL, 'v' },
- { 0, 0, 0, 0 }
+ { NULL, no_argument, NULL, 0 },
};
int opt = getopt_long(argc, argv, "d::s::m::fv", longopts,
int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
usage(cmd_balance_pause_usage);
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
}
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_PAUSE);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
fprintf(stderr, "ERROR: balance pause on '%s' failed - %s\n",
path, (e == ENOTCONN) ? "Not running" : strerror(e));
- return 19;
+ if (e == ENOTCONN)
+ return 2;
+ else
+ return 1;
}
return 0;
int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
usage(cmd_balance_cancel_usage);
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
}
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_CANCEL);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
fprintf(stderr, "ERROR: balance cancel on '%s' failed - %s\n",
path, (e == ENOTCONN) ? "Not in progress" : strerror(e));
- return 19;
+ if (e == ENOTCONN)
+ return 2;
+ else
+ return 1;
}
return 0;
{
struct btrfs_ioctl_balance_args args;
const char *path;
+ DIR *dirstream = NULL;
int fd;
int ret;
int e;
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
}
memset(&args, 0, sizeof(args));
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
if (e == ECANCELED) {
"failed - %s\n", path,
(e == ENOTCONN) ? "Not in progress" :
"Already running");
- return 19;
+ if (e == ENOTCONN)
+ return 2;
+ else
+ return 1;
} else {
fprintf(stderr,
"ERROR: error during balancing '%s' - %s\n"
"There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
- return 19;
+ return 1;
}
} else {
printf("Done, had to relocate %llu out of %llu chunks\n",
NULL
};
+/* Checks the status of the balance if any
+ * return codes:
+ * 2 : Error failed to know if there is any pending balance
+ * 1 : Successful to know status of a pending balance
+ * 0 : When there is no pending balance or completed
+ */
static int cmd_balance_status(int argc, char **argv)
{
struct btrfs_ioctl_balance_args args;
const char *path;
+ DIR *dirstream = NULL;
int fd;
int verbose = 0;
int ret;
int longindex;
static struct option longopts[] = {
{ "verbose", no_argument, NULL, 'v' },
- { 0, 0, 0, 0}
+ { NULL, no_argument, NULL, 0}
};
int opt = getopt_long(argc, argv, "v", longopts, &longindex);
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 to '%s'\n", path);
- return 12;
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 2;
}
ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
+ if (e == ENOTCONN) {
+ printf("No balance found on '%s'\n", path);
+ return 0;
+ }
fprintf(stderr, "ERROR: balance status on '%s' failed - %s\n",
- path, (e == ENOTCONN) ? "Not in progress" : strerror(e));
- return 19;
+ path, strerror(e));
+ return 2;
}
if (args.state & BTRFS_BALANCE_STATE_RUNNING) {
if (verbose)
dump_ioctl_balance_args(&args);
- return 0;
+ return 1;
}
const struct cmd_group balance_cmd_group = {
{ "cancel", cmd_balance_cancel, cmd_balance_cancel_usage, NULL, 0 },
{ "resume", cmd_balance_resume, cmd_balance_resume_usage, NULL, 0 },
{ "status", cmd_balance_status, cmd_balance_status_usage, NULL, 0 },
- { 0, 0, 0, 0, 0 }
+ NULL_CMD_STRUCT
}
};