From patchwork Fri Nov 27 19:30:35 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: 11937141 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 67987C3E8C5 for ; Fri, 27 Nov 2020 19:54:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3D1A208B3 for ; Fri, 27 Nov 2020 19:54:24 +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="p66ygSla" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730852AbgK0TyJ (ORCPT ); Fri, 27 Nov 2020 14:54:09 -0500 Received: from gateway30.websitewelcome.com ([192.185.192.34]:17635 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730718AbgK0TxE (ORCPT ); Fri, 27 Nov 2020 14:53:04 -0500 X-Greylist: delayed 701 seconds by postgrey-1.27 at vger.kernel.org; Fri, 27 Nov 2020 14:53:03 EST Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 21BD1A123 for ; Fri, 27 Nov 2020 13:31:32 -0600 (CST) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id ijSukdLXHfAtaijSukTQit; Fri, 27 Nov 2020 13:31:32 -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=XzUl/OA+elutv3PgG4jfRtkmxPAF/uzTf0X4MmLH7XA=; b=p66ygSla/jDJwV5OaPNsJZ66G2 4rQfmejGMsDubi45GAEAHkIJmz+SLs8VOKM6VB6FTvwmcIjD9cXK8xLjrxCHwz/klBhn4RwsrVKI8 PDEk+FOvxIe7Fm6ExwUiEUN1zRVYBlLzOt9C7TYSEQgGIP0OBrJOZAfnMqMKmIsS3yJ2M2M+Rdi/5 cpEPBdld4b1ZA93Xa2M2uc483Iex06Sm1uPFlrUG5TG+FZ27pJm/g/j+LUPvrddPu7yzG0FIRFFtT M4hz0miRbY7k5uGcp0SalWYBZjoK4zG6Z/TBnwR/htpKu3HcjP/SCadO3m+mkxbgjhklKWhYlaoZb +wZ2hiuQ==; Received: from 200.146.52.186.dynamic.dialup.gvt.net.br ([200.146.52.186]:60574 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 1kijSt-003Dm3-I1; Fri, 27 Nov 2020 16:31:31 -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 v4 3/3] btrfs-progs: tests: Add new logical-resolve test Date: Fri, 27 Nov 2020 16:30:35 -0300 Message-Id: <20201127193035.19171-4-marcos@mpdesouza.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201127193035.19171-1-marcos@mpdesouza.com> References: <20201127193035.19171-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: 200.146.52.186 X-Source-L: No X-Exim-ID: 1kijSt-003Dm3-I1 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 200.146.52.186.dynamic.dialup.gvt.net.br (localhost.suse.de) [200.146.52.186]:60574 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 | 81 +++++++++++++++++++ 1 file changed, 81 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..fcf1147f --- /dev/null +++ b/tests/misc-tests/042-inspect-internal-logical-resolve/test.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# Check if logical-resolve is resolving the paths correctly for different +# subvolume tree configurations. This used to fail 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" + + while read file; do + if [[ "$file" = *"inode "* ]]; then + _log "$file" + elif [ ! -f $file ]; then + _fail "Path not $file file cannot be accessed" + elif [ ! $filename = $file ]; then + _fail "logical-resolve failed. Expected $filename but returned $file" + else + _log "$file" + fi + done < <($TOP/btrfs inspect-internal logical-resolve "$offset" "$TEST_MNT") +} + +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 +# items, and also create a snapshot to have a extent being referenced by two +# different fs trees +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 snapshot "$TEST_MNT/@/vol1" "$TEST_MNT/@/snap1" + +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" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot "$TEST_MNT/@/vol1/subvol1" \ + "$TEST_MNT/@/vol1/snapshot1" + +"$TOP/btrfs" filesystem sync "$TEST_MNT" + +run_check_umount_test_dev + +# to be used later +mkdir -p mnt2 + +$SUDO_HELPER mount -o subvol=/@/vol1 $TEST_DEV "$TEST_MNT" +# create a bind mount to the vol1. logical-resolve should avoid bind mounts, +# otherwise the test will fail +mkdir -p "$TEST_MNT/dir" +$SUDO_HELPER mount --bind "$TEST_MNT/dir" mnt2 + +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 mnt2 +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