All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Alberto Garcia <berto@igalia.com>,
	Wen Congyang <wency@cn.fujitsu.com>,
	qemu devel <qemu-devel@nongnu.org>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	zhanghailiang <zhang.zhanghailiang@huawei.com>,
	qemu block <qemu-block@nongnu.org>,
	Jiang Yunhong <yunhong.jiang@intel.com>,
	Dong Eddie <eddie.dong@intel.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Gonglei <arei.gonglei@huawei.com>,
	Yang Hongyang <yanghy@cn.fujitsu.com>
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v5 2/4] quorum: implement bdrv_add_child() and bdrv_del_child()
Date: Fri, 9 Oct 2015 17:51:55 +0200	[thread overview]
Message-ID: <5617E29B.8000700@redhat.com> (raw)
In-Reply-To: <w51wpux3hj3.fsf@maestria.local.igalia.com>

[-- Attachment #1: Type: text/plain, Size: 2306 bytes --]

On 08.10.2015 10:12, Alberto Garcia wrote:
> On Wed 07 Oct 2015 08:51:21 PM CEST, Max Reitz <mreitz@redhat.com> wrote:
>>> +    if (s->num_children == s->max_children) {
>>> +        if (s->max_children >= INT_MAX) {
>>
>> Opposing Berto (:-)), I like >= even if the > part is actually
>> impossible. I myself like to use constructs such as:
>>
>> for (i = 0; i < n; i++) {
>>     /* ... */
>> }
>> if (i >= n) {
>>     /* ... */
>> }
>>
>> Even though @i can never exceed @n after the loop. This is because my
>> way of thinking is "What if it could exceed @n? Then I'd like to take
>> this branch as well." The same applies here. s->max_children can never
>> exceed INT_MAX, but if it could, we'd want that to be an error, too.
> 
> If s->max_children (and therefore s->num_children) could exceed the
> upper limit then we would probably want to assert on that, because it
> means that there's something seriously broken. The purpose of this code
> is to make sure that the upper limit is... well, an upper limit :-) If
> that invariant no longer holds then I don't think we want a simple "Too
> many children" error.
> 
>>> +        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).

Max

>                 Nothing would break though, at worst it would just be a
> bit counter-intuitive :-)
> 
> https://www.gnu.org/software/libc/manual/html_node/Changing-Block-Size.html
> 
> Berto
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2015-10-09 15:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22  7:44 [Qemu-devel] [PATCH v5 0/4] qapi: child add/delete support Wen Congyang
2015-09-22  7:44 ` [Qemu-devel] [PATCH v5 1/4] Add new block driver interface to add/delete a BDS's child Wen Congyang
2015-10-07 13:35   ` Alberto Garcia
2015-10-08  2:05     ` Wen Congyang
2015-10-07 18:33   ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-10-08  2:06     ` Wen Congyang
2015-10-07 19:00   ` [Qemu-devel] " Dr. David Alan Gilbert
2015-10-08  2:03     ` Wen Congyang
2015-10-08 18:44       ` Dr. David Alan Gilbert
2015-09-22  7:44 ` [Qemu-devel] [PATCH v5 2/4] quorum: implement bdrv_add_child() and bdrv_del_child() Wen Congyang
2015-10-07 14:12   ` Alberto Garcia
2015-10-08  2:10     ` Wen Congyang
2015-10-07 18:51   ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-10-08  8:12     ` Alberto Garcia
2015-10-09 15:51       ` Max Reitz [this message]
2015-10-12 11:56         ` Alberto Garcia
2015-09-22  7:44 ` [Qemu-devel] [PATCH v5 3/4] qmp: add monitor command to add/remove a child Wen Congyang
2015-10-07 14:33   ` Alberto Garcia
2015-10-07 19:42   ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-10-08  6:15     ` Markus Armbruster
2015-10-08  8:29       ` Alberto Garcia
2015-10-08 10:03         ` Kevin Wolf
2015-10-08 10:13           ` Alberto Garcia
2015-10-09 16:14         ` Max Reitz
2015-10-08 11:02       ` [Qemu-devel] Dynamic reconfiguration (was: qmp: add monitor command to add/remove a child) Kevin Wolf
2015-10-08 11:10         ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2015-10-21  8:27           ` [Qemu-devel] [Qemu-block] Dynamic reconfiguration Markus Armbruster
2015-10-26  2:04             ` Wen Congyang
2015-10-26  7:24               ` Markus Armbruster
2015-10-26  7:25                 ` Wen Congyang
2015-10-09 16:13       ` [Qemu-devel] [Qemu-block] [PATCH v5 3/4] qmp: add monitor command to add/remove a child Max Reitz
2015-10-09 16:42         ` Dr. David Alan Gilbert
2015-10-09 18:24           ` Max Reitz
2015-10-12  8:07             ` Dr. David Alan Gilbert
2015-10-12  8:18             ` Kevin Wolf
2015-10-12  7:58           ` Markus Armbruster
2015-10-12  7:56         ` Markus Armbruster
2015-10-12 16:27     ` Max Reitz
2015-09-22  7:44 ` [Qemu-devel] [PATCH v5 4/4] hmp: " Wen Congyang
2015-10-07 14:38   ` Alberto Garcia
2015-09-22 11:15 ` [Qemu-devel] [PATCH v5 0/4] qapi: child add/delete support Dr. David Alan Gilbert
2015-09-23  1:08   ` Wen Congyang
2015-09-23  9:21     ` Dr. David Alan Gilbert
2015-09-23  9:30       ` Wen Congyang
2015-10-07  6:40 ` Wen Congyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5617E29B.8000700@redhat.com \
    --to=mreitz@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=armbru@redhat.com \
    --cc=berto@igalia.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eddie.dong@intel.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wency@cn.fujitsu.com \
    --cc=yanghy@cn.fujitsu.com \
    --cc=yunhong.jiang@intel.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.