Skip to content

Commit 1eebb7b

Browse files
committed
rbd_nbd: fix resize of images mapped using netlink
Include device identifier or cookie in the message sent to the kernel to resize images mapped to NBD devices using netlink. Otherwise, netlink_resize() fails and the size of the device isn't updated. Fixes: https://tracker.ceph.com/issues/64139 Signed-off-by: Ramana Raja <[email protected]>
1 parent b5d0337 commit 1eebb7b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

qa/workunits/rbd/rbd-nbd.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,11 @@ provisioned=`rbd -p ${POOL} --format xml du ${IMAGE} |
202202
used=`rbd -p ${POOL} --format xml du ${IMAGE} |
203203
$XMLSTARLET sel -t -m "//stats/images/image/used_size" -v .`
204204
[ "${used}" -lt "${provisioned}" ]
205+
unmap_device ${DEV} ${PID}
205206

206207
# resize test
208+
DEV=`_sudo rbd device -t nbd -o try-netlink map ${POOL}/${IMAGE}`
209+
get_pid ${POOL}
207210
devname=$(basename ${DEV})
208211
blocks=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
209212
test -n "${blocks}"
@@ -216,9 +219,9 @@ rbd resize ${POOL}/${IMAGE} --allow-shrink --size ${SIZE}M
216219
blocks2=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
217220
test -n "${blocks2}"
218221
test ${blocks2} -eq ${blocks}
222+
unmap_device ${DEV} ${PID}
219223

220224
# read-only option test
221-
unmap_device ${DEV} ${PID}
222225
DEV=`_sudo rbd --device-type nbd map --read-only ${POOL}/${IMAGE}`
223226
PID=$(rbd device --device-type nbd list | awk -v pool=${POOL} -v img=${IMAGE} -v dev=${DEV} \
224227
'$2 == pool && $3 == img && $5 == dev {print $1}')

src/tools/rbd_nbd/rbd-nbd.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static EventSocket terminate_event_sock;
194194
static int parse_args(vector<const char*>& args, std::ostream *err_msg,
195195
Config *cfg);
196196
static int netlink_disconnect(int index);
197-
static int netlink_resize(int nbd_index, uint64_t size);
197+
static int netlink_resize(int nbd_index, const std::string& cookie,
198+
uint64_t size);
198199

199200
static int run_quiesce_hook(const std::string &quiesce_hook,
200201
const std::string &devpath,
@@ -744,6 +745,7 @@ class NBDWatchCtx : public librbd::UpdateWatchCtx
744745
ceph::mutex lock = ceph::make_mutex("NBDWatchCtx::Locker");
745746
bool notify = false;
746747
bool terminated = false;
748+
std::string cookie;
747749

748750
bool wait_notify() {
749751
dout(10) << __func__ << dendl;
@@ -779,11 +781,11 @@ class NBDWatchCtx : public librbd::UpdateWatchCtx
779781
<< dendl;
780782
}
781783
if (use_netlink) {
782-
ret = netlink_resize(nbd_index, new_size);
784+
ret = netlink_resize(nbd_index, cookie, new_size);
783785
} else {
784786
ret = ioctl(fd, NBD_SET_SIZE, new_size);
785787
if (ret < 0) {
786-
derr << "resize failed: " << cpp_strerror(errno) << dendl;
788+
derr << "ioctl resize failed: " << cpp_strerror(errno) << dendl;
787789
}
788790
}
789791
if (!ret) {
@@ -805,13 +807,15 @@ class NBDWatchCtx : public librbd::UpdateWatchCtx
805807
bool _use_netlink,
806808
librados::IoCtx &_io_ctx,
807809
librbd::Image &_image,
808-
unsigned long _size)
810+
unsigned long _size,
811+
std::string _cookie)
809812
: fd(_fd)
810813
, nbd_index(_nbd_index)
811814
, use_netlink(_use_netlink)
812815
, io_ctx(_io_ctx)
813816
, image(_image)
814817
, size(_size)
818+
, cookie(std::move(_cookie))
815819
{
816820
handle_notify_thread = make_named_thread("rbd_handle_notify",
817821
&NBDWatchCtx::handle_notify_entry,
@@ -1319,7 +1323,8 @@ static int netlink_disconnect_by_path(const std::string& devpath)
13191323
return netlink_disconnect(index);
13201324
}
13211325

1322-
static int netlink_resize(int nbd_index, uint64_t size)
1326+
static int netlink_resize(int nbd_index, const std::string& cookie,
1327+
uint64_t size)
13231328
{
13241329
struct nl_sock *sock;
13251330
struct nl_msg *msg;
@@ -1347,6 +1352,8 @@ static int netlink_resize(int nbd_index, uint64_t size)
13471352

13481353
NLA_PUT_U32(msg, NBD_ATTR_INDEX, nbd_index);
13491354
NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size);
1355+
if (!cookie.empty())
1356+
NLA_PUT_STRING(msg, NBD_ATTR_BACKEND_IDENTIFIER, cookie.c_str());
13501357

13511358
ret = nl_send_sync(sock, msg);
13521359
if (ret < 0) {
@@ -1896,7 +1903,7 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
18961903
uint64_t handle;
18971904

18981905
NBDWatchCtx watch_ctx(nbd, nbd_index, use_netlink, io_ctx, image,
1899-
info.size);
1906+
info.size, cfg->cookie);
19001907
r = image.update_watch(&watch_ctx, &handle);
19011908
if (r < 0)
19021909
goto close_nbd;

0 commit comments

Comments
 (0)