All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ankit Kumar <ankit.kumar@samsung.com>
To: axboe@kernel.dk, vincentfu@gmail.com
Cc: fio@vger.kernel.org, kbusch@kernel.org, joshi.k@samsung.com,
	martin.petersen@oracle.com, Ankit Kumar <ankit.kumar@samsung.com>
Subject: [PATCH v3 02/10] engines:io_uring: update arguments to fetch nvme data
Date: Mon, 14 Aug 2023 20:27:39 +0530	[thread overview]
Message-ID: <20230814145747.114725-3-ankit.kumar@samsung.com> (raw)
In-Reply-To: <20230814145747.114725-1-ankit.kumar@samsung.com>

This is a prep patch to keep number of arguments for fio_nvme_get_info
in check. The follow up patches will enable metadata, protection info.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
---
 engines/io_uring.c | 38 +++++++++++++-------------------------
 engines/nvme.c     | 16 ++++++++++------
 engines/nvme.h     |  5 +++--
 3 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/engines/io_uring.c b/engines/io_uring.c
index 09065463..30d9ccd7 100644
--- a/engines/io_uring.c
+++ b/engines/io_uring.c
@@ -1086,30 +1086,24 @@ static int fio_ioring_cmd_open_file(struct thread_data *td, struct fio_file *f)
 
 	if (o->cmd_type == FIO_URING_CMD_NVME) {
 		struct nvme_data *data = NULL;
-		unsigned int nsid, lba_size = 0;
-		__u32 ms = 0;
+		unsigned int lba_size = 0;
 		__u64 nlba = 0;
 		int ret;
 
 		/* Store the namespace-id and lba size. */
 		data = FILE_ENG_DATA(f);
 		if (data == NULL) {
-			ret = fio_nvme_get_info(f, &nsid, &lba_size, &ms, &nlba);
-			if (ret)
-				return ret;
-
 			data = calloc(1, sizeof(struct nvme_data));
-			data->nsid = nsid;
-			if (ms)
-				data->lba_ext = lba_size + ms;
-			else
-				data->lba_shift = ilog2(lba_size);
+			ret = fio_nvme_get_info(f, &nlba, data);
+			if (ret) {
+				free(data);
+				return ret;
+			}
 
 			FILE_SET_ENG_DATA(f, data);
 		}
 
-		assert(data->lba_shift < 32);
-		lba_size = data->lba_ext ? data->lba_ext : (1U << data->lba_shift);
+		lba_size = data->lba_ext ? data->lba_ext : data->lba_size;
 
 		for_each_rw_ddir(ddir) {
 			if (td->o.min_bs[ddir] % lba_size ||
@@ -1173,23 +1167,17 @@ static int fio_ioring_cmd_get_file_size(struct thread_data *td,
 
 	if (o->cmd_type == FIO_URING_CMD_NVME) {
 		struct nvme_data *data = NULL;
-		unsigned int nsid, lba_size = 0;
-		__u32 ms = 0;
 		__u64 nlba = 0;
 		int ret;
 
-		ret = fio_nvme_get_info(f, &nsid, &lba_size, &ms, &nlba);
-		if (ret)
-			return ret;
-
 		data = calloc(1, sizeof(struct nvme_data));
-		data->nsid = nsid;
-		if (ms)
-			data->lba_ext = lba_size + ms;
-		else
-			data->lba_shift = ilog2(lba_size);
+		ret = fio_nvme_get_info(f, &nlba, data);
+		if (ret) {
+			free(data);
+			return ret;
+		}
 
-		f->real_file_size = lba_size * nlba;
+		f->real_file_size = data->lba_size * nlba;
 		fio_file_set_size_known(f);
 
 		FILE_SET_ENG_DATA(f, data);
diff --git a/engines/nvme.c b/engines/nvme.c
index b18ad4c2..7e891eed 100644
--- a/engines/nvme.c
+++ b/engines/nvme.c
@@ -99,8 +99,7 @@ static int nvme_identify(int fd, __u32 nsid, enum nvme_identify_cns cns,
 	return ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
 }
 
-int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz,
-		      __u32 *ms, __u64 *nlba)
+int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, struct nvme_data *data)
 {
 	struct nvme_id_ns ns;
 	int namespace_id;
@@ -137,7 +136,7 @@ int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz,
 		return err;
 	}
 
-	*nsid = namespace_id;
+	data->nsid = namespace_id;
 
 	/*
 	 * 16 or 64 as maximum number of supported LBA formats.
@@ -149,21 +148,26 @@ int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz,
 	else
 		format_idx = (ns.flbas & 0xf) + (((ns.flbas >> 5) & 0x3) << 4);
 
-	*lba_sz = 1 << ns.lbaf[format_idx].ds;
+	data->lba_size = 1 << ns.lbaf[format_idx].ds;
 
 	/*
 	 * Only extended LBA can be supported.
 	 * Bit 4 for flbas indicates if metadata is transferred at the end of
 	 * logical block creating an extended LBA.
 	 */
-	*ms = le16_to_cpu(ns.lbaf[format_idx].ms);
-	if (*ms && !((ns.flbas >> 4) & 0x1)) {
+	data->ms = le16_to_cpu(ns.lbaf[format_idx].ms);
+	if (data->ms && !((ns.flbas >> 4) & 0x1)) {
 		log_err("%s: only extended logical block can be supported\n",
 			f->file_name);
 		err = -ENOTSUP;
 		goto out;
 	}
 
+	if (data->ms)
+		data->lba_ext = data->lba_size + data->ms;
+	else
+		data->lba_shift = ilog2(data->lba_size);
+
 	/* Check for end to end data protection support */
 	if (ns.dps & 0x3) {
 		log_err("%s: end to end data protection not supported\n",
diff --git a/engines/nvme.h b/engines/nvme.h
index 238471dd..e742b14f 100644
--- a/engines/nvme.h
+++ b/engines/nvme.h
@@ -88,7 +88,9 @@ enum nvme_zns_zs {
 struct nvme_data {
 	__u32 nsid;
 	__u32 lba_shift;
+	__u32 lba_size;
 	__u32 lba_ext;
+	__u16 ms;
 };
 
 struct nvme_lbaf {
@@ -219,8 +221,7 @@ struct nvme_dsm_range {
 int fio_nvme_iomgmt_ruhs(struct thread_data *td, struct fio_file *f,
 			 struct nvme_fdp_ruh_status *ruhs, __u32 bytes);
 
-int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz,
-		      __u32 *ms, __u64 *nlba);
+int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, struct nvme_data *data);
 
 int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
 			    struct iovec *iov, struct nvme_dsm_range *dsm);
-- 
2.25.1


  parent reply	other threads:[~2023-08-14  9:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230814093836epcas5p44bc762fa6e4368d532126494115aeba4@epcas5p4.samsung.com>
2023-08-14 14:57 ` [PATCH v3 00/10] Protection information support for io_uring passthrough engine Ankit Kumar
2023-08-14 14:40   ` Vincent Fu
     [not found]   ` <CGME20230814093838epcas5p31b8e832e14afecd49ac828505f325b74@epcas5p3.samsung.com>
2023-08-14 14:57     ` [PATCH v3 01/10] engines:io_uring: add missing error during open file Ankit Kumar
     [not found]   ` <CGME20230814093840epcas5p4177e2c9b9b01f99ea5fd1edd6bc8648b@epcas5p4.samsung.com>
2023-08-14 14:57     ` Ankit Kumar [this message]
     [not found]   ` <CGME20230814093842epcas5p22d5ee07c754ebd5067df214fe4f26dec@epcas5p2.samsung.com>
2023-08-14 14:57     ` [PATCH v3 03/10] engines:io_uring: enable support for separate metadata buffer Ankit Kumar
     [not found]   ` <CGME20230814093844epcas5p2a8eddaeddfbfd01e219491c2c4d79cd7@epcas5p2.samsung.com>
2023-08-14 14:57     ` [PATCH v3 04/10] engines:io_uring: uring_cmd add support for protection info Ankit Kumar
     [not found]   ` <CGME20230814093845epcas5p1e05696c12c9a9720252b80a522d7199c@epcas5p1.samsung.com>
2023-08-14 14:57     ` [PATCH v3 05/10] io_u: move engine data out of union Ankit Kumar
     [not found]   ` <CGME20230814093848epcas5p412a0c5dbf28155c30fe89297135c021d@epcas5p4.samsung.com>
2023-08-14 14:57     ` [PATCH v3 06/10] crc: pull required crc16-t10 files from linux kernel Ankit Kumar
     [not found]   ` <CGME20230814093849epcas5p431ac99960acca2847c4c3226c5781c7e@epcas5p4.samsung.com>
2023-08-14 14:57     ` [PATCH v3 07/10] engines:io_uring: generate and verify pi for 16b guard Ankit Kumar
     [not found]   ` <CGME20230814093851epcas5p28d3ff209e6f92d407d021a566946cacd@epcas5p2.samsung.com>
2023-08-14 14:57     ` [PATCH v3 08/10] crc: pull required crc64 nvme apis from linux kernel Ankit Kumar
     [not found]   ` <CGME20230814093853epcas5p4973ef04622e9bafbc73a9a71c84b94ca@epcas5p4.samsung.com>
2023-08-14 14:57     ` [PATCH v3 09/10] engines:nvme: pull required 48 bit accessors " Ankit Kumar
     [not found]   ` <CGME20230814093854epcas5p3875babea8f98e2414d06ca075d0cd18e@epcas5p3.samsung.com>
2023-08-14 14:57     ` [PATCH v3 10/10] engines:io_uring: generate and verify pi for 64b guard Ankit Kumar
2023-08-14 21:53   ` [PATCH v3 00/10] Protection information support for io_uring passthrough engine 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=20230814145747.114725-3-ankit.kumar@samsung.com \
    --to=ankit.kumar@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    --cc=joshi.k@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=vincentfu@gmail.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.