Print this page
9702 HBA drivers don't need the redundant devfs_clean step
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_lun.c
          +++ new/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_lun.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
       21 +
  21   22  /*
  22   23   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   24   * Use is subject to license terms.
  24   25   *
       26 + */
       27 +
       28 +/*
       29 + * Copyright 2018 Nexenta Systems, Inc.
       30 + */
       31 +
       32 +/*
  25   33   * iSCSI logical unit interfaces
  26   34   */
  27   35  
  28   36  #include "iscsi.h"
  29      -#include <sys/fs/dv_node.h>     /* devfs_clean */
  30   37  #include <sys/bootprops.h>
  31   38  #include <sys/sysevent/eventdefs.h>
  32   39  #include <sys/sysevent/dev.h>
  33   40  
  34   41  /* tpgt bytes in string form */
  35   42  #define TPGT_EXT_SIZE   5
  36   43  
  37   44  /* logical unit number bytes in string form */
  38   45  #define LUN_EXT_SIZE    10
  39   46  
↓ open down ↓ 594 lines elided ↑ open up ↑
 634  641   * If we fail to offline a LUN that we don't want to destroy,
 635  642   * we will mark it with invalid state. If this LUN still
 636  643   * exists on the target, we can have another chance to online
 637  644   * it again when we do the LUN enumeration.
 638  645   */
 639  646  iscsi_status_t
 640  647  iscsi_lun_offline(iscsi_hba_t *ihp, iscsi_lun_t *ilp, boolean_t lun_free)
 641  648  {
 642  649          iscsi_status_t          status          = ISCSI_STATUS_SUCCESS;
 643  650          int                     circ            = 0;
 644      -        dev_info_t              *cdip, *pdip;
 645      -        char                    *devname        = NULL;
      651 +        dev_info_t              *cdip;
 646  652          char                    *pathname       = NULL;
 647      -        int                     rval;
 648  653          boolean_t               offline         = B_FALSE;
 649  654          nvlist_t                *attr_list      = NULL;
 650  655  
 651  656          ASSERT(ilp != NULL);
 652  657          ASSERT((ilp->lun_pip != NULL) || (ilp->lun_dip != NULL));
 653  658  
 654      -        /*
 655      -         * Since we carry the logical units parent
 656      -         * lock across the offline call it will not
 657      -         * issue devfs_clean() and may fail with a
 658      -         * devi_ref count > 0.
 659      -         */
 660      -        if (ilp->lun_pip == NULL) {
      659 +        if (ilp->lun_pip == NULL)
 661  660                  cdip = ilp->lun_dip;
 662      -        } else {
      661 +        else
 663  662                  cdip = mdi_pi_get_client(ilp->lun_pip);
 664      -        }
 665  663  
 666      -        if ((cdip != NULL) &&
 667      -            (lun_free == B_TRUE) &&
 668      -            (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
 669      -                /*
 670      -                 * Make sure node is attached otherwise
 671      -                 * it won't have related cache nodes to
 672      -                 * clean up.  i_ddi_devi_attached is
 673      -                 * similiar to i_ddi_node_state(cdip) >=
 674      -                 * DS_ATTACHED. We should clean up only
 675      -                 * when lun_free is set.
 676      -                 */
 677      -                if (i_ddi_devi_attached(cdip)) {
 678      -
 679      -                        /* Get parent dip */
 680      -                        pdip = ddi_get_parent(cdip);
 681      -
 682      -                        /* Get full devname */
 683      -                        devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
 684      -                        ndi_devi_enter(pdip, &circ);
 685      -                        (void) ddi_deviname(cdip, devname);
 686      -                        /* Release lock before devfs_clean() */
 687      -                        ndi_devi_exit(pdip, circ);
 688      -
 689      -                        /* Clean cache */
 690      -                        (void) devfs_clean(pdip, devname + 1, DV_CLEAN_FORCE);
 691      -                        kmem_free(devname, MAXNAMELEN + 1);
 692      -                }
 693      -        }
 694      -
 695  664          if (cdip != NULL && ilp->lun_type == DTYPE_DIRECT) {
 696  665                  pathname = kmem_zalloc(MAXNAMELEN + 1, KM_SLEEP);
 697  666                  (void) ddi_pathname(cdip, pathname);
 698  667          }
 699  668  
 700  669          /* Attempt to offline the logical units */
 701  670          if (ilp->lun_pip != NULL) {
 702      -
 703  671                  /* virt/mdi */
 704  672                  ndi_devi_enter(scsi_vhci_dip, &circ);
 705      -                if ((lun_free == B_TRUE) &&
 706      -                    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
 707      -                        rval = mdi_pi_offline(ilp->lun_pip,
 708      -                            NDI_DEVI_REMOVE);
 709      -                } else {
 710      -                        rval = mdi_pi_offline(ilp->lun_pip, 0);
 711      -                }
 712      -
 713      -                if (rval == MDI_SUCCESS) {
      673 +                if (mdi_pi_offline(ilp->lun_pip, 0) == MDI_SUCCESS) {
 714  674                          ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
 715  675                          ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
 716  676                          if (lun_free == B_TRUE) {
 717  677                                  (void) mdi_prop_remove(ilp->lun_pip, NULL);
 718  678                                  (void) mdi_pi_free(ilp->lun_pip, 0);
 719  679                          }
 720  680                          offline = B_TRUE;
 721  681                  } else {
 722  682                          status = ISCSI_STATUS_BUSY;
 723  683                          if (lun_free == B_FALSE) {
 724  684                                  ilp->lun_state |= ISCSI_LUN_STATE_INVALID;
 725  685                                  offline = B_TRUE;
 726  686                          }
 727  687                  }
 728  688                  ndi_devi_exit(scsi_vhci_dip, circ);
 729  689  
 730  690          } else  {
 731      -
 732  691                  /* phys/ndi */
      692 +                int flags = NDI_DEVFS_CLEAN;
      693 +
 733  694                  ndi_devi_enter(ihp->hba_dip, &circ);
 734      -                if ((lun_free == B_TRUE) &&
 735      -                    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
 736      -                        rval = ndi_devi_offline(
 737      -                            ilp->lun_dip, NDI_DEVI_REMOVE);
 738      -                } else {
 739      -                        rval = ndi_devi_offline(
 740      -                            ilp->lun_dip, 0);
 741      -                }
 742      -                if (rval != NDI_SUCCESS) {
      695 +                if (lun_free == B_TRUE &&
      696 +                    (ilp->lun_state & ISCSI_LUN_STATE_ONLINE))
      697 +                        flags |= NDI_DEVI_REMOVE;
      698 +                if (ndi_devi_offline(ilp->lun_dip, flags) != NDI_SUCCESS) {
 743  699                          status = ISCSI_STATUS_BUSY;
 744  700                          if (lun_free == B_FALSE) {
 745  701                                  ilp->lun_state |= ISCSI_LUN_STATE_INVALID;
 746  702                                  offline = B_TRUE;
 747  703                          }
 748  704                  } else {
 749  705                          ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
 750  706                          ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
 751  707                          offline = B_TRUE;
 752  708                  }
↓ open down ↓ 28 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX