From 15527ae8faa853ef3850604d55beb224cb79c559 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Mon, 15 Mar 2021 20:30:07 +0100 Subject: [PATCH] krbd: check device node accessibility only if we actually mapped Fix a braino that came with commit f6854ac65d2a ("krbd: make sure the device node is accessible after the mapping"). Signed-off-by: Ilya Dryomov (cherry picked from commit 8330c9fa4e27204c768777afe45af0eeb273c835) --- src/krbd.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/krbd.cc b/src/krbd.cc index 88a50b38d546..1318512d6ca1 100644 --- a/src/krbd.cc +++ b/src/krbd.cc @@ -495,6 +495,9 @@ static int do_map(krbd_ctx *ctx, const krbd_spec& spec, const string& buf, close(fds[0]); close(fds[1]); + if (r < 0) + return r; + /* * Make sure our device node is there. This is intended to help * diagnose environments where "rbd map" is run from a container with @@ -504,6 +507,7 @@ static int do_map(krbd_ctx *ctx, const krbd_spec& spec, const string& buf, * and in some cases can even lead to data loss, depending on higher * level logic and orchestration layers involved. */ + ceph_assert(mapped); if (stat(pname->c_str(), &sb) < 0 || !S_ISBLK(sb.st_mode)) { std::cerr << "rbd: mapping succeeded but " << *pname << " is not accessible, is host /dev mounted?" << std::endl; @@ -518,7 +522,7 @@ static int do_map(krbd_ctx *ctx, const krbd_spec& spec, const string& buf, return -EINVAL; } - return r; + return 0; } static int map_image(struct krbd_ctx *ctx, const krbd_spec& spec, -- 2.47.3