Received: from eggs.gnu.org ([2001:4830:134:3::10]:49349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlbiQ-0002Ks-QP for qemu-devel@nongnu.org; Mon, 12 Oct 2015 07:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlbiL-0008HB-IR for qemu-devel@nongnu.org; Mon, 12 Oct 2015 07:56:30 -0400 From: Alberto Garcia In-Reply-To: <5617E29B.8000700@redhat.com> References: <1442907862-21376-1-git-send-email-wency@cn.fujitsu.com> <1442907862-21376-3-git-send-email-wency@cn.fujitsu.com> <561569A9.50609@redhat.com> <5617E29B.8000700@redhat.com> Date: Mon, 12 Oct 2015 13:56:21 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v5 2/4] quorum: implement bdrv_add_child() and bdrv_del_child() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , Wen Congyang , qemu devel , Eric Blake , Markus Armbruster , Stefan Hajnoczi Cc: Kevin Wolf , zhanghailiang , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang On Fri 09 Oct 2015 05:51:55 PM CEST, Max Reitz wrote: >>>> + s->bs = g_renew(BlockDriverState *, s->bs, s->max_children + 1); >>>> + s->bs[s->num_children] = NULL; >>>> + s->max_children++; >>>> + } >>> >>> Just a suggestion, please feel free to ignore it completely: >>> >>> You can drop the s->max_children field and just always call g_renew() >>> with s->num_children + 1 as the @count parameter. There shouldn't be >>> any (visible) performance penalty, but it would simplify the code. >> >> If s->num_children has decreased since the previous g_renew() call >> (because the user called quorum_del_child()) that could actually reduce >> the array size. > > Yes, it could. And that would be just fine. ;-) > > We'd just keep the array exactly as big as it needs to be. I find that > pretty intuitive. It's just counter-intuitive if you think one should > never use realloc() for reducing the size of a buffer (and I know I > myself tend to write my code thinking that). If the goal is to keep the array exactly as big as it needs to be then we should use g_renew() in quorum_del_child()... Anyway we're digressing :-) this array is one pointer per Quorum child, so the amount of memory we're talking about here is probably negligible. I'm fine with any solution. Berto