mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
block/export: Add 'id' option to block-export-add
We'll need an id to identify block exports in monitor commands. This adds one. Note that this is different from the 'name' option in the NBD server, which is the externally visible export name. While block export ids need to be unique in the whole process, export names must be unique only for the same server. Different export types or (potentially in the future) multiple NBD servers can have the same export name externally, but still need different block export ids internally. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200924152717.287415-19-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
bc4ee65b8c
commit
d53be9ce55
7 changed files with 39 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "block/nbd.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-block-export.h"
|
||||
#include "qemu/id.h"
|
||||
|
||||
static const BlockExportDriver *blk_exp_drivers[] = {
|
||||
&blk_exp_nbd,
|
||||
|
@ -28,6 +29,19 @@ static const BlockExportDriver *blk_exp_drivers[] = {
|
|||
static QLIST_HEAD(, BlockExport) block_exports =
|
||||
QLIST_HEAD_INITIALIZER(block_exports);
|
||||
|
||||
static BlockExport *blk_exp_find(const char *id)
|
||||
{
|
||||
BlockExport *exp;
|
||||
|
||||
QLIST_FOREACH(exp, &block_exports, next) {
|
||||
if (strcmp(id, exp->id) == 0) {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const BlockExportDriver *blk_exp_find_driver(BlockExportType type)
|
||||
{
|
||||
int i;
|
||||
|
@ -46,6 +60,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
|
|||
BlockExport *exp;
|
||||
int ret;
|
||||
|
||||
if (!id_wellformed(export->id)) {
|
||||
error_setg(errp, "Invalid block export id");
|
||||
return NULL;
|
||||
}
|
||||
if (blk_exp_find(export->id)) {
|
||||
error_setg(errp, "Block export id '%s' is already in use", export->id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
drv = blk_exp_find_driver(export->type);
|
||||
if (!drv) {
|
||||
error_setg(errp, "No driver found for the requested export type");
|
||||
|
@ -57,10 +80,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
|
|||
*exp = (BlockExport) {
|
||||
.drv = drv,
|
||||
.refcount = 1,
|
||||
.id = g_strdup(export->id),
|
||||
};
|
||||
|
||||
ret = drv->create(exp, export, errp);
|
||||
if (ret < 0) {
|
||||
g_free(exp->id);
|
||||
g_free(exp);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -87,6 +112,7 @@ static void blk_exp_delete_bh(void *opaque)
|
|||
assert(exp->refcount == 0);
|
||||
QLIST_REMOVE(exp, next);
|
||||
exp->drv->delete(exp);
|
||||
g_free(exp->id);
|
||||
g_free(exp);
|
||||
|
||||
aio_context_release(aio_context);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue