Home | History | Annotate | Download | only in common
      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 _ISCSITGT_IMPL_H
     28 #define	_ISCSITGT_IMPL_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 #include <libxml/xmlreader.h>
     39 
     40 #ifndef MIN
     41 #define	MIN(x, y)	((x) < (y) ? (x) : (y))
     42 #endif
     43 #ifndef MAX
     44 #define	MAX(x, y)	((x) > (y) ? (x) : (y))
     45 #endif
     46 
     47 /*
     48  * Solaris typedefs boolean_t to be an enum with B_TRUE and B_FALSE.
     49  * MacOS X typedefs boolean_t to be an int with #defines for TRUE & FALSE
     50  * I like the use of enum's for return codes so that compilers can catch
     51  * sloppy coding practices so I've defined a Boolean_t which is unique here.
     52  */
     53 typedef enum {
     54 	False = 0,
     55 	True = 1
     56 } Boolean_t;
     57 
     58 #ifndef DTYPE_OSD
     59 #define	DTYPE_OSD	0x11
     60 #endif
     61 
     62 #define	DOOR_MIN_SPACE	128
     63 
     64 #define	ISCSI_TARGET_MGMT_DOOR	"/var/run/iscsi_tgt_door"
     65 /*
     66  * XML element defines.
     67  */
     68 #define	XML_ELEMENT_ERROR	"error"
     69 #define	XML_ELEMENT_CODE	"code"
     70 #define	XML_ELEMENT_MESSAGE	"message"
     71 #define	XML_ELEMENT_TRANSVERS	"transport-version"
     72 #define	XML_ELEMENT_PROPS	"props"
     73 #define	XML_ELEMENT_DATAOUT	"data-out-size"
     74 #define	XML_ELEMENT_BASEDIR	"base-directory"
     75 #define	XML_ELEMENT_CHAPSECRET	"chap-secret"
     76 #define	XML_ELEMENT_DELETE_CHAPSECRET	"delete-chap-secret"
     77 #define	XML_ELEMENT_CHAPNAME	"chap-name"
     78 #define	XML_ELEMENT_DELETE_CHAPNAME	"delete-chap-name"
     79 #define	XML_ELEMENT_RAD_ACCESS	"radius-access"
     80 #define	XML_ELEMENT_RAD_SERV	"radius-server"
     81 #define	XML_ELEMENT_DELETE_RAD_SERV	"delete-radius-server"
     82 #define	XML_ELEMENT_RAD_SECRET	"radius-secret"
     83 #define	XML_ELEMENT_DELETE_RAD_SECRET	"delete-radius-secret"
     84 #define	XML_ELEMENT_ISNS_ACCESS	"isns-access"
     85 #define	XML_ELEMENT_ISNS_SERV	"isns-server"
     86 #define	XML_ELEMENT_ISNS_SERVER_STATUS	"isns-server-status"
     87 #define	XML_ELEMENT_FAST	"fast-write-ack"
     88 #define	XML_ELEMENT_NAME	"name"
     89 #define	XML_ELEMENT_ACL		"acl"
     90 #define	XML_ELEMENT_ACLLIST	"acl-list"
     91 #define	XML_ELEMENT_TPGT	"tpgt"
     92 #define	XML_ELEMENT_TPGTLIST	"tpgt-list"
     93 #define	XML_ELEMENT_SIZE	"size"
     94 #define	XML_ELEMENT_LUN		"lun"
     95 #define	XML_ELEMENT_LUNLIST	"lun-list"
     96 #define	XML_ELEMENT_TYPE	"type"
     97 #define	XML_ELEMENT_ALIAS	"alias"
     98 #define	XML_ELEMENT_BACK	"backing-store"
     99 #define	XML_ELEMENT_DELETE_BACK	"delete-backing-store"
    100 #define	XML_ELEMENT_TARG	"target"
    101 #define	XML_ELEMENT_INIT	"initiator"
    102 #define	XML_ELEMENT_ZFS		"zfs"
    103 #define	XML_ELEMENT_ADMIN	"admin"
    104 #define	XML_ELEMENT_INAME	"iscsi-name"
    105 #define	XML_ELEMENT_MAXRECV	"maxrecv"
    106 #define	XML_ELEMENT_IPADDR	"ip-address"
    107 #define	XML_ELEMENT_IPADDRLIST	"ip-address-list"
    108 #define	XML_ELEMENT_ALL		"all"
    109 #define	XML_ELEMENT_VERBOSE	"verbose"
    110 #define	XML_ELEMENT_LIST	"list"
    111 #define	XML_ELEMENT_RESULT	"result"
    112 #define	XML_ELEMENT_TIMECON	"time-connected"
    113 #define	XML_ELEMENT_READCMDS	"read-commands"
    114 #define	XML_ELEMENT_WRITECMDS	"write-commands"
    115 #define	XML_ELEMENT_READBLKS	"read-blks"
    116 #define	XML_ELEMENT_WRITEBLKS	"write-blks"
    117 #define	XML_ELEMENT_STATS	"statistics"
    118 #define	XML_ELEMENT_CONN	"connection"
    119 #define	XML_ELEMENT_LUNINFO	"lun-information"
    120 #define	XML_ELEMENT_VID		"vid"
    121 #define	XML_ELEMENT_PID		"pid"
    122 #define	XML_ELEMENT_GUID	"guid"
    123 #define	XML_ELEMENT_DTYPE	"dtype"
    124 #define	XML_ELEMENT_IOSTAT	"iostat"
    125 #define	XML_ELEMENT_MACADDR	"mac-addr"
    126 #define	XML_ELEMENT_MGMTPORT	"mgmt-port"
    127 #define	XML_ELEMENT_ISCSIPORT	"iscsi-port"
    128 #define	XML_ELEMENT_TARGLOG	"target-log"
    129 #define	XML_ELEMENT_DBGLVL	"dbg-lvl"
    130 #define	XML_ELEMENT_LOGLVL	"qlog-lvl"
    131 #define	XML_ELEMENT_DBGDAEMON	"daemonize"
    132 #define	XML_ELEMENT_ENFORCE	"enforce-strict-guid"
    133 #define	XML_ELEMENT_VERS	"version"
    134 #define	XML_ELEMENT_MMAP_LUN	"mmap-lun"
    135 #define	XML_ELEMENT_RPM		"rpm"
    136 #define	XML_ELEMENT_HEADS	"heads"
    137 #define	XML_ELEMENT_CYLINDERS	"cylinders"
    138 #define	XML_ELEMENT_SPT		"spt"
    139 #define	XML_ELEMENT_BPS		"bps"
    140 #define	XML_ELEMENT_INTERLEAVE	"interleave"
    141 #define	XML_ELEMENT_PARAMS	"params"
    142 #define	XML_ELEMENT_MAXCMDS	"max-outstanding-cmds"
    143 #define	XML_ELEMENT_THIN_PROVO	"thin-provisioning"
    144 #define	XML_ELEMENT_DISABLE_TPGS	"disable-tpgs"
    145 #define	XML_ELEMENT_STATUS	"status"
    146 #define	XML_ELEMENT_PROGRESS	"progress"
    147 #define	XML_ELEMENT_TIMESTAMPS	"time-stamps"
    148 #define	XML_ELEMENT_INCORE	"in-core"
    149 #define	XML_ELEMENT_VALIDATE	"validate"
    150 #define	XML_ELEMENT_MORESPACE	"more-space-required"
    151 #define	XML_VALUE_TRUE		"true"
    152 #define	XML_ELEMENT_PGR_PERSIST	"PGR-persist"
    153 #define	XML_ELEMENT_PGR_BASEDIR	"PGR-basedir"
    154 
    155 typedef enum {
    156 	NodeFree,
    157 	NodeAlloc,
    158 	NodeName,
    159 	NodeValue
    160 } tgt_node_state;
    161 
    162 typedef enum { MatchName, MatchBoth } match_type_t;
    163 
    164 typedef struct tgt_node {
    165 	struct tgt_node	*x_parent,
    166 			*x_child,
    167 			*x_sibling,
    168 			*x_attr;
    169 	char		*x_name,
    170 			*x_value;
    171 	tgt_node_state	x_state;
    172 } tgt_node_t;
    173 
    174 typedef enum val_type { Tag_String, Tag_Start, Tag_End } val_type_t;
    175 typedef enum xml_val_type { String, Int, Uint64 } xml_val_type_t;
    176 
    177 tgt_node_t *tgt_door_call(char *str, int smf_flags);
    178 void tgt_dump2buf(tgt_node_t *t, char **buf);
    179 
    180 tgt_node_t *tgt_node_alloc(char *name, xml_val_type_t type, void *value);
    181 void tgt_node_free(tgt_node_t *x);
    182 void tgt_node_replace(tgt_node_t *parent, tgt_node_t *child, match_type_t m);
    183 Boolean_t tgt_node_remove(tgt_node_t *parent, tgt_node_t *child,
    184     match_type_t m);
    185 tgt_node_t *tgt_node_next(tgt_node_t *n, char *name, tgt_node_t *cur);
    186 tgt_node_t *tgt_node_next_child(tgt_node_t *n, char *name, tgt_node_t *cur);
    187 tgt_node_t *tgt_node_dup(tgt_node_t *n);
    188 tgt_node_t *tgt_node_find(tgt_node_t *n, char *name);
    189 void tgt_node_add(tgt_node_t *p, tgt_node_t *c);
    190 void tgt_node_add_attr(tgt_node_t *p, tgt_node_t *a);
    191 Boolean_t tgt_node_process(xmlTextReaderPtr r, tgt_node_t **node);
    192 
    193 void tgt_buf_add(char **b, char *element, const char *cdata);
    194 void tgt_buf_add_tag(char **b, const char *str, val_type_t type);
    195 void tgt_buf_add_tag_and_attr(char **b, char *str, char *attr);
    196 
    197 Boolean_t tgt_xml_encode(uint8_t *ip, size_t ip_size, char **buf,
    198     size_t *buf_size);
    199 Boolean_t tgt_xml_decode(char *buf, uint8_t **ip, size_t *ip_size);
    200 Boolean_t tgt_find_value_str(tgt_node_t *n, char *name, char **value);
    201 Boolean_t tgt_find_value_int(tgt_node_t *n, char *name, int *value);
    202 Boolean_t tgt_find_value_intchk(tgt_node_t *n, char *name, int *value);
    203 Boolean_t tgt_find_value_boolean(tgt_node_t *n, char *name, Boolean_t *value);
    204 Boolean_t tgt_find_attr_str(tgt_node_t *n, char *attr, char **value);
    205 Boolean_t tgt_update_value_str(tgt_node_t *node, char *name, char *str);
    206 
    207 #ifdef __cplusplus
    208 }
    209 #endif
    210 
    211 #endif /* _ISCSITGT_IMPL_H */
    212