@@ -194,7 +194,8 @@ static EventSocket terminate_event_sock;
194194static int parse_args (vector<const char *>& args, std::ostream *err_msg,
195195 Config *cfg);
196196static 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
199200static 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