Print this page
NEX-18203 fcp should call mdi_pi_offline() without NDI_DEVI_REMOVE
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-17944 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>
NEX-3153 fcp unable to offline paths to drives behind ATTO Fibrebridge 6500
Reviewed by: Steve Peng <steve.peng@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/fibre-channel/ulp/fcp.c
          +++ new/usr/src/uts/common/io/fibre-channel/ulp/fcp.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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - *
       24 + */
       25 +
       26 +/*
       27 + * Copyright 2018 Nexenta Systems, Inc.
       28 + */
       29 +
       30 +/*
  24   31   * Fibre Channel SCSI ULP Mapping driver
  25   32   */
  26   33  
  27   34  #include <sys/scsi/scsi.h>
  28   35  #include <sys/types.h>
  29   36  #include <sys/varargs.h>
  30   37  #include <sys/devctl.h>
  31   38  #include <sys/thread.h>
  32   39  #include <sys/thread.h>
  33   40  #include <sys/open.h>
  34   41  #include <sys/file.h>
  35   42  #include <sys/sunndi.h>
  36   43  #include <sys/console.h>
  37   44  #include <sys/proc.h>
  38   45  #include <sys/time.h>
  39   46  #include <sys/utsname.h>
  40   47  #include <sys/scsi/impl/scsi_reset_notify.h>
  41   48  #include <sys/ndi_impldefs.h>
  42   49  #include <sys/byteorder.h>
  43      -#include <sys/fs/dv_node.h>
  44   50  #include <sys/ctype.h>
  45   51  #include <sys/sunmdi.h>
  46   52  
  47   53  #include <sys/fibre-channel/fc.h>
  48   54  #include <sys/fibre-channel/impl/fc_ulpif.h>
  49   55  #include <sys/fibre-channel/ulp/fcpvar.h>
  50   56  
  51   57  /*
  52   58   * Discovery Process
  53   59   * =================
↓ open down ↓ 3805 lines elided ↑ open up ↑
3859 3865                  head = fcp_scan_commands(plun);
3860 3866                  if (head != NULL) {
3861 3867                          fcp_abort_commands(head, LUN_PORT);
3862 3868                  }
3863 3869                  lcount = pptr->port_link_cnt;
3864 3870                  tcount = plun->lun_tgt->tgt_change_cnt;
3865 3871                  mutex_exit(&pptr->port_mutex);
3866 3872  
3867 3873                  if (cmd == DEVCTL_DEVICE_REMOVE) {
3868 3874                          flag = NDI_DEVI_REMOVE;
     3875 +                        if (is_mpxio)
     3876 +                                flag |= NDI_USER_REQ;
3869 3877                  }
3870 3878  
3871 3879                  if (is_mpxio) {
3872 3880                          mdi_devi_exit(pptr->port_dip, circ);
3873 3881                  } else {
3874 3882                          ndi_devi_exit(pptr->port_dip, circ);
3875 3883                  }
3876 3884                  devi_entered = 0;
3877 3885  
3878 3886                  *rval = fcp_pass_to_hp_and_wait(pptr, plun, cip,
↓ open down ↓ 4265 lines elided ↑ open up ↑
8144 8152   */
8145 8153  static int
8146 8154  fcp_trigger_lun(struct fcp_lun *plun, child_info_t *cip, int old_mpxio,
8147 8155      int online, int lcount, int tcount, int flags)
8148 8156  {
8149 8157          int                     rval = NDI_FAILURE;
8150 8158          int                     circ;
8151 8159          child_info_t            *ccip;
8152 8160          struct fcp_port         *pptr = plun->lun_tgt->tgt_port;
8153 8161          int                     is_mpxio = pptr->port_mpxio;
8154      -        dev_info_t              *cdip, *pdip;
8155      -        char                    *devname;
8156 8162  
8157 8163          if ((old_mpxio != 0) && (plun->lun_mpxio != old_mpxio)) {
8158 8164                  /*
8159 8165                   * When this event gets serviced, lun_cip and lun_mpxio
8160 8166                   * has changed, so it should be invalidated now.
8161 8167                   */
8162 8168                  FCP_TRACE(fcp_logq, pptr->port_instbuf, fcp_trace,
8163 8169                      FCP_BUF_LEVEL_2, 0, "fcp_trigger_lun: lun_mpxio changed: "
8164 8170                      "plun: %p, cip: %p, what:%d", plun, cip, online);
8165 8171                  return (rval);
↓ open down ↓ 19 lines elided ↑ open up ↑
8185 8191          if (online == FCP_MPXIO_PATH_CLEAR_BUSY ||
8186 8192              online == FCP_MPXIO_PATH_SET_BUSY) {
8187 8193                  if (plun->lun_mpxio) {
8188 8194                          rval = fcp_update_mpxio_path(plun, cip, online);
8189 8195                  } else {
8190 8196                          rval = NDI_SUCCESS;
8191 8197                  }
8192 8198                  return (rval);
8193 8199          }
8194 8200  
8195      -        /*
8196      -         * Explicit devfs_clean() due to ndi_devi_offline() not
8197      -         * executing devfs_clean() if parent lock is held.
8198      -         */
8199      -        ASSERT(!servicing_interrupt());
8200      -        if (online == FCP_OFFLINE) {
8201      -                if (plun->lun_mpxio == 0) {
8202      -                        if (plun->lun_cip == cip) {
8203      -                                cdip = DIP(plun->lun_cip);
8204      -                        } else {
8205      -                                cdip = DIP(cip);
8206      -                        }
8207      -                } else if ((plun->lun_cip == cip) && plun->lun_cip) {
8208      -                        cdip = mdi_pi_get_client(PIP(plun->lun_cip));
8209      -                } else if ((plun->lun_cip != cip) && cip) {
8210      -                        /*
8211      -                         * This means a DTYPE/GUID change, we shall get the
8212      -                         * dip of the old cip instead of the current lun_cip.
8213      -                         */
8214      -                        cdip = mdi_pi_get_client(PIP(cip));
8215      -                }
8216      -                if (cdip) {
8217      -                        if (i_ddi_devi_attached(cdip)) {
8218      -                                pdip = ddi_get_parent(cdip);
8219      -                                devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
8220      -                                ndi_devi_enter(pdip, &circ);
8221      -                                (void) ddi_deviname(cdip, devname);
8222      -                                /*
8223      -                                 * Release parent lock before calling
8224      -                                 * devfs_clean().
8225      -                                 */
8226      -                                ndi_devi_exit(pdip, circ);
8227      -                                (void) devfs_clean(pdip, devname + 1,
8228      -                                    DV_CLEAN_FORCE);
8229      -                                kmem_free(devname, MAXNAMELEN + 1);
8230      -                        }
8231      -                }
8232      -        }
8233      -
8234 8201          if (fc_ulp_busy_port(pptr->port_fp_handle) != 0) {
8235 8202                  return (NDI_FAILURE);
8236 8203          }
8237 8204  
8238 8205          if (is_mpxio) {
8239 8206                  mdi_devi_enter(pptr->port_dip, &circ);
8240 8207          } else {
8241 8208                  ndi_devi_enter(pptr->port_dip, &circ);
8242 8209          }
8243 8210  
↓ open down ↓ 4819 lines elided ↑ open up ↑
13063 13030                      "plun: %p lun state: %x num: %d target state: %x",
13064 13031                      plun, plun->lun_state, plun->lun_num,
13065 13032                      plun->lun_tgt->tgt_port->port_state);
13066 13033                  return (rval);
13067 13034          }
13068 13035  
13069 13036          fcp_wwn_to_ascii(plun->lun_tgt->tgt_port_wwn.raw_wwn, buf);
13070 13037  
13071 13038          (void) snprintf(uaddr, MAXNAMELEN, "w%s,%x", buf, plun->lun_num);
13072 13039  
13073      -        if (plun->lun_old_guid) {
13074      -                if (mdi_pi_find(pdip, plun->lun_old_guid, uaddr) == pip) {
13075      -                        rval = FC_SUCCESS;
13076      -                }
13077      -        } else {
13078      -                if (mdi_pi_find(pdip, plun->lun_guid, uaddr) == pip) {
13079      -                        rval = FC_SUCCESS;
13080      -                }
     13040 +        if (mdi_pi_find(pdip, NULL, uaddr) == pip) {
     13041 +                rval = FC_SUCCESS;
13081 13042          }
     13043 +
13082 13044          return (rval);
13083 13045  }
13084 13046  
13085 13047  static mdi_pathinfo_t *
13086 13048  fcp_find_existing_pip(struct fcp_lun *plun, dev_info_t *pdip)
13087 13049  {
13088 13050          char                    buf[MAXNAMELEN];
13089 13051          char                    uaddr[MAXNAMELEN];
13090 13052          mdi_pathinfo_t          *pip;
13091 13053          struct fcp_tgt  *ptgt = plun->lun_tgt;
↓ open down ↓ 213 lines elided ↑ open up ↑
13305 13267          /*
13306 13268           * We will use this value twice. Make a copy to be sure we use
13307 13269           * the same value in both places.
13308 13270           */
13309 13271          lun_mpxio = plun->lun_mpxio;
13310 13272  
13311 13273          if (lun_mpxio == 0) {
13312 13274                  cdip = DIP(cip);
13313 13275                  mutex_exit(&plun->lun_mutex);
13314 13276                  mutex_exit(&pptr->port_mutex);
13315      -                rval = ndi_devi_offline(DIP(cip), flags);
     13277 +                rval = ndi_devi_offline(DIP(cip), NDI_DEVFS_CLEAN | flags);
13316 13278                  if (rval != NDI_SUCCESS) {
13317 13279                          FCP_TRACE(fcp_logq, pptr->port_instbuf,
13318 13280                              fcp_trace, FCP_BUF_LEVEL_3, 0,
13319 13281                              "fcp_offline_child: ndi_devi_offline failed "
13320 13282                              "rval=%x cip=%p", rval, cip);
13321 13283                  }
13322 13284          } else {
13323 13285                  cdip = mdi_pi_get_client(PIP(cip));
13324 13286                  mutex_exit(&plun->lun_mutex);
13325 13287                  mutex_exit(&pptr->port_mutex);
13326 13288  
13327 13289                  /*
13328 13290                   * Exit phci to avoid deadlock with power management code
13329 13291                   * during mdi_pi_offline
13330 13292                   */
13331 13293                  mdi_hold_path(PIP(cip));
13332 13294                  mdi_devi_exit_phci(pptr->port_dip, *circ);
13333 13295  
13334      -                rval = mdi_pi_offline(PIP(cip), flags);
     13296 +                rval = mdi_pi_offline(PIP(cip), flags & ~NDI_DEVI_REMOVE);
13335 13297  
13336 13298                  mdi_devi_enter_phci(pptr->port_dip, circ);
13337 13299                  mdi_rele_path(PIP(cip));
13338 13300  
13339 13301                  rval = (rval == MDI_SUCCESS) ? NDI_SUCCESS : NDI_FAILURE;
13340 13302          }
13341 13303  
13342 13304          mutex_enter(&ptgt->tgt_mutex);
13343 13305          plun->lun_state &= ~FCP_LUN_INIT;
13344 13306          mutex_exit(&ptgt->tgt_mutex);
↓ open down ↓ 79 lines elided ↑ open up ↑
13424 13386                           * see either valid lun_cip or NULL when holding
13425 13387                           * lun_mutex. We keep a copy in cip.
13426 13388                           */
13427 13389                          cip = plun->lun_cip;
13428 13390                          plun->lun_cip = NULL;
13429 13391  
13430 13392                          mutex_exit(&plun->lun_mutex);
13431 13393                          mutex_exit(&plun->lun_tgt->tgt_mutex);
13432 13394                          mutex_exit(&plun->lun_tgt->tgt_port->port_mutex);
13433 13395  
13434      -                        mdi_devi_enter(
13435      -                            plun->lun_tgt->tgt_port->port_dip, &circ);
     13396 +                        mdi_devi_enter(plun->lun_tgt->tgt_port->port_dip,
     13397 +                            &circ);
13436 13398  
13437 13399                          /*
13438 13400                           * Exit phci to avoid deadlock with power management
13439 13401                           * code during mdi_pi_offline
13440 13402                           */
13441 13403                          mdi_hold_path(PIP(cip));
13442      -                        mdi_devi_exit_phci(
13443      -                            plun->lun_tgt->tgt_port->port_dip, circ);
13444      -                        (void) mdi_pi_offline(PIP(cip),
13445      -                            NDI_DEVI_REMOVE);
13446      -                        mdi_devi_enter_phci(
13447      -                            plun->lun_tgt->tgt_port->port_dip, &circ);
     13404 +                        mdi_devi_exit_phci(plun->lun_tgt->tgt_port->port_dip,
     13405 +                            circ);
     13406 +                        (void) mdi_pi_offline(PIP(cip), 0);
     13407 +                        mdi_devi_enter_phci(plun->lun_tgt->tgt_port->port_dip,
     13408 +                            &circ);
13448 13409                          mdi_rele_path(PIP(cip));
13449 13410  
13450      -                        mdi_devi_exit(
13451      -                            plun->lun_tgt->tgt_port->port_dip, circ);
     13411 +                        mdi_devi_exit(plun->lun_tgt->tgt_port->port_dip, circ);
13452 13412  
13453 13413                          FCP_TRACE(fcp_logq,
13454 13414                              plun->lun_tgt->tgt_port->port_instbuf,
13455 13415                              fcp_trace, FCP_BUF_LEVEL_3, 0,
13456 13416                              "lun=%p pip freed %p", plun, cip);
13457 13417  
13458 13418                          (void) mdi_prop_remove(PIP(cip), NULL);
13459 13419                          (void) mdi_pi_free(PIP(cip), 0);
13460 13420  
13461 13421                          mutex_enter(&plun->lun_tgt->tgt_port->port_mutex);
↓ open down ↓ 2894 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX