rbd-nbd: map using netlink interface by default

Mapping rbd images to nbd devices using ioctl interface is not
robust. It was discovered that the device size or the md5 checksum
of the nbd device was incorrect immediately after mapping using
ioctl method. When using the nbd netlink interface to map RBD images
the issue was not encountered. Switch to using nbd netlink interface
for mapping.

Fixes: https://tracker.ceph.com/issues/64063
Signed-off-by: Ramana Raja <rraja@redhat.com>
This commit is contained in:
Ramana Raja 2024-01-17 13:24:36 -05:00
parent f7b52fc712
commit fcbf7367d2
3 changed files with 21 additions and 21 deletions

View File

@ -110,6 +110,9 @@ CephFS: Disallow delegating preallocated inode ranges to clients. Config
and valid), diff-iterate is now guaranteed to execute locally if exclusive
lock is available. This brings a dramatic performance improvement for QEMU
live disk synchronization and backup use cases.
* RBD: The ``try-netlink`` mapping option for rbd-nbd has become the default
and is now deprecated. If the NBD netlink interface is not supported by the
kernel, then the mapping is retried using the legacy ioctl interface.
>=18.0.0

View File

@ -205,6 +205,7 @@ used=`rbd -p ${POOL} --format xml du ${IMAGE} |
unmap_device ${DEV} ${PID}
# resize test
# also test that try-netlink option is accepted for compatibility
DEV=`_sudo rbd device -t nbd -o try-netlink map ${POOL}/${IMAGE}`
get_pid ${POOL}
devname=$(basename ${DEV})
@ -391,7 +392,7 @@ cat ${LOG_FILE}
expect_false grep 'quiesce failed' ${LOG_FILE}
# test detach/attach
OUT=`_sudo rbd device --device-type nbd --options try-netlink,show-cookie map ${POOL}/${IMAGE}`
OUT=`_sudo rbd device --device-type nbd --show-cookie map ${POOL}/${IMAGE}`
read DEV COOKIE <<< "${OUT}"
get_pid ${POOL}
_sudo mount ${DEV} ${TEMPDIR}/mnt
@ -419,7 +420,7 @@ _sudo umount ${TEMPDIR}/mnt
unmap_device ${DEV} ${PID}
# if kernel supports cookies
if [ -n "${COOKIE}" ]; then
OUT=`_sudo rbd device --device-type nbd --show-cookie --cookie "abc de" --options try-netlink map ${POOL}/${IMAGE}`
OUT=`_sudo rbd device --device-type nbd --show-cookie --cookie "abc de" map ${POOL}/${IMAGE}`
read DEV ANOTHER_COOKIE <<< "${OUT}"
get_pid ${POOL}
test "${ANOTHER_COOKIE}" = "abc de"
@ -429,7 +430,7 @@ DEV=
# test detach/attach with --snap-id
SNAPID=`rbd snap ls ${POOL}/${IMAGE} | awk '$2 == "snap" {print $1}'`
OUT=`_sudo rbd device --device-type nbd --options try-netlink,show-cookie map --snap-id ${SNAPID} ${POOL}/${IMAGE}`
OUT=`_sudo rbd device --device-type nbd --show-cookie map --snap-id ${SNAPID} ${POOL}/${IMAGE}`
read DEV COOKIE <<< "${OUT}"
get_pid ${POOL}
_sudo rbd device detach ${POOL}/${IMAGE} --snap-id ${SNAPID} --device-type nbd

View File

@ -106,7 +106,6 @@ struct Config {
bool quiesce = false;
bool readonly = false;
bool set_max_part = false;
bool try_netlink = false;
bool show_cookie = false;
std::string poolname;
@ -166,7 +165,6 @@ static void usage()
<< " --read-only Map read-only\n"
<< " --reattach-timeout <sec> Set nbd re-attach timeout\n"
<< " (default: " << Config().reattach_timeout << ")\n"
<< " --try-netlink Use the nbd netlink interface\n"
<< " --show-cookie Show device cookie\n"
<< " --cookie Specify device cookie\n"
<< " --snap-id <snap-id> Specify snapshot by ID instead of by name\n"
@ -1682,7 +1680,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
unsigned long flags;
unsigned long size;
unsigned long blksize = RBD_NBD_BLKSIZE;
bool use_netlink;
bool use_netlink = true;
int fd[2];
@ -1859,20 +1857,17 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
server = start_server(fd[1], image, cfg);
use_netlink = cfg->try_netlink || reconnect;
if (use_netlink) {
// generate when the cookie is not supplied at CLI
if (!reconnect && cfg->cookie.empty()) {
uuid_d uuid_gen;
uuid_gen.generate_random();
cfg->cookie = uuid_gen.to_string();
}
r = try_netlink_setup(cfg, fd[0], size, flags, reconnect);
if (r < 0) {
goto free_server;
} else if (r == 1) {
use_netlink = false;
}
// generate when the cookie is not supplied at CLI
if (!reconnect && cfg->cookie.empty()) {
uuid_d uuid_gen;
uuid_gen.generate_random();
cfg->cookie = uuid_gen.to_string();
}
r = try_netlink_setup(cfg, fd[0], size, flags, reconnect);
if (r < 0) {
goto free_server;
} else if (r == 1) {
use_netlink = false;
}
if (!use_netlink) {
@ -2216,7 +2211,8 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
} else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) {
cfg->pretty_format = true;
} else if (ceph_argparse_flag(args, i, "--try-netlink", (char *)NULL)) {
cfg->try_netlink = true;
// netlink used by default. option not required anymore.
// accept for compatibility.
} else if (ceph_argparse_flag(args, i, "--show-cookie", (char *)NULL)) {
cfg->show_cookie = true;
} else if (ceph_argparse_witharg(args, i, &cfg->cookie, "--cookie", (char *)NULL)) {