Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp587924ybt; Fri, 19 Jun 2020 08:47:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuoKypZm1Nzp3dSZYaFK90iLZshaHUJAOsV+/swwKWKjCmtn74IWdERv0gBmO1IHgDFcth X-Received: by 2002:a50:8b44:: with SMTP id l62mr4041524edl.72.1592581673675; Fri, 19 Jun 2020 08:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592581673; cv=none; d=google.com; s=arc-20160816; b=HJ3mtcYnavaQMHwEJ557jw3GxkikvGog3voZOqWk/nP58s/R2hLdCiDWlGOjwalyi2 Q4nUQpIUsz6OGtXcVNR1IwRRJB91HZYEwE1zCLDVa3X0Oq7ZyeA3zB3rbI/nYzaHogKw NCcX4uoKDzAcgzIDT5Y9x4DhjOA1Jj3OEfwXS2JcY2LDpA+xBQAe9fVInHDH79EkYkDU rLxjR3MrN6JDwBrB2UYkHwDClcqsL9GZysxRTD2uSuaK7BX8MSKjxTS2ZZrzcbWfcQ1X 2oEVfYGvObpKLiLj6IcsG5yYxpt2Y9Ko0SvULdiIDhElMCf1FAM0dal0ajElWU/a+jFP zvLQ== 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=uE9ol7y9QZsZ7Lqb+PJqxzZ9njxA6Sg0uHui0QsoaaU=; b=wPANFz7KPX45YDyHKlk+nKmm2skuZyU5dwUCPOS0zawZ1VSKAJ/gngiL942sJ6bHxl 03sYawpvpggxhu9hRsM2Iok1AEZ1uJ/SEGTVtOqA7prDzfUMSh63gLv0+bO2jCsVU5jX zyZRVDLZvAMpqac5zn3v2w68vr70d28JSxameIx2MWGs9f0xdCZ0SL0x3dy1GWELFShb pZVU0v3Q7ICryc5nEnLMf/gY8T/CEjbE5ddU3GDOkS4a5XC97jx8z/68+ZIEKNNYSzY5 2cpx6UY0woyJYlPjr9ImiPt4/Pi6PXTKc6IMcoBv7v/UWHpWryOumy0ktO1ONRefBc+o AHCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=biqfrAHh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si4001021ejn.715.2020.06.19.08.47.30; Fri, 19 Jun 2020 08:47:53 -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=biqfrAHh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393584AbgFSPpD (ORCPT + 99 others); Fri, 19 Jun 2020 11:45:03 -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 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 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: