From owner-svn-src-all@FreeBSD.ORG Tue Jul 15 17:08:06 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1808AF3B; Tue, 15 Jul 2014 17:08:06 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 038C42CA7; Tue, 15 Jul 2014 17:08:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6FH85mx084347; Tue, 15 Jul 2014 17:08:05 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6FH84ZS084338; Tue, 15 Jul 2014 17:08:04 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201407151708.s6FH84ZS084338@svn.freebsd.org> From: Alexander Motin Date: Tue, 15 Jul 2014 17:08:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268685 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jul 2014 17:08:06 -0000 Author: mav Date: Tue Jul 15 17:08:04 2014 New Revision: 268685 URL: http://svnweb.freebsd.org/changeset/base/268685 Log: MFC r268307: Move lun_map() method from command nexus to port. Previous implementation made impossible to do some things, such as calling it for ports other then one through which command arrived. Modified: stable/10/sys/cam/ctl/ctl.c stable/10/sys/cam/ctl/ctl_frontend.h stable/10/sys/cam/ctl/ctl_frontend_iscsi.c stable/10/sys/cam/ctl/ctl_frontend_iscsi.h stable/10/sys/cam/ctl/ctl_io.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Tue Jul 15 17:07:07 2014 (r268684) +++ stable/10/sys/cam/ctl/ctl.c Tue Jul 15 17:08:04 2014 (r268685) @@ -348,6 +348,7 @@ static int ctl_ioctl(struct cdev *dev, u struct thread *td); uint32_t ctl_get_resindex(struct ctl_nexus *nexus); uint32_t ctl_port_idx(int port_num); +static uint32_t ctl_map_lun(int port_num, uint32_t lun); #ifdef unused static union ctl_io *ctl_malloc_io(ctl_io_type io_type, uint32_t targ_port, uint32_t targ_target, uint32_t targ_lun, @@ -3347,6 +3348,19 @@ ctl_port_idx(int port_num) return(port_num - CTL_MAX_PORTS); } +static uint32_t +ctl_map_lun(int port_num, uint32_t lun_id) +{ + struct ctl_port *port; + + port = control_softc->ctl_ports[ctl_port_idx(port_num)]; + if (port == NULL) + return (UINT32_MAX); + if (port->lun_map == NULL) + return (lun_id); + return (port->lun_map(port->targ_lun_arg, lun_id)); +} + /* * Note: This only works for bitmask sizes that are at least 32 bits, and * that are a power of 2. @@ -9258,9 +9272,7 @@ ctl_report_luns(struct ctl_scsiio *ctsio mtx_lock(&control_softc->ctl_lock); for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) { - lun_id = targ_lun_id; - if (ctsio->io_hdr.nexus.lun_map_fn != NULL) - lun_id = ctsio->io_hdr.nexus.lun_map_fn(ctsio->io_hdr.nexus.lun_map_arg, lun_id); + lun_id = ctl_map_lun(ctsio->io_hdr.nexus.targ_port, targ_lun_id); if (lun_id >= CTL_MAX_LUNS) continue; lun = control_softc->ctl_luns[lun_id]; @@ -13238,8 +13250,7 @@ ctl_queue_sense(union ctl_io *io) * information. */ targ_lun = io->io_hdr.nexus.targ_lun; - if (io->io_hdr.nexus.lun_map_fn != NULL) - targ_lun = io->io_hdr.nexus.lun_map_fn(io->io_hdr.nexus.lun_map_arg, targ_lun); + targ_lun = ctl_map_lun(io->io_hdr.nexus.targ_port, targ_lun); if ((targ_lun < CTL_MAX_LUNS) && (ctl_softc->ctl_luns[targ_lun] != NULL)) lun = ctl_softc->ctl_luns[targ_lun]; @@ -13290,11 +13301,8 @@ ctl_queue(union ctl_io *io) #endif /* CTL_TIME_IO */ /* Map FE-specific LUN ID into global one. */ - if (io->io_hdr.nexus.lun_map_fn != NULL) - io->io_hdr.nexus.targ_mapped_lun = io->io_hdr.nexus.lun_map_fn( - io->io_hdr.nexus.lun_map_arg, io->io_hdr.nexus.targ_lun); - else - io->io_hdr.nexus.targ_mapped_lun = io->io_hdr.nexus.targ_lun; + io->io_hdr.nexus.targ_mapped_lun = + ctl_map_lun(io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun); switch (io->io_hdr.io_type) { case CTL_IO_SCSI: Modified: stable/10/sys/cam/ctl/ctl_frontend.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_frontend.h Tue Jul 15 17:07:07 2014 (r268684) +++ stable/10/sys/cam/ctl/ctl_frontend.h Tue Jul 15 17:08:04 2014 (r268685) @@ -49,8 +49,8 @@ typedef enum { typedef int (*fe_init_t)(void); typedef void (*fe_shutdown_t)(void); typedef void (*port_func_t)(void *onoff_arg); -typedef int (*targ_func_t)(void *arg, struct ctl_id targ_id); typedef int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id); +typedef uint32_t (*lun_map_func_t)(void *arg, uint32_t lun_id); typedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td); @@ -217,6 +217,7 @@ struct ctl_port { void *onoff_arg; /* passed to CTL */ lun_func_t lun_enable; /* passed to CTL */ lun_func_t lun_disable; /* passed to CTL */ + lun_map_func_t lun_map; /* passed to CTL */ void *targ_lun_arg; /* passed to CTL */ void (*fe_datamove)(union ctl_io *io); /* passed to CTL */ void (*fe_done)(union ctl_io *io); /* passed to CTL */ Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Tue Jul 15 17:07:07 2014 (r268684) +++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Tue Jul 15 17:08:04 2014 (r268685) @@ -153,11 +153,11 @@ static int cfiscsi_lun_enable(void *arg, struct ctl_id target_id, int lun_id); static int cfiscsi_lun_disable(void *arg, struct ctl_id target_id, int lun_id); +static uint32_t cfiscsi_lun_map(void *arg, uint32_t lun); static int cfiscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td); static void cfiscsi_datamove(union ctl_io *io); static void cfiscsi_done(union ctl_io *io); -static uint32_t cfiscsi_map_lun(void *arg, uint32_t lun); static bool cfiscsi_pdu_update_cmdsn(const struct icl_pdu *request); static void cfiscsi_pdu_handle_nop_out(struct icl_pdu *request); static void cfiscsi_pdu_handle_scsi_command(struct icl_pdu *request); @@ -556,8 +556,6 @@ cfiscsi_pdu_handle_scsi_command(struct i io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; io->io_hdr.nexus.targ_target.id = 0; io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhssc->bhssc_lun); - io->io_hdr.nexus.lun_map_fn = cfiscsi_map_lun; - io->io_hdr.nexus.lun_map_arg = cs; io->scsiio.tag_num = bhssc->bhssc_initiator_task_tag; switch ((bhssc->bhssc_flags & BHSSC_FLAGS_ATTR)) { case BHSSC_FLAGS_ATTR_UNTAGGED: @@ -622,8 +620,6 @@ cfiscsi_pdu_handle_task_request(struct i io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; io->io_hdr.nexus.targ_target.id = 0; io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhstmr->bhstmr_lun); - io->io_hdr.nexus.lun_map_fn = cfiscsi_map_lun; - io->io_hdr.nexus.lun_map_arg = cs; io->taskio.tag_type = CTL_TAG_SIMPLE; /* XXX */ switch (bhstmr->bhstmr_function & ~0x80) { @@ -2004,6 +2000,7 @@ cfiscsi_ioctl_port_create(struct ctl_req port->onoff_arg = ct; port->lun_enable = cfiscsi_lun_enable; port->lun_disable = cfiscsi_lun_disable; + port->lun_map = cfiscsi_lun_map; port->targ_lun_arg = ct; port->fe_datamove = cfiscsi_datamove; port->fe_done = cfiscsi_done; @@ -2250,7 +2247,7 @@ cfiscsi_target_find_or_create(struct cfi } for (i = 0; i < CTL_MAX_LUNS; i++) - newct->ct_luns[i] = -1; + newct->ct_luns[i] = UINT32_MAX; strlcpy(newct->ct_name, name, sizeof(newct->ct_name)); if (alias != NULL) @@ -2267,22 +2264,16 @@ cfiscsi_target_find_or_create(struct cfi * Takes LUN from the target space and returns LUN from the CTL space. */ static uint32_t -cfiscsi_map_lun(void *arg, uint32_t lun) +cfiscsi_lun_map(void *arg, uint32_t lun) { - struct cfiscsi_session *cs; - - cs = arg; + struct cfiscsi_target *ct = arg; if (lun >= CTL_MAX_LUNS) { CFISCSI_DEBUG("requested lun number %d is higher " "than maximum %d", lun, CTL_MAX_LUNS - 1); - return (0xffffffff); + return (UINT32_MAX); } - - if (cs->cs_target->ct_luns[lun] < 0) - return (0xffffffff); - - return (cs->cs_target->ct_luns[lun]); + return (ct->ct_luns[lun]); } static int @@ -2296,7 +2287,7 @@ cfiscsi_target_set_lun(struct cfiscsi_ta return (-1); } - if (ct->ct_luns[lun_id] >= 0) { + if (ct->ct_luns[lun_id] < CTL_MAX_LUNS) { /* * CTL calls cfiscsi_lun_enable() twice for each LUN - once * when the LUN is created, and a second time just before @@ -2365,11 +2356,9 @@ cfiscsi_lun_disable(void *arg, struct ct mtx_lock(&softc->lock); for (i = 0; i < CTL_MAX_LUNS; i++) { - if (ct->ct_luns[i] < 0) - continue; if (ct->ct_luns[i] != lun_id) continue; - ct->ct_luns[lun_id] = -1; + ct->ct_luns[i] = UINT32_MAX; break; } mtx_unlock(&softc->lock); Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_frontend_iscsi.h Tue Jul 15 17:07:07 2014 (r268684) +++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.h Tue Jul 15 17:08:04 2014 (r268685) @@ -38,7 +38,7 @@ struct cfiscsi_target { TAILQ_ENTRY(cfiscsi_target) ct_next; - int ct_luns[CTL_MAX_LUNS]; + uint32_t ct_luns[CTL_MAX_LUNS]; struct cfiscsi_softc *ct_softc; volatile u_int ct_refcount; char ct_name[CTL_ISCSI_NAME_LEN]; Modified: stable/10/sys/cam/ctl/ctl_io.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_io.h Tue Jul 15 17:07:07 2014 (r268684) +++ stable/10/sys/cam/ctl/ctl_io.h Tue Jul 15 17:08:04 2014 (r268685) @@ -221,8 +221,6 @@ struct ctl_nexus { struct ctl_id targ_target; /* Destination target */ uint32_t targ_lun; /* Destination lun */ uint32_t targ_mapped_lun; /* Destination lun CTL-wide */ - uint32_t (*lun_map_fn)(void *arg, uint32_t lun); - void *lun_map_arg; }; typedef enum {