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 (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <libscf.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <errno.h>
2N/A#include <assert.h>
2N/A#include <strings.h>
2N/A#include <libstmf.h>
2N/A#include <libstmf_impl.h>
2N/A#include <store.h>
2N/A#include <syslog.h>
2N/A#include <signal.h>
2N/A#include <pthread.h>
2N/A#include <libnvpair.h>
2N/A#include <limits.h>
2N/A#include <unistd.h>
2N/A
2N/A
2N/A/*
2N/A * This file's functions are responsible for all store and retrieve operations
2N/A * against the STMF smf(5) database. The following shows the currently defined
2N/A * schema for the STMF database:
2N/A *
2N/A * Description of property groups for service: svc:/system/stmf
2N/A *
2N/A * Stability: Volatile
2N/A *
2N/A * 1. Property Group: host_groups
2N/A * Properties: group_name-<N> where <N> is an unsigned integer
2N/A * type: ustring
2N/A * contains: group name
2N/A * group_name-<N>-member_list where <N> is an unsigned
2N/A * integer matching a group_name-<N> property.
2N/A * type: ustring
2N/A * contains: list of members
2N/A *
2N/A * Description:
2N/A * Contains the host group names as well as the host group members
2N/A * for each host group.
2N/A *
2N/A * 2. Property Group: target_groups
2N/A * Properties: group_name-<N> where <N> is an unsigned integer
2N/A * type: ustring
2N/A * contains: group name
2N/A * group_name-<N>-member_list where <N> is an unsigned
2N/A * integer matching a group_name-<N> property.
2N/A * type: ustring
2N/A * contains: list of members
2N/A *
2N/A * Description:
2N/A * Contains the target group names as well as the target group
2N/A * members for each target group.
2N/A *
2N/A * 3. Property Group: lu-<GUID>
2N/A * where <GUID> is a 32 character hexadecimal string.
2N/A * Properties: ve_cnt
2N/A * type: count
2N/A * contains: the number of current view entries
2N/A * view-entry-<N>-<GUID> where <N> is an unsigned integer
2N/A * type: ustring
2N/A * contains: nothing. Used as reference to the view
2N/A * entry property group
2N/A *
2N/A * Description:
2N/A * Contains the references to each view entry. One lu-<GUID>
2N/A * property group will exist for each logical unit with 1 or more
2N/A * view entries.
2N/A * Potentially can hold any other data that can be managed on a per
2N/A * logical unit basis.
2N/A *
2N/A * 4. Property Group: view_entry-<N>-<GUID> (matches property in lu-<GUID>
2N/A * property group)
2N/A * Properties: all_hosts
2N/A * type: boolean
2N/A * contains: when true, the value of host_group is
2N/A * ignored
2N/A * all_targets
2N/A * type: boolean
2N/A * contains: when true, the value of target_group is
2N/A * ignored
2N/A * host_group
2N/A * type: ustring
2N/A * contains: host group for logical unit mapping and
2N/A * masking purposes
2N/A * target_group
2N/A * type: ustring
2N/A * contains: target group for logical unit mapping and
2N/A * masking purposes
2N/A * lu_nbr
2N/A * type: opaque
2N/A * contains: the 8-byte SCSI logical unit number for
2N/A * mapping and masking purposes
2N/A * Description:
2N/A * One "view_entry-<N>-<GUID>" property group will exist for each
2N/A * view entry in the system. This property group name maps
2N/A * directly to the "lu-<GUID>" property group with a matching
2N/A * <GUID>.
2N/A *
2N/A * 5. Property Group: provider_data_pg_<provider-name>
2N/A * where <provider-name> is the name of the provider
2N/A * registered with stmf.
2N/A * Properties: provider_data_prop-<N>
2N/A * where <N> is a sequential identifier for the data
2N/A * chunk.
2N/A * type: opaque
2N/A * contains: up to STMF_PROVIDER_DATA_PROP_SIZE bytes
2N/A * of nvlist packed data.
2N/A * provider_data_count
2N/A * type: count
2N/A * contains: the number of provider data chunks
2N/A * provider_data_type
2N/A * type: integer
2N/A * contains: STMF_PORT_PROVIDER_TYPE or
2N/A * STMF_LU_PROVIDER_TYPE
2N/A *
2N/A * Description:
2N/A * Holds the nvlist packed provider data set via
2N/A * stmfSetProviderData and retrieved via stmfGetProviderData. Data
2N/A * is stored in STMF_PROVIDER_DATA_PROP_SIZE chunks. On retrieve,
2N/A * these chunks are reassembled and unpacked.
2N/A *
2N/A */
2N/A
2N/Astatic int iPsInit(scf_handle_t **, scf_service_t **);
2N/Astatic int iPsCreateDeleteGroup(char *, char *, int);
2N/Astatic int iPsAddRemoveGroupMember(char *, char *, char *, int);
2N/Astatic int iPsGetGroupList(char *, stmfGroupList **);
2N/Astatic int iPsGetGroupMemberList(char *, char *, stmfGroupProperties **);
2N/Astatic int iPsAddViewEntry(char *, char *, stmfViewEntry *);
2N/Astatic int iPsAddRemoveLuViewEntry(char *, char *, int);
2N/Astatic int iPsGetViewEntry(char *, stmfViewEntry *);
2N/Astatic int iPsGetActualGroupName(char *, char *, char *);
2N/Astatic int iPsGetServiceVersion(uint64_t *, scf_handle_t *, scf_service_t *);
2N/Astatic int iPsGetSetPersistType(uint8_t *, scf_handle_t *, scf_service_t *,
2N/A int);
2N/Astatic int iPsGetSetStmfProp(int, char *, int);
2N/Astatic int viewEntryCompare(const void *, const void *);
2N/Astatic int holdSignal(sigset_t *);
2N/Astatic int releaseSignal(sigset_t *);
2N/Astatic void sigHandler();
2N/A
2N/Astatic pthread_mutex_t sigSetLock = PTHREAD_MUTEX_INITIALIZER;
2N/A
2N/Asigset_t sigSet;
2N/Asigset_t signalsCaught;
2N/A
2N/Astruct sigaction currentActionQuit;
2N/Astruct sigaction currentActionTerm;
2N/Astruct sigaction currentActionInt;
2N/A
2N/Aboolean_t actionSet = B_FALSE;
2N/A
2N/A/*
2N/A * Version info for the SMF schema
2N/A */
2N/A#define STMF_SMF_VERSION 1
2N/A
2N/A/*
2N/A * Note: Do not change these property names and size values.
2N/A * They represent fields in the persistent config and once modified
2N/A * will have a nasty side effect of invalidating the existing store.
2N/A * If you do need to change them, you'll need to use the versioning above
2N/A * to retain backward compatiblity with the previous configuration schema.
2N/A */
2N/A
2N/A/* BEGIN STORE PROPERTY DEFINITIONS */
2N/A/*
2N/A * Property Group Names and prefixes
2N/A */
2N/A#define STMF_HOST_GROUPS "host_groups"
2N/A#define STMF_TARGET_GROUPS "target_groups"
2N/A#define STMF_VE_PREFIX "view_entry"
2N/A#define STMF_LU_PREFIX "lu"
2N/A#define STMF_DATA_GROUP "stmf_data"
2N/A
2N/A/*
2N/A * Property names and prefix for logical unit property group
2N/A */
2N/A#define STMF_VE_CNT "ve_cnt"
2N/A#define STMF_GROUP_PREFIX "group_name"
2N/A#define STMF_MEMBER_LIST_SUFFIX "member_list"
2N/A#define STMF_VERSION_NAME "version_name"
2N/A#define STMF_PERSIST_TYPE "persist_method"
2N/A
2N/A/* Property names for stmf properties */
2N/A
2N/A#define DEFAULT_LU_STATE "default_lu_state"
2N/A#define DEFAULT_TARGET_PORT_STATE "default_target_state"
2N/A
2N/A/*
2N/A * Property names for view entry
2N/A */
2N/A#define STMF_VE_ALLHOSTS "all_hosts"
2N/A#define STMF_VE_HOSTGROUP "host_group"
2N/A#define STMF_VE_ALLTARGETS "all_targets"
2N/A#define STMF_VE_TARGETGROUP "target_group"
2N/A#define STMF_VE_LUNBR "lu_nbr"
2N/A
2N/A/* Property group suffix for provider data */
2N/A#define STMF_PROVIDER_DATA_PREFIX "provider_data_pg_"
2N/A#define STMF_PROVIDER_DATA_PROP_PREFIX "provider_data_prop"
2N/A#define STMF_PROVIDER_DATA_PROP_NAME_SIZE 256
2N/A#define STMF_PROVIDER_DATA_PROP_TYPE "provider_type"
2N/A#define STMF_PROVIDER_DATA_PROP_SET_COUNT "provider_data_set_cnt"
2N/A#define STMF_PROVIDER_DATA_PROP_COUNT "provider_data_cnt"
2N/A
2N/A
2N/A#define STMF_SMF_READ_ATTR "solaris.smf.read.stmf"
2N/A
2N/A#define STMF_PS_PERSIST_NONE "none"
2N/A#define STMF_PS_PERSIST_SMF "smf"
2N/A#define STMF_PROVIDER_DATA_PROP_SIZE 4000
2N/A
2N/A#define STMF_PS_LU_ONLINE "default_lu_online"
2N/A#define STMF_PS_LU_OFFLINE "default_lu_offline"
2N/A#define STMF_PS_TARGET_PORT_ONLINE "default_target_online"
2N/A#define STMF_PS_TARGET_PORT_OFFLINE "default_target_offline"
2N/A
2N/A/* END STORE PROPERTY DEFINITIONS */
2N/A
2N/A/* service name */
2N/A#define STMF_SERVICE "system/stmf"
2N/A
2N/A/* limits and flag values */
2N/A#define GROUP_MEMBER_ALLOC 100
2N/A#define VIEW_ENTRY_STRUCT_CNT 6
2N/A#define VIEW_ENTRY_PG_SIZE 256
2N/A#define LOGICAL_UNIT_PG_SIZE 256
2N/A#define VIEW_ENTRY_MAX UINT32_MAX
2N/A#define GROUP_MAX UINT64_MAX
2N/A#define ADD 0
2N/A#define REMOVE 1
2N/A#define GET 0
2N/A#define SET 1
2N/A
2N/A/*
2N/A * sigHandler
2N/A *
2N/A * Catch the signal and set the global signalsCaught to the signal received
2N/A *
2N/A * signalsCaught will be used by releaseSignal to raise this signal when
2N/A * we're done processing our critical code.
2N/A *
2N/A */
2N/Astatic void
2N/AsigHandler(int sig)
2N/A{
2N/A (void) sigaddset(&signalsCaught, sig);
2N/A}
2N/A
2N/A/*
2N/A * iPsAddRemoveGroupMember
2N/A *
2N/A * Add or remove a member for a given group
2N/A *
2N/A * pgName - Property group name
2N/A * groupName - group name to which the member is added/removed
2N/A * memberName - member to be added/removed
2N/A * addRemoveFlag - ADD/REMOVE
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsAddRemoveGroupMember(char *pgName, char *groupName, char *memberName,
2N/Aint addRemoveFlag)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *valueLookup = NULL;
2N/A scf_value_t **valueSet = NULL;
2N/A scf_iter_t *valueIter = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry = NULL;
2N/A int i = 0;
2N/A int lastAlloc;
2N/A int valueArraySize = 0;
2N/A int ret = STMF_PS_SUCCESS;
2N/A char buf[STMF_IDENT_LENGTH];
2N/A int commitRet;
2N/A boolean_t found = B_FALSE;
2N/A
2N/A assert(pgName != NULL && groupName != NULL && memberName != NULL);
2N/A
2N/A /*
2N/A * Init the service handle
2N/A */
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((entry = scf_entry_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((valueIter = scf_iter_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the service property group handle
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * We're changing an existing property by adding a propval
2N/A * There are no add semantics in libscf for a property value. We'll
2N/A * need to read in the current properties and apply them all to the
2N/A * set and then add the one we were asked to add or omit the one
2N/A * we were asked to remove.
2N/A */
2N/A if (scf_transaction_property_change(tran, entry, groupName,
2N/A SCF_TYPE_USTRING) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_GROUP_NOT_FOUND;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A syslog(LOG_ERR, "tran property change %s/%s "
2N/A "failed - %s", pgName, groupName,
2N/A scf_strerror(scf_error()));
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the property handle
2N/A */
2N/A if (scf_pg_get_property(pg, groupName, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Value lookup is used to lookup the existing values
2N/A */
2N/A valueLookup = scf_value_create(handle);
2N/A if (valueLookup == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * valueIter is the iterator handle, create the resource
2N/A */
2N/A if (scf_iter_property_values(valueIter, prop) == -1) {
2N/A syslog(LOG_ERR, "iter values for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate value resource pointers.
2N/A * We need a value resource for each value as value pointers passed
2N/A * to libscf cannot be destroyed until the commit or destroy on the
2N/A * transaction is done.
2N/A *
2N/A * We're using GROUP_MEMBER_ALLOC initially. If it's not large
2N/A * enough, we'll realloc on the fly
2N/A */
2N/A valueSet = (scf_value_t **)calloc(1, sizeof (*valueSet)
2N/A * (lastAlloc = GROUP_MEMBER_ALLOC));
2N/A if (valueSet == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Iterate through the existing values
2N/A */
2N/A while (scf_iter_next_value(valueIter, valueLookup) == 1) {
2N/A bzero(buf, sizeof (buf));
2N/A if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) {
2N/A syslog(LOG_ERR, "iter %s/%s value failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Check for existing
2N/A * If we're adding, it's an error
2N/A * If we're removing, we skip it and simply not
2N/A * add it to the set. Subtraction by omission.
2N/A */
2N/A if ((strlen(buf) == strlen(memberName)) &&
2N/A bcmp(buf, memberName, strlen(buf)) == 0) {
2N/A if (addRemoveFlag == ADD) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A break;
2N/A } else {
2N/A found = B_TRUE;
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Create the value resource for this iteration
2N/A */
2N/A valueSet[i] = scf_value_create(handle);
2N/A if (valueSet[i] == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Set the value
2N/A */
2N/A if (scf_value_set_ustring(valueSet[i], buf) == -1) {
2N/A syslog(LOG_ERR, "set value for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Now add the value
2N/A */
2N/A if (scf_entry_add_value(entry, valueSet[i]) == -1) {
2N/A syslog(LOG_ERR, "add value for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /*
2N/A * realloc if we've hit the previous alloc size
2N/A */
2N/A if (i >= lastAlloc) {
2N/A lastAlloc += GROUP_MEMBER_ALLOC;
2N/A valueSet = realloc(valueSet,
2N/A sizeof (*valueSet) * lastAlloc);
2N/A if (valueSet == NULL) {
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * set valueArraySize to final allocated length
2N/A * so we can use it to destroy the resources correctly
2N/A */
2N/A valueArraySize = i;
2N/A
2N/A if (!found && (addRemoveFlag == REMOVE)) {
2N/A ret = STMF_PS_ERROR_MEMBER_NOT_FOUND;
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * If we're adding, we have one more step. Add the member to the
2N/A * propval list
2N/A */
2N/A if (addRemoveFlag == ADD) {
2N/A /*
2N/A * Now create the new entry
2N/A */
2N/A valueSet[i] = scf_value_create(handle);
2N/A if (valueSet[i] == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A } else {
2N/A valueArraySize++;
2N/A }
2N/A
2N/A /*
2N/A * Set the new member name
2N/A */
2N/A if (scf_value_set_ustring(valueSet[i], memberName) == -1) {
2N/A syslog(LOG_ERR, "set value for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add the new member
2N/A */
2N/A if (scf_entry_add_value(entry, valueSet[i]) == -1) {
2N/A syslog(LOG_ERR, "add value for %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Yes, we're finally done. We actually added or removed one entry
2N/A * from the list.
2N/A * Woohoo!
2N/A */
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (entry != NULL) {
2N/A scf_entry_destroy(entry);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (valueLookup != NULL) {
2N/A scf_value_destroy(valueLookup);
2N/A }
2N/A if (valueIter != NULL) {
2N/A scf_iter_destroy(valueIter);
2N/A }
2N/A
2N/A /*
2N/A * Free valueSet scf resources
2N/A */
2N/A if (valueArraySize > 0) {
2N/A for (i = 0; i < valueArraySize; i++) {
2N/A scf_value_destroy(valueSet[i]);
2N/A }
2N/A }
2N/A /*
2N/A * Now free the pointer array to the resources
2N/A */
2N/A if (valueSet != NULL) {
2N/A free(valueSet);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsAddRemoveLuViewEntry
2N/A *
2N/A * Adds or removes a view entry name property for a given logical unit
2N/A * property group. There is one logical unit property group for every logical
2N/A * unit that has one or more associated view entries.
2N/A *
2N/A * luPgName - Property group name of logical unit
2N/A * viewEntryPgName - Property group name of view entry
2N/A * addRemoveFlag - ADD_VE/REMOVE_VE
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsAddRemoveLuViewEntry(char *luPgName, char *viewEntryPgName,
2N/A int addRemoveFlag)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry = NULL;
2N/A scf_transaction_entry_t *entryVeName = NULL;
2N/A boolean_t createVeCnt = B_FALSE;
2N/A uint64_t veCnt = 0;
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A assert(luPgName != NULL || viewEntryPgName != NULL);
2N/A assert(!(addRemoveFlag != ADD && addRemoveFlag != REMOVE));
2N/A
2N/A /*
2N/A * Init the service handle
2N/A */
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((entry = scf_entry_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* get the LU property group */
2N/A if (scf_service_get_pg(svc, luPgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND &&
2N/A addRemoveFlag == ADD) {
2N/A /* if it doesn't exist, create it */
2N/A if (scf_service_add_pg(svc, luPgName,
2N/A SCF_GROUP_APPLICATION, 0, pg) == -1) {
2N/A syslog(LOG_ERR, "add pg %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A } else {
2N/A /* we need to create the VE_CNT property */
2N/A createVeCnt = B_TRUE;
2N/A ret = STMF_PS_SUCCESS;
2N/A }
2N/A } else if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get lu pg %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A
2N/A if (createVeCnt) {
2N/A /*
2N/A * Create the STMF_VE_CNT property. This will keep the current
2N/A * total view entries for this logical unit.
2N/A */
2N/A if (scf_transaction_property_new(tran, entry, STMF_VE_CNT,
2N/A SCF_TYPE_COUNT) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR,
2N/A "transaction property new %s/%s "
2N/A "failed - %s", luPgName, STMF_VE_CNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A } else {
2N/A /*
2N/A * The STMF_VE_CNT property already exists. Just update
2N/A * it.
2N/A */
2N/A if (scf_transaction_property_change(tran, entry,
2N/A STMF_VE_CNT, SCF_TYPE_COUNT) == -1) {
2N/A syslog(LOG_ERR, "transaction property %s/%s change "
2N/A "failed - %s", luPgName, STMF_VE_CNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_VE_CNT property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_VE_CNT, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_VE_CNT value
2N/A */
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s value failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A */
2N/A if (scf_value_get_count(value, &veCnt) == -1) {
2N/A syslog(LOG_ERR, "get count value %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Reset the value resource as it is used below
2N/A */
2N/A scf_value_reset(value);
2N/A }
2N/A
2N/A if (addRemoveFlag == ADD) {
2N/A veCnt++;
2N/A } else {
2N/A /* Check if this is the last one being removed */
2N/A if (veCnt == 1) {
2N/A /*
2N/A * Delete the pg and get out if this is the last
2N/A * view entry
2N/A */
2N/A if (scf_pg_delete(pg) == -1) {
2N/A syslog(LOG_ERR, "delete pg %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A } else {
2N/A veCnt--;
2N/A }
2N/A }
2N/A
2N/A
2N/A /*
2N/A * Set the view entry count
2N/A */
2N/A scf_value_set_count(value, veCnt);
2N/A
2N/A /*
2N/A * Add the value to the transaction entry
2N/A */
2N/A if (scf_entry_add_value(entry, value) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Create a transaction entry resource for the view entry name
2N/A */
2N/A entryVeName = scf_entry_create(handle);
2N/A if (entryVeName == NULL) {
2N/A syslog(LOG_ERR, "scf transaction entry alloc %s/%s failed - %s",
2N/A luPgName, viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (addRemoveFlag == ADD) {
2N/A /*
2N/A * If adding, create a property with the view entry name
2N/A */
2N/A if (scf_transaction_property_new(tran, entryVeName,
2N/A viewEntryPgName, SCF_TYPE_USTRING) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR,
2N/A "transaction property new %s/%s "
2N/A "failed - %s", luPgName, viewEntryPgName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A } else {
2N/A /*
2N/A * If removing, delete the existing property with the view
2N/A * entry name
2N/A */
2N/A if (scf_transaction_property_delete(tran, entryVeName,
2N/A viewEntryPgName) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR,
2N/A "transaction property delete %s/%s "
2N/A "failed - %s", luPgName, viewEntryPgName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Commit property transaction
2N/A */
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (entry != NULL) {
2N/A scf_entry_destroy(entry);
2N/A }
2N/A if (entryVeName != NULL) {
2N/A scf_entry_destroy(entryVeName);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsAddViewEntry
2N/A *
2N/A * Add a view entry property group and optionally, a logical unit property
2N/A * group if it does not exist.
2N/A *
2N/A * luName - ascii hexadecimal logical unit identifier
2N/A * viewEntryName - name of view entry (VIEW_ENTRY_nn)
2N/A * viewEntry - pointer to stmfViewEntry structure
2N/A */
2N/Astatic int
2N/AiPsAddViewEntry(char *luPgName, char *viewEntryPgName, stmfViewEntry *viewEntry)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_value_t *value[VIEW_ENTRY_STRUCT_CNT];
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry[VIEW_ENTRY_STRUCT_CNT];
2N/A int i = 0;
2N/A int j = 0;
2N/A int ret;
2N/A uint8_t scfBool;
2N/A boolean_t createdVePg = B_FALSE;
2N/A int backoutRet;
2N/A int commitRet;
2N/A
2N/A assert(luPgName != NULL || viewEntryPgName != NULL ||
2N/A viewEntry == NULL);
2N/A
2N/A bzero(value, sizeof (value));
2N/A bzero(entry, sizeof (entry));
2N/A
2N/A /*
2N/A * Init the service handle
2N/A */
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * allocate value and entry resources for scf
2N/A */
2N/A for (i = 0; i < VIEW_ENTRY_STRUCT_CNT; i++) {
2N/A if (((value[i] = scf_value_create(handle)) == NULL) ||
2N/A ((entry[i] = scf_entry_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A i = 0;
2N/A
2N/A /*
2N/A * Create the View Entry property group
2N/A */
2N/A if (scf_service_add_pg(svc, viewEntryPgName, SCF_GROUP_APPLICATION,
2N/A 0, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "add pg %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A createdVePg = B_TRUE;
2N/A
2N/A /*
2N/A * Add the view entry as properties on the view entry group
2N/A */
2N/A
2N/A /*
2N/A * Begin property update transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for add %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add allHosts property
2N/A */
2N/A if (scf_transaction_property_new(tran, entry[i],
2N/A STMF_VE_ALLHOSTS, SCF_TYPE_BOOLEAN) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", viewEntryPgName, STMF_VE_ALLHOSTS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /* Set the allHosts value */
2N/A scfBool = viewEntry->allHosts;
2N/A scf_value_set_boolean(value[i], scfBool);
2N/A
2N/A /*
2N/A * Add the allHosts value to the transaction
2N/A */
2N/A if (scf_entry_add_value(entry[i], value[i]) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLHOSTS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /*
2N/A * Create hostGroup property
2N/A */
2N/A if (scf_transaction_property_new(tran, entry[i],
2N/A STMF_VE_HOSTGROUP, SCF_TYPE_USTRING) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Set the value for hostGroup
2N/A */
2N/A if (scf_value_set_ustring(value[i], viewEntry->hostGroup) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add the hostGroup value to the transaction entry
2N/A */
2N/A if (scf_entry_add_value(entry[i], value[i]) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /*
2N/A * Create the allTargets property
2N/A */
2N/A if (scf_transaction_property_new(tran, entry[i],
2N/A STMF_VE_ALLTARGETS, SCF_TYPE_BOOLEAN) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", viewEntryPgName, STMF_VE_ALLTARGETS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Set the allTargets value
2N/A */
2N/A scfBool = viewEntry->allTargets;
2N/A scf_value_set_boolean(value[i], scfBool);
2N/A
2N/A /*
2N/A * Add the allTargets value to the transaction
2N/A */
2N/A if (scf_entry_add_value(entry[i], value[i]) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLTARGETS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /*
2N/A * Create targetGroup property
2N/A */
2N/A if (scf_transaction_property_new(tran, entry[i],
2N/A STMF_VE_TARGETGROUP, SCF_TYPE_USTRING) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", viewEntryPgName,
2N/A STMF_VE_TARGETGROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Set the value for targetGroup
2N/A */
2N/A if (scf_value_set_ustring(value[i], viewEntry->targetGroup) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_TARGETGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add targetGroup value to the transaction
2N/A */
2N/A if (scf_entry_add_value(entry[i], value[i]) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_TARGETGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /*
2N/A * Create the luNbr property
2N/A */
2N/A if (scf_transaction_property_new(tran, entry[i], STMF_VE_LUNBR,
2N/A SCF_TYPE_OPAQUE) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", viewEntryPgName, STMF_VE_LUNBR,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Set the luNbr
2N/A */
2N/A if (scf_value_set_opaque(value[i], (char *)viewEntry->luNbr,
2N/A sizeof (viewEntry->luNbr)) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_LUNBR, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add luNbr to the transaction entry
2N/A */
2N/A if (scf_entry_add_value(entry[i], value[i]) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_LUNBR, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now that we've successfully added the view entry,
2N/A * update the logical unit property group or create
2N/A * it if it does not exist
2N/A */
2N/A ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName, ADD);
2N/A
2N/A /*
2N/A * If we did not add the view entry name to the logical unit,
2N/A * make sure we do not commit the transaction
2N/A */
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Commit property transaction
2N/A */
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for add %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A /*
2N/A * If we did not commit, try to remove the view entry name
2N/A * from the logical unit.
2N/A * If that fails, we're now inconsistent.
2N/A */
2N/A backoutRet = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName,
2N/A REMOVE);
2N/A
2N/A if (backoutRet != STMF_PS_SUCCESS) {
2N/A syslog(LOG_ERR, "remove lu view entry %s failed"
2N/A "possible inconsistency - %s", luPgName,
2N/A scf_strerror(scf_error()));
2N/A }
2N/A /*
2N/A * We are still in an error scenario even though the remove
2N/A * lu view entry succeeded.
2N/A */
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A /* if there was an error, delete the created pg if one was created */
2N/A if ((ret != STMF_PS_SUCCESS) && createdVePg) {
2N/A if (scf_pg_delete(pg) == -1) {
2N/A syslog(LOG_ERR, "delete VE pg %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A }
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A /*
2N/A * Free value and entry scf resources
2N/A */
2N/A if (i > 0) {
2N/A for (j = 0; j < VIEW_ENTRY_STRUCT_CNT; j++) {
2N/A if (value[j] != NULL)
2N/A scf_value_destroy(value[j]);
2N/A if (entry[j] != NULL)
2N/A scf_entry_destroy(entry[j]);
2N/A }
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A/*
2N/A * psClearProviderData
2N/A *
2N/A * providerName - name of provider data to clear
2N/A */
2N/Aint
2N/ApsClearProviderData(char *providerName, int providerType)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A char pgName[MAXPATHLEN];
2N/A int ret = STMF_PS_SUCCESS;
2N/A boolean_t pgNotFound = B_FALSE;
2N/A
2N/A if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE &&
2N/A providerType != STMF_PORT_PROVIDER_TYPE)) {
2N/A ret = STMF_PS_ERROR_INVALID_ARG;
2N/A goto out;
2N/A }
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if ((pg = scf_pg_create(handle)) == NULL) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * create the property group name
2N/A */
2N/A (void) snprintf(pgName, sizeof (pgName), "%s%s",
2N/A STMF_PROVIDER_DATA_PREFIX, providerName);
2N/A
2N/A /*
2N/A * delete provider property group
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() != SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A } else {
2N/A pgNotFound = B_TRUE;
2N/A }
2N/A }
2N/A
2N/A if (!pgNotFound && (scf_pg_delete(pg) == -1)) {
2N/A syslog(LOG_ERR, "delete pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (pgNotFound) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsCreateDeleteGroup
2N/A *
2N/A * Creates or deletes a group (target or host)
2N/A *
2N/A * When creating a group, two properties are created. One to hold the group
2N/A * name and the other to hold the group members.
2N/A *
2N/A * pgName - Property group name
2N/A * groupName - group name to create
2N/A * addRemoveFlag - ADD_GROUP/REMOVE_GROUP
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsCreateDeleteGroup(char *pgRefName, char *groupName, int addRemoveFlag)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_iter_t *propIter = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry1 = NULL;
2N/A scf_transaction_entry_t *entry2 = NULL;
2N/A scf_value_t *value = NULL;
2N/A uint64_t groupIdx;
2N/A char buf1[MAXNAMELEN];
2N/A char buf2[MAXNAMELEN];
2N/A char tmpbuf[MAXNAMELEN];
2N/A boolean_t found = B_FALSE;
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A assert(groupName != NULL);
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((entry1 = scf_entry_create(handle)) == NULL) ||
2N/A ((entry2 = scf_entry_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((propIter = scf_iter_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the property group being modified
2N/A */
2N/A if (scf_service_get_pg(svc, pgRefName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND &&
2N/A addRemoveFlag == ADD) {
2N/A if (scf_service_add_pg(svc, pgRefName,
2N/A SCF_GROUP_APPLICATION, 0, pg) == -1) {
2N/A syslog(LOG_ERR, "add pg %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A } else if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * propIter is the iterator handle
2N/A */
2N/A if (scf_iter_pg_properties(propIter, pg) == -1) {
2N/A syslog(LOG_ERR, "iter properties for %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Iterate through the group names.
2N/A * If we find it in the list, it's an error when addRemoveFlag == ADD.
2N/A */
2N/A while (scf_iter_next_property(propIter, prop) == 1) {
2N/A if (scf_property_get_name(prop, buf1, sizeof (buf1)) == -1) {
2N/A syslog(LOG_ERR, "get name from %s iter failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Skip over member list properties
2N/A */
2N/A if (strstr(buf1, STMF_MEMBER_LIST_SUFFIX)) {
2N/A continue;
2N/A }
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgRefName, buf1, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A if (scf_value_get_ustring(value, tmpbuf,
2N/A sizeof (tmpbuf)) == -1) {
2N/A syslog(LOG_ERR, "get ustring %s/%s failed - %s",
2N/A pgRefName, buf1, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A if ((strlen(tmpbuf) == strlen(groupName)) &&
2N/A bcmp(tmpbuf, groupName, strlen(tmpbuf)) == 0) {
2N/A if (addRemoveFlag == ADD) {
2N/A ret = STMF_PS_ERROR_EXISTS;
2N/A }
2N/A found = B_TRUE;
2N/A /*
2N/A * buf1 contains the name for REMOVE
2N/A */
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A scf_value_reset(value);
2N/A
2N/A if (!found && addRemoveFlag == REMOVE) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * If we're adding, we need to create a new property name for the
2N/A * new group
2N/A */
2N/A if (addRemoveFlag == ADD) {
2N/A for (groupIdx = 0; groupIdx < GROUP_MAX; groupIdx++) {
2N/A if (snprintf(buf1, sizeof (buf1), "%s-%lld",
2N/A STMF_GROUP_PREFIX, groupIdx) > sizeof (buf1)) {
2N/A syslog(LOG_ERR,
2N/A "buffer overflow on property name %s",
2N/A buf1);
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A if (scf_pg_get_property(pg, buf1, prop) == -1) {
2N/A if (scf_error() != SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get property %s/%s "
2N/A "failed - %s", pgRefName, buf1,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A break;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Now create the new member list property for the new group
2N/A */
2N/A if (snprintf(buf2, sizeof (buf2), "%s-%s", buf1,
2N/A STMF_MEMBER_LIST_SUFFIX) > sizeof (buf2)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A buf1);
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * buf1 now contains the name of the property if it was found in the
2N/A * list in the case of delete or the next available property name
2N/A * in the case of create
2N/A *
2N/A * buf2 now contains the member list property name
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (addRemoveFlag == ADD) {
2N/A /*
2N/A * Create the property 'group name'
2N/A * This is the container for the group name
2N/A */
2N/A if (scf_transaction_property_new(tran, entry1, buf1,
2N/A SCF_TYPE_USTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", pgRefName, buf1,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if (scf_value_set_ustring(value, groupName) == -1) {
2N/A syslog(LOG_ERR, "set ustring %s/%s failed - %s",
2N/A pgRefName, buf1, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if (scf_entry_add_value(entry1, value) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A pgRefName, buf1, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /*
2N/A * Create the property 'group list'
2N/A * This is the container for the group members
2N/A */
2N/A if (scf_transaction_property_new(tran, entry2, buf2,
2N/A SCF_TYPE_USTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", pgRefName, buf2,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A /*
2N/A * Delete the property 'group name'
2N/A */
2N/A if (scf_transaction_property_delete(tran, entry1, buf1)
2N/A == -1) {
2N/A syslog(LOG_ERR,
2N/A "transaction property delete %s/%s failed - %s",
2N/A pgRefName, buf1, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /*
2N/A * Delete the property 'group list'
2N/A */
2N/A if (scf_transaction_property_delete(tran, entry2, buf2)
2N/A == -1) {
2N/A syslog(LOG_ERR, "transaction property delete %s/%s "
2N/A "failed - %s", pgRefName, buf2,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A pgRefName, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (entry1 != NULL) {
2N/A scf_entry_destroy(entry1);
2N/A }
2N/A if (entry2 != NULL) {
2N/A scf_entry_destroy(entry2);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (propIter != NULL) {
2N/A scf_iter_destroy(propIter);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsGetGroupList
2N/A *
2N/A * pgName - Property group name
2N/A * groupList - pointer to pointer to stmfGroupList structure. On success,
2N/A * contains the list of groups
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsGetGroupList(char *pgName, stmfGroupList **groupList)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_iter_t *propIter = NULL;
2N/A scf_value_t *value = NULL;
2N/A char buf[MAXNAMELEN];
2N/A int memberCnt = 0;
2N/A int i = 0;
2N/A int ret = STMF_PS_SUCCESS;
2N/A
2N/A assert(groupList != NULL);
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((propIter = scf_iter_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * propIter is the iterator handle
2N/A */
2N/A if (scf_iter_pg_properties(propIter, pg) == -1) {
2N/A syslog(LOG_ERR, "iter properties for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A while (scf_iter_next_property(propIter, prop) == 1) {
2N/A if (scf_property_get_name(prop, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get name from %s iter failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Skip over member list properties
2N/A */
2N/A if (strstr(buf, STMF_MEMBER_LIST_SUFFIX)) {
2N/A continue;
2N/A }
2N/A memberCnt++;
2N/A }
2N/A
2N/A /*
2N/A * propIter is the iterator handle
2N/A */
2N/A if (scf_iter_pg_properties(propIter, pg) == -1) {
2N/A syslog(LOG_ERR, "iter properties for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A *groupList = (stmfGroupList *)calloc(1, sizeof (stmfGroupList) +
2N/A memberCnt * sizeof (stmfGroupName));
2N/A
2N/A if (*groupList == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * In order to get a list of groups, simply get all of the
2N/A * properties that are not member list properties, i.e. the group
2N/A * name properties.
2N/A * It's possible for this list to grow beyond what was originally
2N/A * read so just ensure we're not writing beyond our allocated buffer
2N/A * by ensuring i < memberCnt
2N/A */
2N/A while ((scf_iter_next_property(propIter, prop) == 1) &&
2N/A (i < memberCnt)) {
2N/A if (scf_property_get_name(prop, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get name from %s iter failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Skip over member list properties
2N/A */
2N/A if (strstr(buf, STMF_MEMBER_LIST_SUFFIX)) {
2N/A continue;
2N/A }
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, buf, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A if (scf_value_get_ustring(value, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get ustring %s/%s failed - %s",
2N/A pgName, buf, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A bcopy(buf, (*groupList)->name[i++], strlen(buf));
2N/A (*groupList)->cnt++;
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A free(*groupList);
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (propIter != NULL) {
2N/A scf_iter_destroy(propIter);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsGetGroupMemberList
2N/A *
2N/A * pgName - Property group name
2N/A * groupName - group name (host group or target group)
2N/A * groupMemberList - pointer to pointer to stmfGroupProperties structure. On
2N/A * success, contains the list of group members
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsGetGroupMemberList(char *pgName, char *groupName,
2N/A stmfGroupProperties **groupMemberList)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *valueLookup = NULL;
2N/A scf_iter_t *valueIter = NULL;
2N/A int i = 0;
2N/A int memberCnt;
2N/A int len;
2N/A int ret = STMF_PS_SUCCESS;
2N/A char buf[MAXNAMELEN];
2N/A
2N/A assert(pgName != NULL && groupName != NULL);
2N/A
2N/A /*
2N/A * init the service handle
2N/A */
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((valueIter = scf_iter_create(handle)) == NULL) ||
2N/A ((valueLookup = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * get the service property group handle
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the property handle
2N/A * based on the target or host group name
2N/A */
2N/A if (scf_pg_get_property(pg, groupName, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * valueIter is the iterator handle
2N/A */
2N/A if (scf_iter_property_values(valueIter, prop) == -1) {
2N/A syslog(LOG_ERR, "iter value %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A while (scf_iter_next_value(valueIter, valueLookup) == 1) {
2N/A if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) {
2N/A syslog(LOG_ERR, "iter value %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A i++;
2N/A }
2N/A
2N/A /*
2N/A * valueIter is the iterator handle
2N/A */
2N/A if (scf_iter_property_values(valueIter, prop) == -1) {
2N/A syslog(LOG_ERR, "iter value %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A memberCnt = i;
2N/A
2N/A *groupMemberList = (stmfGroupProperties *)calloc(1,
2N/A sizeof (stmfGroupProperties) + memberCnt * sizeof (stmfDevid));
2N/A if (*groupMemberList == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A i = 0;
2N/A while ((scf_iter_next_value(valueIter, valueLookup) == 1) &&
2N/A (i < memberCnt)) {
2N/A if ((len = scf_value_get_ustring(valueLookup, buf, MAXNAMELEN))
2N/A == -1) {
2N/A syslog(LOG_ERR, "iter value %s/%s failed - %s",
2N/A pgName, groupName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A if (len < sizeof (stmfDevid) - 1) {
2N/A (*groupMemberList)->name[i].identLength = len;
2N/A bcopy(buf,
2N/A (*groupMemberList)->name[i++].ident, len);
2N/A (*groupMemberList)->cnt++;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A free(*groupMemberList);
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (valueLookup != NULL) {
2N/A scf_value_destroy(valueLookup);
2N/A }
2N/A if (valueIter != NULL) {
2N/A scf_iter_destroy(valueIter);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/ApsGetServicePersist(uint8_t *persistType)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A int ret;
2N/A
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A ret = iPsGetSetPersistType(persistType, handle, svc, GET);
2N/A
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/ApsSetServicePersist(uint8_t persistType)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A int ret;
2N/A
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A ret = iPsGetSetPersistType(&persistType, handle, svc, SET);
2N/A
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/Astatic int
2N/AiPsGetSetPersistType(uint8_t *persistType, scf_handle_t *handle,
2N/Ascf_service_t *svc, int getSet)
2N/A{
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry = NULL;
2N/A char iPersistTypeGet[MAXNAMELEN] = {0};
2N/A char *iPersistType;
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((entry = scf_entry_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (getSet == GET) {
2N/A /* set to default */
2N/A *persistType = STMF_PERSIST_SMF;
2N/A iPersistType = STMF_PS_PERSIST_SMF;
2N/A }
2N/A
2N/A if (getSet == SET) {
2N/A if (*persistType == STMF_PERSIST_SMF) {
2N/A iPersistType = STMF_PS_PERSIST_SMF;
2N/A } else if (*persistType == STMF_PERSIST_NONE) {
2N/A iPersistType = STMF_PS_PERSIST_NONE;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * get stmf data property group
2N/A */
2N/A if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A
2N/A goto out;
2N/A }
2N/A
2N/A /* find persistence property */
2N/A /*
2N/A * Get the persistence property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_PERSIST_TYPE, prop) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /* no persist property found */
2N/A if (ret == STMF_PS_ERROR_NOT_FOUND || getSet == SET) {
2N/A /*
2N/A * If we have no persistType property, go ahead
2N/A * and create it with the user specified value or
2N/A * the default value.
2N/A */
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* is this a SET or GET w/error? */
2N/A if (ret) {
2N/A if (scf_transaction_property_new(tran, entry,
2N/A STMF_PERSIST_TYPE, SCF_TYPE_ASTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property new "
2N/A "%s/%s failed - %s", STMF_DATA_GROUP,
2N/A STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A if (scf_transaction_property_change(tran, entry,
2N/A STMF_PERSIST_TYPE, SCF_TYPE_ASTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property change "
2N/A "%s/%s failed - %s", STMF_DATA_GROUP,
2N/A STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * set the persist type
2N/A */
2N/A if (scf_value_set_astring(value, iPersistType) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * add the value to the transaction
2N/A */
2N/A if (scf_entry_add_value(entry, value) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A /* reset return value */
2N/A ret = STMF_PS_SUCCESS;
2N/A } else if (getSet == GET) {
2N/A /* get the persist property */
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the value of the persist property
2N/A */
2N/A if (scf_value_get_astring(value, iPersistTypeGet, MAXNAMELEN)
2N/A == -1) {
2N/A syslog(LOG_ERR, "get string value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_PERSIST_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A if (getSet == GET) {
2N/A if (strcmp(iPersistTypeGet, STMF_PS_PERSIST_NONE) == 0) {
2N/A *persistType = STMF_PERSIST_NONE;
2N/A } else if (strcmp(iPersistTypeGet, STMF_PS_PERSIST_SMF) == 0) {
2N/A *persistType = STMF_PERSIST_SMF;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/Aout:
2N/A /*
2N/A * Free resources.
2N/A * handle and svc should not be free'd here. They're
2N/A * free'd elsewhere
2N/A */
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (entry != NULL) {
2N/A scf_entry_destroy(entry);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/ApsSetStmfProp(int propType, char *propVal)
2N/A{
2N/A return (iPsGetSetStmfProp(propType, propVal, SET));
2N/A}
2N/A
2N/Aint
2N/ApsGetStmfProp(int propType, char *propVal)
2N/A{
2N/A return (iPsGetSetStmfProp(propType, propVal, GET));
2N/A}
2N/A
2N/Astatic int
2N/AiPsGetSetStmfProp(int propType, char *propVal, int getSet)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry = NULL;
2N/A scf_value_t *value = NULL;
2N/A char *psStmfPropVal;
2N/A char *psStmfProp;
2N/A char stmfPropGet[MAXNAMELEN] = {0};
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A if (propVal == NULL || (getSet != GET && getSet != SET)) {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Init the service handle
2N/A */
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((entry = scf_entry_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if (getSet == GET) {
2N/A switch (propType) {
2N/A case STMF_DEFAULT_LU_STATE :
2N/A psStmfProp = DEFAULT_LU_STATE;
2N/A psStmfPropVal = STMF_PS_LU_ONLINE;
2N/A (void) strcpy(stmfPropGet, psStmfPropVal);
2N/A break;
2N/A case STMF_DEFAULT_TARGET_PORT_STATE :
2N/A psStmfProp = DEFAULT_TARGET_PORT_STATE;
2N/A psStmfPropVal = STMF_PS_TARGET_PORT_ONLINE;
2N/A (void) strcpy(stmfPropGet, psStmfPropVal);
2N/A break;
2N/A default :
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A /* NOTREACHED */
2N/A break;
2N/A }
2N/A }
2N/A if (getSet == SET) {
2N/A switch (propType) {
2N/A case STMF_DEFAULT_LU_STATE :
2N/A psStmfProp = DEFAULT_LU_STATE;
2N/A if (strcasecmp(propVal, "online") == 0) {
2N/A psStmfPropVal = STMF_PS_LU_ONLINE;
2N/A } else if (strcasecmp(propVal, "offline")
2N/A == 0) {
2N/A psStmfPropVal = STMF_PS_LU_OFFLINE;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A break;
2N/A case STMF_DEFAULT_TARGET_PORT_STATE :
2N/A psStmfProp = DEFAULT_TARGET_PORT_STATE;
2N/A if (strcasecmp(propVal, "online") == 0) {
2N/A psStmfPropVal =
2N/A STMF_PS_TARGET_PORT_ONLINE;
2N/A } else if (strcasecmp(propVal, "offline")
2N/A == 0) {
2N/A psStmfPropVal =
2N/A STMF_PS_TARGET_PORT_OFFLINE;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A break;
2N/A default :
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A /* NOTREACHED */
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * get stmf data property group
2N/A */
2N/A
2N/A if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * get the stmf props property, if exists
2N/A */
2N/A
2N/A if (scf_pg_get_property(pg, psStmfProp, prop) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "start transaction for %s/%s "
2N/A "failed - %s", STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /* if stmf prop is not found or while setting the prop */
2N/A
2N/A if (ret == STMF_PS_ERROR_NOT_FOUND || getSet == SET) {
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if (ret) {
2N/A if (scf_transaction_property_new(tran, entry,
2N/A psStmfProp, SCF_TYPE_ASTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property new "
2N/A "%s/%s failed - %s", STMF_DATA_GROUP,
2N/A psStmfProp, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A if (scf_transaction_property_change(tran, entry,
2N/A psStmfProp, SCF_TYPE_ASTRING) == -1) {
2N/A syslog(LOG_ERR,
2N/A "transaction property change "
2N/A "%s/%s failed - %s",
2N/A STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * set stmf prop value
2N/A */
2N/A
2N/A if (scf_value_set_astring(value, psStmfPropVal) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * add the value to the transaction
2N/A */
2N/A
2N/A if (scf_entry_add_value(entry, value) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s"
2N/A "failed - %s", STMF_DATA_GROUP,
2N/A scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A ret = STMF_PS_SUCCESS;
2N/A } else if (getSet == GET) {
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value "
2N/A "%s/%s failed - %s",
2N/A STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* get stmfProp */
2N/A
2N/A if (scf_value_get_astring(value, stmfPropGet, MAXNAMELEN)
2N/A == -1) {
2N/A syslog(LOG_ERR, "get string value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, psStmfProp,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A if (getSet == GET) {
2N/A if (strcmp(stmfPropGet, STMF_PS_LU_ONLINE) == 0) {
2N/A (void) strcpy(propVal, "online");
2N/A } else if (strcmp(stmfPropGet, STMF_PS_LU_OFFLINE) == 0) {
2N/A (void) strcpy(propVal, "offline");
2N/A } else if (strcmp(stmfPropGet, STMF_PS_TARGET_PORT_ONLINE)
2N/A == 0) {
2N/A (void) strcpy(propVal, "online");
2N/A } else if (strcmp(stmfPropGet, STMF_PS_TARGET_PORT_OFFLINE)
2N/A == 0) {
2N/A (void) strcpy(propVal, "offline");
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/Aout:
2N/A /*
2N/A * Free resources.
2N/A */
2N/A
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (entry != NULL) {
2N/A scf_entry_destroy(entry);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * Initialize scf stmf service access
2N/A * handle - returned handle
2N/A * service - returned service handle
2N/A *
2N/A * Both handle and service must be destroyed by the caller
2N/A */
2N/Astatic int
2N/AiPsInit(scf_handle_t **handle, scf_service_t **service)
2N/A{
2N/A scf_scope_t *scope = NULL;
2N/A uint64_t version;
2N/A int ret;
2N/A
2N/A assert(handle != NULL && service != NULL);
2N/A
2N/A if ((*handle = scf_handle_create(SCF_VERSION)) == NULL) {
2N/A syslog(LOG_ERR, "scf_handle_create failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto err;
2N/A }
2N/A
2N/A if (scf_handle_bind(*handle) == -1) {
2N/A syslog(LOG_ERR, "scf_handle_bind failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto err;
2N/A }
2N/A
2N/A if ((*service = scf_service_create(*handle)) == NULL) {
2N/A syslog(LOG_ERR, "scf_service_create failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto err;
2N/A }
2N/A
2N/A if ((scope = scf_scope_create(*handle)) == NULL) {
2N/A syslog(LOG_ERR, "scf_scope_create failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto err;
2N/A }
2N/A
2N/A if (scf_handle_get_scope(*handle, SCF_SCOPE_LOCAL, scope) == -1) {
2N/A syslog(LOG_ERR, "scf_handle_get_scope failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto err;
2N/A }
2N/A
2N/A if (scf_scope_get_service(scope, STMF_SERVICE, *service) == -1) {
2N/A syslog(LOG_ERR, "scf_scope_get_service failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR_SERVICE_NOT_FOUND;
2N/A goto err;
2N/A }
2N/A
2N/A
2N/A /*
2N/A * Get and check the version number
2N/A */
2N/A ret = iPsGetServiceVersion(&version, *handle, *service);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto err;
2N/A }
2N/A
2N/A if (version != STMF_SMF_VERSION) {
2N/A ret = STMF_PS_ERROR_VERSION_MISMATCH;
2N/A goto err;
2N/A }
2N/A
2N/A /* we only need destroy the scope here */
2N/A scf_scope_destroy(scope);
2N/A
2N/A return (STMF_PS_SUCCESS);
2N/A
2N/Aerr:
2N/A if (*handle != NULL) {
2N/A scf_handle_destroy(*handle);
2N/A }
2N/A if (*service != NULL) {
2N/A scf_service_destroy(*service);
2N/A *service = NULL;
2N/A }
2N/A if (scope != NULL) {
2N/A scf_scope_destroy(scope);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * called by iPsInit only
2N/A * iPsGetServiceVersion
2N/A */
2N/Astatic int
2N/AiPsGetServiceVersion(uint64_t *version, scf_handle_t *handle,
2N/Ascf_service_t *svc)
2N/A{
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A scf_transaction_entry_t *entry = NULL;
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((entry = scf_entry_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A *version = STMF_SMF_VERSION;
2N/A
2N/A /*
2N/A * get stmf data property group
2N/A */
2N/A if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /* create the group */
2N/A if (ret == STMF_PS_ERROR_NOT_FOUND) {
2N/A /*
2N/A * create the property group.
2N/A */
2N/A if (scf_service_add_pg(svc, STMF_DATA_GROUP,
2N/A SCF_GROUP_APPLICATION, 0, pg) == -1) {
2N/A syslog(LOG_ERR, "add pg %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /* reset return value */
2N/A ret = STMF_PS_SUCCESS;
2N/A }
2N/A
2N/A /* find version property */
2N/A /*
2N/A * Get the version property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_VERSION_NAME, prop) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /* no version property found */
2N/A if (ret == STMF_PS_ERROR_NOT_FOUND) {
2N/A /*
2N/A * If we have no version property, go ahead
2N/A * and create it. We're obviously making an assumption
2N/A * here that someone did not delete the existing property
2N/A * and that this is the initial set and the initial call
2N/A * to iPsInit.
2N/A * If they did delete it, this will simply plant this
2N/A * library's version on this service. That may or may not be
2N/A * correct and we have no way of determining that.
2N/A */
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_transaction_property_new(tran, entry,
2N/A STMF_VERSION_NAME, SCF_TYPE_COUNT) == -1) {
2N/A syslog(LOG_ERR,
2N/A "transaction property new %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * set the version number
2N/A */
2N/A scf_value_set_count(value, *version);
2N/A
2N/A /*
2N/A * add the value to the transaction
2N/A */
2N/A if (scf_entry_add_value(entry, value) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A STMF_DATA_GROUP, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A /* reset return value */
2N/A ret = STMF_PS_SUCCESS;
2N/A } else {
2N/A /* get the version property */
2N/A if (scf_pg_get_property(pg, STMF_VERSION_NAME, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the actual value of the view entry count property
2N/A */
2N/A if (scf_value_get_count(value, version) == -1) {
2N/A syslog(LOG_ERR, "get count value %s/%s failed - %s",
2N/A STMF_DATA_GROUP, STMF_VERSION_NAME,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources.
2N/A * handle and svc should not be free'd here. They're
2N/A * free'd elsewhere
2N/A */
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (entry != NULL) {
2N/A scf_entry_destroy(entry);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/A
2N/A
2N/A/*
2N/A * iPsGetActualGroupName
2N/A *
2N/A * pgName - Property group name
2N/A * groupName - requested group name
2N/A * actualName - actual group name to reference (len must be >= MAXNAMELEN)
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsGetActualGroupName(char *pgName, char *groupName, char *actualName)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_iter_t *propIter = NULL;
2N/A scf_value_t *value = NULL;
2N/A char buf[MAXNAMELEN];
2N/A int ret;
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((propIter = scf_iter_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * get group list property group
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_GROUP_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * propIter is the iterator handle
2N/A */
2N/A if (scf_iter_pg_properties(propIter, pg) == -1) {
2N/A syslog(LOG_ERR, "iter properties for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Iterate through group properties searching for the requested
2N/A * group name. When we find it, we need to get the property name
2N/A * since it refers to the actual group name.
2N/A */
2N/A
2N/A /* initialize to not found */
2N/A ret = STMF_PS_ERROR_GROUP_NOT_FOUND;
2N/A while (scf_iter_next_property(propIter, prop) == 1) {
2N/A if (scf_property_get_name(prop, actualName, MAXNAMELEN) == -1) {
2N/A syslog(LOG_ERR, "get name from %s iter failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Skip over non-member list properties
2N/A */
2N/A if (strstr(actualName, STMF_MEMBER_LIST_SUFFIX)) {
2N/A continue;
2N/A }
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, actualName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A if (scf_value_get_ustring(value, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get ustring %s/%s failed - %s",
2N/A pgName, actualName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * When we find a match, set success and break
2N/A */
2N/A if ((strlen(buf) == strlen(groupName)) &&
2N/A bcmp(buf, groupName, strlen(buf)) == 0) {
2N/A ret = STMF_PS_SUCCESS;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * if we didn't find it, ret is set to STMF_PS_ERROR_GROUP_NOT_FOUND
2N/A */
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (propIter != NULL) {
2N/A scf_iter_destroy(propIter);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psAddHostGroupMember
2N/A *
2N/A * Add a host group member to a host group,
2N/A *
2N/A * Input: groupName - name of group to which the member is added
2N/A * memberName - name of group member to add
2N/A */
2N/Aint
2N/ApsAddHostGroupMember(char *groupName, char *memberName)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsAddRemoveGroupMember(STMF_HOST_GROUPS, groupPropListName,
2N/A memberName, ADD));
2N/A}
2N/A
2N/A/*
2N/A * psAddTargetGroupMember
2N/A *
2N/A * Add a target port group member to a target group
2N/A *
2N/A * Input: groupName - name of group to which the member is added
2N/A * memberName - name of group member to add. Must be nul terminated.
2N/A */
2N/Aint
2N/ApsAddTargetGroupMember(char *groupName, char *memberName)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsAddRemoveGroupMember(STMF_TARGET_GROUPS, groupPropListName,
2N/A memberName, ADD));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * psAddViewEntry
2N/A *
2N/A * luGuid - logical unit identifier
2N/A * viewEntry - pointer to viewEntry allocated by the caller that contains
2N/A * the values to set for this view entry
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */
2N/A char viewEntryPgName[VIEW_ENTRY_PG_SIZE];
2N/A char scfLuPgName[LOGICAL_UNIT_PG_SIZE];
2N/A int ret = STMF_PS_SUCCESS;
2N/A sigset_t sigmaskRestore;
2N/A
2N/A /* grab the signal hold lock */
2N/A (void) pthread_mutex_lock(&sigSetLock);
2N/A
2N/A /*
2N/A * hold signals until we're done
2N/A */
2N/A if (holdSignal(&sigmaskRestore) != 0) {
2N/A (void) pthread_mutex_unlock(&sigSetLock);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A pg = scf_pg_create(handle);
2N/A if (pg == NULL) {
2N/A syslog(LOG_ERR, "scf pg alloc failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Convert to ASCII uppercase hexadecimal string */
2N/A (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
2N/A "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
2N/A lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4],
2N/A lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9],
2N/A lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13],
2N/A lu->guid[14], lu->guid[15]);
2N/A
2N/A (void) snprintf(scfLuPgName, sizeof (scfLuPgName), "%s-%s",
2N/A STMF_LU_PREFIX, guidAsciiBuf);
2N/A
2N/A bzero(viewEntryPgName, sizeof (viewEntryPgName));
2N/A /*
2N/A * Format of view entry property group name:
2N/A * VE-<view_entry_name>-<lu_name>
2N/A */
2N/A (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName),
2N/A "%s-%d-%s", STMF_VE_PREFIX, viewEntry->veIndex, guidAsciiBuf);
2N/A
2N/A ret = iPsAddViewEntry(scfLuPgName, viewEntryPgName, viewEntry);
2N/A
2N/Aout:
2N/A /*
2N/A * Okay, we're done. Release the signals
2N/A */
2N/A if (releaseSignal(&sigmaskRestore) != 0) {
2N/A /*
2N/A * Don't set this as an STMF_PS_ERROR_*. We succeeded
2N/A * the requested operation. But we do need to log it.
2N/A */
2N/A syslog(LOG_ERR, "Unable to release one or more signals - %s",
2N/A strerror(errno));
2N/A }
2N/A
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A
2N/A /* release the signal hold lock */
2N/A (void) pthread_mutex_unlock(&sigSetLock);
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psCheckService
2N/A *
2N/A * Purpose: Checks whether service exists
2N/A *
2N/A */
2N/Aint
2N/ApsCheckService()
2N/A{
2N/A int ret;
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psCreateHostGroup
2N/A *
2N/A * groupName - name of group to create
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsCreateHostGroup(char *groupName)
2N/A{
2N/A return (iPsCreateDeleteGroup(STMF_HOST_GROUPS, groupName, ADD));
2N/A}
2N/A
2N/A/*
2N/A * psCreateTargetGroup
2N/A *
2N/A * groupName - name of group to create
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsCreateTargetGroup(char *groupName)
2N/A{
2N/A return (iPsCreateDeleteGroup(STMF_TARGET_GROUPS, groupName, ADD));
2N/A}
2N/A
2N/A/*
2N/A * psDeleteHostGroup
2N/A *
2N/A * groupName - name of group to delete
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsDeleteHostGroup(char *groupName)
2N/A{
2N/A return (iPsCreateDeleteGroup(STMF_HOST_GROUPS, groupName, REMOVE));
2N/A}
2N/A
2N/A/*
2N/A * psDeleteTargetGroup
2N/A *
2N/A * groupName - name of group to delete
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsDeleteTargetGroup(char *groupName)
2N/A{
2N/A return (iPsCreateDeleteGroup(STMF_TARGET_GROUPS, groupName,
2N/A REMOVE));
2N/A}
2N/A
2N/A/*
2N/A * psGetHostGroupList
2N/A *
2N/A * groupList - pointer to pointer to stmfGroupList. Contains the list
2N/A * of host groups on successful return.
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsGetHostGroupList(stmfGroupList **groupList)
2N/A{
2N/A return (iPsGetGroupList(STMF_HOST_GROUPS, groupList));
2N/A}
2N/A
2N/A/*
2N/A * psGetLogicalUnitList
2N/A *
2N/A *
2N/A */
2N/Aint
2N/ApsGetLogicalUnitList(stmfGuidList **guidList)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_iter_t *pgIter = NULL;
2N/A char buf[MAXNAMELEN];
2N/A int guidCnt = 0;
2N/A int i = 0, j;
2N/A int ret = STMF_PS_SUCCESS;
2N/A unsigned int guid[sizeof (stmfGuid)];
2N/A stmfGuid outGuid;
2N/A
2N/A assert(guidList != NULL);
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((pgIter = scf_iter_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * pgIter is the iterator handle
2N/A */
2N/A if (scf_iter_service_pgs(pgIter, svc) == -1) {
2N/A syslog(LOG_ERR, "iter property groups failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A while (scf_iter_next_pg(pgIter, pg) == 1) {
2N/A if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get pg name failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Only count LU property groups
2N/A */
2N/A if (strncmp(buf, STMF_LU_PREFIX, strlen(STMF_LU_PREFIX)) == 0) {
2N/A guidCnt++;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * pgIter is the iterator handle
2N/A */
2N/A if (scf_iter_service_pgs(pgIter, svc) == -1) {
2N/A syslog(LOG_ERR, "iter property groups failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A *guidList = (stmfGuidList *)calloc(1, sizeof (stmfGuidList) +
2N/A guidCnt * sizeof (stmfGuid));
2N/A if (*guidList == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * it's possible for entries to be added/removed while we're retrieving
2N/A * the property groups. Just make sure we don't write beyond our
2N/A * allocated buffer by checking to ensure i < guidCnt.
2N/A */
2N/A while ((scf_iter_next_pg(pgIter, pg) == 1) && (i < guidCnt)) {
2N/A if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get pg name failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Only use LU property groups
2N/A */
2N/A if (strncmp(buf, STMF_LU_PREFIX, strlen(STMF_LU_PREFIX)) != 0) {
2N/A continue;
2N/A }
2N/A
2N/A j = strlen(STMF_LU_PREFIX) + strlen("-");
2N/A
2N/A (void) sscanf(buf + j,
2N/A "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
2N/A &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
2N/A &guid[6], &guid[7], &guid[8], &guid[9], &guid[10],
2N/A &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]);
2N/A
2N/A for (j = 0; j < sizeof (stmfGuid); j++) {
2N/A outGuid.guid[j] = guid[j];
2N/A }
2N/A
2N/A bcopy(&outGuid, (*guidList)->guid[i++].guid, sizeof (stmfGuid));
2N/A (*guidList)->cnt++;
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A free(*guidList);
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (pgIter != NULL) {
2N/A scf_iter_destroy(pgIter);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psGetTargetGroupList
2N/A *
2N/A * groupList - pointer to pointer to stmfGroupList. Contains the list
2N/A * of target groups on successful return.
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsGetTargetGroupList(stmfGroupList **groupList)
2N/A{
2N/A return (iPsGetGroupList(STMF_TARGET_GROUPS, groupList));
2N/A}
2N/A
2N/A/*
2N/A * psGetHostGroupMemberList
2N/A *
2N/A * groupName - group name for which to retrieve a member list
2N/A * groupMemberList - pointer to pointer to stmfGroupProperties list
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsGetHostGroupMemberList(char *groupName, stmfGroupProperties **groupMemberList)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsGetGroupMemberList(STMF_HOST_GROUPS, groupPropListName,
2N/A groupMemberList));
2N/A}
2N/A
2N/A/*
2N/A * psGetTargetGroupMemberList
2N/A *
2N/A * groupName - group name for which to retrieve a member list
2N/A * groupMemberList - pointer to pointer to stmfGroupProperties list
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsGetTargetGroupMemberList(char *groupName,
2N/A stmfGroupProperties **groupMemberList)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsGetGroupMemberList(STMF_TARGET_GROUPS,
2N/A groupPropListName, groupMemberList));
2N/A}
2N/A
2N/A/*
2N/A * qsort function
2N/A * sort on veIndex
2N/A */
2N/Astatic int
2N/AviewEntryCompare(const void *p1, const void *p2)
2N/A{
2N/A
2N/A stmfViewEntry *v1 = (stmfViewEntry *)p1, *v2 = (stmfViewEntry *)p2;
2N/A if (v1->veIndex > v2->veIndex)
2N/A return (1);
2N/A if (v1->veIndex < v2->veIndex)
2N/A return (-1);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * psGetViewEntryList
2N/A *
2N/A * luGuid - identifier of logical unit for which to retrieve a view entry list
2N/A * viewEntryList - pointer to pointer to stmfViewEntryList. It will be allocated
2N/A * on successful return.
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A scf_iter_t *propIter = NULL;
2N/A char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */
2N/A char viewEntryPgName[VIEW_ENTRY_PG_SIZE];
2N/A char luPgName[LOGICAL_UNIT_PG_SIZE];
2N/A int ret = STMF_PS_SUCCESS;
2N/A uint64_t i = 0;
2N/A uint64_t veCnt;
2N/A
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((propIter = scf_iter_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Convert to ASCII uppercase hexadecimal string */
2N/A (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
2N/A "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
2N/A lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4],
2N/A lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9],
2N/A lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13],
2N/A lu->guid[14], lu->guid[15]);
2N/A
2N/A /* form the LU property group name (LU-<guid>) */
2N/A (void) snprintf(luPgName, sizeof (luPgName), "%s-%s",
2N/A STMF_LU_PREFIX, guidAsciiBuf);
2N/A
2N/A /* get the property group associated with this LU */
2N/A if (scf_service_get_pg(svc, luPgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /* get the view entry count property */
2N/A if (scf_pg_get_property(pg, STMF_VE_CNT, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the actual value of the view entry count property
2N/A */
2N/A if (scf_value_get_count(value, &veCnt) == -1) {
2N/A syslog(LOG_ERR, "get integer value %s/%s failed - %s",
2N/A luPgName, STMF_VE_CNT, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * propIter is the iterator handle
2N/A */
2N/A if (scf_iter_pg_properties(propIter, pg) == -1) {
2N/A syslog(LOG_ERR, "iter properties for %s failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * alloc the list based on the view entry count
2N/A */
2N/A *viewEntryList = (stmfViewEntryList *)calloc(1,
2N/A sizeof (stmfViewEntryList) + veCnt * sizeof (stmfViewEntry));
2N/A if (*viewEntryList == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A i = 0;
2N/A /*
2N/A * iterate through the view entry properties to find the
2N/A * view entries
2N/A */
2N/A while (scf_iter_next_property(propIter, prop) == 1) {
2N/A /* find match for view entry property */
2N/A if (scf_property_get_name(prop, viewEntryPgName,
2N/A sizeof (viewEntryPgName)) != -1) {
2N/A if (strncmp(viewEntryPgName, STMF_VE_PREFIX,
2N/A strlen(STMF_VE_PREFIX)) != 0) {
2N/A continue;
2N/A }
2N/A /*
2N/A * We've exceeded our alloc limit
2N/A * break with error
2N/A */
2N/A if (i == veCnt) {
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A if ((ret = iPsGetViewEntry(viewEntryPgName,
2N/A &((*viewEntryList)->ve[i]))) != STMF_PS_SUCCESS) {
2N/A break;
2N/A }
2N/A
2N/A i++;
2N/A
2N/A /* set the list count */
2N/A (*viewEntryList)->cnt++;
2N/A } else {
2N/A syslog(LOG_ERR, "scf iter %s properties failed - %s",
2N/A luPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A free(*viewEntryList);
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * We're sorting the final list here based on the veIndex
2N/A * If we don't, the caller is going to have to do it to reap
2N/A * some intelligent output.
2N/A */
2N/A qsort((void *)&((*viewEntryList)->ve[0]), (*viewEntryList)->cnt,
2N/A sizeof (stmfViewEntry), viewEntryCompare);
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A if (propIter != NULL) {
2N/A scf_iter_destroy(propIter);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * iPsGetViewEntry
2N/A *
2N/A * viewEntryPgName - view entry property group name to retrieve
2N/A * viewEntry - pointer to stmfViewEntry structure allocated by the caller
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Astatic int
2N/AiPsGetViewEntry(char *viewEntryPgName, stmfViewEntry *viewEntry)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A uint8_t scfBool;
2N/A char *indexPtr;
2N/A char groupName[sizeof (stmfGroupName)];
2N/A int ret = STMF_PS_SUCCESS;
2N/A
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A bzero(viewEntry, sizeof (stmfViewEntry));
2N/A
2N/A /*
2N/A * get the service property group view entry handle
2N/A */
2N/A if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A
2N/A /*
2N/A * get index
2N/A * format is: VE-<veIndex>-GUID
2N/A */
2N/A indexPtr = strchr(viewEntryPgName, '-');
2N/A if (!indexPtr) {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Set the index */
2N/A viewEntry->veIndex = atoi(strtok(++indexPtr, "-"));
2N/A
2N/A viewEntry->veIndexValid = B_TRUE;
2N/A
2N/A /* get allHosts property */
2N/A if (scf_pg_get_property(pg, STMF_VE_ALLHOSTS,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLHOSTS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLHOSTS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* set allHosts */
2N/A if (scf_value_get_boolean(value, (uint8_t *)&scfBool) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLHOSTS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A viewEntry->allHosts = scfBool;
2N/A
2N/A /* get hostGroup property */
2N/A if (scf_pg_get_property(pg, STMF_VE_HOSTGROUP,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_value_get_ustring(value, groupName,
2N/A sizeof (groupName)) == -1) {
2N/A syslog(LOG_ERR, "get value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_HOSTGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /* set hostGroup */
2N/A bcopy(groupName, viewEntry->hostGroup, strlen(groupName));
2N/A
2N/A /* get allTargets property */
2N/A if (scf_pg_get_property(pg, STMF_VE_ALLTARGETS,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLTARGETS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLTARGETS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* set allTargets */
2N/A if (scf_value_get_boolean(value, (uint8_t *)&scfBool) == -1) {
2N/A syslog(LOG_ERR, "get value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_ALLTARGETS,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A viewEntry->allTargets = scfBool;
2N/A
2N/A /* get targetGroup property */
2N/A if (scf_pg_get_property(pg, STMF_VE_TARGETGROUP, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_TARGETGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_TARGETGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_value_get_ustring(value, groupName,
2N/A sizeof (groupName)) == -1) {
2N/A syslog(LOG_ERR, "get value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_TARGETGROUP,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /* set targetGroup */
2N/A bcopy(groupName, viewEntry->targetGroup, strlen(groupName));
2N/A
2N/A /* get luNbr property */
2N/A if (scf_pg_get_property(pg, STMF_VE_LUNBR,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_LUNBR,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_LUNBR,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* set luNbr */
2N/A if (scf_value_get_opaque(value, (char *)viewEntry->luNbr,
2N/A sizeof (viewEntry->luNbr)) == -1) {
2N/A syslog(LOG_ERR, "get opaque value %s/%s failed - %s",
2N/A viewEntryPgName, STMF_VE_LUNBR,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A /* set luNbrValid to true since we just got it */
2N/A viewEntry->luNbrValid = FIXED_LUN(viewEntry->luNbr) ?
2N/A B_TRUE : B_FALSE;
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * psRemoveHostGroupMember
2N/A *
2N/A * Remove a host group member from a host group,
2N/A *
2N/A * groupName - name of group from which the member is removed
2N/A * memberName - name of group member to remove
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsRemoveHostGroupMember(char *groupName, char *memberName)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsAddRemoveGroupMember(STMF_HOST_GROUPS, groupPropListName,
2N/A memberName, REMOVE));
2N/A}
2N/A
2N/A/*
2N/A * psRemoveTargetGroupMember
2N/A *
2N/A * Remove a target port group member from an target port group,
2N/A *
2N/A * groupName - name of group from which the member is removed
2N/A * memberName - name of group member to remove
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsRemoveTargetGroupMember(char *groupName, char *memberName)
2N/A{
2N/A int ret;
2N/A char groupPropListName[MAXNAMELEN];
2N/A char groupPropName[MAXNAMELEN];
2N/A
2N/A ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName,
2N/A groupPropName);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A return (ret);
2N/A }
2N/A
2N/A if (snprintf(groupPropListName, sizeof (groupPropListName),
2N/A "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) >
2N/A sizeof (groupPropListName)) {
2N/A syslog(LOG_ERR, "buffer overflow on property name %s",
2N/A groupPropName);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A return (iPsAddRemoveGroupMember(STMF_TARGET_GROUPS, groupPropListName,
2N/A memberName, REMOVE));
2N/A}
2N/A
2N/A/*
2N/A * psGetProviderData
2N/A *
2N/A * Retrieves an nvlist on a per provider basis
2N/A *
2N/A * providerName - property group name to use
2N/A * nvl - nvlist to retrieve
2N/A *
2N/A */
2N/Aint
2N/ApsGetProviderData(char *providerName, nvlist_t **nvl, int providerType,
2N/A uint64_t *setToken)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A uint64_t blockCnt = 0;
2N/A ssize_t blockOffset = 0;
2N/A ssize_t actualBlockSize = 0;
2N/A char pgName[MAXPATHLEN];
2N/A char dataPropertyName[STMF_PROVIDER_DATA_PROP_NAME_SIZE];
2N/A char *nvlistEncoded = NULL;
2N/A ssize_t nvlistEncodedSize = 0;
2N/A boolean_t foundSetCnt = B_TRUE;
2N/A int i;
2N/A int ret = STMF_PS_SUCCESS;
2N/A
2N/A if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE &&
2N/A providerType != STMF_PORT_PROVIDER_TYPE)) {
2N/A ret = STMF_PS_ERROR_INVALID_ARG;
2N/A goto out;
2N/A }
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * create the property group name
2N/A */
2N/A (void) snprintf(pgName, sizeof (pgName), "%s%s",
2N/A STMF_PROVIDER_DATA_PREFIX, providerName);
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Retrieve the existing property group.
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() != SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get pg %s failed - %s", pgName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A } else {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_COUNT property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_COUNT value
2N/A */
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A */
2N/A if (scf_value_get_count(value, &blockCnt) == -1) {
2N/A syslog(LOG_ERR, "get integer value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Has the caller requested the token to be set? */
2N/A if (setToken) {
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT property
2N/A * If it doesn't exist, we assume it to be zero.
2N/A */
2N/A *setToken = 0;
2N/A if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A prop) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A foundSetCnt = B_FALSE;
2N/A } else {
2N/A syslog(LOG_ERR, "get property %s/%s "
2N/A "failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A if (foundSetCnt) {
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT value
2N/A */
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR,
2N/A "get property value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A * and set the caller's token
2N/A */
2N/A if (scf_value_get_count(value, setToken) == -1) {
2N/A syslog(LOG_ERR,
2N/A "get integer value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A }
2N/A
2N/A nvlistEncoded = (char *)calloc(1,
2N/A blockCnt * STMF_PROVIDER_DATA_PROP_SIZE);
2N/A if (nvlistEncoded == NULL) {
2N/A syslog(LOG_ERR, "nvlistEncoded alloc failed");
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A for (i = 0; i < blockCnt; i++) {
2N/A bzero(dataPropertyName, sizeof (dataPropertyName));
2N/A /*
2N/A * create the name to use for the property
2N/A */
2N/A (void) snprintf(dataPropertyName, sizeof (dataPropertyName),
2N/A "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i);
2N/A
2N/A if (scf_pg_get_property(pg, dataPropertyName, prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Set the data block offset
2N/A */
2N/A blockOffset = STMF_PROVIDER_DATA_PROP_SIZE * i;
2N/A actualBlockSize = scf_value_get_opaque(value,
2N/A &nvlistEncoded[blockOffset], STMF_PROVIDER_DATA_PROP_SIZE);
2N/A if (actualBlockSize == -1) {
2N/A syslog(LOG_ERR, "get opaque property value %s/%s "
2N/A "failed - %s", pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A nvlistEncodedSize += actualBlockSize;
2N/A }
2N/A
2N/A if (nvlist_unpack(nvlistEncoded, nvlistEncodedSize, nvl, 0) != 0) {
2N/A syslog(LOG_ERR, "unable to unpack nvlist");
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A if (nvlistEncoded != NULL) {
2N/A free(nvlistEncoded);
2N/A }
2N/A
2N/A return (ret);
2N/A
2N/A}
2N/A/*
2N/A * psGetProviderDataList
2N/A *
2N/A * Retrieves the list of providers that currently store persistent data
2N/A *
2N/A * providerList - pointer to a pointer to an stmfProviderList structure
2N/A * On success, this will contain the list of providers
2N/A * currently storing persistent data.
2N/A */
2N/Aint
2N/ApsGetProviderDataList(stmfProviderList **providerList)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_value_t *value = NULL;
2N/A scf_iter_t *pgIter = NULL;
2N/A char buf[MAXNAMELEN];
2N/A int providerCnt = 0;
2N/A int64_t providerType;
2N/A int i = 0, j;
2N/A int ret = STMF_PS_SUCCESS;
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A *providerList = NULL;
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((value = scf_value_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((pgIter = scf_iter_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * pgIter is the iterator handle
2N/A */
2N/A if (scf_iter_service_pgs(pgIter, svc) == -1) {
2N/A syslog(LOG_ERR, "iter property groups failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A while (scf_iter_next_pg(pgIter, pg) == 1) {
2N/A if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get name failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Only count LU property groups
2N/A */
2N/A if (strncmp(buf, STMF_PROVIDER_DATA_PREFIX,
2N/A strlen(STMF_PROVIDER_DATA_PREFIX)) == 0) {
2N/A providerCnt++;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * pgIter is the iterator handle
2N/A */
2N/A if (scf_iter_service_pgs(pgIter, svc) == -1) {
2N/A syslog(LOG_ERR, "iter property groups failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A *providerList = (stmfProviderList *)calloc(1,
2N/A sizeof (stmfProviderList) + providerCnt * sizeof (stmfProvider));
2N/A if (*providerList == NULL) {
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * it's possible for entries to be added/removed while we're retrieving
2N/A * the property groups. Just make sure we don't write beyond our
2N/A * allocated buffer by checking to ensure i < providerCnt.
2N/A */
2N/A while ((scf_iter_next_pg(pgIter, pg) == 1) && (i < providerCnt)) {
2N/A if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) {
2N/A syslog(LOG_ERR, "get name failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A /*
2N/A * Only use provider data property groups
2N/A */
2N/A if (strncmp(buf, STMF_PROVIDER_DATA_PREFIX,
2N/A strlen(STMF_PROVIDER_DATA_PREFIX)) != 0) {
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_TYPE property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_TYPE,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A buf, STMF_PROVIDER_DATA_PROP_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_TYPE value
2N/A */
2N/A if (scf_property_get_value(prop, value) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A buf, STMF_PROVIDER_DATA_PROP_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A */
2N/A if (scf_value_get_integer(value, &providerType) == -1) {
2N/A syslog(LOG_ERR, "get integer value %s/%s failed - %s",
2N/A buf, STMF_PROVIDER_DATA_PROP_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A break;
2N/A }
2N/A
2N/A (*providerList)->provider[i].providerType = providerType;
2N/A
2N/A /* determine offset for copy of provider name */
2N/A j = strlen(STMF_PROVIDER_DATA_PREFIX);
2N/A
2N/A /* copy provider name to caller's list */
2N/A (void) strncpy((*providerList)->provider[i].name, buf + j,
2N/A sizeof ((*providerList)->provider[i].name));
2N/A i++;
2N/A (*providerList)->cnt++;
2N/A }
2N/A
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A free(*providerList);
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (value != NULL) {
2N/A scf_value_destroy(value);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (pgIter != NULL) {
2N/A scf_iter_destroy(pgIter);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * psSetProviderData
2N/A *
2N/A * Stores a packed nvlist on a per provider basis
2N/A *
2N/A * providerName - property group name to use
2N/A * nvl - nvlist to store
2N/A * providerType - type of provider (logical unit or port)
2N/A *
2N/A */
2N/Aint
2N/ApsSetProviderData(char *providerName, nvlist_t *nvl, int providerType,
2N/A uint64_t *setToken)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A scf_property_t *prop = NULL;
2N/A scf_transaction_t *tran = NULL;
2N/A /* represents arrays of entry and value pointers for scf */
2N/A scf_transaction_entry_t **addEntry = NULL;
2N/A scf_transaction_entry_t **deleteEntry = NULL;
2N/A scf_value_t **addValue = NULL;
2N/A
2N/A /*
2N/A * These declarations are for known entry and value set/get
2N/A * operations
2N/A */
2N/A scf_transaction_entry_t *entry1 = NULL;
2N/A scf_transaction_entry_t *entry2 = NULL;
2N/A scf_transaction_entry_t *entry3 = NULL;
2N/A scf_transaction_entry_t *entry5 = NULL;
2N/A scf_value_t *value1 = NULL;
2N/A scf_value_t *value2 = NULL;
2N/A scf_value_t *value3 = NULL;
2N/A scf_value_t *value4 = NULL;
2N/A scf_value_t *value5 = NULL;
2N/A
2N/A boolean_t newPg = B_FALSE;
2N/A char pgName[MAXPATHLEN];
2N/A char dataPropertyName[STMF_PROVIDER_DATA_PROP_NAME_SIZE];
2N/A char *nvlistEncoded = NULL;
2N/A size_t nvlistEncodedSize;
2N/A size_t blockSize;
2N/A int i, j = 0;
2N/A int addEntryAlloc = 0, deleteEntryAlloc = 0, addValueAlloc = 0;
2N/A int blockOffset;
2N/A uint64_t oldBlockCnt = 0;
2N/A uint64_t blockCnt = 0;
2N/A uint64_t setCnt = 0;
2N/A boolean_t foundSetCnt = B_TRUE;
2N/A int ret = STMF_PS_SUCCESS;
2N/A int commitRet;
2N/A
2N/A if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE &&
2N/A providerType != STMF_PORT_PROVIDER_TYPE)) {
2N/A ret = STMF_PS_ERROR_INVALID_ARG;
2N/A goto out;
2N/A }
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A bzero(pgName, sizeof (pgName));
2N/A /*
2N/A * create the property group name
2N/A */
2N/A (void) snprintf(pgName, sizeof (pgName), "%s%s",
2N/A STMF_PROVIDER_DATA_PREFIX, providerName);
2N/A
2N/A /*
2N/A * Allocate scf resources
2N/A */
2N/A if (((pg = scf_pg_create(handle)) == NULL) ||
2N/A ((entry1 = scf_entry_create(handle)) == NULL) ||
2N/A ((entry2 = scf_entry_create(handle)) == NULL) ||
2N/A ((entry3 = scf_entry_create(handle)) == NULL) ||
2N/A ((entry5 = scf_entry_create(handle)) == NULL) ||
2N/A ((value1 = scf_value_create(handle)) == NULL) ||
2N/A ((value2 = scf_value_create(handle)) == NULL) ||
2N/A ((value3 = scf_value_create(handle)) == NULL) ||
2N/A ((value4 = scf_value_create(handle)) == NULL) ||
2N/A ((value5 = scf_value_create(handle)) == NULL) ||
2N/A ((prop = scf_property_create(handle)) == NULL) ||
2N/A ((tran = scf_transaction_create(handle)) == NULL)) {
2N/A syslog(LOG_ERR, "scf alloc resource failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the existing property group
2N/A */
2N/A if (scf_service_get_pg(svc, pgName, pg) == -1) {
2N/A if (scf_error() != SCF_ERROR_NOT_FOUND) {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A } else {
2N/A /*
2N/A * create the property group.
2N/A */
2N/A if (scf_service_add_pg(svc, pgName,
2N/A SCF_GROUP_APPLICATION, 0, pg) == -1) {
2N/A syslog(LOG_ERR, "add pg %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A newPg = B_TRUE;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Begin the transaction
2N/A */
2N/A if (scf_transaction_start(tran, pg) == -1) {
2N/A syslog(LOG_ERR, "start transaction for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (!newPg) {
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_COUNT property
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A prop) == -1) {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_COUNT value
2N/A */
2N/A if (scf_property_get_value(prop, value4) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A */
2N/A if (scf_value_get_count(value4, &oldBlockCnt) == -1) {
2N/A syslog(LOG_ERR, "get integer value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT property
2N/A * If it doesn't exist, we'll create it later after successfully
2N/A * setting the data.
2N/A */
2N/A if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A prop) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A foundSetCnt = B_FALSE;
2N/A } else {
2N/A syslog(LOG_ERR, "get property %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A if (foundSetCnt) {
2N/A /*
2N/A * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT value
2N/A */
2N/A if (scf_property_get_value(prop, value5) == -1) {
2N/A syslog(LOG_ERR, "get property value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now get the actual value from the value handle
2N/A */
2N/A if (scf_value_get_count(value5, &setCnt) == -1) {
2N/A syslog(LOG_ERR, "get integer value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Compare the setCnt prop to the caller's.
2N/A */
2N/A if (setToken && (*setToken != setCnt)) {
2N/A ret = STMF_PS_ERROR_PROV_DATA_STALE;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A setCnt++;
2N/A
2N/A /*
2N/A * prepare the list for writing
2N/A */
2N/A if (nvlist_pack(nvl, &nvlistEncoded, &nvlistEncodedSize,
2N/A NV_ENCODE_XDR, 0) != 0) {
2N/A syslog(LOG_ERR, "nvlist_pack for %s failed",
2N/A pgName);
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /* Determine how many chunks we need to write */
2N/A blockCnt = nvlistEncodedSize/STMF_PROVIDER_DATA_PROP_SIZE;
2N/A if (nvlistEncodedSize % STMF_PROVIDER_DATA_PROP_SIZE)
2N/A blockCnt++;
2N/A
2N/A /* allocate entry and value resources for writing those chunks */
2N/A addEntry = (scf_transaction_entry_t **)calloc(1, sizeof (*addEntry)
2N/A * blockCnt);
2N/A if (addEntry == NULL) {
2N/A syslog(LOG_ERR, "addEntry alloc for %s failed", pgName);
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A addValue = (scf_value_t **)calloc(1, sizeof (*addValue)
2N/A * blockCnt);
2N/A if (addValue == NULL) {
2N/A syslog(LOG_ERR, "value alloc for %s failed", pgName);
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * allocate entry delete resources for deleting anything existing
2N/A * that is more than the new block count. We could leave them around
2N/A * without suffering any ill effects but it will be cleaner to look at
2N/A * in smf tools if they are deleted.
2N/A */
2N/A if (oldBlockCnt > blockCnt) {
2N/A deleteEntry = (scf_transaction_entry_t **)calloc(1,
2N/A sizeof (*deleteEntry) * (oldBlockCnt - blockCnt));
2N/A if (deleteEntry == NULL) {
2N/A syslog(LOG_ERR, "deleteEntry alloc for %s failed",
2N/A pgName);
2N/A ret = STMF_PS_ERROR_NOMEM;
2N/A goto out;
2N/A }
2N/A deleteEntryAlloc = oldBlockCnt - blockCnt;
2N/A }
2N/A
2N/A
2N/A for (i = 0; i < blockCnt; i++) {
2N/A /*
2N/A * Create the entry resource for the prop
2N/A */
2N/A addEntry[i] = scf_entry_create(handle);
2N/A if (addEntry[i] == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* bump alloc count for addEntry allocation */
2N/A addEntryAlloc++;
2N/A
2N/A /*
2N/A * create the name to use for the property
2N/A */
2N/A (void) snprintf(dataPropertyName, sizeof (dataPropertyName),
2N/A "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i);
2N/A
2N/A /*
2N/A * Create the new property
2N/A */
2N/A if (scf_transaction_property_new(tran, addEntry[i],
2N/A dataPropertyName, SCF_TYPE_OPAQUE) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A if (scf_transaction_property_change(tran,
2N/A addEntry[i], dataPropertyName,
2N/A SCF_TYPE_OPAQUE) == -1) {
2N/A syslog(LOG_ERR, "transaction property "
2N/A "change %s/%s failed - %s",
2N/A pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A syslog(LOG_ERR,
2N/A "transaction property new %s/%s "
2N/A "failed - %s", pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A /*
2N/A * Create the value resource for the prop
2N/A */
2N/A addValue[i] = scf_value_create(handle);
2N/A if (addValue[i] == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* bump alloc count for addValue allocation */
2N/A addValueAlloc++;
2N/A
2N/A /*
2N/A * Set the data block offset and size
2N/A */
2N/A if ((STMF_PROVIDER_DATA_PROP_SIZE * (i + 1))
2N/A > nvlistEncodedSize) {
2N/A blockSize = nvlistEncodedSize
2N/A - STMF_PROVIDER_DATA_PROP_SIZE * i;
2N/A } else {
2N/A blockSize = STMF_PROVIDER_DATA_PROP_SIZE;
2N/A }
2N/A
2N/A blockOffset = STMF_PROVIDER_DATA_PROP_SIZE * i;
2N/A if (scf_value_set_opaque(addValue[i],
2N/A &nvlistEncoded[blockOffset], blockSize) == -1) {
2N/A syslog(LOG_ERR, "set value for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Add the data block to the transaction entry
2N/A */
2N/A if (scf_entry_add_value(addEntry[i], addValue[i]) == -1) {
2N/A syslog(LOG_ERR, "add value for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Now we need to delete any chunks (properties) that are no longer
2N/A * needed. Iterate through the rest of the chunks deleting each.
2N/A */
2N/A for (i = blockCnt; i < oldBlockCnt; i++) {
2N/A /*
2N/A * Create the entry resource for the prop
2N/A */
2N/A deleteEntry[j] = scf_entry_create(handle);
2N/A if (deleteEntry[j] == NULL) {
2N/A syslog(LOG_ERR, "scf value alloc for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * create the name to use for the property
2N/A */
2N/A (void) snprintf(dataPropertyName, sizeof (dataPropertyName),
2N/A "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i);
2N/A
2N/A /*
2N/A * Delete the existing property
2N/A */
2N/A if (scf_transaction_property_delete(tran, deleteEntry[j++],
2N/A dataPropertyName) == -1) {
2N/A syslog(LOG_ERR, "delete property %s/%s failed - %s",
2N/A pgName, dataPropertyName,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A if (newPg) {
2N/A /*
2N/A * Ensure the read_authorization property is set
2N/A * for the group
2N/A */
2N/A if (scf_transaction_property_new(tran, entry1,
2N/A "read_authorization", SCF_TYPE_ASTRING) == -1) {
2N/A syslog(LOG_ERR, "transaction property %s/%s new "
2N/A "failed - %s", pgName, "read_authorization",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_value_set_astring(value1, STMF_SMF_READ_ATTR) == -1) {
2N/A syslog(LOG_ERR, "set value %s/%s failed - %s",
2N/A pgName, "read_authorization",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_entry_add_value(entry1, value1) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A pgName, "read_authorization",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A /* create or change the count property */
2N/A if (scf_transaction_property_new(tran, entry2,
2N/A STMF_PROVIDER_DATA_PROP_COUNT, SCF_TYPE_COUNT) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A if (scf_transaction_property_change(tran, entry2,
2N/A STMF_PROVIDER_DATA_PROP_COUNT,
2N/A SCF_TYPE_COUNT) == -1) {
2N/A syslog(LOG_ERR, "transaction property change "
2N/A "%s/%s failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property %s/%s new "
2N/A "failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A scf_value_set_count(value2, blockCnt);
2N/A
2N/A if (scf_entry_add_value(entry2, value2) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* create or change the set count property */
2N/A if (scf_transaction_property_new(tran, entry5,
2N/A STMF_PROVIDER_DATA_PROP_SET_COUNT, SCF_TYPE_COUNT) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A if (scf_transaction_property_change(tran, entry5,
2N/A STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A SCF_TYPE_COUNT) == -1) {
2N/A syslog(LOG_ERR,
2N/A "transaction property change %s/%s "
2N/A "failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A
2N/A
2N/A scf_value_set_count(value5, setCnt);
2N/A
2N/A if (scf_entry_add_value(entry5, value5) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s",
2N/A pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* create or change the provider type property */
2N/A if (scf_transaction_property_new(tran, entry3,
2N/A STMF_PROVIDER_DATA_PROP_TYPE, SCF_TYPE_INTEGER) == -1) {
2N/A if (scf_error() == SCF_ERROR_EXISTS) {
2N/A if (scf_transaction_property_change(tran, entry3,
2N/A STMF_PROVIDER_DATA_PROP_TYPE,
2N/A SCF_TYPE_INTEGER) == -1) {
2N/A syslog(LOG_ERR,
2N/A "transaction property change %s/%s "
2N/A "failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A } else {
2N/A syslog(LOG_ERR, "transaction property new %s/%s "
2N/A "failed - %s", pgName, STMF_PROVIDER_DATA_PROP_TYPE,
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A switch (providerType) {
2N/A case STMF_PORT_PROVIDER_TYPE:
2N/A case STMF_LU_PROVIDER_TYPE:
2N/A scf_value_set_integer(value3, providerType);
2N/A break;
2N/A default:
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A if (scf_entry_add_value(entry3, value3) == -1) {
2N/A syslog(LOG_ERR, "add value %s/%s failed - %s", pgName,
2N/A STMF_PROVIDER_DATA_PROP_TYPE, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A
2N/A if ((commitRet = scf_transaction_commit(tran)) != 1) {
2N/A syslog(LOG_ERR, "transaction commit for %s failed - %s",
2N/A pgName, scf_strerror(scf_error()));
2N/A if (commitRet == 0) {
2N/A ret = STMF_PS_ERROR_BUSY;
2N/A } else {
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /* pass the new token back to the caller if requested */
2N/A if (ret == STMF_PS_SUCCESS && setToken) {
2N/A *setToken = setCnt;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A if (prop != NULL) {
2N/A scf_property_destroy(prop);
2N/A }
2N/A if (tran != NULL) {
2N/A scf_transaction_destroy(tran);
2N/A }
2N/A for (i = 0; i < addEntryAlloc; i++) {
2N/A scf_entry_destroy(addEntry[i]);
2N/A }
2N/A for (i = 0; i < addValueAlloc; i++) {
2N/A scf_value_destroy(addValue[i]);
2N/A }
2N/A free(addValue);
2N/A free(addEntry);
2N/A for (i = 0; i < deleteEntryAlloc; i++) {
2N/A scf_entry_destroy(deleteEntry[i]);
2N/A }
2N/A free(deleteEntry);
2N/A if (entry1 != NULL) {
2N/A scf_entry_destroy(entry1);
2N/A }
2N/A if (entry2 != NULL) {
2N/A scf_entry_destroy(entry2);
2N/A }
2N/A if (entry3 != NULL) {
2N/A scf_entry_destroy(entry3);
2N/A }
2N/A if (entry5 != NULL) {
2N/A scf_entry_destroy(entry5);
2N/A }
2N/A if (value1 != NULL) {
2N/A scf_value_destroy(value1);
2N/A }
2N/A if (value2 != NULL) {
2N/A scf_value_destroy(value2);
2N/A }
2N/A if (value3 != NULL) {
2N/A scf_value_destroy(value3);
2N/A }
2N/A if (value4 != NULL) {
2N/A scf_value_destroy(value4);
2N/A }
2N/A if (value5 != NULL) {
2N/A scf_value_destroy(value5);
2N/A }
2N/A if (nvlistEncoded != NULL) {
2N/A free(nvlistEncoded);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psGetViewEntry
2N/A *
2N/A * Purpose: Get a single view entry based on the logical unit identifier and
2N/A * view entry index
2N/A *
2N/A * lu - logical unit identifier
2N/A * viewEntryIndex - index of view entry
2N/A * ve - caller allocated stmfViewEntry structure. On success, this will
2N/A * contain the retrieved view entry
2N/A */
2N/Aint
2N/ApsGetViewEntry(stmfGuid *lu, uint32_t viewEntryIndex, stmfViewEntry *ve)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */
2N/A char viewEntryPgName[VIEW_ENTRY_PG_SIZE];
2N/A char luPgName[LOGICAL_UNIT_PG_SIZE];
2N/A int ret = STMF_PS_SUCCESS;
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A pg = scf_pg_create(handle);
2N/A if (pg == NULL) {
2N/A syslog(LOG_ERR, "scf pg alloc failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Convert to ASCII uppercase hexadecimal string */
2N/A (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
2N/A "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
2N/A lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4],
2N/A lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9],
2N/A lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13],
2N/A lu->guid[14], lu->guid[15]);
2N/A
2N/A (void) snprintf(luPgName, sizeof (luPgName), "%s-%s",
2N/A STMF_LU_PREFIX, guidAsciiBuf);
2N/A
2N/A /*
2N/A * Format of view entry property group name:
2N/A * VE-<view_entry_index>-<lu_name>
2N/A */
2N/A (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName),
2N/A "%s-%d-%s", STMF_VE_PREFIX, viewEntryIndex, guidAsciiBuf);
2N/A
2N/A if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A
2N/A if ((ret = iPsGetViewEntry(viewEntryPgName, ve)) != STMF_PS_SUCCESS) {
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * psRemoveViewEntry
2N/A *
2N/A * Remove a view entry
2N/A *
2N/A * luGuid - identifier of logical unit from which to remove view entry
2N/A * viewEntryIndex - view entry name to remove
2N/A *
2N/A * returns:
2N/A * STMF_PS_SUCCESS on success
2N/A * STMF_PS_ERROR_* on failure
2N/A */
2N/Aint
2N/ApsRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex)
2N/A{
2N/A scf_handle_t *handle = NULL;
2N/A scf_service_t *svc = NULL;
2N/A scf_propertygroup_t *pg = NULL;
2N/A char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */
2N/A char viewEntryPgName[VIEW_ENTRY_PG_SIZE];
2N/A char luPgName[LOGICAL_UNIT_PG_SIZE];
2N/A int ret = STMF_PS_SUCCESS;
2N/A sigset_t sigmaskRestore;
2N/A
2N/A /* grab the signal hold lock */
2N/A (void) pthread_mutex_lock(&sigSetLock);
2N/A
2N/A /*
2N/A * hold signals until we're done
2N/A */
2N/A if (holdSignal(&sigmaskRestore) != 0) {
2N/A (void) pthread_mutex_unlock(&sigSetLock);
2N/A return (STMF_PS_ERROR);
2N/A }
2N/A
2N/A ret = iPsInit(&handle, &svc);
2N/A if (ret != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A pg = scf_pg_create(handle);
2N/A if (pg == NULL) {
2N/A syslog(LOG_ERR, "scf pg alloc failed - %s",
2N/A scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/A /* Convert to ASCII uppercase hexadecimal string */
2N/A (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
2N/A "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
2N/A lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4],
2N/A lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9],
2N/A lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13],
2N/A lu->guid[14], lu->guid[15]);
2N/A
2N/A (void) snprintf(luPgName, sizeof (luPgName), "%s-%s",
2N/A STMF_LU_PREFIX, guidAsciiBuf);
2N/A
2N/A /*
2N/A * Format of view entry property group name:
2N/A * VE-<view_entry_index>-<lu_name>
2N/A */
2N/A (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName),
2N/A "%s-%d-%s", STMF_VE_PREFIX, viewEntryIndex, guidAsciiBuf);
2N/A
2N/A if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) {
2N/A if (scf_error() == SCF_ERROR_NOT_FOUND) {
2N/A ret = STMF_PS_ERROR_NOT_FOUND;
2N/A } else {
2N/A syslog(LOG_ERR, "get pg %s failed - %s",
2N/A viewEntryPgName, scf_strerror(scf_error()));
2N/A ret = STMF_PS_ERROR;
2N/A }
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * update the logical unit property group to remove
2N/A * the view entry and update the view entry count
2N/A * If it fails, we won't delete the property group so that
2N/A * we maintain consistency.
2N/A */
2N/A if ((ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName,
2N/A REMOVE)) != STMF_PS_SUCCESS) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Delete the view entry. If this fails, we should try to add
2N/A * the logical unit view entry property group back otherwise
2N/A * we're inconsistent.
2N/A */
2N/A if (scf_pg_delete(pg) == -1) {
2N/A syslog(LOG_ERR, "delete pg %s failed - %s", viewEntryPgName,
2N/A scf_strerror(scf_error()));
2N/A if ((ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName,
2N/A ADD)) != STMF_PS_SUCCESS) {
2N/A syslog(LOG_ERR, "add of view entry %s failed, possible"
2N/A "inconsistency - %s", viewEntryPgName,
2N/A scf_strerror(scf_error()));
2N/A }
2N/A ret = STMF_PS_ERROR;
2N/A goto out;
2N/A }
2N/A
2N/Aout:
2N/A /*
2N/A * Okay, we're done. Release the signals
2N/A */
2N/A if (releaseSignal(&sigmaskRestore) != 0) {
2N/A /*
2N/A * Don't set this as an STMF_PS_ERROR_*. We succeeded
2N/A * the requested operation. But we do need to log it.
2N/A */
2N/A syslog(LOG_ERR, "Unable to release one or more signals - %s",
2N/A strerror(errno));
2N/A }
2N/A
2N/A /*
2N/A * Free resources
2N/A */
2N/A if (handle != NULL) {
2N/A scf_handle_destroy(handle);
2N/A }
2N/A if (svc != NULL) {
2N/A scf_service_destroy(svc);
2N/A }
2N/A if (pg != NULL) {
2N/A scf_pg_destroy(pg);
2N/A }
2N/A
2N/A /* release the signal hold lock */
2N/A (void) pthread_mutex_unlock(&sigSetLock);
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A
2N/A
2N/A/*
2N/A * holdSignal
2N/A *
2N/A * Hold SIGINT, SIGTERM, SIGQUIT until further notice.
2N/A *
2N/A * Saves old signal mask on a per thread basis
2N/A * and saves action for the process.
2N/A *
2N/A * Installs action for above signals.
2N/A *
2N/A * locks held: sigSetLock
2N/A *
2N/A * returns:
2N/A * 0 on success
2N/A * non-zero otherwise
2N/A */
2N/Astatic int
2N/AholdSignal(sigset_t *sigmaskRestore)
2N/A{
2N/A struct sigaction act;
2N/A sigset_t sigmask;
2N/A
2N/A /*
2N/A * Return existing signal mask for this thread
2N/A */
2N/A if (pthread_sigmask(0, NULL, sigmaskRestore) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A (void) sigemptyset(&act.sa_mask);
2N/A act.sa_handler = sigHandler;
2N/A act.sa_flags = 0;
2N/A
2N/A /*
2N/A * Have we set the actions for the signals we want to catch?
2N/A */
2N/A if (!actionSet) {
2N/A if (sigaction(SIGQUIT, &act, &currentActionQuit) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A if (sigaction(SIGINT, &act, &currentActionInt) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A if (sigaction(SIGTERM, &act, &currentActionTerm) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A actionSet = B_TRUE;
2N/A }
2N/A
2N/A /*
2N/A * We still need to change the mask for the current thread
2N/A */
2N/A if (sigfillset(&sigmask) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A (void) sigdelset(&sigmask, SIGQUIT);
2N/A
2N/A (void) sigdelset(&sigmask, SIGINT);
2N/A
2N/A (void) sigdelset(&sigmask, SIGTERM);
2N/A
2N/A if (pthread_sigmask(SIG_SETMASK, &sigmask, NULL) != 0) {
2N/A return (1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * releaseSignal
2N/A *
2N/A * Re-install the original signal mask and signal actions
2N/A *
2N/A * Also, raise any signals that were caught during the hold period and clear
2N/A * the signal from the caught set (signalsCaught).
2N/A *
2N/A * locks held: sigSetLock
2N/A *
2N/A * Returns
2N/A * 0 on success
2N/A * non-zero otherwise
2N/A */
2N/Astatic int
2N/AreleaseSignal(sigset_t *sigmaskRestore)
2N/A{
2N/A int ret = 0;
2N/A
2N/A if (sigaction(SIGQUIT, &currentActionQuit, NULL) != 0) {
2N/A ret = 1;
2N/A }
2N/A
2N/A if (sigaction(SIGINT, &currentActionInt, NULL) != 0) {
2N/A ret = 1;
2N/A }
2N/A
2N/A if (sigaction(SIGTERM, &currentActionTerm, NULL) != 0) {
2N/A ret = 1;
2N/A }
2N/A
2N/A actionSet = B_FALSE;
2N/A
2N/A /*
2N/A * Restore previous signal mask for this thread
2N/A */
2N/A if (pthread_sigmask(SIG_SETMASK, sigmaskRestore, NULL) != 0) {
2N/A syslog(LOG_ERR, "Unable to restore sigmask");
2N/A }
2N/A
2N/A /*
2N/A * Now raise signals that were raised while we were held
2N/A */
2N/A if (sigismember(&signalsCaught, SIGTERM)) {
2N/A (void) sigdelset(&signalsCaught, SIGTERM);
2N/A (void) raise(SIGTERM);
2N/A }
2N/A
2N/A if (sigismember(&signalsCaught, SIGINT)) {
2N/A (void) sigdelset(&signalsCaught, SIGINT);
2N/A (void) raise(SIGINT);
2N/A }
2N/A
2N/A if (sigismember(&signalsCaught, SIGQUIT)) {
2N/A (void) sigdelset(&signalsCaught, SIGQUIT);
2N/A (void) raise(SIGQUIT);
2N/A }
2N/A
2N/A return (ret);
2N/A}