block: Merge BlockBackend and BlockDriverState name spaces
BlockBackend's name space is separate only to keep the initial patches simple. Time to merge the two. Retain bdrv_find() and bdrv_get_device_name() for now, to keep this series manageable. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
bfb197e0d9
commit
7f06d47eff
48
block.c
48
block.c
@ -335,31 +335,9 @@ void bdrv_register(BlockDriver *bdrv)
|
|||||||
QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
|
QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new block device (by default it is empty) */
|
BlockDriverState *bdrv_new_root(void)
|
||||||
BlockDriverState *bdrv_new_root(const char *device_name, Error **errp)
|
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs = bdrv_new();
|
||||||
|
|
||||||
assert(*device_name);
|
|
||||||
|
|
||||||
if (*device_name && !id_wellformed(device_name)) {
|
|
||||||
error_setg(errp, "Invalid device name");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bdrv_find(device_name)) {
|
|
||||||
error_setg(errp, "Device with id '%s' already exists",
|
|
||||||
device_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (bdrv_find_node(device_name)) {
|
|
||||||
error_setg(errp,
|
|
||||||
"Device name '%s' conflicts with an existing node name",
|
|
||||||
device_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bs = bdrv_new();
|
|
||||||
|
|
||||||
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
|
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
|
||||||
return bs;
|
return bs;
|
||||||
@ -883,7 +861,7 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* takes care of avoiding namespaces collisions */
|
/* takes care of avoiding namespaces collisions */
|
||||||
if (bdrv_find(node_name)) {
|
if (blk_by_name(node_name)) {
|
||||||
error_setg(errp, "node-name=%s is conflicting with a device id",
|
error_setg(errp, "node-name=%s is conflicting with a device id",
|
||||||
node_name);
|
node_name);
|
||||||
return;
|
return;
|
||||||
@ -3817,16 +3795,12 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This function is to find block backend bs */
|
/* This function is to find block backend bs */
|
||||||
|
/* TODO convert callers to blk_by_name(), then remove */
|
||||||
BlockDriverState *bdrv_find(const char *name)
|
BlockDriverState *bdrv_find(const char *name)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockBackend *blk = blk_by_name(name);
|
||||||
|
|
||||||
QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
|
return blk ? blk_bs(blk) : NULL;
|
||||||
if (!strcmp(name, bdrv_get_device_name(bs))) {
|
|
||||||
return bs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is to find a node in the bs graph */
|
/* This function is to find a node in the bs graph */
|
||||||
@ -3865,13 +3839,14 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
|
|||||||
const char *node_name,
|
const char *node_name,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs = NULL;
|
BlockBackend *blk;
|
||||||
|
BlockDriverState *bs;
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
bs = bdrv_find(device);
|
blk = blk_by_name(device);
|
||||||
|
|
||||||
if (bs) {
|
if (blk) {
|
||||||
return bs;
|
return blk_bs(blk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3908,6 +3883,7 @@ BlockDriverState *bdrv_next(BlockDriverState *bs)
|
|||||||
return QTAILQ_NEXT(bs, device_list);
|
return QTAILQ_NEXT(bs, device_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO check what callers really want: bs->node_name or blk_name() */
|
||||||
const char *bdrv_get_device_name(const BlockDriverState *bs)
|
const char *bdrv_get_device_name(const BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
return bs->blk ? blk_name(bs->blk) : "";
|
return bs->blk ? blk_name(bs->blk) : "";
|
||||||
|
@ -40,10 +40,20 @@ BlockBackend *blk_new(const char *name, Error **errp)
|
|||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
|
|
||||||
assert(name && name[0]);
|
assert(name && name[0]);
|
||||||
|
if (!id_wellformed(name)) {
|
||||||
|
error_setg(errp, "Invalid device name");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (blk_by_name(name)) {
|
if (blk_by_name(name)) {
|
||||||
error_setg(errp, "Device with id '%s' already exists", name);
|
error_setg(errp, "Device with id '%s' already exists", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (bdrv_find_node(name)) {
|
||||||
|
error_setg(errp,
|
||||||
|
"Device name '%s' conflicts with an existing node name",
|
||||||
|
name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
blk = g_new0(BlockBackend, 1);
|
blk = g_new0(BlockBackend, 1);
|
||||||
blk->name = g_strdup(name);
|
blk->name = g_strdup(name);
|
||||||
@ -66,12 +76,7 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = bdrv_new_root(name, errp);
|
bs = bdrv_new_root();
|
||||||
if (!bs) {
|
|
||||||
blk_unref(blk);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
blk->bs = bs;
|
blk->bs = bs;
|
||||||
bs->blk = blk;
|
bs->blk = blk;
|
||||||
return blk;
|
return blk;
|
||||||
|
@ -204,7 +204,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
|
|||||||
int bdrv_create(BlockDriver *drv, const char* filename,
|
int bdrv_create(BlockDriver *drv, const char* filename,
|
||||||
QemuOpts *opts, Error **errp);
|
QemuOpts *opts, Error **errp);
|
||||||
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
||||||
BlockDriverState *bdrv_new_root(const char *device_name, Error **errp);
|
BlockDriverState *bdrv_new_root(void);
|
||||||
BlockDriverState *bdrv_new(void);
|
BlockDriverState *bdrv_new(void);
|
||||||
void bdrv_make_anon(BlockDriverState *bs);
|
void bdrv_make_anon(BlockDriverState *bs);
|
||||||
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
|
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
|
||||||
|
Loading…
Reference in New Issue
Block a user