Received: from eggs.gnu.org ([208.118.235.92]:49524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQcVk-0000OL-IT for qemu-devel@nongnu.org; Fri, 12 Apr 2013 07:51:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQcVj-0000hX-1L for qemu-devel@nongnu.org; Fri, 12 Apr 2013 07:51:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQcVi-0000hP-O2 for qemu-devel@nongnu.org; Fri, 12 Apr 2013 07:51:18 -0400 From: Markus Armbruster References: <1364903250-10429-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1364903250-10429-14-git-send-email-xiawenc@linux.vnet.ibm.com> <87fvyytixe.fsf@blackfin.pond.sub.org> <516659A9.3010101@linux.vnet.ibm.com> <87fvyxff1y.fsf@blackfin.pond.sub.org> <516792CF.9020202@linux.vnet.ibm.com> Date: Fri, 12 Apr 2013 13:51:13 +0200 In-Reply-To: <516792CF.9020202@linux.vnet.ibm.com> (Wenchao Xia's message of "Fri, 12 Apr 2013 12:51:27 +0800") Message-ID: <87wqs8x8zy.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V11 13/17] block: dump to buffer for bdrv_snapshot_dump() and bdrv_image_info_dump() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: kwolf@redhat.com, stefanha@gmail.com, lcapitulino@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com Wenchao Xia writes: > =E4=BA=8E 2013-4-11 20:05, Markus Armbruster =E5=86=99=E9=81=93: >> Wenchao Xia writes: >>=20 >>>>>=20=20=20=20 >>>>> -void bdrv_image_info_dump(ImageInfo *info) >>>>> +void bdrv_image_info_dump(GString *buf, ImageInfo *info) >>>>> { >>>>> char size_buf[128], dsize_buf[128]; >>>>> if (!info->has_actual_size) { >>>>> @@ -370,43 +369,48 @@ void bdrv_image_info_dump(ImageInfo *info) >>>> >>>> I don't like this change, because it introduces buffering for no >>>> discernible reason. Unless you can show me one, I'd like you to keep >>>> printing directly. >>>> >>> HMP code later need to call this function, and then print buf to >>> monitor console, which is the goal of this patch. >>=20 >> Aha, the actual problem is "print either to stdout or to current >> monitor", so that we can share code among qemu-img and monitor commands. >> Such sharing is good, and the problem is real. >>=20 >> bdrv_snapshot_dump() solves it this way: print to a fixed-size buffer, >> which the caller either prints to stdout (qemu-img) or to the current >> monitor (info snapshots). >>=20 >> Your patch makes the buffer flexible. Improvement. >>=20 >> But in my opinion, the detour through the buffer is silly. Why not >> simply use a print function that does the right thing? >>=20 >> We already have such a function for "print either to stderr or to >> current monitor": error_printf(). Could easily add one for stdout. >>=20 >> [...] >>=20 > Indeed it is a better way, how about: > void message_printf(const char *fmt, ...); > I am not sure where should this function be placed, > hmp.c? I figure it needs to go in a file that's linked into the utilities, too. I think these are in make variables util-obj-y, stub-obj-y. I'd be tempted to put it into qemu-error.c. If you don't like that because it's not about errors, consider renaming the file :)