]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: call udevadm settle on map/unmap
authorDan Mick <dan.mick@inktank.com>
Fri, 11 Jan 2013 02:44:44 +0000 (18:44 -0800)
committerDan Mick <dan.mick@inktank.com>
Fri, 11 Jan 2013 22:28:50 +0000 (14:28 -0800)
When we map/unmap devices, udev gets called to manage device nodes;
this will allow the command to wait for those manipulations to complete,
particularly for test runs, so that the device tree is stable by the
time the command exits.

--no-settle is also provided to avoid this behavior if desired (say,
for a series of 'map' commands, perhaps the user wants to wait for
settling only on the last of the series).

Fixes: #3635
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Alex Elder <elder@inktank.com>
src/rbd.cc
src/test/cli/rbd/help.t

index 9aaca568208cb2a767a54513c55b18c0a500b2da..c2c61811ce7e1dd2b0eec982942dd5afee0dace8 100644 (file)
@@ -64,6 +64,8 @@
 static string dir_oid = RBD_DIRECTORY;
 static string dir_info_oid = RBD_INFO;
 
+bool udevadm_settle = true;
+
 void usage()
 {
   cout << 
@@ -127,7 +129,8 @@ void usage()
 "                               format 2 supports cloning\n"
 "  --id <username>              rados user (without 'client.' prefix) to authenticate as\n"
 "  --keyfile <path>             file containing secret key for use with cephx\n"
-"  --shared <tag>               take a shared (rather than exclusive) lock\n";
+"  --shared <tag>               take a shared (rather than exclusive) lock\n"
+"  --no-settle                 do not wait for udevadm to settle on map/unmap\n";
 }
 
 static string feature_str(uint64_t features)
@@ -1206,6 +1209,10 @@ static int do_kernel_add(const char *poolname, const char *imgname, const char *
   r = safe_write(fd, add.c_str(), add.size());
   close(fd);
 
+  // let udevadm do its job before we return
+  if (udevadm_settle)
+    system("/sbin/udevadm settle");
+
   return r;
 }
 
@@ -1397,6 +1404,11 @@ static int do_kernel_rm(const char *dev)
   }
 
   r = close(fd);
+
+  // let udevadm finish, if present
+  if (udevadm_settle)
+    system("/sbin/udevadm settle");
+
   if (r < 0)
     r = -errno;
   return r;
@@ -1620,6 +1632,8 @@ int main(int argc, const char **argv)
       imgname = strdup(val.c_str());
     } else if (ceph_argparse_witharg(args, i, &val, "--shared", (char *)NULL)) {
       lock_tag = strdup(val.c_str());
+    } else if (ceph_argparse_flag(args, i, "--no-settle", (char *)NULL)) {
+      udevadm_settle = false;
     } else {
       ++i;
     }
index e1f6a2f9ecd5263c4b299868ef59e0cb208b7926..5eb838540afa14968b77825308f291803f43fb82 100644 (file)
@@ -60,3 +60,4 @@
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
     --shared <tag>               take a shared (rather than exclusive) lock
+    --no-settle                         do not wait for udevadm to settle on map/unmap