Stop gracefully on NBD_CMD_DISC instead of just exit(0)

This commit is contained in:
Vitaliy Filippov
2026-06-17 12:46:03 +03:00
parent 0e528ca8f3
commit 04c2f8d408
+4 -3
View File
@@ -348,6 +348,7 @@ protected:
int read_ready = 0; int read_ready = 0;
msghdr read_msg = { 0 }, send_msg = { 0 }; msghdr read_msg = { 0 }, send_msg = { 0 };
iovec read_iov = { 0 }; iovec read_iov = { 0 };
bool stop = false;
std::string logfile = "/dev/null"; std::string logfile = "/dev/null";
@@ -678,8 +679,7 @@ help:
}; };
ringloop->register_consumer(&consumer); ringloop->register_consumer(&consumer);
// Add FD to epoll // Add FD to epoll
bool stop = false; epmgr->tfd->set_fd_handler(sockfd[0], false, [this](int peer_fd, int epoll_events)
epmgr->tfd->set_fd_handler(sockfd[0], false, [this, &stop](int peer_fd, int epoll_events)
{ {
if (epoll_events & EPOLLRDHUP) if (epoll_events & EPOLLRDHUP)
{ {
@@ -1118,7 +1118,8 @@ protected:
{ {
// Disconnect // Disconnect
close(nbd_fd); close(nbd_fd);
exit(0); stop = true;
return;
} }
if (be32toh(cur_req.magic) != NBD_REQUEST_MAGIC || if (be32toh(cur_req.magic) != NBD_REQUEST_MAGIC ||
req_type != NBD_CMD_READ && req_type != NBD_CMD_WRITE && req_type != NBD_CMD_FLUSH) req_type != NBD_CMD_READ && req_type != NBD_CMD_WRITE && req_type != NBD_CMD_FLUSH)