From patchwork Mon Nov 16 17:32:47 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: 11910265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69CF2C4742C for ; Mon, 16 Nov 2020 17:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0345421527 for ; Mon, 16 Nov 2020 17:58:55 +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="UYL3BA3O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387904AbgKPR6u (ORCPT ); Mon, 16 Nov 2020 12:58:50 -0500 Received: from gateway32.websitewelcome.com ([192.185.145.178]:37446 "EHLO gateway32.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731742AbgKPR6u (ORCPT ); Mon, 16 Nov 2020 12:58:50 -0500 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 2440D158BD for ; Mon, 16 Nov 2020 11:33:22 -0600 (CST) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id eiNWkjNinmi4BeiNWkjejI; Mon, 16 Nov 2020 11:33:22 -0600 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=cxPF9r7TJ1ZNPalvmCjEm1iNV3uku0zoey/QWFeQ+Sg=; b=UYL3BA3OCyHzmzqy1fhrPr+/ra Y5h7lfU6dHNL0PE5merOg0XqiDk/Ooj703fql4bYsq00wMfVgEx1AG/8FIwfmaGsG8H3pSNMUpPqU 2ZHUI7ymfh3Pc5ykw+Xk0FsFi4bj9ezirRs4UIZkRz+Gf6IcPrUIeM2LRsI3t/vscmkCX/B6Y3MW8 IVmLA23macdst83xhuLHlDtlMqlb17w7d07FRCwRPDp1p6ZET7/3rP2bMZVBcsE1XGEwL9blNxDxa Q7w+24jE+PLiu2LZhqNJzo3ldMnbKxZqpXdOgyfbqojEGvpirIDQsITtipu7Rg1b/8X8QXgx4mYMc gJW4O83Q==; Received: from [191.249.68.105] (port=38938 helo=localhost.suse.de) by br540.hostgator.com.br with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1keiNV-000wCw-Gw; Mon, 16 Nov 2020 14:33:21 -0300 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza , wqu@suse.com, dsterba@suse.com Subject: [PATCH v2 1/3] btrfs-progs: Adapt find_mount_root to verify other fields of mntent struct Date: Mon, 16 Nov 2020 14:32:47 -0300 Message-Id: <20201116173249.11847-2-marcos@mpdesouza.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116173249.11847-1-marcos@mpdesouza.com> References: <20201116173249.11847-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: 191.249.68.105 X-Source-L: No X-Exim-ID: 1keiNV-000wCw-Gw X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.suse.de) [191.249.68.105]:38938 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 8 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza Currently find_mount_root searches for all btrfs filesystems mounted and comparing with mnt_dir of each mountpoint. But there are cases when we need to find the mountpoint for a determined subvolid or subvol path, and these informations are present in mnt_opts of mntent struct. This patch adds two arguments to find_mount_root (data and flag). The data argument hold the information that we want to compare, and the flag argument specifies which field of mntent struct that we want to compare. Currently there is only one flag, BTRFS_FIND_ROOT_PATH, implementing the current behavior. The next patch will add a new flag to expand the functionality. Users of find_mount_root were changed, having the data argument the same as path, since they are only trying to find the mountpoint based on path alone. Signed-off-by: Marcos Paulo de Souza --- cmds/receive.c | 3 ++- cmds/send.c | 6 ++++-- common/utils.c | 15 ++++++++++++--- common/utils.h | 8 +++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index 2aaba3ff..dc64480e 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -1079,7 +1079,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt, if (realmnt[0]) { rctx->root_path = realmnt; } else { - ret = find_mount_root(dest_dir_full_path, &rctx->root_path); + ret = find_mount_root(dest_dir_full_path, dest_dir_full_path, + BTRFS_FIND_ROOT_PATH, &rctx->root_path); if (ret < 0) { errno = -ret; error("failed to determine mount point for %s: %m", diff --git a/cmds/send.c b/cmds/send.c index b8e3ba12..7757f0da 100644 --- a/cmds/send.c +++ b/cmds/send.c @@ -329,7 +329,8 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol) if (sctx->root_path) goto out; - ret = find_mount_root(subvol, &sctx->root_path); + ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH, + &sctx->root_path); if (ret < 0) { errno = -ret; error("failed to determine mount point for %s: %m", subvol); @@ -659,7 +660,8 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv) goto out; } - ret = find_mount_root(subvol, &mount_root); + ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH, + &mount_root); if (ret < 0) { errno = -ret; error("find_mount_root failed on %s: %m", subvol); diff --git a/common/utils.c b/common/utils.c index 1253e87d..1c264455 100644 --- a/common/utils.c +++ b/common/utils.c @@ -1248,7 +1248,7 @@ int ask_user(const char *question) * return 1 if a mount point is found but not btrfs * return <0 if something goes wrong */ -int find_mount_root(const char *path, char **mount_root) +int find_mount_root(const char *path, const char *data, u8 flag, char **mount_root) { FILE *mnttab; int fd; @@ -1258,6 +1258,10 @@ int find_mount_root(const char *path, char **mount_root) int not_btrfs = 1; int longest_matchlen = 0; char *longest_match = NULL; + char *cmp_field = NULL; + bool found; + + BUG_ON(flag != BTRFS_FIND_ROOT_PATH); fd = open(path, O_RDONLY | O_NOATIME); if (fd < 0) @@ -1269,8 +1273,13 @@ int find_mount_root(const char *path, char **mount_root) return -errno; while ((ent = getmntent(mnttab))) { - len = strlen(ent->mnt_dir); - if (strncmp(ent->mnt_dir, path, len) == 0) { + cmp_field = ent->mnt_dir; + + len = strlen(cmp_field); + + found = strncmp(cmp_field, data, len) == 0; + + if (found) { /* match found and use the latest match */ if (longest_matchlen <= len) { free(longest_match); diff --git a/common/utils.h b/common/utils.h index 119c3881..449e1d3e 100644 --- a/common/utils.h +++ b/common/utils.h @@ -52,6 +52,11 @@ #define UNITS_HUMAN (UNITS_HUMAN_BINARY) #define UNITS_DEFAULT (UNITS_HUMAN) +enum btrfs_find_root_flags { + /* check mnt_dir of mntent */ + BTRFS_FIND_ROOT_PATH = 0 +}; + void units_set_mode(unsigned *units, unsigned mode); void units_set_base(unsigned *units, unsigned base); @@ -93,7 +98,8 @@ int csum_tree_block(struct btrfs_fs_info *root, struct extent_buffer *buf, int ask_user(const char *question); int lookup_path_rootid(int fd, u64 *rootid); int get_btrfs_mount(const char *dev, char *mp, size_t mp_size); -int find_mount_root(const char *path, char **mount_root); +int find_mount_root(const char *path, const char *data, u8 flag, + char **mount_root); int get_device_info(int fd, u64 devid, struct btrfs_ioctl_dev_info_args *di_args); int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret); From patchwork Mon Nov 16 17:32:48 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: 11910261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28C25C2D0A3 for ; Mon, 16 Nov 2020 17:57:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D03AE21527 for ; Mon, 16 Nov 2020 17:57:31 +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="rUe3mojX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387791AbgKPR5H (ORCPT ); Mon, 16 Nov 2020 12:57:07 -0500 Received: from gateway20.websitewelcome.com ([192.185.62.46]:34112 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387746AbgKPR5H (ORCPT ); Mon, 16 Nov 2020 12:57:07 -0500 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 2F364400D4CE9 for ; Mon, 16 Nov 2020 11:30:18 -0600 (CST) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id eiNXkr8EDYLDneiNYkuHlP; Mon, 16 Nov 2020 11:33:24 -0600 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=CvCF2EJByJxft3hiWPr9rn0jNMAENVSlLPjoW6c+JnE=; b=rUe3mojXWiFaKKx2jlowLVkx9R ARXuHL1mrmC4y9iu5L5F6wKXA1YDGtp+0ZmIKp62hM0ynO8XOx6fkWGBfbqGx5Atlu2/fCCsgn7Vh RxPlR9/WfzEUypfIiMhLcmzMk+D8PAq1D/1Ak7Atq+ZzrxY+GoXEly/h9dq2ULPDEu3j2HoeMc7NQ mqICZxEvnhBj4M/6rQWL+v45eFXU4HCRrj7TtQZ97GBo8EY6V+GYqd/3z2BqoU/La0DMcOzcz/dkZ sMZYooCw1S0IR3ylVKNMkpLNVChsNWKGP7E4DZxQ3zrk2DD+PBQaNYm+5DfqHKvviKJ4QaPtrXoaM xsLecA/Q==; Received: from [191.249.68.105] (port=38938 helo=localhost.suse.de) by br540.hostgator.com.br with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1keiNX-000wCw-0F; Mon, 16 Nov 2020 14:33:23 -0300 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza , wqu@suse.com, dsterba@suse.com Subject: [PATCH v2 2/3] btrfs-progs: inspect: Fix logical-resolve file path lookup Date: Mon, 16 Nov 2020 14:32:48 -0300 Message-Id: <20201116173249.11847-3-marcos@mpdesouza.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116173249.11847-1-marcos@mpdesouza.com> References: <20201116173249.11847-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: 191.249.68.105 X-Source-L: No X-Exim-ID: 1keiNX-000wCw-0F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.suse.de) [191.249.68.105]:38938 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 12 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza [BUG] logical-resolve is currently broken on systems that have a child subvolume being mounted without access to the parent subvolume. This is the default for SLE/openSUSE installations. openSUSE has the subvolume '@' as the parent of all other subvolumes like /boot, /home. The subvolume '@' is never mounted, and accessed, but only it's child: mount | grep btrfs /dev/sda2 on / type btrfs (rw,relatime,ssd,space_cache,subvolid=267,subvol=/@/.snapshots/1/snapshot) /dev/sda2 on /opt type btrfs (rw,relatime,ssd,space_cache,subvolid=262,subvol=/@/opt) /dev/sda2 on /boot/grub2/i386-pc type btrfs (rw,relatime,ssd,space_cache,subvolid=265,subvol=/@/boot/grub2/i386-pc) logical-resolve command calls btrfs_list_path_for_root, that returns the subvolume full-path that corresponds to the tree id of the logical address. As the name implies, the 'full-path' returns all subvolumes, starting from '@'. Later on, btrfs_open_dir is calles using the path returned, but it fails to resolve it since it contains the '@' and this subvolume cannot be accessed. The same problem can be triggered to any user that calls for logical-resolve on a child subvolume that has the parent subvolume not accessible. Another problem in the current approach is that it believes that a subvolume will be mounted in a directory with the same name e.g /@/boot being mounted in /boot. When this is not true, the code also fails, since it uses the subvolume name as the path accessible by the user. [FIX] Extent the find_mount_root function by allowing it to check for mnt_opts member of mntent struct. Using this new approach we can change logical-resolve command to search for subvolid=XXX,subvol=YYY. This is the two problems stated above by not trusting the subvolume name being the mountpoint name, and not following the subvolume tree blindly. Signed-off-by: Marcos Paulo de Souza --- cmds/inspect.c | 30 ++++++++++++++++++++++-------- common/utils.c | 13 +++++++++---- common/utils.h | 5 ++++- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cmds/inspect.c b/cmds/inspect.c index 2530b904..0dc62d18 100644 --- a/cmds/inspect.c +++ b/cmds/inspect.c @@ -245,15 +245,29 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, path_ptr[-1] = '\0'; path_fd = fd; } else { - path_ptr[-1] = '/'; - ret = snprintf(path_ptr, bytes_left, "%s", - name); - free(name); - if (ret >= bytes_left) { - error("path buffer too small: %d bytes", - bytes_left - ret); + char *mounted = NULL; + char volid_str[PATH_MAX]; + + /* + * btrfs_list_path_for_root returns the full + * path to the subvolume pointed by root, but the + * subvolume can be mounted in a directory name + * different from the subvolume name. In this + * case we need to find the correct mountpoint + * using same subvol path and subvol id found + * before. + */ + snprintf(volid_str, PATH_MAX, "subvolid=%llu,subvol=/%s", + root, name); + + ret = find_mount_root(full_path, volid_str, + BTRFS_FIND_ROOT_OPTS, &mounted); + if (ret < 0) goto out; - } + + strncpy(full_path, mounted, PATH_MAX); + free(mounted); + path_fd = btrfs_open_dir(full_path, &dirs, 1); if (path_fd < 0) { ret = -ENOENT; diff --git a/common/utils.c b/common/utils.c index 1c264455..7e6f406b 100644 --- a/common/utils.c +++ b/common/utils.c @@ -1261,8 +1261,6 @@ int find_mount_root(const char *path, const char *data, u8 flag, char **mount_ro char *cmp_field = NULL; bool found; - BUG_ON(flag != BTRFS_FIND_ROOT_PATH); - fd = open(path, O_RDONLY | O_NOATIME); if (fd < 0) return -errno; @@ -1273,11 +1271,18 @@ int find_mount_root(const char *path, const char *data, u8 flag, char **mount_ro return -errno; while ((ent = getmntent(mnttab))) { - cmp_field = ent->mnt_dir; + /* BTRFS_FIND_ROOT_PATH is the default behavior */ + if (flag == BTRFS_FIND_ROOT_OPTS) + cmp_field = ent->mnt_opts; + else + cmp_field = ent->mnt_dir; len = strlen(cmp_field); - found = strncmp(cmp_field, data, len) == 0; + if (flag == BTRFS_FIND_ROOT_OPTS) + found = strstr(cmp_field, data) != NULL; + else + found = strncmp(cmp_field, data, len) == 0; if (found) { /* match found and use the latest match */ diff --git a/common/utils.h b/common/utils.h index 449e1d3e..b5d256c6 100644 --- a/common/utils.h +++ b/common/utils.h @@ -54,7 +54,10 @@ enum btrfs_find_root_flags { /* check mnt_dir of mntent */ - BTRFS_FIND_ROOT_PATH = 0 + BTRFS_FIND_ROOT_PATH = 0, + + /* check mnt_opts of mntent */ + BTRFS_FIND_ROOT_OPTS }; void units_set_mode(unsigned *units, unsigned mode); From patchwork Mon Nov 16 17:32:49 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: 11910263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F22F2C4742C for ; Mon, 16 Nov 2020 17:57:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 980F320B80 for ; Mon, 16 Nov 2020 17:57:31 +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="rTkDUdG9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387756AbgKPR5H (ORCPT ); Mon, 16 Nov 2020 12:57:07 -0500 Received: from gateway20.websitewelcome.com ([192.185.62.46]:34273 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730857AbgKPR5G (ORCPT ); Mon, 16 Nov 2020 12:57:06 -0500 X-Greylist: delayed 1416 seconds by postgrey-1.27 at vger.kernel.org; Mon, 16 Nov 2020 12:57:05 EST Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 7AAE1400D85E1 for ; Mon, 16 Nov 2020 11:30:19 -0600 (CST) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id eiNZkr8FyYLDneiNZkuHn9; Mon, 16 Nov 2020 11:33:25 -0600 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=jUQSCKI6mTIM4Af6V5qrOX0YjAnsc4zom74o4Q8WaEM=; b=rTkDUdG9sM9KS7og3sJr1NwDcS g+jNncFqjwEALSU2rFyjJb2UG/ftL20IVZ04mRgIrdpoM9M1SbyHvJK1z9VWHFnznYMqdgs06wI0E X2/JxadOjLESLJ9mGw8kO59H3Fpc5a8pQwrxcjE56Cdi4FjwrV9TWBkL6BgIDoUw7wUlPJg3SYFp5 8QmuL3l1/NzEOJ+BcAfGCLWwuh+4sBqEiSFXDZxxNwnUZXOFAS/NBfkNSoITnO/ohfyvs+Ds4HXmM OXYtGC51SVwIZWLE1CqFtdxhPJYLW8nB4jE5f6IiuJ8cmMOjs3eY1XPD5CTPQHc588F3DnXSjNoLz hY27jtYw==; Received: from [191.249.68.105] (port=38938 helo=localhost.suse.de) by br540.hostgator.com.br with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1keiNY-000wCw-HB; Mon, 16 Nov 2020 14:33:24 -0300 From: Marcos Paulo de Souza To: linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza , wqu@suse.com, dsterba@suse.com Subject: [PATCH v2 3/3] btrfs-progs: tests: Add new logical-resolve test Date: Mon, 16 Nov 2020 14:32:49 -0300 Message-Id: <20201116173249.11847-4-marcos@mpdesouza.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116173249.11847-1-marcos@mpdesouza.com> References: <20201116173249.11847-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: 191.249.68.105 X-Source-L: No X-Exim-ID: 1keiNY-000wCw-HB X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.suse.de) [191.249.68.105]:38938 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 16 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza Signed-off-by: Marcos Paulo de Souza --- .../test.sh | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 tests/misc-tests/042-inspect-internal-logical-resolve/test.sh diff --git a/tests/misc-tests/042-inspect-internal-logical-resolve/test.sh b/tests/misc-tests/042-inspect-internal-logical-resolve/test.sh new file mode 100755 index 00000000..adb52289 --- /dev/null +++ b/tests/misc-tests/042-inspect-internal-logical-resolve/test.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# Check if logical-resolve is resolving the paths correctly for different +# subvolume tree configurations. This used to fails when a child subvolume was +# mounted without the parent subvolume being accessible. + +source "$TEST_TOP/common" + +setup_root_helper +prepare_test_dev + +check_prereq btrfs +check_prereq mkfs.btrfs + +check_logical_offset_filename() +{ + local filename + local offset + offset="$1" + filename="$2" + + out=$($TOP/btrfs inspect-internal logical-resolve "$offset" "$TEST_MNT") + if [ ! $filename = $out ]; then + _fail "logical-resolve failed. Expected $filename but returned $out" + fi +} + +run_check_mkfs_test_dev +run_check_mount_test_dev + +# create top subvolume called '@' +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@" + +# create a file in eacch subvolume of @, and each file will have 2 EXTENT_DATA item +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@/vol1" +vol1id=$($SUDO_HELPER "$TOP/btrfs" inspect-internal rootid "$TEST_MNT/@/vol1") +run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=150 of="$TEST_MNT/@/vol1/file1" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@/vol1/subvol1" +subvol1id=$($SUDO_HELPER "$TOP/btrfs" inspect-internal rootid "$TEST_MNT/@/vol1/subvol1") +run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=150 of="$TEST_MNT/@/vol1/subvol1/file2" + +"$TOP/btrfs" filesystem sync "$TEST_MNT" + +run_check_umount_test_dev + +$SUDO_HELPER mount -o subvol=/@/vol1 $TEST_DEV "$TEST_MNT" +for offset in $("$TOP/btrfs" inspect-internal dump-tree -t "$vol1id" \ + "$TEST_DEV" | awk '/disk byte/ { print $5 }'); do + check_logical_offset_filename "$offset" "$TEST_MNT/file1" +done + +run_check_umount_test_dev + +$SUDO_HELPER mount -o subvol=/@/vol1/subvol1 $TEST_DEV "$TEST_MNT" +for offset in $("$TOP/btrfs" inspect-internal dump-tree -t "$subvol1id" \ + "$TEST_DEV" | awk '/disk byte/ { print $5 }'); do + check_logical_offset_filename "$offset" "$TEST_MNT/file2" +done + +run_check_umount_test_dev