From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PULL 14/28] block: Merge BlockBackend and BlockDriverState name spaces
Date: Mon, 20 Oct 2014 15:35:40 +0200 [thread overview]
Message-ID: <1413812154-11153-15-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1413812154-11153-1-git-send-email-kwolf@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
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>
---
block.c | 48 ++++++++++++------------------------------------
block/block-backend.c | 17 +++++++++++------
include/block/block.h | 2 +-
3 files changed, 24 insertions(+), 43 deletions(-)
diff --git a/block.c b/block.c
index 5c37970..2d80d6a 100644
--- a/block.c
+++ b/block.c
@@ -335,31 +335,9 @@ void bdrv_register(BlockDriver *bdrv)
QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
}
-/* create a new block device (by default it is empty) */
-BlockDriverState *bdrv_new_root(const char *device_name, Error **errp)
+BlockDriverState *bdrv_new_root(void)
{
- BlockDriverState *bs;
-
- 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();
+ BlockDriverState *bs = bdrv_new();
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
return bs;
@@ -883,7 +861,7 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
}
/* 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",
node_name);
return;
@@ -3817,16 +3795,12 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
}
/* This function is to find block backend bs */
+/* TODO convert callers to blk_by_name(), then remove */
BlockDriverState *bdrv_find(const char *name)
{
- BlockDriverState *bs;
+ BlockBackend *blk = blk_by_name(name);
- QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
- if (!strcmp(name, bdrv_get_device_name(bs))) {
- return bs;
- }
- }
- return NULL;
+ return blk ? blk_bs(blk) : NULL;
}
/* 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,
Error **errp)
{
- BlockDriverState *bs = NULL;
+ BlockBackend *blk;
+ BlockDriverState *bs;
if (device) {
- bs = bdrv_find(device);
+ blk = blk_by_name(device);
- if (bs) {
- return bs;
+ if (blk) {
+ return blk_bs(blk);
}
}
@@ -3908,6 +3883,7 @@ BlockDriverState *bdrv_next(BlockDriverState *bs)
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)
{
return bs->blk ? blk_name(bs->blk) : "";
diff --git a/block/block-backend.c b/block/block-backend.c
index 6236b5b..fb91680 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -40,10 +40,20 @@ BlockBackend *blk_new(const char *name, Error **errp)
BlockBackend *blk;
assert(name && name[0]);
+ if (!id_wellformed(name)) {
+ error_setg(errp, "Invalid device name");
+ return NULL;
+ }
if (blk_by_name(name)) {
error_setg(errp, "Device with id '%s' already exists", name);
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->name = g_strdup(name);
@@ -66,12 +76,7 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)
return NULL;
}
- bs = bdrv_new_root(name, errp);
- if (!bs) {
- blk_unref(blk);
- return NULL;
- }
-
+ bs = bdrv_new_root();
blk->bs = bs;
bs->blk = blk;
return blk;
diff --git a/include/block/block.h b/include/block/block.h
index 3880e05..3dc7c56 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -204,7 +204,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
int bdrv_create(BlockDriver *drv, 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);
void bdrv_make_anon(BlockDriverState *bs);
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
--
1.8.3.1
next prev parent reply other threads:[~2014-10-20 13:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-20 13:35 [Qemu-devel] [PULL 00/28] Block patches Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 01/28] qcow2: fix leak of Qcow2DiscardRegion in update_refcount_discard Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 02/28] block/raw-posix: Fix disk corruption in try_fiemap Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 03/28] block/raw-posix: use seek_hole ahead of fiemap Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 04/28] nbd: Fix filename generation Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 05/28] block: Split bdrv_new_root() off bdrv_new() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 06/28] block: New BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 07/28] block: Connect BlockBackend to BlockDriverState Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 08/28] block: Connect BlockBackend and DriveInfo Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 09/28] block: Code motion to get rid of stubs/blockdev.c Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 10/28] block: Make BlockBackend own its BlockDriverState Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 11/28] blockdev: Eliminate drive_del() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 12/28] block: Eliminate bdrv_iterate(), use bdrv_next() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 13/28] block: Eliminate BlockDriverState member device_name[] Kevin Wolf
2014-10-20 13:35 ` Kevin Wolf [this message]
2014-10-20 13:35 ` [Qemu-devel] [PULL 15/28] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo() Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 16/28] block: Rename BlockDriverAIOCB* to BlockAIOCB* Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 17/28] block: Rename BlockDriverCompletionFunc to BlockCompletionFunc Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 18/28] virtio-blk: Drop redundant VirtIOBlock member conf Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 19/28] virtio-blk: Rename VirtIOBlkConf variables to conf Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 20/28] hw: Convert from BlockDriverState to BlockBackend, mostly Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 21/28] ide: Complete conversion from BlockDriverState to BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 22/28] pc87312: Drop unused members of PC87312State Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 23/28] blockdev: Drop superfluous DriveInfo member id Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 24/28] blockdev: Fix blockdev-add not to create DriveInfo Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 25/28] block/qapi: Convert qmp_query_block() to BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 26/28] blockdev: Convert qmp_eject(), qmp_change_blockdev() " Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 27/28] block: Lift device model API into BlockBackend Kevin Wolf
2014-10-20 13:35 ` [Qemu-devel] [PULL 28/28] block: Make device model's references to BlockBackend strong Kevin Wolf
2014-10-22 17:30 ` [Qemu-devel] [PULL 00/28] Block patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1413812154-11153-15-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).