Print this page
3862 stmf + kstat = kernel panic
3863 stmf_itl_task_start() must check for ilu->ilu_kstat_io is non-null
3864 memory leak in the iSCSI code
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Jeremy Jones <jeremy@delphix.com>
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Richard Elling <richard.elling@gmail.com>
Approved by: Gordon Ross <gwr@nexenta.com>
3621 ZFS LU stuck in the offlining state
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Jeff Biseda <jeff.biseda@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Approved by: Christopher Siden <christopher.siden@delphix.com>


   3  *
   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  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 #ifndef _STMF_IMPL_H
  25 #define _STMF_IMPL_H
  26 
  27 #include <sys/stmf_defines.h>
  28 #include <sys/stmf_ioctl.h>
  29 
  30 #ifdef  __cplusplus
  31 extern "C" {
  32 #endif
  33 
  34 typedef uint32_t stmf_event_handle_t;
  35 #define STMF_MAX_NUM_EVENTS             (sizeof (stmf_event_handle_t) * 8)
  36 #define STMF_EVENT_ADD(h, e)            (atomic_or_32(&(h), \
  37                                                 ((uint32_t)1) << (e)))
  38 #define STMF_EVENT_REMOVE(h, e)         (atomic_and_32(&(h), \
  39                                                 ~(((uint32_t)1) << (e))))
  40 #define STMF_EVENT_ENABLED(h, e)        (((h) & ((uint32_t)1) << (e)) != 0)
  41 #define STMF_EVENT_CLEAR_ALL(h)         ((h) = 0)
  42 #define STMF_EVENT_ALLOC_HANDLE(h)      ((h) = 0)


  80         struct stmf_i_lu *ilu_next;
  81         struct stmf_i_lu *ilu_prev;
  82         char            *ilu_alias;
  83         char            ilu_ascii_hex_guid[STMF_GUID_INPUT + 1];
  84         kmutex_t        ilu_task_lock;
  85         uint32_t        ilu_task_cntr1;
  86         uint32_t        ilu_task_cntr2;
  87         uint32_t        *ilu_cur_task_cntr;
  88         uint32_t        ilu_ntasks;      /* # of tasks in the ilu_task list */
  89         uint32_t        ilu_ntasks_free;        /* # of tasks that are free */
  90         uint32_t        ilu_ntasks_min_free; /* # minimal free tasks */
  91         uint32_t        rsvd1;
  92         uint32_t        ilu_proxy_registered;
  93         uint64_t        ilu_reg_msgid;
  94         struct stmf_i_scsi_task *ilu_tasks;
  95         struct stmf_i_scsi_task *ilu_free_tasks;
  96         struct stmf_itl_data    *ilu_itl_list;
  97         kstat_t         *ilu_kstat_info;
  98         kstat_t         *ilu_kstat_io;
  99         kmutex_t        ilu_kstat_lock;

 100 
 101         /* point to the luid entry in stmf_state.stmf_luid_list */
 102         void            *ilu_luid;
 103 } stmf_i_lu_t;
 104 
 105 /*
 106  * ilu_flags
 107  */
 108 #define ILU_STALL_DEREGISTER            0x0001
 109 #define ILU_RESET_ACTIVE                0x0002
 110 
 111 typedef struct stmf_i_port_provider {
 112         stmf_port_provider_t    *ipp_pp;
 113         uint32_t                ipp_alloc_size;
 114         uint32_t                ipp_npps;
 115         uint32_t                ipp_cb_in_progress:1,
 116                                 ipp_rsvd:31;
 117         struct stmf_i_port_provider *ipp_next;
 118         struct stmf_pp_data     *ipp_ppd;
 119 } stmf_i_port_provider_t;


 147         kmutex_t                ilport_kstat_lock;
 148         char                    ilport_kstat_tgt_name[STMF_TGT_NAME_LEN];
 149         /* which target group this port belongs to in stmf_state.stmf_tg_list */
 150         void                    *ilport_tg;
 151         id_t                    ilport_instance;
 152         /* XXX Need something to track all the remote ports also */
 153 } stmf_i_local_port_t;
 154 
 155 #define STMF_AVG_ONLINE_INTERVAL        (30 * drv_usectohz(1000000))
 156 
 157 #define MAX_IRPORT                      0x10000
 158 
 159 typedef struct stmf_i_remote_port {
 160         struct scsi_devid_desc  *irport_id;
 161         kmutex_t                irport_mutex;
 162         int                     irport_refcnt;
 163         id_t                    irport_instance;
 164         avl_node_t              irport_ln;
 165 } stmf_i_remote_port_t;
 166 
 167 typedef struct stmf_i_itl_kstat {
 168         char                    iitl_kstat_nm[KSTAT_STRLEN];
 169         char                    iitl_kstat_lport[STMF_TGT_NAME_LEN];
 170         char                    iitl_kstat_guid[STMF_GUID_INPUT + 1];
 171         char                    *iitl_kstat_strbuf;
 172         int                     iitl_kstat_strbuflen;
 173         kstat_t                 *iitl_kstat_info;
 174         kstat_t                 *iitl_kstat_taskq;
 175         kstat_t                 *iitl_kstat_lu_xfer;
 176         kstat_t                 *iitl_kstat_lport_xfer;
 177         avl_node_t              iitl_kstat_ln;
 178 } stmf_i_itl_kstat_t;
 179 
 180 /*
 181  * ilport flags
 182  */
 183 #define ILPORT_FORCED_OFFLINE           0x01
 184 #define ILPORT_SS_GOT_INITIAL_LUNS      0x02
 185 
 186 typedef struct stmf_i_scsi_session {
 187         stmf_scsi_session_t     *iss_ss;
 188         uint32_t                iss_alloc_size;
 189         uint32_t                iss_flags;
 190         stmf_i_remote_port_t    *iss_irport;
 191         struct stmf_i_scsi_session *iss_next;
 192         /*
 193          * Ideally we should maintain 2 maps. One would indicate a new map
 194          * which will become available only upon receipt of a REPORT LUN
 195          * cmd.
 196          */
 197         struct stmf_lun_map     *iss_sm;
 198         /*
 199          * which host group the host of this session belongs to in


 308  */
 309 #define ITASK_CMD_MASK                  0x1F
 310 #define ITASK_CMD_BUF_NDX(cmd)          (((uint8_t)(cmd)) >> 5)
 311 #define ITASK_CMD_NEW_TASK              0x1
 312 #define ITASK_CMD_DATA_XFER_DONE        0x2
 313 #define ITASK_CMD_STATUS_DONE           0x3
 314 #define ITASK_CMD_ABORT                 0x4
 315 #define ITASK_CMD_SEND_STATUS           0x5
 316 #define ITASK_CMD_POLL                  0x10
 317 #define ITASK_CMD_POLL_LU               (ITASK_CMD_POLL | 1)
 318 #define ITASK_CMD_POLL_LPORT            (ITASK_CMD_POLL | 2)
 319 
 320 /*
 321  * struct maintained on a per itl basis when the lu registers ITL handle.
 322  */
 323 typedef struct stmf_itl_data {
 324         uint32_t                        itl_counter;
 325         uint8_t                         itl_flags;
 326         uint8_t                         itl_hdlrm_reason;
 327         uint16_t                        itl_lun;
 328         char                            *itl_kstat_strbuf;
 329         int                             itl_kstat_strbuflen;
 330         kstat_t                         *itl_kstat_info;
 331         kstat_t                         *itl_kstat_taskq;
 332         kstat_t                         *itl_kstat_lu_xfer;
 333         kstat_t                         *itl_kstat_lport_xfer;
 334         void                            *itl_handle;
 335         struct stmf_i_lu                *itl_ilu;
 336         struct stmf_i_scsi_session      *itl_session;
 337         struct stmf_itl_data            *itl_next;
 338 } stmf_itl_data_t;
 339 
 340 /*
 341  * itl flags
 342  */
 343 #define STMF_ITL_BEING_TERMINATED       0x01
 344 
 345 /*
 346  * data structures to maintain provider private data.
 347  */
 348 typedef struct stmf_pp_data {
 349         struct stmf_pp_data     *ppd_next;
 350         void                    *ppd_provider;
 351         nvlist_t                *ppd_nv;
 352         uint32_t                ppd_lu_provider:1,
 353                                 ppd_port_provider:1,




   3  *
   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  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013 by Delphix. All rights reserved.
  24  */
  25 #ifndef _STMF_IMPL_H
  26 #define _STMF_IMPL_H
  27 
  28 #include <sys/stmf_defines.h>
  29 #include <sys/stmf_ioctl.h>
  30 
  31 #ifdef  __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 typedef uint32_t stmf_event_handle_t;
  36 #define STMF_MAX_NUM_EVENTS             (sizeof (stmf_event_handle_t) * 8)
  37 #define STMF_EVENT_ADD(h, e)            (atomic_or_32(&(h), \
  38                                                 ((uint32_t)1) << (e)))
  39 #define STMF_EVENT_REMOVE(h, e)         (atomic_and_32(&(h), \
  40                                                 ~(((uint32_t)1) << (e))))
  41 #define STMF_EVENT_ENABLED(h, e)        (((h) & ((uint32_t)1) << (e)) != 0)
  42 #define STMF_EVENT_CLEAR_ALL(h)         ((h) = 0)
  43 #define STMF_EVENT_ALLOC_HANDLE(h)      ((h) = 0)


  81         struct stmf_i_lu *ilu_next;
  82         struct stmf_i_lu *ilu_prev;
  83         char            *ilu_alias;
  84         char            ilu_ascii_hex_guid[STMF_GUID_INPUT + 1];
  85         kmutex_t        ilu_task_lock;
  86         uint32_t        ilu_task_cntr1;
  87         uint32_t        ilu_task_cntr2;
  88         uint32_t        *ilu_cur_task_cntr;
  89         uint32_t        ilu_ntasks;      /* # of tasks in the ilu_task list */
  90         uint32_t        ilu_ntasks_free;        /* # of tasks that are free */
  91         uint32_t        ilu_ntasks_min_free; /* # minimal free tasks */
  92         uint32_t        rsvd1;
  93         uint32_t        ilu_proxy_registered;
  94         uint64_t        ilu_reg_msgid;
  95         struct stmf_i_scsi_task *ilu_tasks;
  96         struct stmf_i_scsi_task *ilu_free_tasks;
  97         struct stmf_itl_data    *ilu_itl_list;
  98         kstat_t         *ilu_kstat_info;
  99         kstat_t         *ilu_kstat_io;
 100         kmutex_t        ilu_kstat_lock;
 101         kcondvar_t      ilu_offline_pending_cv;
 102 
 103         /* point to the luid entry in stmf_state.stmf_luid_list */
 104         void            *ilu_luid;
 105 } stmf_i_lu_t;
 106 
 107 /*
 108  * ilu_flags
 109  */
 110 #define ILU_STALL_DEREGISTER            0x0001
 111 #define ILU_RESET_ACTIVE                0x0002
 112 
 113 typedef struct stmf_i_port_provider {
 114         stmf_port_provider_t    *ipp_pp;
 115         uint32_t                ipp_alloc_size;
 116         uint32_t                ipp_npps;
 117         uint32_t                ipp_cb_in_progress:1,
 118                                 ipp_rsvd:31;
 119         struct stmf_i_port_provider *ipp_next;
 120         struct stmf_pp_data     *ipp_ppd;
 121 } stmf_i_port_provider_t;


 149         kmutex_t                ilport_kstat_lock;
 150         char                    ilport_kstat_tgt_name[STMF_TGT_NAME_LEN];
 151         /* which target group this port belongs to in stmf_state.stmf_tg_list */
 152         void                    *ilport_tg;
 153         id_t                    ilport_instance;
 154         /* XXX Need something to track all the remote ports also */
 155 } stmf_i_local_port_t;
 156 
 157 #define STMF_AVG_ONLINE_INTERVAL        (30 * drv_usectohz(1000000))
 158 
 159 #define MAX_IRPORT                      0x10000
 160 
 161 typedef struct stmf_i_remote_port {
 162         struct scsi_devid_desc  *irport_id;
 163         kmutex_t                irport_mutex;
 164         int                     irport_refcnt;
 165         id_t                    irport_instance;
 166         avl_node_t              irport_ln;
 167 } stmf_i_remote_port_t;
 168 













 169 /*
 170  * ilport flags
 171  */
 172 #define ILPORT_FORCED_OFFLINE           0x01
 173 #define ILPORT_SS_GOT_INITIAL_LUNS      0x02
 174 
 175 typedef struct stmf_i_scsi_session {
 176         stmf_scsi_session_t     *iss_ss;
 177         uint32_t                iss_alloc_size;
 178         uint32_t                iss_flags;
 179         stmf_i_remote_port_t    *iss_irport;
 180         struct stmf_i_scsi_session *iss_next;
 181         /*
 182          * Ideally we should maintain 2 maps. One would indicate a new map
 183          * which will become available only upon receipt of a REPORT LUN
 184          * cmd.
 185          */
 186         struct stmf_lun_map     *iss_sm;
 187         /*
 188          * which host group the host of this session belongs to in


 297  */
 298 #define ITASK_CMD_MASK                  0x1F
 299 #define ITASK_CMD_BUF_NDX(cmd)          (((uint8_t)(cmd)) >> 5)
 300 #define ITASK_CMD_NEW_TASK              0x1
 301 #define ITASK_CMD_DATA_XFER_DONE        0x2
 302 #define ITASK_CMD_STATUS_DONE           0x3
 303 #define ITASK_CMD_ABORT                 0x4
 304 #define ITASK_CMD_SEND_STATUS           0x5
 305 #define ITASK_CMD_POLL                  0x10
 306 #define ITASK_CMD_POLL_LU               (ITASK_CMD_POLL | 1)
 307 #define ITASK_CMD_POLL_LPORT            (ITASK_CMD_POLL | 2)
 308 
 309 /*
 310  * struct maintained on a per itl basis when the lu registers ITL handle.
 311  */
 312 typedef struct stmf_itl_data {
 313         uint32_t                        itl_counter;
 314         uint8_t                         itl_flags;
 315         uint8_t                         itl_hdlrm_reason;
 316         uint16_t                        itl_lun;






 317         void                            *itl_handle;
 318         struct stmf_i_lu                *itl_ilu;
 319         struct stmf_i_scsi_session      *itl_session;
 320         struct stmf_itl_data            *itl_next;
 321 } stmf_itl_data_t;
 322 
 323 /*
 324  * itl flags
 325  */
 326 #define STMF_ITL_BEING_TERMINATED       0x01
 327 
 328 /*
 329  * data structures to maintain provider private data.
 330  */
 331 typedef struct stmf_pp_data {
 332         struct stmf_pp_data     *ppd_next;
 333         void                    *ppd_provider;
 334         nvlist_t                *ppd_nv;
 335         uint32_t                ppd_lu_provider:1,
 336                                 ppd_port_provider:1,