Received: from eggs.gnu.org ([2001:4830:134:3::10]:45222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1t9k-0002EV-BG for qemu-devel@nongnu.org; Wed, 02 Nov 2016 06:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1t9h-0003Qa-14 for qemu-devel@nongnu.org; Wed, 02 Nov 2016 06:52:32 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1t9g-0003PY-P4 for qemu-devel@nongnu.org; Wed, 02 Nov 2016 06:52:28 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA2AmoT8014951 for ; Wed, 2 Nov 2016 06:52:26 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 26fd6egdtb-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 02 Nov 2016 06:52:26 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 Nov 2016 04:52:25 -0600 References: <20161012204907.25941-1-mreitz@redhat.com> <20161012204907.25941-3-mreitz@redhat.com> From: Hao QingFeng Date: Wed, 2 Nov 2016 18:52:29 +0800 MIME-Version: 1.0 In-Reply-To: <20161012204907.25941-3-mreitz@redhat.com> Content-Type: text/plain; charset=gbk; format=flowed Message-Id: <7be11d16-d2ae-e892-5f97-17f971859a3a@linux.vnet.ibm.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/3] block: Emit modules in bdrv_iterate_format() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Kevin Wolf , Stefan Hajnoczi =D4=DA 2016-10-13 4:49, Max Reitz =D0=B4=B5=C0: > Some block drivers may not be loaded yet, but qemu supports them > nonetheless. bdrv_iterate_format() should report them, too. > > Signed-off-by: Max Reitz > --- > block.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/block.c b/block.c > index e46e4b2..88a1ea5 100644 > --- a/block.c > +++ b/block.c > @@ -2815,6 +2815,24 @@ void bdrv_iterate_format(void (*it)(void *opaque= , const char *name), > } > } > > + for (i =3D 0; i < (int)ARRAY_SIZE(block_driver_modules); i++) { > + const char *format_name =3D block_driver_modules[i].format_nam= e; > + > + if (format_name) { > + bool found =3D false; > + int j =3D count; > + > + while (formats && j && !found) { > + found =3D !strcmp(formats[--j], format_name); > + } > + > + if (!found) { > + formats =3D g_renew(const char *, formats, count + 1); > + formats[count++] =3D format_name; > + } > + } > + } > + Sorry for a bit late response. The function looks fine but just some=20 doubt on g_renew in this piece of code(and the legacy), does g_renew(realloc) has much=20 performance impact if it's call many times since alloc and memory copy are both also=20 run many times? So how about increase the memory for more instead of 1 each time? formats =3D g_renew(const char *, formats, count + 10); A new counter also needs to be introduced to record the space size. Thanks > qsort(formats, count, sizeof(formats[0]), qsort_strcmp); > > for (i =3D 0; i < count; i++) { --=20 QingFeng Hao(Robin)