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 1FEC46A32F; Sun, 7 Apr 2024 13:12:03 +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=1712495524; cv=none; b=TWCaENQ982t00saPwsqLnWSWGiV+w7/tt99Q6JXoaNZBVt/Etu+roekzyBL95IkFfxss5NR0kiUquV22gmm7kc0vZmstIb52KSPjp4WjbxZZzMs4mspXfmzGslr3yDY4c0woSWSYnq2+CD8tjuvjDfZVv3L4JylLGh0ynJSr8sw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495524; c=relaxed/simple; bh=D9JxBqtKVRixS5B3UdgLpo0BGeo7AEJcLnmwxoUmCmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5SD4wp5vEzrgiVp50iEcH5r4N47M0uDimFhOgFhOv/371EXKmwuJ5GXfPKTasBiHbKh2uB9xaEjjdbT/VeKv6FnU68574fPmRY26/h6f2M9xIV18iZn+4UO06hKdRIgzQmnfzYbO+aEdvBtxecYU6lNot4y4PPEUpiN+GnW7BY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YYQCOdJT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YYQCOdJT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB09BC43390; Sun, 7 Apr 2024 13:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712495523; bh=D9JxBqtKVRixS5B3UdgLpo0BGeo7AEJcLnmwxoUmCmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YYQCOdJTG3bZCUgCau8oT/adtFuXpTTNJoq+LEmH7SoMi5kkkqyTHAn7db8dvkifi WWNyWK00Y33uM9qpBvGCRfe1s7EujtubwIUdQhUYI7OKQP4355LHqpK41U1tR24bv5 TkfCVrF/tI67U+CjIyaev+h/kVTi4X/yKFiNruEAZz5l/XLKnjT75WzGjebsJAkvzO smUeXcgrL/W8DlV2byNbAdccs0MwbVQuF4wyhLFMUMONPZkBo9fphYr3lb+hx55d4X qHlBjIx4KU9gI1yR/3dB8PbcqLWWUWVh6PAIUMohDPY8lESMKv6boYcaZ0K5s3MbT5 sgLgH7SL+YCXA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anand Jain , Boris Burkov , David Sterba , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 19/25] btrfs: return accurate error code on open failure in open_fs_devices() Date: Sun, 7 Apr 2024 09:11:07 -0400 Message-ID: <20240407131130.1050321-19-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240407131130.1050321-1-sashal@kernel.org> References: <20240407131130.1050321-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.4 Content-Transfer-Encoding: 8bit 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 d67785be2c778..847cedb838dea 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1172,23 +1172,30 @@ 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; 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