@@ -103,6 +103,10 @@ static struct Command commands[] = {
"balance progress", "[-m|--monitor] <path>\n"
"Show progress of the balance operation running on <path>."
},
+ { do_balance_cancel, 1,
+ "balance cancel", "<path>\n"
+ "Cancel the balance operation running on <path>."
+ },
{ do_scan,
999, "device scan", "[<device> [<device>..]\n"
"Scan all device for or the passed device for a btrfs\n"
@@ -922,6 +922,47 @@ int do_balance_progress(int argc, char **argv)
return 0;
}
+int do_balance_cancel(int nargs, char **argv)
+{
+ char *path = argv[1];
+ int fdmnt;
+ int ret = 0;
+ int err = 0;
+
+ fdmnt = open_file_or_dir(path);
+ if(fdmnt < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 12;
+ }
+
+ ret = ioctl(fdmnt, BTRFS_IOC_BALANCE_CANCEL, NULL);
+ err = errno;
+
+ if(ret) {
+ switch(err) {
+ case 0:
+ break;
+ case EINVAL:
+ fprintf(stderr, "ERROR: no balance in progress.\n");
+ err = 20;
+ break;
+ case ECANCELED:
+ fprintf(stderr, "ERROR: operation already cancelled.\n");
+ err = 21;
+ break;
+ default:
+ fprintf(stderr, "ERROR: ioctl returned error '%d'.\n",
+ err);
+ err = 22;
+ break;
+ }
+ }
+
+ close(fdmnt);
+
+ return err;
+}
+
int do_remove_volume(int nargs, char **args)
{
@@ -24,6 +24,7 @@ int do_show_filesystem(int nargs, char **argv);
int do_add_volume(int nargs, char **args);
int do_balance(int nargs, char **argv);
int do_balance_progress(int nargs, char **argv);
+int do_balance_cancel(int nargs, char **argv);
int do_remove_volume(int nargs, char **args);
int do_scan(int nargs, char **argv);
int do_resize(int nargs, char **argv);
@@ -176,4 +176,5 @@ struct btrfs_ioctl_balance_progress {
struct btrfs_ioctl_space_args)
#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 25, \
struct btrfs_ioctl_balance_progress)
+#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 26)
#endif