[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/31] block: Ignore duplicate or NULL format_name in
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 04/31] block: Ignore duplicate or NULL format_name in bdrv_iterate_format |
Date: |
Wed, 30 Apr 2014 20:23:36 +0200 |
From: Jeff Cody <address@hidden>
Some block drivers have multiple BlockDriver instances with identical
format_name fields (e.g. gluster, nbd).
Both qemu-img and qemu will use bdrv_iterate_format() to list the
supported formats when a help option is invoked. As protocols and
formats may register multiple drivers, redundant listings of formats
occur (e.g., "Supported formats: ... gluster gluster gluster gluster ...
").
Since the list of driver formats will be small, this performs a simple
linear search on format_name, and ignores any duplicates.
The end result change is that the iterator will no longer receive
duplicate string names, nor will it receive NULL pointers.
Signed-off-by: Jeff Cody <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 4745712..100fa86 100644
--- a/block.c
+++ b/block.c
@@ -3601,10 +3601,25 @@ void bdrv_iterate_format(void (*it)(void *opaque, const
char *name),
void *opaque)
{
BlockDriver *drv;
+ int count = 0;
+ const char **formats = NULL;
QLIST_FOREACH(drv, &bdrv_drivers, list) {
- it(opaque, drv->format_name);
+ if (drv->format_name) {
+ bool found = false;
+ int i = count;
+ while (formats && i && !found) {
+ found = !strcmp(formats[--i], drv->format_name);
+ }
+
+ if (!found) {
+ formats = g_realloc(formats, (count + 1) * sizeof(char *));
+ formats[count++] = drv->format_name;
+ it(opaque, drv->format_name);
+ }
+ }
}
+ g_free(formats);
}
/* This function is to find block backend bs */
--
1.8.3.1
- [Qemu-devel] [PULL 00/31] Block patches, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 01/31] block: fix qemu-img --help invocation, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 02/31] mirror: Use DIV_ROUND_UP, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 03/31] block: Add '--version' option to qemu-img, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 04/31] block: Ignore duplicate or NULL format_name in bdrv_iterate_format,
Kevin Wolf <=
- [Qemu-devel] [PULL 07/31] block: qemu-iotests - fix image cleanup when using spaced pathnames, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 06/31] mirror: Check for bdrv_get_info result, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 08/31] block: qemu-iotests: make test 019 and 086 work with spaced pathnames, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 05/31] mirror: Fix resource leak when bdrv_getlength fails, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 10/31] iotests: Discarding compressed clusters on qcow2, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 09/31] qcow2: Fix discard, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 11/31] block: Create bdrv_inherited_flags(), Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 12/31] block: Create bdrv_backing_flags(), Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 13/31] block: Remove BDRV_O_COPY_ON_READ for bs->file, Kevin Wolf, 2014/04/30
- [Qemu-devel] [PULL 14/31] block: Unlink temporary files in raw-posix/win32, Kevin Wolf, 2014/04/30