From: Ilya Dryomov Date: Mon, 15 Mar 2021 19:30:07 +0000 (+0100) Subject: krbd: check device node accessibility only if we actually mapped X-Git-Tag: v16.2.0~92^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=161d05ca0baf6ef38e7d9b3453dc3e2627d11693;p=ceph.git 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) --- 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,