2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _LIBISCSIT_H
2N/A#define _LIBISCSIT_H
2N/A
2N/A#ifndef _KERNEL
2N/A#include <libnvpair.h>
2N/A#include <sys/socket.h>
2N/A#endif
2N/A
2N/A#include <sys/iscsit/iscsit_common.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#define MAX_TARGETS 255 /* maximum targets that may be created */
2N/A#define MAX_TPGT 256
2N/A#define CFG_TPGTLIST "tpgt-list"
2N/A
2N/A#define IS_IQN_NAME(s) (strncmp((s), "iqn.", 4) == 0)
2N/A#define IS_EUI_NAME(s) (strncmp((s), "eui.", 4) == 0)
2N/A
2N/A/*
2N/A * Object Hierarchy
2N/A *
2N/A * _______________________
2N/A * | |
2N/A * | iSCSI Target Config |
2N/A * | it_config_t |
2N/A * |_______________________|
2N/A * | |
2N/A * | |
2N/A * | | ________ ________ ________
2N/A * | | | | | | | |
2N/A * | | | Target |-->| Target |-- - - -->| Target |
2N/A * | | |________| |________| |________|
2N/A * | | |
2N/A * | | |
2N/A * | | |
2N/A * | | | ______ ______
2N/A * | | | | | | |
2N/A * | | +----->| TPGT |-- - - -->| TPGT |
2N/A * | | |______| |______|
2N/A * | | | |
2N/A * | +--+ | |
2N/A * | | _______ _______ | ______ |
2N/A * | | | | | |<--+ | |<--+
2N/A * | +->| TPG |-->| TPG |-- - - -->| TPG |
2N/A * | |_______| |_______| |______|
2N/A * |
2N/A * | ___________ ___________ ___________
2N/A * | | | | | | |
2N/A * +---->| Initiator |-->| Initiator |-- - - -->| Initiator |
2N/A * | Context | | Context | | Context |
2N/A * |___________| |___________| |___________|
2N/A *
2N/A *
2N/A * it_config_t includes a list of global properties
2N/A *
2N/A * Targets include a list of properties which override the global properties
2N/A * if set
2N/A *
2N/A * Initiators also include a list of properties but never inherit properties
2N/A * from the global config.
2N/A */
2N/A
2N/A/*
2N/A * Function: it_config_load()
2N/A *
2N/A * Allocate and create an it_config_t structure representing the
2N/A * current iSCSI configuration. This structure is compiled using
2N/A * the 'provider' data returned by stmfGetProviderData(). If there
2N/A * is no provider data associated with iscsit, the it_config_t
2N/A * structure will be set to a default configuration.
2N/A *
2N/A * Parameters:
2N/A * cfg A C representation of the current iSCSI configuration
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid parameter
2N/A */
2N/Aint
2N/Ait_config_load(it_config_t **cfg);
2N/A
2N/A/*
2N/A * Function: it_config_commit()
2N/A *
2N/A * Informs the iscsit service that the configuration has changed and
2N/A * commits the new configuration to persistent store by calling
2N/A * stmfSetProviderData. This function can be called multiple times
2N/A * during a configuration sequence if necessary.
2N/A *
2N/A * Parameters:
2N/A * cfg A C representation of the current iSCSI configuration
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid it_config_t structure
2N/A * STMF_ERROR_SERVICE_DATA_VERSION Configuration was updated by another
2N/A * client. See stmfSetProviderDataProt().
2N/A */
2N/Aint
2N/Ait_config_commit(it_config_t *cfg);
2N/A
2N/A/*
2N/A * Function: it_config_setprop()
2N/A *
2N/A * Validate the provided property list and set the global properties
2N/A * for iSCSI Target. If errlist is not NULL, returns detailed
2N/A * errors for each property that failed. The format for errorlist
2N/A * is key = property, value = error string.
2N/A *
2N/A * Parameters:
2N/A *
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * proplist nvlist_t containing properties for this target.
2N/A * errlist (optional) nvlist_t of errors encountered when
2N/A * validating the properties.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid property
2N/A *
2N/A */
2N/Aint
2N/Ait_config_setprop(it_config_t *cfg, nvlist_t *proplist, nvlist_t **errlist);
2N/A
2N/A/*
2N/A * Function: it_config_free()
2N/A *
2N/A * Free any resources associated with the it_config_t structure.
2N/A *
2N/A * Parameters:
2N/A * cfg A C representation of the current iSCSI configuration
2N/A */
2N/Avoid
2N/Ait_config_free(it_config_t *cfg);
2N/A
2N/A/*
2N/A * Function: it_tgt_create()
2N/A *
2N/A * Allocate and create an it_tgt_t structure representing a new iSCSI
2N/A * target node. If tgt_name is NULL, then a unique target node name will
2N/A * be generated automatically. Otherwise, the value of tgt_name will be
2N/A * used as the target node name. The new it_tgt_t structure is added to
2N/A * the target list (cfg_tgt_list) in the configuration structure, and the
2N/A * new target will not be instantiated until the modified configuration
2N/A * is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tgt Pointer to an iSCSI target structure
2N/A * tgt_name The target node name for the target to be created.
2N/A * The name must be in either IQN or EUI format. If
2N/A * this value is NULL, a node name will be generated
2N/A * automatically in IQN format.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid parameter or creating would create too many
2N/A * targets.
2N/A * EEXIST The requested target node name is already configured
2N/A * EFAULT Invalid iSCSI target name
2N/A */
2N/Aint
2N/Ait_tgt_create(it_config_t *cfg, it_tgt_t **tgt, char *tgt_name);
2N/A
2N/A/*
2N/A * Function: it_tgt_setprop()
2N/A *
2N/A * Validate the provided property list and set the properties for
2N/A * the specified target. If errlist is not NULL, returns detailed
2N/A * errors for each property that failed. The format for errorlist
2N/A * is key = property, value = error string.
2N/A *
2N/A * Parameters:
2N/A *
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tgt Pointer to an iSCSI target structure
2N/A * proplist nvlist_t containing properties for this target.
2N/A * errlist (optional) nvlist_t of errors encountered when
2N/A * validating the properties.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid property
2N/A *
2N/A */
2N/Aint
2N/Ait_tgt_setprop(it_config_t *cfg, it_tgt_t *tgt, nvlist_t *proplist,
2N/A nvlist_t **errlist);
2N/A
2N/A
2N/A/*
2N/A * Function: it_tgt_delete()
2N/A *
2N/A * Delete target represented by 'tgt', where 'tgt' is an existing
2N/A * it_tgt_t structure within the configuration 'cfg'. The target removal
2N/A * will not take effect until the modified configuration is committed
2N/A * by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tgt Pointer to an iSCSI target structure
2N/A * force Set the target to offline before removing it from
2N/A * the config. If not specified, the operation will
2N/A * fail if the target is determined to be online.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * EBUSY Target is online
2N/A */
2N/Aint
2N/Ait_tgt_delete(it_config_t *cfg, it_tgt_t *tgt, boolean_t force);
2N/A
2N/A/*
2N/A * Function: it_tpgt_create()
2N/A *
2N/A * Allocate and create an it_tpgt_t structure representing a new iSCSI
2N/A * target portal group tag. The new it_tpgt_t structure is added to the
2N/A * target tpgt list (tgt_tpgt_list) in the it_tgt_t structure. The new
2N/A * target portal group tag will not be instantiated until the modified
2N/A * configuration is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tgt Pointer to the iSCSI target structure associated
2N/A * with the target portal group tag
2N/A * tpgt Pointer to a target portal group tag structure
2N/A * tpg_name The name of the TPG to be associated with this TPGT
2N/A * tpgt_tag 16-bit numerical identifier for this TPGT. Valid
2N/A * values are 2 through 65535. If tpgt_tag is '0',
2N/A * this function will assign an appropriate tag number.
2N/A * If tpgt_tag is != 0, and the requested number is
2N/A * unavailable, another value will be chosen.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid parameter
2N/A * EEXIST Specified TPG is already associated with the target
2N/A * E2BIG All tag numbers already in use
2N/A */
2N/Aint
2N/Ait_tpgt_create(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t **tpgt,
2N/A char *tpg_name, uint16_t tpgt_tag);
2N/A
2N/A/*
2N/A * Function: it_tpgt_delete()
2N/A *
2N/A * Delete the target portal group tag represented by 'tpgt', where
2N/A * 'tpgt' is an existing is_tpgt_t structure within the target 'tgt'.
2N/A * The target portal group tag removal will not take effect until the
2N/A * modified configuation is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tgt Pointer to the iSCSI target structure associated
2N/A * with the target portal group tag
2N/A * tpgt Pointer to a target portal group tag structure
2N/A */
2N/Avoid
2N/Ait_tpgt_delete(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t *tpgt);
2N/A
2N/A/*
2N/A * Function: it_tpg_create()
2N/A *
2N/A * Allocate and create an it_tpg_t structure representing a new iSCSI
2N/A * target portal group. The new it_tpg_t structure is added to the global
2N/A * tpg list (cfg_tgt_list) in the it_config_t structure. The new target
2N/A * portal group will not be instantiated until the modified configuration
2N/A * is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tpg Pointer to the it_tpg_t structure representing
2N/A * the target portal group
2N/A * tpg_name Identifier for the target portal group
2N/A * portal_ip_port A string containing an appropriatedly formatted
2N/A * IP address:port. Both IPv4 and IPv6 addresses are
2N/A * permitted. This value becomes the first portal in
2N/A * the TPG -- applications can add additional values
2N/A * using it_portal_create() before committing the TPG.
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Cannot allocate resources
2N/A * EINVAL Invalid parameter
2N/A * EEXIST Portal already configured for another portal group
2N/A * associated with this target.
2N/A */
2N/Aint
2N/Ait_tpg_create(it_config_t *cfg, it_tpg_t **tpg, char *tpg_name,
2N/A char *portal_ip_port);
2N/A
2N/A/*
2N/A * Function: it_tpg_delete()
2N/A *
2N/A * Delete target portal group represented by 'tpg', where 'tpg' is an
2N/A * existing it_tpg_t structure within the global configuration 'cfg'.
2N/A * The target portal group removal will not take effect until the
2N/A * modified configuration is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configuration obtained from
2N/A * it_config_load()
2N/A * tpg Pointer to the it_tpg_t structure representing
2N/A * the target portal group
2N/A * force Remove this target portal group even if it's
2N/A * associated with one or more targets.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * EINVAL Invalid parameter
2N/A * EBUSY Portal group associated with one or more targets.
2N/A */
2N/Aint
2N/Ait_tpg_delete(it_config_t *cfg, it_tpg_t *tpg, boolean_t force);
2N/A
2N/A/*
2N/A * Function: it_portal_create()
2N/A *
2N/A * Add an it_portal_t structure representing a new portal to the specified
2N/A * target portal group. The change to the target portal group will not take
2N/A * effect until the modified configuration is committed by calling
2N/A * it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configration obtained from
2N/A * it_config_load()
2N/A * tpg Pointer to the it_tpg_t structure representing the
2N/A * target portal group or "none" to remove
2N/A * portal Pointer to the it_portal_t structure representing
2N/A * the portal
2N/A * portal_ip_port A string containing an appropriately formatted
2N/A * IP address or IP address:port in either IPv4 or
2N/A * IPv6 format.
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid parameter
2N/A * EEXIST Portal already configured for another portal group
2N/A */
2N/Aint
2N/Ait_portal_create(it_config_t *cfg, it_tpg_t *tpg, it_portal_t **portal,
2N/A char *portal_ip_port);
2N/A
2N/A/*
2N/A * Function: it_portal_delete()
2N/A *
2N/A * Remove the specified portal from the specified target portal group.
2N/A * The portal removal will not take effect until the modified configuration
2N/A * is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configration obtained from
2N/A * it_config_load()
2N/A * tpg Pointer to the it_tpg_t structure representing the
2N/A * target portal group
2N/A * portal Pointer to the it_portal_t structure representing
2N/A * the portal
2N/A */
2N/Avoid
2N/Ait_portal_delete(it_config_t *cfg, it_tpg_t *tpg, it_portal_t *portal);
2N/A
2N/A/*
2N/A * Function: it_ini_create()
2N/A *
2N/A * Add an initiator context to the global configuration. The new
2N/A * initiator context will not be instantiated until the modified
2N/A * configuration is committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configration obtained from
2N/A * it_config_load()
2N/A * ini Pointer to the it_ini_t structure representing
2N/A * the initiator context.
2N/A * ini_node_name The iSCSI node name of the remote initiator.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid parameter.
2N/A * EEXIST Initiator already configured
2N/A * EFAULT Invalid initiator name
2N/A */
2N/Aint
2N/Ait_ini_create(it_config_t *cfg, it_ini_t **ini, char *ini_node_name);
2N/A
2N/A/*
2N/A * Function: it_ini_setprop()
2N/A *
2N/A * Validate the provided property list and set the initiator properties.
2N/A * If errlist is not NULL, returns detailed errors for each property
2N/A * that failed. The format for errorlist is
2N/A * key = property, value = error string.
2N/A *
2N/A * Parameters:
2N/A *
2N/A * ini The initiator being updated.
2N/A * proplist nvlist_t containing properties for this target.
2N/A * errlist (optional) nvlist_t of errors encountered when
2N/A * validating the properties.
2N/A *
2N/A * Return Values:
2N/A * 0 Success
2N/A * ENOMEM Could not allocate resources
2N/A * EINVAL Invalid property
2N/A *
2N/A */
2N/Aint
2N/Ait_ini_setprop(it_ini_t *ini, nvlist_t *proplist, nvlist_t **errlist);
2N/A
2N/A/*
2N/A * Function: it_ini_delete()
2N/A *
2N/A * Remove the specified initiator context from the global configuration.
2N/A * The removal will not take effect until the modified configuration is
2N/A * committed by calling it_config_commit().
2N/A *
2N/A * Parameters:
2N/A * cfg The current iSCSI configration obtained from
2N/A * it_config_load()
2N/A * ini Pointer to the it_ini_t structure representing
2N/A * the initiator context.
2N/A */
2N/Avoid
2N/Ait_ini_delete(it_config_t *cfg, it_ini_t *ini);
2N/A
2N/A/*
2N/A * Function: it_config_free()
2N/A *
2N/A * Free any resources associated with the it_config_t structure.
2N/A *
2N/A * Parameters:
2N/A * cfg A C representation of the current iSCSI configuration
2N/A */
2N/Avoid
2N/Ait_config_free(it_config_t *cfg);
2N/A
2N/A/*
2N/A * Function: it_tgt_free()
2N/A *
2N/A * Frees an it_tgt_t structure. If tgt_next is not NULL, frees
2N/A * all structures in the list.
2N/A */
2N/Avoid
2N/Ait_tgt_free(it_tgt_t *tgt);
2N/A
2N/A/*
2N/A * Function: it_tpgt_free()
2N/A *
2N/A * Deallocates resources of an it_tpgt_t structure. If tpgt->next
2N/A * is not NULL, frees all members of the list.
2N/A */
2N/Avoid
2N/Ait_tpgt_free(it_tpgt_t *tpgt);
2N/A
2N/A/*
2N/A * Function: it_tpg_free()
2N/A *
2N/A * Deallocates resources associated with an it_tpg_t structure.
2N/A * If tpg->next is not NULL, frees all members of the list.
2N/A */
2N/Avoid
2N/Ait_tpg_free(it_tpg_t *tpg);
2N/A
2N/A/*
2N/A * Function: it_ini_free()
2N/A *
2N/A * Deallocates resources of an it_ini_t structure. If ini->next is
2N/A * not NULL, frees all members of the list.
2N/A */
2N/Avoid
2N/Ait_ini_free(it_ini_t *ini);
2N/A
2N/A/*
2N/A * Function: validate_iscsi_name()
2N/A *
2N/A * Ensures the passed-in string is a valid IQN or EUI iSCSI name
2N/A */
2N/Aboolean_t
2N/Avalidate_iscsi_name(char *in_name);
2N/A
2N/A/*
2N/A * Function: canonical_iscsi_name()
2N/A *
2N/A * Fold the iqn iscsi name to lower-case and the EUI-64 identifier of
2N/A * the eui iscsi name to upper-case.
2N/A * Ensures the passed-in string is a valid IQN or EUI iSCSI name
2N/A */
2N/Avoid
2N/Acanonical_iscsi_name(char *tgt);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _LIBISCSIT_H */