From owner-svn-src-stable-12@freebsd.org Tue Jun 2 20:40:12 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C63302F9A44; Tue, 2 Jun 2020 20:40:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49c3nm1Wnfz3V7G; Tue, 2 Jun 2020 20:40:11 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3712B22A86; Tue, 2 Jun 2020 20:40:11 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 052KeB2m050677; Tue, 2 Jun 2020 20:40:11 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 052KeAWG050673; Tue, 2 Jun 2020 20:40:10 GMT (envelope-from mav@FreeBSD.org) Message-Id: <202006022040.052KeAWG050673@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 2 Jun 2020 20:40:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361734 - stable/12/sys/cam/ctl X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/cam/ctl X-SVN-Commit-Revision: 361734 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jun 2020 20:40:12 -0000 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"); 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);