From: Or Ozeri Date: Wed, 20 Jan 2021 13:36:10 +0000 (+0200) Subject: tools/rbd-nbd: change block size to 4K for LUKS2 images X-Git-Tag: v16.1.0^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=93c826fb668826a035d5207dee2483f82bbf2666;p=ceph.git tools/rbd-nbd: change block size to 4K for LUKS2 images 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 (cherry picked from commit 988039f6ec9210d13f7bdaee9d73ac009c0ceb91) --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index c692e0ce0896..3a13ff82fb1c 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -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; }