block/export: Create BlockBackend in blk_exp_add()

Every export type will need a BlockBackend, so creating it centrally in
blk_exp_add() instead of the .create driver callback avoids duplication.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200924152717.287415-24-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2020-09-24 17:27:09 +02:00
parent 37a4f70cea
commit 331170e073
4 changed files with 63 additions and 61 deletions

View file

@ -177,9 +177,6 @@ int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args,
Error **errp)
{
BlockExportOptionsNbd *arg = &exp_args->u.nbd;
BlockDriverState *bs = NULL;
AioContext *aio_context;
int ret;
assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD);
@ -207,38 +204,16 @@ int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args,
return -EEXIST;
}
bs = bdrv_lookup_bs(NULL, exp_args->node_name, errp);
if (!bs) {
return -ENOENT;
}
aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
if (!arg->has_writable) {
arg->writable = false;
}
if (bdrv_is_read_only(bs) && arg->writable) {
ret = -EINVAL;
if (blk_is_read_only(exp->blk) && arg->writable) {
error_setg(errp, "Cannot export read-only node as writable");
goto out;
return -EINVAL;
}
if (!exp_args->has_writethrough) {
exp_args->writethrough = false;
}
ret = nbd_export_new(exp, bs, arg->name, arg->description, arg->bitmap,
!arg->writable, !arg->writable,
exp_args->writethrough, errp);
if (ret < 0) {
goto out;
}
ret = 0;
out:
aio_context_release(aio_context);
return ret;
return nbd_export_new(exp, arg->name, arg->description, arg->bitmap,
!arg->writable, !arg->writable, errp);
}
void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp)