From be4f1126467e93d0984628a60d860cfa1ab1a771 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 9 Nov 2020 09:08:39 +0000 Subject: [PATCH] rbd-nbd: try to disconnect before terminating when read from nbd socket returned error Signed-off-by: Mykola Golub --- src/tools/rbd_nbd/rbd-nbd.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 713a0b83b63..11ccdf0e4b4 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -181,6 +181,7 @@ static EventSocket terminate_event_sock; static int parse_args(vector& args, std::ostream *err_msg, Config *cfg); +static int netlink_disconnect(int index); static int netlink_resize(int nbd_index, uint64_t size); static int run_quiesce_hook(const std::string &quiesce_hook, @@ -361,7 +362,7 @@ private: } r = -errno; derr << "failed to poll nbd: " << cpp_strerror(r) << dendl; - goto signal; + goto error; } if ((poll_fds[1].revents & POLLIN) != 0) { @@ -378,7 +379,7 @@ private: if (r < 0) { derr << "failed to read nbd request header: " << cpp_strerror(r) << dendl; - goto signal; + goto error; } if (ctx->request.magic != htonl(NBD_REQUEST_MAGIC)) { @@ -409,7 +410,7 @@ private: if (r < 0) { derr << *ctx << ": failed to read nbd request data: " << cpp_strerror(r) << dendl; - goto signal; + goto error; } ctx->data.push_back(ptr); break; @@ -439,6 +440,13 @@ private: goto signal; } } +error: + { + int r = netlink_disconnect(nbd_index); + if (r == 1) { + ioctl(nbd, NBD_DISCONNECT); + } + } signal: std::lock_guard l{lock}; terminated = true; -- 2.39.5