aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2014-08-27 12:08:55 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2014-08-28 13:42:25 +0100
commitada4240103470371533967334cda9965854fcbda (patch)
tree94253097d4959afff61ae330bd35ae64902162d5 /block.c
parent6d0de8eb21b7a581999ca89a9b447fd1c91e23db (diff)
downloadqemu-ada4240103470371533967334cda9965854fcbda.zip
qemu-ada4240103470371533967334cda9965854fcbda.tar.gz
qemu-ada4240103470371533967334cda9965854fcbda.tar.bz2
block: sort formats alphabetically in bdrv_iterate_format()
Format names are best consumed in alphabetical order. This makes human-readable output easy to produce. bdrv_iterate_format() already has an array of format strings. Sort them before invoking the iteration callback. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/block.c b/block.c
index e9380f6..1df13ac 100644
--- a/block.c
+++ b/block.c
@@ -3744,11 +3744,17 @@ const char *bdrv_get_format_name(BlockDriverState *bs)
return bs->drv ? bs->drv->format_name : NULL;
}
+static int qsort_strcmp(const void *a, const void *b)
+{
+ return strcmp(a, b);
+}
+
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
void *opaque)
{
BlockDriver *drv;
int count = 0;
+ int i;
const char **formats = NULL;
QLIST_FOREACH(drv, &bdrv_drivers, list) {
@@ -3762,10 +3768,16 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
if (!found) {
formats = g_renew(const char *, formats, count + 1);
formats[count++] = drv->format_name;
- it(opaque, drv->format_name);
}
}
}
+
+ qsort(formats, count, sizeof(formats[0]), qsort_strcmp);
+
+ for (i = 0; i < count; i++) {
+ it(opaque, formats[i]);
+ }
+
g_free(formats);
}