mirror of
https://github.com/qemu/qemu.git
synced 2025-08-14 20:31:47 +00:00
block: Ignore duplicate or NULL format_name in bdrv_iterate_format
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 <jcody@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
5f6979cba9
commit
e855e4fb7b
15
block.c
15
block.c
@ -3601,11 +3601,26 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
|
|||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
BlockDriver *drv;
|
BlockDriver *drv;
|
||||||
|
int count = 0;
|
||||||
|
const char **formats = NULL;
|
||||||
|
|
||||||
QLIST_FOREACH(drv, &bdrv_drivers, list) {
|
QLIST_FOREACH(drv, &bdrv_drivers, list) {
|
||||||
|
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);
|
it(opaque, drv->format_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
g_free(formats);
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is to find block backend bs */
|
/* This function is to find block backend bs */
|
||||||
BlockDriverState *bdrv_find(const char *name)
|
BlockDriverState *bdrv_find(const char *name)
|
||||||
|
Loading…
Reference in New Issue
Block a user