From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC9AE13C3F5; Tue, 14 May 2024 11:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715686338; cv=none; b=bRwPjYmPtp4+i6TA3tUsRh7LiHygyLJeEI/S9NHroNRhlZkf33/r+UMB2iG3bljb0PZyKBHKBk6tFIyL2cs9WWzRWGTBs9WwhWrHd3voayniQCjHuIF+oSbBnrwhv4HqrG9XTDB0kA/bnXjjhRQXZhsnAJvUQmgrBq2pSynkRVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715686338; c=relaxed/simple; bh=FoUcC11yACV+cCC5Ct9fO41bVrYdpU2QlKpPeVC1zf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gnabW7xFn8wQWILJ3GCOAX/cIknKaZz3Fq0J3Pm9x8m0Z33pbPODwtbjlLGm2Uqx3XcOFni2SBePyIf5WrX8OEg7lRZgr0pQjRwPu3bJgYJCN9b3UkHVna8z1K/EpkyxIRQ6rCWbiv/Se1xI0D0iXkJjC1zBdJDlqjn4o6K05eg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WFVEooNy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WFVEooNy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33370C2BD10; Tue, 14 May 2024 11:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715686338; bh=FoUcC11yACV+cCC5Ct9fO41bVrYdpU2QlKpPeVC1zf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WFVEooNyNxkJH5/ZdLvLmU+u2QdKjYc6aqOZPZ6uxtCF6a9i/hzKKoQsv+WeuWsOs IzfzEHHdeHPMwnDwgCPUHkqUJQTHsfhYwS97EXw9hL/snXmE3VUySDgqoXQgYKvwSp i2QpL2Gi0NN/6RA2lWNijCSam/rjndbaTy1nCXy4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Boris Burkov , Anand Jain , David Sterba , Sasha Levin Subject: [PATCH 6.1 103/236] btrfs: return accurate error code on open failure in open_fs_devices() Date: Tue, 14 May 2024 12:17:45 +0200 Message-ID: <20240514101024.279955272@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101020.320785513@linuxfoundation.org> References: <20240514101020.320785513@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anand Jain [ Upstream commit 2f1aeab9fca1a5f583be1add175d1ee95c213cfa ] When attempting to exclusive open a device which has no exclusive open permission, such as a physical device associated with the flakey dm device, the open operation will fail, resulting in a mount failure. In this particular scenario, we erroneously return -EINVAL instead of the correct error code provided by the bdev_open_by_path() function, which is -EBUSY. Fix this, by returning error code from the bdev_open_by_path() function. With this correction, the mount error message will align with that of ext4 and xfs. Reviewed-by: Boris Burkov Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ab5d410d560e7..a92069fbc0287 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1233,25 +1233,32 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, struct btrfs_device *device; struct btrfs_device *latest_dev = NULL; struct btrfs_device *tmp_device; + int ret = 0; flags |= FMODE_EXCL; list_for_each_entry_safe(device, tmp_device, &fs_devices->devices, dev_list) { - int ret; + int ret2; - ret = btrfs_open_one_device(fs_devices, device, flags, holder); - if (ret == 0 && + ret2 = btrfs_open_one_device(fs_devices, device, flags, holder); + if (ret2 == 0 && (!latest_dev || device->generation > latest_dev->generation)) { latest_dev = device; - } else if (ret == -ENODATA) { + } else if (ret2 == -ENODATA) { fs_devices->num_devices--; list_del(&device->dev_list); btrfs_free_device(device); } + if (ret == 0 && ret2 != 0) + ret = ret2; } - if (fs_devices->open_devices == 0) + + if (fs_devices->open_devices == 0) { + if (ret) + return ret; return -EINVAL; + } fs_devices->opened = 1; fs_devices->latest_dev = latest_dev; -- 2.43.0