From patchwork Thu Apr 16 00:46:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11492175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1635C912 for ; Thu, 16 Apr 2020 01:04:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D29FD206A2 for ; Thu, 16 Apr 2020 01:04:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="kLLnY7jw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405868AbgDPBEf (ORCPT ); Wed, 15 Apr 2020 21:04:35 -0400 Received: from gateway30.websitewelcome.com ([192.185.180.41]:22521 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405821AbgDPBEc (ORCPT ); Wed, 15 Apr 2020 21:04:32 -0400 X-Greylist: delayed 1205 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Apr 2020 21:04:31 EDT Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 93D2DBA712 for ; Wed, 15 Apr 2020 19:44:22 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id OsdijnV8MVQh0OsdijxSz5; Wed, 15 Apr 2020 19:44:22 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Kp9uLZU//RbzdWsCumY2HiyuXj9Q52SB5U6JH6t6D0w=; b=kLLnY7jwUWx4pJLQpa0qdFK/XH aKijh4fQVLqXYNKpd1eCAIQPsbhF9nHJgRyqF/xUU1QxiVj733cTTYAqJmWk2ZtGPgo6/SJH8qwSP TAbNg4KQGdZiq0CTxgH1vAEW0fZJkQrSvuyenyBNFvNniSFj0S+IOfkuKzl5oBeeDYVBmcZcwL8sP qYbR+9uzFp+Q8rtUg/lFhzYkgJLEODf6Gent54MlPqKNqSmYRd39ReJNqSq1PnxFKwRZJywhHNVAa JtEIbSAjMpaKm48DgChCnRDIJeH39Wf+F6pceBbHhClbKf6J10zxOAFF6BTsM2m/iISruRvVMoWoi oLG4LZKw==; Received: from [177.132.129.218] (port=35128 helo=hephaestus.suse.de) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jOsdi-0046UY-01; Wed, 15 Apr 2020 21:44:22 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, linux-btrfs@vger.kernel.org, wqu@suse.com Cc: Marcos Paulo de Souza Subject: [PATCHv3 1/3] btrfs-progs: Move resize into functionaly into utils.c Date: Wed, 15 Apr 2020 21:46:40 -0300 Message-Id: <20200416004642.9941-2-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200416004642.9941-1-marcos@mpdesouza.com> References: <20200416004642.9941-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 177.132.129.218 X-Source-L: No X-Exim-ID: 1jOsdi-0046UY-01 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.suse.de) [177.132.129.218]:35128 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 7 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza 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 --- 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 From patchwork Thu Apr 16 00:46:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11492177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BE3F912 for ; Thu, 16 Apr 2020 01:04:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2CE220725 for ; Thu, 16 Apr 2020 01:04:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="qrs9bWSA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405962AbgDPBEs (ORCPT ); Wed, 15 Apr 2020 21:04:48 -0400 Received: from gateway30.websitewelcome.com ([192.185.180.41]:26505 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405821AbgDPBEn (ORCPT ); Wed, 15 Apr 2020 21:04:43 -0400 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id EF149BA95A for ; Wed, 15 Apr 2020 19:44:23 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id OsdjjuD8E8vkBOsdjjgCsa; Wed, 15 Apr 2020 19:44:23 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FPrDtuZxJBRFC3hCMADAu+KSjucy8BgOLCucy5y4jYM=; b=qrs9bWSAbnMkzZ6d12Gkli1c4P UqfwCgVM6r190IRxmqEJwigu3Q15khau9L2FGhPeWJpBOHIKXzxu0+XskiXTrMn9wkVvp7YlYAxa9 C8VnwSOgQfFPOQGlRn2dghA2WMxYNlADseEOCt9kJVWJOU88VA6LaJ0tQ43pdGLon81H/abkVBghk WOKT9/w8Fa50DkHPImhWUi++eYZWiJJpjm1/nxzwN1RqKkmZpY5rNR8EcSrlD3U6q0BhLsLze+Tkf 5Ek0joc9QCPjP6zsH110vhHhcy/rhfv7O6A9o+/4U57fmr5o1sMWa/IDM/iNb4eILG7OsnSd90f2Q CKXMNfuA==; Received: from [177.132.129.218] (port=35128 helo=hephaestus.suse.de) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jOsdj-0046UY-DP; Wed, 15 Apr 2020 21:44:23 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, linux-btrfs@vger.kernel.org, wqu@suse.com Cc: Marcos Paulo de Souza Subject: [PATCHv3 2/3] btrfs-progs: replace: New argument to resize the fs after replace Date: Wed, 15 Apr 2020 21:46:41 -0300 Message-Id: <20200416004642.9941-3-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200416004642.9941-1-marcos@mpdesouza.com> References: <20200416004642.9941-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 177.132.129.218 X-Source-L: No X-Exim-ID: 1jOsdj-0046UY-DP X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.suse.de) [177.132.129.218]:35128 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 11 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza 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 --- 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* :: Cancel a running device replace operation. -*start* [-Bfr] | :: +*start* [options] | :: 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 . + -B:::: no background replace. +--autoresize:::: +automatically resizes the filesystem to it's max size if the is +bigger than . *status* [-1] :: 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 #include #include +#include #include #include #include @@ -91,7 +92,7 @@ static int dev_replace_handle_sigint(int fd) } static const char *const cmd_replace_start_usage[] = { - "btrfs replace start [-Bfr] | ", + "btrfs replace start [options] | ", "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 parameter format.", "The needs to be same size or larger than the .", "", - "-r only read from 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 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 ", - "-B do not background", + "Options:", + "--autoresize automatically resizes the filesystem to it's max size if the", + " is bigger than ", + "-r only read from 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 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 ", + "-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) From patchwork Thu Apr 16 00:46:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11492183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB09492C for ; Thu, 16 Apr 2020 01:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A308420725 for ; Thu, 16 Apr 2020 01:08:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="AXm7jSZB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406123AbgDPBIT (ORCPT ); Wed, 15 Apr 2020 21:08:19 -0400 Received: from gator3069.hostgator.com ([192.185.45.2]:20744 "EHLO gateway21.websitewelcome.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1729471AbgDPBIQ (ORCPT ); Wed, 15 Apr 2020 21:08:16 -0400 X-Greylist: delayed 1422 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Apr 2020 21:08:15 EDT Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 84F3E400CD416 for ; Wed, 15 Apr 2020 19:44:25 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id OsdljaPWmSl8qOsdlj2iFP; Wed, 15 Apr 2020 19:44:25 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9WvtvDUzuPjGAnBn38mamDOCpOC1H3+8bpBgt77l5QU=; b=AXm7jSZBx6yjozo+MoLcI/mppg QHBBzaOVJiYqkhmLHyQ0jh8SVNoa+CGIkNlgBNZV9IVm2I3EXP26+0Ed/XZiohsc+ZnYqgpt5goun n+RYfMgXCEYF3mV+3NkaQeTeQZUwIkeS21fYf9g2M2WwwwQhpTxvpue+IYtnvw6MgUTEYcsOQb9n+ TQDvFyR5H0wu/h2EBeDLyN+5St5tWASCAjpwUj/HOpu38iZp70teNWpw5u3jS0UBhDsg9waZ3M1YM p51Oy2NA+qFzIy/+wyjcSH55KA/cItPPL/HueOYPXVXa8+WHaEaYw7jJpaHcYhig4CtT/7EyIHeCZ gGpQFdMg==; Received: from [177.132.129.218] (port=35128 helo=hephaestus.suse.de) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jOsdk-0046UY-Qo; Wed, 15 Apr 2020 21:44:25 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, linux-btrfs@vger.kernel.org, wqu@suse.com Cc: Marcos Paulo de Souza Subject: [PATCHv3 3/3] btrfs-progs: tests: misc: Add some replace tests Date: Wed, 15 Apr 2020 21:46:42 -0300 Message-Id: <20200416004642.9941-4-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200416004642.9941-1-marcos@mpdesouza.com> References: <20200416004642.9941-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 177.132.129.218 X-Source-L: No X-Exim-ID: 1jOsdk-0046UY-Qo X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.suse.de) [177.132.129.218]:35128 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 15 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza The new test includes a check for the new --autoresize option Signed-off-by: Marcos Paulo de Souza --- 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