Print this page
OS-68 cfgadm can cause kernel panic when trying to configure a retired device


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.

  24  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  25  * Copyright (c) 2016 by Delphix. All rights reserved.
  26  */
  27 
  28 #include <sys/note.h>
  29 
  30 /*
  31  * Generic SCSI Host Bus Adapter interface implementation
  32  */
  33 #include <sys/scsi/scsi.h>
  34 #include <sys/scsi/generic/sas.h>
  35 #include <sys/file.h>
  36 #include <sys/disp.h>                     /* for minclsyspri */
  37 #include <sys/ddi_impldefs.h>
  38 #include <sys/ndi_impldefs.h>
  39 #include <sys/sunndi.h>
  40 #include <sys/ddi.h>
  41 #include <sys/sunmdi.h>
  42 #include <sys/mdi_impldefs.h>
  43 #include <sys/callb.h>


3083 int
3084 scsi_hba_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
3085     int *rvalp)
3086 {
3087         dev_info_t              *self;
3088         struct devctl_iocdata   *dcp = NULL;
3089         dev_info_t              *child = NULL;
3090         mdi_pathinfo_t          *path = NULL;
3091         struct scsi_device      *sd;
3092         scsi_hba_tran_t         *tran;
3093         uint_t                  bus_state;
3094         int                     rv = 0;
3095         int                     circ;
3096         char                    *name;
3097         char                    *addr;
3098 
3099         self = e_ddi_hold_devi_by_dev(dev, 0);
3100         if (self == NULL) {
3101                 rv = ENXIO;
3102                 goto out;





3103         }
3104 
3105         tran = ddi_get_driver_private(self);
3106         if (tran == NULL) {
3107                 rv = ENXIO;
3108                 goto out;
3109         }
3110 
3111         /* Ioctls for which the generic implementation suffices. */
3112         switch (cmd) {
3113         case DEVCTL_BUS_GETSTATE:
3114                 rv = ndi_devctl_ioctl(self, cmd, arg, mode, 0);
3115                 goto out;
3116         }
3117 
3118         /* read devctl ioctl data */
3119         if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) {
3120                 rv = EFAULT;
3121                 goto out;
3122         }




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  26  * Copyright (c) 2016 by Delphix. All rights reserved.
  27  */
  28 
  29 #include <sys/note.h>
  30 
  31 /*
  32  * Generic SCSI Host Bus Adapter interface implementation
  33  */
  34 #include <sys/scsi/scsi.h>
  35 #include <sys/scsi/generic/sas.h>
  36 #include <sys/file.h>
  37 #include <sys/disp.h>                     /* for minclsyspri */
  38 #include <sys/ddi_impldefs.h>
  39 #include <sys/ndi_impldefs.h>
  40 #include <sys/sunndi.h>
  41 #include <sys/ddi.h>
  42 #include <sys/sunmdi.h>
  43 #include <sys/mdi_impldefs.h>
  44 #include <sys/callb.h>


3084 int
3085 scsi_hba_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
3086     int *rvalp)
3087 {
3088         dev_info_t              *self;
3089         struct devctl_iocdata   *dcp = NULL;
3090         dev_info_t              *child = NULL;
3091         mdi_pathinfo_t          *path = NULL;
3092         struct scsi_device      *sd;
3093         scsi_hba_tran_t         *tran;
3094         uint_t                  bus_state;
3095         int                     rv = 0;
3096         int                     circ;
3097         char                    *name;
3098         char                    *addr;
3099 
3100         self = e_ddi_hold_devi_by_dev(dev, 0);
3101         if (self == NULL) {
3102                 rv = ENXIO;
3103                 goto out;
3104         }
3105 
3106         if (DEVI(self)->devi_flags & (DEVI_RETIRED | DEVI_RETIRING)) {
3107                 rv = ENXIO;
3108                 goto out;
3109         }
3110 
3111         tran = ddi_get_driver_private(self);
3112         if (tran == NULL) {
3113                 rv = ENXIO;
3114                 goto out;
3115         }
3116 
3117         /* Ioctls for which the generic implementation suffices. */
3118         switch (cmd) {
3119         case DEVCTL_BUS_GETSTATE:
3120                 rv = ndi_devctl_ioctl(self, cmd, arg, mode, 0);
3121                 goto out;
3122         }
3123 
3124         /* read devctl ioctl data */
3125         if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) {
3126                 rv = EFAULT;
3127                 goto out;
3128         }