]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: unmap wrongly skipped wait for terminate
authorMykola Golub <mgolub@suse.com>
Mon, 2 Nov 2020 17:56:56 +0000 (17:56 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 10 Nov 2020 17:15:59 +0000 (17:15 +0000)
if netlink disconnect succeeded.

Also make sure wait_for_terminate returns 0 on success.

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

index 01be6ce0be7a9155f935efd069fa150ca523da71..edec26932b5b93466fef8c1af296a096b2859f52 100644 (file)
@@ -1479,7 +1479,7 @@ static int wait_for_terminate(int pid, int timeout)
     if (errno == ENOSYS) {
       return wait_for_terminate_legacy(pid, timeout);
     }
-    if (errno == -ESRCH) {
+    if (errno == ESRCH) {
       return 0;
     }
     int r = -errno;
@@ -1499,6 +1499,8 @@ static int wait_for_terminate(int pid, int timeout)
     cerr << "rbd-nbd: failed to poll rbd-nbd process: " << cpp_strerror(r)
          << std::endl;
     goto done;
+  } else {
+    r = 0;
   }
 
   if ((poll_fds[0].revents & POLLIN) == 0) {
@@ -1730,34 +1732,39 @@ static int do_detach(Config *cfg)
 
 static int do_unmap(Config *cfg)
 {
-  int r, nbd;
-
   /*
    * The netlink disconnect call supports devices setup with netlink or ioctl,
    * so we always try that first.
    */
-  r = netlink_disconnect_by_path(cfg->devpath);
-  if (r != 1)
+  int r = netlink_disconnect_by_path(cfg->devpath);
+  if (r < 0) {
     return r;
-
-  nbd = open(cfg->devpath.c_str(), O_RDWR);
-  if (nbd < 0) {
-    cerr << "rbd-nbd: failed to open device: " << cfg->devpath << std::endl;
-    return nbd;
   }
 
-  r = ioctl(nbd, NBD_DISCONNECT);
-  if (r < 0) {
+  if (r == 1) {
+    int nbd = open(cfg->devpath.c_str(), O_RDWR);
+    if (nbd < 0) {
+      cerr << "rbd-nbd: failed to open device: " << cfg->devpath << std::endl;
+      return nbd;
+    }
+
+    r = ioctl(nbd, NBD_DISCONNECT);
+    if (r < 0) {
       cerr << "rbd-nbd: the device is not used" << std::endl;
-  }
+    }
 
-  close(nbd);
+    close(nbd);
 
-  if (r < 0) {
-    return r;
+    if (r < 0) {
+      return r;
+    }
   }
 
-  return wait_for_terminate(cfg->pid, cfg->reattach_timeout);
+  if (cfg->pid > 0) {
+    r = wait_for_terminate(cfg->pid, cfg->reattach_timeout);
+  }
+
+  return 0;
 }
 
 static int parse_imgpath(const std::string &imgpath, Config *cfg,