]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-nbd: try to disconnect before terminating
authorMykola Golub <mgolub@suse.com>
Mon, 9 Nov 2020 09:08:39 +0000 (09:08 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 10 Nov 2020 17:16:00 +0000 (17:16 +0000)
when read from nbd socket returned error

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/tools/rbd_nbd/rbd-nbd.cc

index 713a0b83b63caf3c083782a3a9653222b5f5b917..11ccdf0e4b4db5a35538560a99f7f3cfe0b1ec9c 100644 (file)
@@ -181,6 +181,7 @@ static EventSocket terminate_event_sock;
 
 static int parse_args(vector<const char*>& 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;