git: ccaaee460717 - main - ctl_backend_ramdisk: Prepare for NVMe support

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 03 May 2024 00:16:03 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=ccaaee4607170e167114ace059ce6408a2c465d1

commit ccaaee4607170e167114ace059ce6408a2c465d1
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-05-02 23:32:58 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-05-02 23:38:30 +0000

    ctl_backend_ramdisk: Prepare for NVMe support
    
    - Use wrapper routines for access to shared fields between SCSI and
      NVMe I/O requests.
    
    - Use protocol-agnostic wrapper routines for I/O completion status.
    
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D44849
---
 sys/cam/ctl/ctl_backend_ramdisk.c | 53 +++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/sys/cam/ctl/ctl_backend_ramdisk.c b/sys/cam/ctl/ctl_backend_ramdisk.c
index ecb0caae89b1..1fe239b47293 100644
--- a/sys/cam/ctl/ctl_backend_ramdisk.c
+++ b/sys/cam/ctl/ctl_backend_ramdisk.c
@@ -365,11 +365,10 @@ ctl_backend_ramdisk_cmp(union ctl_io *io)
 	struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
 	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	uint8_t *page;
-	uint8_t info[8];
 	uint64_t lba;
 	u_int lbaoff, lbas, res, off;
 
-	lbas = io->scsiio.kern_data_len / cbe_lun->blocksize;
+	lbas = ctl_kern_data_len(io) / cbe_lun->blocksize;
 	lba = ARGS(io)->lba + PRIV(io)->len - lbas;
 	off = 0;
 	for (; lbas > 0; lbas--, lba++) {
@@ -377,7 +376,7 @@ ctl_backend_ramdisk_cmp(union ctl_io *io)
 		    lba >> cbe_lun->pblockexp, GP_READ);
 		lbaoff = lba & ~(UINT_MAX << cbe_lun->pblockexp);
 		page += lbaoff * cbe_lun->blocksize;
-		res = cmp(io->scsiio.kern_data_ptr + off, page,
+		res = cmp(ctl_kern_data_ptr(io) + off, page,
 		    cbe_lun->blocksize);
 		off += res;
 		if (res < cbe_lun->blocksize)
@@ -385,14 +384,8 @@ ctl_backend_ramdisk_cmp(union ctl_io *io)
 	}
 	free(io->scsiio.kern_data_ptr, M_RAMDISK);
 	if (lbas > 0) {
-		off += io->scsiio.kern_rel_offset - io->scsiio.kern_data_len;
-		scsi_u64to8b(off, info);
-		ctl_set_sense(&io->scsiio, /*current_error*/ 1,
-		    /*sense_key*/ SSD_KEY_MISCOMPARE,
-		    /*asc*/ 0x1D, /*ascq*/ 0x00,
-		    /*type*/ SSD_ELEM_INFO,
-		    /*size*/ sizeof(info), /*data*/ &info,
-		    /*type*/ SSD_ELEM_NONE);
+		off += ctl_kern_rel_offset(io) - ctl_kern_data_len(io);
+		ctl_io_set_compare_failure(io, off);
 		return (1);
 	}
 	return (0);
@@ -405,9 +398,9 @@ ctl_backend_ramdisk_move_done(union ctl_io *io, bool samethr)
 	    (struct ctl_be_ramdisk_lun *)CTL_BACKEND_LUN(io);
 
 	CTL_DEBUG_PRINT(("ctl_backend_ramdisk_move_done\n"));
-	if (io->scsiio.kern_sg_entries > 0)
-		free(io->scsiio.kern_data_ptr, M_RAMDISK);
-	io->scsiio.kern_rel_offset += io->scsiio.kern_data_len;
+	if (ctl_kern_sg_entries(io) > 0)
+		free(ctl_kern_data_ptr(io), M_RAMDISK);
+	ctl_add_kern_rel_offset(io, ctl_kern_data_len(io));
 	if ((io->io_hdr.flags & CTL_FLAG_ABORT) == 0 &&
 	    (io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE) {
 		if (ARGS(io)->flags & CTL_LLF_COMPARE) {
@@ -424,7 +417,7 @@ ctl_backend_ramdisk_move_done(union ctl_io *io, bool samethr)
 			    &be_lun->io_task);
 			return (0);
 		}
-		ctl_set_success(&io->scsiio);
+		ctl_io_set_success(io);
 	}
 done:
 	ctl_data_submit_done(io);
@@ -441,10 +434,10 @@ ctl_backend_ramdisk_compare(union ctl_io *io)
 	lbas = MIN(lbas, 131072 / cbe_lun->blocksize);
 	len = lbas * cbe_lun->blocksize;
 
-	io->scsiio.be_move_done = ctl_backend_ramdisk_move_done;
-	io->scsiio.kern_data_ptr = malloc(len, M_RAMDISK, M_WAITOK);
-	io->scsiio.kern_data_len = len;
-	io->scsiio.kern_sg_entries = 0;
+	ctl_set_be_move_done(io, ctl_backend_ramdisk_move_done);
+	ctl_set_kern_data_ptr(io, malloc(len, M_RAMDISK, M_WAITOK));
+	ctl_set_kern_data_len(io, len);
+	ctl_set_kern_sg_entries(io, 0);
 	io->io_hdr.flags |= CTL_FLAG_ALLOCATED;
 	PRIV(io)->len += lbas;
 	ctl_datamove(io);
@@ -469,17 +462,17 @@ ctl_backend_ramdisk_rw(union ctl_io *io)
 	off = lbaoff * cbe_lun->blocksize;
 	op = (ARGS(io)->flags & CTL_LLF_WRITE) ? GP_WRITE : GP_READ;
 	if (sgs > 1) {
-		io->scsiio.kern_data_ptr = malloc(sizeof(struct ctl_sg_entry) *
-		    sgs, M_RAMDISK, M_WAITOK);
-		sg_entries = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr;
+		sg_entries = malloc(sizeof(struct ctl_sg_entry) * sgs,
+		    M_RAMDISK, M_WAITOK);
+		ctl_set_kern_data_ptr(io, sg_entries);
 		len = lbas * cbe_lun->blocksize;
 		for (i = 0; i < sgs; i++) {
 			page = ctl_backend_ramdisk_getpage(be_lun,
 			    (lba >> cbe_lun->pblockexp) + i, op);
 			if (page == P_UNMAPPED || page == P_ANCHORED) {
-				free(io->scsiio.kern_data_ptr, M_RAMDISK);
+				free(sg_entries, M_RAMDISK);
 nospc:
-				ctl_set_space_alloc_fail(&io->scsiio);
+				ctl_io_set_space_alloc_fail(io);
 				ctl_data_submit_done(io);
 				return;
 			}
@@ -494,17 +487,17 @@ nospc:
 		if (page == P_UNMAPPED || page == P_ANCHORED)
 			goto nospc;
 		sgs = 0;
-		io->scsiio.kern_data_ptr = page + off;
+		ctl_set_kern_data_ptr(io, page + off);
 	}
 
-	io->scsiio.be_move_done = ctl_backend_ramdisk_move_done;
-	io->scsiio.kern_data_len = lbas * cbe_lun->blocksize;
-	io->scsiio.kern_sg_entries = sgs;
+	ctl_set_be_move_done(io, ctl_backend_ramdisk_move_done);
+	ctl_set_kern_data_len(io, lbas * cbe_lun->blocksize);
+	ctl_set_kern_sg_entries(io, sgs);
 	io->io_hdr.flags |= CTL_FLAG_ALLOCATED;
 	PRIV(io)->len += lbas;
 	if ((ARGS(io)->flags & CTL_LLF_READ) &&
 	    ARGS(io)->len <= PRIV(io)->len) {
-		ctl_set_success(&io->scsiio);
+		ctl_io_set_success(io);
 		if (cbe_lun->serseq >= CTL_LUN_SERSEQ_SOFT)
 			ctl_serseq_done(io);
 	}
@@ -517,7 +510,7 @@ ctl_backend_ramdisk_submit(union ctl_io *io)
 	struct ctl_lba_len_flags *lbalen = ARGS(io);
 
 	if (lbalen->flags & CTL_LLF_VERIFY) {
-		ctl_set_success(&io->scsiio);
+		ctl_io_set_success(io);
 		ctl_data_submit_done(io);
 		return (CTL_RETVAL_COMPLETE);
 	}