From 8f18a482029642a8c5081711b2df36f1123e3c96 Mon Sep 17 00:00:00 2001 From: Li Wang Date: Thu, 7 Dec 2017 22:03:45 +0800 Subject: [PATCH] rbd-nbd: fix ebusy when do map When doing rbd-nbd map, if the Ceph service is not available, the codes will wait on rados.connect(), unless killing the process. In that case, the close_nbd logic is skipped with NBD_CLEAR_SOCK ioctl not called. On the CentOS 7 kernel, it leaves nbd->file not cleared, which causes the subsequent map requests return EBUSY, this patch fixes it by connecting Ceph first prior to calling NBD_SET_SOCK ioctl Fixes: http://tracker.ceph.com/issues/23528 Signed-off-by: Li Wang (cherry picked from commit ab77dcc0170c0d63795fe0d50427cda630bfd593) Conflicts: src/tools/rbd_nbd/rbd-nbd.cc: - Resolved for cfg changes & devpath.empty() - Removed cfg->exclusive condition as exclusive bool not available --- src/tools/rbd_nbd/rbd-nbd.cc | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 51046eba26ed5..07d6561a6b3f0 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -564,6 +564,32 @@ static int do_map(int argc, const char *argv[]) goto close_ret; } + r = rados.init_with_context(g_ceph_context); + if (r < 0) + goto close_fd; + + r = rados.connect(); + if (r < 0) + goto close_fd; + + r = rados.ioctx_create(poolname.c_str(), io_ctx); + if (r < 0) + goto close_fd; + + r = rbd.open(io_ctx, image, imgname.c_str()); + if (r < 0) + goto close_fd; + + if (!snapname.empty()) { + r = image.snap_set(snapname.c_str()); + if (r < 0) + goto close_fd; + } + + r = image.stat(info, sizeof(info)); + if (r < 0) + goto close_fd; + if (devpath.empty()) { char dev[64]; bool try_load_module = true; @@ -630,32 +656,6 @@ static int do_map(int argc, const char *argv[]) if (!snapname.empty() || readonly) flags |= NBD_FLAG_READ_ONLY; - r = rados.init_with_context(g_ceph_context); - if (r < 0) - goto close_nbd; - - r = rados.connect(); - if (r < 0) - goto close_nbd; - - r = rados.ioctx_create(poolname.c_str(), io_ctx); - if (r < 0) - goto close_nbd; - - r = rbd.open(io_ctx, image, imgname.c_str()); - if (r < 0) - goto close_nbd; - - if (!snapname.empty()) { - r = image.snap_set(snapname.c_str()); - if (r < 0) - goto close_nbd; - } - - r = image.stat(info, sizeof(info)); - if (r < 0) - goto close_nbd; - r = ioctl(nbd, NBD_SET_BLKSIZE, RBD_NBD_BLKSIZE); if (r < 0) { r = -errno; -- 2.39.5