From patchwork Thu Apr 2 03:49:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6144181 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4D09B9F350 for ; Thu, 2 Apr 2015 03:50:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CDF620386 for ; Thu, 2 Apr 2015 03:50:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85EAE20382 for ; Thu, 2 Apr 2015 03:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753092AbbDBDuB (ORCPT ); Wed, 1 Apr 2015 23:50:01 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:33841 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753058AbbDBDt5 (ORCPT ); Wed, 1 Apr 2015 23:49:57 -0400 Received: by pdbni2 with SMTP id ni2so75961012pdb.1 for ; Wed, 01 Apr 2015 20:49:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=G4IxZ5O5FSRTd8JRvZHL4I6RDT10GRcOH8OtinxjRbg=; b=DUZm06vFrsN97wwbvRCgwjTuasi8WhJsMjkjGPKdeVlW49uPhCuC97GfNzNMH0px+0 RyZtVI/HCqOtC+CoPBpxbegcV3JrmC/tBGG/18WF/D6HCGExXmkKi1qZ/RQISvmb7qJO 3CSgcFhHoNesq7hw5lgg7rIdXUZXOwon5HCrEuCwee4XQsd0hndUxIR0581ybWYwJih6 RE6EAqKfDiw5w2VdtE8VZrxuI2wnSbjFtMBSTYb2g0xpH3aok+hgtyxqTKJBogHw9LlB VE3awDurtNpgxYo2T9OjSlgRM2kIU8aV8zgWacQ+5uKxvPzRYJE/MwOnankdC/qHyF0x nvvg== X-Gm-Message-State: ALoCoQltyAC1GrNGIkeBE41SxByWqsIrHj9GjFfElTzRdRuc8Fx8zwPEFqHsvf9jdhviDJqd9Wod X-Received: by 10.66.139.70 with SMTP id qw6mr1507510pab.112.1427946596694; Wed, 01 Apr 2015 20:49:56 -0700 (PDT) Received: from mew.Belkin (c-73-19-41-147.hsd1.wa.comcast.net. [73.19.41.147]) by mx.google.com with ESMTPSA id xc4sm3609708pac.9.2015.04.01.20.49.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 20:49:55 -0700 (PDT) Date: Wed, 1 Apr 2015 20:49:54 -0700 From: Omar Sandoval To: David Sterba Cc: "Eric W. Biederman" , Chris Mason , Josef Bacik , Timo Kokkonen , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] Btrfs: prevent deletion of mounted subvolumes Message-ID: <20150402034954.GA25368@mew.Belkin> References: <64e28e67cbab0a2cd97411b848911414a743d83f.1427705646.git.osandov@osandov.com> <20150330123034.GB32051@suse.cz> <20150330184135.GA27227@mew.dhcp4.washington.edu> <87k2xwv6y8.fsf@x220.int.ebiederm.org> <20150401070328.GA27048@mew> <20150401112242.GG6821@suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150401112242.GG6821@suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 On Wed, Apr 01, 2015 at 01:22:42PM +0200, David Sterba wrote: > On Wed, Apr 01, 2015 at 12:03:28AM -0700, Omar Sandoval wrote: > > --- a/fs/btrfs/super.c > > +++ b/fs/btrfs/super.c > > @@ -1024,6 +1024,10 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) > > struct btrfs_root *root = info->tree_root; > > char *compress_type; > > > > + if (dentry != dentry->d_sb->s_root) { > > + seq_puts(seq, ",subvol="); > > + seq_dentry(seq, dentry, " \t\n\\"); > > Unfortunatelly this does not work if the default subvolume is not the > toplevel one and the implicit mount (ie. without subvol=) is used. Then > this leads to subvol=/ although it should be subvol=/the/default . > > There was a patch to build the path in the show_options callback, but it > looked too heavy (taking locks, doing lookups). This is unrelated to the > problem reported by Timo, though the fix might also fix this one. Hm, yeah, that's unfortunate, thanks for pointing that out. It looks like we can get the subvolume ID reliably: ---- ---- With that, userspace has enough information to determine whether a subvolume is mounted. That would be racy with concurrent mounts, though... Just to throw another idea out there, what about doing something like my VFS patch, but then making it optional whether the kernel should error out on a mounted subvolume, e.g., with a flag to the ioctl? btrfs-progs could default to the original EBUSY behavior for users who depend on it, but we could add a "force" flag to `btrfs subvolume delete` in order to avert the DoS situation Eric wants to avoid. Thoughts on that? diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 05fef19..a74ddb3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1024,6 +1024,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) struct btrfs_root *root = info->tree_root; char *compress_type; + seq_printf(seq, ",subvolid=%llu", + BTRFS_I(d_inode(dentry))->root->root_key.objectid); if (btrfs_test_opt(root, DEGRADED)) seq_puts(seq, ",degraded"); if (btrfs_test_opt(root, NODATASUM))