From ceff5bd79cdf94c650902fe9a20d316dcbfa1cc9 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Wed, 12 Oct 2016 22:49:05 +0200 Subject: block: Fix bdrv_iterate_format() sorting bdrv_iterate_format() did not actually sort the formats by name but by "pointer interpreted as string". That is probably not what we intended to do, so fix it (by changing qsort_strcmp() so it matches the example from qsort()'s manual page). Signed-off-by: Max Reitz Message-id: 20161012204907.25941-2-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'block.c') diff --git a/block.c b/block.c index c19c6c6d42..67c70c1010 100644 --- a/block.c +++ b/block.c @@ -2796,7 +2796,7 @@ const char *bdrv_get_format_name(BlockDriverState *bs) static int qsort_strcmp(const void *a, const void *b) { - return strcmp(a, b); + return strcmp(*(char *const *)a, *(char *const *)b); } void bdrv_iterate_format(void (*it)(void *opaque, const char *name), -- cgit 1.4.1 From eb0df69f50bd64454bcb9457e875cd52f00dced8 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Wed, 12 Oct 2016 22:49:06 +0200 Subject: block: Emit modules in bdrv_iterate_format() Some block drivers may not be loaded yet, but qemu supports them nonetheless. bdrv_iterate_format() should report them, too. Signed-off-by: Max Reitz Message-id: 20161012204907.25941-3-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- block.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'block.c') diff --git a/block.c b/block.c index 67c70c1010..39ddea3411 100644 --- a/block.c +++ b/block.c @@ -2822,6 +2822,24 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name), } } + for (i = 0; i < (int)ARRAY_SIZE(block_driver_modules); i++) { + const char *format_name = block_driver_modules[i].format_name; + + if (format_name) { + bool found = false; + int j = count; + + while (formats && j && !found) { + found = !strcmp(formats[--j], format_name); + } + + if (!found) { + formats = g_renew(const char *, formats, count + 1); + formats[count++] = format_name; + } + } + } + qsort(formats, count, sizeof(formats[0]), qsort_strcmp); for (i = 0; i < count; i++) { -- cgit 1.4.1