linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hugo Mills <hugo@carfax.org.uk>
To: linux-btrfs@vger.kernel.org
Cc: Hugo Mills <hugo@carfax.org.uk>
Subject: [patch 2/2] User-space tool for cancelling balance operations.
Date: Sat, 30 Oct 2010 01:10:24 +0100	[thread overview]
Message-ID: <20101030001042.809576287@carfax.org.uk> (raw)
In-Reply-To: 20101030001022.247934404@carfax.org.uk

Add an option to the btrfs tool to use the ioctl for cancelling
balance operations.

SIgned-off-by: Hugo Mills <hugo@carfax.org.uk>

---
 btrfs.c      |    4 ++++
 btrfs_cmds.c |   41 +++++++++++++++++++++++++++++++++++++++++
 btrfs_cmds.h |    1 +
 ioctl.h      |    1 +
 4 files changed, 47 insertions(+)

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", "<path>\n"
 		"Show progress of the balance operation running on <path>."
 	},
+	{ do_balance_cancel, 1,
+	  "balance cancel", "<path>\n"
+		"Cancel the balance operation running on <path>."
+	},
 	{ do_scan,
 	  999, "device scan", "[<device> [<device>..]\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



  parent reply	other threads:[~2010-10-30  0:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-30  0:10 [patch 0/2] Control filesystem balances (userspace) Hugo Mills
2010-10-30  0:10 ` [patch 1/2] Balance progress monitoring Hugo Mills
2010-10-30  0:10 ` Hugo Mills [this message]
2010-10-30  0:30 ` [patch 0/2] Control filesystem balances (userspace) Jérôme Poulin
2010-10-30 17:49 ` Goffredo Baroncelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101030001042.809576287@carfax.org.uk \
    --to=hugo@carfax.org.uk \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).