mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-16 14:41:55 -06:00
nbd/server: Allow users to adjust handshake limit in QMP
Although defaulting the handshake limit to 10 seconds was a nice QoI
change to weed out intentionally slow clients, it can interfere with
integration testing done with manual NBD_OPT commands over 'nbdsh
--opt-mode'. Expose a QMP knob 'handshake-max-secs' to allow the user
to alter the timeout away from the default.
The parameter name here intentionally matches the spelling of the
constant added in commit fb1c2aaa98
, and not the command-line spelling
added in the previous patch for qemu-nbd; that's because in QMP,
longer names serve as good self-documentation, and unlike the command
line, machines don't have problems generating longer spellings.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-ID: <20250203222722.650694-6-eblake@redhat.com>
[eblake: s/max-secs/max-seconds/ in QMP]
Acked-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
This commit is contained in:
parent
617017f8dc
commit
ff12e6a5ff
4 changed files with 33 additions and 13 deletions
|
@ -402,8 +402,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbd_server_start(addr, NULL, NULL, NBD_DEFAULT_MAX_CONNECTIONS,
|
nbd_server_start(addr, NBD_DEFAULT_HANDSHAKE_MAX_SECS, NULL, NULL,
|
||||||
&local_err);
|
NBD_DEFAULT_MAX_CONNECTIONS, &local_err);
|
||||||
qapi_free_SocketAddress(addr);
|
qapi_free_SocketAddress(addr);
|
||||||
if (local_err != NULL) {
|
if (local_err != NULL) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
|
@ -28,6 +28,7 @@ typedef struct NBDConn {
|
||||||
|
|
||||||
typedef struct NBDServerData {
|
typedef struct NBDServerData {
|
||||||
QIONetListener *listener;
|
QIONetListener *listener;
|
||||||
|
uint32_t handshake_max_secs;
|
||||||
QCryptoTLSCreds *tlscreds;
|
QCryptoTLSCreds *tlscreds;
|
||||||
char *tlsauthz;
|
char *tlsauthz;
|
||||||
uint32_t max_connections;
|
uint32_t max_connections;
|
||||||
|
@ -84,8 +85,7 @@ static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
|
||||||
nbd_update_server_watch(nbd_server);
|
nbd_update_server_watch(nbd_server);
|
||||||
|
|
||||||
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
|
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
|
||||||
/* TODO - expose handshake timeout as QMP option */
|
nbd_client_new(cioc, nbd_server->handshake_max_secs,
|
||||||
nbd_client_new(cioc, NBD_DEFAULT_HANDSHAKE_MAX_SECS,
|
|
||||||
nbd_server->tlscreds, nbd_server->tlsauthz,
|
nbd_server->tlscreds, nbd_server->tlsauthz,
|
||||||
nbd_blockdev_client_closed, conn);
|
nbd_blockdev_client_closed, conn);
|
||||||
}
|
}
|
||||||
|
@ -162,9 +162,9 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
|
void nbd_server_start(SocketAddress *addr, uint32_t handshake_max_secs,
|
||||||
const char *tls_authz, uint32_t max_connections,
|
const char *tls_creds, const char *tls_authz,
|
||||||
Error **errp)
|
uint32_t max_connections, Error **errp)
|
||||||
{
|
{
|
||||||
if (nbd_server) {
|
if (nbd_server) {
|
||||||
error_setg(errp, "NBD server already running");
|
error_setg(errp, "NBD server already running");
|
||||||
|
@ -173,6 +173,7 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
|
||||||
|
|
||||||
nbd_server = g_new0(NBDServerData, 1);
|
nbd_server = g_new0(NBDServerData, 1);
|
||||||
nbd_server->max_connections = max_connections;
|
nbd_server->max_connections = max_connections;
|
||||||
|
nbd_server->handshake_max_secs = handshake_max_secs;
|
||||||
nbd_server->listener = qio_net_listener_new();
|
nbd_server->listener = qio_net_listener_new();
|
||||||
|
|
||||||
qio_net_listener_set_name(nbd_server->listener,
|
qio_net_listener_set_name(nbd_server->listener,
|
||||||
|
@ -210,12 +211,17 @@ void nbd_server_start_options(NbdServerOptions *arg, Error **errp)
|
||||||
if (!arg->has_max_connections) {
|
if (!arg->has_max_connections) {
|
||||||
arg->max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
|
arg->max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
|
||||||
}
|
}
|
||||||
|
if (!arg->has_handshake_max_seconds) {
|
||||||
|
arg->handshake_max_seconds = NBD_DEFAULT_HANDSHAKE_MAX_SECS;
|
||||||
|
}
|
||||||
|
|
||||||
nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz,
|
nbd_server_start(arg->addr, arg->handshake_max_seconds, arg->tls_creds,
|
||||||
arg->max_connections, errp);
|
arg->tls_authz, arg->max_connections, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_nbd_server_start(SocketAddressLegacy *addr,
|
void qmp_nbd_server_start(SocketAddressLegacy *addr,
|
||||||
|
bool has_handshake_max_secs,
|
||||||
|
uint32_t handshake_max_secs,
|
||||||
const char *tls_creds,
|
const char *tls_creds,
|
||||||
const char *tls_authz,
|
const char *tls_authz,
|
||||||
bool has_max_connections, uint32_t max_connections,
|
bool has_max_connections, uint32_t max_connections,
|
||||||
|
@ -226,8 +232,12 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
|
||||||
if (!has_max_connections) {
|
if (!has_max_connections) {
|
||||||
max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
|
max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
|
||||||
}
|
}
|
||||||
|
if (!has_handshake_max_secs) {
|
||||||
|
handshake_max_secs = NBD_DEFAULT_HANDSHAKE_MAX_SECS;
|
||||||
|
}
|
||||||
|
|
||||||
nbd_server_start(addr_flat, tls_creds, tls_authz, max_connections, errp);
|
nbd_server_start(addr_flat, handshake_max_secs, tls_creds, tls_authz,
|
||||||
|
max_connections, errp);
|
||||||
qapi_free_SocketAddress(addr_flat);
|
qapi_free_SocketAddress(addr_flat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -428,9 +428,9 @@ void nbd_client_put(NBDClient *client);
|
||||||
void nbd_server_is_qemu_nbd(int max_connections);
|
void nbd_server_is_qemu_nbd(int max_connections);
|
||||||
bool nbd_server_is_running(void);
|
bool nbd_server_is_running(void);
|
||||||
int nbd_server_max_connections(void);
|
int nbd_server_max_connections(void);
|
||||||
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
|
void nbd_server_start(SocketAddress *addr, uint32_t handshake_max_secs,
|
||||||
const char *tls_authz, uint32_t max_connections,
|
const char *tls_creds, const char *tls_authz,
|
||||||
Error **errp);
|
uint32_t max_connections, Error **errp);
|
||||||
void nbd_server_start_options(NbdServerOptions *arg, Error **errp);
|
void nbd_server_start_options(NbdServerOptions *arg, Error **errp);
|
||||||
|
|
||||||
/* nbd_read
|
/* nbd_read
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
#
|
#
|
||||||
# @addr: Address on which to listen.
|
# @addr: Address on which to listen.
|
||||||
#
|
#
|
||||||
|
# @handshake-max-seconds: Time limit, in seconds, at which a client
|
||||||
|
# that has not completed the negotiation handshake will be
|
||||||
|
# disconnected, 0 for no limit (since 10.0; default: 10).
|
||||||
|
#
|
||||||
# @tls-creds: ID of the TLS credentials object (since 2.6).
|
# @tls-creds: ID of the TLS credentials object (since 2.6).
|
||||||
#
|
#
|
||||||
# @tls-authz: ID of the QAuthZ authorization object used to validate
|
# @tls-authz: ID of the QAuthZ authorization object used to validate
|
||||||
|
@ -34,6 +38,7 @@
|
||||||
##
|
##
|
||||||
{ 'struct': 'NbdServerOptions',
|
{ 'struct': 'NbdServerOptions',
|
||||||
'data': { 'addr': 'SocketAddress',
|
'data': { 'addr': 'SocketAddress',
|
||||||
|
'*handshake-max-seconds': 'uint32',
|
||||||
'*tls-creds': 'str',
|
'*tls-creds': 'str',
|
||||||
'*tls-authz': 'str',
|
'*tls-authz': 'str',
|
||||||
'*max-connections': 'uint32' } }
|
'*max-connections': 'uint32' } }
|
||||||
|
@ -52,6 +57,10 @@
|
||||||
#
|
#
|
||||||
# @addr: Address on which to listen.
|
# @addr: Address on which to listen.
|
||||||
#
|
#
|
||||||
|
# @handshake-max-seconds: Time limit, in seconds, at which a client
|
||||||
|
# that has not completed the negotiation handshake will be
|
||||||
|
# disconnected, or 0 for no limit (since 10.0; default: 10).
|
||||||
|
#
|
||||||
# @tls-creds: ID of the TLS credentials object (since 2.6).
|
# @tls-creds: ID of the TLS credentials object (since 2.6).
|
||||||
#
|
#
|
||||||
# @tls-authz: ID of the QAuthZ authorization object used to validate
|
# @tls-authz: ID of the QAuthZ authorization object used to validate
|
||||||
|
@ -72,6 +81,7 @@
|
||||||
##
|
##
|
||||||
{ 'command': 'nbd-server-start',
|
{ 'command': 'nbd-server-start',
|
||||||
'data': { 'addr': 'SocketAddressLegacy',
|
'data': { 'addr': 'SocketAddressLegacy',
|
||||||
|
'*handshake-max-seconds': 'uint32',
|
||||||
'*tls-creds': 'str',
|
'*tls-creds': 'str',
|
||||||
'*tls-authz': 'str',
|
'*tls-authz': 'str',
|
||||||
'*max-connections': 'uint32' },
|
'*max-connections': 'uint32' },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue