From patchwork Mon Nov 8 20:03:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 318512 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 oAC1I1aO023460 for ; Fri, 12 Nov 2010 01:18:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757343Ab0KLBRu (ORCPT ); Thu, 11 Nov 2010 20:17:50 -0500 Received: from frost.carfax.org.uk ([212.13.194.111]:4306 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754001Ab0KLBRt (ORCPT ); Thu, 11 Nov 2010 20:17:49 -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:02 +0000 (UTC) X-Greylist: delayed 1899 seconds by postgrey-1.27 at vger.kernel.org; Thu, 11 Nov 2010 20:17:48 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 <1a77871a7e41984b5f153862ae4f61a3f59f4cc3@carfax.org.uk>) id 1PGhmK-0006tf-0H; Fri, 12 Nov 2010 00:46:08 +0000 Received: from hrm by vlad.carfax.org.uk with local (Exim 4.72) (envelope-from <1a77871a7e41984b5f153862ae4f61a3f59f4cc3@vlad.carfax.org.uk>) id 1PGhmI-0001yg-NG; Fri, 12 Nov 2010 00:46:06 +0000 Message-Id: <1a77871a7e41984b5f153862ae4f61a3f59f4cc3.1289521433.git.hugo@carfax.org.uk> In-Reply-To: References: From: Hugo Mills Date: Mon, 8 Nov 2010 20:03:49 +0000 Subject: [PATCH v2 1/3] Balance progress monitoring. To: linux-btrfs@vger.kernel.org, Goffredo Baroncelli , Chris Mason 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: This patch introduces a basic form of progress monitoring for balance operations, by counting the number of block groups remaining. The information is exposed to userspace by an ioctl. We also add "btrfs balance start" as an alias for "btrfs filesystem balance", so that all balance-related functions are available under one prefix. [...] 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 diff --git a/btrfs.c b/btrfs.c index 46314cf..0b6186c 100644 --- a/btrfs.c +++ b/btrfs.c @@ -95,6 +95,14 @@ static struct Command commands[] = { "filesystem balance", "\n" "Balance the chunks across the device." }, + { do_balance, 1, + "balance start", "\n" + "Synonym for \"btrfs filesystem balance\"." + }, + { do_balance_progress, -1, + "balance progress", "[-m|--monitor] \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" diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 8031c58..2745d64 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -28,6 +28,7 @@ #include #include #include +#include #undef ULONG_MAX @@ -776,6 +777,65 @@ int do_balance(int argc, char **argv) } return 0; } + +int get_balance_progress(char *path, struct btrfs_ioctl_balance_progress *bal) +{ + int fdmnt; + int ret = 0; + int err = 0; + + fdmnt = open_file_or_dir(path); + if(fdmnt < 0) { + return -1; + } + + ret = ioctl(fdmnt, BTRFS_IOC_BALANCE_PROGRESS, bal); + if(ret) + err = errno; + close(fdmnt); + + return err; +} + +int do_balance_progress(int argc, char **argv) +{ + char *path; + int ret = 0; + int err = 0; + struct btrfs_ioctl_balance_progress bal; + + path = argv[1]; + + ret = get_balance_progress(path, &bal); + if (!ret) + printf("\r%llu/%llu block groups moved, " + "%0.2f%% complete.\n", + bal.completed, + bal.expected, + (float)bal.completed/bal.expected*100.0); + + switch(ret) { + case 0: + break; + case -1: + fprintf(stderr, "ERROR: can't access '%s'\n", path); + return 13; + case EINVAL: + if (!monitor) { + fprintf(stderr, + "No balance operation running on '%s'.\n", + path); + return 20; + } + break; + default: + fprintf(stderr, "ERROR: ioctl returned error %d.", err); + return 21; + } + + return 0; +} + int do_remove_volume(int nargs, char **args) { diff --git a/btrfs_cmds.h b/btrfs_cmds.h index 7bde191..47b0a27 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -23,6 +23,7 @@ int do_defrag(int argc, char **argv); 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); diff --git a/ioctl.h b/ioctl.h index 776d7a9..888ceb9 100644 --- a/ioctl.h +++ b/ioctl.h @@ -132,6 +132,11 @@ struct btrfs_ioctl_space_args { 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 @@ struct btrfs_ioctl_space_args { #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, 25, \ + struct btrfs_ioctl_balance_progress) #endif diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 26ef982..69d8613 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -21,6 +21,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-][gkm]|max \fP .PP +\fBbtrfs\fP \fBbalance progress\fP \fI\fP +.PP \fBbtrfs\fP \fBdevice scan\fP\fI [ [..]]\fP .PP \fBbtrfs\fP \fBdevice show\fP\fI |