From patchwork Sun May 25 02:55:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4238161 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9C3D7BF90B for ; Sun, 25 May 2014 01:56:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB8B420295 for ; Sun, 25 May 2014 01:56:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFDA420172 for ; Sun, 25 May 2014 01:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751433AbaEYB4V (ORCPT ); Sat, 24 May 2014 21:56:21 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:57520 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751322AbaEYB4U (ORCPT ); Sat, 24 May 2014 21:56:20 -0400 Received: by mail-wg0-f51.google.com with SMTP id x13so6454754wgg.22 for ; Sat, 24 May 2014 18:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xZPLGJI4hkHhflQd37N7wBUL8H+gkSxdXVWjPmXy42Q=; b=WWc1FIr5TXgEgE7bs/hihnGqfpoiNy+o4yeV26ceD3MiRu2KsEDyBECZwRcJvKy/36 jOQeiYGtCdl9VS4BoSdtx5R3V9JeQo//6bTz6Avy7zWQ2huq7golLtuNmnevE1TjOOsK 9CVTyKMFKYb/wCod72OdRLdJqMD5LfQ/7CGrzXIBd/KEq7Q5peEmwSBu8lnL7uHwMDFh b+qxAlFZzKd2O45zVj3Beti/4vWCiGZAy4CjHvcqk/10R1LxLmf9Umlg+KB6jokguhKZ BwxdY6d75mVjPU+ytyrfSNKSzvQgaiTbRtyXpknWaAU08/qbqywZVqYWUPLbUVzUFatr hkEQ== X-Received: by 10.180.228.42 with SMTP id sf10mr15342882wic.48.1400982979078; Sat, 24 May 2014 18:56:19 -0700 (PDT) Received: from debian-vm3.lan (bl10-252-12.dsl.telepac.pt. [85.243.252.12]) by mx.google.com with ESMTPSA id bn7sm14698267wjc.7.2014.05.24.18.56.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 May 2014 18:56:18 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH v2] Btrfs: set dead flag on the right root when destroying snapshot Date: Sun, 25 May 2014 03:55:44 +0100 Message-Id: <1400986544-22440-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1400985885-16386-1-git-send-email-fdmanana@gmail.com> References: <1400985885-16386-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We were setting the BTRFS_ROOT_SUBVOL_DEAD flag on the root of the parent of our target snapshot, instead of setting it in the target snapshot's root. This is easy to observe by running the following scenario: mkfs.btrfs -f /dev/sdd mount /dev/sdd /mnt btrfs subvolume create /mnt/first_subvol btrfs subvolume snapshot -r /mnt /mnt/mysnap1 btrfs subvolume delete /mnt/first_subvol btrfs subvolume snapshot -r /mnt /mnt/mysnap2 btrfs send -p /mnt/mysnap1 /mnt/mysnap2 -f /tmp/send.data The send command failed because the send ioctl returned -EPERM. A test case for xfstests follows. Signed-off-by: Filipe David Borba Manana Reviewed-by: David Sterba --- V2: Add missing replacements of 'root' with 'dest'. fs/btrfs/ioctl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 362720a..38f2169 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2312,16 +2312,16 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, * again is not run concurrently. */ spin_lock(&dest->root_item_lock); - root_flags = btrfs_root_flags(&root->root_item); - if (root->send_in_progress == 0) { - btrfs_set_root_flags(&root->root_item, + root_flags = btrfs_root_flags(&dest->root_item); + if (dest->send_in_progress == 0) { + btrfs_set_root_flags(&dest->root_item, root_flags | BTRFS_ROOT_SUBVOL_DEAD); spin_unlock(&dest->root_item_lock); } else { spin_unlock(&dest->root_item_lock); btrfs_warn(root->fs_info, "Attempt to delete subvolume %llu during send", - root->root_key.objectid); + dest->root_key.objectid); err = -EPERM; goto out_dput; } @@ -2416,8 +2416,8 @@ out_up_write: out_unlock: if (err) { spin_lock(&dest->root_item_lock); - root_flags = btrfs_root_flags(&root->root_item); - btrfs_set_root_flags(&root->root_item, + root_flags = btrfs_root_flags(&dest->root_item); + btrfs_set_root_flags(&dest->root_item, root_flags & ~BTRFS_ROOT_SUBVOL_DEAD); spin_unlock(&dest->root_item_lock); }