From: Hanna Reitz <hreitz@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH v3 2/6] block: block-status cache for data regions
Date: Tue, 17 Aug 2021 08:19:43 +0200 [thread overview]
Message-ID: <b7660c0a-99e4-1fe3-9f9f-061e55cef17b@redhat.com> (raw)
In-Reply-To: <20210816213823.uocknsk4zgulrk3v@redhat.com>
On 16.08.21 23:38, Eric Blake wrote:
> On Thu, Aug 12, 2021 at 10:41:44AM +0200, Hanna Reitz wrote:
>> As we have attempted before
>> (https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg06451.html,
>> "file-posix: Cache lseek result for data regions";
>> https://lists.nongnu.org/archive/html/qemu-block/2021-02/msg00934.html,
>> "file-posix: Cache next hole"), this patch seeks to reduce the number of
>> SEEK_DATA/HOLE operations the file-posix driver has to perform. The
>> main difference is that this time it is implemented as part of the
>> general block layer code.
>>
>> We only use the cache for nodes without children (i.e. protocol nodes),
>> because that is where the problem is: Drivers that rely on block-status
>> implementations outside of qemu (e.g. SEEK_DATA/HOLE).
>>
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/307
>> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
>> ---
>> +++ b/block.c
>> +/**
>> + * Check whether [offset, offset + bytes) overlaps with the cached
>> + * block-status data region.
>> + *
>> + * If so, and @pnum is not NULL, set *pnum to `bsc.data_end - offset`,
>> + * which is what bdrv_bsc_is_data()'s interface needs.
>> + * Otherwise, *pnum is not touched.
> Why duplicate this comment,...
I don’t think it can be duplicated, because this is a static function.
It is very similar to bdrv_bsc_is_data()’s interface, I admit, but it
isn’t exactly the same (besides the _locked suffix, the only difference
is that bdrv_bsc_is_data() is for a single byte, while this function
checks a range).
>> + */
>> +static bool bdrv_bsc_range_overlaps_locked(BlockDriverState *bs,
>> + int64_t offset, int64_t bytes,
>> + int64_t *pnum)
>> +{
>> + BdrvBlockStatusCache *bsc = qatomic_rcu_read(&bs->block_status_cache);
>> + bool overlaps;
>> +
>> + overlaps =
>> + qatomic_read(&bsc->valid) &&
>> + ranges_overlap(offset, bytes, bsc->data_start,
>> + bsc->data_end - bsc->data_start);
>> +
>> + if (overlaps && pnum) {
>> + *pnum = bsc->data_end - offset;
>> + }
>> +
>> + return overlaps;
>> +}
>> +
>> +/**
>> + * See block_int.h for this function's documentation.
>> + */
>> +bool bdrv_bsc_is_data(BlockDriverState *bs, int64_t offset, int64_t *pnum)
>> +{
>> + RCU_READ_LOCK_GUARD();
>> +
>> + return bdrv_bsc_range_overlaps_locked(bs, offset, 1, pnum);
>> +}
>> +
>> +/**
>> + * See block_int.h for this function's documentation.
> ...but not these?
These are not static functions, and so I can point to the header where
they’re declared.
(We have a wild mix of where functions are described in qemu, and it’s
often in their C files. I prefer having descriptions in the header, but
because we have the precedent of explaining interfaces in C files, I
thought I can’t get around adding at least pointers in the C file.)
> But that's minor.
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
Hanna
next prev parent reply other threads:[~2021-08-17 6:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-12 8:41 [PATCH v3 0/6] block-status cache for data regions Hanna Reitz
2021-08-12 8:41 ` [PATCH v3 1/6] block: Drop BDS comment regarding bdrv_append() Hanna Reitz
2021-08-12 8:41 ` [PATCH v3 2/6] block: block-status cache for data regions Hanna Reitz
2021-08-16 21:38 ` Eric Blake
2021-08-17 6:19 ` Hanna Reitz [this message]
2021-08-25 9:54 ` Vladimir Sementsov-Ogievskiy
2021-08-12 8:41 ` [PATCH v3 3/6] block: Clarify that @bytes is no limit on *pnum Hanna Reitz
2021-08-17 15:03 ` Eric Blake
2021-08-12 8:41 ` [PATCH v3 4/6] block/file-posix: Do not force-cap *pnum Hanna Reitz
2021-08-12 8:41 ` [PATCH v3 5/6] block/gluster: " Hanna Reitz
2021-08-12 8:41 ` [PATCH v3 6/6] block/iscsi: " Hanna Reitz
2021-09-07 9:23 ` [PATCH v3 0/6] block-status cache for data regions Hanna Reitz
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=b7660c0a-99e4-1fe3-9f9f-061e55cef17b@redhat.com \
--to=hreitz@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.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).