diff mbox

[7/7] block: dump to monitor for bdrv_snapshot_dump() and bdrv_image_info_dump()

Message ID 1366968675-1451-8-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia April 26, 2013, 9:31 a.m. UTC
This patch introduce a new print function, which will output message to
monitor when it present. With it, bdrv_snapshot_dump() need no more buffer
and can avoid string truncation, bdrv_image_info_dump() can also be used by
hmp code later, besides qemu-img code.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 block/qapi.c                |   60 ++++++++++++++++++++++--------------------
 include/block/qapi.h        |    2 +-
 include/qemu/error-report.h |    1 +
 qemu-img.c                  |    7 +++--
 savevm.c                    |    7 +++--
 util/qemu-error.c           |   18 +++++++++++++
 6 files changed, 59 insertions(+), 36 deletions(-)

Comments

Stefan Hajnoczi April 26, 2013, 2:46 p.m. UTC | #1
On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
>      }
>  
>      if (total > 0) {
> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
> +        bdrv_snapshot_dump(NULL);
> +        monitor_printf(mon, "\n");

Luiz: any issue with mixing monitor_printf(mon) and
monitor_vprintf(cur_mon) calls?  I guess there was a reason for
explicitly passing mon instead of relying on cur_mon.

>          for (i = 0; i < total; i++) {
>              sn = &sn_tab[available_snapshots[i]];
> -            monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
> +            bdrv_snapshot_dump(sn);
> +            monitor_printf(mon, "\n");
>          }
>      } else {
>          monitor_printf(mon, "There is no suitable snapshot available\n");
> diff --git a/util/qemu-error.c b/util/qemu-error.c
> index 08a36f4..a47bf32 100644
> --- a/util/qemu-error.c
> +++ b/util/qemu-error.c
> @@ -213,3 +213,21 @@ void error_report(const char *fmt, ...)
>      va_end(ap);
>      error_printf("\n");
>  }
> +
> +/*
> + * Print to current monitor if we have one, else to stdout. It is similar with
> + * error_printf().
> + * TODO just like error_vprintf()

TODO?
Wayne Xia April 27, 2013, 3:37 a.m. UTC | #2
于 2013-4-26 22:46, Stefan Hajnoczi 写道:
> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
>>       }
>>
>>       if (total > 0) {
>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
>> +        bdrv_snapshot_dump(NULL);
>> +        monitor_printf(mon, "\n");
>
> Luiz: any issue with mixing monitor_printf(mon) and
> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> explicitly passing mon instead of relying on cur_mon.
>
>>           for (i = 0; i < total; i++) {
>>               sn = &sn_tab[available_snapshots[i]];
>> -            monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
>> +            bdrv_snapshot_dump(sn);
>> +            monitor_printf(mon, "\n");
>>           }
>>       } else {
>>           monitor_printf(mon, "There is no suitable snapshot available\n");
>> diff --git a/util/qemu-error.c b/util/qemu-error.c
>> index 08a36f4..a47bf32 100644
>> --- a/util/qemu-error.c
>> +++ b/util/qemu-error.c
>> @@ -213,3 +213,21 @@ void error_report(const char *fmt, ...)
>>       va_end(ap);
>>       error_printf("\n");
>>   }
>> +
>> +/*
>> + * Print to current monitor if we have one, else to stdout. It is similar with
>> + * error_printf().
>> + * TODO just like error_vprintf()
>
> TODO?
>

   Same with error_vprintf's comments:
/*
  * Print to current monitor if we have one, else to stderr.
  * TODO should return int, so callers can calculate width, but that
  * requires surgery to monitor_vprintf().  Left for another day.
  */
Luiz Capitulino April 29, 2013, 7:05 p.m. UTC | #3
On Fri, 26 Apr 2013 16:46:57 +0200
Stefan Hajnoczi <stefanha@gmail.com> wrote:

> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> > @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
> >      }
> >  
> >      if (total > 0) {
> > -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
> > +        bdrv_snapshot_dump(NULL);
> > +        monitor_printf(mon, "\n");
> 
> Luiz: any issue with mixing monitor_printf(mon) and
> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> explicitly passing mon instead of relying on cur_mon.

where are they being mixed?
Wayne Xia May 2, 2013, 2:05 a.m. UTC | #4
于 2013-4-30 3:05, Luiz Capitulino 写道:
> On Fri, 26 Apr 2013 16:46:57 +0200
> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
>>>       }
>>>
>>>       if (total > 0) {
>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
>>> +        bdrv_snapshot_dump(NULL);
>>> +        monitor_printf(mon, "\n");
>>
>> Luiz: any issue with mixing monitor_printf(mon) and
>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>> explicitly passing mon instead of relying on cur_mon.
>
> where are they being mixed?
>
   bdrv_snapshot_dump() used a global variable "cur_mon" inside, instead
of let caller pass in a explicit montior* "mon", I guess that is the
question.
Luiz Capitulino May 2, 2013, 12:02 p.m. UTC | #5
On Thu, 02 May 2013 10:05:08 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> > On Fri, 26 Apr 2013 16:46:57 +0200
> > Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >
> >> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
> >>>       }
> >>>
> >>>       if (total > 0) {
> >>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
> >>> +        bdrv_snapshot_dump(NULL);
> >>> +        monitor_printf(mon, "\n");
> >>
> >> Luiz: any issue with mixing monitor_printf(mon) and
> >> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> >> explicitly passing mon instead of relying on cur_mon.
> >
> > where are they being mixed?
> >
>    bdrv_snapshot_dump() used a global variable "cur_mon" inside, instead
> of let caller pass in a explicit montior* "mon", I guess that is the
> question.

I'd have to see the code to tell, but yes, what Stefan described is the
best practice for the Monitor.
Wayne Xia May 3, 2013, 2:51 a.m. UTC | #6
于 2013-5-2 20:02, Luiz Capitulino 写道:
> On Thu, 02 May 2013 10:05:08 +0800
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>
>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>
>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
>>>>>        }
>>>>>
>>>>>        if (total > 0) {
>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
>>>>> +        bdrv_snapshot_dump(NULL);
>>>>> +        monitor_printf(mon, "\n");
>>>>
>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>> explicitly passing mon instead of relying on cur_mon.
>>>
>>> where are they being mixed?
>>>
>>     bdrv_snapshot_dump() used a global variable "cur_mon" inside, instead
>> of let caller pass in a explicit montior* "mon", I guess that is the
>> question.
>
> I'd have to see the code to tell, but yes, what Stefan described is the
> best practice for the Monitor.
>
   I think this would not be a problem until qemu wants more than one
human monitor console, and then we may require a data structure to tell
where to output the string: stdout, *mon, or even stderr, and
error_printf() also need to be changed.
Wayne Xia May 6, 2013, 2:09 a.m. UTC | #7
于 2013-5-3 10:51, Wenchao Xia 写道:
> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>> On Thu, 02 May 2013 10:05:08 +0800
>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>
>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>
>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
>>>>>> QDict *qdict)
>>>>>>        }
>>>>>>
>>>>>>        if (total > 0) {
>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>> sizeof(buf), NULL));
>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>> +        monitor_printf(mon, "\n");
>>>>>
>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>
>>>> where are they being mixed?
>>>>
>>>     bdrv_snapshot_dump() used a global variable "cur_mon" inside,
>>> instead
>>> of let caller pass in a explicit montior* "mon", I guess that is the
>>> question.
>>
>> I'd have to see the code to tell, but yes, what Stefan described is the
>> best practice for the Monitor.
>>
>    I think this would not be a problem until qemu wants more than one
> human monitor console, and then we may require a data structure to tell
> where to output the string: stdout, *mon, or even stderr, and
> error_printf() also need to be changed.
>
   Luiz, what is your idea? I'd like to respin v2 if no issues for it.
Luiz Capitulino May 6, 2013, 1:22 p.m. UTC | #8
On Mon, 06 May 2013 10:09:43 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-5-3 10:51, Wenchao Xia 写道:
> > 于 2013-5-2 20:02, Luiz Capitulino 写道:
> >> On Thu, 02 May 2013 10:05:08 +0800
> >> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>
> >>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> >>>> On Fri, 26 Apr 2013 16:46:57 +0200
> >>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >>>>
> >>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
> >>>>>> QDict *qdict)
> >>>>>>        }
> >>>>>>
> >>>>>>        if (total > 0) {
> >>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
> >>>>>> sizeof(buf), NULL));
> >>>>>> +        bdrv_snapshot_dump(NULL);
> >>>>>> +        monitor_printf(mon, "\n");
> >>>>>
> >>>>> Luiz: any issue with mixing monitor_printf(mon) and
> >>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> >>>>> explicitly passing mon instead of relying on cur_mon.
> >>>>
> >>>> where are they being mixed?
> >>>>
> >>>     bdrv_snapshot_dump() used a global variable "cur_mon" inside,
> >>> instead
> >>> of let caller pass in a explicit montior* "mon", I guess that is the
> >>> question.
> >>
> >> I'd have to see the code to tell, but yes, what Stefan described is the
> >> best practice for the Monitor.
> >>
> >    I think this would not be a problem until qemu wants more than one
> > human monitor console, and then we may require a data structure to tell
> > where to output the string: stdout, *mon, or even stderr, and
> > error_printf() also need to be changed.
> >
>    Luiz, what is your idea? I'd like to respin v2 if no issues for it.

As I said before, I'd have to see the code to tell. But answering your comment,
the code does support multiple monitors.
Wayne Xia May 15, 2013, 2:10 a.m. UTC | #9
于 2013-5-6 21:22, Luiz Capitulino 写道:
> On Mon, 06 May 2013 10:09:43 +0800
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>
>> 于 2013-5-3 10:51, Wenchao Xia 写道:
>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>>>> On Thu, 02 May 2013 10:05:08 +0800
>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>
>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>>>
>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
>>>>>>>> QDict *qdict)
>>>>>>>>         }
>>>>>>>>
>>>>>>>>         if (total > 0) {
>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>>>> sizeof(buf), NULL));
>>>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>>>> +        monitor_printf(mon, "\n");
>>>>>>>
>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>>>
>>>>>> where are they being mixed?
>>>>>>
>>>>>      bdrv_snapshot_dump() used a global variable "cur_mon" inside,
>>>>> instead
>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
>>>>> question.
>>>>
>>>> I'd have to see the code to tell, but yes, what Stefan described is the
>>>> best practice for the Monitor.
>>>>
>>>     I think this would not be a problem until qemu wants more than one
>>> human monitor console, and then we may require a data structure to tell
>>> where to output the string: stdout, *mon, or even stderr, and
>>> error_printf() also need to be changed.
>>>
>>     Luiz, what is your idea? I'd like to respin v2 if no issues for it.
>
> As I said before, I'd have to see the code to tell. But answering your comment,
> the code does support multiple monitors.
>
Hi Luiz,
   Sorry to ask again, do you think method above is OK now, waiting for
your confirm.
Luiz Capitulino May 15, 2013, 12:28 p.m. UTC | #10
On Wed, 15 May 2013 10:10:37 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-5-6 21:22, Luiz Capitulino 写道:
> > On Mon, 06 May 2013 10:09:43 +0800
> > Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >
> >> 于 2013-5-3 10:51, Wenchao Xia 写道:
> >>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
> >>>> On Thu, 02 May 2013 10:05:08 +0800
> >>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>
> >>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> >>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
> >>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >>>>>>
> >>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
> >>>>>>>> QDict *qdict)
> >>>>>>>>         }
> >>>>>>>>
> >>>>>>>>         if (total > 0) {
> >>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
> >>>>>>>> sizeof(buf), NULL));
> >>>>>>>> +        bdrv_snapshot_dump(NULL);
> >>>>>>>> +        monitor_printf(mon, "\n");
> >>>>>>>
> >>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
> >>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> >>>>>>> explicitly passing mon instead of relying on cur_mon.
> >>>>>>
> >>>>>> where are they being mixed?
> >>>>>>
> >>>>>      bdrv_snapshot_dump() used a global variable "cur_mon" inside,
> >>>>> instead
> >>>>> of let caller pass in a explicit montior* "mon", I guess that is the
> >>>>> question.
> >>>>
> >>>> I'd have to see the code to tell, but yes, what Stefan described is the
> >>>> best practice for the Monitor.
> >>>>
> >>>     I think this would not be a problem until qemu wants more than one
> >>> human monitor console, and then we may require a data structure to tell
> >>> where to output the string: stdout, *mon, or even stderr, and
> >>> error_printf() also need to be changed.
> >>>
> >>     Luiz, what is your idea? I'd like to respin v2 if no issues for it.
> >
> > As I said before, I'd have to see the code to tell. But answering your comment,
> > the code does support multiple monitors.
> >
> Hi Luiz,
>    Sorry to ask again, do you think method above is OK now, waiting for
> your confirm.

Can you point me to the code in question?
Wayne Xia May 16, 2013, 2:22 a.m. UTC | #11
于 2013-5-15 20:28, Luiz Capitulino 写道:
> On Wed, 15 May 2013 10:10:37 +0800
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>
>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
>>> On Mon, 06 May 2013 10:09:43 +0800
>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>
>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>>>>>> On Thu, 02 May 2013 10:05:08 +0800
>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>
>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
>>>>>>>>>> QDict *qdict)
>>>>>>>>>>          }
>>>>>>>>>>
>>>>>>>>>>          if (total > 0) {
>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>>>>>> sizeof(buf), NULL));
>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>>>>>> +        monitor_printf(mon, "\n");
>>>>>>>>>
>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>>>>>
>>>>>>>> where are they being mixed?
>>>>>>>>
>>>>>>>       bdrv_snapshot_dump() used a global variable "cur_mon" inside,
>>>>>>> instead
>>>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
>>>>>>> question.
>>>>>>
>>>>>> I'd have to see the code to tell, but yes, what Stefan described is the
>>>>>> best practice for the Monitor.
>>>>>>
>>>>>      I think this would not be a problem until qemu wants more than one
>>>>> human monitor console, and then we may require a data structure to tell
>>>>> where to output the string: stdout, *mon, or even stderr, and
>>>>> error_printf() also need to be changed.
>>>>>
>>>>      Luiz, what is your idea? I'd like to respin v2 if no issues for it.
>>>
>>> As I said before, I'd have to see the code to tell. But answering your comment,
>>> the code does support multiple monitors.
>>>
>> Hi Luiz,
>>     Sorry to ask again, do you think method above is OK now, waiting for
>> your confirm.
>
> Can you point me to the code in question?
>
Sure, it is

+
+/*
+ * Print to current monitor if we have one, else to stdout. It is 
similar with
+ * error_printf().
+ * TODO just like error_vprintf()
+ */
+void message_printf(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    if (cur_mon) {
+        monitor_vprintf(cur_mon, fmt, ap);
+    } else {
+        vfprintf(stdout, fmt, ap);
+    }
+    va_end(ap);
+}

   This function used global variable cur_mon instead of input parameter,
similar to error_printf().
Luiz Capitulino May 16, 2013, 12:17 p.m. UTC | #12
On Thu, 16 May 2013 10:22:09 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-5-15 20:28, Luiz Capitulino 写道:
> > On Wed, 15 May 2013 10:10:37 +0800
> > Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >
> >> 于 2013-5-6 21:22, Luiz Capitulino 写道:
> >>> On Mon, 06 May 2013 10:09:43 +0800
> >>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>
> >>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
> >>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
> >>>>>> On Thu, 02 May 2013 10:05:08 +0800
> >>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>>
> >>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> >>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
> >>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
> >>>>>>>>>> QDict *qdict)
> >>>>>>>>>>          }
> >>>>>>>>>>
> >>>>>>>>>>          if (total > 0) {
> >>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
> >>>>>>>>>> sizeof(buf), NULL));
> >>>>>>>>>> +        bdrv_snapshot_dump(NULL);
> >>>>>>>>>> +        monitor_printf(mon, "\n");
> >>>>>>>>>
> >>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
> >>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> >>>>>>>>> explicitly passing mon instead of relying on cur_mon.
> >>>>>>>>
> >>>>>>>> where are they being mixed?
> >>>>>>>>
> >>>>>>>       bdrv_snapshot_dump() used a global variable "cur_mon" inside,
> >>>>>>> instead
> >>>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
> >>>>>>> question.
> >>>>>>
> >>>>>> I'd have to see the code to tell, but yes, what Stefan described is the
> >>>>>> best practice for the Monitor.
> >>>>>>
> >>>>>      I think this would not be a problem until qemu wants more than one
> >>>>> human monitor console, and then we may require a data structure to tell
> >>>>> where to output the string: stdout, *mon, or even stderr, and
> >>>>> error_printf() also need to be changed.
> >>>>>
> >>>>      Luiz, what is your idea? I'd like to respin v2 if no issues for it.
> >>>
> >>> As I said before, I'd have to see the code to tell. But answering your comment,
> >>> the code does support multiple monitors.
> >>>
> >> Hi Luiz,
> >>     Sorry to ask again, do you think method above is OK now, waiting for
> >> your confirm.
> >
> > Can you point me to the code in question?
> >
> Sure, it is
> 
> +
> +/*
> + * Print to current monitor if we have one, else to stdout. It is 
> similar with
> + * error_printf().
> + * TODO just like error_vprintf()
> + */
> +void message_printf(const char *fmt, ...)
> +{
> +    va_list ap;
> +
> +    va_start(ap, fmt);
> +    if (cur_mon) {
> +        monitor_vprintf(cur_mon, fmt, ap);
> +    } else {
> +        vfprintf(stdout, fmt, ap);
> +    }
> +    va_end(ap);
> +}
> 
>    This function used global variable cur_mon instead of input parameter,
> similar to error_printf().

Why do you need it? Why can't you you use error_printf() for example?
Wayne Xia May 17, 2013, 3:30 a.m. UTC | #13
于 2013-5-16 20:17, Luiz Capitulino 写道:
> On Thu, 16 May 2013 10:22:09 +0800
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>
>> 于 2013-5-15 20:28, Luiz Capitulino 写道:
>>> On Wed, 15 May 2013 10:10:37 +0800
>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>
>>>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
>>>>> On Mon, 06 May 2013 10:09:43 +0800
>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>
>>>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
>>>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>>>>>>>> On Thu, 02 May 2013 10:05:08 +0800
>>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>>>
>>>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
>>>>>>>>>>>> QDict *qdict)
>>>>>>>>>>>>           }
>>>>>>>>>>>>
>>>>>>>>>>>>           if (total > 0) {
>>>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>>>>>>>> sizeof(buf), NULL));
>>>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>>>>>>>> +        monitor_printf(mon, "\n");
>>>>>>>>>>>
>>>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>>>>>>>
>>>>>>>>>> where are they being mixed?
>>>>>>>>>>
>>>>>>>>>        bdrv_snapshot_dump() used a global variable "cur_mon" inside,
>>>>>>>>> instead
>>>>>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
>>>>>>>>> question.
>>>>>>>>
>>>>>>>> I'd have to see the code to tell, but yes, what Stefan described is the
>>>>>>>> best practice for the Monitor.
>>>>>>>>
>>>>>>>       I think this would not be a problem until qemu wants more than one
>>>>>>> human monitor console, and then we may require a data structure to tell
>>>>>>> where to output the string: stdout, *mon, or even stderr, and
>>>>>>> error_printf() also need to be changed.
>>>>>>>
>>>>>>       Luiz, what is your idea? I'd like to respin v2 if no issues for it.
>>>>>
>>>>> As I said before, I'd have to see the code to tell. But answering your comment,
>>>>> the code does support multiple monitors.
>>>>>
>>>> Hi Luiz,
>>>>      Sorry to ask again, do you think method above is OK now, waiting for
>>>> your confirm.
>>>
>>> Can you point me to the code in question?
>>>
>> Sure, it is
>>
>> +
>> +/*
>> + * Print to current monitor if we have one, else to stdout. It is
>> similar with
>> + * error_printf().
>> + * TODO just like error_vprintf()
>> + */
>> +void message_printf(const char *fmt, ...)
>> +{
>> +    va_list ap;
>> +
>> +    va_start(ap, fmt);
>> +    if (cur_mon) {
>> +        monitor_vprintf(cur_mon, fmt, ap);
>> +    } else {
>> +        vfprintf(stdout, fmt, ap);
>> +    }
>> +    va_end(ap);
>> +}
>>
>>     This function used global variable cur_mon instead of input parameter,
>> similar to error_printf().
>
> Why do you need it? Why can't you you use error_printf() for example?
>
   error_printf() will print out to stderr in qemu-img, but stdout is
wanted for those dump info function.
Luiz Capitulino May 17, 2013, 12:30 p.m. UTC | #14
On Fri, 17 May 2013 11:30:31 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-5-16 20:17, Luiz Capitulino 写道:
> > On Thu, 16 May 2013 10:22:09 +0800
> > Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >
> >> 于 2013-5-15 20:28, Luiz Capitulino 写道:
> >>> On Wed, 15 May 2013 10:10:37 +0800
> >>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>
> >>>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
> >>>>> On Mon, 06 May 2013 10:09:43 +0800
> >>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>
> >>>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
> >>>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
> >>>>>>>> On Thu, 02 May 2013 10:05:08 +0800
> >>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>>>>
> >>>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> >>>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
> >>>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
> >>>>>>>>>>>> QDict *qdict)
> >>>>>>>>>>>>           }
> >>>>>>>>>>>>
> >>>>>>>>>>>>           if (total > 0) {
> >>>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
> >>>>>>>>>>>> sizeof(buf), NULL));
> >>>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
> >>>>>>>>>>>> +        monitor_printf(mon, "\n");
> >>>>>>>>>>>
> >>>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
> >>>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
> >>>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
> >>>>>>>>>>
> >>>>>>>>>> where are they being mixed?
> >>>>>>>>>>
> >>>>>>>>>        bdrv_snapshot_dump() used a global variable "cur_mon" inside,
> >>>>>>>>> instead
> >>>>>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
> >>>>>>>>> question.
> >>>>>>>>
> >>>>>>>> I'd have to see the code to tell, but yes, what Stefan described is the
> >>>>>>>> best practice for the Monitor.
> >>>>>>>>
> >>>>>>>       I think this would not be a problem until qemu wants more than one
> >>>>>>> human monitor console, and then we may require a data structure to tell
> >>>>>>> where to output the string: stdout, *mon, or even stderr, and
> >>>>>>> error_printf() also need to be changed.
> >>>>>>>
> >>>>>>       Luiz, what is your idea? I'd like to respin v2 if no issues for it.
> >>>>>
> >>>>> As I said before, I'd have to see the code to tell. But answering your comment,
> >>>>> the code does support multiple monitors.
> >>>>>
> >>>> Hi Luiz,
> >>>>      Sorry to ask again, do you think method above is OK now, waiting for
> >>>> your confirm.
> >>>
> >>> Can you point me to the code in question?
> >>>
> >> Sure, it is
> >>
> >> +
> >> +/*
> >> + * Print to current monitor if we have one, else to stdout. It is
> >> similar with
> >> + * error_printf().
> >> + * TODO just like error_vprintf()
> >> + */
> >> +void message_printf(const char *fmt, ...)
> >> +{
> >> +    va_list ap;
> >> +
> >> +    va_start(ap, fmt);
> >> +    if (cur_mon) {
> >> +        monitor_vprintf(cur_mon, fmt, ap);
> >> +    } else {
> >> +        vfprintf(stdout, fmt, ap);
> >> +    }
> >> +    va_end(ap);
> >> +}
> >>
> >>     This function used global variable cur_mon instead of input parameter,
> >> similar to error_printf().
> >
> > Why do you need it? Why can't you you use error_printf() for example?
> >
>    error_printf() will print out to stderr in qemu-img, but stdout is
> wanted for those dump info function.

You can refactor the code so that you can pass a FILE *stream argument to
error_vprintf() and maybe add error_printf_stream()?
Wayne Xia May 20, 2013, 2:39 a.m. UTC | #15
于 2013-5-17 20:30, Luiz Capitulino 写道:
> On Fri, 17 May 2013 11:30:31 +0800
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>
>> 于 2013-5-16 20:17, Luiz Capitulino 写道:
>>> On Thu, 16 May 2013 10:22:09 +0800
>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>
>>>> 于 2013-5-15 20:28, Luiz Capitulino 写道:
>>>>> On Wed, 15 May 2013 10:10:37 +0800
>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>
>>>>>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
>>>>>>> On Mon, 06 May 2013 10:09:43 +0800
>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>>
>>>>>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
>>>>>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>>>>>>>>>> On Thu, 02 May 2013 10:05:08 +0800
>>>>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>>>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>>>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor *mon, const
>>>>>>>>>>>>>> QDict *qdict)
>>>>>>>>>>>>>>            }
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>            if (total > 0) {
>>>>>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>>>>>>>>>> sizeof(buf), NULL));
>>>>>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>>>>>>>>>> +        monitor_printf(mon, "\n");
>>>>>>>>>>>>>
>>>>>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a reason for
>>>>>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>>>>>>>>>
>>>>>>>>>>>> where are they being mixed?
>>>>>>>>>>>>
>>>>>>>>>>>         bdrv_snapshot_dump() used a global variable "cur_mon" inside,
>>>>>>>>>>> instead
>>>>>>>>>>> of let caller pass in a explicit montior* "mon", I guess that is the
>>>>>>>>>>> question.
>>>>>>>>>>
>>>>>>>>>> I'd have to see the code to tell, but yes, what Stefan described is the
>>>>>>>>>> best practice for the Monitor.
>>>>>>>>>>
>>>>>>>>>        I think this would not be a problem until qemu wants more than one
>>>>>>>>> human monitor console, and then we may require a data structure to tell
>>>>>>>>> where to output the string: stdout, *mon, or even stderr, and
>>>>>>>>> error_printf() also need to be changed.
>>>>>>>>>
>>>>>>>>        Luiz, what is your idea? I'd like to respin v2 if no issues for it.
>>>>>>>
>>>>>>> As I said before, I'd have to see the code to tell. But answering your comment,
>>>>>>> the code does support multiple monitors.
>>>>>>>
>>>>>> Hi Luiz,
>>>>>>       Sorry to ask again, do you think method above is OK now, waiting for
>>>>>> your confirm.
>>>>>
>>>>> Can you point me to the code in question?
>>>>>
>>>> Sure, it is
>>>>
>>>> +
>>>> +/*
>>>> + * Print to current monitor if we have one, else to stdout. It is
>>>> similar with
>>>> + * error_printf().
>>>> + * TODO just like error_vprintf()
>>>> + */
>>>> +void message_printf(const char *fmt, ...)
>>>> +{
>>>> +    va_list ap;
>>>> +
>>>> +    va_start(ap, fmt);
>>>> +    if (cur_mon) {
>>>> +        monitor_vprintf(cur_mon, fmt, ap);
>>>> +    } else {
>>>> +        vfprintf(stdout, fmt, ap);
>>>> +    }
>>>> +    va_end(ap);
>>>> +}
>>>>
>>>>      This function used global variable cur_mon instead of input parameter,
>>>> similar to error_printf().
>>>
>>> Why do you need it? Why can't you you use error_printf() for example?
>>>
>>     error_printf() will print out to stderr in qemu-img, but stdout is
>> wanted for those dump info function.
>
> You can refactor the code so that you can pass a FILE *stream argument to
> error_vprintf() and maybe add error_printf_stream()?
>
   The name is a bit confusing, maybe qemu_printf()? Another problem is,
monitor have a buf[] instead of a FILE*, I think it need a structure
include those:

typdef enum QemuOutputType {
     QEMU_OUTPUT_TYPE_STREAM,
     QEMU_OUTPUT_TYPE_MONITOR,
} QemuOutputType;

typedef struct QemuOutput {
     QemuOutputType type;
     union {
         FILE *file;
         Monitor *mon;
     };
}

   It may brings some inconvienience to caller, but this is what I can
think out now.
Wayne Xia May 22, 2013, 2:09 a.m. UTC | #16
于 2013-5-20 10:39, Wenchao Xia 写道:
> 于 2013-5-17 20:30, Luiz Capitulino 写道:
>> On Fri, 17 May 2013 11:30:31 +0800
>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>
>>> 于 2013-5-16 20:17, Luiz Capitulino 写道:
>>>> On Thu, 16 May 2013 10:22:09 +0800
>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>
>>>>> 于 2013-5-15 20:28, Luiz Capitulino 写道:
>>>>>> On Wed, 15 May 2013 10:10:37 +0800
>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>
>>>>>>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
>>>>>>>> On Mon, 06 May 2013 10:09:43 +0800
>>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>>>
>>>>>>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
>>>>>>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
>>>>>>>>>>> On Thu, 02 May 2013 10:05:08 +0800
>>>>>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
>>>>>>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
>>>>>>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
>>>>>>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor 
>>>>>>>>>>>>>>> *mon, const
>>>>>>>>>>>>>>> QDict *qdict)
>>>>>>>>>>>>>>>            }
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>            if (total > 0) {
>>>>>>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
>>>>>>>>>>>>>>> sizeof(buf), NULL));
>>>>>>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
>>>>>>>>>>>>>>> +        monitor_printf(mon, "\n");
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
>>>>>>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a 
>>>>>>>>>>>>>> reason for
>>>>>>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
>>>>>>>>>>>>>
>>>>>>>>>>>>> where are they being mixed?
>>>>>>>>>>>>>
>>>>>>>>>>>>         bdrv_snapshot_dump() used a global variable 
>>>>>>>>>>>> "cur_mon" inside,
>>>>>>>>>>>> instead
>>>>>>>>>>>> of let caller pass in a explicit montior* "mon", I guess 
>>>>>>>>>>>> that is the
>>>>>>>>>>>> question.
>>>>>>>>>>>
>>>>>>>>>>> I'd have to see the code to tell, but yes, what Stefan 
>>>>>>>>>>> described is the
>>>>>>>>>>> best practice for the Monitor.
>>>>>>>>>>>
>>>>>>>>>>        I think this would not be a problem until qemu wants 
>>>>>>>>>> more than one
>>>>>>>>>> human monitor console, and then we may require a data 
>>>>>>>>>> structure to tell
>>>>>>>>>> where to output the string: stdout, *mon, or even stderr, and
>>>>>>>>>> error_printf() also need to be changed.
>>>>>>>>>>
>>>>>>>>>        Luiz, what is your idea? I'd like to respin v2 if no 
>>>>>>>>> issues for it.
>>>>>>>>
>>>>>>>> As I said before, I'd have to see the code to tell. But 
>>>>>>>> answering your comment,
>>>>>>>> the code does support multiple monitors.
>>>>>>>>
>>>>>>> Hi Luiz,
>>>>>>>       Sorry to ask again, do you think method above is OK now, 
>>>>>>> waiting for
>>>>>>> your confirm.
>>>>>>
>>>>>> Can you point me to the code in question?
>>>>>>
>>>>> Sure, it is
>>>>>
>>>>> +
>>>>> +/*
>>>>> + * Print to current monitor if we have one, else to stdout. It is
>>>>> similar with
>>>>> + * error_printf().
>>>>> + * TODO just like error_vprintf()
>>>>> + */
>>>>> +void message_printf(const char *fmt, ...)
>>>>> +{
>>>>> +    va_list ap;
>>>>> +
>>>>> +    va_start(ap, fmt);
>>>>> +    if (cur_mon) {
>>>>> +        monitor_vprintf(cur_mon, fmt, ap);
>>>>> +    } else {
>>>>> +        vfprintf(stdout, fmt, ap);
>>>>> +    }
>>>>> +    va_end(ap);
>>>>> +}
>>>>>
>>>>>      This function used global variable cur_mon instead of input 
>>>>> parameter,
>>>>> similar to error_printf().
>>>>
>>>> Why do you need it? Why can't you you use error_printf() for example?
>>>>
>>>     error_printf() will print out to stderr in qemu-img, but stdout is
>>> wanted for those dump info function.
>>
>> You can refactor the code so that you can pass a FILE *stream argument to
>> error_vprintf() and maybe add error_printf_stream()?
>>
>    The name is a bit confusing, maybe qemu_printf()? Another problem is,
> monitor have a buf[] instead of a FILE*, I think it need a structure
> include those:
> 
> typdef enum QemuOutputType {
>      QEMU_OUTPUT_TYPE_STREAM,
>      QEMU_OUTPUT_TYPE_MONITOR,
> } QemuOutputType;
> 
> typedef struct QemuOutput {
>      QemuOutputType type;
>      union {
>          FILE *file;
>          Monitor *mon;
>      };
> }
> 
>    It may brings some inconvienience to caller, but this is what I can
> think out now.
> 
  Luiz, I am going to respin V2 as above, can I have you confirm on it?
Luiz Capitulino May 22, 2013, 12:23 p.m. UTC | #17
On Wed, 22 May 2013 10:09:19 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> 于 2013-5-20 10:39, Wenchao Xia 写道:
> > 于 2013-5-17 20:30, Luiz Capitulino 写道:
> >> On Fri, 17 May 2013 11:30:31 +0800
> >> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>
> >>> 于 2013-5-16 20:17, Luiz Capitulino 写道:
> >>>> On Thu, 16 May 2013 10:22:09 +0800
> >>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>
> >>>>> 于 2013-5-15 20:28, Luiz Capitulino 写道:
> >>>>>> On Wed, 15 May 2013 10:10:37 +0800
> >>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>>
> >>>>>>> 于 2013-5-6 21:22, Luiz Capitulino 写道:
> >>>>>>>> On Mon, 06 May 2013 10:09:43 +0800
> >>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>>>>
> >>>>>>>>> 于 2013-5-3 10:51, Wenchao Xia 写道:
> >>>>>>>>>> 于 2013-5-2 20:02, Luiz Capitulino 写道:
> >>>>>>>>>>> On Thu, 02 May 2013 10:05:08 +0800
> >>>>>>>>>>> Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>>> 于 2013-4-30 3:05, Luiz Capitulino 写道:
> >>>>>>>>>>>>> On Fri, 26 Apr 2013 16:46:57 +0200
> >>>>>>>>>>>>> Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> On Fri, Apr 26, 2013 at 05:31:15PM +0800, Wenchao Xia wrote:
> >>>>>>>>>>>>>>> @@ -2586,10 +2585,12 @@ void do_info_snapshots(Monitor 
> >>>>>>>>>>>>>>> *mon, const
> >>>>>>>>>>>>>>> QDict *qdict)
> >>>>>>>>>>>>>>>            }
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>            if (total > 0) {
> >>>>>>>>>>>>>>> -        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf,
> >>>>>>>>>>>>>>> sizeof(buf), NULL));
> >>>>>>>>>>>>>>> +        bdrv_snapshot_dump(NULL);
> >>>>>>>>>>>>>>> +        monitor_printf(mon, "\n");
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Luiz: any issue with mixing monitor_printf(mon) and
> >>>>>>>>>>>>>> monitor_vprintf(cur_mon) calls?  I guess there was a 
> >>>>>>>>>>>>>> reason for
> >>>>>>>>>>>>>> explicitly passing mon instead of relying on cur_mon.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> where are they being mixed?
> >>>>>>>>>>>>>
> >>>>>>>>>>>>         bdrv_snapshot_dump() used a global variable 
> >>>>>>>>>>>> "cur_mon" inside,
> >>>>>>>>>>>> instead
> >>>>>>>>>>>> of let caller pass in a explicit montior* "mon", I guess 
> >>>>>>>>>>>> that is the
> >>>>>>>>>>>> question.
> >>>>>>>>>>>
> >>>>>>>>>>> I'd have to see the code to tell, but yes, what Stefan 
> >>>>>>>>>>> described is the
> >>>>>>>>>>> best practice for the Monitor.
> >>>>>>>>>>>
> >>>>>>>>>>        I think this would not be a problem until qemu wants 
> >>>>>>>>>> more than one
> >>>>>>>>>> human monitor console, and then we may require a data 
> >>>>>>>>>> structure to tell
> >>>>>>>>>> where to output the string: stdout, *mon, or even stderr, and
> >>>>>>>>>> error_printf() also need to be changed.
> >>>>>>>>>>
> >>>>>>>>>        Luiz, what is your idea? I'd like to respin v2 if no 
> >>>>>>>>> issues for it.
> >>>>>>>>
> >>>>>>>> As I said before, I'd have to see the code to tell. But 
> >>>>>>>> answering your comment,
> >>>>>>>> the code does support multiple monitors.
> >>>>>>>>
> >>>>>>> Hi Luiz,
> >>>>>>>       Sorry to ask again, do you think method above is OK now, 
> >>>>>>> waiting for
> >>>>>>> your confirm.
> >>>>>>
> >>>>>> Can you point me to the code in question?
> >>>>>>
> >>>>> Sure, it is
> >>>>>
> >>>>> +
> >>>>> +/*
> >>>>> + * Print to current monitor if we have one, else to stdout. It is
> >>>>> similar with
> >>>>> + * error_printf().
> >>>>> + * TODO just like error_vprintf()
> >>>>> + */
> >>>>> +void message_printf(const char *fmt, ...)
> >>>>> +{
> >>>>> +    va_list ap;
> >>>>> +
> >>>>> +    va_start(ap, fmt);
> >>>>> +    if (cur_mon) {
> >>>>> +        monitor_vprintf(cur_mon, fmt, ap);
> >>>>> +    } else {
> >>>>> +        vfprintf(stdout, fmt, ap);
> >>>>> +    }
> >>>>> +    va_end(ap);
> >>>>> +}
> >>>>>
> >>>>>      This function used global variable cur_mon instead of input 
> >>>>> parameter,
> >>>>> similar to error_printf().
> >>>>
> >>>> Why do you need it? Why can't you you use error_printf() for example?
> >>>>
> >>>     error_printf() will print out to stderr in qemu-img, but stdout is
> >>> wanted for those dump info function.
> >>
> >> You can refactor the code so that you can pass a FILE *stream argument to
> >> error_vprintf() and maybe add error_printf_stream()?
> >>
> >    The name is a bit confusing, maybe qemu_printf()? Another problem is,
> > monitor have a buf[] instead of a FILE*, I think it need a structure
> > include those:
> > 
> > typdef enum QemuOutputType {
> >      QEMU_OUTPUT_TYPE_STREAM,
> >      QEMU_OUTPUT_TYPE_MONITOR,
> > } QemuOutputType;
> > 
> > typedef struct QemuOutput {
> >      QemuOutputType type;
> >      union {
> >          FILE *file;
> >          Monitor *mon;
> >      };
> > }
> > 
> >    It may brings some inconvienience to caller, but this is what I can
> > think out now.
> > 
>   Luiz, I am going to respin V2 as above, can I have you confirm on it?

I'm honestly a bit confused with what you're suggesting. I'd just respin the
patches and restart the discussion.
diff mbox

Patch

diff --git a/block/qapi.c b/block/qapi.c
index 155e77e..15c7656 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -259,7 +259,8 @@  static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
     return buf;
 }
 
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
+/* Dump to monitor if it present, otherwise to stdout. */
+void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)
 {
     char buf1[128], date_buf[128], clock_buf[128];
     struct tm tm;
@@ -267,9 +268,8 @@  char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
     int64_t secs;
 
     if (!sn) {
-        snprintf(buf, buf_size,
-                 "%-10s%-20s%7s%20s%15s",
-                 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
+        message_printf("%-10s%-20s%7s%20s%15s",
+                       "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
     } else {
         ti = sn->date_sec;
         localtime_r(&ti, &tm);
@@ -282,16 +282,16 @@  char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
                  (int)((secs / 60) % 60),
                  (int)(secs % 60),
                  (int)((sn->vm_clock_nsec / 1000000) % 1000));
-        snprintf(buf, buf_size,
-                 "%-10s%-20s%7s%20s%15s",
-                 sn->id_str, sn->name,
-                 get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
-                 date_buf,
-                 clock_buf);
+        message_printf("%-10s%-20s%7s%20s%15s",
+                       sn->id_str, sn->name,
+                       get_human_readable_size(buf1, sizeof(buf1),
+                                               sn->vm_state_size),
+                       date_buf,
+                       clock_buf);
     }
-    return buf;
 }
 
+/* Dump to monitor if it present, otherwise to stdout. */
 void bdrv_image_info_dump(ImageInfo *info)
 {
     char size_buf[128], dsize_buf[128];
@@ -302,43 +302,44 @@  void bdrv_image_info_dump(ImageInfo *info)
                                 info->actual_size);
     }
     get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
-    printf("image: %s\n"
-           "file format: %s\n"
-           "virtual size: %s (%" PRId64 " bytes)\n"
-           "disk size: %s\n",
-           info->filename, info->format, size_buf,
-           info->virtual_size,
-           dsize_buf);
+    message_printf("image: %s\n"
+                   "file format: %s\n"
+                   "virtual size: %s (%" PRId64 " bytes)\n"
+                   "disk size: %s\n",
+                   info->filename, info->format, size_buf,
+                   info->virtual_size,
+                   dsize_buf);
 
     if (info->has_encrypted && info->encrypted) {
-        printf("encrypted: yes\n");
+        message_printf("encrypted: yes\n");
     }
 
     if (info->has_cluster_size) {
-        printf("cluster_size: %" PRId64 "\n", info->cluster_size);
+        message_printf("cluster_size: %" PRId64 "\n", info->cluster_size);
     }
 
     if (info->has_dirty_flag && info->dirty_flag) {
-        printf("cleanly shut down: no\n");
+        message_printf("cleanly shut down: no\n");
     }
 
     if (info->has_backing_filename) {
-        printf("backing file: %s", info->backing_filename);
+        message_printf("backing file: %s", info->backing_filename);
         if (info->has_full_backing_filename) {
-            printf(" (actual path: %s)", info->full_backing_filename);
+            message_printf(" (actual path: %s)", info->full_backing_filename);
         }
-        putchar('\n');
+        message_printf("\n");
         if (info->has_backing_filename_format) {
-            printf("backing file format: %s\n", info->backing_filename_format);
+            message_printf("backing file format: %s\n",
+                           info->backing_filename_format);
         }
     }
 
     if (info->has_snapshots) {
         SnapshotInfoList *elem;
-        char buf[256];
 
-        printf("Snapshot list:\n");
-        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+        message_printf("Snapshot list:\n");
+        bdrv_snapshot_dump(NULL);
+        message_printf("\n");
 
         /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
          * we convert to the block layer's native QEMUSnapshotInfo for now.
@@ -354,7 +355,8 @@  void bdrv_image_info_dump(ImageInfo *info)
 
             pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
             pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
-            printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
+            bdrv_snapshot_dump(&sn);
+            message_printf("\n");
         }
     }
 }
diff --git a/include/block/qapi.h b/include/block/qapi.h
index 55d1848..d93652d 100644
--- a/include/block/qapi.h
+++ b/include/block/qapi.h
@@ -36,6 +36,6 @@  void bdrv_collect_image_info(BlockDriverState *bs,
 BlockInfo *bdrv_query_info(BlockDriverState *s);
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
 
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
+void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
 void bdrv_image_info_dump(ImageInfo *info);
 #endif
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index c902cc1..90341bd 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -40,4 +40,5 @@  void error_set_progname(const char *argv0);
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 const char *error_get_progname(void);
 
+void message_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 #endif
diff --git a/qemu-img.c b/qemu-img.c
index 5d1e480..f732b9a 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1554,16 +1554,17 @@  static void dump_snapshots(BlockDriverState *bs)
 {
     QEMUSnapshotInfo *sn_tab, *sn;
     int nb_sns, i;
-    char buf[256];
 
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
     if (nb_sns <= 0)
         return;
     printf("Snapshot list:\n");
-    printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+    bdrv_snapshot_dump(NULL);
+    printf("\n");
     for(i = 0; i < nb_sns; i++) {
         sn = &sn_tab[i];
-        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
+        bdrv_snapshot_dump(sn);
+        printf("\n");
     }
     g_free(sn_tab);
 }
diff --git a/savevm.c b/savevm.c
index ac81c9b..c00ba00 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2542,7 +2542,6 @@  void do_info_snapshots(Monitor *mon, const QDict *qdict)
     int nb_sns, i, available;
     int total;
     int *available_snapshots;
-    char buf[256];
 
     bs = find_vmstate_bs();
     if (!bs) {
@@ -2586,10 +2585,12 @@  void do_info_snapshots(Monitor *mon, const QDict *qdict)
     }
 
     if (total > 0) {
-        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+        bdrv_snapshot_dump(NULL);
+        monitor_printf(mon, "\n");
         for (i = 0; i < total; i++) {
             sn = &sn_tab[available_snapshots[i]];
-            monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
+            bdrv_snapshot_dump(sn);
+            monitor_printf(mon, "\n");
         }
     } else {
         monitor_printf(mon, "There is no suitable snapshot available\n");
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 08a36f4..a47bf32 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -213,3 +213,21 @@  void error_report(const char *fmt, ...)
     va_end(ap);
     error_printf("\n");
 }
+
+/*
+ * Print to current monitor if we have one, else to stdout. It is similar with
+ * error_printf().
+ * TODO just like error_vprintf()
+ */
+void message_printf(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    if (cur_mon) {
+        monitor_vprintf(cur_mon, fmt, ap);
+    } else {
+        vfprintf(stdout, fmt, ap);
+    }
+    va_end(ap);
+}