From patchwork Fri May 5 22:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 157 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id mVvZD5P/DFkUHwAAtiB/HQ for ; Sat, 06 May 2017 00:41:23 +0200 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 7845E40693; Sat, 6 May 2017 00:41:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.5 tests=BAYES_00,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Sat, 6 May 2017 00:41:20 +0200 (CEST) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id ACD2120843; Fri, 5 May 2017 22:41:17 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 282F0207E0 for ; Fri, 5 May 2017 22:41:15 +0000 (UTC) Received: from nymeria.archlinux.org (nymeria.archlinux.org [IPv6:2a00:1828:2000:547::2]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 5 May 2017 22:41:15 +0000 (UTC) Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 8D5814047F for ; Sat, 6 May 2017 00:41:13 +0200 (CEST) Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS for ; Sat, 6 May 2017 00:41:13 +0200 (CEST) Received: from build64-par (unknown [IPv6:2601:803:202:9275:21f:e2ff:fe4d:191b]) by mav.lukeshu.com (Postfix) with ESMTPSA id 6767983CF2 for ; Fri, 5 May 2017 18:41:11 -0400 (EDT) From: Luke Shumaker To: arch-projects@archlinux.org Date: Fri, 5 May 2017 18:40:58 -0400 Message-Id: <20170505224110.28990-2-lukeshu@parabola.nu> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170505224110.28990-1-lukeshu@parabola.nu> References: <20170505224110.28990-1-lukeshu@parabola.nu> Subject: [arch-projects] [devtools][PATCH 01/13] makechrootpkg: delete_chroot: Fix the is-btrfs-subvolume check. X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Arch Linux projects development discussion Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 375 Status: X-Keywords: Content-Length: 2126 First of all, it ran `is_btrfs "$chrootdir"` to decide if it was on btrfs, but $chrootdir wasn't defined locally; it just happens to work because $chrootdir was defined in main(). (I noticed this because in Parabola, it is called differently, so $chrootdir was empty). So I was tempted to just change it to `is_btrfs "$copydir"`, but if $copydir is just a regular directory on a btrfs filesystem, then it It would leave much of $copydir intact. What we really care about is if $copydir is a btrfs subvolume; which we can check by combining the is_btrfs check with inspecting the inum of the directory. I put this combined check in lib/archroot.sh:is_subvolume. https://lists.archlinux.org/pipermail/arch-projects/2013-September/003901.html --- lib/archroot.sh | 11 ++++++++++- makechrootpkg.in | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/archroot.sh b/lib/archroot.sh index 46d4963..87c28a2 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -25,6 +25,15 @@ is_btrfs() { } ## +# usage : is_subvolume( $path ) +# return : whether $path is a the root of a btrfs subvolume (including +# the top-level subvolume). +## +is_subvolume() { + [[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs && "$(stat -c %i "$1")" == 256 ]] +} + +## # usage : subvolume_delete_recursive( $path ) # # Find all btrfs subvolumes under and including $path and delete them. @@ -32,7 +41,7 @@ is_btrfs() { subvolume_delete_recursive() { local subvol - is_btrfs "$1" || return 0 + is_subvolume "$1" || return 0 while IFS= read -d $'\0' -r subvol; do if ! btrfs subvolume delete "$subvol" &>/dev/null; then diff --git a/makechrootpkg.in b/makechrootpkg.in index 72b7eb7..88c2cdc 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -144,7 +144,7 @@ delete_chroot() { local copy=${1:-$2} stat_busy "Removing chroot copy [%s]" "$copy" - if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then + if is_subvolume "$copydir" && ! mountpoint -q "$copydir"; then subvolume_delete_recursive "$copydir" || die "Unable to delete subvolume %s" "$copydir" else