diff mbox

[v3,2/4] block: auto-generated node-names

Message ID cb38aeceb10a0499590ec0f15d221c3d81adb786.1444691409.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody Oct. 12, 2015, 11:36 p.m. UTC
If a node-name is not specified, automatically generate the node-name.

Generated node-names will use the "block" sub-system identifier.

Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Markus Armbruster Oct. 13, 2015, 7:39 a.m. UTC | #1
Jeff Cody <jcody@redhat.com> writes:

> If a node-name is not specified, automatically generate the node-name.
>
> Generated node-names will use the "block" sub-system identifier.
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: John Snow <jsnow@redhat.com>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/block.c b/block.c
> index 1f90b47..5947704 100644
> --- a/block.c
> +++ b/block.c
> @@ -763,12 +763,15 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
>                                    const char *node_name,
>                                    Error **errp)
>  {
> +    char *gen_node_name = NULL;
> +
>      if (!node_name) {
> -        return;
> -    }
> -
> -    /* Check for empty string or invalid characters */
> -    if (!id_wellformed(node_name)) {
> +        node_name = gen_node_name = id_generate(ID_BLOCK);
> +    } else if (!id_wellformed(node_name)) {
> +        /*
> +         * Check for empty string or invalid characters, but not if it is
> +         * generated (generated names use characters not available to the user)
> +         */
>          error_setg(errp, "Invalid node name");
>          return;
>      }

I'd drop the comment, as the code is obvious enough now.  Could be done
on commit.

> @@ -777,18 +780,20 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
>      if (blk_by_name(node_name)) {
>          error_setg(errp, "node-name=%s is conflicting with a device id",
>                     node_name);
> -        return;
> +        goto out;
>      }
>  
>      /* takes care of avoiding duplicates node names */
>      if (bdrv_find_node(node_name)) {
>          error_setg(errp, "Duplicate node name");
> -        return;
> +        goto out;
>      }
>  
>      /* copy node name into the bs and insert it into the graph list */
>      pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
>      QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
> +out:
> +    g_free(gen_node_name);
>  }
>  
>  static QemuOptsList bdrv_runtime_opts = {

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index 1f90b47..5947704 100644
--- a/block.c
+++ b/block.c
@@ -763,12 +763,15 @@  static void bdrv_assign_node_name(BlockDriverState *bs,
                                   const char *node_name,
                                   Error **errp)
 {
+    char *gen_node_name = NULL;
+
     if (!node_name) {
-        return;
-    }
-
-    /* Check for empty string or invalid characters */
-    if (!id_wellformed(node_name)) {
+        node_name = gen_node_name = id_generate(ID_BLOCK);
+    } else if (!id_wellformed(node_name)) {
+        /*
+         * Check for empty string or invalid characters, but not if it is
+         * generated (generated names use characters not available to the user)
+         */
         error_setg(errp, "Invalid node name");
         return;
     }
@@ -777,18 +780,20 @@  static void bdrv_assign_node_name(BlockDriverState *bs,
     if (blk_by_name(node_name)) {
         error_setg(errp, "node-name=%s is conflicting with a device id",
                    node_name);
-        return;
+        goto out;
     }
 
     /* takes care of avoiding duplicates node names */
     if (bdrv_find_node(node_name)) {
         error_setg(errp, "Duplicate node name");
-        return;
+        goto out;
     }
 
     /* copy node name into the bs and insert it into the graph list */
     pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
     QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
+out:
+    g_free(gen_node_name);
 }
 
 static QemuOptsList bdrv_runtime_opts = {