From: Niklas Cassel <Niklas.Cassel@wdc.com>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Cc: "fio@vger.kernel.org" <fio@vger.kernel.org>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH 05/11] zbd: introduce zbd_verify_file_sizes()
Date: Fri, 10 Dec 2021 12:05:26 +0000 [thread overview]
Message-ID: <YbNChXps+eWFEGXO@x1-carbon> (raw)
In-Reply-To: <20211210021541.317315-6-damien.lemoal@opensource.wdc.com>
On Fri, Dec 10, 2021 at 11:15:35AM +0900, Damien Le Moal wrote:
> Introduce the helper function zbd_verify_file_sizes() to check whether
> the offset and size options are aligned with zone boundaries for a
> job/file combination. This avoids large indentation of the code in
> zbd_verify_sizes() and makes the code easier to read.
>
> No functional changes.
>
> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> ---
> zbd.c | 135 ++++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 74 insertions(+), 61 deletions(-)
>
> diff --git a/zbd.c b/zbd.c
> index 70afdd82..70073461 100644
> --- a/zbd.c
> +++ b/zbd.c
> @@ -485,76 +485,89 @@ static bool zbd_is_seq_job(struct fio_file *f)
> /*
> * Verify whether offset and size parameters are aligned with zone boundaries.
> */
> -static bool zbd_verify_sizes(void)
> +static bool zbd_verify_file_sizes(struct thread_data *td, struct fio_file *f)
> {
> const struct fio_zone_info *z;
> - struct thread_data *td;
> - struct fio_file *f;
> uint64_t new_offset, new_end;
> uint32_t zone_idx;
> +
> + if (!f->zbd_info)
> + return true;
> + if (f->file_offset >= f->real_file_size)
> + return true;
> + if (!zbd_is_seq_job(f))
> + return true;
> +
> + if (!td->o.zone_size) {
> + td->o.zone_size = f->zbd_info->zone_size;
> + if (!td->o.zone_size) {
> + log_err("%s: invalid 0 zone size\n",
> + f->file_name);
> + return false;
> + }
> + } else if (td->o.zone_size != f->zbd_info->zone_size) {
> + log_err("%s: zonesize %llu does not match the device zone size %"PRIu64".\n",
> + f->file_name, td->o.zone_size,
> + f->zbd_info->zone_size);
> + return false;
> + }
> +
> + if (td->o.zone_skip % td->o.zone_size) {
> + log_err("%s: zoneskip %llu is not a multiple of the device zone size %llu.\n",
> + f->file_name, td->o.zone_skip,
> + td->o.zone_size);
> + return false;
> + }
> +
> + zone_idx = zbd_zone_idx(f, f->file_offset);
> + z = get_zone(f, zone_idx);
> + if ((f->file_offset != z->start) &&
> + (td->o.td_ddir != TD_DDIR_READ)) {
> + new_offset = zbd_zone_end(z);
> + if (new_offset >= f->file_offset + f->io_size) {
> + log_info("%s: io_size must be at least one zone\n",
> + f->file_name);
> + return false;
> + }
> + log_info("%s: rounded up offset from %"PRIu64" to %"PRIu64"\n",
> + f->file_name, f->file_offset,
> + new_offset);
> + f->io_size -= (new_offset - f->file_offset);
> + f->file_offset = new_offset;
> + }
> +
> + zone_idx = zbd_zone_idx(f, f->file_offset + f->io_size);
> + z = get_zone(f, zone_idx);
> + new_end = z->start;
> + if ((td->o.td_ddir != TD_DDIR_READ) &&
> + (f->file_offset + f->io_size != new_end)) {
> + if (new_end <= f->file_offset) {
> + log_info("%s: io_size must be at least one zone\n",
> + f->file_name);
> + return false;
> + }
> + log_info("%s: rounded down io_size from %"PRIu64" to %"PRIu64"\n",
> + f->file_name, f->io_size,
> + new_end - f->file_offset);
> + f->io_size = new_end - f->file_offset;
> + }
> +
> + return true;
> +}
> +
> +/*
> + * Verify whether offset and size parameters are aligned with zone boundaries.
> + */
> +static bool zbd_verify_sizes(void)
> +{
> + struct thread_data *td;
> + struct fio_file *f;
> int i, j;
>
> for_each_td(td, i) {
> for_each_file(td, f, j) {
> - if (!f->zbd_info)
> - continue;
> - if (f->file_offset >= f->real_file_size)
> - continue;
> - if (!zbd_is_seq_job(f))
> - continue;
> -
> - if (!td->o.zone_size) {
> - td->o.zone_size = f->zbd_info->zone_size;
> - if (!td->o.zone_size) {
> - log_err("%s: invalid 0 zone size\n",
> - f->file_name);
> - return false;
> - }
> - } else if (td->o.zone_size != f->zbd_info->zone_size) {
> - log_err("%s: job parameter zonesize %llu does not match disk zone size %"PRIu64".\n",
> - f->file_name, td->o.zone_size,
> - f->zbd_info->zone_size);
> - return false;
> - }
> -
> - if (td->o.zone_skip % td->o.zone_size) {
> - log_err("%s: zoneskip %llu is not a multiple of the device zone size %llu.\n",
> - f->file_name, td->o.zone_skip,
> - td->o.zone_size);
> + if (!zbd_verify_file_sizes(td, f))
Just looking at this, I would assume that zbd_verify_file_sizes() returns 0 on
success.
Perhaps rename zbd_verify_file_sizes to something like:
zbd_file_is_zone_aligned()
then it is more obvious from the name that it returns true on success.
Kind regards,
Niklas
next prev parent reply other threads:[~2021-12-10 12:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 2:15 [PATCH 00/11] Cleanup zbd code Damien Le Moal
2021-12-10 2:15 ` [PATCH 01/11] fio: Improve documentation of ignore_zone_limits option Damien Le Moal
2021-12-10 12:04 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 02/11] zbd: define local functions as static Damien Le Moal
2021-12-10 12:04 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 03/11] zbd: move and cleanup code Damien Le Moal
2021-12-10 12:04 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 04/11] zbd: remove is_zone_open() helper Damien Le Moal
2021-12-10 12:05 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 05/11] zbd: introduce zbd_verify_file_sizes() Damien Le Moal
2021-12-10 12:05 ` Niklas Cassel [this message]
2021-12-10 2:15 ` [PATCH 06/11] zbd: fix code style issues Damien Le Moal
2021-12-10 12:05 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 07/11] zbd: simplify zbd_close_zone() Damien Le Moal
2021-12-10 12:06 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 08/11] zbd: simplify zbd_open_zone() Damien Le Moal
2021-12-10 12:06 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 09/11] zbd: rename zbd_zone_idx() and zbd_zone_nr() Damien Le Moal
2021-12-10 12:07 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 10/11] zbd: rename get_zone() Damien Le Moal
2021-12-10 12:08 ` Niklas Cassel
2021-12-10 2:15 ` [PATCH 11/11] zbd: introduce zbd_get_zone_from_offset() helper Damien Le Moal
2021-12-10 12:09 ` Niklas Cassel
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=YbNChXps+eWFEGXO@x1-carbon \
--to=niklas.cassel@wdc.com \
--cc=axboe@kernel.dk \
--cc=damien.lemoal@opensource.wdc.com \
--cc=fio@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox