svn commit: r361734 - stable/12/sys/cam/ctl

Alexander Motin mav at FreeBSD.org
Tue Jun 2 20:40:13 UTC 2020


Author: mav
Date: Tue Jun  2 20:40:10 2020
New Revision: 361734
URL: https://svnweb.freebsd.org/changeset/base/361734

Log:
  MFC r361604: Make struct ctl_be_lun first element of struct ctl_be_*_lun.
  
  It allows to remove some extra pointer dereferences and slightly tightens
  up the code by unification.

Modified:
  stable/12/sys/cam/ctl/ctl.c
  stable/12/sys/cam/ctl/ctl_backend.h
  stable/12/sys/cam/ctl/ctl_backend_block.c
  stable/12/sys/cam/ctl/ctl_backend_ramdisk.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/cam/ctl/ctl.c
==============================================================================
--- stable/12/sys/cam/ctl/ctl.c	Tue Jun  2 20:39:34 2020	(r361733)
+++ stable/12/sys/cam/ctl/ctl.c	Tue Jun  2 20:40:10 2020	(r361734)
@@ -3081,7 +3081,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, 
 				break;
 
 			if (lun->backend->lun_info != NULL) {
-				retval = lun->backend->lun_info(lun->be_lun->be_lun, sb);
+				retval = lun->backend->lun_info(lun->be_lun, sb);
 				if (retval != 0)
 					break;
 			}
@@ -4749,7 +4749,7 @@ ctl_free_lun(struct ctl_lun *lun)
 	/*
 	 * Tell the backend to free resources, if this LUN has a backend.
 	 */
-	lun->be_lun->lun_shutdown(lun->be_lun->be_lun);
+	lun->be_lun->lun_shutdown(lun->be_lun);
 
 	lun->ie_reportcnt = UINT32_MAX;
 	callout_drain(&lun->ie_callout);
@@ -6706,7 +6706,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
 	data = page_index->page_data;
 
 	if (lun->backend->lun_attr != NULL &&
-	    (val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksavail"))
+	    (val = lun->backend->lun_attr(lun->be_lun, "blocksavail"))
 	     != UINT64_MAX) {
 		phdr = (struct scsi_log_param_header *)data;
 		scsi_ulto2b(0x0001, phdr->param_code);
@@ -6719,7 +6719,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
 	}
 
 	if (lun->backend->lun_attr != NULL &&
-	    (val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksused"))
+	    (val = lun->backend->lun_attr(lun->be_lun, "blocksused"))
 	     != UINT64_MAX) {
 		phdr = (struct scsi_log_param_header *)data;
 		scsi_ulto2b(0x0002, phdr->param_code);
@@ -6732,7 +6732,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
 	}
 
 	if (lun->backend->lun_attr != NULL &&
-	    (val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksavail"))
+	    (val = lun->backend->lun_attr(lun->be_lun, "poolblocksavail"))
 	     != UINT64_MAX) {
 		phdr = (struct scsi_log_param_header *)data;
 		scsi_ulto2b(0x00f1, phdr->param_code);
@@ -6745,7 +6745,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
 	}
 
 	if (lun->backend->lun_attr != NULL &&
-	    (val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksused"))
+	    (val = lun->backend->lun_attr(lun->be_lun, "poolblocksused"))
 	     != UINT64_MAX) {
 		phdr = (struct scsi_log_param_header *)data;
 		scsi_ulto2b(0x00f2, phdr->param_code);
@@ -13384,8 +13384,7 @@ ctl_thresh_thread(void *arg)
 					continue;
 				}
 				mtx_unlock(&softc->ctl_lock); // XXX
-				val = lun->backend->lun_attr(
-				    lun->be_lun->be_lun, attr);
+				val = lun->backend->lun_attr(lun->be_lun, attr);
 				mtx_lock(&softc->ctl_lock);
 				if (val == UINT64_MAX)
 					continue;

Modified: stable/12/sys/cam/ctl/ctl_backend.h
==============================================================================
--- stable/12/sys/cam/ctl/ctl_backend.h	Tue Jun  2 20:39:34 2020	(r361733)
+++ stable/12/sys/cam/ctl/ctl_backend.h	Tue Jun  2 20:40:10 2020	(r361734)
@@ -80,7 +80,8 @@ typedef enum {
 	MODULE_DEPEND(name, cam, 1, 1, 1)
 
 
-typedef void (*be_callback_t)(void *be_lun);
+struct ctl_be_lun;
+typedef void (*be_callback_t)(struct ctl_be_lun *be_lun);
 
 /*
  * The lun_type field is the SCSI device type of this particular LUN.  In
@@ -147,7 +148,6 @@ struct ctl_be_lun {
 	uint8_t			lun_type;	/* passed to CTL */
 	ctl_backend_lun_flags	flags;		/* passed to CTL */
 	ctl_lun_serseq		serseq;		/* passed to CTL */
-	void			*be_lun;	/* passed to CTL */
 	uint64_t		maxlba;		/* passed to CTL */
 	uint32_t		blocksize;	/* passed to CTL */
 	uint16_t		pblockexp;	/* passed to CTL */
@@ -178,8 +178,8 @@ typedef int (*be_func_t)(union ctl_io *io);
 typedef void (*be_vfunc_t)(union ctl_io *io);
 typedef int (*be_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
 			  struct thread *td);
-typedef int (*be_luninfo_t)(void *be_lun, struct sbuf *sb);
-typedef uint64_t (*be_lunattr_t)(void *be_lun, const char *attrname);
+typedef int (*be_luninfo_t)(struct ctl_be_lun *be_lun, struct sbuf *sb);
+typedef uint64_t (*be_lunattr_t)(struct ctl_be_lun *be_lun, const char *attrname);
 
 struct ctl_backend_driver {
 	char		  name[CTL_BE_NAME_LEN]; /* passed to CTL */

Modified: stable/12/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- stable/12/sys/cam/ctl/ctl_backend_block.c	Tue Jun  2 20:39:34 2020	(r361733)
+++ stable/12/sys/cam/ctl/ctl_backend_block.c	Tue Jun  2 20:40:10 2020	(r361734)
@@ -152,6 +152,7 @@ typedef uint64_t (*cbb_getattr_t)(struct ctl_be_block_
  * and a backend block LUN, and between a backend block LUN and a CTL LUN.
  */
 struct ctl_be_block_lun {
+	struct ctl_be_lun cbe_lun;		/* Must be first element. */
 	struct ctl_lun_create_params params;
 	char *dev_path;
 	ctl_be_block_type dev_type;
@@ -168,7 +169,6 @@ struct ctl_be_block_lun {
 	struct devstat *disk_stats;
 	ctl_be_block_lun_flags flags;
 	SLIST_ENTRY(ctl_be_block_lun) links;
-	struct ctl_be_lun cbe_lun;
 	struct taskqueue *io_taskqueue;
 	struct task io_task;
 	int num_threads;
@@ -272,11 +272,11 @@ static int ctl_be_block_rm(struct ctl_be_block_softc *
 			   struct ctl_lun_req *req);
 static int ctl_be_block_modify(struct ctl_be_block_softc *softc,
 			   struct ctl_lun_req *req);
-static void ctl_be_block_lun_shutdown(void *be_lun);
+static void ctl_be_block_lun_shutdown(struct ctl_be_lun *cbe_lun);
 static int ctl_be_block_config_write(union ctl_io *io);
 static int ctl_be_block_config_read(union ctl_io *io);
-static int ctl_be_block_lun_info(void *be_lun, struct sbuf *sb);
-static uint64_t ctl_be_block_lun_attr(void *be_lun, const char *attrname);
+static int ctl_be_block_lun_info(struct ctl_be_lun *cbe_lun, struct sbuf *sb);
+static uint64_t ctl_be_block_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname);
 static int ctl_be_block_init(void);
 static int ctl_be_block_shutdown(void);
 
@@ -1736,12 +1736,10 @@ static int
 ctl_be_block_submit(union ctl_io *io)
 {
 	struct ctl_be_block_lun *be_lun;
-	struct ctl_be_lun *cbe_lun;
 
 	DPRINTF("entered\n");
 
-	cbe_lun = CTL_BACKEND_LUN(io);
-	be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
+	be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io);
 
 	/*
 	 * Make sure we only get SCSI I/O.
@@ -2222,7 +2220,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, 
 
 	be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK);
 	cbe_lun = &be_lun->cbe_lun;
-	cbe_lun->be_lun = be_lun;
 	be_lun->params = req->reqdata.create;
 	be_lun->softc = softc;
 	STAILQ_INIT(&be_lun->input_queue);
@@ -2586,9 +2583,9 @@ bailout_error:
 }
 
 static void
-ctl_be_block_lun_shutdown(void *lun)
+ctl_be_block_lun_shutdown(struct ctl_be_lun *cbe_lun)
 {
-	struct ctl_be_block_lun *be_lun = lun;
+	struct ctl_be_block_lun *be_lun = (struct ctl_be_block_lun *)cbe_lun;
 	struct ctl_be_block_softc *softc = be_lun->softc;
 
 	taskqueue_drain_all(be_lun->io_taskqueue);
@@ -2619,7 +2616,7 @@ ctl_be_block_config_write(union ctl_io *io)
 	DPRINTF("entered\n");
 
 	cbe_lun = CTL_BACKEND_LUN(io);
-	be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
+	be_lun = (struct ctl_be_block_lun *)cbe_lun;
 
 	retval = 0;
 	switch (io->scsiio.cdb[0]) {
@@ -2698,13 +2695,11 @@ static int
 ctl_be_block_config_read(union ctl_io *io)
 {
 	struct ctl_be_block_lun *be_lun;
-	struct ctl_be_lun *cbe_lun;
 	int retval = 0;
 
 	DPRINTF("entered\n");
 
-	cbe_lun = CTL_BACKEND_LUN(io);
-	be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
+	be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io);
 
 	switch (io->scsiio.cdb[0]) {
 	case SERVICE_ACTION_IN:
@@ -2738,13 +2733,11 @@ ctl_be_block_config_read(union ctl_io *io)
 }
 
 static int
-ctl_be_block_lun_info(void *be_lun, struct sbuf *sb)
+ctl_be_block_lun_info(struct ctl_be_lun *cbe_lun, struct sbuf *sb)
 {
-	struct ctl_be_block_lun *lun;
+	struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)cbe_lun;
 	int retval;
 
-	lun = (struct ctl_be_block_lun *)be_lun;
-
 	retval = sbuf_printf(sb, "\t<num_threads>");
 	if (retval != 0)
 		goto bailout;
@@ -2758,9 +2751,9 @@ bailout:
 }
 
 static uint64_t
-ctl_be_block_lun_attr(void *be_lun, const char *attrname)
+ctl_be_block_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname)
 {
-	struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)be_lun;
+	struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)cbe_lun;
 
 	if (lun->getattr == NULL)
 		return (UINT64_MAX);

Modified: stable/12/sys/cam/ctl/ctl_backend_ramdisk.c
==============================================================================
--- stable/12/sys/cam/ctl/ctl_backend_ramdisk.c	Tue Jun  2 20:39:34 2020	(r361733)
+++ stable/12/sys/cam/ctl/ctl_backend_ramdisk.c	Tue Jun  2 20:40:10 2020	(r361734)
@@ -106,6 +106,7 @@ typedef enum {
 } ctl_be_ramdisk_lun_flags;
 
 struct ctl_be_ramdisk_lun {
+	struct ctl_be_lun	cbe_lun;	/* Must be first element. */
 	struct ctl_lun_create_params params;
 	int			indir;
 	uint8_t			**pages;
@@ -120,7 +121,6 @@ struct ctl_be_ramdisk_lun {
 	struct ctl_be_ramdisk_softc *softc;
 	ctl_be_ramdisk_lun_flags flags;
 	SLIST_ENTRY(ctl_be_ramdisk_lun) links;
-	struct ctl_be_lun	cbe_lun;
 	struct taskqueue	*io_taskqueue;
 	struct task		io_task;
 	STAILQ_HEAD(, ctl_io_hdr) cont_queue;
@@ -146,7 +146,7 @@ static int ctl_backend_ramdisk_submit(union ctl_io *io
 static void ctl_backend_ramdisk_worker(void *context, int pending);
 static int ctl_backend_ramdisk_config_read(union ctl_io *io);
 static int ctl_backend_ramdisk_config_write(union ctl_io *io);
-static uint64_t ctl_backend_ramdisk_lun_attr(void *be_lun, const char *attrname);
+static uint64_t ctl_backend_ramdisk_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname);
 static int ctl_backend_ramdisk_ioctl(struct cdev *dev, u_long cmd,
 				     caddr_t addr, int flag, struct thread *td);
 static int ctl_backend_ramdisk_rm(struct ctl_be_ramdisk_softc *softc,
@@ -155,7 +155,7 @@ static int ctl_backend_ramdisk_create(struct ctl_be_ra
 				      struct ctl_lun_req *req);
 static int ctl_backend_ramdisk_modify(struct ctl_be_ramdisk_softc *softc,
 				  struct ctl_lun_req *req);
-static void ctl_backend_ramdisk_lun_shutdown(void *be_lun);
+static void ctl_backend_ramdisk_lun_shutdown(struct ctl_be_lun *cbe_lun);
 
 static struct ctl_backend_driver ctl_be_ramdisk_driver = 
 {
@@ -367,7 +367,7 @@ static int
 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 = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	uint8_t *page;
 	uint8_t info[8];
 	uint64_t lba;
@@ -404,8 +404,8 @@ ctl_backend_ramdisk_cmp(union ctl_io *io)
 static int
 ctl_backend_ramdisk_move_done(union ctl_io *io)
 {
-	struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
-	struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun =
+	    (struct ctl_be_ramdisk_lun *)CTL_BACKEND_LUN(io);
 #ifdef CTL_TIME_IO
 	struct bintime cur_bt;
 #endif
@@ -481,7 +481,7 @@ static void
 ctl_backend_ramdisk_rw(union ctl_io *io)
 {
 	struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
-	struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	struct ctl_sg_entry *sg_entries;
 	uint8_t *page;
 	uint64_t lba;
@@ -593,7 +593,7 @@ static int
 ctl_backend_ramdisk_gls(union ctl_io *io)
 {
 	struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
-	struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	struct scsi_get_lba_status_data *data;
 	uint8_t *page;
 	u_int lbaoff;
@@ -647,7 +647,7 @@ static void
 ctl_backend_ramdisk_delete(struct ctl_be_lun *cbe_lun, off_t lba, off_t len,
     int anchor)
 {
-	struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	uint8_t *page;
 	uint64_t p, lp;
 	u_int lbaoff;
@@ -689,7 +689,7 @@ static void
 ctl_backend_ramdisk_ws(union ctl_io *io)
 {
 	struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
-	struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	struct ctl_lba_len_flags *lbalen = ARGS(io);
 	uint8_t *page;
 	uint64_t lba;
@@ -823,9 +823,9 @@ ctl_backend_ramdisk_config_write(union ctl_io *io)
 }
 
 static uint64_t
-ctl_backend_ramdisk_lun_attr(void *arg, const char *attrname)
+ctl_backend_ramdisk_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname)
 {
-	struct ctl_be_ramdisk_lun *be_lun = arg;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	uint64_t		val;
 
 	val = UINT64_MAX;
@@ -971,7 +971,6 @@ ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc
 
 	be_lun = malloc(sizeof(*be_lun), M_RAMDISK, M_ZERO | M_WAITOK);
 	cbe_lun = &be_lun->cbe_lun;
-	cbe_lun->be_lun = be_lun;
 	cbe_lun->options = nvlist_clone(req->args_nvl);
 	be_lun->params = req->reqdata.create;
 	be_lun->softc = softc;
@@ -1246,9 +1245,9 @@ bailout_error:
 }
 
 static void
-ctl_backend_ramdisk_lun_shutdown(void *lun)
+ctl_backend_ramdisk_lun_shutdown(struct ctl_be_lun *cbe_lun)
 {
-	struct ctl_be_ramdisk_lun *be_lun = lun;
+	struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
 	struct ctl_be_ramdisk_softc *softc = be_lun->softc;
 
 	taskqueue_drain_all(be_lun->io_taskqueue);


More information about the svn-src-all mailing list