From patchwork Thu Apr 9 21:34:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6191001 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 921E6BF4A6 for ; Thu, 9 Apr 2015 21:37:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BA4A4203AC for ; Thu, 9 Apr 2015 21:37:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D58C82037A for ; Thu, 9 Apr 2015 21:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754399AbbDIVhA (ORCPT ); Thu, 9 Apr 2015 17:37:00 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:35668 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752517AbbDIVfX (ORCPT ); Thu, 9 Apr 2015 17:35:23 -0400 Received: by pabtp1 with SMTP id tp1so308136pab.2 for ; Thu, 09 Apr 2015 14:35:23 -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=ZrsZ6J8aGKTvT/QKMCdr8OMBxh7b6k/kF6cBTt9r7fk=; b=cXDjcws210kVpffLrL+8MZZeBVMVzHYrMg0Y4Uh+BXSZ8SmDQqmGXbFYGC3k0RwRrD 8sHnl+nKcbN9Wb1Y2gt7QRxuARTcLpD+A71OdyTZdmk4515bcVsV4AzJNvHsTcw4/OuA +oNnU4QQF9tF+GzZ8gNf21zD0BSH0J9Tz4JTxQ9TJMq7ypw/o182TI6An4rc9p6Go1hE 8m3VDQqCQNLHWgN2XksHJKxcb8YfxH786V8xjRY+jqkPTPP4wcxL+tkJoN5T4sc6tXx3 Uv3p+cRJ9vy4nLowZcymS9iy3ZtNkxl369LMWCSPWodWMldgE4j+hJWupw5sSgk78Ag0 IuEA== X-Gm-Message-State: ALoCoQmniRNUjD6m69FtMgOby+VP4lakM8uw8hLPW6T2J79w320LHgaq0OkJKYx7Brwi/QcHxrEf X-Received: by 10.66.251.165 with SMTP id zl5mr59045690pac.93.1428615323097; Thu, 09 Apr 2015 14:35:23 -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 ot6sm15540730pdb.28.2015.04.09.14.35.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Apr 2015 14:35:22 -0700 (PDT) From: Omar Sandoval To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Qu Wenruo , Omar Sandoval Subject: [PATCH v2 1/6] Btrfs: lock superblock before remounting for rw subvol Date: Thu, 9 Apr 2015 14:34:51 -0700 Message-Id: X-Mailer: git-send-email 2.3.5 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") Signed-off-by: Omar Sandoval Reviewed-by: David Sterba --- fs/btrfs/super.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 05fef19..d38be09 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1205,7 +1205,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);