Skip to contentSkip to conversation

Make open by reference use id then node-name

PATCH Applied Benoît Canet 4 participants 7 messages Feb 12, 2014 – Feb 14, 2014

lore
Share & tools
lore
#0 lore raw

cover Make open by reference use id then node-name

This series was asked by Kevin.
It sit on top of the snapshot fix patch and max openv2 series.

I have done the following tests.

check qemu-iotest ok
snapshot blockbackend by id ok
open quorum by node-name reference and id reference ok Error messages seems ok

Benoît Canet (2):
block: Relax bdrv_lookup_bs constraints.
block: Open by reference will try device then node_name.

 block.c    | 36 +++++++++++++++++++-----------------
 blockdev.c |  6 ++++++
 2 files changed, 25 insertions(+), 17 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/2 block: Relax bdrv_lookup_bs constraints.

The following patch will reuse bdrv_lookup_bs in order to open images by references so the rules of usage of bdrv_lookup_bs must be relaxed a bit.

---
 block.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
block.c +11 -15
index 3843f59..5ca901b 100644
@@ -3579,30 +3579,26 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
 {
     BlockDriverState *bs = NULL;
 
-    if ((!device && !node_name) || (device && node_name)) {
-        error_setg(errp, "Use either device or node-name but not both");
-        return NULL;
-    }
-
     if (device) {
         bs = bdrv_find(device);
 
-        if (!bs) {
-            error_set(errp, QERR_DEVICE_NOT_FOUND, device);
-            return NULL;
+        if (bs) {
+            return bs;
         }
-
-        return bs;
     }
 
-    bs = bdrv_find_node(node_name);
+    if (node_name) {
+        bs = bdrv_find_node(node_name);
 
-    if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, node_name);
-        return NULL;
+        if (bs) {
+            return bs;
+        }
     }
 
-    return bs;
+    error_setg(errp, "Cannot find device=%s nor node_name=%s",
+                     device ? device : "",
+                     node_name ? node_name : "");
+    return NULL;
 }
 
 BlockDriverState *bdrv_next(BlockDriverState *bs)
Signature · 1 line
1.8.3.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Relax bdrv_lookup_bs constraints.

Quoted 7 lines · Benoît Canet

The following patch will reuse bdrv_lookup_bs in order to open images by references so the rules of usage of bdrv_lookup_bs must be relaxed a bit.

---
  block.c | 26 +++++++++++---------------
  1 file changed, 11 insertions(+), 15 deletions(-)
#3 lore raw

PATCH 2/2 block: Open by reference will try device then node_name.

In reply to Benoît Canet

Since we introduced node_name for named bs of the graph modify the opening by reference to use it as a fallback.

This patch also enforce the separation of the device id and graph node namespaces.

---
 block.c    | 10 ++++++++--
 blockdev.c |  6 ++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
block.c +8 -2
index 5ca901b..af22e8a 100644
@@ -796,6 +796,13 @@ static int bdrv_assign_node_name(BlockDriverState *bs,
         return -EINVAL;
     }
 
+    /* takes care of avoiding namespaces collisions */
+    if (bdrv_find(node_name)) {
+        error_setg(errp, "node-name=%s is conflicting with a device id",
+                   node_name);
+        return -EINVAL;
+    }
+
     /* takes care of avoiding duplicates node names */
     if (bdrv_find_node(node_name)) {
         error_setg(errp, "Duplicate node name");
@@ -1193,9 +1200,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
             return -EINVAL;
         }
 
-        bs = bdrv_find(reference);
+        bs = bdrv_lookup_bs(reference, reference, errp);
         if (!bs) {
-            error_setg(errp, "Cannot find block device '%s'", reference);
             return -ENODEV;
         }
         bdrv_ref(bs);
blockdev.c +6 -0
index 7b7e349..5cd50f3 100644
@@ -463,6 +463,12 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
         }
     }
 
+    if (bdrv_find_node(qemu_opts_id(opts))) {
+        error_setg(errp, "device id=%s is conflicting with a node-name",
+                   qemu_opts_id(opts));
+        goto early_err;
+    }
+
     /* init */
     dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->id = g_strdup(qemu_opts_id(opts));
Signature · 1 line
1.8.3.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Open by reference will try device then node_name.

Quoted 11 lines · Benoît Canet

Since we introduced node_name for named bs of the graph modify the opening by reference to use it as a fallback.

This patch also enforce the separation of the device id and graph node namespaces.

---
  block.c    | 10 ++++++++--
  blockdev.c |  6 ++++++
  2 files changed, 14 insertions(+), 2 deletions(-)
#5 lore raw
In reply to Benoît Canet

[ CC Stefan ]

Am 12.02.2014 um 17:15 hat Benoît Canet geschrieben:

Quoted 5 lines

This series was asked by Kevin.
It sit on top of the snapshot fix patch and max openv2 series.

I have done the following tests.

Quoted 8 lines

check qemu-iotest ok
snapshot blockbackend by id ok
open quorum by node-name reference and id reference ok Error messages seems ok

Benoît Canet (2):
block: Relax bdrv_lookup_bs constraints.
block: Open by reference will try device then node_name.

Very nice! Haven't reviewed it in detail, but you got the review from Max, which should be good enough for Stefan to merge it.

Kevin

#6 lore raw
In reply to Benoît Canet
Quoted 10 lines · Benoît Canet

This series was asked by Kevin.
It sit on top of the snapshot fix patch and max openv2 series.

I have done the following tests.

check qemu-iotest ok
snapshot blockbackend by id ok
open quorum by node-name reference and id reference ok Error messages seems ok

Quoted 12 lines

Benoît Canet (2):
block: Relax bdrv_lookup_bs constraints.
block: Open by reference will try device then node_name.

 block.c    | 36 +++++++++++++++++++-----------------
 blockdev.c |  6 ++++++
 2 files changed, 25 insertions(+), 17 deletions(-)
Signature · 1 line
1.8.3.2

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan