From: Nir Soffer <nsoffer@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Nir Soffer <nirsof@gmail.com>, qemu-block <qemu-block@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] block: Use QEMU_IS_ALIGNED instead of reinventing it
Date: Tue, 20 Aug 2019 23:46:49 +0300 [thread overview]
Message-ID: <CAMRbyytuCKqVbuZxtbz9rthYdO-w+CrEy-hHe9nrYVZ=j8P04g@mail.gmail.com> (raw)
In-Reply-To: <0d8c2c6a-55ef-3517-b93c-05d9a04e5d26@redhat.com>
On Tue, Aug 20, 2019 at 10:51 PM Max Reitz <mreitz@redhat.com> wrote:
> On 17.08.19 19:53, Nir Soffer wrote:
> > Replace instances of:
> >
> > (n & (BDRV_SECTOR_SIZE - 1)) == 0)
> >
> > With:
> >
> > QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)
> >
> > Which reveals the intent of the code better, and makes it easier to
> > locate the code checking alignment.
> >
> > QEMU_IS_ALIGNED is implemented using %, which may be less efficient but
> > it is used only in assert() except one instance, so it should not
> > matter.
> >
> > Signed-off-by: Nir Soffer <nsoffer@redhat.com>
> > ---
> > block/bochs.c | 4 ++--
> > block/cloop.c | 4 ++--
> > block/dmg.c | 4 ++--
> > block/io.c | 8 ++++----
> > block/qcow2.c | 4 ++--
> > block/vvfat.c | 8 ++++----
> > qemu-img.c | 2 +-
> > 7 files changed, 17 insertions(+), 17 deletions(-)
>
> Because John was speaking about a magical incantation, I found
> BDRV_SECTOR_MASK. There are two places in block/qcow2-cluster.c that
> use that to check alignment, I think those should be amended as well.
>
$ git grep BDRV_SECTOR_MASK
block/qcow2-cluster.c: assert((offset_in_cluster &
~BDRV_SECTOR_MASK) == 0);
block/qcow2-cluster.c: assert((bytes & ~BDRV_SECTOR_MASK) == 0);
Right, should use QEMU_IS_ALIGNED
include/block/block.h:#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)
include/block/block.h:#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK
migration/block.c: flags = addr & ~BDRV_SECTOR_MASK;
This could use (BDRV_SECTOR_SIZE - 1).
In Linux SECTOR_MASK is defined as:
drivers/block/null_blk_main.c:#define SECTOR_MASK
(PAGE_SECTORS - 1)
It seems that qemu use use the same.
I will try to handle these in v2.
Nir
prev parent reply other threads:[~2019-08-20 20:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-17 17:53 [Qemu-devel] [PATCH] block: Use QEMU_IS_ALIGNED instead of reinventing it Nir Soffer
2019-08-20 19:27 ` [Qemu-devel] [Qemu-block] " John Snow
2019-08-20 20:28 ` Nir Soffer
2019-08-20 19:50 ` [Qemu-devel] " Max Reitz
2019-08-20 20:46 ` Nir Soffer [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='CAMRbyytuCKqVbuZxtbz9rthYdO-w+CrEy-hHe9nrYVZ=j8P04g@mail.gmail.com' \
--to=nsoffer@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nirsof@gmail.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).