diff --git a/src/client/nbd_proxy.cpp b/src/client/nbd_proxy.cpp index 26b6c6f9..2880f709 100644 --- a/src/client/nbd_proxy.cpp +++ b/src/client/nbd_proxy.cpp @@ -759,6 +759,12 @@ help: ringloop->loop(); ringloop->wait(); } + if (watch && nbd_fd < 0) + { + // The device is disconnected and may already be mapped by someone else + cli->st_cli->close_watch(watch); + watch = NULL; + } cli->flush(); } diff --git a/src/client/ublk_server.cpp b/src/client/ublk_server.cpp index dabf2702..ec53cc75 100644 --- a/src/client/ublk_server.cpp +++ b/src/client/ublk_server.cpp @@ -87,6 +87,7 @@ protected: cluster_client_t *cli = NULL; inode_watch_t *watch = NULL; bool size_changed = false; + bool started = false; std::string logfile = "/dev/null"; std::string pidfile; @@ -361,12 +362,14 @@ help: } consumer.loop = [this]() { - if (size_changed) + // Not before START_DEV or after stop: UPDATE_SIZE on a device without a disk crashes unpatched 6.16-6.19 kernels + if (size_changed && started && !stop) try_resize(); submit_postponed(); }; ringloop->register_consumer(&consumer); start_device(recover); + started = true; if (pidfile != "") write_pid(); if (bg) @@ -700,7 +703,7 @@ protected: { return; } - size_changed = true; + size_changed = false; ring_data_t* data = ((ring_data_t*)sqe->user_data); data->callback = [this, size = device_size](ring_data_t *data) { @@ -709,6 +712,7 @@ protected: fprintf(stderr, "Failed to update size of /dev/ublkb%d to %ju bytes: %s (code %d)\n", ublk_dev.dev_id, size, strerror(-data->res), data->res); } }; + ringloop->submit(); } void map_ublk_queue()