From: Michael Tokarev <mjt@tls.msk.ru>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] Combine bdrv_co_readv and bdrv_co_writev into bdrv_co_rw_vector
Date: Wed, 29 Feb 2012 20:45:28 +0400 [thread overview]
Message-ID: <4F4E5628.7020002@msgid.tls.msk.ru> (raw)
In-Reply-To: <4F4E5140.5030600@redhat.com>
On 29.02.2012 20:24, Paolo Bonzini wrote:
> Il 29/02/2012 17:12, Michael Tokarev ha scritto:
>> On 29.02.2012 20:01, Paolo Bonzini wrote:
>>> Il 29/02/2012 00:54, Michael Tokarev ha scritto:
>>>> BlockDriver *drv = bs->drv;
>>>> BdrvTrackedRequest req;
>>>> + bool is_write = flags & (BDRV_REQ_WRITE|BDRV_REQ_ZERO_WRITE);
>>>> int ret;
>>>
>>> You can do BDRV_REQ_WRITE|BDRV_REQ_ZERO_WRITE, but not
>>> BDRV_REQ_READ|BDRV_REQ_COPY_ON_READ. That's ugly.
>>
>> BDRV_REQ_READ is zero. This is just mnemonic to avoid "magic
>> numbers" elsewhere in the code. This is an internal function
>> and the comment above it says just that, and it is always
>> called with just ONE value. It is not a bitmask, it is used
>> as such inside this very routine ONLY. The argument is declared
>> as enum too, -- this should tell something. In the function
>> prototype it should have been named "opcode" or "request",
>> not "flags". It is used as flags only inside this function.
>>
>> This code isn't written by me, it was this way before.
>> I just added 2 more possible values for this parameter.
>
> If you have 4 values, make them 1/2/4/8 or 0/1/2/3. Not 0/1/2/4.
You didn't read what I wrote, did you?
In the _original_ code, this very enum was ALREADY used as
a bitmask, but only inside this routine. I can change that,
but it has nothing to do with the patch in question. Making
it 0/1/2/3 will break that.
And yet again, I dislike this code myself, and I mentioned
this already, but that's why I put the "RFC" in the original
subject -- RFC for the general "idea".
>> No block driver -- at least currently -- needs any other value
>> here except of read-or-write (or is_write). COPY_ON_READ is
>> not a business of the individual block drivers currently.
>
> Sure, but ZERO_WRITES is (we have a separate callback).
I already replied about this. To me it looks like it is
better to keep it as separate, for several reasons:
very few drivers will actually implement it in a
reasonable way. By turning it into "request type"
of a common dispatcher method (like bdrv_rw) means
that each driver will have to recognize it and call
some common emulation routine, instead of letting
the upper layer to deal with it.
it matches much better the discard method instead of
rw method, so if we want to combine, lets' go there
instead.
it does not accept data, just like discard.
So we still end up with reads or writes. And using
bool instead of a enum for these is easier.
>
>> These defines are _only_ to make some code a bit more readable,
>> in a very few places where it necessary to call individual
>> read or write block driver method. So that the construct:
>>
>> ret - s->bdrv_co_rw_vector(bs, ..., true)
>>
>> becomes
>>
>> ret - s->bdrv_co_rw_vector(bs, ..., BDRV_WRITE)
>>
>> and it is immediately obvious that it is write. The prototype
>> of the method has "bool is_write" here.
>
> If you use an enum, the prototype shouldn't be bool.
I use a bool, not an enum. The parameter is called "is_write".
It is also used in lots of other places.
>>> But I'm skeptical, the
>>> actual amount of unification is not that large.
>>
>> This is not about unification. This is, as described in the introduction
>> email, about removing complexity of a very twisted nature of read and
>> write code paths, for a start.
>
> The patches are a balance of removing duplication and adding
> conditionals, no? Removing duplication is unification.
The unification is just a (good) side effect.
Thanks,
/mjt
prev parent reply other threads:[~2012-02-29 16:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1330473276-8975-1-git-send-email-mjt@tls.msk.ru>
2012-02-28 23:54 ` [Qemu-devel] [PATCH 1/3] Combine bdrv_read and bdrv_write to bdrv_rw Michael Tokarev
2012-02-29 15:53 ` Paolo Bonzini
2012-02-29 16:00 ` Michael Tokarev
2012-02-29 16:07 ` Paolo Bonzini
2012-02-29 16:36 ` Michael Tokarev
2012-02-28 23:54 ` [Qemu-devel] [PATCH 2/3] Combine bdrv_aio_readv and bdrv_aio_writev into bdrv_aio_rw_vector Michael Tokarev
2012-02-29 15:54 ` Paolo Bonzini
2012-02-29 16:16 ` Michael Tokarev
2012-02-28 23:54 ` [Qemu-devel] [PATCH 3/3] Combine bdrv_co_readv and bdrv_co_writev into bdrv_co_rw_vector Michael Tokarev
2012-02-29 16:01 ` Paolo Bonzini
2012-02-29 16:12 ` Michael Tokarev
2012-02-29 16:24 ` Paolo Bonzini
2012-02-29 16:45 ` Michael Tokarev [this message]
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=4F4E5628.7020002@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.