mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
nbd: Improve server handling of shutdown requests
NBD commit 6d34500b clarified how clients and servers are supposed to behave before closing a connection. It added NBD_REP_ERR_SHUTDOWN (for the server to announce it is about to go away during option haggling, so the client should quit sending NBD_OPT_* other than NBD_OPT_ABORT) and ESHUTDOWN (for the server to announce it is about to go away during transmission, so the client should quit sending NBD_CMD_* other than NBD_CMD_DISC). It also clarified that NBD_OPT_ABORT gets a reply, while NBD_CMD_DISC does not. This patch merely adds the missing reply to NBD_OPT_ABORT and teaches the client to recognize server errors. Actually teaching the server to send NBD_REP_ERR_SHUTDOWN or ESHUTDOWN would require knowing that the server has been requested to shut down soon (maybe we could do that by installing a SIGINT handler in qemu-nbd, which transitions from RUNNING to a new state that waits for the client to react, rather than just out-right quitting - but that's a bigger task for another day). Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1476469998-28592-15-git-send-email-eblake@redhat.com> [Move dummy ESHUTDOWN to include/qemu/osdep.h. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
8b34a9dbc3
commit
b6f5d3b573
5 changed files with 41 additions and 4 deletions
10
nbd/server.c
10
nbd/server.c
|
@ -39,6 +39,8 @@ static int system_errno_to_nbd_errno(int err)
|
|||
case EFBIG:
|
||||
case ENOSPC:
|
||||
return NBD_ENOSPC;
|
||||
case ESHUTDOWN:
|
||||
return NBD_ESHUTDOWN;
|
||||
case EINVAL:
|
||||
default:
|
||||
return NBD_EINVAL;
|
||||
|
@ -527,6 +529,10 @@ static int nbd_negotiate_options(NBDClient *client)
|
|||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
/* Let the client keep trying, unless they asked to quit */
|
||||
if (clientflags == NBD_OPT_ABORT) {
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (fixedNewstyle) {
|
||||
|
@ -539,6 +545,10 @@ static int nbd_negotiate_options(NBDClient *client)
|
|||
break;
|
||||
|
||||
case NBD_OPT_ABORT:
|
||||
/* NBD spec says we must try to reply before
|
||||
* disconnecting, but that we must also tolerate
|
||||
* guests that don't wait for our reply. */
|
||||
nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, clientflags);
|
||||
return -EINVAL;
|
||||
|
||||
case NBD_OPT_EXPORT_NAME:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue