From patchwork Fri Jun 6 03:26:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 4309651 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7B3899F357 for ; Fri, 6 Jun 2014 03:24:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 796B020265 for ; Fri, 6 Jun 2014 03:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C9ED20222 for ; Fri, 6 Jun 2014 03:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752623AbaFFDYd (ORCPT ); Thu, 5 Jun 2014 23:24:33 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:36717 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752563AbaFFDYc (ORCPT ); Thu, 5 Jun 2014 23:24:32 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s563OPXa010074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Jun 2014 03:24:26 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s563OO7v003681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 6 Jun 2014 03:24:24 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s563OOrl009660; Fri, 6 Jun 2014 03:24:24 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Jun 2014 20:24:24 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, wangsl.fnst@cn.fujitsu.com, clm@fb.com, jbacik@fb.com, quwenruo@cn.fujitsu.com Subject: [PATCH V3] Btrfs: device_list_add() should not update list when mounted Date: Fri, 6 Jun 2014 11:26:41 +0800 Message-Id: <1402025201-17140-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.2 X-Source-IP: acsinet22.oracle.com [141.146.126.238] 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 (looks like there was some sendmail problem I don't see this in the btrfs list, sending again. sorry for multiple copies if any). device_list_add() is called when user runs btrfs dev scan, which would add any btrfs device into the btrfs_fs_devices list. Now think of a mounted btrfs. And a new device which contains the a SB from the mounted btrfs devices. In this situation when user runs btrfs dev scan, the current code would just replace existing device with the new device. Which is to note that old device is neither closed nor gracefully removed from the btrfs. The FS is still operational with the old bdev however the device name is the btrfs_device is new which is provided by the btrfs dev scan. reproducer: devmgt[1] detach /dev/sdc replace the missing disk /dev/sdc btrfs rep start -f 1 /dev/sde /btrfs Label: none uuid: 5dc0aaf4-4683-4050-b2d6-5ebe5f5cd120 Total devices 2 FS bytes used 32.00KiB devid 1 size 958.94MiB used 115.88MiB path /dev/sde devid 2 size 958.94MiB used 103.88MiB path /dev/sdd make /dev/sdc to reappear devmgt attach host2 btrfs dev scan btrfs fi show -m Label: none uuid: 5dc0aaf4-4683-4050-b2d6-5ebe5f5cd120^M Total devices 2 FS bytes used 32.00KiB^M devid 1 size 958.94MiB used 115.88MiB path /dev/sdc <- Wrong. devid 2 size 958.94MiB used 103.88MiB path /dev/sdd since /dev/sdc has been replaced with /dev/sde, the /dev/sdc shouldn't be part of the btrfs-fsid when it reappears. If user want it to be part of it then sys admin should be using btrfs device add instead. [1] github.com/anajain/devmgt.git Signed-off-by: Anand Jain --- v2->v3: simpler commit and comment message v1->v2: remove '---' in commit messages which conflict with git am fs/btrfs/volumes.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bb2cd66..605d9ef 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -472,9 +472,12 @@ static noinline int device_list_add(const char *path, device = __find_device(&fs_devices->devices, devid, disk_super->dev_item.uuid); } + if (!device) { - if (fs_devices->opened) + if (fs_devices->opened) { + printk(KERN_INFO "BTRFS: device list add failed, FS is open"); return -EBUSY; + } device = btrfs_alloc_device(NULL, &devid, disk_super->dev_item.uuid); @@ -497,6 +500,34 @@ static noinline int device_list_add(const char *path, device->fs_devices = fs_devices; } else if (!device->name || strcmp(device->name->str, path)) { + /* + * When FS is already mounted. + * 1. If you are here and if the device->name is NULL that means + * this device was missing at time of FS mount. + * 2. If you are here and if the device->name is different from 'path' + * that means either + * a. The same device disappeared and reappeared with different + * name. or + * b. The missing-disk-which-was-replaced, has reappeared now. + * + * We must allow 1 and 2a above. But 2b would be a spurious and + * unintentional. + * Further in case of 1 and 2a above, the disk at 'path' would have + * missed some transaction when it was away and in case of 2a + * the stale bdev has to be updated as well. + * 2b must not be allowed at all time. + */ + + /* + * As of now don't allow update to btrfs_fs_device through the + * btrfs dev scan cli, after FS has been mounted. + */ + + if (fs_devices->opened) { + printk(KERN_INFO "BTRFS: device list update failed, FS is open"); + return -EBUSY; + } + name = rcu_string_strdup(path, GFP_NOFS); if (!name) return -ENOMEM;