diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index cf21b5e40a..d564d8d234 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -413,7 +413,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) goto exit; } - nbd_server_start(addr, NULL, NULL, 0, &local_err); + nbd_server_start(addr, NULL, NULL, NBD_DEFAULT_MAX_CONNECTIONS, + &local_err); qapi_free_SocketAddress(addr); if (local_err != NULL) { goto exit; diff --git a/blockdev-nbd.c b/blockdev-nbd.c index bf02ddc1e0..b357ae9bf1 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -170,6 +170,10 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds, void nbd_server_start_options(NbdServerOptions *arg, Error **errp) { + if (!arg->has_max_connections) { + arg->max_connections = NBD_DEFAULT_MAX_CONNECTIONS; + } + nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz, arg->max_connections, errp); } @@ -182,6 +186,10 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, { SocketAddress *addr_flat = socket_address_flatten(addr); + if (!has_max_connections) { + max_connections = NBD_DEFAULT_MAX_CONNECTIONS; + } + nbd_server_start(addr_flat, tls_creds, tls_authz, max_connections, errp); qapi_free_SocketAddress(addr_flat); } diff --git a/include/block/nbd.h b/include/block/nbd.h index 3392a5c319..88be104e31 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -33,6 +33,13 @@ extern const BlockExportDriver blk_exp_nbd; */ #define NBD_DEFAULT_HANDSHAKE_MAX_SECS 10 +/* + * NBD_DEFAULT_MAX_CONNECTIONS: Number of client sockets to allow at + * once; must be large enough to allow a MULTI_CONN-aware client like + * nbdcopy to create its typical number of 8-16 sockets. + */ +#define NBD_DEFAULT_MAX_CONNECTIONS 100 + /* Handshake phase structs - this struct is passed on the wire */ struct NBDOption { diff --git a/qapi/block-export.json b/qapi/block-export.json index 4627bbc4e6..67d2337f91 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -24,7 +24,7 @@ # @max-connections: The maximum number of connections to allow at the same # time, 0 for unlimited. Setting this to 1 also stops # the server from advertising multiple client support -# (since 5.2; default: 0) +# (since 5.2; default: 100) # # Since: 4.2 ## @@ -55,7 +55,7 @@ # @max-connections: The maximum number of connections to allow at the same # time, 0 for unlimited. Setting this to 1 also stops # the server from advertising multiple client support -# (since 5.2; default: 0). +# (since 5.2; default: 100). # # Returns: error if the server is already running. #