linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: Add further checks to btrfs replace start command
@ 2015-08-20  5:24 Goffredo Baroncelli
  2015-08-25 15:38 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Goffredo Baroncelli @ 2015-08-20  5:24 UTC (permalink / raw)
  To: linux-btrfs, dsterba; +Cc: Goffredo Baroncelli

Add further checks to btrfs replace start command.

The following tests where added in user space before calling
the ioctl():
1) check if the new disk is greather or equal to the old one
2) check if the source device is or a block device or a
numerical dev-id

These checks are already performed in kernel space; however
when "btrfs replace start" is ran in background is not possible
to show any error returned by the ioctl(), so in case of fail 
the user had to check dmesg to understand the what happened.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 cmds-replace.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/cmds-replace.c b/cmds-replace.c
index 85365e3..45fe060 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -142,6 +142,8 @@ static int cmd_start_replace(int argc, char **argv)
 	int do_not_background = 0;
 	int mixed = 0;
 	DIR *dirstream = NULL;
+	u64 srcdev_size;
+	u64 dstdev_size;
 
 	while ((c = getopt(argc, argv, "Brf")) != -1) {
 		switch (c) {
@@ -249,16 +251,28 @@ static int cmd_start_replace(int argc, char **argv)
 				srcdev, path);
 			goto leave_with_error;
 		}
-	} else if (is_block_device(srcdev)) {
+		srcdev_size = di_args[i].total_bytes;
+	} else if (is_block_device(srcdev) > 0) {
 		strncpy((char *)start_args.start.srcdev_name, srcdev,
 			BTRFS_DEVICE_PATH_NAME_MAX);
 		start_args.start.srcdevid = 0;
+		srcdev_size = get_partition_size(srcdev);
+	} else {
+		fprintf(stderr, "ERROR: source device must be a block device or a devid\n");
+		goto leave_with_error;
 	}
 
 	ret = test_dev_for_mkfs(dstdev, force_using_targetdev);
 	if (ret)
 		goto leave_with_error;
 
+	dstdev_size = get_partition_size(dstdev);
+	if (srcdev_size > dstdev_size) {
+		fprintf(stderr, "ERROR: target device smaller than source device (required %llu bytes)\n",
+			srcdev_size);
+		goto leave_with_error;
+	}
+
 	fddstdev = open(dstdev, O_RDWR);
 	if (fddstdev < 0) {
 		fprintf(stderr, "Unable to open %s\n", dstdev);
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs-progs: Add further checks to btrfs replace start command
  2015-08-20  5:24 [PATCH] btrfs-progs: Add further checks to btrfs replace start command Goffredo Baroncelli
@ 2015-08-25 15:38 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2015-08-25 15:38 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: linux-btrfs, dsterba, Goffredo Baroncelli

On Thu, Aug 20, 2015 at 07:24:23AM +0200, Goffredo Baroncelli wrote:
> Add further checks to btrfs replace start command.
> 
> The following tests where added in user space before calling
> the ioctl():
> 1) check if the new disk is greather or equal to the old one
> 2) check if the source device is or a block device or a
> numerical dev-id
> 
> These checks are already performed in kernel space; however
> when "btrfs replace start" is ran in background is not possible
> to show any error returned by the ioctl(), so in case of fail 
> the user had to check dmesg to understand the what happened.
> 
> Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-25 15:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-20  5:24 [PATCH] btrfs-progs: Add further checks to btrfs replace start command Goffredo Baroncelli
2015-08-25 15:38 ` David Sterba

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).