]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add support for single-major device number allocation scheme
authorIlya Dryomov <ilya.dryomov@inktank.com>
Fri, 13 Dec 2013 15:40:52 +0000 (17:40 +0200)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Fri, 13 Dec 2013 15:40:52 +0000 (17:40 +0200)
With the preparatory commits ("rbd: match against wholedisk device
numbers on unmap" and "rbd: match against both major and minor on unmap
on kernels >= 3.14") in, this amounts to chosing to work with new rbd
bus interfaces (/sys/bus/rbd/{add,remove}_single_major) if they are
available, instead of the old ones (/sys/bus/rbd/{add,remove}).

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
src/rbd.cc

index 7264489efe4395660b006bf198dd868f922378b8..5de6d85134e3337171991235e996a043ae20a464 100644 (file)
@@ -1705,8 +1705,19 @@ static int do_kernel_add(const char *poolname, const char *imgname,
     }
   }
 
-  // write to /sys/bus/rbd/add
-  int fd = open("/sys/bus/rbd/add", O_WRONLY);
+  // 'add' interface is deprecated, see if 'add_single_major' is
+  // available and use it if it is
+  //
+  // ('add' and 'add_single_major' interfaces are identical, except
+  // that if rbd kernel module is new enough and is configured to use
+  // single-major scheme, 'add' is disabled in order to prevent old
+  // userspace from doing weird things at unmap time)
+  const char *fname = "/sys/bus/rbd/add_single_major";
+  if (stat(fname, &sb)) {
+    fname = "/sys/bus/rbd/add";
+  }
+
+  int fd = open(fname, O_WRONLY);
   if (fd < 0) {
     r = -errno;
     if (r == -ENOENT) {
@@ -1988,7 +1999,14 @@ static int do_kernel_rm(const char *dev)
     }
   }
 
-  int fd = open("/sys/bus/rbd/remove", O_WRONLY);
+  // see comment in do_kernel_add(), same goes for 'remove' vs
+  // 'remove_single_major'
+  const char *fname = "/sys/bus/rbd/remove_single_major";
+  if (stat(fname, &sbuf)) {
+    fname = "/sys/bus/rbd/remove";
+  }
+
+  int fd = open(fname, O_WRONLY);
   if (fd < 0) {
     return -errno;
   }