Skip to content

Commit ff12e6a

Browse files
committed
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 fb1c2aa, 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 <[email protected]> Message-ID: <[email protected]> [eblake: s/max-secs/max-seconds/ in QMP] Acked-by: Markus Armbruster <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
1 parent 617017f commit ff12e6a

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

block/monitor/block-hmp-cmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
402402
goto exit;
403403
}
404404

405-
nbd_server_start(addr, NULL, NULL, NBD_DEFAULT_MAX_CONNECTIONS,
406-
&local_err);
405+
nbd_server_start(addr, NBD_DEFAULT_HANDSHAKE_MAX_SECS, NULL, NULL,
406+
NBD_DEFAULT_MAX_CONNECTIONS, &local_err);
407407
qapi_free_SocketAddress(addr);
408408
if (local_err != NULL) {
409409
goto exit;

blockdev-nbd.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef struct NBDConn {
2828

2929
typedef struct NBDServerData {
3030
QIONetListener *listener;
31+
uint32_t handshake_max_secs;
3132
QCryptoTLSCreds *tlscreds;
3233
char *tlsauthz;
3334
uint32_t max_connections;
@@ -84,8 +85,7 @@ static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
8485
nbd_update_server_watch(nbd_server);
8586

8687
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
87-
/* TODO - expose handshake timeout as QMP option */
88-
nbd_client_new(cioc, NBD_DEFAULT_HANDSHAKE_MAX_SECS,
88+
nbd_client_new(cioc, nbd_server->handshake_max_secs,
8989
nbd_server->tlscreds, nbd_server->tlsauthz,
9090
nbd_blockdev_client_closed, conn);
9191
}
@@ -162,9 +162,9 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
162162
}
163163

164164

165-
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
166-
const char *tls_authz, uint32_t max_connections,
167-
Error **errp)
165+
void nbd_server_start(SocketAddress *addr, uint32_t handshake_max_secs,
166+
const char *tls_creds, const char *tls_authz,
167+
uint32_t max_connections, Error **errp)
168168
{
169169
if (nbd_server) {
170170
error_setg(errp, "NBD server already running");
@@ -173,6 +173,7 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
173173

174174
nbd_server = g_new0(NBDServerData, 1);
175175
nbd_server->max_connections = max_connections;
176+
nbd_server->handshake_max_secs = handshake_max_secs;
176177
nbd_server->listener = qio_net_listener_new();
177178

178179
qio_net_listener_set_name(nbd_server->listener,
@@ -210,12 +211,17 @@ void nbd_server_start_options(NbdServerOptions *arg, Error **errp)
210211
if (!arg->has_max_connections) {
211212
arg->max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
212213
}
214+
if (!arg->has_handshake_max_seconds) {
215+
arg->handshake_max_seconds = NBD_DEFAULT_HANDSHAKE_MAX_SECS;
216+
}
213217

214-
nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz,
215-
arg->max_connections, errp);
218+
nbd_server_start(arg->addr, arg->handshake_max_seconds, arg->tls_creds,
219+
arg->tls_authz, arg->max_connections, errp);
216220
}
217221

218222
void qmp_nbd_server_start(SocketAddressLegacy *addr,
223+
bool has_handshake_max_secs,
224+
uint32_t handshake_max_secs,
219225
const char *tls_creds,
220226
const char *tls_authz,
221227
bool has_max_connections, uint32_t max_connections,
@@ -226,8 +232,12 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
226232
if (!has_max_connections) {
227233
max_connections = NBD_DEFAULT_MAX_CONNECTIONS;
228234
}
235+
if (!has_handshake_max_secs) {
236+
handshake_max_secs = NBD_DEFAULT_HANDSHAKE_MAX_SECS;
237+
}
229238

230-
nbd_server_start(addr_flat, tls_creds, tls_authz, max_connections, errp);
239+
nbd_server_start(addr_flat, handshake_max_secs, tls_creds, tls_authz,
240+
max_connections, errp);
231241
qapi_free_SocketAddress(addr_flat);
232242
}
233243

include/block/nbd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ void nbd_client_put(NBDClient *client);
428428
void nbd_server_is_qemu_nbd(int max_connections);
429429
bool nbd_server_is_running(void);
430430
int nbd_server_max_connections(void);
431-
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
432-
const char *tls_authz, uint32_t max_connections,
433-
Error **errp);
431+
void nbd_server_start(SocketAddress *addr, uint32_t handshake_max_secs,
432+
const char *tls_creds, const char *tls_authz,
433+
uint32_t max_connections, Error **errp);
434434
void nbd_server_start_options(NbdServerOptions *arg, Error **errp);
435435

436436
/* nbd_read

qapi/block-export.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#
1818
# @addr: Address on which to listen.
1919
#
20+
# @handshake-max-seconds: Time limit, in seconds, at which a client
21+
# that has not completed the negotiation handshake will be
22+
# disconnected, 0 for no limit (since 10.0; default: 10).
23+
#
2024
# @tls-creds: ID of the TLS credentials object (since 2.6).
2125
#
2226
# @tls-authz: ID of the QAuthZ authorization object used to validate
@@ -34,6 +38,7 @@
3438
##
3539
{ 'struct': 'NbdServerOptions',
3640
'data': { 'addr': 'SocketAddress',
41+
'*handshake-max-seconds': 'uint32',
3742
'*tls-creds': 'str',
3843
'*tls-authz': 'str',
3944
'*max-connections': 'uint32' } }
@@ -52,6 +57,10 @@
5257
#
5358
# @addr: Address on which to listen.
5459
#
60+
# @handshake-max-seconds: Time limit, in seconds, at which a client
61+
# that has not completed the negotiation handshake will be
62+
# disconnected, or 0 for no limit (since 10.0; default: 10).
63+
#
5564
# @tls-creds: ID of the TLS credentials object (since 2.6).
5665
#
5766
# @tls-authz: ID of the QAuthZ authorization object used to validate
@@ -72,6 +81,7 @@
7281
##
7382
{ 'command': 'nbd-server-start',
7483
'data': { 'addr': 'SocketAddressLegacy',
84+
'*handshake-max-seconds': 'uint32',
7585
'*tls-creds': 'str',
7686
'*tls-authz': 'str',
7787
'*max-connections': 'uint32' },

0 commit comments

Comments
 (0)