Home | History | Annotate | Download | only in iscsitgtd
      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 /*
     23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #ifndef _TARGET_H
     28 #define	_TARGET_H
     29 
     30 /*
     31  * Block comment which describes the contents of this file.
     32  */
     33 
     34 #ifdef __cplusplus
     35 extern "C" {
     36 #endif
     37 
     38 #define	DEFAULT_CONFIG		"/etc/iscsi/"
     39 #define	DEFAULT_CONFIG_LOCATION	DEFAULT_CONFIG "target_config.xml"
     40 #define	DEFAULT_TARGET_BASEDIR	DEFAULT_CONFIG
     41 #define	DEFAULT_TARGET_LOG	"/tmp/target_log"
     42 
     43 /*
     44  * []------------------------------------------------------------------[]
     45  * | Common strings which are used throughout the target.		|
     46  * []------------------------------------------------------------------[]
     47  */
     48 /*
     49  * Target type strings are used to distinguish between the emulated types.
     50  * These strings are stored in the params file so they must not be changed
     51  * without thinking about upgrade issues.
     52  */
     53 #define	TGT_TYPE_DISK		"disk"
     54 #define	TGT_TYPE_TAPE		"tape"
     55 #define	TGT_TYPE_OSD		"osd"
     56 #define	TGT_TYPE_RAW		"raw"
     57 #define	TGT_TYPE_INVALID	"invalid"
     58 
     59 /*
     60  * During the creation phase of a LU it starts out offline during block
     61  * initialization, once initialization is complete it will transition to
     62  * online. If during the initialization an error occurs it will be so marked.
     63  */
     64 #define	TGT_STATUS_OFFLINE	"offline"
     65 #define	TGT_STATUS_ONLINE	"online"
     66 #define	TGT_STATUS_ERRORED	"errored"
     67 
     68 /*
     69  * Base file names for the logical units (LU). The format used is params.%d and
     70  * lun.%d These are used both to build the LU name and when searching the
     71  * target directory for valid luns. Don't change these names unless the upgrade
     72  * path has been thought about.
     73  */
     74 #define	PARAMBASE		"params."
     75 #define	LUNBASE			"lun."
     76 #define	OSDBASE			"osd_root."
     77 #define	PERSISTENCEBASE		"pgr."
     78 #define	ISCSI_TARGET_ALIAS	"TargetAlias"
     79 #define	ZVOL_PATH		"/dev/zvol/rdsk/"
     80 
     81 /*
     82  * Base file name for persistent reservation data (PR). The format used is pr.
     83  * This name is used both to build the PR name and when searching the target
     84  * directory for persistent reservation data. Don't change these names unless
     85  * the upgrade path has been thought about.
     86  */
     87 #define	PRBASE			"persistent_reservations"
     88 
     89 /*
     90  * The IQN names that are created use libuuid + the local target name
     91  * as the idr_str portion of: iqn.1986-03.com.sun:<version>:<id_str>
     92  * In case this changes we also include a version number. Currently
     93  * version 1 is used by the Solaris iSCSI Initiator which has the MAC address,
     94  * timestamp, and hostname.
     95  */
     96 #define	TARGET_NAME_VERS	2
     97 #define	TARGET_NOFILE		10000
     98 
     99 /*
    100  * Minimum and maximum values for Target Portal Group Tag as specified
    101  * by RFC3720
    102  */
    103 #define	TPGT_MIN		1
    104 #define	TPGT_MAX		65535
    105 
    106 /*
    107  * Minimum and maximum values for MaxRecvDataSegmentLength
    108  */
    109 #define	MAXRCVDATA_MIN		512
    110 #define	MAXRCVDATA_MAX		((1 << 24) - 1)
    111 
    112 /*
    113  * Major/minor versioning for the configuration files.
    114  * If we find a configuration file that has a higher
    115  * major number than we support we exit. Major number
    116  * changes are for radical structure differences. Shouldn't
    117  * happen, but we've got a means of detecting such a situation
    118  * a bailing out before doing any damage. Minor number changes
    119  * mean additions to the current format have been added. For
    120  * right now, we use -1, which means ignore the minor number. In
    121  * the future it would be possible for the software to determine
    122  * that a file had certain additions, but maybe not all changes.
    123  */
    124 #define	XML_VERS_MAIN_MAJ	1
    125 #define	XML_VERS_MAIN_MIN	-1
    126 #define	XML_VERS_TARG_MAJ	1
    127 #define	XML_VERS_TARG_MIN	-1
    128 #define	XML_VERS_LUN_MAJ	1
    129 #define	XML_VERS_LUN_MIN	-1
    130 #define	XML_VERS_RESULT_MAJ	1
    131 #define	XML_VERS_RESULT_MIN	-1
    132 
    133 /*
    134  * Default values of the LUN parameters
    135  */
    136 #define	DEFAULT_LUN_SIZE	((1024 * 1024 * 1024) / 512)
    137 #define	DEFAULT_RPM		7200
    138 #define	DEFAULT_HEADS		16
    139 #define	DEFAULT_CYLINDERS	100
    140 #define	DEFAULT_SPT		128
    141 #define	DEFAULT_BYTES_PER	512
    142 #define	DEFAULT_INTERLEAVE	1
    143 #define	DEFAULT_PID		"SOLARIS"
    144 #define	DEFAULT_VID		"SUN"
    145 #define	DEFAULT_REVISION	"1"
    146 
    147 /*
    148  * SPC-3 revision 21c, section 7.6.4.4.4
    149  * EUI-64 based 16-byte IDENTIFIER field format
    150  */
    151 typedef struct eui_16 {
    152 	uchar_t	e_vers,
    153 		e_resrv1,
    154 		e_mac[6],
    155 		e_company_id[3],
    156 		e_resv2,
    157 		e_timestamp[4];
    158 } eui_16_t;
    159 
    160 /*
    161  * SPC-4 revision 11, section 7.6.3.6.5
    162  * NAA IEEE Registered Extended designator format
    163  */
    164 typedef struct naa_16 {
    165 #if defined(_BIT_FIELDS_LTOH)
    166 	uchar_t	n_company_id_hi	: 4,
    167 		n_naa		: 4;
    168 #elif defined(_BIT_FIELDS_HTOL)
    169 	uchar_t	n_naa		: 4,
    170 		n_company_id_hi	: 4;
    171 #else
    172 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
    173 #endif
    174 	uchar_t	n_company_id_b1,
    175 		n_company_id_b2;
    176 #if defined(_BIT_FIELDS_LTOH)
    177 	uchar_t	n_resv1		: 4,
    178 		n_company_id_lo	: 4;
    179 #elif defined(_BIT_FIELDS_HTOL)
    180 	uchar_t	n_company_id_lo	: 4,
    181 		n_resv1		: 4;
    182 #else
    183 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
    184 #endif
    185 	uchar_t	n_timestamp[4];
    186 	uchar_t	n_resv2;
    187 	uchar_t	n_mac[6];
    188 	uchar_t	n_resv3;
    189 } naa_16_t;
    190 
    191 #define	SUN_EUI_16_VERS		1
    192 #define	SUN_NAA_16_TYPE		6
    193 
    194 #define	SUN_INQUIRY_ID_TYPE(GUID)	\
    195 	(((naa_16_t *)(GUID))->n_naa == SUN_NAA_16_TYPE ? \
    196 	SPC_INQUIRY_ID_TYPE_NAA : SPC_INQUIRY_ID_TYPE_EUI)
    197 
    198 #define	SUN_EN			0x144f
    199 #define	MIN_VAL			4
    200 
    201 #ifndef min
    202 #define	min(a, b) ((a) > (b) ? (b) : (a))
    203 #endif
    204 #ifndef max
    205 #define	max(a, b) ((a) > (b) ? (a) : (b))
    206 #endif
    207 
    208 typedef struct {
    209 	char	*name;
    210 	char	*(*func)(char *, char *);
    211 	char	*delete_name;
    212 } admin_table_t;
    213 
    214 #include <sys/socket.h>
    215 #include <umem.h>
    216 #include <iscsitgt_impl.h>
    217 #include "queue.h"
    218 
    219 void create_func(tgt_node_t *, target_queue_t *, target_queue_t *, ucred_t *);
    220 void modify_func(tgt_node_t *, target_queue_t *, target_queue_t *, ucred_t *);
    221 void remove_func(tgt_node_t *, target_queue_t *, target_queue_t *, ucred_t *);
    222 void list_func(tgt_node_t *, target_queue_t *, target_queue_t *, ucred_t *);
    223 void logout_targ(char *targ);
    224 char *update_basedir(char *, char *);
    225 char *valid_radius_srv(char *name, char *prop);
    226 char *valid_isns_srv(char *name, char *prop);
    227 Boolean_t if_find_mac(target_queue_t *mgmt);
    228 void if_target_address(char **text, int *text_length, struct sockaddr *sp);
    229 
    230 extern admin_table_t	admin_prop_list[];
    231 extern char 		*target_basedir;
    232 extern char 		*target_log;
    233 extern char		*config_file;
    234 extern char		*pgr_basedir;
    235 extern tgt_node_t	*targets_config;
    236 extern tgt_node_t	*main_config;
    237 extern uchar_t		mac_addr[];
    238 extern size_t		mac_len;
    239 extern int		main_vers_maj,
    240 			main_vers_min,
    241 			targets_vers_maj,
    242 			targets_vers_min,
    243 			iscsi_port;
    244 extern Boolean_t	enforce_strict_guid,
    245 			thin_provisioning,
    246 			disable_tpgs,
    247 			dbg_timestamps,
    248 			pgr_persist;
    249 extern pthread_rwlock_t	targ_config_mutex;
    250 extern umem_cache_t	*iscsi_cmd_cache,
    251 			*t10_cmd_cache,
    252 			*queue_cache;
    253 
    254 #ifdef __cplusplus
    255 }
    256 #endif
    257 
    258 #endif /* _TARGET_H */
    259