1a6d42e7dSPeter Dunlap /*
2a6d42e7dSPeter Dunlap  * CDDL HEADER START
3a6d42e7dSPeter Dunlap  *
4a6d42e7dSPeter Dunlap  * The contents of this file are subject to the terms of the
5a6d42e7dSPeter Dunlap  * Common Development and Distribution License (the "License").
6a6d42e7dSPeter Dunlap  * You may not use this file except in compliance with the License.
7a6d42e7dSPeter Dunlap  *
8a6d42e7dSPeter Dunlap  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9a6d42e7dSPeter Dunlap  * or http://www.opensolaris.org/os/licensing.
10a6d42e7dSPeter Dunlap  * See the License for the specific language governing permissions
11a6d42e7dSPeter Dunlap  * and limitations under the License.
12a6d42e7dSPeter Dunlap  *
13a6d42e7dSPeter Dunlap  * When distributing Covered Code, include this CDDL HEADER in each
14a6d42e7dSPeter Dunlap  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15a6d42e7dSPeter Dunlap  * If applicable, add the following below this CDDL HEADER, with the
16a6d42e7dSPeter Dunlap  * fields enclosed by brackets "[]" replaced with your own identifying
17a6d42e7dSPeter Dunlap  * information: Portions Copyright [yyyy] [name of copyright owner]
18a6d42e7dSPeter Dunlap  *
19a6d42e7dSPeter Dunlap  * CDDL HEADER END
20a6d42e7dSPeter Dunlap  */
21a6d42e7dSPeter Dunlap /*
22836fc322SSam Cramer  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23a6d42e7dSPeter Dunlap  * Use is subject to license terms.
24a6d42e7dSPeter Dunlap  */
259fc69cd9SShampavman /*
26*61dfa509SRick McNeal  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
279fc69cd9SShampavman  */
28a6d42e7dSPeter Dunlap 
29a6d42e7dSPeter Dunlap #ifndef	_LIBISCSIT_H
30a6d42e7dSPeter Dunlap #define	_LIBISCSIT_H
31a6d42e7dSPeter Dunlap 
32a6d42e7dSPeter Dunlap #ifndef _KERNEL
33a6d42e7dSPeter Dunlap #include <libnvpair.h>
34a6d42e7dSPeter Dunlap #include <sys/socket.h>
35a6d42e7dSPeter Dunlap #endif
36a6d42e7dSPeter Dunlap 
37bf604c64SPeter Dunlap #include <sys/iscsit/iscsit_common.h>
38bf604c64SPeter Dunlap 
39a6d42e7dSPeter Dunlap #ifdef	__cplusplus
40a6d42e7dSPeter Dunlap extern "C" {
41a6d42e7dSPeter Dunlap #endif
42a6d42e7dSPeter Dunlap 
43*61dfa509SRick McNeal #define	MAX_TARGETS	4095 /* maximum targets that may be created */
44a6d42e7dSPeter Dunlap #define	MAX_TPGT	256
45a6d42e7dSPeter Dunlap #define	CFG_TPGTLIST	"tpgt-list"
46a6d42e7dSPeter Dunlap 
47fcc214c3SCharles Ting #define	IS_IQN_NAME(s) (strncmp((s), "iqn.", 4) == 0)
48fcc214c3SCharles Ting #define	IS_EUI_NAME(s) (strncmp((s), "eui.", 4) == 0)
49fcc214c3SCharles Ting 
509fc69cd9SShampavman /*
519fc69cd9SShampavman  * We change the default IQN here to org.illumos.
529fc69cd9SShampavman  * Other distros using it need to change accordingly.
539fc69cd9SShampavman  */
549fc69cd9SShampavman 
559fc69cd9SShampavman #define	DEFAULT_IQN	"iqn.2010-08.org.illumos:"
569fc69cd9SShampavman 
57a6d42e7dSPeter Dunlap /*
58a6d42e7dSPeter Dunlap  * Object Hierarchy
59a6d42e7dSPeter Dunlap  *
60a6d42e7dSPeter Dunlap  *  _______________________
61a6d42e7dSPeter Dunlap  * |                       |
62a6d42e7dSPeter Dunlap  * |  iSCSI Target Config  |
63a6d42e7dSPeter Dunlap  * |      it_config_t      |
64a6d42e7dSPeter Dunlap  * |_______________________|
65a6d42e7dSPeter Dunlap  *    |     |
66a6d42e7dSPeter Dunlap  *    |     |
67a6d42e7dSPeter Dunlap  *    |     |      ________     ________              ________
68a6d42e7dSPeter Dunlap  *    |     |     |        |   |        |            |        |
69a6d42e7dSPeter Dunlap  *    |     |     | Target |-->| Target |--  - -  -->| Target |
70a6d42e7dSPeter Dunlap  *    |     |     |________|   |________|            |________|
71a6d42e7dSPeter Dunlap  *    |     |           |
72a6d42e7dSPeter Dunlap  *    |     |           |
73a6d42e7dSPeter Dunlap  *    |     |           |
74a6d42e7dSPeter Dunlap  *    |     |           |       ______              ______
75a6d42e7dSPeter Dunlap  *    |     |           |      |      |            |      |
76a6d42e7dSPeter Dunlap  *    |     |           +----->| TPGT |--  - -  -->| TPGT |
77a6d42e7dSPeter Dunlap  *    |     |                  |______|            |______|
78a6d42e7dSPeter Dunlap  *    |     |                       |                   |
79a6d42e7dSPeter Dunlap  *    |  +--+                       |                   |
80a6d42e7dSPeter Dunlap  *    |  |   _______     _______    |         ______    |
81a6d42e7dSPeter Dunlap  *    |  |  |       |   |       |<--+        |      |<--+
82a6d42e7dSPeter Dunlap  *    |  +->|  TPG  |-->|  TPG  |--  - -  -->| TPG  |
83a6d42e7dSPeter Dunlap  *    |     |_______|   |_______|            |______|
84a6d42e7dSPeter Dunlap  *    |
85a6d42e7dSPeter Dunlap  *    |      ___________     ___________              ___________
86a6d42e7dSPeter Dunlap  *    |     |           |   |           |            |           |
87a6d42e7dSPeter Dunlap  *    +---->| Initiator |-->| Initiator |--  - -  -->| Initiator |
88a6d42e7dSPeter Dunlap  *          |  Context  |   |  Context  |            |  Context  |
89a6d42e7dSPeter Dunlap  *          |___________|   |___________|            |___________|
90a6d42e7dSPeter Dunlap  *
91a6d42e7dSPeter Dunlap  *
92a6d42e7dSPeter Dunlap  * it_config_t includes a list of global properties
93a6d42e7dSPeter Dunlap  *
94a6d42e7dSPeter Dunlap  * Targets include a list of properties which override the global properties
95a6d42e7dSPeter Dunlap  * if set
96a6d42e7dSPeter Dunlap  *
97a6d42e7dSPeter Dunlap  * Initiators also include a list of properties but never inherit properties
98a6d42e7dSPeter Dunlap  * from the global config.
99a6d42e7dSPeter Dunlap  */
100a6d42e7dSPeter Dunlap 
101a6d42e7dSPeter Dunlap /*
102a6d42e7dSPeter Dunlap  * Function:  it_config_load()
103a6d42e7dSPeter Dunlap  *
104a6d42e7dSPeter Dunlap  * Allocate and create an it_config_t structure representing the
105a6d42e7dSPeter Dunlap  * current iSCSI configuration.  This structure is compiled using
106a6d42e7dSPeter Dunlap  * the 'provider' data returned by stmfGetProviderData().  If there
107a6d42e7dSPeter Dunlap  * is no provider data associated with iscsit, the it_config_t
108a6d42e7dSPeter Dunlap  * structure will be set to a default configuration.
109a6d42e7dSPeter Dunlap  *
110a6d42e7dSPeter Dunlap  * Parameters:
111a6d42e7dSPeter Dunlap  *    cfg		A C representation of the current iSCSI configuration
112a6d42e7dSPeter Dunlap  *
113a6d42e7dSPeter Dunlap  * Return Values:
114a6d42e7dSPeter Dunlap  *    0			Success
115a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
116a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter
117a6d42e7dSPeter Dunlap  */
118a6d42e7dSPeter Dunlap int
119a6d42e7dSPeter Dunlap it_config_load(it_config_t **cfg);
120a6d42e7dSPeter Dunlap 
121a6d42e7dSPeter Dunlap /*
122a6d42e7dSPeter Dunlap  * Function:  it_config_commit()
123a6d42e7dSPeter Dunlap  *
124a6d42e7dSPeter Dunlap  * Informs the iscsit service that the configuration has changed and
125a6d42e7dSPeter Dunlap  * commits the new configuration to persistent store by calling
126a6d42e7dSPeter Dunlap  * stmfSetProviderData.  This function can be called multiple times
127a6d42e7dSPeter Dunlap  * during a configuration sequence if necessary.
128a6d42e7dSPeter Dunlap  *
129a6d42e7dSPeter Dunlap  * Parameters:
130a6d42e7dSPeter Dunlap  *    cfg		A C representation of the current iSCSI configuration
131a6d42e7dSPeter Dunlap  *
132a6d42e7dSPeter Dunlap  * Return Values:
133a6d42e7dSPeter Dunlap  *    0			Success
134a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
135a6d42e7dSPeter Dunlap  *    EINVAL		Invalid it_config_t structure
136a6d42e7dSPeter Dunlap  *    STMF_ERROR_SERVICE_DATA_VERSION	Configuration was updated by another
137a6d42e7dSPeter Dunlap  *			client.  See stmfSetProviderDataProt().
138a6d42e7dSPeter Dunlap  */
139a6d42e7dSPeter Dunlap int
140a6d42e7dSPeter Dunlap it_config_commit(it_config_t *cfg);
141a6d42e7dSPeter Dunlap 
142a6d42e7dSPeter Dunlap /*
143a6d42e7dSPeter Dunlap  * Function:  it_config_setprop()
144a6d42e7dSPeter Dunlap  *
145a6d42e7dSPeter Dunlap  * Validate the provided property list and set the global properties
146a6d42e7dSPeter Dunlap  * for iSCSI Target.  If errlist is not NULL, returns detailed
147a6d42e7dSPeter Dunlap  * errors for each property that failed.  The format for errorlist
148a6d42e7dSPeter Dunlap  * is key = property, value = error string.
149a6d42e7dSPeter Dunlap  *
150a6d42e7dSPeter Dunlap  * Parameters:
151a6d42e7dSPeter Dunlap  *
152a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
153a6d42e7dSPeter Dunlap  *			it_config_load()
154a6d42e7dSPeter Dunlap  *    proplist		nvlist_t containing properties for this target.
155a6d42e7dSPeter Dunlap  *    errlist		(optional)  nvlist_t of errors encountered when
156a6d42e7dSPeter Dunlap  *			validating the properties.
157a6d42e7dSPeter Dunlap  *
158a6d42e7dSPeter Dunlap  * Return Values:
159a6d42e7dSPeter Dunlap  *    0			Success
160a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
161a6d42e7dSPeter Dunlap  *    EINVAL		Invalid property
162a6d42e7dSPeter Dunlap  *
163a6d42e7dSPeter Dunlap  */
164a6d42e7dSPeter Dunlap int
165a6d42e7dSPeter Dunlap it_config_setprop(it_config_t *cfg, nvlist_t *proplist, nvlist_t **errlist);
166a6d42e7dSPeter Dunlap 
167a6d42e7dSPeter Dunlap /*
168a6d42e7dSPeter Dunlap  * Function:  it_config_free()
169a6d42e7dSPeter Dunlap  *
170a6d42e7dSPeter Dunlap  * Free any resources associated with the it_config_t structure.
171a6d42e7dSPeter Dunlap  *
172a6d42e7dSPeter Dunlap  * Parameters:
173a6d42e7dSPeter Dunlap  *    cfg		A C representation of the current iSCSI configuration
174a6d42e7dSPeter Dunlap  */
175a6d42e7dSPeter Dunlap void
176a6d42e7dSPeter Dunlap it_config_free(it_config_t *cfg);
177a6d42e7dSPeter Dunlap 
178a6d42e7dSPeter Dunlap /*
179a6d42e7dSPeter Dunlap  * Function:  it_tgt_create()
180a6d42e7dSPeter Dunlap  *
181a6d42e7dSPeter Dunlap  * Allocate and create an it_tgt_t structure representing a new iSCSI
182a6d42e7dSPeter Dunlap  * target node.  If tgt_name is NULL, then a unique target node name will
183a6d42e7dSPeter Dunlap  * be generated automatically.  Otherwise, the value of tgt_name will be
184a6d42e7dSPeter Dunlap  * used as the target node name.  The new it_tgt_t structure is added to
185a6d42e7dSPeter Dunlap  * the target list (cfg_tgt_list) in the configuration structure, and the
186a6d42e7dSPeter Dunlap  * new target will not be instantiated until the modified configuration
187a6d42e7dSPeter Dunlap  * is committed by calling it_config_commit().
188a6d42e7dSPeter Dunlap  *
189a6d42e7dSPeter Dunlap  * Parameters:
190a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
191a6d42e7dSPeter Dunlap  *			it_config_load()
192a6d42e7dSPeter Dunlap  *    tgt		Pointer to an iSCSI target structure
193a6d42e7dSPeter Dunlap  *    tgt_name		The target node name for the target to be created.
194a6d42e7dSPeter Dunlap  *			The name must be in either IQN or EUI format.  If
195a6d42e7dSPeter Dunlap  *			this value is NULL, a node name will be generated
196a6d42e7dSPeter Dunlap  *			automatically in IQN format.
197a6d42e7dSPeter Dunlap  *
198a6d42e7dSPeter Dunlap  * Return Values:
199a6d42e7dSPeter Dunlap  *    0			Success
200a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
201836fc322SSam Cramer  *    EINVAL		Invalid parameter or creating would create too many
202836fc322SSam Cramer  *			targets.
203a6d42e7dSPeter Dunlap  *    EEXIST		The requested target node name is already configured
204a6d42e7dSPeter Dunlap  *    EFAULT		Invalid iSCSI target name
205a6d42e7dSPeter Dunlap  */
206a6d42e7dSPeter Dunlap int
207a6d42e7dSPeter Dunlap it_tgt_create(it_config_t *cfg, it_tgt_t **tgt, char *tgt_name);
208a6d42e7dSPeter Dunlap 
209a6d42e7dSPeter Dunlap /*
210a6d42e7dSPeter Dunlap  * Function:  it_tgt_setprop()
211a6d42e7dSPeter Dunlap  *
212a6d42e7dSPeter Dunlap  * Validate the provided property list and set the properties for
213a6d42e7dSPeter Dunlap  * the specified target.  If errlist is not NULL, returns detailed
214a6d42e7dSPeter Dunlap  * errors for each property that failed.  The format for errorlist
215a6d42e7dSPeter Dunlap  * is key = property, value = error string.
216a6d42e7dSPeter Dunlap  *
217a6d42e7dSPeter Dunlap  * Parameters:
218a6d42e7dSPeter Dunlap  *
219a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
220a6d42e7dSPeter Dunlap  *			it_config_load()
221a6d42e7dSPeter Dunlap  *    tgt		Pointer to an iSCSI target structure
222a6d42e7dSPeter Dunlap  *    proplist		nvlist_t containing properties for this target.
223a6d42e7dSPeter Dunlap  *    errlist		(optional)  nvlist_t of errors encountered when
224a6d42e7dSPeter Dunlap  *			validating the properties.
225a6d42e7dSPeter Dunlap  *
226a6d42e7dSPeter Dunlap  * Return Values:
227a6d42e7dSPeter Dunlap  *    0			Success
228a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
229a6d42e7dSPeter Dunlap  *    EINVAL		Invalid property
230a6d42e7dSPeter Dunlap  *
231a6d42e7dSPeter Dunlap  */
232a6d42e7dSPeter Dunlap int
233a6d42e7dSPeter Dunlap it_tgt_setprop(it_config_t *cfg, it_tgt_t *tgt, nvlist_t *proplist,
234a6d42e7dSPeter Dunlap     nvlist_t **errlist);
235a6d42e7dSPeter Dunlap 
236a6d42e7dSPeter Dunlap 
237a6d42e7dSPeter Dunlap /*
238a6d42e7dSPeter Dunlap  * Function:  it_tgt_delete()
239a6d42e7dSPeter Dunlap  *
240a6d42e7dSPeter Dunlap  * Delete target represented by 'tgt', where 'tgt' is an existing
241a6d42e7dSPeter Dunlap  * it_tgt_t structure within the configuration 'cfg'.  The target removal
242a6d42e7dSPeter Dunlap  * will not take effect until the modified configuration is committed
243a6d42e7dSPeter Dunlap  * by calling it_config_commit().
244a6d42e7dSPeter Dunlap  *
245a6d42e7dSPeter Dunlap  * Parameters:
246a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
247a6d42e7dSPeter Dunlap  *			it_config_load()
248a6d42e7dSPeter Dunlap  *    tgt		Pointer to an iSCSI target structure
249a6d42e7dSPeter Dunlap  *    force		Set the target to offline before removing it from
250a6d42e7dSPeter Dunlap  *			the config.  If not specified, the operation will
251a6d42e7dSPeter Dunlap  *			fail if the target is determined to be online.
252a6d42e7dSPeter Dunlap  *
253a6d42e7dSPeter Dunlap  * Return Values:
254a6d42e7dSPeter Dunlap  *    0			Success
255a6d42e7dSPeter Dunlap  *    EBUSY		Target is online
256a6d42e7dSPeter Dunlap  */
257a6d42e7dSPeter Dunlap int
258a6d42e7dSPeter Dunlap it_tgt_delete(it_config_t *cfg, it_tgt_t *tgt, boolean_t force);
259a6d42e7dSPeter Dunlap 
260a6d42e7dSPeter Dunlap /*
261a6d42e7dSPeter Dunlap  * Function:  it_tpgt_create()
262a6d42e7dSPeter Dunlap  *
263a6d42e7dSPeter Dunlap  * Allocate and create an it_tpgt_t structure representing a new iSCSI
264a6d42e7dSPeter Dunlap  * target portal group tag.  The new it_tpgt_t structure is added to the
265a6d42e7dSPeter Dunlap  * target tpgt list (tgt_tpgt_list) in the it_tgt_t structure.  The new
266a6d42e7dSPeter Dunlap  * target portal group tag will not be instantiated until the modified
267a6d42e7dSPeter Dunlap  * configuration is committed by calling it_config_commit().
268a6d42e7dSPeter Dunlap  *
269a6d42e7dSPeter Dunlap  * Parameters:
270a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
271a6d42e7dSPeter Dunlap  *			it_config_load()
272a6d42e7dSPeter Dunlap  *    tgt		Pointer to the iSCSI target structure associated
273a6d42e7dSPeter Dunlap  *			with the target portal group tag
274a6d42e7dSPeter Dunlap  *    tpgt		Pointer to a target portal group tag structure
275a6d42e7dSPeter Dunlap  *    tpg_name		The name of the TPG to be associated with this TPGT
276a6d42e7dSPeter Dunlap  *    tpgt_tag		16-bit numerical identifier for this TPGT.  Valid
277a6d42e7dSPeter Dunlap  *			values are 2 through 65535.  If tpgt_tag is '0',
278a6d42e7dSPeter Dunlap  *			this function will assign an appropriate tag number.
279a6d42e7dSPeter Dunlap  *			If tpgt_tag is != 0, and the requested number is
280a6d42e7dSPeter Dunlap  *			unavailable, another value will be chosen.
281a6d42e7dSPeter Dunlap  *
282a6d42e7dSPeter Dunlap  * Return Values:
283a6d42e7dSPeter Dunlap  *    0			Success
284a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
285a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter
286a6d42e7dSPeter Dunlap  *    EEXIST		Specified TPG is already associated with the target
287a6d42e7dSPeter Dunlap  *    E2BIG		All tag numbers already in use
288a6d42e7dSPeter Dunlap  */
289a6d42e7dSPeter Dunlap int
290a6d42e7dSPeter Dunlap it_tpgt_create(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t **tpgt,
291a6d42e7dSPeter Dunlap     char *tpg_name, uint16_t tpgt_tag);
292a6d42e7dSPeter Dunlap 
293a6d42e7dSPeter Dunlap /*
294a6d42e7dSPeter Dunlap  * Function:  it_tpgt_delete()
295a6d42e7dSPeter Dunlap  *
296a6d42e7dSPeter Dunlap  * Delete the target portal group tag represented by 'tpgt', where
297a6d42e7dSPeter Dunlap  * 'tpgt' is an existing is_tpgt_t structure within the target 'tgt'.
298a6d42e7dSPeter Dunlap  * The target portal group tag removal will not take effect until the
299a6d42e7dSPeter Dunlap  * modified configuation is committed by calling it_config_commit().
300a6d42e7dSPeter Dunlap  *
301a6d42e7dSPeter Dunlap  * Parameters:
302a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
303a6d42e7dSPeter Dunlap  *			it_config_load()
304a6d42e7dSPeter Dunlap  *    tgt		Pointer to the iSCSI target structure associated
305a6d42e7dSPeter Dunlap  *			with the target portal group tag
306a6d42e7dSPeter Dunlap  *    tpgt		Pointer to a target portal group tag structure
307a6d42e7dSPeter Dunlap  */
308a6d42e7dSPeter Dunlap void
309a6d42e7dSPeter Dunlap it_tpgt_delete(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t *tpgt);
310a6d42e7dSPeter Dunlap 
311a6d42e7dSPeter Dunlap /*
312a6d42e7dSPeter Dunlap  * Function:  it_tpg_create()
313a6d42e7dSPeter Dunlap  *
314a6d42e7dSPeter Dunlap  * Allocate and create an it_tpg_t structure representing a new iSCSI
315a6d42e7dSPeter Dunlap  * target portal group.  The new it_tpg_t structure is added to the global
316a6d42e7dSPeter Dunlap  * tpg list (cfg_tgt_list) in the it_config_t structure.  The new target
317a6d42e7dSPeter Dunlap  * portal group will not be instantiated until the modified configuration
318a6d42e7dSPeter Dunlap  * is committed by calling it_config_commit().
319a6d42e7dSPeter Dunlap  *
320a6d42e7dSPeter Dunlap  * Parameters:
321a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
322a6d42e7dSPeter Dunlap  *			it_config_load()
323a6d42e7dSPeter Dunlap  *    tpg		Pointer to the it_tpg_t structure representing
324a6d42e7dSPeter Dunlap  *			the target portal group
325a6d42e7dSPeter Dunlap  *    tpg_name		Identifier for the target portal group
326a6d42e7dSPeter Dunlap  *    portal_ip_port	A string containing an appropriatedly formatted
327a6d42e7dSPeter Dunlap  *			IP address:port.  Both IPv4 and IPv6 addresses are
328a6d42e7dSPeter Dunlap  *			permitted.  This value becomes the first portal in
329a6d42e7dSPeter Dunlap  *			the TPG -- applications can add additional values
330a6d42e7dSPeter Dunlap  *			using it_portal_create() before committing the TPG.
331a6d42e7dSPeter Dunlap  * Return Values:
332a6d42e7dSPeter Dunlap  *    0			Success
333a6d42e7dSPeter Dunlap  *    ENOMEM		Cannot allocate resources
334a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter
335a6d42e7dSPeter Dunlap  *    EEXIST		Portal already configured for another portal group
336a6d42e7dSPeter Dunlap  *			associated with this target.
337a6d42e7dSPeter Dunlap  */
338a6d42e7dSPeter Dunlap int
339a6d42e7dSPeter Dunlap it_tpg_create(it_config_t *cfg, it_tpg_t **tpg, char *tpg_name,
340a6d42e7dSPeter Dunlap     char *portal_ip_port);
341a6d42e7dSPeter Dunlap 
342a6d42e7dSPeter Dunlap /*
343a6d42e7dSPeter Dunlap  * Function:  it_tpg_delete()
344a6d42e7dSPeter Dunlap  *
345a6d42e7dSPeter Dunlap  * Delete target portal group represented by 'tpg', where 'tpg' is an
346a6d42e7dSPeter Dunlap  * existing it_tpg_t structure within the global configuration 'cfg'.
347a6d42e7dSPeter Dunlap  * The target portal group removal will not take effect until the
348a6d42e7dSPeter Dunlap  * modified configuration is committed by calling it_config_commit().
349a6d42e7dSPeter Dunlap  *
350a6d42e7dSPeter Dunlap  * Parameters:
351a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configuration obtained from
352a6d42e7dSPeter Dunlap  *			it_config_load()
353a6d42e7dSPeter Dunlap  *    tpg		Pointer to the it_tpg_t structure representing
354a6d42e7dSPeter Dunlap  *			the target portal group
355a6d42e7dSPeter Dunlap  *    force		Remove this target portal group even if it's
356a6d42e7dSPeter Dunlap  *			associated with one or more targets.
357a6d42e7dSPeter Dunlap  *
358a6d42e7dSPeter Dunlap  * Return Values:
359a6d42e7dSPeter Dunlap  *    0			Success
360a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter
361a6d42e7dSPeter Dunlap  *    EBUSY		Portal group associated with one or more targets.
362a6d42e7dSPeter Dunlap  */
363a6d42e7dSPeter Dunlap int
364a6d42e7dSPeter Dunlap it_tpg_delete(it_config_t *cfg, it_tpg_t *tpg, boolean_t force);
365a6d42e7dSPeter Dunlap 
366a6d42e7dSPeter Dunlap /*
367a6d42e7dSPeter Dunlap  * Function:  it_portal_create()
368a6d42e7dSPeter Dunlap  *
369a6d42e7dSPeter Dunlap  * Add an it_portal_t structure representing a new portal to the specified
370a6d42e7dSPeter Dunlap  * target portal group.  The change to the target portal group will not take
371a6d42e7dSPeter Dunlap  * effect until the modified configuration is committed by calling
372a6d42e7dSPeter Dunlap  * it_config_commit().
373a6d42e7dSPeter Dunlap  *
374a6d42e7dSPeter Dunlap  * Parameters:
375a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configration obtained from
376a6d42e7dSPeter Dunlap  *			it_config_load()
377a6d42e7dSPeter Dunlap  *    tpg		Pointer to the it_tpg_t structure representing the
378a6d42e7dSPeter Dunlap  *			target portal group or "none" to remove
379a6d42e7dSPeter Dunlap  *    portal		Pointer to the it_portal_t structure representing
380a6d42e7dSPeter Dunlap  *			the portal
381a6d42e7dSPeter Dunlap  *    portal_ip_port	A string containing an appropriately formatted
382a6d42e7dSPeter Dunlap  *			IP address or IP address:port in either IPv4 or
383a6d42e7dSPeter Dunlap  *			IPv6 format.
384a6d42e7dSPeter Dunlap  * Return Values:
385a6d42e7dSPeter Dunlap  *    0			Success
386a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
387a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter
388a6d42e7dSPeter Dunlap  *    EEXIST		Portal already configured for another portal group
389a6d42e7dSPeter Dunlap  */
390a6d42e7dSPeter Dunlap int
391a6d42e7dSPeter Dunlap it_portal_create(it_config_t *cfg, it_tpg_t *tpg, it_portal_t **portal,
392a6d42e7dSPeter Dunlap     char *portal_ip_port);
393a6d42e7dSPeter Dunlap 
394a6d42e7dSPeter Dunlap /*
395a6d42e7dSPeter Dunlap  * Function:  it_portal_delete()
396a6d42e7dSPeter Dunlap  *
397a6d42e7dSPeter Dunlap  * Remove the specified portal from the specified target portal group.
398a6d42e7dSPeter Dunlap  * The portal removal will not take effect until the modified configuration
399a6d42e7dSPeter Dunlap  * is committed by calling it_config_commit().
400a6d42e7dSPeter Dunlap  *
401a6d42e7dSPeter Dunlap  * Parameters:
402a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configration obtained from
403a6d42e7dSPeter Dunlap  *			it_config_load()
404a6d42e7dSPeter Dunlap  *    tpg		Pointer to the it_tpg_t structure representing the
405a6d42e7dSPeter Dunlap  *			target portal group
406a6d42e7dSPeter Dunlap  *    portal		Pointer to the it_portal_t structure representing
407a6d42e7dSPeter Dunlap  *			the portal
408a6d42e7dSPeter Dunlap  */
409a6d42e7dSPeter Dunlap void
410a6d42e7dSPeter Dunlap it_portal_delete(it_config_t *cfg, it_tpg_t *tpg, it_portal_t *portal);
411a6d42e7dSPeter Dunlap 
412a6d42e7dSPeter Dunlap /*
413a6d42e7dSPeter Dunlap  * Function:  it_ini_create()
414a6d42e7dSPeter Dunlap  *
415a6d42e7dSPeter Dunlap  * Add an initiator context to the global configuration. The new
416a6d42e7dSPeter Dunlap  * initiator context will not be instantiated until the modified
417a6d42e7dSPeter Dunlap  * configuration is committed by calling it_config_commit().
418a6d42e7dSPeter Dunlap  *
419a6d42e7dSPeter Dunlap  * Parameters:
420a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configration obtained from
421a6d42e7dSPeter Dunlap  *			it_config_load()
422a6d42e7dSPeter Dunlap  *    ini		Pointer to the it_ini_t structure representing
423a6d42e7dSPeter Dunlap  *			the initiator context.
424a6d42e7dSPeter Dunlap  *    ini_node_name	The iSCSI node name of the remote initiator.
425a6d42e7dSPeter Dunlap  *
426a6d42e7dSPeter Dunlap  * Return Values:
427a6d42e7dSPeter Dunlap  *    0			Success
428a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
429a6d42e7dSPeter Dunlap  *    EINVAL		Invalid parameter.
430a6d42e7dSPeter Dunlap  *    EEXIST		Initiator already configured
431a6d42e7dSPeter Dunlap  *    EFAULT		Invalid initiator name
432a6d42e7dSPeter Dunlap  */
433a6d42e7dSPeter Dunlap int
434a6d42e7dSPeter Dunlap it_ini_create(it_config_t *cfg, it_ini_t **ini, char *ini_node_name);
435a6d42e7dSPeter Dunlap 
436a6d42e7dSPeter Dunlap /*
437a6d42e7dSPeter Dunlap  * Function:  it_ini_setprop()
438a6d42e7dSPeter Dunlap  *
439a6d42e7dSPeter Dunlap  * Validate the provided property list and set the initiator properties.
440a6d42e7dSPeter Dunlap  * If errlist is not NULL, returns detailed errors for each property
441a6d42e7dSPeter Dunlap  * that failed.  The format for errorlist is
442a6d42e7dSPeter Dunlap  *		 key = property, value = error string.
443a6d42e7dSPeter Dunlap  *
444a6d42e7dSPeter Dunlap  * Parameters:
445a6d42e7dSPeter Dunlap  *
446a6d42e7dSPeter Dunlap  *    ini		The initiator being updated.
447a6d42e7dSPeter Dunlap  *    proplist		nvlist_t containing properties for this target.
448a6d42e7dSPeter Dunlap  *    errlist		(optional)  nvlist_t of errors encountered when
449a6d42e7dSPeter Dunlap  *			validating the properties.
450a6d42e7dSPeter Dunlap  *
451a6d42e7dSPeter Dunlap  * Return Values:
452a6d42e7dSPeter Dunlap  *    0			Success
453a6d42e7dSPeter Dunlap  *    ENOMEM		Could not allocate resources
454a6d42e7dSPeter Dunlap  *    EINVAL		Invalid property
455a6d42e7dSPeter Dunlap  *
456a6d42e7dSPeter Dunlap  */
457a6d42e7dSPeter Dunlap int
458a6d42e7dSPeter Dunlap it_ini_setprop(it_ini_t *ini, nvlist_t *proplist, nvlist_t **errlist);
459a6d42e7dSPeter Dunlap 
460a6d42e7dSPeter Dunlap /*
461a6d42e7dSPeter Dunlap  * Function:  it_ini_delete()
462a6d42e7dSPeter Dunlap  *
463a6d42e7dSPeter Dunlap  * Remove the specified initiator context from the global configuration.
464a6d42e7dSPeter Dunlap  * The removal will not take effect until the modified configuration is
465a6d42e7dSPeter Dunlap  * committed by calling it_config_commit().
466a6d42e7dSPeter Dunlap  *
467a6d42e7dSPeter Dunlap  * Parameters:
468a6d42e7dSPeter Dunlap  *    cfg		The current iSCSI configration obtained from
469a6d42e7dSPeter Dunlap  *			it_config_load()
470a6d42e7dSPeter Dunlap  *    ini		Pointer to the it_ini_t structure representing
471a6d42e7dSPeter Dunlap  *			the initiator context.
472a6d42e7dSPeter Dunlap  */
473a6d42e7dSPeter Dunlap void
474a6d42e7dSPeter Dunlap it_ini_delete(it_config_t *cfg, it_ini_t *ini);
475a6d42e7dSPeter Dunlap 
476a6d42e7dSPeter Dunlap /*
477a6d42e7dSPeter Dunlap  * Function:  it_config_free()
478a6d42e7dSPeter Dunlap  *
479a6d42e7dSPeter Dunlap  * Free any resources associated with the it_config_t structure.
480a6d42e7dSPeter Dunlap  *
481a6d42e7dSPeter Dunlap  * Parameters:
482a6d42e7dSPeter Dunlap  *    cfg       A C representation of the current iSCSI configuration
483a6d42e7dSPeter Dunlap  */
484a6d42e7dSPeter Dunlap void
485a6d42e7dSPeter Dunlap it_config_free(it_config_t *cfg);
486a6d42e7dSPeter Dunlap 
487a6d42e7dSPeter Dunlap /*
488a6d42e7dSPeter Dunlap  * Function:  it_tgt_free()
489a6d42e7dSPeter Dunlap  *
490a6d42e7dSPeter Dunlap  * Frees an it_tgt_t structure.  If tgt_next is not NULL, frees
491a6d42e7dSPeter Dunlap  * all structures in the list.
492a6d42e7dSPeter Dunlap  */
493a6d42e7dSPeter Dunlap void
494a6d42e7dSPeter Dunlap it_tgt_free(it_tgt_t *tgt);
495a6d42e7dSPeter Dunlap 
496a6d42e7dSPeter Dunlap /*
497a6d42e7dSPeter Dunlap  * Function:  it_tpgt_free()
498a6d42e7dSPeter Dunlap  *
499a6d42e7dSPeter Dunlap  * Deallocates resources of an it_tpgt_t structure.  If tpgt->next
500a6d42e7dSPeter Dunlap  * is not NULL, frees all members of the list.
501a6d42e7dSPeter Dunlap  */
502a6d42e7dSPeter Dunlap void
503a6d42e7dSPeter Dunlap it_tpgt_free(it_tpgt_t *tpgt);
504a6d42e7dSPeter Dunlap 
505a6d42e7dSPeter Dunlap /*
506a6d42e7dSPeter Dunlap  * Function:  it_tpg_free()
507a6d42e7dSPeter Dunlap  *
508a6d42e7dSPeter Dunlap  * Deallocates resources associated with an it_tpg_t structure.
509a6d42e7dSPeter Dunlap  * If tpg->next is not NULL, frees all members of the list.
510a6d42e7dSPeter Dunlap  */
511a6d42e7dSPeter Dunlap void
512a6d42e7dSPeter Dunlap it_tpg_free(it_tpg_t *tpg);
513a6d42e7dSPeter Dunlap 
514a6d42e7dSPeter Dunlap /*
515a6d42e7dSPeter Dunlap  * Function:  it_ini_free()
516a6d42e7dSPeter Dunlap  *
517a6d42e7dSPeter Dunlap  * Deallocates resources of an it_ini_t structure. If ini->next is
518a6d42e7dSPeter Dunlap  * not NULL, frees all members of the list.
519a6d42e7dSPeter Dunlap  */
520a6d42e7dSPeter Dunlap void
521a6d42e7dSPeter Dunlap it_ini_free(it_ini_t *ini);
522a6d42e7dSPeter Dunlap 
523a6d42e7dSPeter Dunlap /*
524a6d42e7dSPeter Dunlap  * Function:  validate_iscsi_name()
525a6d42e7dSPeter Dunlap  *
526a6d42e7dSPeter Dunlap  * Ensures the passed-in string is a valid IQN or EUI iSCSI name
527a6d42e7dSPeter Dunlap  */
528a6d42e7dSPeter Dunlap boolean_t
529a6d42e7dSPeter Dunlap validate_iscsi_name(char *in_name);
530a6d42e7dSPeter Dunlap 
531fcc214c3SCharles Ting /*
532fcc214c3SCharles Ting  * Function:  canonical_iscsi_name()
533fcc214c3SCharles Ting  *
534fcc214c3SCharles Ting  * Fold the iqn iscsi name to lower-case and the EUI-64 identifier of
535fcc214c3SCharles Ting  * the eui iscsi name to upper-case.
536fcc214c3SCharles Ting  * Ensures the passed-in string is a valid IQN or EUI iSCSI name
537fcc214c3SCharles Ting  */
538fcc214c3SCharles Ting void
539fcc214c3SCharles Ting canonical_iscsi_name(char *tgt);
540fcc214c3SCharles Ting 
541a6d42e7dSPeter Dunlap #ifdef	__cplusplus
542a6d42e7dSPeter Dunlap }
543a6d42e7dSPeter Dunlap #endif
544a6d42e7dSPeter Dunlap 
545a6d42e7dSPeter Dunlap #endif	/* _LIBISCSIT_H */
546