提交 ada42401 编写于 作者: S Stefan Hajnoczi

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: NStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: NBenoît Canet <benoit.canet@nodalink.com>
上级 6d0de8eb
...@@ -3744,11 +3744,17 @@ const char *bdrv_get_format_name(BlockDriverState *bs) ...@@ -3744,11 +3744,17 @@ const char *bdrv_get_format_name(BlockDriverState *bs)
return bs->drv ? bs->drv->format_name : NULL; 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 bdrv_iterate_format(void (*it)(void *opaque, const char *name),
void *opaque) void *opaque)
{ {
BlockDriver *drv; BlockDriver *drv;
int count = 0; int count = 0;
int i;
const char **formats = NULL; const char **formats = NULL;
QLIST_FOREACH(drv, &bdrv_drivers, list) { QLIST_FOREACH(drv, &bdrv_drivers, list) {
...@@ -3762,10 +3768,16 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name), ...@@ -3762,10 +3768,16 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
if (!found) { if (!found) {
formats = g_renew(const char *, formats, count + 1); formats = g_renew(const char *, formats, count + 1);
formats[count++] = drv->format_name; 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); g_free(formats);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册