All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: fio@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: Niklas Cassel <niklas.cassel@wdc.com>,
	Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Subject: [PATCH v2 11/12] zbd: introduce zbd_offset_to_zone() helper
Date: Tue, 14 Dec 2021 10:24:12 +0900	[thread overview]
Message-ID: <20211214012413.464798-12-damien.lemoal@opensource.wdc.com> (raw)
In-Reply-To: <20211214012413.464798-1-damien.lemoal@opensource.wdc.com>

Introduce the helper function zbd_offset_to_zone() to get a zone
structure using a file offset. In many functions, this replaces the
two line code pattern:

	zone_idx = zbd_offset_to_zone_idx(f, offset);
	z = zbd_get_zone(f, zone_idx);

with a single line of code:

	z = zbd_offset_to_zone(f, offset);

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
 zbd.c | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/zbd.c b/zbd.c
index 095a6bad..b1fd6b4b 100644
--- a/zbd.c
+++ b/zbd.c
@@ -129,6 +129,12 @@ static inline struct fio_zone_info *zbd_get_zone(const struct fio_file *f,
 	return &f->zbd_info->zone_info[zone_idx];
 }
 
+static inline struct fio_zone_info *
+zbd_offset_to_zone(const struct fio_file *f,  uint64_t offset)
+{
+	return zbd_get_zone(f, zbd_offset_to_zone_idx(f, offset));
+}
+
 /**
  * zbd_get_zoned_model - Get a device zoned model
  * @td: FIO thread data
@@ -510,7 +516,6 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td,
 {
 	const struct fio_zone_info *z;
 	uint64_t new_offset, new_end;
-	uint32_t zone_idx;
 
 	if (!f->zbd_info)
 		return true;
@@ -540,8 +545,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td,
 		return false;
 	}
 
-	zone_idx = zbd_offset_to_zone_idx(f, f->file_offset);
-	z = zbd_get_zone(f, zone_idx);
+	z = zbd_offset_to_zone(f, f->file_offset);
 	if ((f->file_offset != z->start) &&
 	    (td->o.td_ddir != TD_DDIR_READ)) {
 		new_offset = zbd_zone_end(z);
@@ -557,8 +561,7 @@ static bool zbd_zone_align_file_sizes(struct thread_data *td,
 		f->file_offset = new_offset;
 	}
 
-	zone_idx = zbd_offset_to_zone_idx(f, f->file_offset + f->io_size);
-	z = zbd_get_zone(f, zone_idx);
+	z = zbd_offset_to_zone(f, f->file_offset + f->io_size);
 	new_end = z->start;
 	if ((td->o.td_ddir != TD_DDIR_READ) &&
 	    (f->file_offset + f->io_size != new_end)) {
@@ -1595,15 +1598,11 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q,
 	const struct fio_file *f = io_u->file;
 	struct zoned_block_device_info *zbd_info = f->zbd_info;
 	struct fio_zone_info *z;
-	uint32_t zone_idx;
 	uint64_t zone_end;
 
 	assert(zbd_info);
 
-	zone_idx = zbd_offset_to_zone_idx(f, io_u->offset);
-	assert(zone_idx < zbd_info->nr_zones);
-	z = zbd_get_zone(f, zone_idx);
-
+	z = zbd_offset_to_zone(f, io_u->offset);
 	assert(z->has_wp);
 
 	if (!success)
@@ -1611,7 +1610,7 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q,
 
 	dprint(FD_ZBD,
 	       "%s: queued I/O (%lld, %llu) for zone %u\n",
-	       f->file_name, io_u->offset, io_u->buflen, zone_idx);
+	       f->file_name, io_u->offset, io_u->buflen, zbd_zone_idx(f, z));
 
 	switch (io_u->ddir) {
 	case DDIR_WRITE:
@@ -1654,19 +1653,15 @@ static void zbd_put_io(struct thread_data *td, const struct io_u *io_u)
 	const struct fio_file *f = io_u->file;
 	struct zoned_block_device_info *zbd_info = f->zbd_info;
 	struct fio_zone_info *z;
-	uint32_t zone_idx;
 
 	assert(zbd_info);
 
-	zone_idx = zbd_offset_to_zone_idx(f, io_u->offset);
-	assert(zone_idx < zbd_info->nr_zones);
-	z = zbd_get_zone(f, zone_idx);
-
+	z = zbd_offset_to_zone(f, io_u->offset);
 	assert(z->has_wp);
 
 	dprint(FD_ZBD,
 	       "%s: terminate I/O (%lld, %llu) for zone %u\n",
-	       f->file_name, io_u->offset, io_u->buflen, zone_idx);
+	       f->file_name, io_u->offset, io_u->buflen, zbd_zone_idx(f, z));
 
 	zbd_end_zone_io(td, io_u, z);
 
@@ -1708,14 +1703,12 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u)
 	struct fio_file *f = io_u->file;
 	enum fio_ddir ddir = io_u->ddir;
 	struct fio_zone_info *z;
-	uint32_t zone_idx;
 
 	assert(td->o.zone_mode == ZONE_MODE_ZBD);
 	assert(td->o.zone_size);
 	assert(f->zbd_info);
 
-	zone_idx = zbd_offset_to_zone_idx(f, f->last_pos[ddir]);
-	z = zbd_get_zone(f, zone_idx);
+	z = zbd_offset_to_zone(f, f->last_pos[ddir]);
 
 	/*
 	 * When the zone capacity is smaller than the zone size and the I/O is
@@ -1729,7 +1722,7 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u)
 		       "%s: Jump from zone capacity limit to zone end:"
 		       " (%"PRIu64" -> %"PRIu64") for zone %u (%"PRIu64")\n",
 		       f->file_name, f->last_pos[ddir],
-		       zbd_zone_end(z), zone_idx, z->capacity);
+		       zbd_zone_end(z), zbd_zone_idx(f, z), z->capacity);
 		td->io_skip_bytes += zbd_zone_end(z) - f->last_pos[ddir];
 		f->last_pos[ddir] = zbd_zone_end(z);
 	}
@@ -1810,7 +1803,6 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u)
 {
 	struct fio_file *f = io_u->file;
 	struct zoned_block_device_info *zbdi = f->zbd_info;
-	uint32_t zone_idx_b;
 	struct fio_zone_info *zb, *zl, *orig_zb;
 	uint32_t orig_len = io_u->buflen;
 	uint64_t min_bs = td->o.min_bs[io_u->ddir];
@@ -1822,8 +1814,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u)
 	assert(is_valid_offset(f, io_u->offset));
 	assert(io_u->buflen);
 
-	zone_idx_b = zbd_offset_to_zone_idx(f, io_u->offset);
-	zb = zbd_get_zone(f, zone_idx_b);
+	zb = zbd_offset_to_zone(f, io_u->offset);
 	orig_zb = zb;
 
 	if (!zb->has_wp) {
@@ -2102,12 +2093,9 @@ int zbd_do_io_u_trim(const struct thread_data *td, struct io_u *io_u)
 {
 	struct fio_file *f = io_u->file;
 	struct fio_zone_info *z;
-	uint32_t zone_idx;
 	int ret;
 
-	zone_idx = zbd_offset_to_zone_idx(f, io_u->offset);
-	z = zbd_get_zone(f, zone_idx);
-
+	z = zbd_offset_to_zone(f, io_u->offset);
 	if (!z->has_wp)
 		return 0;
 
-- 
2.31.1


  parent reply	other threads:[~2021-12-14  1:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14  1:24 [PATCH v2 00/12] Cleanup zbd code Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 01/12] fio: Improve documentation of ignore_zone_limits option Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 02/12] zbd: define local functions as static Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 03/12] zbd: move and cleanup code Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 04/12] zbd: remove is_zone_open() helper Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 05/12] zbd: introduce zbd_zone_align_file_sizes() helper Damien Le Moal
2021-12-14  8:33   ` Niklas Cassel
2021-12-14  1:24 ` [PATCH v2 06/12] zbd: fix code style issues Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 07/12] zbd: simplify zbd_close_zone() Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 08/12] zbd: simplify zbd_open_zone() Damien Le Moal
2021-12-14  1:24 ` [PATCH v2 09/12] zbd: rename zbd_zone_idx() and zbd_zone_nr() Damien Le Moal
2021-12-14  8:33   ` Niklas Cassel
2021-12-14  1:24 ` [PATCH v2 10/12] zbd: rename get_zone() Damien Le Moal
2021-12-14  1:24 ` Damien Le Moal [this message]
2021-12-14  8:34   ` [PATCH v2 11/12] zbd: introduce zbd_offset_to_zone() helper Niklas Cassel
2021-12-14  1:24 ` [PATCH v2 12/12] t/zbd: Avoid inappropriate blkzone command call in zone_cap_bs Damien Le Moal
2021-12-14  8:34   ` Niklas Cassel
2021-12-14 13:48 ` [PATCH v2 00/12] Cleanup zbd code Jens Axboe

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=20211214012413.464798-12-damien.lemoal@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    --cc=niklas.cassel@wdc.com \
    --cc=shinichiro.kawasaki@wdc.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.