diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2015-10-17 22:14:52 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2015-10-17 22:14:52 +0100 |
commit | c737c7a608f4cd2c06e6600303845c4b469822c5 (patch) | |
tree | 062bb9ec0082a16928572cb7ff0a039d79de93bb /util | |
parent | 6d57410a79d51d92673c54f26624b44f27fa6214 (diff) | |
parent | 6b826af7b010ed1963b1e7bfb5c389dcdbaff222 (diff) | |
download | qemu-c737c7a608f4cd2c06e6600303845c4b469822c5.zip qemu-c737c7a608f4cd2c06e6600303845c4b469822c5.tar.gz qemu-c737c7a608f4cd2c06e6600303845c4b469822c5.tar.bz2 |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches
# gpg: Signature made Fri 16 Oct 2015 14:36:50 BST using RSA key ID C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
* remotes/kevin/tags/for-upstream: (29 commits)
blkdebug: Don't confuse image as backing file
qcow2: Remove forward declaration of QCowAIOCB
qemu-nbd: always compile in --aio=MODE option
blockdev: always compile in -drive aio= parsing
raw-posix: warn about BDRV_O_NATIVE_AIO if libaio is unavailable
block: auto-generated node-names
util - add automated ID generation utility
blkverify: Fix BDS leak in .bdrv_open error path
block: Allow bdrv_unref_child(bs, NULL)
block: Remove bdrv_swap()
block: Add and use bdrv_replace_in_backing_chain()
blockjob: Store device name at job creation
block: Implement bdrv_append() without bdrv_swap()
block: Introduce parents list
block-backend: Add blk_set_bs()
block/io: Make bdrv_requests_pending() public
block: Split bdrv_move_feature_fields()
block: Manage backing file references in bdrv_set_backing_hd()
block: Convert bs->backing_hd to BdrvChild
block: Remove bdrv_open_image()
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/id.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -26,3 +26,40 @@ bool id_wellformed(const char *id) } return true; } + +#define ID_SPECIAL_CHAR '#' + +static const char *const id_subsys_str[] = { + [ID_QDEV] = "qdev", + [ID_BLOCK] = "block", +}; + +/* + * Generates an ID of the form PREFIX SUBSYSTEM NUMBER + * where: + * + * - PREFIX is the reserved character '#' + * - SUBSYSTEM identifies the subsystem creating the ID + * - NUMBER is a decimal number unique within SUBSYSTEM. + * + * Example: "#block146" + * + * Note that these IDs do not satisfy id_wellformed(). + * + * The caller is responsible for freeing the returned string with g_free() + */ +char *id_generate(IdSubSystems id) +{ + static uint64_t id_counters[ID_MAX]; + uint32_t rnd; + + assert(id < ID_MAX); + assert(id_subsys_str[id]); + + rnd = g_random_int_range(0, 100); + + return g_strdup_printf("%c%s%" PRIu64 "%02" PRId32, ID_SPECIAL_CHAR, + id_subsys_str[id], + id_counters[id]++, + rnd); +} |