ctl.c (284797) | ctl.c (284798) |
---|---|
1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 28 unchanged lines hidden (view full) --- 37 * CAM Target Layer, a SCSI device emulation subsystem. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#define _CTL_C 43 44#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 28 unchanged lines hidden (view full) --- 37 * CAM Target Layer, a SCSI device emulation subsystem. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#define _CTL_C 43 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl.c 284797 2015-06-25 07:10:51Z mav $"); | 45__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl.c 284798 2015-06-25 07:11:48Z mav $"); |
46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/ctype.h> 50#include <sys/kernel.h> 51#include <sys/types.h> 52#include <sys/kthread.h> 53#include <sys/bio.h> --- 326 unchanged lines hidden (view full) --- 380 int param); 381static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest); 382static int ctl_init(void); 383void ctl_shutdown(void); 384static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td); 385static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td); 386static void ctl_ioctl_online(void *arg); 387static void ctl_ioctl_offline(void *arg); | 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/ctype.h> 50#include <sys/kernel.h> 51#include <sys/types.h> 52#include <sys/kthread.h> 53#include <sys/bio.h> --- 326 unchanged lines hidden (view full) --- 380 int param); 381static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest); 382static int ctl_init(void); 383void ctl_shutdown(void); 384static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td); 385static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td); 386static void ctl_ioctl_online(void *arg); 387static void ctl_ioctl_offline(void *arg); |
388static int ctl_ioctl_lun_enable(void *arg, struct ctl_id targ_id, int lun_id); 389static int ctl_ioctl_lun_disable(void *arg, struct ctl_id targ_id, int lun_id); | 388static int ctl_ioctl_lun_enable(void *arg, int lun_id); 389static int ctl_ioctl_lun_disable(void *arg, int lun_id); |
390static int ctl_ioctl_do_datamove(struct ctl_scsiio *ctsio); 391static int ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio); 392static int ctl_ioctl_submit_wait(union ctl_io *io); 393static void ctl_ioctl_datamove(union ctl_io *io); 394static void ctl_ioctl_done(union ctl_io *io); 395static void ctl_ioctl_hard_startstop_callback(void *arg, 396 struct cfi_metatask *metatask); 397static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask); 398static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, 399 struct ctl_ooa *ooa_hdr, 400 struct ctl_ooa_entry *kern_entries); 401static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 402 struct thread *td); 403static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun, | 390static int ctl_ioctl_do_datamove(struct ctl_scsiio *ctsio); 391static int ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio); 392static int ctl_ioctl_submit_wait(union ctl_io *io); 393static void ctl_ioctl_datamove(union ctl_io *io); 394static void ctl_ioctl_done(union ctl_io *io); 395static void ctl_ioctl_hard_startstop_callback(void *arg, 396 struct cfi_metatask *metatask); 397static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask); 398static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, 399 struct ctl_ooa *ooa_hdr, 400 struct ctl_ooa_entry *kern_entries); 401static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 402 struct thread *td); 403static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun, |
404 struct ctl_be_lun *be_lun, struct ctl_id target_id); | 404 struct ctl_be_lun *be_lun); |
405static int ctl_free_lun(struct ctl_lun *lun); 406static void ctl_create_lun(struct ctl_be_lun *be_lun); 407static struct ctl_port * ctl_io_port(struct ctl_io_hdr *io_hdr); 408/** 409static void ctl_failover_change_pages(struct ctl_softc *softc, 410 struct ctl_scsiio *ctsio, int master); 411**/ 412 --- 712 unchanged lines hidden (view full) --- 1125 if (softc->ha_id == 0) { 1126 softc->flags |= CTL_FLAG_ACTIVE_SHELF; 1127 softc->is_single = 1; 1128 softc->port_offset = 0; 1129 } else 1130 softc->port_offset = (softc->ha_id - 1) * CTL_MAX_PORTS; 1131 softc->persis_offset = softc->port_offset * CTL_MAX_INIT_PER_PORT; 1132 | 405static int ctl_free_lun(struct ctl_lun *lun); 406static void ctl_create_lun(struct ctl_be_lun *be_lun); 407static struct ctl_port * ctl_io_port(struct ctl_io_hdr *io_hdr); 408/** 409static void ctl_failover_change_pages(struct ctl_softc *softc, 410 struct ctl_scsiio *ctsio, int master); 411**/ 412 --- 712 unchanged lines hidden (view full) --- 1125 if (softc->ha_id == 0) { 1126 softc->flags |= CTL_FLAG_ACTIVE_SHELF; 1127 softc->is_single = 1; 1128 softc->port_offset = 0; 1129 } else 1130 softc->port_offset = (softc->ha_id - 1) * CTL_MAX_PORTS; 1131 softc->persis_offset = softc->port_offset * CTL_MAX_INIT_PER_PORT; 1132 |
1133 /* 1134 * XXX KDM need to figure out where we want to get our target ID 1135 * and WWID. Is it different on each port? 1136 */ 1137 softc->target.id = 0; 1138 softc->target.wwid[0] = 0x12345678; 1139 softc->target.wwid[1] = 0x87654321; | |
1140 STAILQ_INIT(&softc->lun_list); 1141 STAILQ_INIT(&softc->pending_lun_queue); 1142 STAILQ_INIT(&softc->fe_list); 1143 STAILQ_INIT(&softc->port_list); 1144 STAILQ_INIT(&softc->be_list); 1145 ctl_tpc_init(softc); 1146 1147 if (ctl_pool_create(softc, "othersc", CTL_POOL_ENTRIES_OTHER_SC, --- 496 unchanged lines hidden (view full) --- 1644 scsi_ulto2b(iid, id->scsi_addr); 1645 scsi_ulto2b(port->targ_port, id->rel_trgt_port_id); 1646 return (sizeof(*id)); 1647 } 1648 } 1649} 1650 1651static int | 1133 STAILQ_INIT(&softc->lun_list); 1134 STAILQ_INIT(&softc->pending_lun_queue); 1135 STAILQ_INIT(&softc->fe_list); 1136 STAILQ_INIT(&softc->port_list); 1137 STAILQ_INIT(&softc->be_list); 1138 ctl_tpc_init(softc); 1139 1140 if (ctl_pool_create(softc, "othersc", CTL_POOL_ENTRIES_OTHER_SC, --- 496 unchanged lines hidden (view full) --- 1637 scsi_ulto2b(iid, id->scsi_addr); 1638 scsi_ulto2b(port->targ_port, id->rel_trgt_port_id); 1639 return (sizeof(*id)); 1640 } 1641 } 1642} 1643 1644static int |
1652ctl_ioctl_lun_enable(void *arg, struct ctl_id targ_id, int lun_id) | 1645ctl_ioctl_lun_enable(void *arg, int lun_id) |
1653{ 1654 return (0); 1655} 1656 1657static int | 1646{ 1647 return (0); 1648} 1649 1650static int |
1658ctl_ioctl_lun_disable(void *arg, struct ctl_id targ_id, int lun_id) | 1651ctl_ioctl_lun_disable(void *arg, int lun_id) |
1659{ 1660 return (0); 1661} 1662 1663/* 1664 * Data movement routine for the CTL ioctl frontend port. 1665 */ 1666static int --- 808 unchanged lines hidden (view full) --- 2475 * because the online/offline operations 2476 * can potentially block. We need to 2477 * reference count the frontends so they 2478 * can't go away, 2479 */ 2480 mtx_unlock(&softc->ctl_lock); 2481 2482 if (cmd == CTL_ENABLE_PORT) { | 1652{ 1653 return (0); 1654} 1655 1656/* 1657 * Data movement routine for the CTL ioctl frontend port. 1658 */ 1659static int --- 808 unchanged lines hidden (view full) --- 2468 * because the online/offline operations 2469 * can potentially block. We need to 2470 * reference count the frontends so they 2471 * can't go away, 2472 */ 2473 mtx_unlock(&softc->ctl_lock); 2474 2475 if (cmd == CTL_ENABLE_PORT) { |
2483 struct ctl_lun *lun; 2484 2485 STAILQ_FOREACH(lun, &softc->lun_list, 2486 links) { 2487 port->lun_enable(port->targ_lun_arg, 2488 lun->target, 2489 lun->lun); 2490 } 2491 | |
2492 ctl_port_online(port); 2493 } else if (cmd == CTL_DISABLE_PORT) { | 2476 ctl_port_online(port); 2477 } else if (cmd == CTL_DISABLE_PORT) { |
2494 struct ctl_lun *lun; 2495 | |
2496 ctl_port_offline(port); | 2478 ctl_port_offline(port); |
2497 2498 STAILQ_FOREACH(lun, &softc->lun_list, 2499 links) { 2500 port->lun_disable( 2501 port->targ_lun_arg, 2502 lun->target, 2503 lun->lun); 2504 } | |
2505 } 2506 2507 mtx_lock(&softc->ctl_lock); 2508 2509 if (cmd == CTL_SET_PORT_WWNS) 2510 ctl_port_set_wwns(port, 2511 (entry->flags & CTL_PORT_WWNN_VALID) ? 2512 1 : 0, entry->wwnn, --- 1044 unchanged lines hidden (view full) --- 3557 struct ctl_port *port; 3558 3559 mtx_lock(&softc->ctl_lock); 3560 if (lm->port >= CTL_MAX_PORTS || 3561 (port = softc->ctl_ports[lm->port]) == NULL) { 3562 mtx_unlock(&softc->ctl_lock); 3563 return (ENXIO); 3564 } | 2479 } 2480 2481 mtx_lock(&softc->ctl_lock); 2482 2483 if (cmd == CTL_SET_PORT_WWNS) 2484 ctl_port_set_wwns(port, 2485 (entry->flags & CTL_PORT_WWNN_VALID) ? 2486 1 : 0, entry->wwnn, --- 1044 unchanged lines hidden (view full) --- 3531 struct ctl_port *port; 3532 3533 mtx_lock(&softc->ctl_lock); 3534 if (lm->port >= CTL_MAX_PORTS || 3535 (port = softc->ctl_ports[lm->port]) == NULL) { 3536 mtx_unlock(&softc->ctl_lock); 3537 return (ENXIO); 3538 } |
3539 mtx_unlock(&softc->ctl_lock); // XXX: port_enable sleeps |
|
3565 if (lm->plun < CTL_MAX_LUNS) { 3566 if (lm->lun == UINT32_MAX) 3567 retval = ctl_lun_map_unset(port, lm->plun); 3568 else if (lm->lun < CTL_MAX_LUNS && 3569 softc->ctl_luns[lm->lun] != NULL) 3570 retval = ctl_lun_map_set(port, lm->plun, lm->lun); | 3540 if (lm->plun < CTL_MAX_LUNS) { 3541 if (lm->lun == UINT32_MAX) 3542 retval = ctl_lun_map_unset(port, lm->plun); 3543 else if (lm->lun < CTL_MAX_LUNS && 3544 softc->ctl_luns[lm->lun] != NULL) 3545 retval = ctl_lun_map_set(port, lm->plun, lm->lun); |
3571 else { 3572 mtx_unlock(&softc->ctl_lock); | 3546 else |
3573 return (ENXIO); | 3547 return (ENXIO); |
3574 } | |
3575 } else if (lm->plun == UINT32_MAX) { 3576 if (lm->lun == UINT32_MAX) 3577 retval = ctl_lun_map_deinit(port); 3578 else 3579 retval = ctl_lun_map_init(port); | 3548 } else if (lm->plun == UINT32_MAX) { 3549 if (lm->lun == UINT32_MAX) 3550 retval = ctl_lun_map_deinit(port); 3551 else 3552 retval = ctl_lun_map_init(port); |
3580 } else { 3581 mtx_unlock(&softc->ctl_lock); | 3553 } else |
3582 return (ENXIO); | 3554 return (ENXIO); |
3583 } 3584 mtx_unlock(&softc->ctl_lock); | |
3585 break; 3586 } 3587 default: { 3588 /* XXX KDM should we fix this? */ 3589#if 0 3590 struct ctl_backend_driver *backend; 3591 unsigned int type; 3592 int found; --- 53 unchanged lines hidden (view full) --- 3646 return(port_num); 3647 else 3648 return(port_num - CTL_MAX_PORTS); 3649} 3650 3651int 3652ctl_lun_map_init(struct ctl_port *port) 3653{ | 3555 break; 3556 } 3557 default: { 3558 /* XXX KDM should we fix this? */ 3559#if 0 3560 struct ctl_backend_driver *backend; 3561 unsigned int type; 3562 int found; --- 53 unchanged lines hidden (view full) --- 3616 return(port_num); 3617 else 3618 return(port_num - CTL_MAX_PORTS); 3619} 3620 3621int 3622ctl_lun_map_init(struct ctl_port *port) 3623{ |
3624 struct ctl_softc *softc = control_softc; 3625 struct ctl_lun *lun; |
|
3654 uint32_t i; 3655 3656 if (port->lun_map == NULL) 3657 port->lun_map = malloc(sizeof(uint32_t) * CTL_MAX_LUNS, 3658 M_CTL, M_NOWAIT); 3659 if (port->lun_map == NULL) 3660 return (ENOMEM); 3661 for (i = 0; i < CTL_MAX_LUNS; i++) 3662 port->lun_map[i] = UINT32_MAX; | 3626 uint32_t i; 3627 3628 if (port->lun_map == NULL) 3629 port->lun_map = malloc(sizeof(uint32_t) * CTL_MAX_LUNS, 3630 M_CTL, M_NOWAIT); 3631 if (port->lun_map == NULL) 3632 return (ENOMEM); 3633 for (i = 0; i < CTL_MAX_LUNS; i++) 3634 port->lun_map[i] = UINT32_MAX; |
3635 if (port->status & CTL_PORT_STATUS_ONLINE) { 3636 STAILQ_FOREACH(lun, &softc->lun_list, links) 3637 port->lun_disable(port->targ_lun_arg, lun->lun); 3638 } |
|
3663 return (0); 3664} 3665 3666int 3667ctl_lun_map_deinit(struct ctl_port *port) 3668{ | 3639 return (0); 3640} 3641 3642int 3643ctl_lun_map_deinit(struct ctl_port *port) 3644{ |
3645 struct ctl_softc *softc = control_softc; 3646 struct ctl_lun *lun; |
|
3669 3670 if (port->lun_map == NULL) 3671 return (0); 3672 free(port->lun_map, M_CTL); 3673 port->lun_map = NULL; | 3647 3648 if (port->lun_map == NULL) 3649 return (0); 3650 free(port->lun_map, M_CTL); 3651 port->lun_map = NULL; |
3652 if (port->status & CTL_PORT_STATUS_ONLINE) { 3653 STAILQ_FOREACH(lun, &softc->lun_list, links) 3654 port->lun_enable(port->targ_lun_arg, lun->lun); 3655 } |
|
3674 return (0); 3675} 3676 3677int 3678ctl_lun_map_set(struct ctl_port *port, uint32_t plun, uint32_t glun) 3679{ 3680 int status; | 3656 return (0); 3657} 3658 3659int 3660ctl_lun_map_set(struct ctl_port *port, uint32_t plun, uint32_t glun) 3661{ 3662 int status; |
3663 uint32_t old; |
|
3681 3682 if (port->lun_map == NULL) { 3683 status = ctl_lun_map_init(port); 3684 if (status != 0) 3685 return (status); 3686 } | 3664 3665 if (port->lun_map == NULL) { 3666 status = ctl_lun_map_init(port); 3667 if (status != 0) 3668 return (status); 3669 } |
3670 old = port->lun_map[plun]; |
|
3687 port->lun_map[plun] = glun; | 3671 port->lun_map[plun] = glun; |
3672 if ((port->status & CTL_PORT_STATUS_ONLINE) && old >= CTL_MAX_LUNS) 3673 port->lun_enable(port->targ_lun_arg, plun); |
|
3688 return (0); 3689} 3690 3691int 3692ctl_lun_map_unset(struct ctl_port *port, uint32_t plun) 3693{ | 3674 return (0); 3675} 3676 3677int 3678ctl_lun_map_unset(struct ctl_port *port, uint32_t plun) 3679{ |
3680 uint32_t old; |
|
3694 3695 if (port->lun_map == NULL) 3696 return (0); | 3681 3682 if (port->lun_map == NULL) 3683 return (0); |
3684 old = port->lun_map[plun]; |
|
3697 port->lun_map[plun] = UINT32_MAX; | 3685 port->lun_map[plun] = UINT32_MAX; |
3686 if ((port->status & CTL_PORT_STATUS_ONLINE) && old < CTL_MAX_LUNS) 3687 port->lun_disable(port->targ_lun_arg, plun); |
|
3698 return (0); 3699} 3700 | 3688 return (0); 3689} 3690 |
3701int 3702ctl_lun_map_unsetg(struct ctl_port *port, uint32_t glun) 3703{ 3704 int i; 3705 3706 if (port->lun_map == NULL) 3707 return (0); 3708 for (i = 0; i < CTL_MAX_LUNS; i++) { 3709 if (port->lun_map[i] == glun) 3710 port->lun_map[i] = UINT32_MAX; 3711 } 3712 return (0); 3713} 3714 | |
3715uint32_t 3716ctl_lun_map_from_port(struct ctl_port *port, uint32_t lun_id) 3717{ 3718 3719 if (port == NULL) 3720 return (UINT32_MAX); 3721 if (port->lun_map == NULL || lun_id >= CTL_MAX_LUNS) 3722 return (lun_id); --- 806 unchanged lines hidden (view full) --- 4529 * wants us to allocate the LUN and he can block. 4530 * - ctl_softc is always set 4531 * - be_lun is set if the LUN has a backend (needed for disk LUNs) 4532 * 4533 * Returns 0 for success, non-zero (errno) for failure. 4534 */ 4535static int 4536ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun, | 3691uint32_t 3692ctl_lun_map_from_port(struct ctl_port *port, uint32_t lun_id) 3693{ 3694 3695 if (port == NULL) 3696 return (UINT32_MAX); 3697 if (port->lun_map == NULL || lun_id >= CTL_MAX_LUNS) 3698 return (lun_id); --- 806 unchanged lines hidden (view full) --- 4505 * wants us to allocate the LUN and he can block. 4506 * - ctl_softc is always set 4507 * - be_lun is set if the LUN has a backend (needed for disk LUNs) 4508 * 4509 * Returns 0 for success, non-zero (errno) for failure. 4510 */ 4511static int 4512ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun, |
4537 struct ctl_be_lun *const be_lun, struct ctl_id target_id) | 4513 struct ctl_be_lun *const be_lun) |
4538{ 4539 struct ctl_lun *nlun, *lun; 4540 struct scsi_vpd_id_descriptor *desc; 4541 struct scsi_vpd_id_t10 *t10id; 4542 const char *eui, *naa, *scsiname, *vendor, *value; 4543 int lun_number, i, lun_malloced; 4544 int devidlen, idlen1, idlen2 = 0, len; 4545 --- 120 unchanged lines hidden (view full) --- 4666 CTL_LUN_CONFIG_FAILURE); 4667 return (ENOSPC); 4668 } 4669 lun_number = be_lun->req_lun_id; 4670 } else { 4671 lun_number = ctl_ffz(ctl_softc->ctl_lun_mask, CTL_MAX_LUNS); 4672 if (lun_number == -1) { 4673 mtx_unlock(&ctl_softc->ctl_lock); | 4514{ 4515 struct ctl_lun *nlun, *lun; 4516 struct scsi_vpd_id_descriptor *desc; 4517 struct scsi_vpd_id_t10 *t10id; 4518 const char *eui, *naa, *scsiname, *vendor, *value; 4519 int lun_number, i, lun_malloced; 4520 int devidlen, idlen1, idlen2 = 0, len; 4521 --- 120 unchanged lines hidden (view full) --- 4642 CTL_LUN_CONFIG_FAILURE); 4643 return (ENOSPC); 4644 } 4645 lun_number = be_lun->req_lun_id; 4646 } else { 4647 lun_number = ctl_ffz(ctl_softc->ctl_lun_mask, CTL_MAX_LUNS); 4648 if (lun_number == -1) { 4649 mtx_unlock(&ctl_softc->ctl_lock); |
4674 printf("ctl: can't allocate LUN on target %ju, out of " 4675 "LUNs\n", (uintmax_t)target_id.id); | 4650 printf("ctl: can't allocate LUN, out of LUNs\n"); |
4676 if (lun->flags & CTL_LUN_MALLOCED) 4677 free(lun, M_CTL); 4678 be_lun->lun_config_status(be_lun->be_lun, 4679 CTL_LUN_CONFIG_FAILURE); 4680 return (ENOSPC); 4681 } 4682 } 4683 ctl_set_mask(ctl_softc->ctl_lun_mask, lun_number); 4684 4685 mtx_init(&lun->lun_lock, "CTL LUN", NULL, MTX_DEF); | 4651 if (lun->flags & CTL_LUN_MALLOCED) 4652 free(lun, M_CTL); 4653 be_lun->lun_config_status(be_lun->be_lun, 4654 CTL_LUN_CONFIG_FAILURE); 4655 return (ENOSPC); 4656 } 4657 } 4658 ctl_set_mask(ctl_softc->ctl_lun_mask, lun_number); 4659 4660 mtx_init(&lun->lun_lock, "CTL LUN", NULL, MTX_DEF); |
4686 lun->target = target_id; | |
4687 lun->lun = lun_number; 4688 lun->be_lun = be_lun; 4689 /* 4690 * The processor LUN is always enabled. Disk LUNs come on line 4691 * disabled, and must be enabled by the backend. 4692 */ 4693 lun->flags |= CTL_LUN_DISABLED; 4694 lun->backend = be_lun->be; --- 79 unchanged lines hidden (view full) --- 4774 * Assumptions: 4775 * - LUN has already been marked invalid and any pending I/O has been taken 4776 * care of. 4777 */ 4778static int 4779ctl_free_lun(struct ctl_lun *lun) 4780{ 4781 struct ctl_softc *softc; | 4661 lun->lun = lun_number; 4662 lun->be_lun = be_lun; 4663 /* 4664 * The processor LUN is always enabled. Disk LUNs come on line 4665 * disabled, and must be enabled by the backend. 4666 */ 4667 lun->flags |= CTL_LUN_DISABLED; 4668 lun->backend = be_lun->be; --- 79 unchanged lines hidden (view full) --- 4748 * Assumptions: 4749 * - LUN has already been marked invalid and any pending I/O has been taken 4750 * care of. 4751 */ 4752static int 4753ctl_free_lun(struct ctl_lun *lun) 4754{ 4755 struct ctl_softc *softc; |
4782 struct ctl_port *port; | |
4783 struct ctl_lun *nlun; 4784 int i; 4785 4786 softc = lun->ctl_softc; 4787 4788 mtx_assert(&softc->ctl_lock, MA_OWNED); 4789 | 4756 struct ctl_lun *nlun; 4757 int i; 4758 4759 softc = lun->ctl_softc; 4760 4761 mtx_assert(&softc->ctl_lock, MA_OWNED); 4762 |
4790 STAILQ_FOREACH(port, &softc->port_list, links) 4791 ctl_lun_map_unsetg(port, lun->lun); 4792 | |
4793 STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links); 4794 4795 ctl_clear_mask(softc->ctl_lun_mask, lun->lun); 4796 4797 softc->ctl_luns[lun->lun] = NULL; 4798 4799 if (!TAILQ_EMPTY(&lun->ooa_queue)) 4800 panic("Freeing a LUN %p with outstanding I/O!!\n", lun); --- 31 unchanged lines hidden (view full) --- 4832{ 4833 struct ctl_softc *softc; 4834 4835 softc = control_softc; 4836 4837 /* 4838 * ctl_alloc_lun() should handle all potential failure cases. 4839 */ | 4763 STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links); 4764 4765 ctl_clear_mask(softc->ctl_lun_mask, lun->lun); 4766 4767 softc->ctl_luns[lun->lun] = NULL; 4768 4769 if (!TAILQ_EMPTY(&lun->ooa_queue)) 4770 panic("Freeing a LUN %p with outstanding I/O!!\n", lun); --- 31 unchanged lines hidden (view full) --- 4802{ 4803 struct ctl_softc *softc; 4804 4805 softc = control_softc; 4806 4807 /* 4808 * ctl_alloc_lun() should handle all potential failure cases. 4809 */ |
4840 ctl_alloc_lun(softc, NULL, be_lun, softc->target); | 4810 ctl_alloc_lun(softc, NULL, be_lun); |
4841} 4842 4843int 4844ctl_add_lun(struct ctl_be_lun *be_lun) 4845{ 4846 struct ctl_softc *softc = control_softc; 4847 4848 mtx_lock(&softc->ctl_lock); --- 26 unchanged lines hidden (view full) --- 4875 mtx_unlock(&softc->ctl_lock); 4876 return (0); 4877 } 4878 lun->flags &= ~CTL_LUN_DISABLED; 4879 mtx_unlock(&lun->lun_lock); 4880 4881 for (port = STAILQ_FIRST(&softc->port_list); port != NULL; port = nport) { 4882 nport = STAILQ_NEXT(port, links); | 4811} 4812 4813int 4814ctl_add_lun(struct ctl_be_lun *be_lun) 4815{ 4816 struct ctl_softc *softc = control_softc; 4817 4818 mtx_lock(&softc->ctl_lock); --- 26 unchanged lines hidden (view full) --- 4845 mtx_unlock(&softc->ctl_lock); 4846 return (0); 4847 } 4848 lun->flags &= ~CTL_LUN_DISABLED; 4849 mtx_unlock(&lun->lun_lock); 4850 4851 for (port = STAILQ_FIRST(&softc->port_list); port != NULL; port = nport) { 4852 nport = STAILQ_NEXT(port, links); |
4853 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0 || 4854 port->lun_map != NULL) 4855 continue; |
|
4883 4884 /* 4885 * Drop the lock while we call the FETD's enable routine. 4886 * This can lead to a callback into CTL (at least in the 4887 * case of the internal initiator frontend. 4888 */ 4889 mtx_unlock(&softc->ctl_lock); | 4856 4857 /* 4858 * Drop the lock while we call the FETD's enable routine. 4859 * This can lead to a callback into CTL (at least in the 4860 * case of the internal initiator frontend. 4861 */ 4862 mtx_unlock(&softc->ctl_lock); |
4890 retval = port->lun_enable(port->targ_lun_arg, lun->target,lun->lun); | 4863 retval = port->lun_enable(port->targ_lun_arg, lun->lun); |
4891 mtx_lock(&softc->ctl_lock); 4892 if (retval != 0) { 4893 printf("%s: FETD %s port %d returned error " | 4864 mtx_lock(&softc->ctl_lock); 4865 if (retval != 0) { 4866 printf("%s: FETD %s port %d returned error " |
4894 "%d for lun_enable on target %ju lun %jd\n", 4895 __func__, port->port_name, port->targ_port, retval, 4896 (uintmax_t)lun->target.id, (intmax_t)lun->lun); | 4867 "%d for lun_enable on lun %jd\n", 4868 __func__, port->port_name, port->targ_port, 4869 retval, (intmax_t)lun->lun); |
4897 } 4898 } 4899 4900 mtx_unlock(&softc->ctl_lock); 4901 4902 return (0); 4903} 4904 --- 14 unchanged lines hidden (view full) --- 4919 mtx_unlock(&lun->lun_lock); 4920 mtx_unlock(&softc->ctl_lock); 4921 return (0); 4922 } 4923 lun->flags |= CTL_LUN_DISABLED; 4924 mtx_unlock(&lun->lun_lock); 4925 4926 STAILQ_FOREACH(port, &softc->port_list, links) { | 4870 } 4871 } 4872 4873 mtx_unlock(&softc->ctl_lock); 4874 4875 return (0); 4876} 4877 --- 14 unchanged lines hidden (view full) --- 4892 mtx_unlock(&lun->lun_lock); 4893 mtx_unlock(&softc->ctl_lock); 4894 return (0); 4895 } 4896 lun->flags |= CTL_LUN_DISABLED; 4897 mtx_unlock(&lun->lun_lock); 4898 4899 STAILQ_FOREACH(port, &softc->port_list, links) { |
4900 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0 || 4901 port->lun_map != NULL) 4902 continue; |
|
4927 mtx_unlock(&softc->ctl_lock); 4928 /* 4929 * Drop the lock before we call the frontend's disable 4930 * routine, to avoid lock order reversals. 4931 * 4932 * XXX KDM what happens if the frontend list changes while 4933 * we're traversing it? It's unlikely, but should be handled. 4934 */ | 4903 mtx_unlock(&softc->ctl_lock); 4904 /* 4905 * Drop the lock before we call the frontend's disable 4906 * routine, to avoid lock order reversals. 4907 * 4908 * XXX KDM what happens if the frontend list changes while 4909 * we're traversing it? It's unlikely, but should be handled. 4910 */ |
4935 retval = port->lun_disable(port->targ_lun_arg, lun->target, 4936 lun->lun); | 4911 retval = port->lun_disable(port->targ_lun_arg, lun->lun); |
4937 mtx_lock(&softc->ctl_lock); 4938 if (retval != 0) { 4939 printf("%s: FETD %s port %d returned error " | 4912 mtx_lock(&softc->ctl_lock); 4913 if (retval != 0) { 4914 printf("%s: FETD %s port %d returned error " |
4940 "%d for lun_disable on target %ju lun %jd\n", 4941 __func__, port->port_name, port->targ_port, retval, 4942 (uintmax_t)lun->target.id, (intmax_t)lun->lun); | 4915 "%d for lun_disable on lun %jd\n", 4916 __func__, port->port_name, port->targ_port, 4917 retval, (intmax_t)lun->lun); |
4943 } 4944 } 4945 4946 mtx_unlock(&softc->ctl_lock); 4947 4948 return (0); 4949} 4950 --- 9439 unchanged lines hidden --- | 4918 } 4919 } 4920 4921 mtx_unlock(&softc->ctl_lock); 4922 4923 return (0); 4924} 4925 --- 9439 unchanged lines hidden --- |