From patchwork Sun Apr 10 21:16:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 697161 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3ALGdFd024061 for ; Sun, 10 Apr 2011 21:16:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758015Ab1DJVQi (ORCPT ); Sun, 10 Apr 2011 17:16:38 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:1740 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757973Ab1DJVQg (ORCPT ); Sun, 10 Apr 2011 17:16:36 -0400 Received: from ruthven.carfax.org.uk ([10.0.0.10]) by frost.carfax.org.uk with esmtp (Exim 4.69) (envelope-from ) id 1Q91zm-0005Ai-W7; Sun, 10 Apr 2011 21:16:35 +0000 Received: from [10.0.0.10] (helo=ruthven.carfax.org.uk) by ruthven.carfax.org.uk with esmtp (Exim 4.72) (envelope-from ) id 1Q91zm-0003TJ-Ni; Sun, 10 Apr 2011 22:16:34 +0100 From: Hugo Mills To: chris.mason@oracle.com, linux-btrfs@vger.kernel.org Subject: [PATCH v5 3/8] User-space tool for cancelling balance operations. Date: Sun, 10 Apr 2011 22:16:29 +0100 Message-Id: <4bd034d604ce77f80ffc2600015025da6f31c75a.1302469689.git.hugo@carfax.org.uk> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: To: linux-btrfs@vger.kernel.org X-frost.carfax.org.uk-Spam-Score: -0.0 (/) X-frost.carfax.org.uk-Spam-Report: Spam detection software, running on the system "spamd1.lon.bitfolk.com", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add an option to the btrfs tool to use the ioctl for cancelling balance operations. Signed-off-by: Hugo Mills --- btrfs.c | 4 ++++ btrfs_cmds.c | 41 +++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 1 + man/btrfs.8.in | 6 ++++++ 5 files changed, 53 insertions(+), 0 deletions(-) [...] Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 10 Apr 2011 21:16:51 +0000 (UTC) Add an option to the btrfs tool to use the ioctl for cancelling balance operations. Signed-off-by: Hugo Mills --- btrfs.c | 4 ++++ btrfs_cmds.c | 41 +++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 1 + man/btrfs.8.in | 6 ++++++ 5 files changed, 53 insertions(+), 0 deletions(-) diff --git a/btrfs.c b/btrfs.c index 0b6186c..93f7886 100644 --- a/btrfs.c +++ b/btrfs.c @@ -103,6 +103,10 @@ static struct Command commands[] = { "balance progress", "[-m|--monitor] \n" "Show progress of the balance operation running on ." }, + { do_balance_cancel, 1, + "balance cancel", "\n" + "Cancel the balance operation running on ." + }, { do_scan, 999, "device scan", "[ [..]\n" "Scan all device for or the passed device for a btrfs\n" diff --git a/btrfs_cmds.c b/btrfs_cmds.c index c681b5a..d246a8b 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -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) { diff --git a/btrfs_cmds.h b/btrfs_cmds.h index 47b0a27..5cb0d9c 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -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); diff --git a/ioctl.h b/ioctl.h index 3eeaa33..40c0b57 100644 --- a/ioctl.h +++ b/ioctl.h @@ -176,4 +176,5 @@ struct btrfs_ioctl_balance_progress { struct btrfs_ioctl_space_args) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) #endif diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 90be97e..d7fab80 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -25,6 +25,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fI\fP .PP +\fBbtrfs\fP \fBbalance cancel\fP \fI\fP +.PP \fBbtrfs\fP \fBdevice show\fP\fI |