Skip to content

Commit

Permalink
Merge pull request #1333 from ejoerns/nbd-graceful-shutdown
Browse files Browse the repository at this point in the history
src/nbd: manually trigger NBD disconnect
  • Loading branch information
jluebbe committed Jan 22, 2024
2 parents 7efe531 + b376f54 commit 793485b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,16 @@ gboolean r_nbd_stop_server(RaucNBDServer *nbd_srv, GError **error)
g_message("nbd server stopping");

if (nbd_srv->sock >= 0) {
struct nbd_request request = {0};

/* If socket is still active, manually invoke NBD_CMD_DISC
* first, to trigger a graceful shutdown of the NBD server. */
request.magic = GUINT32_TO_BE(NBD_REQUEST_MAGIC);
request.type = GUINT32_TO_BE(NBD_CMD_DISC);
request.len = 0;
if (!r_write_exact(nbd_srv->sock, (guint8*)&request, sizeof(request), NULL))
g_error("failed to send nbd disconnect request");

g_close(nbd_srv->sock, NULL);
nbd_srv->sock = -1;
}
Expand Down

0 comments on commit 793485b

Please sign in to comment.