mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
block/export: Add BlockExport infrastructure and block-export-add
We want to have a common set of commands for all types of block exports. Currently, this is only NBD, but we're going to add more types. This patch adds the basic BlockExport and BlockExportDriver structs and a QMP command block-export-add that creates a new export based on the given BlockExportOptions. qmp_nbd_server_add() becomes a wrapper around qmp_block_export_add(). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200924152717.287415-5-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
143ea7670c
commit
56ee86261e
9 changed files with 134 additions and 10 deletions
|
@ -148,17 +148,20 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
|
|||
qapi_free_SocketAddress(addr_flat);
|
||||
}
|
||||
|
||||
void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp)
|
||||
BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp)
|
||||
{
|
||||
BlockExportOptionsNbd *arg = &exp_args->u.nbd;
|
||||
BlockDriverState *bs = NULL;
|
||||
BlockBackend *on_eject_blk;
|
||||
NBDExport *exp;
|
||||
NBDExport *exp = NULL;
|
||||
int64_t len;
|
||||
AioContext *aio_context;
|
||||
|
||||
assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD);
|
||||
|
||||
if (!nbd_server) {
|
||||
error_setg(errp, "NBD server not running");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!arg->has_name) {
|
||||
|
@ -167,24 +170,24 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp)
|
|||
|
||||
if (strlen(arg->name) > NBD_MAX_STRING_SIZE) {
|
||||
error_setg(errp, "export name '%s' too long", arg->name);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) {
|
||||
error_setg(errp, "description '%s' too long", arg->description);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (nbd_export_find(arg->name)) {
|
||||
error_setg(errp, "NBD server already has export named '%s'", arg->name);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
on_eject_blk = blk_by_name(arg->device);
|
||||
|
||||
bs = bdrv_lookup_bs(arg->device, arg->device, errp);
|
||||
if (!bs) {
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
aio_context = bdrv_get_aio_context(bs);
|
||||
|
@ -217,6 +220,17 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp)
|
|||
|
||||
out:
|
||||
aio_context_release(aio_context);
|
||||
/* TODO Remove the cast: nbd_export_new() will return a BlockExport. */
|
||||
return (BlockExport*) exp;
|
||||
}
|
||||
|
||||
void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp)
|
||||
{
|
||||
BlockExportOptions export = {
|
||||
.type = BLOCK_EXPORT_TYPE_NBD,
|
||||
.u.nbd = *arg,
|
||||
};
|
||||
qmp_block_export_add(&export, errp);
|
||||
}
|
||||
|
||||
void qmp_nbd_server_remove(const char *name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue