qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message
@ 2014-05-05 16:53 Mike Day
  2014-05-06  3:05 ` Fam Zheng
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mike Day @ 2014-05-05 16:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Mike Day, stefanha

The help message for qemu-img lists the supported block formats, of
which there are 27 as of version 2.0.50. The formats are printed in
the order of their driver's position in a linked list, which appears
random. This patch prints the formats in sorted order, making it
easier to read and to find a specific format in the list.

v2: Incorporated feedback from Stefan Hajnoczi

Signed-off-by: Mike Day <ncmike@ncultra.org>
---
 qemu-img.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 96f4463..a559108 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -32,6 +32,7 @@
 #include "block/block_int.h"
 #include "block/qapi.h"
 #include <getopt.h>
+#include <glib.h>
 
 #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \
                           ", Copyright (c) 2004-2008 Fabrice Bellard\n"
@@ -55,9 +56,25 @@ typedef enum OutputFormat {
 #define BDRV_O_FLAGS BDRV_O_CACHE_WB
 #define BDRV_DEFAULT_CACHE "writeback"
 
-static void format_print(void *opaque, const char *name)
+static gint compare_data(gconstpointer a, gconstpointer b, gpointer user)
 {
-    printf(" %s", name);
+    return g_strcmp0(a, b);
+}
+
+static void print_format(gpointer data, gpointer user)
+{
+    printf(" %s", (char *)data);
+}
+
+static void add_format_to_seq(void *opaque, const char *fmt_name)
+{
+    GSequence *seq = (GSequence *)opaque;
+
+    if (!g_sequence_lookup(seq, (gpointer)fmt_name,
+                           compare_data, NULL)) {
+        g_sequence_insert_sorted(seq, (gpointer)fmt_name,
+                                 compare_data, NULL);
+    }
 }
 
 static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
@@ -144,8 +161,12 @@ static void QEMU_NORETURN help(void)
            "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
 
     printf("%s\nSupported formats:", help_msg);
-    bdrv_iterate_format(format_print, NULL);
+    GSequence *seq = g_sequence_new(NULL);
+    bdrv_iterate_format(add_format_to_seq, seq);
+    g_sequence_foreach(seq, print_format, NULL);
     printf("\n");
+    g_sequence_free(seq);
+
     exit(EXIT_SUCCESS);
 }
 
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message
  2014-05-05 16:53 [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message Mike Day
@ 2014-05-06  3:05 ` Fam Zheng
  2014-05-06 11:30 ` Stefan Hajnoczi
  2014-05-16 13:59 ` Laurent Desnogues
  2 siblings, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2014-05-06  3:05 UTC (permalink / raw)
  To: Mike Day; +Cc: kwolf, qemu-devel, stefanha

On Mon, 05/05 12:53, Mike Day wrote:
> The help message for qemu-img lists the supported block formats, of
> which there are 27 as of version 2.0.50. The formats are printed in
> the order of their driver's position in a linked list, which appears
> random. This patch prints the formats in sorted order, making it
> easier to read and to find a specific format in the list.
> 

Revision note should go below --- , so the line won't get into the commit log
when maintainers apply the patch, like:

> 
> Signed-off-by: Mike Day <ncmike@ncultra.org>
> ---

v2: Incorporated feedback from Stefan Hajnoczi

>  qemu-img.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 96f4463..a559108 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -32,6 +32,7 @@
>  #include "block/block_int.h"
>  #include "block/qapi.h"
>  #include <getopt.h>
> +#include <glib.h>
>  
>  #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \
>                            ", Copyright (c) 2004-2008 Fabrice Bellard\n"
> @@ -55,9 +56,25 @@ typedef enum OutputFormat {
>  #define BDRV_O_FLAGS BDRV_O_CACHE_WB
>  #define BDRV_DEFAULT_CACHE "writeback"
>  
> -static void format_print(void *opaque, const char *name)
> +static gint compare_data(gconstpointer a, gconstpointer b, gpointer user)
>  {
> -    printf(" %s", name);
> +    return g_strcmp0(a, b);
> +}
> +
> +static void print_format(gpointer data, gpointer user)
> +{
> +    printf(" %s", (char *)data);
> +}
> +
> +static void add_format_to_seq(void *opaque, const char *fmt_name)
> +{
> +    GSequence *seq = (GSequence *)opaque;

Stefan pointed in comments for v1:

       GSequence *seq = opaque;

> +
> +    if (!g_sequence_lookup(seq, (gpointer)fmt_name,
> +                           compare_data, NULL)) {
> +        g_sequence_insert_sorted(seq, (gpointer)fmt_name,
> +                                 compare_data, NULL);
> +    }
>  }
>  
>  static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
> @@ -144,8 +161,12 @@ static void QEMU_NORETURN help(void)
>             "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
>  
>      printf("%s\nSupported formats:", help_msg);
> -    bdrv_iterate_format(format_print, NULL);
> +    GSequence *seq = g_sequence_new(NULL);

Let's put this variable declaration above statements, or move the printf above
down.

Thanks,
Fam

> +    bdrv_iterate_format(add_format_to_seq, seq);
> +    g_sequence_foreach(seq, print_format, NULL);
>      printf("\n");
> +    g_sequence_free(seq);
> +
>      exit(EXIT_SUCCESS);
>  }
>  
> -- 
> 1.9.0
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message
  2014-05-05 16:53 [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message Mike Day
  2014-05-06  3:05 ` Fam Zheng
@ 2014-05-06 11:30 ` Stefan Hajnoczi
  2014-05-16 13:59 ` Laurent Desnogues
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-05-06 11:30 UTC (permalink / raw)
  To: Mike Day; +Cc: kwolf, Fam Zheng, qemu-devel

On Mon, May 05, 2014 at 12:53:34PM -0400, Mike Day wrote:
> The help message for qemu-img lists the supported block formats, of
> which there are 27 as of version 2.0.50. The formats are printed in
> the order of their driver's position in a linked list, which appears
> random. This patch prints the formats in sorted order, making it
> easier to read and to find a specific format in the list.
> 
> v2: Incorporated feedback from Stefan Hajnoczi
> 
> Signed-off-by: Mike Day <ncmike@ncultra.org>
> ---
>  qemu-img.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)

Thanks, applied to my block tree with Fam's suggestions squashed in:
https://github.com/stefanha/qemu/commits/block

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message
  2014-05-05 16:53 [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message Mike Day
  2014-05-06  3:05 ` Fam Zheng
  2014-05-06 11:30 ` Stefan Hajnoczi
@ 2014-05-16 13:59 ` Laurent Desnogues
  2014-05-16 14:12   ` Mike Day
  2 siblings, 1 reply; 5+ messages in thread
From: Laurent Desnogues @ 2014-05-16 13:59 UTC (permalink / raw)
  To: Mike Day; +Cc: Kevin Wolf, qemu-devel@nongnu.org, Stefan Hajnoczi

Hi,

just noticed the use of some too recent glib features: g_strcmp0
and GSequence related ones.

Thanks,

Laurent

On Mon, May 5, 2014 at 6:53 PM, Mike Day <ncmike@ncultra.org> wrote:
> The help message for qemu-img lists the supported block formats, of
> which there are 27 as of version 2.0.50. The formats are printed in
> the order of their driver's position in a linked list, which appears
> random. This patch prints the formats in sorted order, making it
> easier to read and to find a specific format in the list.
>
> v2: Incorporated feedback from Stefan Hajnoczi
>
> Signed-off-by: Mike Day <ncmike@ncultra.org>
> ---
>  qemu-img.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 96f4463..a559108 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -32,6 +32,7 @@
>  #include "block/block_int.h"
>  #include "block/qapi.h"
>  #include <getopt.h>
> +#include <glib.h>
>
>  #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \
>                            ", Copyright (c) 2004-2008 Fabrice Bellard\n"
> @@ -55,9 +56,25 @@ typedef enum OutputFormat {
>  #define BDRV_O_FLAGS BDRV_O_CACHE_WB
>  #define BDRV_DEFAULT_CACHE "writeback"
>
> -static void format_print(void *opaque, const char *name)
> +static gint compare_data(gconstpointer a, gconstpointer b, gpointer user)
>  {
> -    printf(" %s", name);
> +    return g_strcmp0(a, b);
> +}
> +
> +static void print_format(gpointer data, gpointer user)
> +{
> +    printf(" %s", (char *)data);
> +}
> +
> +static void add_format_to_seq(void *opaque, const char *fmt_name)
> +{
> +    GSequence *seq = (GSequence *)opaque;
> +
> +    if (!g_sequence_lookup(seq, (gpointer)fmt_name,
> +                           compare_data, NULL)) {
> +        g_sequence_insert_sorted(seq, (gpointer)fmt_name,
> +                                 compare_data, NULL);
> +    }
>  }
>
>  static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
> @@ -144,8 +161,12 @@ static void QEMU_NORETURN help(void)
>             "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
>
>      printf("%s\nSupported formats:", help_msg);
> -    bdrv_iterate_format(format_print, NULL);
> +    GSequence *seq = g_sequence_new(NULL);
> +    bdrv_iterate_format(add_format_to_seq, seq);
> +    g_sequence_foreach(seq, print_format, NULL);
>      printf("\n");
> +    g_sequence_free(seq);
> +
>      exit(EXIT_SUCCESS);
>  }
>
> --
> 1.9.0
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message
  2014-05-16 13:59 ` Laurent Desnogues
@ 2014-05-16 14:12   ` Mike Day
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Day @ 2014-05-16 14:12 UTC (permalink / raw)
  To: Laurent Desnogues; +Cc: Kevin Wolf, qemu-devel@nongnu.org, Stefan Hajnoczi

On Fri, May 16, 2014 at 9:59 AM, Laurent Desnogues
<laurent.desnogues@gmail.com> wrote:
>
> just noticed the use of some too recent glib features: g_strcmp0
> and GSequence related ones.

There is a patch upstream that removes g_sequence_lookup, which was
not linking on one platform. I haven't seen any other reports of
breakage. g_strcmp would be trivial to replace, of course.

thanks!

Mike

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-05-16 14:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-05 16:53 [Qemu-devel] [PATCH] [v2 PATCH] qemu-img: sort block formats in help message Mike Day
2014-05-06  3:05 ` Fam Zheng
2014-05-06 11:30 ` Stefan Hajnoczi
2014-05-16 13:59 ` Laurent Desnogues
2014-05-16 14:12   ` Mike Day

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).