From patchwork Fri Nov 5 23:34:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 318552 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 oAC1I1aN023460 for ; Fri, 12 Nov 2010 01:18:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757338Ab0KLBRs (ORCPT ); Thu, 11 Nov 2010 20:17:48 -0500 Received: from frost.carfax.org.uk ([212.13.194.111]:4305 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754001Ab0KLBRr (ORCPT ); Thu, 11 Nov 2010 20:17:47 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 12 Nov 2010 01:18:01 +0000 (UTC) X-Greylist: delayed 1898 seconds by postgrey-1.27 at vger.kernel.org; Thu, 11 Nov 2010 20:17:47 EST Received: from intmx.carfax.org.uk ([10.0.0.5] helo=vlad.carfax.org.uk ident=Debian-exim) by frost.carfax.org.uk with esmtp (Exim 4.69) (envelope-from <43c88d2b49066e32a19d90cc6060615653f104eb@carfax.org.uk>) id 1PGhmK-0006tk-0N; Fri, 12 Nov 2010 00:46:08 +0000 Received: from hrm by vlad.carfax.org.uk with local (Exim 4.72) (envelope-from <43c88d2b49066e32a19d90cc6060615653f104eb@vlad.carfax.org.uk>) id 1PGhmJ-0001yo-01; Fri, 12 Nov 2010 00:46:07 +0000 Message-Id: <43c88d2b49066e32a19d90cc6060615653f104eb.1289521433.git.hugo@carfax.org.uk> In-Reply-To: References: From: Hugo Mills Date: Fri, 5 Nov 2010 23:34:02 +0000 Subject: [PATCH v2 3/3] User-space tool for cancelling balance operations. To: linux-btrfs@vger.kernel.org, Goffredo Baroncelli , Chris Mason X-frost.carfax.org.uk-Spam-Score: 2.1 (++) 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 + 4 files changed, 47 insertions(+), 0 deletions(-) [...] Content analysis details: (2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 2.1 DATE_IN_PAST_96_XX Date: is 96 hours or more before Received: date -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 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 888ceb9..1fc665b 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, 25, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 26) #endif