From patchwork Fri Jun 19 14:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223996 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA8C9C433DF for ; Fri, 19 Jun 2020 15:45:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA508206FA for ; Fri, 19 Jun 2020 15:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592581507; bh=TW6j57xA4M2KvkhtMtP8V3nsqFz0J5n9lmoDknQHfxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sKpyt1PJM1vM1Ok9C9iyt3VpV8GzQTb8zx4OAalEpIeX8dZr7OzMdx/7NOkIzlVVz 8alrRnWePlhcO1lVckFPI2kxbnRsbZSE36j1e0BVz4GRqDuWrQphNzXXcnfmr3FGiw r5ljLxqLUeVLCHOipw+BJbWWSo3PKUzWpkxLCIrs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391802AbgFSPpB (ORCPT ); Fri, 19 Jun 2020 11:45:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:59372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393567AbgFSP1g (ORCPT ); Fri, 19 Jun 2020 11:27:36 -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 DB6F121941; Fri, 19 Jun 2020 15:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580455; bh=TW6j57xA4M2KvkhtMtP8V3nsqFz0J5n9lmoDknQHfxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=biqfrAHhrEO9lJmMcDyW309+IF8W8Hg91F62BJ0afWAzH+8hNijlfmycJLQnkrioj Y11TzrRwf7j/EQUqTM6RIoCHtaTSUmxtTX5YshqrBp1wJgkxYWjM+XPPYSsoMvl4M9 PVO7m7ESbQM8ny6ys07grXCP73JbNjolKjWZVVLc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , David Sterba Subject: [PATCH 5.7 256/376] btrfs: free alien device after device add Date: Fri, 19 Jun 2020 16:32:54 +0200 Message-Id: <20200619141722.444467186@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Anand Jain commit 7f551d969037cc128eca60688d9c5a300d84e665 upstream. When an old device has new fsid through 'btrfs device add -f ' our fs_devices list has an alien device in one of the fs_devices lists. By having an alien device in fs_devices, we have two issues so far 1. missing device does not not show as missing in the userland 2. degraded mount will fail Both issues are caused by the fact that there's an alien device in the fs_devices list. (Alien means that it does not belong to the filesystem, identified by fsid, or does not contain btrfs filesystem at all, eg. due to overwrite). A device can be scanned/added through the control device ioctls SCAN_DEV, DEVICES_READY or by ADD_DEV. And device coming through the control device is checked against the all other devices in the lists, but this was not the case for ADD_DEV. This patch fixes both issues above by removing the alien device. CC: stable@vger.kernel.org # 5.4+ Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2663,8 +2663,18 @@ int btrfs_init_new_device(struct btrfs_f ret = btrfs_commit_transaction(trans); } - /* Update ctime/mtime for libblkid */ + /* + * Now that we have written a new super block to this device, check all + * other fs_devices list if device_path alienates any other scanned + * device. + * We can ignore the return value as it typically returns -EINVAL and + * only succeeds if the device was an alien. + */ + btrfs_forget_devices(device_path); + + /* Update ctime/mtime for blkid or udev */ update_dev_time(device_path); + return ret; error_sysfs: