From patchwork Sat Oct 30 00:10:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 291512 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 o9U0BQTO007465 for ; Sat, 30 Oct 2010 00:11:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762183Ab0J3ALV (ORCPT ); Fri, 29 Oct 2010 20:11:21 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:2464 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762192Ab0J3ALS (ORCPT ); Fri, 29 Oct 2010 20:11:18 -0400 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 ) id 1PBz2T-0000d5-GH for linux-btrfs@vger.kernel.org; Sat, 30 Oct 2010 00:11:17 +0000 Received: from hrm by vlad.carfax.org.uk with local (Exim 4.72) (envelope-from ) id 1PBz2T-0003pS-1l; Sat, 30 Oct 2010 01:11:17 +0100 Message-Id: <20101030001042.809576287@carfax.org.uk> User-Agent: quilt/0.48-1 Date: Sat, 30 Oct 2010 01:10:24 +0100 From: Hugo Mills To: linux-btrfs@vger.kernel.org Cc: Hugo Mills Subject: [patch 2/2] User-space tool for cancelling balance operations. References: <20101030001022.247934404@carfax.org.uk> Content-Disposition: inline; filename=balance-cancel X-frost.carfax.org.uk-Spam-Score: -0.0 (/) X-frost.carfax.org.uk-Spam-Report: Spam detection software, running on the system "spamd0.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(+) [...] 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.3 (demeter1.kernel.org [140.211.167.41]); Sat, 30 Oct 2010 00:11:26 +0000 (UTC) Index: btrfs-progs-unstable/btrfs.c =================================================================== --- btrfs-progs-unstable.orig/btrfs.c 2010-10-30 00:19:59.968416575 +0100 +++ btrfs-progs-unstable/btrfs.c 2010-10-30 00:20:38.446849736 +0100 @@ -99,6 +99,10 @@ "balance progress", "\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" Index: btrfs-progs-unstable/btrfs_cmds.c =================================================================== --- btrfs-progs-unstable.orig/btrfs_cmds.c 2010-10-30 00:04:48.335524683 +0100 +++ btrfs-progs-unstable/btrfs_cmds.c 2010-10-30 00:20:22.267508562 +0100 @@ -848,6 +848,47 @@ 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) { Index: btrfs-progs-unstable/btrfs_cmds.h =================================================================== --- btrfs-progs-unstable.orig/btrfs_cmds.h 2010-10-30 00:04:48.335524683 +0100 +++ btrfs-progs-unstable/btrfs_cmds.h 2010-10-30 00:20:22.307506934 +0100 @@ -24,6 +24,7 @@ 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); Index: btrfs-progs-unstable/ioctl.h =================================================================== --- btrfs-progs-unstable.orig/ioctl.h 2010-10-30 00:04:48.325525089 +0100 +++ btrfs-progs-unstable/ioctl.h 2010-10-30 00:20:22.357504895 +0100 @@ -176,4 +176,5 @@ struct btrfs_ioctl_space_args) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 21, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 22) #endif