1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

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.
This commit is contained in:
Alexander Motin 2014-07-06 06:21:34 +00:00
parent 561764b1c5
commit c26eee2dc9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=268307
5 changed files with 30 additions and 34 deletions

View File

@ -346,6 +346,7 @@ static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
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,
@ -3345,6 +3346,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.
@ -9256,9 +9270,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];
@ -13240,8 +13252,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];
@ -13292,11 +13303,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:

View File

@ -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 */

View File

@ -149,11 +149,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);
@ -552,8 +552,6 @@ cfiscsi_pdu_handle_scsi_command(struct icl_pdu *request)
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:
@ -618,8 +616,6 @@ cfiscsi_pdu_handle_task_request(struct icl_pdu *request)
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) {
@ -2000,6 +1996,7 @@ cfiscsi_ioctl_port_create(struct ctl_req *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;
@ -2246,7 +2243,7 @@ cfiscsi_target_find_or_create(struct cfiscsi_softc *softc, const char *name,
}
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)
@ -2263,22 +2260,16 @@ cfiscsi_target_find_or_create(struct cfiscsi_softc *softc, const char *name,
* 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
@ -2292,7 +2283,7 @@ cfiscsi_target_set_lun(struct cfiscsi_target *ct,
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
@ -2361,11 +2352,9 @@ cfiscsi_lun_disable(void *arg, struct ctl_id target_id, int lun_id)
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);

View File

@ -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];

View File

@ -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 {