Home | History | Annotate | Download | only in iscsit
      1 /*
      2  * CDDL HEADER START
      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 2009 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 #ifndef _ISNS_CLIENT_H_
     26 #define	_ISNS_CLIENT_H_
     27 
     28 #include <iscsit.h>
     29 
     30 /*
     31  * List of iSNS servers with which we register.
     32  */
     33 
     34 typedef struct {
     35 	int			svr_retry_count;
     36 	struct sockaddr_storage	svr_sa;
     37 	clock_t			svr_last_msg;
     38 	list_node_t		svr_ln;
     39 	uint32_t		svr_registered:1,
     40 				svr_reset_needed:1,
     41 				svr_delete_needed:1,
     42 				svr_targets_changed:1;
     43 	uint32_t		svr_last_target_index;
     44 	uint32_t		svr_esi_interval;
     45 	avl_tree_t		svr_target_list;
     46 } iscsit_isns_svr_t;
     47 
     48 /*
     49  * Type of registration to perform (deregister, register, update)
     50  */
     51 typedef enum {
     52 	ISNS_DEREGISTER_TARGET = 0,
     53 	ISNS_DEREGISTER_ALL,
     54 	ISNS_REGISTER_TARGET,
     55 	ISNS_REGISTER_ALL,
     56 	ISNS_MODIFY_TARGET
     57 } isns_reg_type_t;
     58 
     59 /*
     60  * This structure is used to keep state with regard to the RX threads used
     61  * for ESI.
     62  */
     63 
     64 
     65 typedef struct {
     66 	kthread_t			*esi_thread;
     67 	kt_did_t			esi_thread_did;
     68 	ksocket_t			esi_so;
     69 	kmutex_t			esi_mutex;
     70 	kcondvar_t			esi_cv;
     71 	uint16_t			esi_port;
     72 	boolean_t			esi_enabled;
     73 	boolean_t			esi_valid;
     74 	boolean_t			esi_thread_running;
     75 } isns_esi_tinfo_t;
     76 
     77 
     78 /*
     79  * Portal list - both default portals from idm_get_ipaddr and portals
     80  * defined in target port groups.
     81  */
     82 
     83 typedef struct isns_portal_s {
     84 	struct sockaddr_storage		portal_addr;
     85 	avl_node_t			portal_node;
     86 	timespec_t			portal_esi_timestamp;
     87 	iscsit_portal_t			*portal_iscsit;	/* if in TPG */
     88 	boolean_t			portal_default; /* if in default */
     89 } isns_portal_t;
     90 
     91 
     92 typedef struct isns_tpgt_addr_s {
     93 	list_node_t		portal_ln;
     94 	struct sockaddr_storage	portal_addr;
     95 } isns_tpgt_addr_t;
     96 
     97 typedef struct isns_tpgt_s {
     98 	list_node_t		ti_tpgt_ln;
     99 	uint16_t		ti_tpgt_tag;
    100 	list_t			ti_portal_list;
    101 } isns_tpgt_t;
    102 
    103 typedef struct isns_target_info_s {
    104 	idm_refcnt_t		ti_refcnt;
    105 	char			ti_tgt_name[MAX_ISCSI_NODENAMELEN];
    106 	char			ti_tgt_alias[MAX_ISCSI_NODENAMELEN];
    107 	list_t			ti_tpgt_list;
    108 } isns_target_info_t;
    109 
    110 /* Contents of isns_target_list and svr->svr_target_list */
    111 typedef struct isns_target_s {
    112 	iscsit_tgt_t		*target;
    113 	avl_node_t		target_node;
    114 	boolean_t		target_registered;
    115 	boolean_t		target_update_needed;
    116 	boolean_t		target_delete_needed;
    117 	isns_target_info_t	*target_info;
    118 } isns_target_t;
    119 
    120 /*
    121  * If no ESI request is received within this number of intervals, we'll
    122  * try to re-register with the server.
    123  */
    124 #define	MAX_ESI_INTERVALS			3
    125 
    126 /*
    127  * Interval to ask the server to send us ESI probes, in seconds.
    128  */
    129 #define	ISNS_DEFAULT_ESI_INTERVAL		20
    130 
    131 /*
    132  * Registration Period (when not using ESI), in seconds. (15 min)
    133  */
    134 #define	ISNS_DEFAULT_REGISTRATION_PERIOD	900
    135 
    136 /*
    137  * Initial delay before sending first DevAttrReg message.
    138  */
    139 #define	ISNS_INITIAL_DELAY			5
    140 
    141 it_cfg_status_t
    142 isnst_config_merge(it_config_t *cfg);
    143 
    144 int iscsit_isns_init(iscsit_hostinfo_t *hostinfo);
    145 void iscsit_isns_fini();
    146 int iscsit_isns_register(iscsit_tgt_t *target);
    147 int iscsit_isns_deregister(iscsit_tgt_t *target);
    148 void iscsit_isns_target_update(iscsit_tgt_t *target);
    149 void iscsit_isns_portal_online(iscsit_portal_t *portal);
    150 void iscsit_isns_portal_offline(iscsit_portal_t *portal);
    151 
    152 #endif /* _ISNS_CLIENT_H_ */
    153