From patchwork Mon May 18 09:16:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6427031 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AD051C0432 for ; Mon, 18 May 2015 09:16:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9DD922060B for ; Mon, 18 May 2015 09:16:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 835312060A for ; Mon, 18 May 2015 09:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752845AbbERJQp (ORCPT ); Mon, 18 May 2015 05:16:45 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:34576 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752740AbbERJQo (ORCPT ); Mon, 18 May 2015 05:16:44 -0400 Received: by pdbnk13 with SMTP id nk13so45892353pdb.1 for ; Mon, 18 May 2015 02:16:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=yBmf7l58mn+57CZ9ZFQrU7+xcEr6rYCHPJTtZWqkF18=; b=dn3b9J9lwTJ8UVHxCrjNoHmKrAENkW6p1o8RS4RibIksQYe4H5wRFvsgxXVUzPX9g8 4t3GSRj0QbK1CNvW+K21o+DsP3mrmx4tkwr3D9uLFHvMUEjggL7qTqIBoItzZCa2wK1n 3PqStmnNMBqpQODou1Pq4ucOq8abV9Uc66FZDNtHMMqQ5rXGgCDAEOqggJU35jZ4v16/ XuGRcTUtwEERQZ4kOfen3TW6Cn9MW2O+XnnHO9CNJmVqbm9xcnvj3Edv33R+0+HYwGWn NhYS5VVTBUX0IHD3PxdK76bpYstSeGh16i49GHfXKb1iq8citXDjBL/9SpspR46HHI3W 9V4w== X-Gm-Message-State: ALoCoQkDbLECq9nIdEihYmeNEu7TjmLQDTNBr3lKRB6+1CyPIxjI22lg5jAh/PfQKfujypM5acMU X-Received: by 10.66.140.36 with SMTP id rd4mr42283754pab.109.1431940603219; Mon, 18 May 2015 02:16:43 -0700 (PDT) Received: from mew.localdomain (c-76-104-211-44.hsd1.wa.comcast.net. [76.104.211.44]) by mx.google.com with ESMTPSA id v2sm9377370pdn.90.2015.05.18.02.16.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 May 2015 02:16:42 -0700 (PDT) From: Omar Sandoval To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Cc: Qu Wenruo , Omar Sandoval Subject: [PATCH v3 1/6] Btrfs: lock superblock before remounting for rw subvol Date: Mon, 18 May 2015 02:16:26 -0700 Message-Id: <89684580fa5b3dce63d7491789f835eb3ce6d4dd.1431939732.git.osandov@osandov.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@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=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 Since commit 0723a0473fb4 ("btrfs: allow mounting btrfs subvolumes with different ro/rw options"), when mounting a subvolume read/write when another subvolume has previously been mounted read-only, we first do a remount. However, this should be done with the superblock locked, as per sync_filesystem(): /* * We need to be protected against the filesystem going from * r/o to r/w or vice versa. */ WARN_ON(!rwsem_is_locked(&sb->s_umount)); This WARN_ON can easily be hit with: mkfs.btrfs -f /dev/vdb mount /dev/vdb /mnt btrfs subvol create /mnt/vol1 btrfs subvol create /mnt/vol2 umount /mnt mount -oro,subvol=/vol1 /dev/vdb /mnt mount -orw,subvol=/vol2 /dev/vdb /mnt2 Fixes: 0723a0473fb4 ("btrfs: allow mounting btrfs subvolumes with different ro/rw options") Reviewed-by: David Sterba Signed-off-by: Omar Sandoval --- fs/btrfs/super.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 9e66f5e..0576750 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1214,7 +1214,9 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, return ERR_CAST(mnt); } + down_write(&mnt->mnt_sb->s_umount); r = btrfs_remount(mnt->mnt_sb, &flags, NULL); + up_write(&mnt->mnt_sb->s_umount); if (r < 0) { /* FIXME: release vfsmount mnt ??*/ kfree(newargs);