Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1260372pxa; Thu, 20 Aug 2020 07:01:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS2Eb7ZnB3aPqPyFm8YmQYVx2bG4zwo80beVWVw1Uqg9ojSPKXNJmIvZWVTwEeVAMg25Lz X-Received: by 2002:a17:906:e17:: with SMTP id l23mr3280495eji.13.1597932069258; Thu, 20 Aug 2020 07:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597932069; cv=none; d=google.com; s=arc-20160816; b=lkDzfPh4UG4thPWJ9CkExol/IIZOeO9iBc8lc1OsWYyJ1uTvL4bpDTfjEy5nD6VPQp qo8yvdkaN+5bolCb60TumSC/pNxCOhaya2Nr73UOpAbXZdyZ3Sgv1DLl60kfsfThasbA S7wifHa02YW6iJtxpys9pOG2uYShYvA/NU0vExEy9E7SJmzjnctpvsBkHwhVTN+arFZW 23hVLJSPYGIi0+euRjSC33rE8+M3PWzGCplnv1HK4JWmiqauJTSUCUpEafdY/Cwawbar 0jVe8YemKjeyTvKW9uB5W8ke2f3fjb43HbFG86/CCWAKWLXXmAl3MGGRfNDcMvy7rZXY Mj2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AZHCdC7/zD89SIb0Y5BGt4MH0dcGOu1PXswdY9a7suQ=; b=bEGPsswnvEnRSBTTd13lwfUhfZHF+qvbdi32rUlo0rmDnyqMi1UOTCT4Lo5F2yj07I zbJG2AETK4Ab3e/WtWE0GugWut/CqgixCfYfA9Zle7aRXzdxyfRqzpNSZn/AeA3qaJUD Jk4auM4sYY9Xd+bDiixXZgwlzXSgX0h7PG4/4esk7cfrk7iBxvCwlTTl/Ih6h/DFXUhV FP8lZDf74MG4OqJ1iFKaVL1KugE7iie9RZkTMN+7m11Rl+4kn9MzREVgGsL1d2WCpai9 +UEYEzZl9HmuiR4CvknIkLfqQkqjg7d6BQcIVW0deYMrDxU0z8Uk7iwjgC33jh4IkrWn PvlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rmBJXqt0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u27si1093039ejj.716.2020.08.20.07.00.44; Thu, 20 Aug 2020 07:01:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rmBJXqt0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731307AbgHTN7K (ORCPT + 99 others); Thu, 20 Aug 2020 09:59:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:60614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbgHTJYZ (ORCPT ); Thu, 20 Aug 2020 05:24:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A29122CB1; Thu, 20 Aug 2020 09:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915464; bh=+ovO2cUVQ9x1FMkutMCyDN2YYRsnBrHjjN50/X+tt9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rmBJXqt0voH9cEA475+ufLb+R/9T9ltWzAPrEXVIIWgLG1pa+M6EJPC9JFSo7CElu 9f2SLRfwU871QC78TD82MIGZCIVhKR9WZZRWLspP4K8nx8g5RgeXPpKRbGoS8OzfC5 9Gysnxg4xTTygAkfE9I2MLSDlVlnTShacFAqV9UI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Martin K. Petersen" , Anand Jain , David Sterba Subject: [PATCH 5.8 022/232] btrfs: dont traverse into the seed devices in show_devname Date: Thu, 20 Aug 2020 11:17:53 +0200 Message-Id: <20200820091613.821160235@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anand Jain commit 4faf55b03823e96c44dc4e364520000ed3b12fdb upstream. ->show_devname currently shows the lowest devid in the list. As the seed devices have the lowest devid in the sprouted filesystem, the userland tool such as findmnt end up seeing seed device instead of the device from the read-writable sprouted filesystem. As shown below. mount /dev/sda /btrfs mount: /btrfs: WARNING: device write-protected, mounted read-only. findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 btrfs dev add -f /dev/sdb /btrfs umount /btrfs mount /dev/sdb /btrfs findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 All sprouts from a single seed will show the same seed device and the same fsid. That's confusing. This is causing problems in our prototype as there isn't any reference to the sprout file-system(s) which is being used for actual read and write. This was added in the patch which implemented the show_devname in btrfs commit 9c5085c14798 ("Btrfs: implement ->show_devname"). I tried to look for any particular reason that we need to show the seed device, there isn't any. So instead, do not traverse through the seed devices, just show the lowest devid in the sprouted fsid. After the patch: mount /dev/sda /btrfs mount: /btrfs: WARNING: device write-protected, mounted read-only. findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 btrfs dev add -f /dev/sdb /btrfs mount -o rw,remount /dev/sdb /btrfs findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sdb /btrfs 595ca0e6-b82e-46b5-b9e2-c72a6928be48 mount /dev/sda /btrfs1 mount: /btrfs1: WARNING: device write-protected, mounted read-only. btrfs dev add -f /dev/sdc /btrfs1 findmnt --output SOURCE,TARGET,UUID /btrfs1 SOURCE TARGET UUID /dev/sdc /btrfs1 ca1dbb7a-8446-4f95-853c-a20f3f82bdbb cat /proc/self/mounts | grep btrfs /dev/sdb /btrfs btrfs rw,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0 /dev/sdc /btrfs1 btrfs ro,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0 Reported-by: Martin K. Petersen CC: stable@vger.kernel.org # 4.19+ Tested-by: Martin K. Petersen Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/super.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2296,9 +2296,7 @@ static int btrfs_unfreeze(struct super_b static int btrfs_show_devname(struct seq_file *m, struct dentry *root) { struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb); - struct btrfs_fs_devices *cur_devices; struct btrfs_device *dev, *first_dev = NULL; - struct list_head *head; /* * Lightweight locking of the devices. We should not need @@ -2308,18 +2306,13 @@ static int btrfs_show_devname(struct seq * least until the rcu_read_unlock. */ rcu_read_lock(); - cur_devices = fs_info->fs_devices; - while (cur_devices) { - head = &cur_devices->devices; - list_for_each_entry_rcu(dev, head, dev_list) { - if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state)) - continue; - if (!dev->name) - continue; - if (!first_dev || dev->devid < first_dev->devid) - first_dev = dev; - } - cur_devices = cur_devices->seed; + list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) { + if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state)) + continue; + if (!dev->name) + continue; + if (!first_dev || dev->devid < first_dev->devid) + first_dev = dev; } if (first_dev)