From: Ilya Dryomov Date: Fri, 13 Dec 2013 15:40:52 +0000 (+0200) Subject: rbd: add support for single-major device number allocation scheme X-Git-Tag: v0.75~113^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8a473bcc9910eea56f3d8841082c54a6c6bbb9fb;p=ceph.git rbd: add support for single-major device number allocation scheme 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 --- diff --git a/src/rbd.cc b/src/rbd.cc index 7264489efe43..5de6d85134e3 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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; }