]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rbd-nbd: change block size to 4K for LUKS2 images
authorOr Ozeri <oro@il.ibm.com>
Wed, 20 Jan 2021 13:36:10 +0000 (15:36 +0200)
committerJason Dillaman <dillaman@redhat.com>
Thu, 21 Jan 2021 20:06:36 +0000 (15:06 -0500)
This commit sets the NBD device block size to 4K for images encrypted using LUKS2 (whose sector size is by default 4K(.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
(cherry picked from commit 988039f6ec9210d13f7bdaee9d73ac009c0ceb91)

src/tools/rbd_nbd/rbd-nbd.cc

index c692e0ce0896410d202c36031bfab9ff5c418443..3a13ff82fb1ccaffd15b8e54512d45d02f463c1d 100644 (file)
@@ -1009,7 +1009,8 @@ static int parse_nbd_index(const std::string& devpath)
   return index;
 }
 
-static int try_ioctl_setup(Config *cfg, int fd, uint64_t size, uint64_t flags)
+static int try_ioctl_setup(Config *cfg, int fd, uint64_t size,
+                           uint64_t blksize, uint64_t flags)
 {
   int index = 0, r;
 
@@ -1072,7 +1073,7 @@ static int try_ioctl_setup(Config *cfg, int fd, uint64_t size, uint64_t flags)
     }
   }
 
-  r = ioctl(nbd, NBD_SET_BLKSIZE, RBD_NBD_BLKSIZE);
+  r = ioctl(nbd, NBD_SET_BLKSIZE, blksize);
   if (r < 0) {
     r = -errno;
     cerr << "rbd-nbd: NBD_SET_BLKSIZE failed" << std::endl;
@@ -1560,6 +1561,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
   int read_only = 0;
   unsigned long flags;
   unsigned long size;
+  unsigned long blksize = RBD_NBD_BLKSIZE;
   bool use_netlink;
 
   int fd[2];
@@ -1677,6 +1679,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
         opts.passphrase = passphrase;
         r = image.encryption_load(
                 RBD_ENCRYPTION_FORMAT_LUKS2, &opts, sizeof(opts));
+        blksize = 4096;
         break;
       }
       default:
@@ -1728,7 +1731,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
   }
 
   if (!use_netlink) {
-    r = try_ioctl_setup(cfg, fd[0], size, flags);
+    r = try_ioctl_setup(cfg, fd[0], size, blksize, flags);
     if (r < 0)
       goto free_server;
   }