[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [Qemu-block] [PATCHv2 for-2.4] block: Auto-generate nod
From: |
Alberto Garcia |
Subject: |
Re: [Qemu-devel] [Qemu-block] [PATCHv2 for-2.4] block: Auto-generate node_names for each BDS entry |
Date: |
Tue, 23 Jun 2015 09:14:07 +0200 |
User-agent: |
Notmuch/0.13.2 (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu) |
On Tue 23 Jun 2015 01:10:39 AM CEST, Eric Blake <address@hidden> wrote:
> +#define GEN_NODE_NAME_PREFIX "__qemu##"
> +#define GEN_NODE_NAME_MAX_LEN (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
> static void bdrv_assign_node_name(BlockDriverState *bs,
> const char *node_name,
> Error **errp)
> {
> + char gen_node_name[GEN_NODE_NAME_MAX_LEN];
> + static uint32_t counter; /* simple counter to guarantee uniqueness */
Any reason why you use uint32_t instead of just unsigned ?
> - if (!id_wellformed(node_name)) {
> + int len;
> + snprintf(gen_node_name, GEN_NODE_NAME_MAX_LEN,
> + "%s%08x", GEN_NODE_NAME_PREFIX, counter++);
> + len = strlen(gen_node_name);
No need to use strlen() here, snprintf() already returns the number of
characters written.
> + while (len < GEN_NODE_NAME_MAX_LEN - 1) {
> + gen_node_name[len++] = g_random_int_range('A', 'Z');
> + }
I think this doesn't include the 'Z', the upper bound of the interval is
open.
Berto