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