mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
nbd: Merge nbd_export_new() and nbd_export_create()
There is no real reason any more why nbd_export_new() and nbd_export_create() should be separate functions. The latter only performs a few checks before it calls the former. What makes the current state stand out is that it's the only function in BlockExportDriver that is not a static function inside nbd/server.c, but a small wrapper in blockdev-nbd.c that then calls back into nbd/server.c for the real functionality. Move all the checks to nbd/server.c and make the resulting function static to improve readability. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200924152717.287415-27-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
30dbc81d31
commit
5b1cb49704
3 changed files with 45 additions and 56 deletions
|
@ -37,6 +37,11 @@ void nbd_server_is_qemu_nbd(bool value)
|
|||
is_qemu_nbd = value;
|
||||
}
|
||||
|
||||
bool nbd_server_is_running(void)
|
||||
{
|
||||
return nbd_server || is_qemu_nbd;
|
||||
}
|
||||
|
||||
static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
|
||||
{
|
||||
nbd_client_put(client);
|
||||
|
@ -173,41 +178,6 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
|
|||
qapi_free_SocketAddress(addr_flat);
|
||||
}
|
||||
|
||||
int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args,
|
||||
Error **errp)
|
||||
{
|
||||
BlockExportOptionsNbd *arg = &exp_args->u.nbd;
|
||||
|
||||
assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD);
|
||||
|
||||
if (!nbd_server && !is_qemu_nbd) {
|
||||
error_setg(errp, "NBD server not running");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!arg->has_name) {
|
||||
arg->name = exp_args->node_name;
|
||||
}
|
||||
|
||||
if (strlen(arg->name) > NBD_MAX_STRING_SIZE) {
|
||||
error_setg(errp, "export name '%s' too long", arg->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) {
|
||||
error_setg(errp, "description '%s' too long", arg->description);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (nbd_export_find(arg->name)) {
|
||||
error_setg(errp, "NBD server already has export named '%s'", arg->name);
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
return nbd_export_new(exp, arg->name, arg->description, arg->bitmap,
|
||||
!exp_args->writable, !exp_args->writable, errp);
|
||||
}
|
||||
|
||||
void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp)
|
||||
{
|
||||
BlockExport *export;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue