diff mbox series

[2/6] char: Factor out qemu_chr_print_types()

Message ID 20201023101222.250147-3-kwolf@redhat.com
State New
Headers show
Series qemu-storage-daemon: QAPIfy --chardev | expand

Commit Message

Kevin Wolf Oct. 23, 2020, 10:12 a.m. UTC
We'll want to call the same from a non-QemuOpts code path.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/chardev/char.h |  1 +
 chardev/char.c         | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

Marc-André Lureau Oct. 23, 2020, 10:38 a.m. UTC | #1
On Fri, Oct 23, 2020 at 2:14 PM Kevin Wolf <kwolf@redhat.com> wrote:

> We'll want to call the same from a non-QemuOpts code path.

>

> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

> ---

>  include/chardev/char.h |  1 +

>  chardev/char.c         | 17 +++++++++++------

>  2 files changed, 12 insertions(+), 6 deletions(-)

>

> diff --git a/include/chardev/char.h b/include/chardev/char.h

> index db42f0a8c6..3b91645081 100644

> --- a/include/chardev/char.h

> +++ b/include/chardev/char.h

> @@ -212,6 +212,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s,

>   */

>  void qemu_chr_be_event(Chardev *s, QEMUChrEvent event);

>

> +void qemu_chr_print_types(void);

>  int qemu_chr_add_client(Chardev *s, int fd);

>  Chardev *qemu_chr_find(const char *name);

>

> diff --git a/chardev/char.c b/chardev/char.c

> index 78553125d3..028612c333 100644

> --- a/chardev/char.c

> +++ b/chardev/char.c

> @@ -633,6 +633,16 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts,

> Error **errp)

>      return backend;

>  }

>

> +void qemu_chr_print_types(void)

> +{

> +    GString *str = g_string_new("");

>


Suggest g_auto here

+
> +    chardev_name_foreach(help_string_append, str);

> +

> +    qemu_printf("Available chardev backend types: %s\n", str->str);

> +    g_string_free(str, true);

> +}

> +

>  Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,

>                                  Error **errp)

>  {

> @@ -644,12 +654,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,

> GMainContext *context,

>      char *bid = NULL;

>

>      if (name && is_help_option(name)) {

> -        GString *str = g_string_new("");

> -

> -        chardev_name_foreach(help_string_append, str);

> -

> -        qemu_printf("Available chardev backend types: %s\n", str->str);

> -        g_string_free(str, true);

> +        qemu_chr_print_types();

>          return NULL;

>      }

>

> --

> 2.28.0

>

>

>

anyway
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


-- 
Marc-André Lureau
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 23, 2020 at 2:14 PM Kevin Wolf &lt;<a href="mailto:kwolf@redhat.com">kwolf@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We&#39;ll want to call the same from a non-QemuOpts code path.<br>
<br>
Signed-off-by: Kevin Wolf &lt;<a href="mailto:kwolf@redhat.com" target="_blank">kwolf@redhat.com</a>&gt;<br>

---<br>
 include/chardev/char.h |  1 +<br>
 chardev/char.c         | 17 +++++++++++------<br>
 2 files changed, 12 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/include/chardev/char.h b/include/chardev/char.h<br>
index db42f0a8c6..3b91645081 100644<br>
--- a/include/chardev/char.h<br>
+++ b/include/chardev/char.h<br>
@@ -212,6 +212,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s,<br>
  */<br>
 void qemu_chr_be_event(Chardev *s, QEMUChrEvent event);<br>
<br>
+void qemu_chr_print_types(void);<br>
 int qemu_chr_add_client(Chardev *s, int fd);<br>
 Chardev *qemu_chr_find(const char *name);<br>
<br>
diff --git a/chardev/char.c b/chardev/char.c<br>
index 78553125d3..028612c333 100644<br>
--- a/chardev/char.c<br>
+++ b/chardev/char.c<br>
@@ -633,6 +633,16 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)<br>
     return backend;<br>
 }<br>
<br>
+void qemu_chr_print_types(void)<br>
+{<br>
+    GString *str = g_string_new(&quot;&quot;);<br></blockquote><div><br></div><div>Suggest g_auto here</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+    chardev_name_foreach(help_string_append, str);<br>
+<br>
+    qemu_printf(&quot;Available chardev backend types: %s\n&quot;, str-&gt;str);<br>
+    g_string_free(str, true);<br>
+}<br>
+<br>
 Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,<br>
                                 Error **errp)<br>
 {<br>
@@ -644,12 +654,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,<br>
     char *bid = NULL;<br>
<br>
     if (name &amp;&amp; is_help_option(name)) {<br>
-        GString *str = g_string_new(&quot;&quot;);<br>
-<br>
-        chardev_name_foreach(help_string_append, str);<br>
-<br>
-        qemu_printf(&quot;Available chardev backend types: %s\n&quot;, str-&gt;str);<br>
-        g_string_free(str, true);<br>
+        qemu_chr_print_types();<br>
         return NULL;<br>
     }<br>
<br>
-- <br>
2.28.0<br>
<br>
<br>
</blockquote></div><br clear="all"><div>anyway<br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;</div><div> </div><br>-- <br><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>
Markus Armbruster Oct. 23, 2020, 12:15 p.m. UTC | #2
Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> On Fri, Oct 23, 2020 at 2:14 PM Kevin Wolf <kwolf@redhat.com> wrote:

>

>> We'll want to call the same from a non-QemuOpts code path.

>>

>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

>> ---

>>  include/chardev/char.h |  1 +

>>  chardev/char.c         | 17 +++++++++++------

>>  2 files changed, 12 insertions(+), 6 deletions(-)

>>

>> diff --git a/include/chardev/char.h b/include/chardev/char.h

>> index db42f0a8c6..3b91645081 100644

>> --- a/include/chardev/char.h

>> +++ b/include/chardev/char.h

>> @@ -212,6 +212,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s,

>>   */

>>  void qemu_chr_be_event(Chardev *s, QEMUChrEvent event);

>>

>> +void qemu_chr_print_types(void);

>>  int qemu_chr_add_client(Chardev *s, int fd);

>>  Chardev *qemu_chr_find(const char *name);

>>

>> diff --git a/chardev/char.c b/chardev/char.c

>> index 78553125d3..028612c333 100644

>> --- a/chardev/char.c

>> +++ b/chardev/char.c

>> @@ -633,6 +633,16 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts,

>> Error **errp)

>>      return backend;

>>  }

>>

>> +void qemu_chr_print_types(void)

>> +{

>> +    GString *str = g_string_new("");

>>

>

> Suggest g_auto here


g_autoptr(GList) str = ..., I presume.

> +

>> +    chardev_name_foreach(help_string_append, str);

>> +

>> +    qemu_printf("Available chardev backend types: %s\n", str->str);

>> +    g_string_free(str, true);

>> +}

>> +

>>  Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,

>>                                  Error **errp)

>>  {

>> @@ -644,12 +654,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,

>> GMainContext *context,

>>      char *bid = NULL;

>>

>>      if (name && is_help_option(name)) {

>> -        GString *str = g_string_new("");

>> -

>> -        chardev_name_foreach(help_string_append, str);

>> -

>> -        qemu_printf("Available chardev backend types: %s\n", str->str);

>> -        g_string_free(str, true);

>> +        qemu_chr_print_types();

>>          return NULL;

>>      }

>>

>> --

>> 2.28.0

>>

>>

>>

> anyway

> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox series

Patch

diff --git a/include/chardev/char.h b/include/chardev/char.h
index db42f0a8c6..3b91645081 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -212,6 +212,7 @@  void qemu_chr_be_update_read_handlers(Chardev *s,
  */
 void qemu_chr_be_event(Chardev *s, QEMUChrEvent event);
 
+void qemu_chr_print_types(void);
 int qemu_chr_add_client(Chardev *s, int fd);
 Chardev *qemu_chr_find(const char *name);
 
diff --git a/chardev/char.c b/chardev/char.c
index 78553125d3..028612c333 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -633,6 +633,16 @@  ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
     return backend;
 }
 
+void qemu_chr_print_types(void)
+{
+    GString *str = g_string_new("");
+
+    chardev_name_foreach(help_string_append, str);
+
+    qemu_printf("Available chardev backend types: %s\n", str->str);
+    g_string_free(str, true);
+}
+
 Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,
                                 Error **errp)
 {
@@ -644,12 +654,7 @@  Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,
     char *bid = NULL;
 
     if (name && is_help_option(name)) {
-        GString *str = g_string_new("");
-
-        chardev_name_foreach(help_string_append, str);
-
-        qemu_printf("Available chardev backend types: %s\n", str->str);
-        g_string_free(str, true);
+        qemu_chr_print_types();
         return NULL;
     }