From patchwork Sat Oct 30 00:10:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 291502 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 o9U0BQTN007465 for ; Sat, 30 Oct 2010 00:11:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762199Ab0J3ALU (ORCPT ); Fri, 29 Oct 2010 20:11:20 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:2463 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762183Ab0J3ALS (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-0000d4-Au 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 1PBz2S-0003pO-TO; Sat, 30 Oct 2010 01:11:16 +0100 Message-Id: <20101030001042.578795639@carfax.org.uk> User-Agent: quilt/0.48-1 Date: Sat, 30 Oct 2010 01:10:23 +0100 From: Hugo Mills To: linux-btrfs@vger.kernel.org Cc: Hugo Mills Subject: [patch 1/2] Balance progress monitoring. References: <20101030001022.247934404@carfax.org.uk> Content-Disposition: inline; filename=balance-progress X-frost.carfax.org.uk-Spam-Score: -0.0 (/) X-frost.carfax.org.uk-Spam-Report: Spam detection software, running on the system "spamd3.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 support to the btrfs tool for monitoring a balance operation on a filesystem. Signed-off-by: Hugo Mills --- btrfs.c | 4 ++++ btrfs_cmds.c | 40 ++++++++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ioctl.h | 7 +++++++ 4 files changed, 52 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-28 22:58:54.805035975 +0100 +++ btrfs-progs-unstable/btrfs.c 2010-10-30 00:19:59.968416575 +0100 @@ -95,6 +95,10 @@ "filesystem balance", "\n" "Balance the chunks across the device." }, + { do_balance_progress, 1, + "balance progress", "\n" + "Show progress of 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-28 22:58:54.855033936 +0100 +++ btrfs-progs-unstable/btrfs_cmds.c 2010-10-30 00:04:48.335524683 +0100 @@ -808,6 +808,46 @@ } return 0; } + +int do_balance_progress(int argc, char **argv) +{ + char *path = argv[1]; + int fdmnt; + int ret = 0; + int err = 0; + struct btrfs_ioctl_balance_progress bal; + + 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_PROGRESS, &bal); + if(!ret) + err = errno; + close(fdmnt); + + switch(err) { + case 0: + break; + case -EINVAL: + fprintf(stderr, "No balance operation running on '%s'.\n", + path); + return 20; + default: + fprintf(stderr, "ERROR: ioctl returned error %d.", err); + return 21; + } + + printf("%llu/%llu block groups moved, %0.2f%% complete.\n", + bal.completed, + bal.expected, + (float)bal.completed/bal.expected*100.0); + + return 0; +} + int do_remove_volume(int nargs, char **args) { Index: btrfs-progs-unstable/btrfs_cmds.h =================================================================== --- btrfs-progs-unstable.orig/btrfs_cmds.h 2010-10-28 22:58:54.895032304 +0100 +++ btrfs-progs-unstable/btrfs_cmds.h 2010-10-30 00:04:48.335524683 +0100 @@ -23,6 +23,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_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-28 23:14:16.937413446 +0100 +++ btrfs-progs-unstable/ioctl.h 2010-10-30 00:04:48.325525089 +0100 @@ -132,6 +132,11 @@ struct btrfs_ioctl_space_info spaces[0]; }; +struct btrfs_ioctl_balance_progress { + __u64 expected; + __u64 completed; +}; + #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args) #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ @@ -169,4 +174,6 @@ #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64) #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 21, \ + struct btrfs_ioctl_balance_progress) #endif