[PATCH 3/7] engines/nvme: refactor filling protection information

Vincent Fu <[email protected]> Fri, 25 Jul 2025 13:57:59 -0400
Newsgroups org.kernel.vger.fio
Message-ID <[email protected]>
Factor out of fio_nvme_pi_fill() the code that generates and fills in
the Guard Protection Information field. This is so that later patches
can use this code without filling in the fields in the NVMe command.

No functional change intended.

Signed-off-by: Anuj Gupta <[email protected]>
Signed-off-by: Vincent Fu <[email protected]>
---
 engines/nvme.c | 19 +++++++++++++------
 engines/nvme.h |  2 ++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/engines/nvme.c b/engines/nvme.c
index 1e142e8d..4b3d3860 100644
--- a/engines/nvme.c
+++ b/engines/nvme.c
@@ -405,14 +405,9 @@ int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
 	return 0;
 }
 
-void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
-		      struct nvme_cmd_ext_io_opts *opts)
+void fio_nvme_generate_guard(struct io_u *io_u, struct nvme_cmd_ext_io_opts *opts)
 {
 	struct nvme_data *data = FILE_ENG_DATA(io_u->file);
-	__u64 slba;
-
-	slba = get_slba(data, io_u->offset);
-	cmd->cdw12 |= opts->io_flags;
 
 	if (data->pi_type && !(opts->io_flags & NVME_IO_PRINFO_PRACT)) {
 		if (data->guard_type == NVME_NVM_NS_16B_GUARD)
@@ -420,6 +415,18 @@ void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
 		else if (data->guard_type == NVME_NVM_NS_64B_GUARD)
 			fio_nvme_generate_pi_64b_guard(data, io_u, opts);
 	}
+}
+
+void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
+		      struct nvme_cmd_ext_io_opts *opts)
+{
+	struct nvme_data *data = FILE_ENG_DATA(io_u->file);
+	__u64 slba;
+
+	slba = get_slba(data, io_u->offset);
+	cmd->cdw12 |= opts->io_flags;
+
+	fio_nvme_generate_guard(io_u, opts);
 
 	switch (data->pi_type) {
 	case NVME_NS_DPS_PI_TYPE1:
diff --git a/engines/nvme.h b/engines/nvme.h
index 0fef54e9..4371eb5b 100644
--- a/engines/nvme.h
+++ b/engines/nvme.h
@@ -438,6 +438,8 @@ int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
 void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
 		      struct nvme_cmd_ext_io_opts *opts);
 
+void fio_nvme_generate_guard(struct io_u *io_u, struct nvme_cmd_ext_io_opts *opts);
+
 int fio_nvme_pi_verify(struct nvme_data *data, struct io_u *io_u);
 
 int fio_nvme_get_zoned_model(struct thread_data *td, struct fio_file *f,
-- 
2.47.2