linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace
@ 2020-04-16  0:46 Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c Marcos Paulo de Souza
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-04-16  0:46 UTC (permalink / raw)
  To: dsterba, linux-btrfs, wqu; +Cc: Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

Changes from v2:
* Fixed the code format after moving function resize_filesystem in patch 0001
  (suggested by David)
* Sorted the resize_filesystem function prototype in patch 0001 (suggested by
  David)
* Changed the -a into long argument --autoresize in patch 0002 (suggested by
  David)
* Translate srcdev if the argument is not a devid (suggested by David)
* This also changes the way we use the ioctl, now only passing devid to the
  kernel, instead of passing the path and letting the kernel to translate
* Add tests to check the autoresize functionality

Changes from v1:
* Reworded the help message and the docs telling the user that the fs will be
  resized to it's max size (suggested by Qu)
* Added a warning message saying that the resize failed, asking the user to
  resize manually. (suggested by Qu)

Both changes were done only in patch 0002.

Anand suggested this job to be done in kernel side, atomically, but as I
received a good review from Qu I decided to send a v3 of this patchset.

Please review, thanks!

Original cover-letter[1]:
These two patches make possible to resize the fs after a successful replace
finishes. The flag -a is responsible for doing it (-r is already use, so -a in
this context means "automatically").

The first patch just moves the resize rationale to utils.c and the second patch
adds the flag an calls resize if -a is informed replace finishes successfully.

Please review!

Marcos Paulo de Souza (3):
  btrfs-progs: Move resize into functionaly into utils.c
  btrfs-progs: replace: New argument to resize the fs after replace
  btrfs-progs: tests: misc: Add some replace tests

 Documentation/btrfs-replace.asciidoc        |   5 +-
 cmds/filesystem.c                           |  58 +----------
 cmds/replace.c                              | 105 +++++++++++++-------
 common/utils.c                              |  60 +++++++++++
 common/utils.h                              |   2 +
 tests/misc-tests/039-replace-device/test.sh |  56 +++++++++++
 6 files changed, 192 insertions(+), 94 deletions(-)
 create mode 100755 tests/misc-tests/039-replace-device/test.sh

-- 
2.25.1


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

* [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c
  2020-04-16  0:46 [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
@ 2020-04-16  0:46 ` Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 2/3] btrfs-progs: replace: New argument to resize the fs after replace Marcos Paulo de Souza
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-04-16  0:46 UTC (permalink / raw)
  To: dsterba, linux-btrfs, wqu; +Cc: Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

This function will be used in the next patch to auto resize the
filesystem when a bigger disk is added.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 cmds/filesystem.c | 58 ++-------------------------------------------
 common/utils.c    | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 common/utils.h    |  2 ++
 3 files changed, 64 insertions(+), 56 deletions(-)

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index c4bb13dd..cb7c3806 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -1075,11 +1075,7 @@ static const char * const cmd_filesystem_resize_usage[] = {
 static int cmd_filesystem_resize(const struct cmd_struct *cmd,
 				 int argc, char **argv)
 {
-	struct btrfs_ioctl_vol_args	args;
-	int	fd, res, len, e;
-	char	*amount, *path;
-	DIR	*dirstream = NULL;
-	struct stat st;
+	char *amount, *path;
 
 	clean_args_no_options_relaxed(cmd, argc, argv);
 
@@ -1089,57 +1085,7 @@ static int cmd_filesystem_resize(const struct cmd_struct *cmd,
 	amount = argv[optind];
 	path = argv[optind + 1];
 
-	len = strlen(amount);
-	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-		error("resize value too long (%s)", amount);
-		return 1;
-	}
-
-	res = stat(path, &st);
-	if (res < 0) {
-		error("resize: cannot stat %s: %m", path);
-		return 1;
-	}
-	if (!S_ISDIR(st.st_mode)) {
-		error("resize works on mounted filesystems and accepts only\n"
-			"directories as argument. Passing file containing a btrfs image\n"
-			"would resize the underlying filesystem instead of the image.\n");
-		return 1;
-	}
-
-	fd = btrfs_open_dir(path, &dirstream, 1);
-	if (fd < 0)
-		return 1;
-
-	printf("Resize '%s' of '%s'\n", path, amount);
-	memset(&args, 0, sizeof(args));
-	strncpy_null(args.name, amount);
-	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
-	e = errno;
-	close_file_or_dir(fd, dirstream);
-	if( res < 0 ){
-		switch (e) {
-		case EFBIG:
-			error("unable to resize '%s': no enough free space",
-				path);
-			break;
-		default:
-			error("unable to resize '%s': %m", path);
-			break;
-		}
-		return 1;
-	} else if (res > 0) {
-		const char *err_str = btrfs_err_str(res);
-
-		if (err_str) {
-			error("resizing of '%s' failed: %s", path, err_str);
-		} else {
-			error("resizing of '%s' failed: unknown error %d",
-				path, res);
-		}
-		return 1;
-	}
-	return 0;
+	return resize_filesystem(amount, path);
 }
 static DEFINE_SIMPLE_COMMAND(filesystem_resize, "resize");
 
diff --git a/common/utils.c b/common/utils.c
index 2517bb34..99d638cc 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -461,6 +461,66 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
 	return snprintf(str, str_size, "%.2f%s", fraction, suffix[num_divs]);
 }
 
+int resize_filesystem(const char *amount, const char *path)
+{
+	struct btrfs_ioctl_vol_args args;
+	int fd, res, len, e;
+	DIR *dirstream = NULL;
+	struct stat st;
+
+	len = strlen(amount);
+	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
+		error("resize value too long (%s)", amount);
+		return 1;
+	}
+
+	res = stat(path, &st);
+	if (res < 0) {
+		error("resize: cannot stat %s: %m", path);
+		return 1;
+	}
+	if (!S_ISDIR(st.st_mode)) {
+		error("resize works on mounted filesystems and accepts only\n"
+			"directories as argument. Passing file containing a btrfs image\n"
+			"would resize the underlying filesystem instead of the image.\n");
+		return 1;
+	}
+
+	fd = btrfs_open_dir(path, &dirstream, 1);
+	if (fd < 0)
+		return 1;
+
+	printf("Resize '%s' of '%s'\n", path, amount);
+	memset(&args, 0, sizeof(args));
+	strncpy_null(args.name, amount);
+	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
+	e = errno;
+	close_file_or_dir(fd, dirstream);
+	if( res < 0 ){
+		switch (e) {
+		case EFBIG:
+			error("unable to resize '%s': no enough free space",
+				path);
+			break;
+		default:
+			error("unable to resize '%s': %m", path);
+			break;
+		}
+		return 1;
+	} else if (res > 0) {
+		const char *err_str = btrfs_err_str(res);
+
+		if (err_str) {
+			error("resizing of '%s' failed: %s", path, err_str);
+		} else {
+			error("resizing of '%s' failed: unknown error %d",
+				path, res);
+		}
+		return 1;
+	}
+	return 0;
+}
+
 /*
  * Checks to make sure that the label matches our requirements.
  * Returns:
diff --git a/common/utils.h b/common/utils.h
index 79c168c5..ba873c02 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -147,4 +147,6 @@ static inline int btrfs_test_for_mixed_profiles_by_fd(int fd)
 int btrfs_check_for_mixed_profiles_by_path(const char *path);
 int btrfs_check_for_mixed_profiles_by_fd(int fd);
 
+int resize_filesystem(const char *amount, const char *path);
+
 #endif
-- 
2.25.1


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

* [PATCHv3 2/3] btrfs-progs: replace: New argument to resize the fs after replace
  2020-04-16  0:46 [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c Marcos Paulo de Souza
@ 2020-04-16  0:46 ` Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 3/3] btrfs-progs: tests: misc: Add some replace tests Marcos Paulo de Souza
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-04-16  0:46 UTC (permalink / raw)
  To: dsterba, linux-btrfs, wqu; +Cc: Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

Add new --autoresize long opt to resize the fs automatically after
replace. The code now checks if the srcdev is a path, and translates it
to a devid, making it being consumed later on if auto resize is
specified.

By using the --autoresize flag on replace makes btrfs issue a resize ioctl after
the replace finishes. This argument is a shortcut for

btrfs replace start -f 3 /dev/sdf BTRFS/
btrfs fi resize 3:max BTRFS/

Fixes: #21

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 Documentation/btrfs-replace.asciidoc |   5 +-
 cmds/replace.c                       | 105 +++++++++++++++++----------
 2 files changed, 72 insertions(+), 38 deletions(-)

diff --git a/Documentation/btrfs-replace.asciidoc b/Documentation/btrfs-replace.asciidoc
index b73bf1b3..f6eb6d20 100644
--- a/Documentation/btrfs-replace.asciidoc
+++ b/Documentation/btrfs-replace.asciidoc
@@ -18,7 +18,7 @@ SUBCOMMAND
 *cancel* <mount_point>::
 Cancel a running device replace operation.
 
-*start* [-Bfr] <srcdev>|<devid> <targetdev> <path>::
+*start* [options] <srcdev>|<devid> <targetdev> <path>::
 Replace device of a btrfs filesystem.
 +
 On a live filesystem, duplicate the data to the target device which
@@ -53,6 +53,9 @@ never allowed to be used as the <targetdev>.
 +
 -B::::
 no background replace.
+--autoresize::::
+automatically resizes the filesystem to it's max size if the <targetdev> is
+bigger than <srcdev>.
 
 *status* [-1] <mount_point>::
 Print status and progress information of a running device replace operation.
diff --git a/cmds/replace.c b/cmds/replace.c
index 2321aa15..48017c04 100644
--- a/cmds/replace.c
+++ b/cmds/replace.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <errno.h>
@@ -91,7 +92,7 @@ static int dev_replace_handle_sigint(int fd)
 }
 
 static const char *const cmd_replace_start_usage[] = {
-	"btrfs replace start [-Bfr] <srcdev>|<devid> <targetdev> <mount_point>",
+	"btrfs replace start [options] <srcdev>|<devid> <targetdev> <mount_point>",
 	"Replace device of a btrfs filesystem.",
 	"On a live filesystem, duplicate the data to the target device which",
 	"is currently stored on the source device. If the source device is not",
@@ -104,15 +105,18 @@ static const char *const cmd_replace_start_usage[] = {
 	"from the system, you have to use the <devid> parameter format.",
 	"The <targetdev> needs to be same size or larger than the <srcdev>.",
 	"",
-	"-r     only read from <srcdev> if no other zero-defect mirror exists",
-	"       (enable this if your drive has lots of read errors, the access",
-	"       would be very slow)",
-	"-f     force using and overwriting <targetdev> even if it looks like",
-	"       containing a valid btrfs filesystem. A valid filesystem is",
-	"       assumed if a btrfs superblock is found which contains a",
-	"       correct checksum. Devices which are currently mounted are",
-	"       never allowed to be used as the <targetdev>",
-	"-B     do not background",
+	"Options:",
+	"--autoresize  automatically resizes the filesystem to it's max size if the",
+	"              <targetdev> is bigger than <srcdev>",
+	"-r            only read from <srcdev> if no other zero-defect mirror exists",
+	"              (enable this if your drive has lots of read errors, the access",
+	"              would be very slow)",
+	"-f            force using and overwriting <targetdev> even if it looks like",
+	"              containing a valid btrfs filesystem. A valid filesystem is",
+	"              assumed if a btrfs superblock is found which contains a",
+	"              correct checksum. Devices which are currently mounted are",
+	"              never allowed to be used as the <targetdev>",
+	"-B            do not background",
 	NULL
 };
 
@@ -121,6 +125,8 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 {
 	struct btrfs_ioctl_dev_replace_args start_args = {0};
 	struct btrfs_ioctl_dev_replace_args status_args = {0};
+	struct btrfs_ioctl_fs_info_args fi_args;
+	struct btrfs_ioctl_dev_info_args *di_args = NULL;
 	int ret;
 	int i;
 	int c;
@@ -129,6 +135,7 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 	char *path;
 	char *srcdev;
 	char *dstdev = NULL;
+	bool auto_resize = false;
 	int avoid_reading_from_srcdev = 0;
 	int force_using_targetdev = 0;
 	u64 dstdev_block_count;
@@ -137,8 +144,13 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 	u64 srcdev_size;
 	u64 dstdev_size;
 
+	enum { GETOPT_VAL_AUTORESIZE = 257 };
+	static struct option long_opts[] = {
+		{"autoresize", no_argument, NULL, GETOPT_VAL_AUTORESIZE}
+	};
+
 	optind = 0;
-	while ((c = getopt(argc, argv, "Brf")) != -1) {
+	while ((c = getopt_long(argc, argv, "Brf", long_opts, NULL)) != -1) {
 		switch (c) {
 		case 'B':
 			do_not_background = 1;
@@ -149,6 +161,9 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 		case 'f':
 			force_using_targetdev = 1;
 			break;
+		case GETOPT_VAL_AUTORESIZE:
+			auto_resize = true;
+			break;
 		default:
 			usage_unknown_option(cmd, argv);
 		}
@@ -202,45 +217,46 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 		goto leave_with_error;
 	}
 
-	if (string_is_numerical(srcdev)) {
-		struct btrfs_ioctl_fs_info_args fi_args;
-		struct btrfs_ioctl_dev_info_args *di_args = NULL;
+	ret = get_fs_info(path, &fi_args, &di_args);
+	if (ret) {
+		errno = -ret;
+		error("failed to get device info: %m");
+		free(di_args);
+		goto leave_with_error;
+	}
+	if (!fi_args.num_devices) {
+		error("no devices found");
+		free(di_args);
+		goto leave_with_error;
+	}
 
+	if (string_is_numerical(srcdev)) {
 		start_args.start.srcdevid = arg_strtou64(srcdev);
 
-		ret = get_fs_info(path, &fi_args, &di_args);
-		if (ret) {
-			errno = -ret;
-			error("failed to get device info: %m");
-			free(di_args);
-			goto leave_with_error;
-		}
-		if (!fi_args.num_devices) {
-			error("no devices found");
-			free(di_args);
-			goto leave_with_error;
-		}
-
 		for (i = 0; i < fi_args.num_devices; i++)
 			if (start_args.start.srcdevid == di_args[i].devid)
 				break;
 		srcdev_size = di_args[i].total_bytes;
-		free(di_args);
-		if (i == fi_args.num_devices) {
-			error("'%s' is not a valid devid for filesystem '%s'",
-				srcdev, path);
-			goto leave_with_error;
-		}
 	} else if (path_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);
+		for (i = 0; i < fi_args.num_devices; i++)
+			if (strcmp(srcdev, (char *)di_args[i].path) == 0)
+				break;
+
+		start_args.start.srcdevid = di_args[i].devid;
+		srcdev_size = di_args[i].total_bytes;
 	} else {
 		error("source device must be a block device or a devid");
 		goto leave_with_error;
 	}
 
+	free(di_args);
+	di_args = NULL;
+	if (i == fi_args.num_devices) {
+		error("'%s' is not a valid devid for filesystem '%s'",
+			srcdev, path);
+		goto leave_with_error;
+	}
+
 	ret = test_dev_for_mkfs(dstdev, force_using_targetdev);
 	if (ret)
 		goto leave_with_error;
@@ -309,10 +325,25 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
 			goto leave_with_error;
 		}
 	}
+
+	if (ret == 0 && auto_resize && dstdev_size > srcdev_size) {
+		char amount[BTRFS_PATH_NAME_MAX + 1];
+		snprintf(amount, BTRFS_DEVICE_PATH_NAME_MAX, "%llu:max",
+						start_args.start.srcdevid);
+
+		if (resize_filesystem(amount, path)) {
+			warning("resize failed, please resize the filesystem manually by executing:"
+				"\nbtrfs fi resize %llu:max %s", start_args.start.srcdevid, path);
+			goto leave_with_error;
+		}
+	}
+
 	close_file_or_dir(fdmnt, dirstream);
 	return 0;
 
 leave_with_error:
+	if (di_args)
+		free(di_args);
 	if (dstdev)
 		free(dstdev);
 	if (fdmnt != -1)
-- 
2.25.1


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

* [PATCHv3 3/3] btrfs-progs: tests: misc: Add some replace tests
  2020-04-16  0:46 [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c Marcos Paulo de Souza
  2020-04-16  0:46 ` [PATCHv3 2/3] btrfs-progs: replace: New argument to resize the fs after replace Marcos Paulo de Souza
@ 2020-04-16  0:46 ` Marcos Paulo de Souza
       [not found] ` <706b6fae-94d6-62bf-d52e-d0db057e3bd3@casa-di-locascio.net>
  2020-05-31 19:11 ` Marcos Paulo de Souza
  4 siblings, 0 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-04-16  0:46 UTC (permalink / raw)
  To: dsterba, linux-btrfs, wqu; +Cc: Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

The new test includes a check for the new --autoresize option

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 tests/misc-tests/039-replace-device/test.sh | 56 +++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 tests/misc-tests/039-replace-device/test.sh

diff --git a/tests/misc-tests/039-replace-device/test.sh b/tests/misc-tests/039-replace-device/test.sh
new file mode 100755
index 00000000..64b80bed
--- /dev/null
+++ b/tests/misc-tests/039-replace-device/test.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+#
+# test the different arguments accepted by "btrfs replace"
+
+source "$TEST_TOP/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+setup_loopdevs 2
+prepare_loopdevs
+dev1=${loopdevs[1]}
+dev2=${loopdevs[2]}
+
+# resize only works with disk size bigger than the replaced disk
+run_check_stdout truncate -s3g `pwd`/img3
+dev3=`run_check_stdout $SUDO_HELPER losetup --find --show $(pwd)/img3`
+
+test()
+{
+	local srcdev
+	local final_size
+	local resize_arg
+	srcdev="$1"
+	final_size="$2"
+	resize_arg="$3"
+	args="-B -f"
+
+	if [ -n "$resize_arg" ]; then
+		args="$args --autoresize"
+	fi
+
+	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev1" "$dev2"
+	TEST_DEV="$dev1"
+
+	run_check_mount_test_dev
+	run_check_stdout $SUDO_HELPER "$TOP/btrfs" replace start $args "$srcdev" "$dev3" "$TEST_MNT"
+	run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" | head -2 | \
+			grep -q "$final_size\\.00GiB"
+	[ $? -eq 1 ] && _fail "Device size don't match. Expected size: $final_size\\.00GiB"
+	run_check_umount_test_dev
+}
+
+# test replace using devid and path, and also test the final fs size when
+# --autoresize is passed, executing the replace + resize in just one command.
+test 2 4
+test 2 5 true
+test "$dev2" 4
+test "$dev2" 5 true
+
+run_check $SUDO_HELPER losetup -d "$dev3"
+rm `pwd`/img3
+
+cleanup_loopdevs
-- 
2.25.1


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

* Re: [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace
       [not found] ` <706b6fae-94d6-62bf-d52e-d0db057e3bd3@casa-di-locascio.net>
@ 2020-04-17  2:15   ` Marcos Paulo de Souza
  0 siblings, 0 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-04-17  2:15 UTC (permalink / raw)
  To: devel, linux-btrfs

On Thu, 2020-04-16 at 07:18 +0100, devel@roosoftl.ltd.uk wrote:
> On 16/04/2020 01:46, Marcos Paulo de Souza wrote:
> > From: Marcos Paulo de Souza <mpdesouza@suse.com>
> >
> > Changes from v2:
> > * Fixed the code format after moving function resize_filesystem in
> patch 0001
> >   (suggested by David)
> > * Sorted the resize_filesystem function prototype in patch 0001
> (suggested by
> >   David)
> > * Changed the -a into long argument --autoresize in patch 0002
> (suggested by
> >   David)
> > * Translate srcdev if the argument is not a devid (suggested by
> David)
> > * This also changes the way we use the ioctl, now only passing
> devid to the
> >   kernel, instead of passing the path and letting the kernel to
> translate
> > * Add tests to check the autoresize functionality
> >
> > Changes from v1:
> > * Reworded the help message and the docs telling the user that the
> fs will be
> >   resized to it's max size (suggested by Qu)
> > * Added a warning message saying that the resize failed, asking the
> user to
> >   resize manually. (suggested by Qu)
> >
> > Both changes were done only in patch 0002.
> >
> > Anand suggested this job to be done in kernel side, atomically, but
> as I
> > received a good review from Qu I decided to send a v3 of this
> patchset.
> >
> > Please review, thanks!
> >
> > Original cover-letter[1]:
> > These two patches make possible to resize the fs after a successful
> replace
> > finishes. The flag -a is responsible for doing it (-r is already
> use, so -a in
> > this context means "automatically").
> >
> > The first patch just moves the resize rationale to utils.c and the
> second patch
> > adds the flag an calls resize if -a is informed replace finishes
> successfully.
> >
> > Please review!
> >
> > Marcos Paulo de Souza (3):
> >   btrfs-progs: Move resize into functionaly into utils.c
> >   btrfs-progs: replace: New argument to resize the fs after replace
> >   btrfs-progs: tests: misc: Add some replace tests
> >
> >  Documentation/btrfs-replace.asciidoc        |   5 +-
> >  cmds/filesystem.c                           |  58 +----------
> >  cmds/replace.c                              | 105 +++++++++++++---
> ----
> >  common/utils.c                              |  60 +++++++++++
> >  common/utils.h                              |   2 +
> >  tests/misc-tests/039-replace-device/test.sh |  56 +++++++++++
> >  6 files changed, 192 insertions(+), 94 deletions(-)
> >  create mode 100755 tests/misc-tests/039-replace-device/test.sh
> >
> Hmm,
> 
> 
> Does this take into account if different raid levels are used for
> data
> and meta data. When I last was upgrading a fs with larger drive it
> was
> not just a case of making the over all file size different I had to
> also
> change the ratio of metadata to data. And then I had to balance a
> whole
> lot (which found a bug in memory at the time)

What do you mean about "ratio of metadata to data"? The new disk will
receive the same content of the old disk, so, it the metadata wasn't
balanced before the replace, it might be a good idea to execute balance
after adding a maybe larger disk.

Can you please describe in more details you problem, or the problem you
had at the time you did the replace last time? It seems it's not
related to the resize itself, so these patches do not change the
current behavior.

> 
> 
> How do you deal with these edge cases ? Especially if you replacing
> with
> a smaller disk and then have to shrink the metadata ratio?

Replace does not accept a smaller disk to replace a larger one.

> 
> 
> Just curious.

Me too. These patches were meant to help people to avoid executing two
different command for a pretty common action, all details behind
replace and resize are the same, it's just a "helper" to make users to
use the full capacity of a newly added disk.


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

* Re: [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace
  2020-04-16  0:46 [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
                   ` (3 preceding siblings ...)
       [not found] ` <706b6fae-94d6-62bf-d52e-d0db057e3bd3@casa-di-locascio.net>
@ 2020-05-31 19:11 ` Marcos Paulo de Souza
  4 siblings, 0 replies; 6+ messages in thread
From: Marcos Paulo de Souza @ 2020-05-31 19:11 UTC (permalink / raw)
  To: dsterba, linux-btrfs, wqu; +Cc: Marcos Paulo de Souza

Humble ping :)

On Wed, 2020-04-15 at 21:46 -0300, Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
> 
> Changes from v2:
> * Fixed the code format after moving function resize_filesystem in
> patch 0001
>   (suggested by David)
> * Sorted the resize_filesystem function prototype in patch 0001
> (suggested by
>   David)
> * Changed the -a into long argument --autoresize in patch 0002
> (suggested by
>   David)
> * Translate srcdev if the argument is not a devid (suggested by
> David)
> * This also changes the way we use the ioctl, now only passing devid
> to the
>   kernel, instead of passing the path and letting the kernel to
> translate
> * Add tests to check the autoresize functionality
> 
> Changes from v1:
> * Reworded the help message and the docs telling the user that the fs
> will be
>   resized to it's max size (suggested by Qu)
> * Added a warning message saying that the resize failed, asking the
> user to
>   resize manually. (suggested by Qu)
> 
> Both changes were done only in patch 0002.
> 
> Anand suggested this job to be done in kernel side, atomically, but
> as I
> received a good review from Qu I decided to send a v3 of this
> patchset.
> 
> Please review, thanks!
> 
> Original cover-letter[1]:
> These two patches make possible to resize the fs after a successful
> replace
> finishes. The flag -a is responsible for doing it (-r is already use,
> so -a in
> this context means "automatically").
> 
> The first patch just moves the resize rationale to utils.c and the
> second patch
> adds the flag an calls resize if -a is informed replace finishes
> successfully.
> 
> Please review!
> 
> Marcos Paulo de Souza (3):
>   btrfs-progs: Move resize into functionaly into utils.c
>   btrfs-progs: replace: New argument to resize the fs after replace
>   btrfs-progs: tests: misc: Add some replace tests
> 
>  Documentation/btrfs-replace.asciidoc        |   5 +-
>  cmds/filesystem.c                           |  58 +----------
>  cmds/replace.c                              | 105 +++++++++++++-----
> --
>  common/utils.c                              |  60 +++++++++++
>  common/utils.h                              |   2 +
>  tests/misc-tests/039-replace-device/test.sh |  56 +++++++++++
>  6 files changed, 192 insertions(+), 94 deletions(-)
>  create mode 100755 tests/misc-tests/039-replace-device/test.sh
> 


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

end of thread, other threads:[~2020-05-31 19:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16  0:46 [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
2020-04-16  0:46 ` [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c Marcos Paulo de Souza
2020-04-16  0:46 ` [PATCHv3 2/3] btrfs-progs: replace: New argument to resize the fs after replace Marcos Paulo de Souza
2020-04-16  0:46 ` [PATCHv3 3/3] btrfs-progs: tests: misc: Add some replace tests Marcos Paulo de Souza
     [not found] ` <706b6fae-94d6-62bf-d52e-d0db057e3bd3@casa-di-locascio.net>
2020-04-17  2:15   ` [PATCHv3 0/3] btrfs-progs: Auto resize fs after device replace Marcos Paulo de Souza
2020-05-31 19:11 ` Marcos Paulo de Souza

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