1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 224b31676fSsrivijitha dugganapalli * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 23*894ed91cSMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved. 24fcf3ce44SJohn Forte */ 25fcf3ce44SJohn Forte 26fcf3ce44SJohn Forte #include <libscf.h> 27fcf3ce44SJohn Forte #include <stdio.h> 28fcf3ce44SJohn Forte #include <stdlib.h> 29fcf3ce44SJohn Forte #include <errno.h> 30fcf3ce44SJohn Forte #include <assert.h> 31fcf3ce44SJohn Forte #include <strings.h> 32fcf3ce44SJohn Forte #include <libstmf.h> 33fcf3ce44SJohn Forte #include <store.h> 34fcf3ce44SJohn Forte #include <syslog.h> 35fcf3ce44SJohn Forte #include <signal.h> 36fcf3ce44SJohn Forte #include <pthread.h> 37fcf3ce44SJohn Forte #include <libnvpair.h> 38fcf3ce44SJohn Forte #include <limits.h> 39fcf3ce44SJohn Forte #include <unistd.h> 40fcf3ce44SJohn Forte 41fcf3ce44SJohn Forte /* 42fcf3ce44SJohn Forte * This file's functions are responsible for all store and retrieve operations 43fcf3ce44SJohn Forte * against the STMF smf(5) database. The following shows the currently defined 44fcf3ce44SJohn Forte * schema for the STMF database: 45fcf3ce44SJohn Forte * 46fcf3ce44SJohn Forte * Description of property groups for service: svc:/system/stmf 47fcf3ce44SJohn Forte * 48fcf3ce44SJohn Forte * Stability: Volatile 49fcf3ce44SJohn Forte * 50fcf3ce44SJohn Forte * 1. Property Group: host_groups 51fcf3ce44SJohn Forte * Properties: group_name-<N> where <N> is an unsigned integer 52fcf3ce44SJohn Forte * type: ustring 53fcf3ce44SJohn Forte * contains: group name 54fcf3ce44SJohn Forte * group_name-<N>-member_list where <N> is an unsigned 55fcf3ce44SJohn Forte * integer matching a group_name-<N> property. 56fcf3ce44SJohn Forte * type: ustring 57fcf3ce44SJohn Forte * contains: list of members 58fcf3ce44SJohn Forte * 59fcf3ce44SJohn Forte * Description: 60fcf3ce44SJohn Forte * Contains the host group names as well as the host group members 61fcf3ce44SJohn Forte * for each host group. 62fcf3ce44SJohn Forte * 63fcf3ce44SJohn Forte * 2. Property Group: target_groups 64fcf3ce44SJohn Forte * Properties: group_name-<N> where <N> is an unsigned integer 65fcf3ce44SJohn Forte * type: ustring 66fcf3ce44SJohn Forte * contains: group name 67fcf3ce44SJohn Forte * group_name-<N>-member_list where <N> is an unsigned 68fcf3ce44SJohn Forte * integer matching a group_name-<N> property. 69fcf3ce44SJohn Forte * type: ustring 70fcf3ce44SJohn Forte * contains: list of members 71fcf3ce44SJohn Forte * 72fcf3ce44SJohn Forte * Description: 73fcf3ce44SJohn Forte * Contains the target group names as well as the target group 74fcf3ce44SJohn Forte * members for each target group. 75fcf3ce44SJohn Forte * 76fcf3ce44SJohn Forte * 3. Property Group: lu-<GUID> 77fcf3ce44SJohn Forte * where <GUID> is a 32 character hexadecimal string. 78fcf3ce44SJohn Forte * Properties: ve_cnt 79fcf3ce44SJohn Forte * type: count 80fcf3ce44SJohn Forte * contains: the number of current view entries 81fcf3ce44SJohn Forte * view-entry-<N>-<GUID> where <N> is an unsigned integer 82fcf3ce44SJohn Forte * type: ustring 83fcf3ce44SJohn Forte * contains: nothing. Used as reference to the view 84fcf3ce44SJohn Forte * entry property group 85fcf3ce44SJohn Forte * 86fcf3ce44SJohn Forte * Description: 87fcf3ce44SJohn Forte * Contains the references to each view entry. One lu-<GUID> 88fcf3ce44SJohn Forte * property group will exist for each logical unit with 1 or more 89fcf3ce44SJohn Forte * view entries. 90fcf3ce44SJohn Forte * Potentially can hold any other data that can be managed on a per 91fcf3ce44SJohn Forte * logical unit basis. 92fcf3ce44SJohn Forte * 93fcf3ce44SJohn Forte * 4. Property Group: view_entry-<N>-<GUID> (matches property in lu-<GUID> 94fcf3ce44SJohn Forte * property group) 95fcf3ce44SJohn Forte * Properties: all_hosts 96fcf3ce44SJohn Forte * type: boolean 97fcf3ce44SJohn Forte * contains: when true, the value of host_group is 98fcf3ce44SJohn Forte * ignored 99fcf3ce44SJohn Forte * all_targets 100fcf3ce44SJohn Forte * type: boolean 101fcf3ce44SJohn Forte * contains: when true, the value of target_group is 102fcf3ce44SJohn Forte * ignored 103fcf3ce44SJohn Forte * host_group 104fcf3ce44SJohn Forte * type: ustring 105fcf3ce44SJohn Forte * contains: host group for logical unit mapping and 106fcf3ce44SJohn Forte * masking purposes 107fcf3ce44SJohn Forte * target_group 108fcf3ce44SJohn Forte * type: ustring 109fcf3ce44SJohn Forte * contains: target group for logical unit mapping and 110fcf3ce44SJohn Forte * masking purposes 111fcf3ce44SJohn Forte * lu_nbr 112fcf3ce44SJohn Forte * type: opaque 113fcf3ce44SJohn Forte * contains: the 8-byte SCSI logical unit number for 114fcf3ce44SJohn Forte * mapping and masking purposes 115fcf3ce44SJohn Forte * Description: 116fcf3ce44SJohn Forte * One "view_entry-<N>-<GUID>" property group will exist for each 117fcf3ce44SJohn Forte * view entry in the system. This property group name maps 118fcf3ce44SJohn Forte * directly to the "lu-<GUID>" property group with a matching 119fcf3ce44SJohn Forte * <GUID>. 120fcf3ce44SJohn Forte * 121fcf3ce44SJohn Forte * 5. Property Group: provider_data_pg_<provider-name> 122fcf3ce44SJohn Forte * where <provider-name> is the name of the provider 123fcf3ce44SJohn Forte * registered with stmf. 124fcf3ce44SJohn Forte * Properties: provider_data_prop-<N> 125fcf3ce44SJohn Forte * where <N> is a sequential identifier for the data 126fcf3ce44SJohn Forte * chunk. 127fcf3ce44SJohn Forte * type: opaque 128fcf3ce44SJohn Forte * contains: up to STMF_PROVIDER_DATA_PROP_SIZE bytes 129fcf3ce44SJohn Forte * of nvlist packed data. 130fcf3ce44SJohn Forte * provider_data_count 131fcf3ce44SJohn Forte * type: count 132fcf3ce44SJohn Forte * contains: the number of provider data chunks 133fcf3ce44SJohn Forte * provider_data_type 134fcf3ce44SJohn Forte * type: integer 135fcf3ce44SJohn Forte * contains: STMF_PORT_PROVIDER_TYPE or 136fcf3ce44SJohn Forte * STMF_LU_PROVIDER_TYPE 137fcf3ce44SJohn Forte * 138fcf3ce44SJohn Forte * Description: 139fcf3ce44SJohn Forte * Holds the nvlist packed provider data set via 140fcf3ce44SJohn Forte * stmfSetProviderData and retrieved via stmfGetProviderData. Data 141fcf3ce44SJohn Forte * is stored in STMF_PROVIDER_DATA_PROP_SIZE chunks. On retrieve, 142fcf3ce44SJohn Forte * these chunks are reassembled and unpacked. 143fcf3ce44SJohn Forte * 144fcf3ce44SJohn Forte */ 145fcf3ce44SJohn Forte 146fcf3ce44SJohn Forte static int iPsInit(scf_handle_t **, scf_service_t **); 147fcf3ce44SJohn Forte static int iPsCreateDeleteGroup(char *, char *, int); 148fcf3ce44SJohn Forte static int iPsAddRemoveGroupMember(char *, char *, char *, int); 149fcf3ce44SJohn Forte static int iPsGetGroupList(char *, stmfGroupList **); 150fcf3ce44SJohn Forte static int iPsGetGroupMemberList(char *, char *, stmfGroupProperties **); 151fcf3ce44SJohn Forte static int iPsAddViewEntry(char *, char *, stmfViewEntry *); 152fcf3ce44SJohn Forte static int iPsAddRemoveLuViewEntry(char *, char *, int); 153fcf3ce44SJohn Forte static int iPsGetViewEntry(char *, stmfViewEntry *); 154fcf3ce44SJohn Forte static int iPsGetActualGroupName(char *, char *, char *); 155fcf3ce44SJohn Forte static int iPsGetServiceVersion(uint64_t *, scf_handle_t *, scf_service_t *); 1568fe96085Stim szeto static int iPsGetSetPersistType(uint8_t *, scf_handle_t *, scf_service_t *, 1578fe96085Stim szeto int); 1584b31676fSsrivijitha dugganapalli static int iPsGetSetStmfProp(int, char *, int); 159fcf3ce44SJohn Forte static int viewEntryCompare(const void *, const void *); 160fcf3ce44SJohn Forte static int holdSignal(sigset_t *); 161fcf3ce44SJohn Forte static int releaseSignal(sigset_t *); 162fcf3ce44SJohn Forte static void sigHandler(); 163fcf3ce44SJohn Forte 164fcf3ce44SJohn Forte static pthread_mutex_t sigSetLock = PTHREAD_MUTEX_INITIALIZER; 165fcf3ce44SJohn Forte 166fcf3ce44SJohn Forte sigset_t sigSet; 167fcf3ce44SJohn Forte sigset_t signalsCaught; 168fcf3ce44SJohn Forte 169fcf3ce44SJohn Forte struct sigaction currentActionQuit; 170fcf3ce44SJohn Forte struct sigaction currentActionTerm; 171fcf3ce44SJohn Forte struct sigaction currentActionInt; 172fcf3ce44SJohn Forte 173fcf3ce44SJohn Forte boolean_t actionSet = B_FALSE; 174fcf3ce44SJohn Forte 175fcf3ce44SJohn Forte /* 176fcf3ce44SJohn Forte * Version info for the SMF schema 177fcf3ce44SJohn Forte */ 178fcf3ce44SJohn Forte #define STMF_SMF_VERSION 1 179fcf3ce44SJohn Forte 180fcf3ce44SJohn Forte /* 1818fe96085Stim szeto * Note: Do not change these property names and size values. 1828fe96085Stim szeto * They represent fields in the persistent config and once modified 1838fe96085Stim szeto * will have a nasty side effect of invalidating the existing store. 1848fe96085Stim szeto * If you do need to change them, you'll need to use the versioning above 1858fe96085Stim szeto * to retain backward compatiblity with the previous configuration schema. 1868fe96085Stim szeto */ 1878fe96085Stim szeto 1888fe96085Stim szeto /* BEGIN STORE PROPERTY DEFINITIONS */ 1898fe96085Stim szeto /* 190fcf3ce44SJohn Forte * Property Group Names and prefixes 191fcf3ce44SJohn Forte */ 192fcf3ce44SJohn Forte #define STMF_HOST_GROUPS "host_groups" 193fcf3ce44SJohn Forte #define STMF_TARGET_GROUPS "target_groups" 194fcf3ce44SJohn Forte #define STMF_VE_PREFIX "view_entry" 195fcf3ce44SJohn Forte #define STMF_LU_PREFIX "lu" 196fcf3ce44SJohn Forte #define STMF_DATA_GROUP "stmf_data" 197fcf3ce44SJohn Forte 198fcf3ce44SJohn Forte /* 199fcf3ce44SJohn Forte * Property names and prefix for logical unit property group 200fcf3ce44SJohn Forte */ 201fcf3ce44SJohn Forte #define STMF_VE_CNT "ve_cnt" 202fcf3ce44SJohn Forte #define STMF_GROUP_PREFIX "group_name" 203fcf3ce44SJohn Forte #define STMF_MEMBER_LIST_SUFFIX "member_list" 204fcf3ce44SJohn Forte #define STMF_VERSION_NAME "version_name" 2058fe96085Stim szeto #define STMF_PERSIST_TYPE "persist_method" 206fcf3ce44SJohn Forte 2074b31676fSsrivijitha dugganapalli /* Property names for stmf properties */ 2084b31676fSsrivijitha dugganapalli 2094b31676fSsrivijitha dugganapalli #define DEFAULT_LU_STATE "default_lu_state" 2104b31676fSsrivijitha dugganapalli #define DEFAULT_TARGET_PORT_STATE "default_target_state" 2114b31676fSsrivijitha dugganapalli 212fcf3ce44SJohn Forte /* 213fcf3ce44SJohn Forte * Property names for view entry 214fcf3ce44SJohn Forte */ 215fcf3ce44SJohn Forte #define STMF_VE_ALLHOSTS "all_hosts" 216fcf3ce44SJohn Forte #define STMF_VE_HOSTGROUP "host_group" 217fcf3ce44SJohn Forte #define STMF_VE_ALLTARGETS "all_targets" 218fcf3ce44SJohn Forte #define STMF_VE_TARGETGROUP "target_group" 219fcf3ce44SJohn Forte #define STMF_VE_LUNBR "lu_nbr" 220fcf3ce44SJohn Forte 221fcf3ce44SJohn Forte /* Property group suffix for provider data */ 222fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PREFIX "provider_data_pg_" 223fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PROP_PREFIX "provider_data_prop" 224fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PROP_NAME_SIZE 256 225fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PROP_TYPE "provider_type" 226fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PROP_SET_COUNT "provider_data_set_cnt" 227fcf3ce44SJohn Forte #define STMF_PROVIDER_DATA_PROP_COUNT "provider_data_cnt" 2288fe96085Stim szeto 229fcf3ce44SJohn Forte 230fcf3ce44SJohn Forte #define STMF_SMF_READ_ATTR "solaris.smf.read.stmf" 231fcf3ce44SJohn Forte 2328fe96085Stim szeto #define STMF_PS_PERSIST_NONE "none" 2338fe96085Stim szeto #define STMF_PS_PERSIST_SMF "smf" 2348fe96085Stim szeto #define STMF_PROVIDER_DATA_PROP_SIZE 4000 2354b31676fSsrivijitha dugganapalli 2364b31676fSsrivijitha dugganapalli #define STMF_PS_LU_ONLINE "default_lu_online" 2374b31676fSsrivijitha dugganapalli #define STMF_PS_LU_OFFLINE "default_lu_offline" 2384b31676fSsrivijitha dugganapalli #define STMF_PS_TARGET_PORT_ONLINE "default_target_online" 2394b31676fSsrivijitha dugganapalli #define STMF_PS_TARGET_PORT_OFFLINE "default_target_offline" 2404b31676fSsrivijitha dugganapalli 2418fe96085Stim szeto /* END STORE PROPERTY DEFINITIONS */ 242fcf3ce44SJohn Forte 243fcf3ce44SJohn Forte /* service name */ 244fcf3ce44SJohn Forte #define STMF_SERVICE "system/stmf" 245fcf3ce44SJohn Forte 246fcf3ce44SJohn Forte /* limits and flag values */ 247fcf3ce44SJohn Forte #define GROUP_MEMBER_ALLOC 100 248fcf3ce44SJohn Forte #define VIEW_ENTRY_STRUCT_CNT 6 249fcf3ce44SJohn Forte #define VIEW_ENTRY_PG_SIZE 256 250fcf3ce44SJohn Forte #define LOGICAL_UNIT_PG_SIZE 256 251fcf3ce44SJohn Forte #define VIEW_ENTRY_MAX UINT32_MAX 252fcf3ce44SJohn Forte #define GROUP_MAX UINT64_MAX 253fcf3ce44SJohn Forte #define ADD 0 254fcf3ce44SJohn Forte #define REMOVE 1 2558fe96085Stim szeto #define GET 0 2568fe96085Stim szeto #define SET 1 257fcf3ce44SJohn Forte 258fcf3ce44SJohn Forte /* 259fcf3ce44SJohn Forte * sigHandler 260fcf3ce44SJohn Forte * 261fcf3ce44SJohn Forte * Catch the signal and set the global signalsCaught to the signal received 262fcf3ce44SJohn Forte * 263fcf3ce44SJohn Forte * signalsCaught will be used by releaseSignal to raise this signal when 264fcf3ce44SJohn Forte * we're done processing our critical code. 265fcf3ce44SJohn Forte * 266fcf3ce44SJohn Forte */ 267fcf3ce44SJohn Forte static void 268fcf3ce44SJohn Forte sigHandler(int sig) 269fcf3ce44SJohn Forte { 270fcf3ce44SJohn Forte (void) sigaddset(&signalsCaught, sig); 271fcf3ce44SJohn Forte } 272fcf3ce44SJohn Forte 273fcf3ce44SJohn Forte /* 274fcf3ce44SJohn Forte * iPsAddRemoveGroupMember 275fcf3ce44SJohn Forte * 276fcf3ce44SJohn Forte * Add or remove a member for a given group 277fcf3ce44SJohn Forte * 278fcf3ce44SJohn Forte * pgName - Property group name 279fcf3ce44SJohn Forte * groupName - group name to which the member is added/removed 280fcf3ce44SJohn Forte * memberName - member to be added/removed 281fcf3ce44SJohn Forte * addRemoveFlag - ADD/REMOVE 282fcf3ce44SJohn Forte * 283fcf3ce44SJohn Forte * returns: 284fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 285fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 286fcf3ce44SJohn Forte */ 287fcf3ce44SJohn Forte static int 288fcf3ce44SJohn Forte iPsAddRemoveGroupMember(char *pgName, char *groupName, char *memberName, 289fcf3ce44SJohn Forte int addRemoveFlag) 290fcf3ce44SJohn Forte { 291fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 292fcf3ce44SJohn Forte scf_service_t *svc = NULL; 293fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 294fcf3ce44SJohn Forte scf_property_t *prop = NULL; 295fcf3ce44SJohn Forte scf_value_t *valueLookup = NULL; 296fcf3ce44SJohn Forte scf_value_t **valueSet = NULL; 297fcf3ce44SJohn Forte scf_iter_t *valueIter = NULL; 298fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 299fcf3ce44SJohn Forte scf_transaction_entry_t *entry = NULL; 300fcf3ce44SJohn Forte int i = 0; 301fcf3ce44SJohn Forte int lastAlloc; 302fcf3ce44SJohn Forte int valueArraySize = 0; 303fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 304fcf3ce44SJohn Forte char buf[STMF_IDENT_LENGTH]; 305fcf3ce44SJohn Forte int commitRet; 306fcf3ce44SJohn Forte boolean_t found = B_FALSE; 307fcf3ce44SJohn Forte 308fcf3ce44SJohn Forte assert(pgName != NULL && groupName != NULL && memberName != NULL); 309fcf3ce44SJohn Forte 310fcf3ce44SJohn Forte /* 311fcf3ce44SJohn Forte * Init the service handle 312fcf3ce44SJohn Forte */ 313fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 314fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 315fcf3ce44SJohn Forte goto out; 316fcf3ce44SJohn Forte } 317fcf3ce44SJohn Forte 318fcf3ce44SJohn Forte /* 319fcf3ce44SJohn Forte * Allocate scf resources 320fcf3ce44SJohn Forte */ 321fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 322fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL) || 323fcf3ce44SJohn Forte ((entry = scf_entry_create(handle)) == NULL) || 324fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 325fcf3ce44SJohn Forte ((valueIter = scf_iter_create(handle)) == NULL)) { 326fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 327fcf3ce44SJohn Forte scf_strerror(scf_error())); 328fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 329fcf3ce44SJohn Forte goto out; 330fcf3ce44SJohn Forte } 331fcf3ce44SJohn Forte 332fcf3ce44SJohn Forte /* 333fcf3ce44SJohn Forte * Get the service property group handle 334fcf3ce44SJohn Forte */ 335fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 336fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 337fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 338fcf3ce44SJohn Forte } else { 339fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 340fcf3ce44SJohn Forte } 34186b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 34286b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 34386b7dbefSPeter Gill 344fcf3ce44SJohn Forte goto out; 345fcf3ce44SJohn Forte } 346fcf3ce44SJohn Forte 347fcf3ce44SJohn Forte /* 348fcf3ce44SJohn Forte * Begin the transaction 349fcf3ce44SJohn Forte */ 350fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 35186b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 35286b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 353fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 354fcf3ce44SJohn Forte goto out; 355fcf3ce44SJohn Forte } 356fcf3ce44SJohn Forte 357fcf3ce44SJohn Forte /* 358fcf3ce44SJohn Forte * We're changing an existing property by adding a propval 359fcf3ce44SJohn Forte * There are no add semantics in libscf for a property value. We'll 360fcf3ce44SJohn Forte * need to read in the current properties and apply them all to the 361fcf3ce44SJohn Forte * set and then add the one we were asked to add or omit the one 362fcf3ce44SJohn Forte * we were asked to remove. 363fcf3ce44SJohn Forte */ 364fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, entry, groupName, 365fcf3ce44SJohn Forte SCF_TYPE_USTRING) == -1) { 366fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 367fcf3ce44SJohn Forte ret = STMF_PS_ERROR_GROUP_NOT_FOUND; 368fcf3ce44SJohn Forte } else { 369fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 37086b7dbefSPeter Gill syslog(LOG_ERR, "tran property change %s/%s " 37186b7dbefSPeter Gill "failed - %s", pgName, groupName, 372fcf3ce44SJohn Forte scf_strerror(scf_error())); 373fcf3ce44SJohn Forte } 374fcf3ce44SJohn Forte goto out; 375fcf3ce44SJohn Forte } 376fcf3ce44SJohn Forte 377fcf3ce44SJohn Forte /* 378fcf3ce44SJohn Forte * Get the property handle 379fcf3ce44SJohn Forte */ 380fcf3ce44SJohn Forte if (scf_pg_get_property(pg, groupName, prop) == -1) { 38186b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 38286b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 383fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 384fcf3ce44SJohn Forte goto out; 385fcf3ce44SJohn Forte } 386fcf3ce44SJohn Forte 387fcf3ce44SJohn Forte /* 388fcf3ce44SJohn Forte * Value lookup is used to lookup the existing values 389fcf3ce44SJohn Forte */ 390fcf3ce44SJohn Forte valueLookup = scf_value_create(handle); 391fcf3ce44SJohn Forte if (valueLookup == NULL) { 39286b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s failed - %s", 39386b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 394fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 395fcf3ce44SJohn Forte goto out; 396fcf3ce44SJohn Forte } 397fcf3ce44SJohn Forte 398fcf3ce44SJohn Forte /* 399fcf3ce44SJohn Forte * valueIter is the iterator handle, create the resource 400fcf3ce44SJohn Forte */ 401fcf3ce44SJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) { 40286b7dbefSPeter Gill syslog(LOG_ERR, "iter values for %s/%s failed - %s", 40386b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 404fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 405fcf3ce44SJohn Forte goto out; 406fcf3ce44SJohn Forte } 407fcf3ce44SJohn Forte 408fcf3ce44SJohn Forte /* 409fcf3ce44SJohn Forte * Allocate value resource pointers. 410fcf3ce44SJohn Forte * We need a value resource for each value as value pointers passed 411fcf3ce44SJohn Forte * to libscf cannot be destroyed until the commit or destroy on the 412fcf3ce44SJohn Forte * transaction is done. 413fcf3ce44SJohn Forte * 414fcf3ce44SJohn Forte * We're using GROUP_MEMBER_ALLOC initially. If it's not large 415fcf3ce44SJohn Forte * enough, we'll realloc on the fly 416fcf3ce44SJohn Forte */ 417fcf3ce44SJohn Forte valueSet = (scf_value_t **)calloc(1, sizeof (*valueSet) 418fcf3ce44SJohn Forte * (lastAlloc = GROUP_MEMBER_ALLOC)); 419fcf3ce44SJohn Forte if (valueSet == NULL) { 420fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 421fcf3ce44SJohn Forte goto out; 422fcf3ce44SJohn Forte } 423fcf3ce44SJohn Forte 424fcf3ce44SJohn Forte /* 425fcf3ce44SJohn Forte * Iterate through the existing values 426fcf3ce44SJohn Forte */ 427fcf3ce44SJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) { 428fcf3ce44SJohn Forte bzero(buf, sizeof (buf)); 429fcf3ce44SJohn Forte if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) { 43086b7dbefSPeter Gill syslog(LOG_ERR, "iter %s/%s value failed - %s", 43186b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 432fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 433fcf3ce44SJohn Forte break; 434fcf3ce44SJohn Forte } 435fcf3ce44SJohn Forte 436fcf3ce44SJohn Forte /* 437fcf3ce44SJohn Forte * Check for existing 438fcf3ce44SJohn Forte * If we're adding, it's an error 439fcf3ce44SJohn Forte * If we're removing, we skip it and simply not 440fcf3ce44SJohn Forte * add it to the set. Subtraction by omission. 441fcf3ce44SJohn Forte */ 442fcf3ce44SJohn Forte if ((strlen(buf) == strlen(memberName)) && 443fcf3ce44SJohn Forte bcmp(buf, memberName, strlen(buf)) == 0) { 444fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 445fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 446fcf3ce44SJohn Forte break; 447fcf3ce44SJohn Forte } else { 448fcf3ce44SJohn Forte found = B_TRUE; 449fcf3ce44SJohn Forte continue; 450fcf3ce44SJohn Forte } 451fcf3ce44SJohn Forte } 452fcf3ce44SJohn Forte 453fcf3ce44SJohn Forte /* 454fcf3ce44SJohn Forte * Create the value resource for this iteration 455fcf3ce44SJohn Forte */ 456fcf3ce44SJohn Forte valueSet[i] = scf_value_create(handle); 457fcf3ce44SJohn Forte if (valueSet[i] == NULL) { 45886b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s failed - %s", 45986b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 460fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 461fcf3ce44SJohn Forte break; 462fcf3ce44SJohn Forte } 463fcf3ce44SJohn Forte 464fcf3ce44SJohn Forte /* 465fcf3ce44SJohn Forte * Set the value 466fcf3ce44SJohn Forte */ 467fcf3ce44SJohn Forte if (scf_value_set_ustring(valueSet[i], buf) == -1) { 46886b7dbefSPeter Gill syslog(LOG_ERR, "set value for %s/%s failed - %s", 46986b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 470fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 471fcf3ce44SJohn Forte break; 472fcf3ce44SJohn Forte } 473fcf3ce44SJohn Forte 474fcf3ce44SJohn Forte /* 475fcf3ce44SJohn Forte * Now add the value 476fcf3ce44SJohn Forte */ 477fcf3ce44SJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) { 47886b7dbefSPeter Gill syslog(LOG_ERR, "add value for %s/%s failed - %s", 47986b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 480fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 481fcf3ce44SJohn Forte break; 482fcf3ce44SJohn Forte } 483fcf3ce44SJohn Forte 484fcf3ce44SJohn Forte i++; 485fcf3ce44SJohn Forte 486fcf3ce44SJohn Forte /* 487fcf3ce44SJohn Forte * realloc if we've hit the previous alloc size 488fcf3ce44SJohn Forte */ 489fcf3ce44SJohn Forte if (i >= lastAlloc) { 490fcf3ce44SJohn Forte lastAlloc += GROUP_MEMBER_ALLOC; 491fcf3ce44SJohn Forte valueSet = realloc(valueSet, 492fcf3ce44SJohn Forte sizeof (*valueSet) * lastAlloc); 493fcf3ce44SJohn Forte if (valueSet == NULL) { 494fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 495fcf3ce44SJohn Forte break; 496fcf3ce44SJohn Forte } 497fcf3ce44SJohn Forte } 498fcf3ce44SJohn Forte } 499fcf3ce44SJohn Forte 500fcf3ce44SJohn Forte /* 501fcf3ce44SJohn Forte * set valueArraySize to final allocated length 502fcf3ce44SJohn Forte * so we can use it to destroy the resources correctly 503fcf3ce44SJohn Forte */ 504fcf3ce44SJohn Forte valueArraySize = i; 505fcf3ce44SJohn Forte 506fcf3ce44SJohn Forte if (!found && (addRemoveFlag == REMOVE)) { 507fcf3ce44SJohn Forte ret = STMF_PS_ERROR_MEMBER_NOT_FOUND; 508fcf3ce44SJohn Forte } 509fcf3ce44SJohn Forte 510fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 511fcf3ce44SJohn Forte goto out; 512fcf3ce44SJohn Forte } 513fcf3ce44SJohn Forte 514fcf3ce44SJohn Forte /* 515fcf3ce44SJohn Forte * If we're adding, we have one more step. Add the member to the 516fcf3ce44SJohn Forte * propval list 517fcf3ce44SJohn Forte */ 518fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 519fcf3ce44SJohn Forte /* 520fcf3ce44SJohn Forte * Now create the new entry 521fcf3ce44SJohn Forte */ 522fcf3ce44SJohn Forte valueSet[i] = scf_value_create(handle); 523fcf3ce44SJohn Forte if (valueSet[i] == NULL) { 52486b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s/%s failed - %s", 52586b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 526fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 527fcf3ce44SJohn Forte goto out; 528fcf3ce44SJohn Forte } else { 529fcf3ce44SJohn Forte valueArraySize++; 530fcf3ce44SJohn Forte } 531fcf3ce44SJohn Forte 532fcf3ce44SJohn Forte /* 533fcf3ce44SJohn Forte * Set the new member name 534fcf3ce44SJohn Forte */ 535fcf3ce44SJohn Forte if (scf_value_set_ustring(valueSet[i], memberName) == -1) { 53686b7dbefSPeter Gill syslog(LOG_ERR, "set value for %s/%s failed - %s", 53786b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 538fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 539fcf3ce44SJohn Forte goto out; 540fcf3ce44SJohn Forte } 541fcf3ce44SJohn Forte 542fcf3ce44SJohn Forte /* 543fcf3ce44SJohn Forte * Add the new member 544fcf3ce44SJohn Forte */ 545fcf3ce44SJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) { 54686b7dbefSPeter Gill syslog(LOG_ERR, "add value for %s/%s failed - %s", 54786b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 548fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 549fcf3ce44SJohn Forte goto out; 550fcf3ce44SJohn Forte } 551fcf3ce44SJohn Forte } 552fcf3ce44SJohn Forte 553fcf3ce44SJohn Forte /* 554fcf3ce44SJohn Forte * Yes, we're finally done. We actually added or removed one entry 555fcf3ce44SJohn Forte * from the list. 556fcf3ce44SJohn Forte * Woohoo! 557fcf3ce44SJohn Forte */ 558fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 55986b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 56086b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 561fcf3ce44SJohn Forte if (commitRet == 0) { 562fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 563fcf3ce44SJohn Forte } else { 564fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 565fcf3ce44SJohn Forte } 566fcf3ce44SJohn Forte goto out; 567fcf3ce44SJohn Forte } 568fcf3ce44SJohn Forte 569fcf3ce44SJohn Forte out: 570fcf3ce44SJohn Forte /* 571fcf3ce44SJohn Forte * Free resources 572fcf3ce44SJohn Forte */ 573fcf3ce44SJohn Forte if (handle != NULL) { 574fcf3ce44SJohn Forte scf_handle_destroy(handle); 575fcf3ce44SJohn Forte } 576fcf3ce44SJohn Forte if (svc != NULL) { 577fcf3ce44SJohn Forte scf_service_destroy(svc); 578fcf3ce44SJohn Forte } 579fcf3ce44SJohn Forte if (pg != NULL) { 580fcf3ce44SJohn Forte scf_pg_destroy(pg); 581fcf3ce44SJohn Forte } 582fcf3ce44SJohn Forte if (tran != NULL) { 583fcf3ce44SJohn Forte scf_transaction_destroy(tran); 584fcf3ce44SJohn Forte } 585fcf3ce44SJohn Forte if (entry != NULL) { 586fcf3ce44SJohn Forte scf_entry_destroy(entry); 587fcf3ce44SJohn Forte } 588fcf3ce44SJohn Forte if (prop != NULL) { 589fcf3ce44SJohn Forte scf_property_destroy(prop); 590fcf3ce44SJohn Forte } 591fcf3ce44SJohn Forte if (valueLookup != NULL) { 592fcf3ce44SJohn Forte scf_value_destroy(valueLookup); 593fcf3ce44SJohn Forte } 594fcf3ce44SJohn Forte if (valueIter != NULL) { 595fcf3ce44SJohn Forte scf_iter_destroy(valueIter); 596fcf3ce44SJohn Forte } 597fcf3ce44SJohn Forte 598fcf3ce44SJohn Forte /* 599fcf3ce44SJohn Forte * Free valueSet scf resources 600fcf3ce44SJohn Forte */ 601fcf3ce44SJohn Forte if (valueArraySize > 0) { 602fcf3ce44SJohn Forte for (i = 0; i < valueArraySize; i++) { 603fcf3ce44SJohn Forte scf_value_destroy(valueSet[i]); 604fcf3ce44SJohn Forte } 605fcf3ce44SJohn Forte } 606fcf3ce44SJohn Forte /* 607fcf3ce44SJohn Forte * Now free the pointer array to the resources 608fcf3ce44SJohn Forte */ 609fcf3ce44SJohn Forte if (valueSet != NULL) { 610fcf3ce44SJohn Forte free(valueSet); 611fcf3ce44SJohn Forte } 612fcf3ce44SJohn Forte 613fcf3ce44SJohn Forte return (ret); 614fcf3ce44SJohn Forte } 615fcf3ce44SJohn Forte 616fcf3ce44SJohn Forte /* 617fcf3ce44SJohn Forte * iPsAddRemoveLuViewEntry 618fcf3ce44SJohn Forte * 619fcf3ce44SJohn Forte * Adds or removes a view entry name property for a given logical unit 620fcf3ce44SJohn Forte * property group. There is one logical unit property group for every logical 621fcf3ce44SJohn Forte * unit that has one or more associated view entries. 622fcf3ce44SJohn Forte * 623fcf3ce44SJohn Forte * luPgName - Property group name of logical unit 624fcf3ce44SJohn Forte * viewEntryPgName - Property group name of view entry 625fcf3ce44SJohn Forte * addRemoveFlag - ADD_VE/REMOVE_VE 626fcf3ce44SJohn Forte * 627fcf3ce44SJohn Forte * returns: 628fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 629fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 630fcf3ce44SJohn Forte */ 631fcf3ce44SJohn Forte static int 632fcf3ce44SJohn Forte iPsAddRemoveLuViewEntry(char *luPgName, char *viewEntryPgName, 633fcf3ce44SJohn Forte int addRemoveFlag) 634fcf3ce44SJohn Forte { 635fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 636fcf3ce44SJohn Forte scf_service_t *svc = NULL; 637fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 638fcf3ce44SJohn Forte scf_property_t *prop = NULL; 639fcf3ce44SJohn Forte scf_value_t *value = NULL; 640fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 641fcf3ce44SJohn Forte scf_transaction_entry_t *entry = NULL; 642fcf3ce44SJohn Forte scf_transaction_entry_t *entryVeName = NULL; 643fcf3ce44SJohn Forte boolean_t createVeCnt = B_FALSE; 644fcf3ce44SJohn Forte uint64_t veCnt = 0; 645fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 646fcf3ce44SJohn Forte int commitRet; 647fcf3ce44SJohn Forte 648fcf3ce44SJohn Forte assert(luPgName != NULL || viewEntryPgName != NULL); 649fcf3ce44SJohn Forte assert(!(addRemoveFlag != ADD && addRemoveFlag != REMOVE)); 650fcf3ce44SJohn Forte 651fcf3ce44SJohn Forte /* 652fcf3ce44SJohn Forte * Init the service handle 653fcf3ce44SJohn Forte */ 654fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 655fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 656fcf3ce44SJohn Forte goto out; 657fcf3ce44SJohn Forte } 658fcf3ce44SJohn Forte 659fcf3ce44SJohn Forte /* 660fcf3ce44SJohn Forte * Allocate scf resources 661fcf3ce44SJohn Forte */ 662fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 663fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL) || 664fcf3ce44SJohn Forte ((entry = scf_entry_create(handle)) == NULL) || 665fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 666fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 667fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 668fcf3ce44SJohn Forte scf_strerror(scf_error())); 669fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 670fcf3ce44SJohn Forte goto out; 671fcf3ce44SJohn Forte } 672fcf3ce44SJohn Forte 673fcf3ce44SJohn Forte /* get the LU property group */ 674fcf3ce44SJohn Forte if (scf_service_get_pg(svc, luPgName, pg) == -1) { 675fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND && 676fcf3ce44SJohn Forte addRemoveFlag == ADD) { 677fcf3ce44SJohn Forte /* if it doesn't exist, create it */ 678fcf3ce44SJohn Forte if (scf_service_add_pg(svc, luPgName, 679fcf3ce44SJohn Forte SCF_GROUP_APPLICATION, 0, pg) == -1) { 68086b7dbefSPeter Gill syslog(LOG_ERR, "add pg %s failed - %s", 68186b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 682fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 683fcf3ce44SJohn Forte } else { 684fcf3ce44SJohn Forte /* we need to create the VE_CNT property */ 685fcf3ce44SJohn Forte createVeCnt = B_TRUE; 686fcf3ce44SJohn Forte ret = STMF_PS_SUCCESS; 687fcf3ce44SJohn Forte } 688fcf3ce44SJohn Forte } else if (scf_error() == SCF_ERROR_NOT_FOUND) { 689fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 690fcf3ce44SJohn Forte } else { 69186b7dbefSPeter Gill syslog(LOG_ERR, "get lu pg %s failed - %s", 69286b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 693fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 694fcf3ce44SJohn Forte } 695fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 696fcf3ce44SJohn Forte goto out; 697fcf3ce44SJohn Forte } 698fcf3ce44SJohn Forte } 699fcf3ce44SJohn Forte 700fcf3ce44SJohn Forte 701fcf3ce44SJohn Forte /* 702fcf3ce44SJohn Forte * Begin the transaction 703fcf3ce44SJohn Forte */ 704fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 70586b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 70686b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 707fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 708fcf3ce44SJohn Forte goto out; 709fcf3ce44SJohn Forte } 710fcf3ce44SJohn Forte 711fcf3ce44SJohn Forte 712fcf3ce44SJohn Forte if (createVeCnt) { 713fcf3ce44SJohn Forte /* 714fcf3ce44SJohn Forte * Create the STMF_VE_CNT property. This will keep the current 715fcf3ce44SJohn Forte * total view entries for this logical unit. 716fcf3ce44SJohn Forte */ 717fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry, STMF_VE_CNT, 718fcf3ce44SJohn Forte SCF_TYPE_COUNT) == -1) { 719fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 720fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 721fcf3ce44SJohn Forte } else { 722fcf3ce44SJohn Forte syslog(LOG_ERR, 72386b7dbefSPeter Gill "transaction property new %s/%s " 72486b7dbefSPeter Gill "failed - %s", luPgName, STMF_VE_CNT, 725fcf3ce44SJohn Forte scf_strerror(scf_error())); 726fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 727fcf3ce44SJohn Forte } 728fcf3ce44SJohn Forte goto out; 729fcf3ce44SJohn Forte } 730fcf3ce44SJohn Forte } else { 731fcf3ce44SJohn Forte /* 732fcf3ce44SJohn Forte * The STMF_VE_CNT property already exists. Just update 733fcf3ce44SJohn Forte * it. 734fcf3ce44SJohn Forte */ 735fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, entry, 736fcf3ce44SJohn Forte STMF_VE_CNT, SCF_TYPE_COUNT) == -1) { 73786b7dbefSPeter Gill syslog(LOG_ERR, "transaction property %s/%s change " 73886b7dbefSPeter Gill "failed - %s", luPgName, STMF_VE_CNT, 739fcf3ce44SJohn Forte scf_strerror(scf_error())); 740fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 741fcf3ce44SJohn Forte goto out; 742fcf3ce44SJohn Forte } 743fcf3ce44SJohn Forte 744fcf3ce44SJohn Forte /* 745fcf3ce44SJohn Forte * Get the STMF_VE_CNT property 746fcf3ce44SJohn Forte */ 747fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_CNT, prop) == -1) { 74886b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 74986b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 750fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 751fcf3ce44SJohn Forte goto out; 752fcf3ce44SJohn Forte } 753fcf3ce44SJohn Forte 754fcf3ce44SJohn Forte /* 755fcf3ce44SJohn Forte * Get the STMF_VE_CNT value 756fcf3ce44SJohn Forte */ 757fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 75886b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s value failed - %s", 75986b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 760fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 761fcf3ce44SJohn Forte goto out; 762fcf3ce44SJohn Forte } 763fcf3ce44SJohn Forte 764fcf3ce44SJohn Forte /* 765fcf3ce44SJohn Forte * Now get the actual value from the value handle 766fcf3ce44SJohn Forte */ 767fcf3ce44SJohn Forte if (scf_value_get_count(value, &veCnt) == -1) { 76886b7dbefSPeter Gill syslog(LOG_ERR, "get count value %s/%s failed - %s", 76986b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 770fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 771fcf3ce44SJohn Forte goto out; 772fcf3ce44SJohn Forte } 773fcf3ce44SJohn Forte 774fcf3ce44SJohn Forte /* 775fcf3ce44SJohn Forte * Reset the value resource as it is used below 776fcf3ce44SJohn Forte */ 777fcf3ce44SJohn Forte scf_value_reset(value); 778fcf3ce44SJohn Forte } 779fcf3ce44SJohn Forte 780fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 781fcf3ce44SJohn Forte veCnt++; 782fcf3ce44SJohn Forte } else { 783fcf3ce44SJohn Forte /* Check if this is the last one being removed */ 784fcf3ce44SJohn Forte if (veCnt == 1) { 785fcf3ce44SJohn Forte /* 786fcf3ce44SJohn Forte * Delete the pg and get out if this is the last 787fcf3ce44SJohn Forte * view entry 788fcf3ce44SJohn Forte */ 789fcf3ce44SJohn Forte if (scf_pg_delete(pg) == -1) { 79086b7dbefSPeter Gill syslog(LOG_ERR, "delete pg %s failed - %s", 79186b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 79286b7dbefSPeter Gill 793fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 794fcf3ce44SJohn Forte } 795fcf3ce44SJohn Forte goto out; 796fcf3ce44SJohn Forte } else { 797fcf3ce44SJohn Forte veCnt--; 798fcf3ce44SJohn Forte } 799fcf3ce44SJohn Forte } 800fcf3ce44SJohn Forte 801fcf3ce44SJohn Forte 802fcf3ce44SJohn Forte /* 803fcf3ce44SJohn Forte * Set the view entry count 804fcf3ce44SJohn Forte */ 805fcf3ce44SJohn Forte scf_value_set_count(value, veCnt); 806fcf3ce44SJohn Forte 807fcf3ce44SJohn Forte /* 808fcf3ce44SJohn Forte * Add the value to the transaction entry 809fcf3ce44SJohn Forte */ 810fcf3ce44SJohn Forte if (scf_entry_add_value(entry, value) == -1) { 81186b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 81286b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 813fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 814fcf3ce44SJohn Forte goto out; 815fcf3ce44SJohn Forte } 816fcf3ce44SJohn Forte 817fcf3ce44SJohn Forte /* 818fcf3ce44SJohn Forte * Create a transaction entry resource for the view entry name 819fcf3ce44SJohn Forte */ 820fcf3ce44SJohn Forte entryVeName = scf_entry_create(handle); 821fcf3ce44SJohn Forte if (entryVeName == NULL) { 82286b7dbefSPeter Gill syslog(LOG_ERR, "scf transaction entry alloc %s/%s failed - %s", 82386b7dbefSPeter Gill luPgName, viewEntryPgName, scf_strerror(scf_error())); 824fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 825fcf3ce44SJohn Forte goto out; 826fcf3ce44SJohn Forte } 827fcf3ce44SJohn Forte 828fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 829fcf3ce44SJohn Forte /* 830fcf3ce44SJohn Forte * If adding, create a property with the view entry name 831fcf3ce44SJohn Forte */ 832fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entryVeName, 833fcf3ce44SJohn Forte viewEntryPgName, SCF_TYPE_USTRING) == -1) { 834fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 835fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 836fcf3ce44SJohn Forte } else { 837fcf3ce44SJohn Forte syslog(LOG_ERR, 83886b7dbefSPeter Gill "transaction property new %s/%s " 83986b7dbefSPeter Gill "failed - %s", luPgName, viewEntryPgName, 840fcf3ce44SJohn Forte scf_strerror(scf_error())); 841fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 842fcf3ce44SJohn Forte } 843fcf3ce44SJohn Forte goto out; 844fcf3ce44SJohn Forte } 845fcf3ce44SJohn Forte } else { 846fcf3ce44SJohn Forte /* 847fcf3ce44SJohn Forte * If removing, delete the existing property with the view 848fcf3ce44SJohn Forte * entry name 849fcf3ce44SJohn Forte */ 850fcf3ce44SJohn Forte if (scf_transaction_property_delete(tran, entryVeName, 851fcf3ce44SJohn Forte viewEntryPgName) == -1) { 852fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 853fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 854fcf3ce44SJohn Forte } else { 855fcf3ce44SJohn Forte syslog(LOG_ERR, 85686b7dbefSPeter Gill "transaction property delete %s/%s " 85786b7dbefSPeter Gill "failed - %s", luPgName, viewEntryPgName, 858fcf3ce44SJohn Forte scf_strerror(scf_error())); 859fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 860fcf3ce44SJohn Forte } 861fcf3ce44SJohn Forte goto out; 862fcf3ce44SJohn Forte } 863fcf3ce44SJohn Forte } 864fcf3ce44SJohn Forte 865fcf3ce44SJohn Forte /* 866fcf3ce44SJohn Forte * Commit property transaction 867fcf3ce44SJohn Forte */ 868fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 86986b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 87086b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 871fcf3ce44SJohn Forte if (commitRet == 0) { 872fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 873fcf3ce44SJohn Forte } else { 874fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 875fcf3ce44SJohn Forte } 876fcf3ce44SJohn Forte goto out; 877fcf3ce44SJohn Forte } 878fcf3ce44SJohn Forte 879fcf3ce44SJohn Forte out: 880fcf3ce44SJohn Forte /* 881fcf3ce44SJohn Forte * Free resources 882fcf3ce44SJohn Forte */ 883fcf3ce44SJohn Forte if (handle != NULL) { 884fcf3ce44SJohn Forte scf_handle_destroy(handle); 885fcf3ce44SJohn Forte } 886fcf3ce44SJohn Forte if (svc != NULL) { 887fcf3ce44SJohn Forte scf_service_destroy(svc); 888fcf3ce44SJohn Forte } 889fcf3ce44SJohn Forte if (pg != NULL) { 890fcf3ce44SJohn Forte scf_pg_destroy(pg); 891fcf3ce44SJohn Forte } 892fcf3ce44SJohn Forte if (tran != NULL) { 893fcf3ce44SJohn Forte scf_transaction_destroy(tran); 894fcf3ce44SJohn Forte } 895fcf3ce44SJohn Forte if (entry != NULL) { 896fcf3ce44SJohn Forte scf_entry_destroy(entry); 897fcf3ce44SJohn Forte } 898fcf3ce44SJohn Forte if (entryVeName != NULL) { 899fcf3ce44SJohn Forte scf_entry_destroy(entryVeName); 900fcf3ce44SJohn Forte } 901fcf3ce44SJohn Forte if (prop != NULL) { 902fcf3ce44SJohn Forte scf_property_destroy(prop); 903fcf3ce44SJohn Forte } 904fcf3ce44SJohn Forte if (value != NULL) { 905fcf3ce44SJohn Forte scf_value_destroy(value); 906fcf3ce44SJohn Forte } 907fcf3ce44SJohn Forte 908fcf3ce44SJohn Forte return (ret); 909fcf3ce44SJohn Forte } 910fcf3ce44SJohn Forte 911fcf3ce44SJohn Forte /* 912fcf3ce44SJohn Forte * iPsAddViewEntry 913fcf3ce44SJohn Forte * 914fcf3ce44SJohn Forte * Add a view entry property group and optionally, a logical unit property 915fcf3ce44SJohn Forte * group if it does not exist. 916fcf3ce44SJohn Forte * 917fcf3ce44SJohn Forte * luName - ascii hexadecimal logical unit identifier 918fcf3ce44SJohn Forte * viewEntryName - name of view entry (VIEW_ENTRY_nn) 919fcf3ce44SJohn Forte * viewEntry - pointer to stmfViewEntry structure 920fcf3ce44SJohn Forte */ 921fcf3ce44SJohn Forte static int 922fcf3ce44SJohn Forte iPsAddViewEntry(char *luPgName, char *viewEntryPgName, stmfViewEntry *viewEntry) 923fcf3ce44SJohn Forte { 924fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 925fcf3ce44SJohn Forte scf_service_t *svc = NULL; 926fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 927fcf3ce44SJohn Forte scf_value_t *value[VIEW_ENTRY_STRUCT_CNT]; 928fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 929fcf3ce44SJohn Forte scf_transaction_entry_t *entry[VIEW_ENTRY_STRUCT_CNT]; 930fcf3ce44SJohn Forte int i = 0; 931fcf3ce44SJohn Forte int j = 0; 932fcf3ce44SJohn Forte int ret; 933fcf3ce44SJohn Forte uint8_t scfBool; 934fcf3ce44SJohn Forte boolean_t createdVePg = B_FALSE; 935fcf3ce44SJohn Forte int backoutRet; 936fcf3ce44SJohn Forte int commitRet; 937fcf3ce44SJohn Forte 938fcf3ce44SJohn Forte assert(luPgName != NULL || viewEntryPgName != NULL || 939fcf3ce44SJohn Forte viewEntry == NULL); 940fcf3ce44SJohn Forte 941fcf3ce44SJohn Forte bzero(value, sizeof (value)); 942fcf3ce44SJohn Forte bzero(entry, sizeof (entry)); 943fcf3ce44SJohn Forte 944fcf3ce44SJohn Forte /* 945fcf3ce44SJohn Forte * Init the service handle 946fcf3ce44SJohn Forte */ 947fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 948fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 949fcf3ce44SJohn Forte goto out; 950fcf3ce44SJohn Forte } 951fcf3ce44SJohn Forte 952fcf3ce44SJohn Forte /* 953fcf3ce44SJohn Forte * Allocate scf resources 954fcf3ce44SJohn Forte */ 955fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 956fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL)) { 957fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 958fcf3ce44SJohn Forte scf_strerror(scf_error())); 959fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 960fcf3ce44SJohn Forte goto out; 961fcf3ce44SJohn Forte } 962fcf3ce44SJohn Forte 963fcf3ce44SJohn Forte /* 964fcf3ce44SJohn Forte * allocate value and entry resources for scf 965fcf3ce44SJohn Forte */ 966fcf3ce44SJohn Forte for (i = 0; i < VIEW_ENTRY_STRUCT_CNT; i++) { 967fcf3ce44SJohn Forte if (((value[i] = scf_value_create(handle)) == NULL) || 968fcf3ce44SJohn Forte ((entry[i] = scf_entry_create(handle)) == NULL)) { 969fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 970fcf3ce44SJohn Forte scf_strerror(scf_error())); 971fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 972fcf3ce44SJohn Forte goto out; 973fcf3ce44SJohn Forte } 974fcf3ce44SJohn Forte } 975fcf3ce44SJohn Forte 976fcf3ce44SJohn Forte i = 0; 977fcf3ce44SJohn Forte 978fcf3ce44SJohn Forte /* 979fcf3ce44SJohn Forte * Create the View Entry property group 980fcf3ce44SJohn Forte */ 981fcf3ce44SJohn Forte if (scf_service_add_pg(svc, viewEntryPgName, SCF_GROUP_APPLICATION, 982fcf3ce44SJohn Forte 0, pg) == -1) { 983fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 984fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 985fcf3ce44SJohn Forte } else { 98686b7dbefSPeter Gill syslog(LOG_ERR, "add pg %s failed - %s", 98786b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 988fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 989fcf3ce44SJohn Forte } 990fcf3ce44SJohn Forte goto out; 991fcf3ce44SJohn Forte } 992fcf3ce44SJohn Forte 993fcf3ce44SJohn Forte createdVePg = B_TRUE; 994fcf3ce44SJohn Forte 995fcf3ce44SJohn Forte /* 996fcf3ce44SJohn Forte * Add the view entry as properties on the view entry group 997fcf3ce44SJohn Forte */ 998fcf3ce44SJohn Forte 999fcf3ce44SJohn Forte /* 1000fcf3ce44SJohn Forte * Begin property update transaction 1001fcf3ce44SJohn Forte */ 1002fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 100386b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for add %s failed - %s", 100486b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 1005fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1006fcf3ce44SJohn Forte goto out; 1007fcf3ce44SJohn Forte } 1008fcf3ce44SJohn Forte 1009fcf3ce44SJohn Forte /* 1010fcf3ce44SJohn Forte * Add allHosts property 1011fcf3ce44SJohn Forte */ 1012fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry[i], 1013fcf3ce44SJohn Forte STMF_VE_ALLHOSTS, SCF_TYPE_BOOLEAN) == -1) { 1014fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 1015fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1016fcf3ce44SJohn Forte } else { 101786b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 101886b7dbefSPeter Gill "failed - %s", viewEntryPgName, STMF_VE_ALLHOSTS, 1019fcf3ce44SJohn Forte scf_strerror(scf_error())); 1020fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1021fcf3ce44SJohn Forte } 1022fcf3ce44SJohn Forte goto out; 1023fcf3ce44SJohn Forte } 1024fcf3ce44SJohn Forte 1025fcf3ce44SJohn Forte /* Set the allHosts value */ 1026fcf3ce44SJohn Forte scfBool = viewEntry->allHosts; 1027fcf3ce44SJohn Forte scf_value_set_boolean(value[i], scfBool); 1028fcf3ce44SJohn Forte 1029fcf3ce44SJohn Forte /* 1030fcf3ce44SJohn Forte * Add the allHosts value to the transaction 1031fcf3ce44SJohn Forte */ 1032fcf3ce44SJohn Forte if (scf_entry_add_value(entry[i], value[i]) == -1) { 103386b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 103486b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLHOSTS, 1035fcf3ce44SJohn Forte scf_strerror(scf_error())); 1036fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1037fcf3ce44SJohn Forte goto out; 1038fcf3ce44SJohn Forte } 1039fcf3ce44SJohn Forte 1040fcf3ce44SJohn Forte i++; 1041fcf3ce44SJohn Forte 1042fcf3ce44SJohn Forte /* 1043fcf3ce44SJohn Forte * Create hostGroup property 1044fcf3ce44SJohn Forte */ 1045fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry[i], 1046fcf3ce44SJohn Forte STMF_VE_HOSTGROUP, SCF_TYPE_USTRING) == -1) { 1047fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 1048fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1049fcf3ce44SJohn Forte } else { 105086b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 105186b7dbefSPeter Gill "failed - %s", viewEntryPgName, STMF_VE_HOSTGROUP, 1052fcf3ce44SJohn Forte scf_strerror(scf_error())); 1053fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1054fcf3ce44SJohn Forte } 1055fcf3ce44SJohn Forte goto out; 1056fcf3ce44SJohn Forte } 1057fcf3ce44SJohn Forte 1058fcf3ce44SJohn Forte /* 1059fcf3ce44SJohn Forte * Set the value for hostGroup 1060fcf3ce44SJohn Forte */ 1061fcf3ce44SJohn Forte if (scf_value_set_ustring(value[i], viewEntry->hostGroup) == -1) { 106286b7dbefSPeter Gill syslog(LOG_ERR, "set value %s/%s failed - %s", 106386b7dbefSPeter Gill viewEntryPgName, STMF_VE_HOSTGROUP, 1064fcf3ce44SJohn Forte scf_strerror(scf_error())); 1065fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1066fcf3ce44SJohn Forte goto out; 1067fcf3ce44SJohn Forte } 1068fcf3ce44SJohn Forte 1069fcf3ce44SJohn Forte /* 1070fcf3ce44SJohn Forte * Add the hostGroup value to the transaction entry 1071fcf3ce44SJohn Forte */ 1072fcf3ce44SJohn Forte if (scf_entry_add_value(entry[i], value[i]) == -1) { 107386b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 107486b7dbefSPeter Gill viewEntryPgName, STMF_VE_HOSTGROUP, 1075fcf3ce44SJohn Forte scf_strerror(scf_error())); 1076fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1077fcf3ce44SJohn Forte goto out; 1078fcf3ce44SJohn Forte } 1079fcf3ce44SJohn Forte 1080fcf3ce44SJohn Forte i++; 1081fcf3ce44SJohn Forte 1082fcf3ce44SJohn Forte /* 1083fcf3ce44SJohn Forte * Create the allTargets property 1084fcf3ce44SJohn Forte */ 1085fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry[i], 1086fcf3ce44SJohn Forte STMF_VE_ALLTARGETS, SCF_TYPE_BOOLEAN) == -1) { 1087fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 1088fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1089fcf3ce44SJohn Forte } else { 109086b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 109186b7dbefSPeter Gill "failed - %s", viewEntryPgName, STMF_VE_ALLTARGETS, 1092fcf3ce44SJohn Forte scf_strerror(scf_error())); 1093fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1094fcf3ce44SJohn Forte } 1095fcf3ce44SJohn Forte goto out; 1096fcf3ce44SJohn Forte } 1097fcf3ce44SJohn Forte 1098fcf3ce44SJohn Forte /* 1099fcf3ce44SJohn Forte * Set the allTargets value 1100fcf3ce44SJohn Forte */ 1101fcf3ce44SJohn Forte scfBool = viewEntry->allTargets; 1102fcf3ce44SJohn Forte scf_value_set_boolean(value[i], scfBool); 1103fcf3ce44SJohn Forte 1104fcf3ce44SJohn Forte /* 1105fcf3ce44SJohn Forte * Add the allTargets value to the transaction 1106fcf3ce44SJohn Forte */ 1107fcf3ce44SJohn Forte if (scf_entry_add_value(entry[i], value[i]) == -1) { 110886b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 110986b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLTARGETS, 1110fcf3ce44SJohn Forte scf_strerror(scf_error())); 1111fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1112fcf3ce44SJohn Forte goto out; 1113fcf3ce44SJohn Forte } 1114fcf3ce44SJohn Forte 1115fcf3ce44SJohn Forte i++; 1116fcf3ce44SJohn Forte 1117fcf3ce44SJohn Forte /* 1118fcf3ce44SJohn Forte * Create targetGroup property 1119fcf3ce44SJohn Forte */ 1120fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry[i], 1121fcf3ce44SJohn Forte STMF_VE_TARGETGROUP, SCF_TYPE_USTRING) == -1) { 1122fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 1123fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1124fcf3ce44SJohn Forte } else { 112586b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 112686b7dbefSPeter Gill "failed - %s", viewEntryPgName, 112786b7dbefSPeter Gill STMF_VE_TARGETGROUP, scf_strerror(scf_error())); 1128fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1129fcf3ce44SJohn Forte } 1130fcf3ce44SJohn Forte goto out; 1131fcf3ce44SJohn Forte } 1132fcf3ce44SJohn Forte 1133fcf3ce44SJohn Forte /* 1134fcf3ce44SJohn Forte * Set the value for targetGroup 1135fcf3ce44SJohn Forte */ 1136fcf3ce44SJohn Forte if (scf_value_set_ustring(value[i], viewEntry->targetGroup) == -1) { 113786b7dbefSPeter Gill syslog(LOG_ERR, "set value %s/%s failed - %s", 113886b7dbefSPeter Gill viewEntryPgName, STMF_VE_TARGETGROUP, 1139fcf3ce44SJohn Forte scf_strerror(scf_error())); 1140fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1141fcf3ce44SJohn Forte goto out; 1142fcf3ce44SJohn Forte } 1143fcf3ce44SJohn Forte 1144fcf3ce44SJohn Forte /* 1145fcf3ce44SJohn Forte * Add targetGroup value to the transaction 1146fcf3ce44SJohn Forte */ 1147fcf3ce44SJohn Forte if (scf_entry_add_value(entry[i], value[i]) == -1) { 114886b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 114986b7dbefSPeter Gill viewEntryPgName, STMF_VE_TARGETGROUP, 1150fcf3ce44SJohn Forte scf_strerror(scf_error())); 1151fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1152fcf3ce44SJohn Forte goto out; 1153fcf3ce44SJohn Forte } 1154fcf3ce44SJohn Forte 1155fcf3ce44SJohn Forte i++; 1156fcf3ce44SJohn Forte 1157fcf3ce44SJohn Forte /* 1158fcf3ce44SJohn Forte * Create the luNbr property 1159fcf3ce44SJohn Forte */ 1160fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry[i], STMF_VE_LUNBR, 1161fcf3ce44SJohn Forte SCF_TYPE_OPAQUE) == -1) { 1162fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 1163fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1164fcf3ce44SJohn Forte } else { 116586b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 116686b7dbefSPeter Gill "failed - %s", viewEntryPgName, STMF_VE_LUNBR, 1167fcf3ce44SJohn Forte scf_strerror(scf_error())); 1168fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1169fcf3ce44SJohn Forte } 1170fcf3ce44SJohn Forte goto out; 1171fcf3ce44SJohn Forte } 1172fcf3ce44SJohn Forte 1173fcf3ce44SJohn Forte /* 1174fcf3ce44SJohn Forte * Set the luNbr 1175fcf3ce44SJohn Forte */ 1176fcf3ce44SJohn Forte if (scf_value_set_opaque(value[i], (char *)viewEntry->luNbr, 1177fcf3ce44SJohn Forte sizeof (viewEntry->luNbr)) == -1) { 117886b7dbefSPeter Gill syslog(LOG_ERR, "set value %s/%s failed - %s", 117986b7dbefSPeter Gill viewEntryPgName, STMF_VE_LUNBR, scf_strerror(scf_error())); 1180fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1181fcf3ce44SJohn Forte goto out; 1182fcf3ce44SJohn Forte } 1183fcf3ce44SJohn Forte 1184fcf3ce44SJohn Forte /* 1185fcf3ce44SJohn Forte * Add luNbr to the transaction entry 1186fcf3ce44SJohn Forte */ 1187fcf3ce44SJohn Forte if (scf_entry_add_value(entry[i], value[i]) == -1) { 118886b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 118986b7dbefSPeter Gill viewEntryPgName, STMF_VE_LUNBR, scf_strerror(scf_error())); 1190fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1191fcf3ce44SJohn Forte goto out; 1192fcf3ce44SJohn Forte } 1193fcf3ce44SJohn Forte 1194fcf3ce44SJohn Forte /* 1195fcf3ce44SJohn Forte * Now that we've successfully added the view entry, 1196fcf3ce44SJohn Forte * update the logical unit property group or create 1197fcf3ce44SJohn Forte * it if it does not exist 1198fcf3ce44SJohn Forte */ 1199fcf3ce44SJohn Forte ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName, ADD); 1200fcf3ce44SJohn Forte 1201fcf3ce44SJohn Forte /* 1202fcf3ce44SJohn Forte * If we did not add the view entry name to the logical unit, 1203fcf3ce44SJohn Forte * make sure we do not commit the transaction 1204fcf3ce44SJohn Forte */ 1205fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1206fcf3ce44SJohn Forte goto out; 1207fcf3ce44SJohn Forte } 1208fcf3ce44SJohn Forte 1209fcf3ce44SJohn Forte /* 1210fcf3ce44SJohn Forte * Commit property transaction 1211fcf3ce44SJohn Forte */ 1212fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 121386b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for add %s failed - %s", 121486b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 1215fcf3ce44SJohn Forte if (commitRet == 0) { 1216fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 1217fcf3ce44SJohn Forte } else { 1218fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1219fcf3ce44SJohn Forte } 1220fcf3ce44SJohn Forte } 1221fcf3ce44SJohn Forte 1222fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1223fcf3ce44SJohn Forte /* 1224fcf3ce44SJohn Forte * If we did not commit, try to remove the view entry name 1225fcf3ce44SJohn Forte * from the logical unit. 1226fcf3ce44SJohn Forte * If that fails, we're now inconsistent. 1227fcf3ce44SJohn Forte */ 1228fcf3ce44SJohn Forte backoutRet = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName, 1229fcf3ce44SJohn Forte REMOVE); 1230fcf3ce44SJohn Forte 1231fcf3ce44SJohn Forte if (backoutRet != STMF_PS_SUCCESS) { 123286b7dbefSPeter Gill syslog(LOG_ERR, "remove lu view entry %s failed" 123386b7dbefSPeter Gill "possible inconsistency - %s", luPgName, 1234fcf3ce44SJohn Forte scf_strerror(scf_error())); 1235fcf3ce44SJohn Forte } 1236fcf3ce44SJohn Forte /* 1237fcf3ce44SJohn Forte * We are still in an error scenario even though the remove 1238fcf3ce44SJohn Forte * lu view entry succeeded. 1239fcf3ce44SJohn Forte */ 1240fcf3ce44SJohn Forte goto out; 1241fcf3ce44SJohn Forte } 1242fcf3ce44SJohn Forte 1243fcf3ce44SJohn Forte out: 1244fcf3ce44SJohn Forte /* 1245fcf3ce44SJohn Forte * Free resources 1246fcf3ce44SJohn Forte */ 1247fcf3ce44SJohn Forte if (handle != NULL) { 1248fcf3ce44SJohn Forte scf_handle_destroy(handle); 1249fcf3ce44SJohn Forte } 1250fcf3ce44SJohn Forte if (svc != NULL) { 1251fcf3ce44SJohn Forte scf_service_destroy(svc); 1252fcf3ce44SJohn Forte } 1253fcf3ce44SJohn Forte /* if there was an error, delete the created pg if one was created */ 1254fcf3ce44SJohn Forte if ((ret != STMF_PS_SUCCESS) && createdVePg) { 1255fcf3ce44SJohn Forte if (scf_pg_delete(pg) == -1) { 125686b7dbefSPeter Gill syslog(LOG_ERR, "delete VE pg %s failed - %s", 125786b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 1258fcf3ce44SJohn Forte } 1259fcf3ce44SJohn Forte } 1260fcf3ce44SJohn Forte if (pg != NULL) { 1261fcf3ce44SJohn Forte scf_pg_destroy(pg); 1262fcf3ce44SJohn Forte } 1263fcf3ce44SJohn Forte if (tran != NULL) { 1264fcf3ce44SJohn Forte scf_transaction_destroy(tran); 1265fcf3ce44SJohn Forte } 1266fcf3ce44SJohn Forte /* 1267fcf3ce44SJohn Forte * Free value and entry scf resources 1268fcf3ce44SJohn Forte */ 1269fcf3ce44SJohn Forte if (i > 0) { 1270fcf3ce44SJohn Forte for (j = 0; j < VIEW_ENTRY_STRUCT_CNT; j++) { 1271fcf3ce44SJohn Forte if (value[j] != NULL) 1272fcf3ce44SJohn Forte scf_value_destroy(value[j]); 1273fcf3ce44SJohn Forte if (entry[j] != NULL) 1274fcf3ce44SJohn Forte scf_entry_destroy(entry[j]); 1275fcf3ce44SJohn Forte } 1276fcf3ce44SJohn Forte } 1277fcf3ce44SJohn Forte 1278fcf3ce44SJohn Forte return (ret); 1279fcf3ce44SJohn Forte } 1280fcf3ce44SJohn Forte /* 1281fcf3ce44SJohn Forte * psClearProviderData 1282fcf3ce44SJohn Forte * 1283fcf3ce44SJohn Forte * providerName - name of provider data to clear 1284fcf3ce44SJohn Forte */ 1285fcf3ce44SJohn Forte int 1286fcf3ce44SJohn Forte psClearProviderData(char *providerName, int providerType) 1287fcf3ce44SJohn Forte { 1288fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 1289fcf3ce44SJohn Forte scf_service_t *svc = NULL; 1290fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 1291fcf3ce44SJohn Forte char pgName[MAXPATHLEN]; 1292fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 1293fcf3ce44SJohn Forte boolean_t pgNotFound = B_FALSE; 1294fcf3ce44SJohn Forte 1295fcf3ce44SJohn Forte if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE && 1296fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE)) { 1297fcf3ce44SJohn Forte ret = STMF_PS_ERROR_INVALID_ARG; 1298fcf3ce44SJohn Forte goto out; 1299fcf3ce44SJohn Forte } 1300fcf3ce44SJohn Forte 1301fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 1302fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1303fcf3ce44SJohn Forte goto out; 1304fcf3ce44SJohn Forte } 1305fcf3ce44SJohn Forte 1306fcf3ce44SJohn Forte /* 1307fcf3ce44SJohn Forte * Allocate scf resources 1308fcf3ce44SJohn Forte */ 1309fcf3ce44SJohn Forte if ((pg = scf_pg_create(handle)) == NULL) { 1310fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 1311fcf3ce44SJohn Forte scf_strerror(scf_error())); 1312fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1313fcf3ce44SJohn Forte goto out; 1314fcf3ce44SJohn Forte } 1315fcf3ce44SJohn Forte 1316fcf3ce44SJohn Forte /* 1317fcf3ce44SJohn Forte * create the property group name 1318fcf3ce44SJohn Forte */ 1319fcf3ce44SJohn Forte (void) snprintf(pgName, sizeof (pgName), "%s%s", 1320fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PREFIX, providerName); 1321fcf3ce44SJohn Forte 1322fcf3ce44SJohn Forte /* 1323fcf3ce44SJohn Forte * delete provider property group 1324fcf3ce44SJohn Forte */ 1325fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 1326fcf3ce44SJohn Forte if (scf_error() != SCF_ERROR_NOT_FOUND) { 132786b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 132886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1329fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1330fcf3ce44SJohn Forte goto out; 1331fcf3ce44SJohn Forte } else { 1332fcf3ce44SJohn Forte pgNotFound = B_TRUE; 1333fcf3ce44SJohn Forte } 1334fcf3ce44SJohn Forte } 1335fcf3ce44SJohn Forte 1336fcf3ce44SJohn Forte if (!pgNotFound && (scf_pg_delete(pg) == -1)) { 133786b7dbefSPeter Gill syslog(LOG_ERR, "delete pg %s failed - %s", 133886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1339fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1340fcf3ce44SJohn Forte goto out; 1341fcf3ce44SJohn Forte } 1342fcf3ce44SJohn Forte 1343fcf3ce44SJohn Forte if (pgNotFound) { 1344fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 1345fcf3ce44SJohn Forte } 1346fcf3ce44SJohn Forte 1347fcf3ce44SJohn Forte out: 1348fcf3ce44SJohn Forte /* 1349fcf3ce44SJohn Forte * Free resources 1350fcf3ce44SJohn Forte */ 1351fcf3ce44SJohn Forte if (handle != NULL) { 1352fcf3ce44SJohn Forte scf_handle_destroy(handle); 1353fcf3ce44SJohn Forte } 1354fcf3ce44SJohn Forte if (svc != NULL) { 1355fcf3ce44SJohn Forte scf_service_destroy(svc); 1356fcf3ce44SJohn Forte } 1357fcf3ce44SJohn Forte if (pg != NULL) { 1358fcf3ce44SJohn Forte scf_pg_destroy(pg); 1359fcf3ce44SJohn Forte } 1360fcf3ce44SJohn Forte 1361fcf3ce44SJohn Forte return (ret); 1362fcf3ce44SJohn Forte } 1363fcf3ce44SJohn Forte 1364fcf3ce44SJohn Forte /* 1365fcf3ce44SJohn Forte * iPsCreateDeleteGroup 1366fcf3ce44SJohn Forte * 1367fcf3ce44SJohn Forte * Creates or deletes a group (target or host) 1368fcf3ce44SJohn Forte * 1369fcf3ce44SJohn Forte * When creating a group, two properties are created. One to hold the group 1370fcf3ce44SJohn Forte * name and the other to hold the group members. 1371fcf3ce44SJohn Forte * 1372fcf3ce44SJohn Forte * pgName - Property group name 1373fcf3ce44SJohn Forte * groupName - group name to create 1374fcf3ce44SJohn Forte * addRemoveFlag - ADD_GROUP/REMOVE_GROUP 1375fcf3ce44SJohn Forte * 1376fcf3ce44SJohn Forte * returns: 1377fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 1378fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 1379fcf3ce44SJohn Forte */ 1380fcf3ce44SJohn Forte static int 1381fcf3ce44SJohn Forte iPsCreateDeleteGroup(char *pgRefName, char *groupName, int addRemoveFlag) 1382fcf3ce44SJohn Forte { 1383fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 1384fcf3ce44SJohn Forte scf_service_t *svc = NULL; 1385fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 1386fcf3ce44SJohn Forte scf_property_t *prop = NULL; 1387fcf3ce44SJohn Forte scf_iter_t *propIter = NULL; 1388fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 1389fcf3ce44SJohn Forte scf_transaction_entry_t *entry1 = NULL; 1390fcf3ce44SJohn Forte scf_transaction_entry_t *entry2 = NULL; 1391fcf3ce44SJohn Forte scf_value_t *value = NULL; 1392fcf3ce44SJohn Forte uint64_t groupIdx; 1393fcf3ce44SJohn Forte char buf1[MAXNAMELEN]; 1394fcf3ce44SJohn Forte char buf2[MAXNAMELEN]; 1395fcf3ce44SJohn Forte char tmpbuf[MAXNAMELEN]; 1396fcf3ce44SJohn Forte boolean_t found = B_FALSE; 1397fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 1398fcf3ce44SJohn Forte int commitRet; 1399fcf3ce44SJohn Forte 1400fcf3ce44SJohn Forte assert(groupName != NULL); 1401fcf3ce44SJohn Forte 1402fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 1403fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1404fcf3ce44SJohn Forte goto out; 1405fcf3ce44SJohn Forte } 1406fcf3ce44SJohn Forte 1407fcf3ce44SJohn Forte /* 1408fcf3ce44SJohn Forte * Allocate scf resources 1409fcf3ce44SJohn Forte */ 1410fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 1411fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL) || 1412fcf3ce44SJohn Forte ((entry1 = scf_entry_create(handle)) == NULL) || 1413fcf3ce44SJohn Forte ((entry2 = scf_entry_create(handle)) == NULL) || 1414fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 1415fcf3ce44SJohn Forte ((propIter = scf_iter_create(handle)) == NULL) || 1416fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 1417fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 1418fcf3ce44SJohn Forte scf_strerror(scf_error())); 1419fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1420fcf3ce44SJohn Forte goto out; 1421fcf3ce44SJohn Forte } 1422fcf3ce44SJohn Forte 1423fcf3ce44SJohn Forte /* 1424fcf3ce44SJohn Forte * Get the property group being modified 1425fcf3ce44SJohn Forte */ 1426fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgRefName, pg) == -1) { 1427fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND && 1428fcf3ce44SJohn Forte addRemoveFlag == ADD) { 1429fcf3ce44SJohn Forte if (scf_service_add_pg(svc, pgRefName, 1430fcf3ce44SJohn Forte SCF_GROUP_APPLICATION, 0, pg) == -1) { 143186b7dbefSPeter Gill syslog(LOG_ERR, "add pg %s failed - %s", 143286b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1433fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1434fcf3ce44SJohn Forte } 1435fcf3ce44SJohn Forte } else if (scf_error() == SCF_ERROR_NOT_FOUND) { 143686b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 143786b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1438fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 1439fcf3ce44SJohn Forte } else { 144086b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 144186b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1442fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1443fcf3ce44SJohn Forte } 1444fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1445fcf3ce44SJohn Forte goto out; 1446fcf3ce44SJohn Forte } 1447fcf3ce44SJohn Forte } 1448fcf3ce44SJohn Forte 1449fcf3ce44SJohn Forte /* 1450fcf3ce44SJohn Forte * propIter is the iterator handle 1451fcf3ce44SJohn Forte */ 1452fcf3ce44SJohn Forte if (scf_iter_pg_properties(propIter, pg) == -1) { 145386b7dbefSPeter Gill syslog(LOG_ERR, "iter properties for %s failed - %s", 145486b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1455fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1456fcf3ce44SJohn Forte goto out; 1457fcf3ce44SJohn Forte } 1458fcf3ce44SJohn Forte 1459fcf3ce44SJohn Forte /* 1460fcf3ce44SJohn Forte * Iterate through the group names. 1461fcf3ce44SJohn Forte * If we find it in the list, it's an error when addRemoveFlag == ADD. 1462fcf3ce44SJohn Forte */ 1463fcf3ce44SJohn Forte while (scf_iter_next_property(propIter, prop) == 1) { 1464fcf3ce44SJohn Forte if (scf_property_get_name(prop, buf1, sizeof (buf1)) == -1) { 146586b7dbefSPeter Gill syslog(LOG_ERR, "get name from %s iter failed - %s", 146686b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1467fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1468fcf3ce44SJohn Forte break; 1469fcf3ce44SJohn Forte } 1470fcf3ce44SJohn Forte /* 1471fcf3ce44SJohn Forte * Skip over member list properties 1472fcf3ce44SJohn Forte */ 1473fcf3ce44SJohn Forte if (strstr(buf1, STMF_MEMBER_LIST_SUFFIX)) { 1474fcf3ce44SJohn Forte continue; 1475fcf3ce44SJohn Forte } 1476fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 147786b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 147886b7dbefSPeter Gill pgRefName, buf1, scf_strerror(scf_error())); 1479fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1480fcf3ce44SJohn Forte break; 1481fcf3ce44SJohn Forte } 1482fcf3ce44SJohn Forte if (scf_value_get_ustring(value, tmpbuf, 1483fcf3ce44SJohn Forte sizeof (tmpbuf)) == -1) { 148486b7dbefSPeter Gill syslog(LOG_ERR, "get ustring %s/%s failed - %s", 148586b7dbefSPeter Gill pgRefName, buf1, scf_strerror(scf_error())); 1486fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1487fcf3ce44SJohn Forte break; 1488fcf3ce44SJohn Forte } 1489fcf3ce44SJohn Forte 1490fcf3ce44SJohn Forte if ((strlen(tmpbuf) == strlen(groupName)) && 1491fcf3ce44SJohn Forte bcmp(tmpbuf, groupName, strlen(tmpbuf)) == 0) { 1492fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 1493fcf3ce44SJohn Forte ret = STMF_PS_ERROR_EXISTS; 1494fcf3ce44SJohn Forte } 1495fcf3ce44SJohn Forte found = B_TRUE; 1496fcf3ce44SJohn Forte /* 1497fcf3ce44SJohn Forte * buf1 contains the name for REMOVE 1498fcf3ce44SJohn Forte */ 1499fcf3ce44SJohn Forte break; 1500fcf3ce44SJohn Forte } 1501fcf3ce44SJohn Forte } 1502fcf3ce44SJohn Forte 1503fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1504fcf3ce44SJohn Forte goto out; 1505fcf3ce44SJohn Forte } 1506fcf3ce44SJohn Forte 1507fcf3ce44SJohn Forte scf_value_reset(value); 1508fcf3ce44SJohn Forte 1509fcf3ce44SJohn Forte if (!found && addRemoveFlag == REMOVE) { 1510fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 1511fcf3ce44SJohn Forte goto out; 1512fcf3ce44SJohn Forte } 1513fcf3ce44SJohn Forte 1514fcf3ce44SJohn Forte /* 1515fcf3ce44SJohn Forte * If we're adding, we need to create a new property name for the 1516fcf3ce44SJohn Forte * new group 1517fcf3ce44SJohn Forte */ 1518fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 1519fcf3ce44SJohn Forte for (groupIdx = 0; groupIdx < GROUP_MAX; groupIdx++) { 1520fcf3ce44SJohn Forte if (snprintf(buf1, sizeof (buf1), "%s-%lld", 1521fcf3ce44SJohn Forte STMF_GROUP_PREFIX, groupIdx) > sizeof (buf1)) { 1522fcf3ce44SJohn Forte syslog(LOG_ERR, 1523fcf3ce44SJohn Forte "buffer overflow on property name %s", 1524fcf3ce44SJohn Forte buf1); 1525fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1526fcf3ce44SJohn Forte break; 1527fcf3ce44SJohn Forte } 1528fcf3ce44SJohn Forte if (scf_pg_get_property(pg, buf1, prop) == -1) { 1529fcf3ce44SJohn Forte if (scf_error() != SCF_ERROR_NOT_FOUND) { 153086b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s " 153186b7dbefSPeter Gill "failed - %s", pgRefName, buf1, 1532fcf3ce44SJohn Forte scf_strerror(scf_error())); 1533fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1534fcf3ce44SJohn Forte } 1535fcf3ce44SJohn Forte break; 1536fcf3ce44SJohn Forte } 1537fcf3ce44SJohn Forte } 1538fcf3ce44SJohn Forte } 1539fcf3ce44SJohn Forte 1540fcf3ce44SJohn Forte /* 1541fcf3ce44SJohn Forte * Now create the new member list property for the new group 1542fcf3ce44SJohn Forte */ 1543fcf3ce44SJohn Forte if (snprintf(buf2, sizeof (buf2), "%s-%s", buf1, 1544fcf3ce44SJohn Forte STMF_MEMBER_LIST_SUFFIX) > sizeof (buf2)) { 1545fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 1546fcf3ce44SJohn Forte buf1); 1547fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1548fcf3ce44SJohn Forte goto out; 1549fcf3ce44SJohn Forte } 1550fcf3ce44SJohn Forte 1551fcf3ce44SJohn Forte /* 1552fcf3ce44SJohn Forte * buf1 now contains the name of the property if it was found in the 1553fcf3ce44SJohn Forte * list in the case of delete or the next available property name 1554fcf3ce44SJohn Forte * in the case of create 1555fcf3ce44SJohn Forte * 1556fcf3ce44SJohn Forte * buf2 now contains the member list property name 1557fcf3ce44SJohn Forte */ 1558fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 155986b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 156086b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1561fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1562fcf3ce44SJohn Forte goto out; 1563fcf3ce44SJohn Forte } 1564fcf3ce44SJohn Forte 1565fcf3ce44SJohn Forte if (addRemoveFlag == ADD) { 1566fcf3ce44SJohn Forte /* 1567fcf3ce44SJohn Forte * Create the property 'group name' 1568fcf3ce44SJohn Forte * This is the container for the group name 1569fcf3ce44SJohn Forte */ 1570fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry1, buf1, 1571fcf3ce44SJohn Forte SCF_TYPE_USTRING) == -1) { 157286b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 157386b7dbefSPeter Gill "failed - %s", pgRefName, buf1, 1574fcf3ce44SJohn Forte scf_strerror(scf_error())); 1575fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1576fcf3ce44SJohn Forte goto out; 1577fcf3ce44SJohn Forte } 1578fcf3ce44SJohn Forte if (scf_value_set_ustring(value, groupName) == -1) { 157986b7dbefSPeter Gill syslog(LOG_ERR, "set ustring %s/%s failed - %s", 158086b7dbefSPeter Gill pgRefName, buf1, scf_strerror(scf_error())); 1581fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1582fcf3ce44SJohn Forte goto out; 1583fcf3ce44SJohn Forte } 1584fcf3ce44SJohn Forte if (scf_entry_add_value(entry1, value) == -1) { 158586b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 158686b7dbefSPeter Gill pgRefName, buf1, scf_strerror(scf_error())); 1587fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1588fcf3ce44SJohn Forte goto out; 1589fcf3ce44SJohn Forte } 1590fcf3ce44SJohn Forte /* 1591fcf3ce44SJohn Forte * Create the property 'group list' 1592fcf3ce44SJohn Forte * This is the container for the group members 1593fcf3ce44SJohn Forte */ 1594fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry2, buf2, 1595fcf3ce44SJohn Forte SCF_TYPE_USTRING) == -1) { 159686b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 159786b7dbefSPeter Gill "failed - %s", pgRefName, buf2, 1598fcf3ce44SJohn Forte scf_strerror(scf_error())); 1599fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1600fcf3ce44SJohn Forte goto out; 1601fcf3ce44SJohn Forte } 1602fcf3ce44SJohn Forte } else { 1603fcf3ce44SJohn Forte /* 1604fcf3ce44SJohn Forte * Delete the property 'group name' 1605fcf3ce44SJohn Forte */ 1606fcf3ce44SJohn Forte if (scf_transaction_property_delete(tran, entry1, buf1) 1607fcf3ce44SJohn Forte == -1) { 1608fcf3ce44SJohn Forte syslog(LOG_ERR, 160986b7dbefSPeter Gill "transaction property delete %s/%s failed - %s", 161086b7dbefSPeter Gill pgRefName, buf1, scf_strerror(scf_error())); 1611fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1612fcf3ce44SJohn Forte goto out; 1613fcf3ce44SJohn Forte } 1614fcf3ce44SJohn Forte /* 1615fcf3ce44SJohn Forte * Delete the property 'group list' 1616fcf3ce44SJohn Forte */ 1617fcf3ce44SJohn Forte if (scf_transaction_property_delete(tran, entry2, buf2) 1618fcf3ce44SJohn Forte == -1) { 161986b7dbefSPeter Gill syslog(LOG_ERR, "transaction property delete %s/%s " 162086b7dbefSPeter Gill "failed - %s", pgRefName, buf2, 1621fcf3ce44SJohn Forte scf_strerror(scf_error())); 1622fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1623fcf3ce44SJohn Forte goto out; 1624fcf3ce44SJohn Forte } 1625fcf3ce44SJohn Forte } 1626fcf3ce44SJohn Forte 1627fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1628fcf3ce44SJohn Forte goto out; 1629fcf3ce44SJohn Forte } 1630fcf3ce44SJohn Forte 1631fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 163286b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 163386b7dbefSPeter Gill pgRefName, scf_strerror(scf_error())); 1634fcf3ce44SJohn Forte if (commitRet == 0) { 1635fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 1636fcf3ce44SJohn Forte } else { 1637fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1638fcf3ce44SJohn Forte } 1639fcf3ce44SJohn Forte } 1640fcf3ce44SJohn Forte 1641fcf3ce44SJohn Forte out: 1642fcf3ce44SJohn Forte /* 1643fcf3ce44SJohn Forte * Free resources 1644fcf3ce44SJohn Forte */ 1645fcf3ce44SJohn Forte if (handle != NULL) { 1646fcf3ce44SJohn Forte scf_handle_destroy(handle); 1647fcf3ce44SJohn Forte } 1648fcf3ce44SJohn Forte if (svc != NULL) { 1649fcf3ce44SJohn Forte scf_service_destroy(svc); 1650fcf3ce44SJohn Forte } 1651fcf3ce44SJohn Forte if (pg != NULL) { 1652fcf3ce44SJohn Forte scf_pg_destroy(pg); 1653fcf3ce44SJohn Forte } 1654fcf3ce44SJohn Forte if (tran != NULL) { 1655fcf3ce44SJohn Forte scf_transaction_destroy(tran); 1656fcf3ce44SJohn Forte } 1657fcf3ce44SJohn Forte if (entry1 != NULL) { 1658fcf3ce44SJohn Forte scf_entry_destroy(entry1); 1659fcf3ce44SJohn Forte } 1660fcf3ce44SJohn Forte if (entry2 != NULL) { 1661fcf3ce44SJohn Forte scf_entry_destroy(entry2); 1662fcf3ce44SJohn Forte } 1663fcf3ce44SJohn Forte if (prop != NULL) { 1664fcf3ce44SJohn Forte scf_property_destroy(prop); 1665fcf3ce44SJohn Forte } 1666fcf3ce44SJohn Forte if (propIter != NULL) { 1667fcf3ce44SJohn Forte scf_iter_destroy(propIter); 1668fcf3ce44SJohn Forte } 1669fcf3ce44SJohn Forte if (value != NULL) { 1670fcf3ce44SJohn Forte scf_value_destroy(value); 1671fcf3ce44SJohn Forte } 1672fcf3ce44SJohn Forte 1673fcf3ce44SJohn Forte return (ret); 1674fcf3ce44SJohn Forte } 1675fcf3ce44SJohn Forte 1676fcf3ce44SJohn Forte /* 1677fcf3ce44SJohn Forte * iPsGetGroupList 1678fcf3ce44SJohn Forte * 1679fcf3ce44SJohn Forte * pgName - Property group name 1680fcf3ce44SJohn Forte * groupList - pointer to pointer to stmfGroupList structure. On success, 1681fcf3ce44SJohn Forte * contains the list of groups 1682fcf3ce44SJohn Forte * 1683fcf3ce44SJohn Forte * returns: 1684fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 1685fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 1686fcf3ce44SJohn Forte */ 1687fcf3ce44SJohn Forte static int 1688fcf3ce44SJohn Forte iPsGetGroupList(char *pgName, stmfGroupList **groupList) 1689fcf3ce44SJohn Forte { 1690fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 1691fcf3ce44SJohn Forte scf_service_t *svc = NULL; 1692fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 1693fcf3ce44SJohn Forte scf_property_t *prop = NULL; 1694fcf3ce44SJohn Forte scf_iter_t *propIter = NULL; 1695fcf3ce44SJohn Forte scf_value_t *value = NULL; 1696fcf3ce44SJohn Forte char buf[MAXNAMELEN]; 1697fcf3ce44SJohn Forte int memberCnt = 0; 1698fcf3ce44SJohn Forte int i = 0; 1699fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 1700fcf3ce44SJohn Forte 1701fcf3ce44SJohn Forte assert(groupList != NULL); 1702fcf3ce44SJohn Forte 1703fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 1704fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1705fcf3ce44SJohn Forte goto out; 1706fcf3ce44SJohn Forte } 1707fcf3ce44SJohn Forte 1708fcf3ce44SJohn Forte /* 1709fcf3ce44SJohn Forte * Allocate scf resources 1710fcf3ce44SJohn Forte */ 1711fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 1712fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 1713fcf3ce44SJohn Forte ((propIter = scf_iter_create(handle)) == NULL) || 1714fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 1715fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 1716fcf3ce44SJohn Forte scf_strerror(scf_error())); 1717fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1718fcf3ce44SJohn Forte goto out; 1719fcf3ce44SJohn Forte } 1720fcf3ce44SJohn Forte 1721fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 1722fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 172386b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 172486b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1725fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 1726fcf3ce44SJohn Forte } else { 172786b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 172886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1729fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1730fcf3ce44SJohn Forte } 1731fcf3ce44SJohn Forte goto out; 1732fcf3ce44SJohn Forte } 1733fcf3ce44SJohn Forte 1734fcf3ce44SJohn Forte /* 1735fcf3ce44SJohn Forte * propIter is the iterator handle 1736fcf3ce44SJohn Forte */ 1737fcf3ce44SJohn Forte if (scf_iter_pg_properties(propIter, pg) == -1) { 173886b7dbefSPeter Gill syslog(LOG_ERR, "iter properties for %s failed - %s", 173986b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1740fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1741fcf3ce44SJohn Forte goto out; 1742fcf3ce44SJohn Forte } 1743fcf3ce44SJohn Forte 1744fcf3ce44SJohn Forte while (scf_iter_next_property(propIter, prop) == 1) { 1745fcf3ce44SJohn Forte if (scf_property_get_name(prop, buf, sizeof (buf)) == -1) { 174686b7dbefSPeter Gill syslog(LOG_ERR, "get name from %s iter failed - %s", 174786b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1748fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1749fcf3ce44SJohn Forte break; 1750fcf3ce44SJohn Forte } 1751fcf3ce44SJohn Forte /* 1752fcf3ce44SJohn Forte * Skip over member list properties 1753fcf3ce44SJohn Forte */ 1754fcf3ce44SJohn Forte if (strstr(buf, STMF_MEMBER_LIST_SUFFIX)) { 1755fcf3ce44SJohn Forte continue; 1756fcf3ce44SJohn Forte } 1757fcf3ce44SJohn Forte memberCnt++; 1758fcf3ce44SJohn Forte } 1759fcf3ce44SJohn Forte 1760fcf3ce44SJohn Forte /* 1761fcf3ce44SJohn Forte * propIter is the iterator handle 1762fcf3ce44SJohn Forte */ 1763fcf3ce44SJohn Forte if (scf_iter_pg_properties(propIter, pg) == -1) { 176486b7dbefSPeter Gill syslog(LOG_ERR, "iter properties for %s failed - %s", 176586b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1766fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1767fcf3ce44SJohn Forte goto out; 1768fcf3ce44SJohn Forte } 1769fcf3ce44SJohn Forte 1770fcf3ce44SJohn Forte *groupList = (stmfGroupList *)calloc(1, sizeof (stmfGroupList) + 1771fcf3ce44SJohn Forte memberCnt * sizeof (stmfGroupName)); 1772fcf3ce44SJohn Forte 1773fcf3ce44SJohn Forte if (*groupList == NULL) { 1774fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 1775fcf3ce44SJohn Forte goto out; 1776fcf3ce44SJohn Forte } 1777fcf3ce44SJohn Forte 1778fcf3ce44SJohn Forte /* 1779fcf3ce44SJohn Forte * In order to get a list of groups, simply get all of the 1780fcf3ce44SJohn Forte * properties that are not member list properties, i.e. the group 1781fcf3ce44SJohn Forte * name properties. 1782fcf3ce44SJohn Forte * It's possible for this list to grow beyond what was originally 1783fcf3ce44SJohn Forte * read so just ensure we're not writing beyond our allocated buffer 1784fcf3ce44SJohn Forte * by ensuring i < memberCnt 1785fcf3ce44SJohn Forte */ 1786fcf3ce44SJohn Forte while ((scf_iter_next_property(propIter, prop) == 1) && 1787fcf3ce44SJohn Forte (i < memberCnt)) { 1788fcf3ce44SJohn Forte if (scf_property_get_name(prop, buf, sizeof (buf)) == -1) { 178986b7dbefSPeter Gill syslog(LOG_ERR, "get name from %s iter failed - %s", 179086b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1791fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1792fcf3ce44SJohn Forte break; 1793fcf3ce44SJohn Forte } 1794fcf3ce44SJohn Forte /* 1795fcf3ce44SJohn Forte * Skip over member list properties 1796fcf3ce44SJohn Forte */ 1797fcf3ce44SJohn Forte if (strstr(buf, STMF_MEMBER_LIST_SUFFIX)) { 1798fcf3ce44SJohn Forte continue; 1799fcf3ce44SJohn Forte } 1800fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 180186b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 180286b7dbefSPeter Gill pgName, buf, scf_strerror(scf_error())); 1803fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1804fcf3ce44SJohn Forte break; 1805fcf3ce44SJohn Forte } 1806fcf3ce44SJohn Forte if (scf_value_get_ustring(value, buf, sizeof (buf)) == -1) { 180786b7dbefSPeter Gill syslog(LOG_ERR, "get ustring %s/%s failed - %s", 180886b7dbefSPeter Gill pgName, buf, scf_strerror(scf_error())); 1809fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1810fcf3ce44SJohn Forte break; 1811fcf3ce44SJohn Forte } 1812fcf3ce44SJohn Forte bcopy(buf, (*groupList)->name[i++], strlen(buf)); 1813fcf3ce44SJohn Forte (*groupList)->cnt++; 1814fcf3ce44SJohn Forte } 1815fcf3ce44SJohn Forte 1816fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1817fcf3ce44SJohn Forte free(*groupList); 1818fcf3ce44SJohn Forte goto out; 1819fcf3ce44SJohn Forte } 1820fcf3ce44SJohn Forte 1821fcf3ce44SJohn Forte out: 1822fcf3ce44SJohn Forte /* 1823fcf3ce44SJohn Forte * Free resources 1824fcf3ce44SJohn Forte */ 1825fcf3ce44SJohn Forte if (handle != NULL) { 1826fcf3ce44SJohn Forte scf_handle_destroy(handle); 1827fcf3ce44SJohn Forte } 1828fcf3ce44SJohn Forte if (svc != NULL) { 1829fcf3ce44SJohn Forte scf_service_destroy(svc); 1830fcf3ce44SJohn Forte } 1831fcf3ce44SJohn Forte if (pg != NULL) { 1832fcf3ce44SJohn Forte scf_pg_destroy(pg); 1833fcf3ce44SJohn Forte } 1834fcf3ce44SJohn Forte if (propIter != NULL) { 1835fcf3ce44SJohn Forte scf_iter_destroy(propIter); 1836fcf3ce44SJohn Forte } 1837fcf3ce44SJohn Forte if (prop != NULL) { 1838fcf3ce44SJohn Forte scf_property_destroy(prop); 1839fcf3ce44SJohn Forte } 1840fcf3ce44SJohn Forte if (value != NULL) { 1841fcf3ce44SJohn Forte scf_value_destroy(value); 1842fcf3ce44SJohn Forte } 1843fcf3ce44SJohn Forte 1844fcf3ce44SJohn Forte return (ret); 1845fcf3ce44SJohn Forte } 1846fcf3ce44SJohn Forte 1847fcf3ce44SJohn Forte /* 1848fcf3ce44SJohn Forte * iPsGetGroupMemberList 1849fcf3ce44SJohn Forte * 1850fcf3ce44SJohn Forte * pgName - Property group name 1851fcf3ce44SJohn Forte * groupName - group name (host group or target group) 1852fcf3ce44SJohn Forte * groupMemberList - pointer to pointer to stmfGroupProperties structure. On 1853fcf3ce44SJohn Forte * success, contains the list of group members 1854fcf3ce44SJohn Forte * 1855fcf3ce44SJohn Forte * returns: 1856fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 1857fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 1858fcf3ce44SJohn Forte */ 1859fcf3ce44SJohn Forte static int 1860fcf3ce44SJohn Forte iPsGetGroupMemberList(char *pgName, char *groupName, 1861fcf3ce44SJohn Forte stmfGroupProperties **groupMemberList) 1862fcf3ce44SJohn Forte { 1863fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 1864fcf3ce44SJohn Forte scf_service_t *svc = NULL; 1865fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 1866fcf3ce44SJohn Forte scf_property_t *prop = NULL; 1867fcf3ce44SJohn Forte scf_value_t *valueLookup = NULL; 1868fcf3ce44SJohn Forte scf_iter_t *valueIter = NULL; 1869fcf3ce44SJohn Forte int i = 0; 1870fcf3ce44SJohn Forte int memberCnt; 1871fcf3ce44SJohn Forte int len; 1872fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 1873fcf3ce44SJohn Forte char buf[MAXNAMELEN]; 1874fcf3ce44SJohn Forte 1875fcf3ce44SJohn Forte assert(pgName != NULL && groupName != NULL); 1876fcf3ce44SJohn Forte 1877fcf3ce44SJohn Forte /* 1878fcf3ce44SJohn Forte * init the service handle 1879fcf3ce44SJohn Forte */ 1880fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 1881fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1882fcf3ce44SJohn Forte goto out; 1883fcf3ce44SJohn Forte } 1884fcf3ce44SJohn Forte 1885fcf3ce44SJohn Forte /* 1886fcf3ce44SJohn Forte * Allocate scf resources 1887fcf3ce44SJohn Forte */ 1888fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 1889fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 1890fcf3ce44SJohn Forte ((valueIter = scf_iter_create(handle)) == NULL) || 1891fcf3ce44SJohn Forte ((valueLookup = scf_value_create(handle)) == NULL)) { 1892fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 1893fcf3ce44SJohn Forte scf_strerror(scf_error())); 1894fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1895fcf3ce44SJohn Forte goto out; 1896fcf3ce44SJohn Forte } 1897fcf3ce44SJohn Forte 1898fcf3ce44SJohn Forte /* 1899fcf3ce44SJohn Forte * get the service property group handle 1900fcf3ce44SJohn Forte */ 1901fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 1902fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 1903fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 1904fcf3ce44SJohn Forte } else { 1905fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1906fcf3ce44SJohn Forte } 190786b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 190886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 1909fcf3ce44SJohn Forte goto out; 1910fcf3ce44SJohn Forte } 1911fcf3ce44SJohn Forte 1912fcf3ce44SJohn Forte /* 1913fcf3ce44SJohn Forte * Get the property handle 1914fcf3ce44SJohn Forte * based on the target or host group name 1915fcf3ce44SJohn Forte */ 1916fcf3ce44SJohn Forte if (scf_pg_get_property(pg, groupName, prop) == -1) { 191786b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 191886b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 1919fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1920fcf3ce44SJohn Forte goto out; 1921fcf3ce44SJohn Forte } 1922fcf3ce44SJohn Forte 1923fcf3ce44SJohn Forte /* 1924fcf3ce44SJohn Forte * valueIter is the iterator handle 1925fcf3ce44SJohn Forte */ 1926fcf3ce44SJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) { 192786b7dbefSPeter Gill syslog(LOG_ERR, "iter value %s/%s failed - %s", 192886b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 1929fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1930fcf3ce44SJohn Forte goto out; 1931fcf3ce44SJohn Forte } 1932fcf3ce44SJohn Forte 1933fcf3ce44SJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) { 1934fcf3ce44SJohn Forte if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) { 193586b7dbefSPeter Gill syslog(LOG_ERR, "iter value %s/%s failed - %s", 193686b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 1937fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1938fcf3ce44SJohn Forte break; 1939fcf3ce44SJohn Forte } 1940fcf3ce44SJohn Forte i++; 1941fcf3ce44SJohn Forte } 1942fcf3ce44SJohn Forte 1943fcf3ce44SJohn Forte /* 1944fcf3ce44SJohn Forte * valueIter is the iterator handle 1945fcf3ce44SJohn Forte */ 1946fcf3ce44SJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) { 194786b7dbefSPeter Gill syslog(LOG_ERR, "iter value %s/%s failed - %s", 194886b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 1949fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1950fcf3ce44SJohn Forte goto out; 1951fcf3ce44SJohn Forte } 1952fcf3ce44SJohn Forte 1953fcf3ce44SJohn Forte memberCnt = i; 1954fcf3ce44SJohn Forte 1955fcf3ce44SJohn Forte *groupMemberList = (stmfGroupProperties *)calloc(1, 1956fcf3ce44SJohn Forte sizeof (stmfGroupProperties) + memberCnt * sizeof (stmfDevid)); 1957fcf3ce44SJohn Forte if (*groupMemberList == NULL) { 1958fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 1959fcf3ce44SJohn Forte goto out; 1960fcf3ce44SJohn Forte } 1961fcf3ce44SJohn Forte 1962fcf3ce44SJohn Forte i = 0; 1963fcf3ce44SJohn Forte while ((scf_iter_next_value(valueIter, valueLookup) == 1) && 1964fcf3ce44SJohn Forte (i < memberCnt)) { 1965fcf3ce44SJohn Forte if ((len = scf_value_get_ustring(valueLookup, buf, MAXNAMELEN)) 1966fcf3ce44SJohn Forte == -1) { 196786b7dbefSPeter Gill syslog(LOG_ERR, "iter value %s/%s failed - %s", 196886b7dbefSPeter Gill pgName, groupName, scf_strerror(scf_error())); 1969fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1970fcf3ce44SJohn Forte break; 1971fcf3ce44SJohn Forte } 1972fcf3ce44SJohn Forte if (len < sizeof (stmfDevid) - 1) { 1973fcf3ce44SJohn Forte (*groupMemberList)->name[i].identLength = len; 1974fcf3ce44SJohn Forte bcopy(buf, 1975fcf3ce44SJohn Forte (*groupMemberList)->name[i++].ident, len); 1976fcf3ce44SJohn Forte (*groupMemberList)->cnt++; 1977fcf3ce44SJohn Forte } else { 1978fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 1979fcf3ce44SJohn Forte break; 1980fcf3ce44SJohn Forte } 1981fcf3ce44SJohn Forte } 1982fcf3ce44SJohn Forte 1983fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 1984fcf3ce44SJohn Forte free(*groupMemberList); 1985fcf3ce44SJohn Forte goto out; 1986fcf3ce44SJohn Forte } 1987fcf3ce44SJohn Forte 1988fcf3ce44SJohn Forte out: 1989fcf3ce44SJohn Forte /* 1990fcf3ce44SJohn Forte * Free resources 1991fcf3ce44SJohn Forte */ 1992fcf3ce44SJohn Forte if (handle != NULL) { 1993fcf3ce44SJohn Forte scf_handle_destroy(handle); 1994fcf3ce44SJohn Forte } 1995fcf3ce44SJohn Forte if (svc != NULL) { 1996fcf3ce44SJohn Forte scf_service_destroy(svc); 1997fcf3ce44SJohn Forte } 1998fcf3ce44SJohn Forte if (pg != NULL) { 1999fcf3ce44SJohn Forte scf_pg_destroy(pg); 2000fcf3ce44SJohn Forte } 2001fcf3ce44SJohn Forte if (prop != NULL) { 2002fcf3ce44SJohn Forte scf_property_destroy(prop); 2003fcf3ce44SJohn Forte } 2004fcf3ce44SJohn Forte if (valueLookup != NULL) { 2005fcf3ce44SJohn Forte scf_value_destroy(valueLookup); 2006fcf3ce44SJohn Forte } 2007fcf3ce44SJohn Forte if (valueIter != NULL) { 2008fcf3ce44SJohn Forte scf_iter_destroy(valueIter); 2009fcf3ce44SJohn Forte } 2010fcf3ce44SJohn Forte 2011fcf3ce44SJohn Forte return (ret); 2012fcf3ce44SJohn Forte } 2013fcf3ce44SJohn Forte 20148fe96085Stim szeto int 20158fe96085Stim szeto psGetServicePersist(uint8_t *persistType) 20168fe96085Stim szeto { 20178fe96085Stim szeto scf_handle_t *handle = NULL; 20188fe96085Stim szeto scf_service_t *svc = NULL; 20198fe96085Stim szeto int ret; 20208fe96085Stim szeto 20218fe96085Stim szeto 20228fe96085Stim szeto ret = iPsInit(&handle, &svc); 20238fe96085Stim szeto if (ret != STMF_PS_SUCCESS) { 20248fe96085Stim szeto return (STMF_PS_ERROR); 20258fe96085Stim szeto } 20268fe96085Stim szeto 20278fe96085Stim szeto ret = iPsGetSetPersistType(persistType, handle, svc, GET); 20288fe96085Stim szeto 20298fe96085Stim szeto /* 20308fe96085Stim szeto * Free resources 20318fe96085Stim szeto */ 20328fe96085Stim szeto if (handle != NULL) { 20338fe96085Stim szeto scf_handle_destroy(handle); 20348fe96085Stim szeto } 20358fe96085Stim szeto if (svc != NULL) { 20368fe96085Stim szeto scf_service_destroy(svc); 20378fe96085Stim szeto } 20388fe96085Stim szeto return (ret); 20398fe96085Stim szeto } 20408fe96085Stim szeto 20418fe96085Stim szeto int 20428fe96085Stim szeto psSetServicePersist(uint8_t persistType) 20438fe96085Stim szeto { 20448fe96085Stim szeto scf_handle_t *handle = NULL; 20458fe96085Stim szeto scf_service_t *svc = NULL; 20468fe96085Stim szeto int ret; 20478fe96085Stim szeto 20488fe96085Stim szeto 20498fe96085Stim szeto ret = iPsInit(&handle, &svc); 20508fe96085Stim szeto if (ret != STMF_PS_SUCCESS) { 20518fe96085Stim szeto return (STMF_PS_ERROR); 20528fe96085Stim szeto } 20538fe96085Stim szeto 20548fe96085Stim szeto ret = iPsGetSetPersistType(&persistType, handle, svc, SET); 20558fe96085Stim szeto 20568fe96085Stim szeto /* 20578fe96085Stim szeto * Free resources 20588fe96085Stim szeto */ 20598fe96085Stim szeto if (handle != NULL) { 20608fe96085Stim szeto scf_handle_destroy(handle); 20618fe96085Stim szeto } 20628fe96085Stim szeto if (svc != NULL) { 20638fe96085Stim szeto scf_service_destroy(svc); 20648fe96085Stim szeto } 20658fe96085Stim szeto return (ret); 20668fe96085Stim szeto } 20678fe96085Stim szeto 20688fe96085Stim szeto static int 20698fe96085Stim szeto iPsGetSetPersistType(uint8_t *persistType, scf_handle_t *handle, 20708fe96085Stim szeto scf_service_t *svc, int getSet) 20718fe96085Stim szeto { 20728fe96085Stim szeto scf_propertygroup_t *pg = NULL; 20738fe96085Stim szeto scf_property_t *prop = NULL; 20748fe96085Stim szeto scf_value_t *value = NULL; 20758fe96085Stim szeto scf_transaction_t *tran = NULL; 20768fe96085Stim szeto scf_transaction_entry_t *entry = NULL; 20778fe96085Stim szeto char iPersistTypeGet[MAXNAMELEN] = {0}; 20788fe96085Stim szeto char *iPersistType; 20798fe96085Stim szeto int ret = STMF_PS_SUCCESS; 20808fe96085Stim szeto int commitRet; 20818fe96085Stim szeto 20828fe96085Stim szeto if (((pg = scf_pg_create(handle)) == NULL) || 20838fe96085Stim szeto ((prop = scf_property_create(handle)) == NULL) || 20848fe96085Stim szeto ((entry = scf_entry_create(handle)) == NULL) || 20858fe96085Stim szeto ((tran = scf_transaction_create(handle)) == NULL) || 20868fe96085Stim szeto ((value = scf_value_create(handle)) == NULL)) { 20878fe96085Stim szeto syslog(LOG_ERR, "scf alloc resource failed - %s", 20888fe96085Stim szeto scf_strerror(scf_error())); 20898fe96085Stim szeto ret = STMF_PS_ERROR; 20908fe96085Stim szeto goto out; 20918fe96085Stim szeto } 20928fe96085Stim szeto 20938fe96085Stim szeto if (getSet == GET) { 20948fe96085Stim szeto /* set to default */ 20958fe96085Stim szeto *persistType = STMF_PERSIST_SMF; 20968fe96085Stim szeto iPersistType = STMF_PS_PERSIST_SMF; 20978fe96085Stim szeto } 20988fe96085Stim szeto 20998fe96085Stim szeto if (getSet == SET) { 21008fe96085Stim szeto if (*persistType == STMF_PERSIST_SMF) { 21018fe96085Stim szeto iPersistType = STMF_PS_PERSIST_SMF; 21028fe96085Stim szeto } else if (*persistType == STMF_PERSIST_NONE) { 21038fe96085Stim szeto iPersistType = STMF_PS_PERSIST_NONE; 21048fe96085Stim szeto } else { 21058fe96085Stim szeto ret = STMF_PS_ERROR; 21068fe96085Stim szeto goto out; 21078fe96085Stim szeto } 21088fe96085Stim szeto } 21098fe96085Stim szeto 21108fe96085Stim szeto /* 21118fe96085Stim szeto * get stmf data property group 21128fe96085Stim szeto */ 21138fe96085Stim szeto if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) { 21148fe96085Stim szeto if (scf_error() == SCF_ERROR_NOT_FOUND) { 21158fe96085Stim szeto ret = STMF_PS_ERROR_NOT_FOUND; 21168fe96085Stim szeto } else { 21178fe96085Stim szeto ret = STMF_PS_ERROR; 21188fe96085Stim szeto } 211986b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 212086b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 212186b7dbefSPeter Gill 21228fe96085Stim szeto goto out; 21238fe96085Stim szeto } 21248fe96085Stim szeto 21258fe96085Stim szeto /* find persistence property */ 21268fe96085Stim szeto /* 21278fe96085Stim szeto * Get the persistence property 21288fe96085Stim szeto */ 21298fe96085Stim szeto if (scf_pg_get_property(pg, STMF_PERSIST_TYPE, prop) == -1) { 21308fe96085Stim szeto if (scf_error() == SCF_ERROR_NOT_FOUND) { 21318fe96085Stim szeto ret = STMF_PS_ERROR_NOT_FOUND; 21328fe96085Stim szeto } else { 213386b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 213486b7dbefSPeter Gill STMF_DATA_GROUP, STMF_PERSIST_TYPE, 21358fe96085Stim szeto scf_strerror(scf_error())); 21368fe96085Stim szeto ret = STMF_PS_ERROR; 21378fe96085Stim szeto goto out; 21388fe96085Stim szeto } 21398fe96085Stim szeto } 21408fe96085Stim szeto 21418fe96085Stim szeto /* no persist property found */ 21428fe96085Stim szeto if (ret == STMF_PS_ERROR_NOT_FOUND || getSet == SET) { 21438fe96085Stim szeto /* 21448fe96085Stim szeto * If we have no persistType property, go ahead 21458fe96085Stim szeto * and create it with the user specified value or 21468fe96085Stim szeto * the default value. 21478fe96085Stim szeto */ 21488fe96085Stim szeto /* 21498fe96085Stim szeto * Begin the transaction 21508fe96085Stim szeto */ 21518fe96085Stim szeto if (scf_transaction_start(tran, pg) == -1) { 215286b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 215386b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 21548fe96085Stim szeto ret = STMF_PS_ERROR; 21558fe96085Stim szeto goto out; 21568fe96085Stim szeto } 21578fe96085Stim szeto 21588fe96085Stim szeto /* is this a SET or GET w/error? */ 21598fe96085Stim szeto if (ret) { 21608fe96085Stim szeto if (scf_transaction_property_new(tran, entry, 21618fe96085Stim szeto STMF_PERSIST_TYPE, SCF_TYPE_ASTRING) == -1) { 216286b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new " 216386b7dbefSPeter Gill "%s/%s failed - %s", STMF_DATA_GROUP, 216486b7dbefSPeter Gill STMF_PERSIST_TYPE, 21658fe96085Stim szeto scf_strerror(scf_error())); 21668fe96085Stim szeto ret = STMF_PS_ERROR; 21678fe96085Stim szeto goto out; 21688fe96085Stim szeto } 21698fe96085Stim szeto } else { 21708fe96085Stim szeto if (scf_transaction_property_change(tran, entry, 21718fe96085Stim szeto STMF_PERSIST_TYPE, SCF_TYPE_ASTRING) == -1) { 217286b7dbefSPeter Gill syslog(LOG_ERR, "transaction property change " 217386b7dbefSPeter Gill "%s/%s failed - %s", STMF_DATA_GROUP, 217486b7dbefSPeter Gill STMF_PERSIST_TYPE, 21758fe96085Stim szeto scf_strerror(scf_error())); 21768fe96085Stim szeto ret = STMF_PS_ERROR; 21778fe96085Stim szeto goto out; 21788fe96085Stim szeto } 21798fe96085Stim szeto } 21808fe96085Stim szeto 21818fe96085Stim szeto /* 21828fe96085Stim szeto * set the persist type 21838fe96085Stim szeto */ 21848fe96085Stim szeto if (scf_value_set_astring(value, iPersistType) == -1) { 218586b7dbefSPeter Gill syslog(LOG_ERR, "set value %s/%s failed - %s", 218686b7dbefSPeter Gill STMF_DATA_GROUP, STMF_PERSIST_TYPE, 21878fe96085Stim szeto scf_strerror(scf_error())); 21888fe96085Stim szeto ret = STMF_PS_ERROR; 21898fe96085Stim szeto goto out; 21908fe96085Stim szeto } 21918fe96085Stim szeto 21928fe96085Stim szeto /* 21938fe96085Stim szeto * add the value to the transaction 21948fe96085Stim szeto */ 21958fe96085Stim szeto if (scf_entry_add_value(entry, value) == -1) { 219686b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 219786b7dbefSPeter Gill STMF_DATA_GROUP, STMF_PERSIST_TYPE, 21988fe96085Stim szeto scf_strerror(scf_error())); 21998fe96085Stim szeto ret = STMF_PS_ERROR; 22008fe96085Stim szeto goto out; 22018fe96085Stim szeto } 22028fe96085Stim szeto if ((commitRet = scf_transaction_commit(tran)) != 1) { 220386b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 220486b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 22058fe96085Stim szeto if (commitRet == 0) { 22068fe96085Stim szeto ret = STMF_PS_ERROR_BUSY; 22078fe96085Stim szeto } else { 22088fe96085Stim szeto ret = STMF_PS_ERROR; 22098fe96085Stim szeto } 22108fe96085Stim szeto goto out; 22118fe96085Stim szeto } 22128fe96085Stim szeto /* reset return value */ 22138fe96085Stim szeto ret = STMF_PS_SUCCESS; 22148fe96085Stim szeto } else if (getSet == GET) { 22158fe96085Stim szeto /* get the persist property */ 22168fe96085Stim szeto if (scf_property_get_value(prop, value) == -1) { 221786b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 221886b7dbefSPeter Gill STMF_DATA_GROUP, STMF_PERSIST_TYPE, 22198fe96085Stim szeto scf_strerror(scf_error())); 22208fe96085Stim szeto ret = STMF_PS_ERROR; 22218fe96085Stim szeto goto out; 22228fe96085Stim szeto } 22238fe96085Stim szeto 22248fe96085Stim szeto /* 22258fe96085Stim szeto * Get the value of the persist property 22268fe96085Stim szeto */ 22278fe96085Stim szeto if (scf_value_get_astring(value, iPersistTypeGet, MAXNAMELEN) 22288fe96085Stim szeto == -1) { 222986b7dbefSPeter Gill syslog(LOG_ERR, "get string value %s/%s failed - %s", 223086b7dbefSPeter Gill STMF_DATA_GROUP, STMF_PERSIST_TYPE, 22318fe96085Stim szeto scf_strerror(scf_error())); 22328fe96085Stim szeto ret = STMF_PS_ERROR; 22338fe96085Stim szeto goto out; 22348fe96085Stim szeto } 22358fe96085Stim szeto } 22368fe96085Stim szeto 22378fe96085Stim szeto if (getSet == GET) { 22388fe96085Stim szeto if (strcmp(iPersistTypeGet, STMF_PS_PERSIST_NONE) == 0) { 22398fe96085Stim szeto *persistType = STMF_PERSIST_NONE; 22408fe96085Stim szeto } else if (strcmp(iPersistTypeGet, STMF_PS_PERSIST_SMF) == 0) { 22418fe96085Stim szeto *persistType = STMF_PERSIST_SMF; 22428fe96085Stim szeto } else { 22438fe96085Stim szeto ret = STMF_PS_ERROR; 22448fe96085Stim szeto goto out; 22458fe96085Stim szeto } 22468fe96085Stim szeto } 22478fe96085Stim szeto out: 22488fe96085Stim szeto /* 22498fe96085Stim szeto * Free resources. 22508fe96085Stim szeto * handle and svc should not be free'd here. They're 22518fe96085Stim szeto * free'd elsewhere 22528fe96085Stim szeto */ 22538fe96085Stim szeto if (pg != NULL) { 22548fe96085Stim szeto scf_pg_destroy(pg); 22558fe96085Stim szeto } 22568fe96085Stim szeto if (prop != NULL) { 22578fe96085Stim szeto scf_property_destroy(prop); 22588fe96085Stim szeto } 22598fe96085Stim szeto if (entry != NULL) { 22608fe96085Stim szeto scf_entry_destroy(entry); 22618fe96085Stim szeto } 22628fe96085Stim szeto if (tran != NULL) { 22638fe96085Stim szeto scf_transaction_destroy(tran); 22648fe96085Stim szeto } 22658fe96085Stim szeto if (value != NULL) { 22668fe96085Stim szeto scf_value_destroy(value); 22678fe96085Stim szeto } 22688fe96085Stim szeto return (ret); 22698fe96085Stim szeto } 22708fe96085Stim szeto 22714b31676fSsrivijitha dugganapalli int 22724b31676fSsrivijitha dugganapalli psSetStmfProp(int propType, char *propVal) 22734b31676fSsrivijitha dugganapalli { 22744b31676fSsrivijitha dugganapalli return (iPsGetSetStmfProp(propType, propVal, SET)); 22754b31676fSsrivijitha dugganapalli } 22764b31676fSsrivijitha dugganapalli 22774b31676fSsrivijitha dugganapalli int 22784b31676fSsrivijitha dugganapalli psGetStmfProp(int propType, char *propVal) 22794b31676fSsrivijitha dugganapalli { 22804b31676fSsrivijitha dugganapalli return (iPsGetSetStmfProp(propType, propVal, GET)); 22814b31676fSsrivijitha dugganapalli } 22824b31676fSsrivijitha dugganapalli 22834b31676fSsrivijitha dugganapalli static int 22844b31676fSsrivijitha dugganapalli iPsGetSetStmfProp(int propType, char *propVal, int getSet) 22854b31676fSsrivijitha dugganapalli { 22864b31676fSsrivijitha dugganapalli scf_handle_t *handle = NULL; 22874b31676fSsrivijitha dugganapalli scf_service_t *svc = NULL; 22884b31676fSsrivijitha dugganapalli scf_property_t *prop = NULL; 22894b31676fSsrivijitha dugganapalli scf_propertygroup_t *pg = NULL; 22904b31676fSsrivijitha dugganapalli scf_transaction_t *tran = NULL; 22914b31676fSsrivijitha dugganapalli scf_transaction_entry_t *entry = NULL; 22924b31676fSsrivijitha dugganapalli scf_value_t *value = NULL; 22934b31676fSsrivijitha dugganapalli char *psStmfPropVal; 22944b31676fSsrivijitha dugganapalli char *psStmfProp; 22954b31676fSsrivijitha dugganapalli char stmfPropGet[MAXNAMELEN] = {0}; 22964b31676fSsrivijitha dugganapalli int ret = STMF_PS_SUCCESS; 22974b31676fSsrivijitha dugganapalli int commitRet; 22984b31676fSsrivijitha dugganapalli 22994b31676fSsrivijitha dugganapalli if (propVal == NULL || (getSet != GET && getSet != SET)) { 23004b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23014b31676fSsrivijitha dugganapalli goto out; 23024b31676fSsrivijitha dugganapalli } 23034b31676fSsrivijitha dugganapalli 23044b31676fSsrivijitha dugganapalli /* 23054b31676fSsrivijitha dugganapalli * Init the service handle 23064b31676fSsrivijitha dugganapalli */ 23074b31676fSsrivijitha dugganapalli 23084b31676fSsrivijitha dugganapalli ret = iPsInit(&handle, &svc); 23094b31676fSsrivijitha dugganapalli if (ret != STMF_PS_SUCCESS) { 23104b31676fSsrivijitha dugganapalli goto out; 23114b31676fSsrivijitha dugganapalli } 23124b31676fSsrivijitha dugganapalli 23134b31676fSsrivijitha dugganapalli /* 23144b31676fSsrivijitha dugganapalli * Allocate scf resources 23154b31676fSsrivijitha dugganapalli */ 23164b31676fSsrivijitha dugganapalli 23174b31676fSsrivijitha dugganapalli if (((pg = scf_pg_create(handle)) == NULL) || 23184b31676fSsrivijitha dugganapalli ((prop = scf_property_create(handle)) == NULL) || 23194b31676fSsrivijitha dugganapalli ((entry = scf_entry_create(handle)) == NULL) || 23204b31676fSsrivijitha dugganapalli ((tran = scf_transaction_create(handle)) == NULL) || 23214b31676fSsrivijitha dugganapalli ((value = scf_value_create(handle)) == NULL)) { 23224b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "scf alloc resource failed - %s", 23234b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 23244b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23254b31676fSsrivijitha dugganapalli goto out; 23264b31676fSsrivijitha dugganapalli } 23274b31676fSsrivijitha dugganapalli if (getSet == GET) { 23284b31676fSsrivijitha dugganapalli switch (propType) { 23294b31676fSsrivijitha dugganapalli case STMF_DEFAULT_LU_STATE : 23304b31676fSsrivijitha dugganapalli psStmfProp = DEFAULT_LU_STATE; 23314b31676fSsrivijitha dugganapalli psStmfPropVal = STMF_PS_LU_ONLINE; 23324b31676fSsrivijitha dugganapalli (void) strcpy(stmfPropGet, psStmfPropVal); 23334b31676fSsrivijitha dugganapalli break; 23344b31676fSsrivijitha dugganapalli case STMF_DEFAULT_TARGET_PORT_STATE : 23354b31676fSsrivijitha dugganapalli psStmfProp = DEFAULT_TARGET_PORT_STATE; 23364b31676fSsrivijitha dugganapalli psStmfPropVal = STMF_PS_TARGET_PORT_ONLINE; 23374b31676fSsrivijitha dugganapalli (void) strcpy(stmfPropGet, psStmfPropVal); 23384b31676fSsrivijitha dugganapalli break; 23394b31676fSsrivijitha dugganapalli default : 23404b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23414b31676fSsrivijitha dugganapalli goto out; 23424b31676fSsrivijitha dugganapalli } 23434b31676fSsrivijitha dugganapalli } 23444b31676fSsrivijitha dugganapalli if (getSet == SET) { 23454b31676fSsrivijitha dugganapalli switch (propType) { 23464b31676fSsrivijitha dugganapalli case STMF_DEFAULT_LU_STATE : 23474b31676fSsrivijitha dugganapalli psStmfProp = DEFAULT_LU_STATE; 2348*894ed91cSMilan Jurik if (strcasecmp(propVal, "online") == 0) { 23494b31676fSsrivijitha dugganapalli psStmfPropVal = STMF_PS_LU_ONLINE; 2350*894ed91cSMilan Jurik } else if (strcasecmp(propVal, 2351*894ed91cSMilan Jurik "offline") == 0) { 23524b31676fSsrivijitha dugganapalli psStmfPropVal = STMF_PS_LU_OFFLINE; 2353*894ed91cSMilan Jurik } else { 23544b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23554b31676fSsrivijitha dugganapalli goto out; 2356*894ed91cSMilan Jurik } 23574b31676fSsrivijitha dugganapalli break; 23584b31676fSsrivijitha dugganapalli case STMF_DEFAULT_TARGET_PORT_STATE : 23594b31676fSsrivijitha dugganapalli psStmfProp = DEFAULT_TARGET_PORT_STATE; 2360*894ed91cSMilan Jurik if (strcasecmp(propVal, "online") == 0) { 23614b31676fSsrivijitha dugganapalli psStmfPropVal = 23624b31676fSsrivijitha dugganapalli STMF_PS_TARGET_PORT_ONLINE; 2363*894ed91cSMilan Jurik } else if (strcasecmp(propVal, 2364*894ed91cSMilan Jurik "offline") == 0) { 23654b31676fSsrivijitha dugganapalli psStmfPropVal = 23664b31676fSsrivijitha dugganapalli STMF_PS_TARGET_PORT_OFFLINE; 2367*894ed91cSMilan Jurik } else { 23684b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23694b31676fSsrivijitha dugganapalli goto out; 2370*894ed91cSMilan Jurik } 23714b31676fSsrivijitha dugganapalli break; 23724b31676fSsrivijitha dugganapalli default : 23734b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23744b31676fSsrivijitha dugganapalli goto out; 23754b31676fSsrivijitha dugganapalli } 23764b31676fSsrivijitha dugganapalli } 23774b31676fSsrivijitha dugganapalli 23784b31676fSsrivijitha dugganapalli /* 23794b31676fSsrivijitha dugganapalli * get stmf data property group 23804b31676fSsrivijitha dugganapalli */ 23814b31676fSsrivijitha dugganapalli 23824b31676fSsrivijitha dugganapalli if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) { 23834b31676fSsrivijitha dugganapalli if (scf_error() == SCF_ERROR_NOT_FOUND) { 23844b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR_NOT_FOUND; 23854b31676fSsrivijitha dugganapalli } else { 23864b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 23874b31676fSsrivijitha dugganapalli } 23884b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "get pg %s failed - %s", 23894b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, scf_strerror(scf_error())); 23904b31676fSsrivijitha dugganapalli goto out; 23914b31676fSsrivijitha dugganapalli } 23924b31676fSsrivijitha dugganapalli 23934b31676fSsrivijitha dugganapalli /* 23944b31676fSsrivijitha dugganapalli * get the stmf props property, if exists 23954b31676fSsrivijitha dugganapalli */ 23964b31676fSsrivijitha dugganapalli 23974b31676fSsrivijitha dugganapalli if (scf_pg_get_property(pg, psStmfProp, prop) == -1) { 23984b31676fSsrivijitha dugganapalli if (scf_error() == SCF_ERROR_NOT_FOUND) { 23994b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR_NOT_FOUND; 24004b31676fSsrivijitha dugganapalli } else { 24014b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "start transaction for %s/%s " 24024b31676fSsrivijitha dugganapalli "failed - %s", STMF_DATA_GROUP, psStmfProp, 24034b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24044b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24054b31676fSsrivijitha dugganapalli goto out; 24064b31676fSsrivijitha dugganapalli } 24074b31676fSsrivijitha dugganapalli } 24084b31676fSsrivijitha dugganapalli 24094b31676fSsrivijitha dugganapalli /* if stmf prop is not found or while setting the prop */ 24104b31676fSsrivijitha dugganapalli 24114b31676fSsrivijitha dugganapalli if (ret == STMF_PS_ERROR_NOT_FOUND || getSet == SET) { 24124b31676fSsrivijitha dugganapalli /* 24134b31676fSsrivijitha dugganapalli * Begin the transaction 24144b31676fSsrivijitha dugganapalli */ 24154b31676fSsrivijitha dugganapalli if (scf_transaction_start(tran, pg) == -1) { 24164b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "start transaction for %s failed - %s", 24174b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, scf_strerror(scf_error())); 24184b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24194b31676fSsrivijitha dugganapalli goto out; 24204b31676fSsrivijitha dugganapalli } 24214b31676fSsrivijitha dugganapalli if (ret) { 24224b31676fSsrivijitha dugganapalli if (scf_transaction_property_new(tran, entry, 24234b31676fSsrivijitha dugganapalli psStmfProp, SCF_TYPE_ASTRING) == -1) { 24244b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "transaction property new " 24254b31676fSsrivijitha dugganapalli "%s/%s failed - %s", STMF_DATA_GROUP, 24264b31676fSsrivijitha dugganapalli psStmfProp, scf_strerror(scf_error())); 24274b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24284b31676fSsrivijitha dugganapalli goto out; 24294b31676fSsrivijitha dugganapalli } 24304b31676fSsrivijitha dugganapalli } else { 24314b31676fSsrivijitha dugganapalli if (scf_transaction_property_change(tran, entry, 24324b31676fSsrivijitha dugganapalli psStmfProp, SCF_TYPE_ASTRING) == -1) { 24334b31676fSsrivijitha dugganapalli syslog(LOG_ERR, 24344b31676fSsrivijitha dugganapalli "transaction property change " 24354b31676fSsrivijitha dugganapalli "%s/%s failed - %s", 24364b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, psStmfProp, 24374b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24384b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24394b31676fSsrivijitha dugganapalli goto out; 24404b31676fSsrivijitha dugganapalli } 24414b31676fSsrivijitha dugganapalli } 24424b31676fSsrivijitha dugganapalli 24434b31676fSsrivijitha dugganapalli /* 24444b31676fSsrivijitha dugganapalli * set stmf prop value 24454b31676fSsrivijitha dugganapalli */ 24464b31676fSsrivijitha dugganapalli 24474b31676fSsrivijitha dugganapalli if (scf_value_set_astring(value, psStmfPropVal) == -1) { 24484b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "set value %s/%s failed - %s", 24494b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, psStmfProp, 24504b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24514b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24524b31676fSsrivijitha dugganapalli goto out; 24534b31676fSsrivijitha dugganapalli } 24544b31676fSsrivijitha dugganapalli 24554b31676fSsrivijitha dugganapalli /* 24564b31676fSsrivijitha dugganapalli * add the value to the transaction 24574b31676fSsrivijitha dugganapalli */ 24584b31676fSsrivijitha dugganapalli 24594b31676fSsrivijitha dugganapalli if (scf_entry_add_value(entry, value) == -1) { 24604b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "add value %s/%s failed - %s", 24614b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, psStmfProp, 24624b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24634b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24644b31676fSsrivijitha dugganapalli goto out; 24654b31676fSsrivijitha dugganapalli } 24664b31676fSsrivijitha dugganapalli if ((commitRet = scf_transaction_commit(tran)) != 1) { 24674b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "transaction commit for %s" 24684b31676fSsrivijitha dugganapalli "failed - %s", STMF_DATA_GROUP, 24694b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24704b31676fSsrivijitha dugganapalli if (commitRet == 0) { 24714b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR_BUSY; 24724b31676fSsrivijitha dugganapalli } else { 24734b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24744b31676fSsrivijitha dugganapalli } 24754b31676fSsrivijitha dugganapalli goto out; 24764b31676fSsrivijitha dugganapalli } 24774b31676fSsrivijitha dugganapalli ret = STMF_PS_SUCCESS; 24784b31676fSsrivijitha dugganapalli } else if (getSet == GET) { 24794b31676fSsrivijitha dugganapalli if (scf_property_get_value(prop, value) == -1) { 24804b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "get property value " 24814b31676fSsrivijitha dugganapalli "%s/%s failed - %s", 24824b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, psStmfProp, 24834b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24844b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24854b31676fSsrivijitha dugganapalli goto out; 24864b31676fSsrivijitha dugganapalli } 24874b31676fSsrivijitha dugganapalli 24884b31676fSsrivijitha dugganapalli /* get stmfProp */ 24894b31676fSsrivijitha dugganapalli 24904b31676fSsrivijitha dugganapalli if (scf_value_get_astring(value, stmfPropGet, MAXNAMELEN) 24914b31676fSsrivijitha dugganapalli == -1) { 24924b31676fSsrivijitha dugganapalli syslog(LOG_ERR, "get string value %s/%s failed - %s", 24934b31676fSsrivijitha dugganapalli STMF_DATA_GROUP, psStmfProp, 24944b31676fSsrivijitha dugganapalli scf_strerror(scf_error())); 24954b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 24964b31676fSsrivijitha dugganapalli goto out; 24974b31676fSsrivijitha dugganapalli } 24984b31676fSsrivijitha dugganapalli } 24994b31676fSsrivijitha dugganapalli if (getSet == GET) { 25004b31676fSsrivijitha dugganapalli if (strcmp(stmfPropGet, STMF_PS_LU_ONLINE) == 0) { 25014b31676fSsrivijitha dugganapalli (void) strcpy(propVal, "online"); 25024b31676fSsrivijitha dugganapalli } else if (strcmp(stmfPropGet, STMF_PS_LU_OFFLINE) == 0) { 25034b31676fSsrivijitha dugganapalli (void) strcpy(propVal, "offline"); 25044b31676fSsrivijitha dugganapalli } else if (strcmp(stmfPropGet, STMF_PS_TARGET_PORT_ONLINE) 25054b31676fSsrivijitha dugganapalli == 0) { 25064b31676fSsrivijitha dugganapalli (void) strcpy(propVal, "online"); 25074b31676fSsrivijitha dugganapalli } else if (strcmp(stmfPropGet, STMF_PS_TARGET_PORT_OFFLINE) 25084b31676fSsrivijitha dugganapalli == 0) { 25094b31676fSsrivijitha dugganapalli (void) strcpy(propVal, "offline"); 25104b31676fSsrivijitha dugganapalli } else { 25114b31676fSsrivijitha dugganapalli ret = STMF_PS_ERROR; 25124b31676fSsrivijitha dugganapalli goto out; 25134b31676fSsrivijitha dugganapalli } 25144b31676fSsrivijitha dugganapalli } 25154b31676fSsrivijitha dugganapalli out: 25164b31676fSsrivijitha dugganapalli /* 25174b31676fSsrivijitha dugganapalli * Free resources. 25184b31676fSsrivijitha dugganapalli */ 25194b31676fSsrivijitha dugganapalli 25204b31676fSsrivijitha dugganapalli if (handle != NULL) { 25214b31676fSsrivijitha dugganapalli scf_handle_destroy(handle); 25224b31676fSsrivijitha dugganapalli } 25234b31676fSsrivijitha dugganapalli if (svc != NULL) { 25244b31676fSsrivijitha dugganapalli scf_service_destroy(svc); 25254b31676fSsrivijitha dugganapalli } 25264b31676fSsrivijitha dugganapalli if (pg != NULL) { 25274b31676fSsrivijitha dugganapalli scf_pg_destroy(pg); 25284b31676fSsrivijitha dugganapalli } 25294b31676fSsrivijitha dugganapalli if (prop != NULL) { 25304b31676fSsrivijitha dugganapalli scf_property_destroy(prop); 25314b31676fSsrivijitha dugganapalli } 25324b31676fSsrivijitha dugganapalli if (entry != NULL) { 25334b31676fSsrivijitha dugganapalli scf_entry_destroy(entry); 25344b31676fSsrivijitha dugganapalli } 25354b31676fSsrivijitha dugganapalli if (tran != NULL) { 25364b31676fSsrivijitha dugganapalli scf_transaction_destroy(tran); 25374b31676fSsrivijitha dugganapalli } 25384b31676fSsrivijitha dugganapalli if (value != NULL) { 25394b31676fSsrivijitha dugganapalli scf_value_destroy(value); 25404b31676fSsrivijitha dugganapalli } 25414b31676fSsrivijitha dugganapalli return (ret); 25424b31676fSsrivijitha dugganapalli } 25434b31676fSsrivijitha dugganapalli 2544fcf3ce44SJohn Forte /* 2545fcf3ce44SJohn Forte * Initialize scf stmf service access 2546fcf3ce44SJohn Forte * handle - returned handle 2547fcf3ce44SJohn Forte * service - returned service handle 2548fcf3ce44SJohn Forte * 2549fcf3ce44SJohn Forte * Both handle and service must be destroyed by the caller 2550fcf3ce44SJohn Forte */ 2551fcf3ce44SJohn Forte static int 2552fcf3ce44SJohn Forte iPsInit(scf_handle_t **handle, scf_service_t **service) 2553fcf3ce44SJohn Forte { 2554fcf3ce44SJohn Forte scf_scope_t *scope = NULL; 2555fcf3ce44SJohn Forte uint64_t version; 2556fcf3ce44SJohn Forte int ret; 2557fcf3ce44SJohn Forte 2558fcf3ce44SJohn Forte assert(handle != NULL && service != NULL); 2559fcf3ce44SJohn Forte 2560fcf3ce44SJohn Forte if ((*handle = scf_handle_create(SCF_VERSION)) == NULL) { 2561fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_handle_create failed - %s", 2562fcf3ce44SJohn Forte scf_strerror(scf_error())); 2563fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2564fcf3ce44SJohn Forte goto err; 2565fcf3ce44SJohn Forte } 2566fcf3ce44SJohn Forte 2567fcf3ce44SJohn Forte if (scf_handle_bind(*handle) == -1) { 2568fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_handle_bind failed - %s", 2569fcf3ce44SJohn Forte scf_strerror(scf_error())); 2570fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2571fcf3ce44SJohn Forte goto err; 2572fcf3ce44SJohn Forte } 2573fcf3ce44SJohn Forte 2574fcf3ce44SJohn Forte if ((*service = scf_service_create(*handle)) == NULL) { 2575fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_service_create failed - %s", 2576fcf3ce44SJohn Forte scf_strerror(scf_error())); 2577fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2578fcf3ce44SJohn Forte goto err; 2579fcf3ce44SJohn Forte } 2580fcf3ce44SJohn Forte 2581fcf3ce44SJohn Forte if ((scope = scf_scope_create(*handle)) == NULL) { 2582fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_scope_create failed - %s", 2583fcf3ce44SJohn Forte scf_strerror(scf_error())); 2584fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2585fcf3ce44SJohn Forte goto err; 2586fcf3ce44SJohn Forte } 2587fcf3ce44SJohn Forte 2588fcf3ce44SJohn Forte if (scf_handle_get_scope(*handle, SCF_SCOPE_LOCAL, scope) == -1) { 2589fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_handle_get_scope failed - %s", 2590fcf3ce44SJohn Forte scf_strerror(scf_error())); 2591fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2592fcf3ce44SJohn Forte goto err; 2593fcf3ce44SJohn Forte } 2594fcf3ce44SJohn Forte 2595fcf3ce44SJohn Forte if (scf_scope_get_service(scope, STMF_SERVICE, *service) == -1) { 2596fcf3ce44SJohn Forte syslog(LOG_ERR, "scf_scope_get_service failed - %s", 2597fcf3ce44SJohn Forte scf_strerror(scf_error())); 2598fcf3ce44SJohn Forte ret = STMF_PS_ERROR_SERVICE_NOT_FOUND; 2599fcf3ce44SJohn Forte goto err; 2600fcf3ce44SJohn Forte } 2601fcf3ce44SJohn Forte 2602fcf3ce44SJohn Forte 2603fcf3ce44SJohn Forte /* 2604fcf3ce44SJohn Forte * Get and check the version number 2605fcf3ce44SJohn Forte */ 2606fcf3ce44SJohn Forte ret = iPsGetServiceVersion(&version, *handle, *service); 2607fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 2608fcf3ce44SJohn Forte goto err; 2609fcf3ce44SJohn Forte } 2610fcf3ce44SJohn Forte 2611fcf3ce44SJohn Forte if (version != STMF_SMF_VERSION) { 2612fcf3ce44SJohn Forte ret = STMF_PS_ERROR_VERSION_MISMATCH; 2613fcf3ce44SJohn Forte goto err; 2614fcf3ce44SJohn Forte } 2615fcf3ce44SJohn Forte 2616fcf3ce44SJohn Forte /* we only need destroy the scope here */ 2617fcf3ce44SJohn Forte scf_scope_destroy(scope); 2618fcf3ce44SJohn Forte 2619fcf3ce44SJohn Forte return (STMF_PS_SUCCESS); 2620fcf3ce44SJohn Forte 2621fcf3ce44SJohn Forte err: 2622fcf3ce44SJohn Forte if (*handle != NULL) { 2623fcf3ce44SJohn Forte scf_handle_destroy(*handle); 2624fcf3ce44SJohn Forte } 2625fcf3ce44SJohn Forte if (*service != NULL) { 2626fcf3ce44SJohn Forte scf_service_destroy(*service); 2627fcf3ce44SJohn Forte *service = NULL; 2628fcf3ce44SJohn Forte } 2629fcf3ce44SJohn Forte if (scope != NULL) { 2630fcf3ce44SJohn Forte scf_scope_destroy(scope); 2631fcf3ce44SJohn Forte } 2632fcf3ce44SJohn Forte return (ret); 2633fcf3ce44SJohn Forte } 2634fcf3ce44SJohn Forte 26358fe96085Stim szeto 2636fcf3ce44SJohn Forte /* 2637fcf3ce44SJohn Forte * called by iPsInit only 2638fcf3ce44SJohn Forte * iPsGetServiceVersion 2639fcf3ce44SJohn Forte */ 2640fcf3ce44SJohn Forte static int 2641fcf3ce44SJohn Forte iPsGetServiceVersion(uint64_t *version, scf_handle_t *handle, 2642fcf3ce44SJohn Forte scf_service_t *svc) 2643fcf3ce44SJohn Forte { 2644fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 2645fcf3ce44SJohn Forte scf_property_t *prop = NULL; 2646fcf3ce44SJohn Forte scf_value_t *value = NULL; 2647fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 2648fcf3ce44SJohn Forte scf_transaction_entry_t *entry = NULL; 2649fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 2650fcf3ce44SJohn Forte int commitRet; 2651fcf3ce44SJohn Forte 2652fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 2653fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 2654fcf3ce44SJohn Forte ((entry = scf_entry_create(handle)) == NULL) || 2655fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL) || 2656fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 2657fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 2658fcf3ce44SJohn Forte scf_strerror(scf_error())); 2659fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2660fcf3ce44SJohn Forte goto out; 2661fcf3ce44SJohn Forte } 2662fcf3ce44SJohn Forte 2663fcf3ce44SJohn Forte *version = STMF_SMF_VERSION; 2664fcf3ce44SJohn Forte 2665fcf3ce44SJohn Forte /* 2666fcf3ce44SJohn Forte * get stmf data property group 2667fcf3ce44SJohn Forte */ 2668fcf3ce44SJohn Forte if (scf_service_get_pg(svc, STMF_DATA_GROUP, pg) == -1) { 2669fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 2670fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 2671fcf3ce44SJohn Forte } else { 267286b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 267386b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 2674fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2675fcf3ce44SJohn Forte goto out; 2676fcf3ce44SJohn Forte } 2677fcf3ce44SJohn Forte } 2678fcf3ce44SJohn Forte 2679fcf3ce44SJohn Forte /* create the group */ 2680fcf3ce44SJohn Forte if (ret == STMF_PS_ERROR_NOT_FOUND) { 2681fcf3ce44SJohn Forte /* 2682fcf3ce44SJohn Forte * create the property group. 2683fcf3ce44SJohn Forte */ 2684fcf3ce44SJohn Forte if (scf_service_add_pg(svc, STMF_DATA_GROUP, 2685fcf3ce44SJohn Forte SCF_GROUP_APPLICATION, 0, pg) == -1) { 268686b7dbefSPeter Gill syslog(LOG_ERR, "add pg %s failed - %s", 268786b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 2688fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2689fcf3ce44SJohn Forte goto out; 2690fcf3ce44SJohn Forte } 2691fcf3ce44SJohn Forte /* reset return value */ 2692fcf3ce44SJohn Forte ret = STMF_PS_SUCCESS; 2693fcf3ce44SJohn Forte } 2694fcf3ce44SJohn Forte 2695fcf3ce44SJohn Forte /* find version property */ 2696fcf3ce44SJohn Forte /* 2697fcf3ce44SJohn Forte * Get the version property 2698fcf3ce44SJohn Forte */ 2699fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VERSION_NAME, prop) == -1) { 2700fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 2701fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 2702fcf3ce44SJohn Forte } else { 270386b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 270486b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2705fcf3ce44SJohn Forte scf_strerror(scf_error())); 2706fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2707fcf3ce44SJohn Forte goto out; 2708fcf3ce44SJohn Forte } 2709fcf3ce44SJohn Forte } 2710fcf3ce44SJohn Forte 2711fcf3ce44SJohn Forte /* no version property found */ 2712fcf3ce44SJohn Forte if (ret == STMF_PS_ERROR_NOT_FOUND) { 2713fcf3ce44SJohn Forte /* 2714fcf3ce44SJohn Forte * If we have no version property, go ahead 2715fcf3ce44SJohn Forte * and create it. We're obviously making an assumption 2716fcf3ce44SJohn Forte * here that someone did not delete the existing property 2717fcf3ce44SJohn Forte * and that this is the initial set and the initial call 2718fcf3ce44SJohn Forte * to iPsInit. 2719fcf3ce44SJohn Forte * If they did delete it, this will simply plant this 2720fcf3ce44SJohn Forte * library's version on this service. That may or may not be 2721fcf3ce44SJohn Forte * correct and we have no way of determining that. 2722fcf3ce44SJohn Forte */ 2723fcf3ce44SJohn Forte /* 2724fcf3ce44SJohn Forte * Begin the transaction 2725fcf3ce44SJohn Forte */ 2726fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 272786b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 272886b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 2729fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2730fcf3ce44SJohn Forte goto out; 2731fcf3ce44SJohn Forte } 2732fcf3ce44SJohn Forte 2733fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry, 2734fcf3ce44SJohn Forte STMF_VERSION_NAME, SCF_TYPE_COUNT) == -1) { 2735fcf3ce44SJohn Forte syslog(LOG_ERR, 273686b7dbefSPeter Gill "transaction property new %s/%s failed - %s", 273786b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2738fcf3ce44SJohn Forte scf_strerror(scf_error())); 2739fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2740fcf3ce44SJohn Forte goto out; 2741fcf3ce44SJohn Forte } 2742fcf3ce44SJohn Forte 2743fcf3ce44SJohn Forte /* 2744fcf3ce44SJohn Forte * set the version number 2745fcf3ce44SJohn Forte */ 2746fcf3ce44SJohn Forte scf_value_set_count(value, *version); 2747fcf3ce44SJohn Forte 2748fcf3ce44SJohn Forte /* 2749fcf3ce44SJohn Forte * add the value to the transaction 2750fcf3ce44SJohn Forte */ 2751fcf3ce44SJohn Forte if (scf_entry_add_value(entry, value) == -1) { 275286b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 275386b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2754fcf3ce44SJohn Forte scf_strerror(scf_error())); 2755fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2756fcf3ce44SJohn Forte goto out; 2757fcf3ce44SJohn Forte } 2758fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 275986b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 276086b7dbefSPeter Gill STMF_DATA_GROUP, scf_strerror(scf_error())); 2761fcf3ce44SJohn Forte if (commitRet == 0) { 2762fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 2763fcf3ce44SJohn Forte } else { 2764fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2765fcf3ce44SJohn Forte } 2766fcf3ce44SJohn Forte goto out; 2767fcf3ce44SJohn Forte } 2768fcf3ce44SJohn Forte /* reset return value */ 2769fcf3ce44SJohn Forte ret = STMF_PS_SUCCESS; 2770fcf3ce44SJohn Forte } else { 2771fcf3ce44SJohn Forte /* get the version property */ 2772fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VERSION_NAME, prop) == -1) { 277386b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 277486b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2775fcf3ce44SJohn Forte scf_strerror(scf_error())); 2776fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2777fcf3ce44SJohn Forte goto out; 2778fcf3ce44SJohn Forte } 2779fcf3ce44SJohn Forte 2780fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 278186b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 278286b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2783fcf3ce44SJohn Forte scf_strerror(scf_error())); 2784fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2785fcf3ce44SJohn Forte goto out; 2786fcf3ce44SJohn Forte } 2787fcf3ce44SJohn Forte 2788fcf3ce44SJohn Forte /* 2789fcf3ce44SJohn Forte * Get the actual value of the view entry count property 2790fcf3ce44SJohn Forte */ 2791fcf3ce44SJohn Forte if (scf_value_get_count(value, version) == -1) { 279286b7dbefSPeter Gill syslog(LOG_ERR, "get count value %s/%s failed - %s", 279386b7dbefSPeter Gill STMF_DATA_GROUP, STMF_VERSION_NAME, 2794fcf3ce44SJohn Forte scf_strerror(scf_error())); 2795fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2796fcf3ce44SJohn Forte goto out; 2797fcf3ce44SJohn Forte } 2798fcf3ce44SJohn Forte } 2799fcf3ce44SJohn Forte 2800fcf3ce44SJohn Forte out: 2801fcf3ce44SJohn Forte /* 2802fcf3ce44SJohn Forte * Free resources. 2803fcf3ce44SJohn Forte * handle and svc should not be free'd here. They're 2804fcf3ce44SJohn Forte * free'd elsewhere 2805fcf3ce44SJohn Forte */ 2806fcf3ce44SJohn Forte if (pg != NULL) { 2807fcf3ce44SJohn Forte scf_pg_destroy(pg); 2808fcf3ce44SJohn Forte } 2809fcf3ce44SJohn Forte if (prop != NULL) { 2810fcf3ce44SJohn Forte scf_property_destroy(prop); 2811fcf3ce44SJohn Forte } 2812fcf3ce44SJohn Forte if (entry != NULL) { 2813fcf3ce44SJohn Forte scf_entry_destroy(entry); 2814fcf3ce44SJohn Forte } 2815fcf3ce44SJohn Forte if (tran != NULL) { 2816fcf3ce44SJohn Forte scf_transaction_destroy(tran); 2817fcf3ce44SJohn Forte } 2818fcf3ce44SJohn Forte if (value != NULL) { 2819fcf3ce44SJohn Forte scf_value_destroy(value); 2820fcf3ce44SJohn Forte } 2821fcf3ce44SJohn Forte return (ret); 2822fcf3ce44SJohn Forte } 2823fcf3ce44SJohn Forte 2824fcf3ce44SJohn Forte 2825fcf3ce44SJohn Forte 2826fcf3ce44SJohn Forte /* 2827fcf3ce44SJohn Forte * iPsGetActualGroupName 2828fcf3ce44SJohn Forte * 2829fcf3ce44SJohn Forte * pgName - Property group name 2830fcf3ce44SJohn Forte * groupName - requested group name 2831fcf3ce44SJohn Forte * actualName - actual group name to reference (len must be >= MAXNAMELEN) 2832fcf3ce44SJohn Forte * 2833fcf3ce44SJohn Forte * returns: 2834fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 2835fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 2836fcf3ce44SJohn Forte */ 2837fcf3ce44SJohn Forte static int 2838fcf3ce44SJohn Forte iPsGetActualGroupName(char *pgName, char *groupName, char *actualName) 2839fcf3ce44SJohn Forte { 2840fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 2841fcf3ce44SJohn Forte scf_service_t *svc = NULL; 2842fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 2843fcf3ce44SJohn Forte scf_property_t *prop = NULL; 2844fcf3ce44SJohn Forte scf_iter_t *propIter = NULL; 2845fcf3ce44SJohn Forte scf_value_t *value = NULL; 2846fcf3ce44SJohn Forte char buf[MAXNAMELEN]; 2847fcf3ce44SJohn Forte int ret; 2848fcf3ce44SJohn Forte 2849fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 2850fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 2851fcf3ce44SJohn Forte goto out; 2852fcf3ce44SJohn Forte } 2853fcf3ce44SJohn Forte 2854fcf3ce44SJohn Forte /* 2855fcf3ce44SJohn Forte * Allocate scf resources 2856fcf3ce44SJohn Forte */ 2857fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 2858fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 2859fcf3ce44SJohn Forte ((propIter = scf_iter_create(handle)) == NULL) || 2860fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 2861fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 2862fcf3ce44SJohn Forte scf_strerror(scf_error())); 2863fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2864fcf3ce44SJohn Forte goto out; 2865fcf3ce44SJohn Forte } 2866fcf3ce44SJohn Forte 2867fcf3ce44SJohn Forte /* 2868fcf3ce44SJohn Forte * get group list property group 2869fcf3ce44SJohn Forte */ 2870fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 2871fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 2872fcf3ce44SJohn Forte ret = STMF_PS_ERROR_GROUP_NOT_FOUND; 2873fcf3ce44SJohn Forte } else { 287486b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 287586b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 2876fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2877fcf3ce44SJohn Forte } 2878fcf3ce44SJohn Forte goto out; 2879fcf3ce44SJohn Forte } 2880fcf3ce44SJohn Forte 2881fcf3ce44SJohn Forte /* 2882fcf3ce44SJohn Forte * propIter is the iterator handle 2883fcf3ce44SJohn Forte */ 2884fcf3ce44SJohn Forte if (scf_iter_pg_properties(propIter, pg) == -1) { 288586b7dbefSPeter Gill syslog(LOG_ERR, "iter properties for %s failed - %s", 288686b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 2887fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2888fcf3ce44SJohn Forte goto out; 2889fcf3ce44SJohn Forte } 2890fcf3ce44SJohn Forte 2891fcf3ce44SJohn Forte /* 2892fcf3ce44SJohn Forte * Iterate through group properties searching for the requested 2893fcf3ce44SJohn Forte * group name. When we find it, we need to get the property name 2894fcf3ce44SJohn Forte * since it refers to the actual group name. 2895fcf3ce44SJohn Forte */ 2896fcf3ce44SJohn Forte 2897fcf3ce44SJohn Forte /* initialize to not found */ 2898fcf3ce44SJohn Forte ret = STMF_PS_ERROR_GROUP_NOT_FOUND; 2899fcf3ce44SJohn Forte while (scf_iter_next_property(propIter, prop) == 1) { 2900fcf3ce44SJohn Forte if (scf_property_get_name(prop, actualName, MAXNAMELEN) == -1) { 290186b7dbefSPeter Gill syslog(LOG_ERR, "get name from %s iter failed - %s", 290286b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 2903fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2904fcf3ce44SJohn Forte break; 2905fcf3ce44SJohn Forte } 2906fcf3ce44SJohn Forte /* 2907fcf3ce44SJohn Forte * Skip over non-member list properties 2908fcf3ce44SJohn Forte */ 2909fcf3ce44SJohn Forte if (strstr(actualName, STMF_MEMBER_LIST_SUFFIX)) { 2910fcf3ce44SJohn Forte continue; 2911fcf3ce44SJohn Forte } 2912fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 291386b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 291486b7dbefSPeter Gill pgName, actualName, scf_strerror(scf_error())); 2915fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2916fcf3ce44SJohn Forte break; 2917fcf3ce44SJohn Forte } 2918fcf3ce44SJohn Forte if (scf_value_get_ustring(value, buf, sizeof (buf)) == -1) { 291986b7dbefSPeter Gill syslog(LOG_ERR, "get ustring %s/%s failed - %s", 292086b7dbefSPeter Gill pgName, actualName, scf_strerror(scf_error())); 2921fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 2922fcf3ce44SJohn Forte break; 2923fcf3ce44SJohn Forte } 2924fcf3ce44SJohn Forte 2925fcf3ce44SJohn Forte /* 2926fcf3ce44SJohn Forte * When we find a match, set success and break 2927fcf3ce44SJohn Forte */ 2928fcf3ce44SJohn Forte if ((strlen(buf) == strlen(groupName)) && 2929fcf3ce44SJohn Forte bcmp(buf, groupName, strlen(buf)) == 0) { 2930fcf3ce44SJohn Forte ret = STMF_PS_SUCCESS; 2931fcf3ce44SJohn Forte break; 2932fcf3ce44SJohn Forte } 2933fcf3ce44SJohn Forte } 2934fcf3ce44SJohn Forte 2935fcf3ce44SJohn Forte /* 2936fcf3ce44SJohn Forte * if we didn't find it, ret is set to STMF_PS_ERROR_GROUP_NOT_FOUND 2937fcf3ce44SJohn Forte */ 2938fcf3ce44SJohn Forte 2939fcf3ce44SJohn Forte out: 2940fcf3ce44SJohn Forte /* 2941fcf3ce44SJohn Forte * Free resources 2942fcf3ce44SJohn Forte */ 2943fcf3ce44SJohn Forte if (handle != NULL) { 2944fcf3ce44SJohn Forte scf_handle_destroy(handle); 2945fcf3ce44SJohn Forte } 2946fcf3ce44SJohn Forte if (svc != NULL) { 2947fcf3ce44SJohn Forte scf_service_destroy(svc); 2948fcf3ce44SJohn Forte } 2949fcf3ce44SJohn Forte if (pg != NULL) { 2950fcf3ce44SJohn Forte scf_pg_destroy(pg); 2951fcf3ce44SJohn Forte } 2952fcf3ce44SJohn Forte if (propIter != NULL) { 2953fcf3ce44SJohn Forte scf_iter_destroy(propIter); 2954fcf3ce44SJohn Forte } 2955fcf3ce44SJohn Forte if (prop != NULL) { 2956fcf3ce44SJohn Forte scf_property_destroy(prop); 2957fcf3ce44SJohn Forte } 2958fcf3ce44SJohn Forte if (value != NULL) { 2959fcf3ce44SJohn Forte scf_value_destroy(value); 2960fcf3ce44SJohn Forte } 2961fcf3ce44SJohn Forte 2962fcf3ce44SJohn Forte return (ret); 2963fcf3ce44SJohn Forte } 2964fcf3ce44SJohn Forte 2965fcf3ce44SJohn Forte /* 2966fcf3ce44SJohn Forte * psAddHostGroupMember 2967fcf3ce44SJohn Forte * 2968fcf3ce44SJohn Forte * Add a host group member to a host group, 2969fcf3ce44SJohn Forte * 2970fcf3ce44SJohn Forte * Input: groupName - name of group to which the member is added 2971fcf3ce44SJohn Forte * memberName - name of group member to add 2972fcf3ce44SJohn Forte */ 2973fcf3ce44SJohn Forte int 2974fcf3ce44SJohn Forte psAddHostGroupMember(char *groupName, char *memberName) 2975fcf3ce44SJohn Forte { 2976fcf3ce44SJohn Forte int ret; 2977fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 2978fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 2979fcf3ce44SJohn Forte 2980fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName, 2981fcf3ce44SJohn Forte groupPropName); 2982fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 2983fcf3ce44SJohn Forte return (ret); 2984fcf3ce44SJohn Forte } 2985fcf3ce44SJohn Forte 2986fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 2987fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 2988fcf3ce44SJohn Forte sizeof (groupPropListName)) { 2989fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 2990fcf3ce44SJohn Forte groupPropName); 2991fcf3ce44SJohn Forte return (STMF_PS_ERROR); 2992fcf3ce44SJohn Forte } 2993fcf3ce44SJohn Forte 2994fcf3ce44SJohn Forte return (iPsAddRemoveGroupMember(STMF_HOST_GROUPS, groupPropListName, 2995fcf3ce44SJohn Forte memberName, ADD)); 2996fcf3ce44SJohn Forte } 2997fcf3ce44SJohn Forte 2998fcf3ce44SJohn Forte /* 2999fcf3ce44SJohn Forte * psAddTargetGroupMember 3000fcf3ce44SJohn Forte * 3001fcf3ce44SJohn Forte * Add a target port group member to a target group 3002fcf3ce44SJohn Forte * 3003fcf3ce44SJohn Forte * Input: groupName - name of group to which the member is added 3004fcf3ce44SJohn Forte * memberName - name of group member to add. Must be nul terminated. 3005fcf3ce44SJohn Forte */ 3006fcf3ce44SJohn Forte int 3007fcf3ce44SJohn Forte psAddTargetGroupMember(char *groupName, char *memberName) 3008fcf3ce44SJohn Forte { 3009fcf3ce44SJohn Forte int ret; 3010fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 3011fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 3012fcf3ce44SJohn Forte 3013fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName, 3014fcf3ce44SJohn Forte groupPropName); 3015fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3016fcf3ce44SJohn Forte return (ret); 3017fcf3ce44SJohn Forte } 3018fcf3ce44SJohn Forte 3019fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 3020fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 3021fcf3ce44SJohn Forte sizeof (groupPropListName)) { 3022fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 3023fcf3ce44SJohn Forte groupPropName); 3024fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3025fcf3ce44SJohn Forte } 3026fcf3ce44SJohn Forte 3027fcf3ce44SJohn Forte return (iPsAddRemoveGroupMember(STMF_TARGET_GROUPS, groupPropListName, 3028fcf3ce44SJohn Forte memberName, ADD)); 3029fcf3ce44SJohn Forte } 3030fcf3ce44SJohn Forte 3031fcf3ce44SJohn Forte 3032fcf3ce44SJohn Forte /* 3033fcf3ce44SJohn Forte * psAddViewEntry 3034fcf3ce44SJohn Forte * 3035fcf3ce44SJohn Forte * luGuid - logical unit identifier 3036fcf3ce44SJohn Forte * viewEntry - pointer to viewEntry allocated by the caller that contains 3037fcf3ce44SJohn Forte * the values to set for this view entry 3038fcf3ce44SJohn Forte * 3039fcf3ce44SJohn Forte * returns: 3040fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3041fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3042fcf3ce44SJohn Forte */ 3043fcf3ce44SJohn Forte int 3044fcf3ce44SJohn Forte psAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry) 3045fcf3ce44SJohn Forte { 3046fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 3047fcf3ce44SJohn Forte scf_service_t *svc = NULL; 3048fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 3049fcf3ce44SJohn Forte char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */ 3050fcf3ce44SJohn Forte char viewEntryPgName[VIEW_ENTRY_PG_SIZE]; 3051fcf3ce44SJohn Forte char scfLuPgName[LOGICAL_UNIT_PG_SIZE]; 3052fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 3053fcf3ce44SJohn Forte sigset_t sigmaskRestore; 3054fcf3ce44SJohn Forte 3055fcf3ce44SJohn Forte /* grab the signal hold lock */ 3056fcf3ce44SJohn Forte (void) pthread_mutex_lock(&sigSetLock); 3057fcf3ce44SJohn Forte 3058fcf3ce44SJohn Forte /* 3059fcf3ce44SJohn Forte * hold signals until we're done 3060fcf3ce44SJohn Forte */ 3061fcf3ce44SJohn Forte if (holdSignal(&sigmaskRestore) != 0) { 3062fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&sigSetLock); 3063fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3064fcf3ce44SJohn Forte } 3065fcf3ce44SJohn Forte 3066fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 3067fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3068fcf3ce44SJohn Forte goto out; 3069fcf3ce44SJohn Forte } 3070fcf3ce44SJohn Forte 3071fcf3ce44SJohn Forte pg = scf_pg_create(handle); 3072fcf3ce44SJohn Forte if (pg == NULL) { 3073fcf3ce44SJohn Forte syslog(LOG_ERR, "scf pg alloc failed - %s", 3074fcf3ce44SJohn Forte scf_strerror(scf_error())); 3075fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3076fcf3ce44SJohn Forte goto out; 3077fcf3ce44SJohn Forte } 3078fcf3ce44SJohn Forte 3079fcf3ce44SJohn Forte /* Convert to ASCII uppercase hexadecimal string */ 3080fcf3ce44SJohn Forte (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 3081fcf3ce44SJohn Forte "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 3082fcf3ce44SJohn Forte lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4], 3083fcf3ce44SJohn Forte lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9], 3084fcf3ce44SJohn Forte lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13], 3085fcf3ce44SJohn Forte lu->guid[14], lu->guid[15]); 3086fcf3ce44SJohn Forte 3087fcf3ce44SJohn Forte (void) snprintf(scfLuPgName, sizeof (scfLuPgName), "%s-%s", 3088fcf3ce44SJohn Forte STMF_LU_PREFIX, guidAsciiBuf); 3089fcf3ce44SJohn Forte 3090fcf3ce44SJohn Forte bzero(viewEntryPgName, sizeof (viewEntryPgName)); 3091fcf3ce44SJohn Forte /* 3092fcf3ce44SJohn Forte * Format of view entry property group name: 3093fcf3ce44SJohn Forte * VE-<view_entry_name>-<lu_name> 3094fcf3ce44SJohn Forte */ 3095fcf3ce44SJohn Forte (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName), 3096fcf3ce44SJohn Forte "%s-%d-%s", STMF_VE_PREFIX, viewEntry->veIndex, guidAsciiBuf); 3097fcf3ce44SJohn Forte 3098fcf3ce44SJohn Forte ret = iPsAddViewEntry(scfLuPgName, viewEntryPgName, viewEntry); 3099fcf3ce44SJohn Forte 3100fcf3ce44SJohn Forte out: 3101fcf3ce44SJohn Forte /* 3102fcf3ce44SJohn Forte * Okay, we're done. Release the signals 3103fcf3ce44SJohn Forte */ 3104fcf3ce44SJohn Forte if (releaseSignal(&sigmaskRestore) != 0) { 3105fcf3ce44SJohn Forte /* 3106fcf3ce44SJohn Forte * Don't set this as an STMF_PS_ERROR_*. We succeeded 3107fcf3ce44SJohn Forte * the requested operation. But we do need to log it. 3108fcf3ce44SJohn Forte */ 3109fcf3ce44SJohn Forte syslog(LOG_ERR, "Unable to release one or more signals - %s", 3110fcf3ce44SJohn Forte strerror(errno)); 3111fcf3ce44SJohn Forte } 3112fcf3ce44SJohn Forte 3113fcf3ce44SJohn Forte /* 3114fcf3ce44SJohn Forte * Free resources 3115fcf3ce44SJohn Forte */ 3116fcf3ce44SJohn Forte if (handle != NULL) { 3117fcf3ce44SJohn Forte scf_handle_destroy(handle); 3118fcf3ce44SJohn Forte } 3119fcf3ce44SJohn Forte if (svc != NULL) { 3120fcf3ce44SJohn Forte scf_service_destroy(svc); 3121fcf3ce44SJohn Forte } 3122fcf3ce44SJohn Forte if (pg != NULL) { 3123fcf3ce44SJohn Forte scf_pg_destroy(pg); 3124fcf3ce44SJohn Forte } 3125fcf3ce44SJohn Forte 3126fcf3ce44SJohn Forte /* release the signal hold lock */ 3127fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&sigSetLock); 3128fcf3ce44SJohn Forte 3129fcf3ce44SJohn Forte return (ret); 3130fcf3ce44SJohn Forte } 3131fcf3ce44SJohn Forte 3132fcf3ce44SJohn Forte /* 3133fcf3ce44SJohn Forte * psCheckService 3134fcf3ce44SJohn Forte * 3135fcf3ce44SJohn Forte * Purpose: Checks whether service exists 3136fcf3ce44SJohn Forte * 3137fcf3ce44SJohn Forte */ 3138fcf3ce44SJohn Forte int 3139fcf3ce44SJohn Forte psCheckService() 3140fcf3ce44SJohn Forte { 3141fcf3ce44SJohn Forte int ret; 3142fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 3143fcf3ce44SJohn Forte scf_service_t *svc = NULL; 3144fcf3ce44SJohn Forte 3145fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 3146fcf3ce44SJohn Forte 3147fcf3ce44SJohn Forte /* 3148fcf3ce44SJohn Forte * Free resources 3149fcf3ce44SJohn Forte */ 3150fcf3ce44SJohn Forte if (handle != NULL) { 3151fcf3ce44SJohn Forte scf_handle_destroy(handle); 3152fcf3ce44SJohn Forte } 3153fcf3ce44SJohn Forte if (svc != NULL) { 3154fcf3ce44SJohn Forte scf_service_destroy(svc); 3155fcf3ce44SJohn Forte } 3156fcf3ce44SJohn Forte 3157fcf3ce44SJohn Forte return (ret); 3158fcf3ce44SJohn Forte } 3159fcf3ce44SJohn Forte 3160fcf3ce44SJohn Forte /* 3161fcf3ce44SJohn Forte * psCreateHostGroup 3162fcf3ce44SJohn Forte * 3163fcf3ce44SJohn Forte * groupName - name of group to create 3164fcf3ce44SJohn Forte * 3165fcf3ce44SJohn Forte * returns: 3166fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3167fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3168fcf3ce44SJohn Forte */ 3169fcf3ce44SJohn Forte int 3170fcf3ce44SJohn Forte psCreateHostGroup(char *groupName) 3171fcf3ce44SJohn Forte { 3172fcf3ce44SJohn Forte return (iPsCreateDeleteGroup(STMF_HOST_GROUPS, groupName, ADD)); 3173fcf3ce44SJohn Forte } 3174fcf3ce44SJohn Forte 3175fcf3ce44SJohn Forte /* 3176fcf3ce44SJohn Forte * psCreateTargetGroup 3177fcf3ce44SJohn Forte * 3178fcf3ce44SJohn Forte * groupName - name of group to create 3179fcf3ce44SJohn Forte * 3180fcf3ce44SJohn Forte * returns: 3181fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3182fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3183fcf3ce44SJohn Forte */ 3184fcf3ce44SJohn Forte int 3185fcf3ce44SJohn Forte psCreateTargetGroup(char *groupName) 3186fcf3ce44SJohn Forte { 3187fcf3ce44SJohn Forte return (iPsCreateDeleteGroup(STMF_TARGET_GROUPS, groupName, ADD)); 3188fcf3ce44SJohn Forte } 3189fcf3ce44SJohn Forte 3190fcf3ce44SJohn Forte /* 3191fcf3ce44SJohn Forte * psDeleteHostGroup 3192fcf3ce44SJohn Forte * 3193fcf3ce44SJohn Forte * groupName - name of group to delete 3194fcf3ce44SJohn Forte * 3195fcf3ce44SJohn Forte * returns: 3196fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3197fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3198fcf3ce44SJohn Forte */ 3199fcf3ce44SJohn Forte int 3200fcf3ce44SJohn Forte psDeleteHostGroup(char *groupName) 3201fcf3ce44SJohn Forte { 3202fcf3ce44SJohn Forte return (iPsCreateDeleteGroup(STMF_HOST_GROUPS, groupName, REMOVE)); 3203fcf3ce44SJohn Forte } 3204fcf3ce44SJohn Forte 3205fcf3ce44SJohn Forte /* 3206fcf3ce44SJohn Forte * psDeleteTargetGroup 3207fcf3ce44SJohn Forte * 3208fcf3ce44SJohn Forte * groupName - name of group to delete 3209fcf3ce44SJohn Forte * 3210fcf3ce44SJohn Forte * returns: 3211fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3212fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3213fcf3ce44SJohn Forte */ 3214fcf3ce44SJohn Forte int 3215fcf3ce44SJohn Forte psDeleteTargetGroup(char *groupName) 3216fcf3ce44SJohn Forte { 3217fcf3ce44SJohn Forte return (iPsCreateDeleteGroup(STMF_TARGET_GROUPS, groupName, 3218fcf3ce44SJohn Forte REMOVE)); 3219fcf3ce44SJohn Forte } 3220fcf3ce44SJohn Forte 3221fcf3ce44SJohn Forte /* 3222fcf3ce44SJohn Forte * psGetHostGroupList 3223fcf3ce44SJohn Forte * 3224fcf3ce44SJohn Forte * groupList - pointer to pointer to stmfGroupList. Contains the list 3225fcf3ce44SJohn Forte * of host groups on successful return. 3226fcf3ce44SJohn Forte * 3227fcf3ce44SJohn Forte * returns: 3228fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3229fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3230fcf3ce44SJohn Forte */ 3231fcf3ce44SJohn Forte int 3232fcf3ce44SJohn Forte psGetHostGroupList(stmfGroupList **groupList) 3233fcf3ce44SJohn Forte { 3234fcf3ce44SJohn Forte return (iPsGetGroupList(STMF_HOST_GROUPS, groupList)); 3235fcf3ce44SJohn Forte } 3236fcf3ce44SJohn Forte 3237fcf3ce44SJohn Forte /* 3238fcf3ce44SJohn Forte * psGetLogicalUnitList 3239fcf3ce44SJohn Forte * 3240fcf3ce44SJohn Forte * 3241fcf3ce44SJohn Forte */ 3242fcf3ce44SJohn Forte int 3243fcf3ce44SJohn Forte psGetLogicalUnitList(stmfGuidList **guidList) 3244fcf3ce44SJohn Forte { 3245fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 3246fcf3ce44SJohn Forte scf_service_t *svc = NULL; 3247fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 3248fcf3ce44SJohn Forte scf_iter_t *pgIter = NULL; 3249fcf3ce44SJohn Forte char buf[MAXNAMELEN]; 3250fcf3ce44SJohn Forte int guidCnt = 0; 3251fcf3ce44SJohn Forte int i = 0, j; 3252fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 3253fcf3ce44SJohn Forte unsigned int guid[sizeof (stmfGuid)]; 3254fcf3ce44SJohn Forte stmfGuid outGuid; 3255fcf3ce44SJohn Forte 3256fcf3ce44SJohn Forte assert(guidList != NULL); 3257fcf3ce44SJohn Forte 3258fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 3259fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3260fcf3ce44SJohn Forte goto out; 3261fcf3ce44SJohn Forte } 3262fcf3ce44SJohn Forte 3263fcf3ce44SJohn Forte /* 3264fcf3ce44SJohn Forte * Allocate scf resources 3265fcf3ce44SJohn Forte */ 3266fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 3267fcf3ce44SJohn Forte ((pgIter = scf_iter_create(handle)) == NULL)) { 3268fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 3269fcf3ce44SJohn Forte scf_strerror(scf_error())); 3270fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3271fcf3ce44SJohn Forte goto out; 3272fcf3ce44SJohn Forte } 3273fcf3ce44SJohn Forte 3274fcf3ce44SJohn Forte /* 3275fcf3ce44SJohn Forte * pgIter is the iterator handle 3276fcf3ce44SJohn Forte */ 3277fcf3ce44SJohn Forte if (scf_iter_service_pgs(pgIter, svc) == -1) { 3278fcf3ce44SJohn Forte syslog(LOG_ERR, "iter property groups failed - %s", 3279fcf3ce44SJohn Forte scf_strerror(scf_error())); 3280fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3281fcf3ce44SJohn Forte goto out; 3282fcf3ce44SJohn Forte } 3283fcf3ce44SJohn Forte 3284fcf3ce44SJohn Forte while (scf_iter_next_pg(pgIter, pg) == 1) { 3285fcf3ce44SJohn Forte if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) { 328686b7dbefSPeter Gill syslog(LOG_ERR, "get pg name failed - %s", 3287fcf3ce44SJohn Forte scf_strerror(scf_error())); 3288fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3289fcf3ce44SJohn Forte break; 3290fcf3ce44SJohn Forte } 3291fcf3ce44SJohn Forte /* 3292fcf3ce44SJohn Forte * Only count LU property groups 3293fcf3ce44SJohn Forte */ 3294fcf3ce44SJohn Forte if (strncmp(buf, STMF_LU_PREFIX, strlen(STMF_LU_PREFIX)) == 0) { 3295fcf3ce44SJohn Forte guidCnt++; 3296fcf3ce44SJohn Forte } 3297fcf3ce44SJohn Forte } 3298fcf3ce44SJohn Forte 3299fcf3ce44SJohn Forte /* 3300fcf3ce44SJohn Forte * pgIter is the iterator handle 3301fcf3ce44SJohn Forte */ 3302fcf3ce44SJohn Forte if (scf_iter_service_pgs(pgIter, svc) == -1) { 3303fcf3ce44SJohn Forte syslog(LOG_ERR, "iter property groups failed - %s", 3304fcf3ce44SJohn Forte scf_strerror(scf_error())); 3305fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3306fcf3ce44SJohn Forte goto out; 3307fcf3ce44SJohn Forte } 3308fcf3ce44SJohn Forte 3309fcf3ce44SJohn Forte *guidList = (stmfGuidList *)calloc(1, sizeof (stmfGuidList) + 3310fcf3ce44SJohn Forte guidCnt * sizeof (stmfGuid)); 3311fcf3ce44SJohn Forte if (*guidList == NULL) { 3312fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 3313fcf3ce44SJohn Forte goto out; 3314fcf3ce44SJohn Forte } 3315fcf3ce44SJohn Forte 3316fcf3ce44SJohn Forte /* 3317fcf3ce44SJohn Forte * it's possible for entries to be added/removed while we're retrieving 3318fcf3ce44SJohn Forte * the property groups. Just make sure we don't write beyond our 3319fcf3ce44SJohn Forte * allocated buffer by checking to ensure i < guidCnt. 3320fcf3ce44SJohn Forte */ 3321fcf3ce44SJohn Forte while ((scf_iter_next_pg(pgIter, pg) == 1) && (i < guidCnt)) { 3322fcf3ce44SJohn Forte if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) { 332386b7dbefSPeter Gill syslog(LOG_ERR, "get pg name failed - %s", 3324fcf3ce44SJohn Forte scf_strerror(scf_error())); 3325fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3326fcf3ce44SJohn Forte break; 3327fcf3ce44SJohn Forte } 3328fcf3ce44SJohn Forte /* 3329fcf3ce44SJohn Forte * Only use LU property groups 3330fcf3ce44SJohn Forte */ 3331fcf3ce44SJohn Forte if (strncmp(buf, STMF_LU_PREFIX, strlen(STMF_LU_PREFIX)) != 0) { 3332fcf3ce44SJohn Forte continue; 3333fcf3ce44SJohn Forte } 3334fcf3ce44SJohn Forte 3335fcf3ce44SJohn Forte j = strlen(STMF_LU_PREFIX) + strlen("-"); 3336fcf3ce44SJohn Forte 3337fcf3ce44SJohn Forte (void) sscanf(buf + j, 3338fcf3ce44SJohn Forte "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", 3339fcf3ce44SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5], 3340fcf3ce44SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], 3341fcf3ce44SJohn Forte &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]); 3342fcf3ce44SJohn Forte 3343fcf3ce44SJohn Forte for (j = 0; j < sizeof (stmfGuid); j++) { 3344fcf3ce44SJohn Forte outGuid.guid[j] = guid[j]; 3345fcf3ce44SJohn Forte } 3346fcf3ce44SJohn Forte 3347fcf3ce44SJohn Forte bcopy(&outGuid, (*guidList)->guid[i++].guid, sizeof (stmfGuid)); 3348fcf3ce44SJohn Forte (*guidList)->cnt++; 3349fcf3ce44SJohn Forte } 3350fcf3ce44SJohn Forte 3351fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3352fcf3ce44SJohn Forte free(*guidList); 3353fcf3ce44SJohn Forte goto out; 3354fcf3ce44SJohn Forte } 3355fcf3ce44SJohn Forte 3356fcf3ce44SJohn Forte out: 3357fcf3ce44SJohn Forte /* 3358fcf3ce44SJohn Forte * Free resources 3359fcf3ce44SJohn Forte */ 3360fcf3ce44SJohn Forte if (handle != NULL) { 3361fcf3ce44SJohn Forte scf_handle_destroy(handle); 3362fcf3ce44SJohn Forte } 3363fcf3ce44SJohn Forte if (svc != NULL) { 3364fcf3ce44SJohn Forte scf_service_destroy(svc); 3365fcf3ce44SJohn Forte } 3366fcf3ce44SJohn Forte if (pg != NULL) { 3367fcf3ce44SJohn Forte scf_pg_destroy(pg); 3368fcf3ce44SJohn Forte } 3369fcf3ce44SJohn Forte if (pgIter != NULL) { 3370fcf3ce44SJohn Forte scf_iter_destroy(pgIter); 3371fcf3ce44SJohn Forte } 3372fcf3ce44SJohn Forte 3373fcf3ce44SJohn Forte return (ret); 3374fcf3ce44SJohn Forte } 3375fcf3ce44SJohn Forte 3376fcf3ce44SJohn Forte /* 3377fcf3ce44SJohn Forte * psGetTargetGroupList 3378fcf3ce44SJohn Forte * 3379fcf3ce44SJohn Forte * groupList - pointer to pointer to stmfGroupList. Contains the list 3380fcf3ce44SJohn Forte * of target groups on successful return. 3381fcf3ce44SJohn Forte * 3382fcf3ce44SJohn Forte * returns: 3383fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3384fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3385fcf3ce44SJohn Forte */ 3386fcf3ce44SJohn Forte int 3387fcf3ce44SJohn Forte psGetTargetGroupList(stmfGroupList **groupList) 3388fcf3ce44SJohn Forte { 3389fcf3ce44SJohn Forte return (iPsGetGroupList(STMF_TARGET_GROUPS, groupList)); 3390fcf3ce44SJohn Forte } 3391fcf3ce44SJohn Forte 3392fcf3ce44SJohn Forte /* 3393fcf3ce44SJohn Forte * psGetHostGroupMemberList 3394fcf3ce44SJohn Forte * 3395fcf3ce44SJohn Forte * groupName - group name for which to retrieve a member list 3396fcf3ce44SJohn Forte * groupMemberList - pointer to pointer to stmfGroupProperties list 3397fcf3ce44SJohn Forte * 3398fcf3ce44SJohn Forte * returns: 3399fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3400fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3401fcf3ce44SJohn Forte */ 3402fcf3ce44SJohn Forte int 3403fcf3ce44SJohn Forte psGetHostGroupMemberList(char *groupName, stmfGroupProperties **groupMemberList) 3404fcf3ce44SJohn Forte { 3405fcf3ce44SJohn Forte int ret; 3406fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 3407fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 3408fcf3ce44SJohn Forte 3409fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName, 3410fcf3ce44SJohn Forte groupPropName); 3411fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3412fcf3ce44SJohn Forte return (ret); 3413fcf3ce44SJohn Forte } 3414fcf3ce44SJohn Forte 3415fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 3416fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 3417fcf3ce44SJohn Forte sizeof (groupPropListName)) { 3418fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 3419fcf3ce44SJohn Forte groupPropName); 3420fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3421fcf3ce44SJohn Forte } 3422fcf3ce44SJohn Forte 3423fcf3ce44SJohn Forte return (iPsGetGroupMemberList(STMF_HOST_GROUPS, groupPropListName, 3424fcf3ce44SJohn Forte groupMemberList)); 3425fcf3ce44SJohn Forte } 3426fcf3ce44SJohn Forte 3427fcf3ce44SJohn Forte /* 3428fcf3ce44SJohn Forte * psGetTargetGroupMemberList 3429fcf3ce44SJohn Forte * 3430fcf3ce44SJohn Forte * groupName - group name for which to retrieve a member list 3431fcf3ce44SJohn Forte * groupMemberList - pointer to pointer to stmfGroupProperties list 3432fcf3ce44SJohn Forte * 3433fcf3ce44SJohn Forte * returns: 3434fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3435fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3436fcf3ce44SJohn Forte */ 3437fcf3ce44SJohn Forte int 3438fcf3ce44SJohn Forte psGetTargetGroupMemberList(char *groupName, 3439fcf3ce44SJohn Forte stmfGroupProperties **groupMemberList) 3440fcf3ce44SJohn Forte { 3441fcf3ce44SJohn Forte int ret; 3442fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 3443fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 3444fcf3ce44SJohn Forte 3445fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName, 3446fcf3ce44SJohn Forte groupPropName); 3447fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3448fcf3ce44SJohn Forte return (ret); 3449fcf3ce44SJohn Forte } 3450fcf3ce44SJohn Forte 3451fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 3452fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 3453fcf3ce44SJohn Forte sizeof (groupPropListName)) { 3454fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 3455fcf3ce44SJohn Forte groupPropName); 3456fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3457fcf3ce44SJohn Forte } 3458fcf3ce44SJohn Forte 3459fcf3ce44SJohn Forte return (iPsGetGroupMemberList(STMF_TARGET_GROUPS, 3460fcf3ce44SJohn Forte groupPropListName, groupMemberList)); 3461fcf3ce44SJohn Forte } 3462fcf3ce44SJohn Forte 3463fcf3ce44SJohn Forte /* 3464fcf3ce44SJohn Forte * qsort function 3465fcf3ce44SJohn Forte * sort on veIndex 3466fcf3ce44SJohn Forte */ 3467fcf3ce44SJohn Forte static int 3468fcf3ce44SJohn Forte viewEntryCompare(const void *p1, const void *p2) 3469fcf3ce44SJohn Forte { 3470fcf3ce44SJohn Forte 3471fcf3ce44SJohn Forte stmfViewEntry *v1 = (stmfViewEntry *)p1, *v2 = (stmfViewEntry *)p2; 3472fcf3ce44SJohn Forte if (v1->veIndex > v2->veIndex) 3473fcf3ce44SJohn Forte return (1); 3474fcf3ce44SJohn Forte if (v1->veIndex < v2->veIndex) 3475fcf3ce44SJohn Forte return (-1); 3476fcf3ce44SJohn Forte return (0); 3477fcf3ce44SJohn Forte } 3478fcf3ce44SJohn Forte 3479fcf3ce44SJohn Forte /* 3480fcf3ce44SJohn Forte * psGetViewEntryList 3481fcf3ce44SJohn Forte * 3482fcf3ce44SJohn Forte * luGuid - identifier of logical unit for which to retrieve a view entry list 3483fcf3ce44SJohn Forte * viewEntryList - pointer to pointer to stmfViewEntryList. It will be allocated 3484fcf3ce44SJohn Forte * on successful return. 3485fcf3ce44SJohn Forte * 3486fcf3ce44SJohn Forte * returns: 3487fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3488fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3489fcf3ce44SJohn Forte */ 3490fcf3ce44SJohn Forte int 3491fcf3ce44SJohn Forte psGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList) 3492fcf3ce44SJohn Forte { 3493fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 3494fcf3ce44SJohn Forte scf_service_t *svc = NULL; 3495fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 3496fcf3ce44SJohn Forte scf_property_t *prop = NULL; 3497fcf3ce44SJohn Forte scf_value_t *value = NULL; 3498fcf3ce44SJohn Forte scf_iter_t *propIter = NULL; 3499fcf3ce44SJohn Forte char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */ 3500fcf3ce44SJohn Forte char viewEntryPgName[VIEW_ENTRY_PG_SIZE]; 3501fcf3ce44SJohn Forte char luPgName[LOGICAL_UNIT_PG_SIZE]; 3502fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 3503fcf3ce44SJohn Forte uint64_t i = 0; 3504fcf3ce44SJohn Forte uint64_t veCnt; 3505fcf3ce44SJohn Forte 3506fcf3ce44SJohn Forte 3507fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 3508fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3509fcf3ce44SJohn Forte goto out; 3510fcf3ce44SJohn Forte } 3511fcf3ce44SJohn Forte 3512fcf3ce44SJohn Forte /* 3513fcf3ce44SJohn Forte * Allocate scf resources 3514fcf3ce44SJohn Forte */ 3515fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 3516fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 3517fcf3ce44SJohn Forte ((propIter = scf_iter_create(handle)) == NULL) || 3518fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 3519fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 3520fcf3ce44SJohn Forte scf_strerror(scf_error())); 3521fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3522fcf3ce44SJohn Forte goto out; 3523fcf3ce44SJohn Forte } 3524fcf3ce44SJohn Forte 3525fcf3ce44SJohn Forte /* Convert to ASCII uppercase hexadecimal string */ 3526fcf3ce44SJohn Forte (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 3527fcf3ce44SJohn Forte "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 3528fcf3ce44SJohn Forte lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4], 3529fcf3ce44SJohn Forte lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9], 3530fcf3ce44SJohn Forte lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13], 3531fcf3ce44SJohn Forte lu->guid[14], lu->guid[15]); 3532fcf3ce44SJohn Forte 3533fcf3ce44SJohn Forte /* form the LU property group name (LU-<guid>) */ 3534fcf3ce44SJohn Forte (void) snprintf(luPgName, sizeof (luPgName), "%s-%s", 3535fcf3ce44SJohn Forte STMF_LU_PREFIX, guidAsciiBuf); 3536fcf3ce44SJohn Forte 3537fcf3ce44SJohn Forte /* get the property group associated with this LU */ 3538fcf3ce44SJohn Forte if (scf_service_get_pg(svc, luPgName, pg) == -1) { 3539fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 3540fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 3541fcf3ce44SJohn Forte } else { 354286b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 354386b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 3544fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3545fcf3ce44SJohn Forte } 3546fcf3ce44SJohn Forte goto out; 3547fcf3ce44SJohn Forte } 3548fcf3ce44SJohn Forte 3549fcf3ce44SJohn Forte /* get the view entry count property */ 3550fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_CNT, prop) == -1) { 355186b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 355286b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 3553fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3554fcf3ce44SJohn Forte goto out; 3555fcf3ce44SJohn Forte } 3556fcf3ce44SJohn Forte 3557fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 355886b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 355986b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 3560fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3561fcf3ce44SJohn Forte goto out; 3562fcf3ce44SJohn Forte } 3563fcf3ce44SJohn Forte 3564fcf3ce44SJohn Forte /* 3565fcf3ce44SJohn Forte * Get the actual value of the view entry count property 3566fcf3ce44SJohn Forte */ 3567fcf3ce44SJohn Forte if (scf_value_get_count(value, &veCnt) == -1) { 356886b7dbefSPeter Gill syslog(LOG_ERR, "get integer value %s/%s failed - %s", 356986b7dbefSPeter Gill luPgName, STMF_VE_CNT, scf_strerror(scf_error())); 3570fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3571fcf3ce44SJohn Forte goto out; 3572fcf3ce44SJohn Forte } 3573fcf3ce44SJohn Forte 3574fcf3ce44SJohn Forte /* 3575fcf3ce44SJohn Forte * propIter is the iterator handle 3576fcf3ce44SJohn Forte */ 3577fcf3ce44SJohn Forte if (scf_iter_pg_properties(propIter, pg) == -1) { 357886b7dbefSPeter Gill syslog(LOG_ERR, "iter properties for %s failed - %s", 357986b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 3580fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3581fcf3ce44SJohn Forte goto out; 3582fcf3ce44SJohn Forte } 3583fcf3ce44SJohn Forte 3584fcf3ce44SJohn Forte /* 3585fcf3ce44SJohn Forte * alloc the list based on the view entry count 3586fcf3ce44SJohn Forte */ 3587fcf3ce44SJohn Forte *viewEntryList = (stmfViewEntryList *)calloc(1, 3588fcf3ce44SJohn Forte sizeof (stmfViewEntryList) + veCnt * sizeof (stmfViewEntry)); 3589fcf3ce44SJohn Forte if (*viewEntryList == NULL) { 3590fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 3591fcf3ce44SJohn Forte goto out; 3592fcf3ce44SJohn Forte } 3593fcf3ce44SJohn Forte 3594fcf3ce44SJohn Forte i = 0; 3595fcf3ce44SJohn Forte /* 3596fcf3ce44SJohn Forte * iterate through the view entry properties to find the 3597fcf3ce44SJohn Forte * view entries 3598fcf3ce44SJohn Forte */ 3599fcf3ce44SJohn Forte while (scf_iter_next_property(propIter, prop) == 1) { 3600fcf3ce44SJohn Forte /* find match for view entry property */ 3601fcf3ce44SJohn Forte if (scf_property_get_name(prop, viewEntryPgName, 3602fcf3ce44SJohn Forte sizeof (viewEntryPgName)) != -1) { 3603fcf3ce44SJohn Forte if (strncmp(viewEntryPgName, STMF_VE_PREFIX, 3604fcf3ce44SJohn Forte strlen(STMF_VE_PREFIX)) != 0) { 3605fcf3ce44SJohn Forte continue; 3606fcf3ce44SJohn Forte } 3607fcf3ce44SJohn Forte /* 3608fcf3ce44SJohn Forte * We've exceeded our alloc limit 3609fcf3ce44SJohn Forte * break with error 3610fcf3ce44SJohn Forte */ 3611fcf3ce44SJohn Forte if (i == veCnt) { 3612fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3613fcf3ce44SJohn Forte break; 3614fcf3ce44SJohn Forte } 3615fcf3ce44SJohn Forte 3616fcf3ce44SJohn Forte if ((ret = iPsGetViewEntry(viewEntryPgName, 3617fcf3ce44SJohn Forte &((*viewEntryList)->ve[i]))) != STMF_PS_SUCCESS) { 3618fcf3ce44SJohn Forte break; 3619fcf3ce44SJohn Forte } 3620fcf3ce44SJohn Forte 3621fcf3ce44SJohn Forte i++; 3622fcf3ce44SJohn Forte 3623fcf3ce44SJohn Forte /* set the list count */ 3624fcf3ce44SJohn Forte (*viewEntryList)->cnt++; 3625fcf3ce44SJohn Forte } else { 362686b7dbefSPeter Gill syslog(LOG_ERR, "scf iter %s properties failed - %s", 362786b7dbefSPeter Gill luPgName, scf_strerror(scf_error())); 3628fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3629fcf3ce44SJohn Forte break; 3630fcf3ce44SJohn Forte } 3631fcf3ce44SJohn Forte 3632fcf3ce44SJohn Forte } 3633fcf3ce44SJohn Forte 3634fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3635fcf3ce44SJohn Forte free(*viewEntryList); 3636fcf3ce44SJohn Forte goto out; 3637fcf3ce44SJohn Forte } 3638fcf3ce44SJohn Forte 3639fcf3ce44SJohn Forte /* 3640fcf3ce44SJohn Forte * We're sorting the final list here based on the veIndex 3641fcf3ce44SJohn Forte * If we don't, the caller is going to have to do it to reap 3642fcf3ce44SJohn Forte * some intelligent output. 3643fcf3ce44SJohn Forte */ 3644fcf3ce44SJohn Forte qsort((void *)&((*viewEntryList)->ve[0]), (*viewEntryList)->cnt, 3645fcf3ce44SJohn Forte sizeof (stmfViewEntry), viewEntryCompare); 3646fcf3ce44SJohn Forte 3647fcf3ce44SJohn Forte out: 3648fcf3ce44SJohn Forte /* 3649fcf3ce44SJohn Forte * Free resources 3650fcf3ce44SJohn Forte */ 3651fcf3ce44SJohn Forte if (handle != NULL) { 3652fcf3ce44SJohn Forte scf_handle_destroy(handle); 3653fcf3ce44SJohn Forte } 3654fcf3ce44SJohn Forte if (svc != NULL) { 3655fcf3ce44SJohn Forte scf_service_destroy(svc); 3656fcf3ce44SJohn Forte } 3657fcf3ce44SJohn Forte if (pg != NULL) { 3658fcf3ce44SJohn Forte scf_pg_destroy(pg); 3659fcf3ce44SJohn Forte } 3660fcf3ce44SJohn Forte if (prop != NULL) { 3661fcf3ce44SJohn Forte scf_property_destroy(prop); 3662fcf3ce44SJohn Forte } 3663fcf3ce44SJohn Forte if (value != NULL) { 3664fcf3ce44SJohn Forte scf_value_destroy(value); 3665fcf3ce44SJohn Forte } 3666fcf3ce44SJohn Forte if (propIter != NULL) { 3667fcf3ce44SJohn Forte scf_iter_destroy(propIter); 3668fcf3ce44SJohn Forte } 3669fcf3ce44SJohn Forte 3670fcf3ce44SJohn Forte return (ret); 3671fcf3ce44SJohn Forte } 3672fcf3ce44SJohn Forte 3673fcf3ce44SJohn Forte /* 3674fcf3ce44SJohn Forte * iPsGetViewEntry 3675fcf3ce44SJohn Forte * 3676fcf3ce44SJohn Forte * viewEntryPgName - view entry property group name to retrieve 3677fcf3ce44SJohn Forte * viewEntry - pointer to stmfViewEntry structure allocated by the caller 3678fcf3ce44SJohn Forte * 3679fcf3ce44SJohn Forte * returns: 3680fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3681fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3682fcf3ce44SJohn Forte */ 3683fcf3ce44SJohn Forte static int 3684fcf3ce44SJohn Forte iPsGetViewEntry(char *viewEntryPgName, stmfViewEntry *viewEntry) 3685fcf3ce44SJohn Forte { 3686fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 3687fcf3ce44SJohn Forte scf_service_t *svc = NULL; 3688fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 3689fcf3ce44SJohn Forte scf_property_t *prop = NULL; 3690fcf3ce44SJohn Forte scf_value_t *value = NULL; 3691fcf3ce44SJohn Forte uint8_t scfBool; 3692fcf3ce44SJohn Forte char *indexPtr; 3693fcf3ce44SJohn Forte char groupName[sizeof (stmfGroupName)]; 3694fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 3695fcf3ce44SJohn Forte 3696fcf3ce44SJohn Forte 3697fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 3698fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3699fcf3ce44SJohn Forte goto out; 3700fcf3ce44SJohn Forte } 3701fcf3ce44SJohn Forte 3702fcf3ce44SJohn Forte /* 3703fcf3ce44SJohn Forte * Allocate scf resources 3704fcf3ce44SJohn Forte */ 3705fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 3706fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 3707fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL)) { 3708fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 3709fcf3ce44SJohn Forte scf_strerror(scf_error())); 3710fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3711fcf3ce44SJohn Forte goto out; 3712fcf3ce44SJohn Forte } 3713fcf3ce44SJohn Forte 3714fcf3ce44SJohn Forte bzero(viewEntry, sizeof (stmfViewEntry)); 3715fcf3ce44SJohn Forte 3716fcf3ce44SJohn Forte /* 3717fcf3ce44SJohn Forte * get the service property group view entry handle 3718fcf3ce44SJohn Forte */ 3719fcf3ce44SJohn Forte if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) { 3720fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 3721fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 3722fcf3ce44SJohn Forte } else { 372386b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 372486b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 3725fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3726fcf3ce44SJohn Forte } 3727fcf3ce44SJohn Forte goto out; 3728fcf3ce44SJohn Forte } 3729fcf3ce44SJohn Forte 3730fcf3ce44SJohn Forte 3731fcf3ce44SJohn Forte /* 3732fcf3ce44SJohn Forte * get index 3733fcf3ce44SJohn Forte * format is: VE-<veIndex>-GUID 3734fcf3ce44SJohn Forte */ 3735fcf3ce44SJohn Forte indexPtr = strchr(viewEntryPgName, '-'); 3736fcf3ce44SJohn Forte if (!indexPtr) { 3737fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3738fcf3ce44SJohn Forte goto out; 3739fcf3ce44SJohn Forte } 3740fcf3ce44SJohn Forte 3741fcf3ce44SJohn Forte /* Set the index */ 3742fcf3ce44SJohn Forte viewEntry->veIndex = atoi(strtok(++indexPtr, "-")); 3743fcf3ce44SJohn Forte 3744fcf3ce44SJohn Forte viewEntry->veIndexValid = B_TRUE; 3745fcf3ce44SJohn Forte 3746fcf3ce44SJohn Forte /* get allHosts property */ 3747fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_ALLHOSTS, 3748fcf3ce44SJohn Forte prop) == -1) { 374986b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 375086b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLHOSTS, 3751fcf3ce44SJohn Forte scf_strerror(scf_error())); 3752fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3753fcf3ce44SJohn Forte goto out; 3754fcf3ce44SJohn Forte } 3755fcf3ce44SJohn Forte 3756fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 375786b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 375886b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLHOSTS, 3759fcf3ce44SJohn Forte scf_strerror(scf_error())); 3760fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3761fcf3ce44SJohn Forte goto out; 3762fcf3ce44SJohn Forte } 3763fcf3ce44SJohn Forte 3764fcf3ce44SJohn Forte /* set allHosts */ 3765fcf3ce44SJohn Forte if (scf_value_get_boolean(value, (uint8_t *)&scfBool) == -1) { 376686b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 376786b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLHOSTS, 3768fcf3ce44SJohn Forte scf_strerror(scf_error())); 3769fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3770fcf3ce44SJohn Forte goto out; 3771fcf3ce44SJohn Forte } 3772fcf3ce44SJohn Forte viewEntry->allHosts = scfBool; 3773fcf3ce44SJohn Forte 3774fcf3ce44SJohn Forte /* get hostGroup property */ 3775fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_HOSTGROUP, 3776fcf3ce44SJohn Forte prop) == -1) { 377786b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 377886b7dbefSPeter Gill viewEntryPgName, STMF_VE_HOSTGROUP, 3779fcf3ce44SJohn Forte scf_strerror(scf_error())); 3780fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3781fcf3ce44SJohn Forte goto out; 3782fcf3ce44SJohn Forte } 3783fcf3ce44SJohn Forte 3784fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 378586b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 378686b7dbefSPeter Gill viewEntryPgName, STMF_VE_HOSTGROUP, 3787fcf3ce44SJohn Forte scf_strerror(scf_error())); 3788fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3789fcf3ce44SJohn Forte goto out; 3790fcf3ce44SJohn Forte } 3791fcf3ce44SJohn Forte 3792fcf3ce44SJohn Forte if (scf_value_get_ustring(value, groupName, 3793fcf3ce44SJohn Forte sizeof (groupName)) == -1) { 379486b7dbefSPeter Gill syslog(LOG_ERR, "get value %s/%s failed - %s", 379586b7dbefSPeter Gill viewEntryPgName, STMF_VE_HOSTGROUP, 3796fcf3ce44SJohn Forte scf_strerror(scf_error())); 3797fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3798fcf3ce44SJohn Forte goto out; 3799fcf3ce44SJohn Forte } 3800fcf3ce44SJohn Forte /* set hostGroup */ 3801fcf3ce44SJohn Forte bcopy(groupName, viewEntry->hostGroup, strlen(groupName)); 3802fcf3ce44SJohn Forte 3803fcf3ce44SJohn Forte /* get allTargets property */ 3804fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_ALLTARGETS, 3805fcf3ce44SJohn Forte prop) == -1) { 380686b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 380786b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLTARGETS, 3808fcf3ce44SJohn Forte scf_strerror(scf_error())); 3809fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3810fcf3ce44SJohn Forte goto out; 3811fcf3ce44SJohn Forte } 3812fcf3ce44SJohn Forte 3813fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 381486b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 381586b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLTARGETS, 3816fcf3ce44SJohn Forte scf_strerror(scf_error())); 3817fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3818fcf3ce44SJohn Forte goto out; 3819fcf3ce44SJohn Forte } 3820fcf3ce44SJohn Forte 3821fcf3ce44SJohn Forte /* set allTargets */ 3822fcf3ce44SJohn Forte if (scf_value_get_boolean(value, (uint8_t *)&scfBool) == -1) { 382386b7dbefSPeter Gill syslog(LOG_ERR, "get value %s/%s failed - %s", 382486b7dbefSPeter Gill viewEntryPgName, STMF_VE_ALLTARGETS, 3825fcf3ce44SJohn Forte scf_strerror(scf_error())); 3826fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3827fcf3ce44SJohn Forte goto out; 3828fcf3ce44SJohn Forte } 3829fcf3ce44SJohn Forte viewEntry->allTargets = scfBool; 3830fcf3ce44SJohn Forte 3831fcf3ce44SJohn Forte /* get targetGroup property */ 3832fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_TARGETGROUP, prop) == -1) { 383386b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 383486b7dbefSPeter Gill viewEntryPgName, STMF_VE_TARGETGROUP, 3835fcf3ce44SJohn Forte scf_strerror(scf_error())); 3836fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3837fcf3ce44SJohn Forte goto out; 3838fcf3ce44SJohn Forte } 3839fcf3ce44SJohn Forte 3840fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 384186b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 384286b7dbefSPeter Gill viewEntryPgName, STMF_VE_TARGETGROUP, 3843fcf3ce44SJohn Forte scf_strerror(scf_error())); 3844fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3845fcf3ce44SJohn Forte goto out; 3846fcf3ce44SJohn Forte } 3847fcf3ce44SJohn Forte 3848fcf3ce44SJohn Forte if (scf_value_get_ustring(value, groupName, 3849fcf3ce44SJohn Forte sizeof (groupName)) == -1) { 385086b7dbefSPeter Gill syslog(LOG_ERR, "get value %s/%s failed - %s", 385186b7dbefSPeter Gill viewEntryPgName, STMF_VE_TARGETGROUP, 3852fcf3ce44SJohn Forte scf_strerror(scf_error())); 3853fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3854fcf3ce44SJohn Forte goto out; 3855fcf3ce44SJohn Forte } 3856fcf3ce44SJohn Forte /* set targetGroup */ 3857fcf3ce44SJohn Forte bcopy(groupName, viewEntry->targetGroup, strlen(groupName)); 3858fcf3ce44SJohn Forte 3859fcf3ce44SJohn Forte /* get luNbr property */ 3860fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_VE_LUNBR, 3861fcf3ce44SJohn Forte prop) == -1) { 386286b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 386386b7dbefSPeter Gill viewEntryPgName, STMF_VE_LUNBR, 3864fcf3ce44SJohn Forte scf_strerror(scf_error())); 3865fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3866fcf3ce44SJohn Forte goto out; 3867fcf3ce44SJohn Forte } 3868fcf3ce44SJohn Forte 3869fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 387086b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 387186b7dbefSPeter Gill viewEntryPgName, STMF_VE_LUNBR, 3872fcf3ce44SJohn Forte scf_strerror(scf_error())); 3873fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3874fcf3ce44SJohn Forte goto out; 3875fcf3ce44SJohn Forte } 3876fcf3ce44SJohn Forte 3877fcf3ce44SJohn Forte /* set luNbr */ 3878fcf3ce44SJohn Forte if (scf_value_get_opaque(value, (char *)viewEntry->luNbr, 3879fcf3ce44SJohn Forte sizeof (viewEntry->luNbr)) == -1) { 388086b7dbefSPeter Gill syslog(LOG_ERR, "get opaque value %s/%s failed - %s", 388186b7dbefSPeter Gill viewEntryPgName, STMF_VE_LUNBR, 3882fcf3ce44SJohn Forte scf_strerror(scf_error())); 3883fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 3884fcf3ce44SJohn Forte goto out; 3885fcf3ce44SJohn Forte } 3886fcf3ce44SJohn Forte /* set luNbrValid to true since we just got it */ 3887fcf3ce44SJohn Forte viewEntry->luNbrValid = B_TRUE; 3888fcf3ce44SJohn Forte 3889fcf3ce44SJohn Forte out: 3890fcf3ce44SJohn Forte /* 3891fcf3ce44SJohn Forte * Free resources 3892fcf3ce44SJohn Forte */ 3893fcf3ce44SJohn Forte if (handle != NULL) { 3894fcf3ce44SJohn Forte scf_handle_destroy(handle); 3895fcf3ce44SJohn Forte } 3896fcf3ce44SJohn Forte if (svc != NULL) { 3897fcf3ce44SJohn Forte scf_service_destroy(svc); 3898fcf3ce44SJohn Forte } 3899fcf3ce44SJohn Forte if (pg != NULL) { 3900fcf3ce44SJohn Forte scf_pg_destroy(pg); 3901fcf3ce44SJohn Forte } 3902fcf3ce44SJohn Forte if (value != NULL) { 3903fcf3ce44SJohn Forte scf_value_destroy(value); 3904fcf3ce44SJohn Forte } 3905fcf3ce44SJohn Forte if (prop != NULL) { 3906fcf3ce44SJohn Forte scf_property_destroy(prop); 3907fcf3ce44SJohn Forte } 3908fcf3ce44SJohn Forte 3909fcf3ce44SJohn Forte return (ret); 3910fcf3ce44SJohn Forte } 3911fcf3ce44SJohn Forte 3912fcf3ce44SJohn Forte 3913fcf3ce44SJohn Forte /* 3914fcf3ce44SJohn Forte * psRemoveHostGroupMember 3915fcf3ce44SJohn Forte * 3916fcf3ce44SJohn Forte * Remove a host group member from a host group, 3917fcf3ce44SJohn Forte * 3918fcf3ce44SJohn Forte * groupName - name of group from which the member is removed 3919fcf3ce44SJohn Forte * memberName - name of group member to remove 3920fcf3ce44SJohn Forte * 3921fcf3ce44SJohn Forte * returns: 3922fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3923fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3924fcf3ce44SJohn Forte */ 3925fcf3ce44SJohn Forte int 3926fcf3ce44SJohn Forte psRemoveHostGroupMember(char *groupName, char *memberName) 3927fcf3ce44SJohn Forte { 3928fcf3ce44SJohn Forte int ret; 3929fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 3930fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 3931fcf3ce44SJohn Forte 3932fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_HOST_GROUPS, groupName, 3933fcf3ce44SJohn Forte groupPropName); 3934fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3935fcf3ce44SJohn Forte return (ret); 3936fcf3ce44SJohn Forte } 3937fcf3ce44SJohn Forte 3938fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 3939fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 3940fcf3ce44SJohn Forte sizeof (groupPropListName)) { 3941fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 3942fcf3ce44SJohn Forte groupPropName); 3943fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3944fcf3ce44SJohn Forte } 3945fcf3ce44SJohn Forte 3946fcf3ce44SJohn Forte return (iPsAddRemoveGroupMember(STMF_HOST_GROUPS, groupPropListName, 3947fcf3ce44SJohn Forte memberName, REMOVE)); 3948fcf3ce44SJohn Forte } 3949fcf3ce44SJohn Forte 3950fcf3ce44SJohn Forte /* 3951fcf3ce44SJohn Forte * psRemoveTargetGroupMember 3952fcf3ce44SJohn Forte * 3953fcf3ce44SJohn Forte * Remove a target port group member from an target port group, 3954fcf3ce44SJohn Forte * 3955fcf3ce44SJohn Forte * groupName - name of group from which the member is removed 3956fcf3ce44SJohn Forte * memberName - name of group member to remove 3957fcf3ce44SJohn Forte * 3958fcf3ce44SJohn Forte * returns: 3959fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 3960fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 3961fcf3ce44SJohn Forte */ 3962fcf3ce44SJohn Forte int 3963fcf3ce44SJohn Forte psRemoveTargetGroupMember(char *groupName, char *memberName) 3964fcf3ce44SJohn Forte { 3965fcf3ce44SJohn Forte int ret; 3966fcf3ce44SJohn Forte char groupPropListName[MAXNAMELEN]; 3967fcf3ce44SJohn Forte char groupPropName[MAXNAMELEN]; 3968fcf3ce44SJohn Forte 3969fcf3ce44SJohn Forte ret = iPsGetActualGroupName(STMF_TARGET_GROUPS, groupName, 3970fcf3ce44SJohn Forte groupPropName); 3971fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 3972fcf3ce44SJohn Forte return (ret); 3973fcf3ce44SJohn Forte } 3974fcf3ce44SJohn Forte 3975fcf3ce44SJohn Forte if (snprintf(groupPropListName, sizeof (groupPropListName), 3976fcf3ce44SJohn Forte "%s-%s", groupPropName, STMF_MEMBER_LIST_SUFFIX) > 3977fcf3ce44SJohn Forte sizeof (groupPropListName)) { 3978fcf3ce44SJohn Forte syslog(LOG_ERR, "buffer overflow on property name %s", 3979fcf3ce44SJohn Forte groupPropName); 3980fcf3ce44SJohn Forte return (STMF_PS_ERROR); 3981fcf3ce44SJohn Forte } 3982fcf3ce44SJohn Forte 3983fcf3ce44SJohn Forte return (iPsAddRemoveGroupMember(STMF_TARGET_GROUPS, groupPropListName, 3984fcf3ce44SJohn Forte memberName, REMOVE)); 3985fcf3ce44SJohn Forte } 3986fcf3ce44SJohn Forte 3987fcf3ce44SJohn Forte /* 3988fcf3ce44SJohn Forte * psGetProviderData 3989fcf3ce44SJohn Forte * 3990fcf3ce44SJohn Forte * Retrieves an nvlist on a per provider basis 3991fcf3ce44SJohn Forte * 3992fcf3ce44SJohn Forte * providerName - property group name to use 3993fcf3ce44SJohn Forte * nvl - nvlist to retrieve 3994fcf3ce44SJohn Forte * 3995fcf3ce44SJohn Forte */ 3996fcf3ce44SJohn Forte int 3997fcf3ce44SJohn Forte psGetProviderData(char *providerName, nvlist_t **nvl, int providerType, 3998fcf3ce44SJohn Forte uint64_t *setToken) 3999fcf3ce44SJohn Forte { 4000fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 4001fcf3ce44SJohn Forte scf_service_t *svc = NULL; 4002fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 4003fcf3ce44SJohn Forte scf_property_t *prop = NULL; 4004fcf3ce44SJohn Forte scf_value_t *value = NULL; 4005fcf3ce44SJohn Forte uint64_t blockCnt = 0; 4006fcf3ce44SJohn Forte ssize_t blockOffset = 0; 4007fcf3ce44SJohn Forte ssize_t actualBlockSize = 0; 4008fcf3ce44SJohn Forte char pgName[MAXPATHLEN]; 4009fcf3ce44SJohn Forte char dataPropertyName[STMF_PROVIDER_DATA_PROP_NAME_SIZE]; 4010fcf3ce44SJohn Forte char *nvlistEncoded = NULL; 4011fcf3ce44SJohn Forte ssize_t nvlistEncodedSize = 0; 4012fcf3ce44SJohn Forte boolean_t foundSetCnt = B_TRUE; 4013fcf3ce44SJohn Forte int i; 4014fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 4015fcf3ce44SJohn Forte 4016fcf3ce44SJohn Forte if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE && 4017fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE)) { 4018fcf3ce44SJohn Forte ret = STMF_PS_ERROR_INVALID_ARG; 4019fcf3ce44SJohn Forte goto out; 4020fcf3ce44SJohn Forte } 4021fcf3ce44SJohn Forte 4022fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 4023fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 4024fcf3ce44SJohn Forte goto out; 4025fcf3ce44SJohn Forte } 4026fcf3ce44SJohn Forte 4027fcf3ce44SJohn Forte /* 4028fcf3ce44SJohn Forte * create the property group name 4029fcf3ce44SJohn Forte */ 4030fcf3ce44SJohn Forte (void) snprintf(pgName, sizeof (pgName), "%s%s", 4031fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PREFIX, providerName); 4032fcf3ce44SJohn Forte 4033fcf3ce44SJohn Forte /* 4034fcf3ce44SJohn Forte * Allocate scf resources 4035fcf3ce44SJohn Forte */ 4036fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 4037fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL) || 4038fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL)) { 4039fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 4040fcf3ce44SJohn Forte scf_strerror(scf_error())); 4041fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4042fcf3ce44SJohn Forte goto out; 4043fcf3ce44SJohn Forte } 4044fcf3ce44SJohn Forte 4045fcf3ce44SJohn Forte /* 4046fcf3ce44SJohn Forte * Retrieve the existing property group. 4047fcf3ce44SJohn Forte */ 4048fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 4049fcf3ce44SJohn Forte if (scf_error() != SCF_ERROR_NOT_FOUND) { 405086b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", pgName, 4051fcf3ce44SJohn Forte scf_strerror(scf_error())); 4052fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4053fcf3ce44SJohn Forte goto out; 4054fcf3ce44SJohn Forte } else { 4055fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 4056fcf3ce44SJohn Forte goto out; 4057fcf3ce44SJohn Forte } 4058fcf3ce44SJohn Forte } 4059fcf3ce44SJohn Forte 4060fcf3ce44SJohn Forte /* 4061fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_COUNT property 4062fcf3ce44SJohn Forte */ 4063fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_COUNT, 4064fcf3ce44SJohn Forte prop) == -1) { 406586b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 406686b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4067fcf3ce44SJohn Forte scf_strerror(scf_error())); 4068fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4069fcf3ce44SJohn Forte goto out; 4070fcf3ce44SJohn Forte } 4071fcf3ce44SJohn Forte 4072fcf3ce44SJohn Forte /* 4073fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_COUNT value 4074fcf3ce44SJohn Forte */ 4075fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 407686b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 407786b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4078fcf3ce44SJohn Forte scf_strerror(scf_error())); 4079fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4080fcf3ce44SJohn Forte goto out; 4081fcf3ce44SJohn Forte } 4082fcf3ce44SJohn Forte 4083fcf3ce44SJohn Forte /* 4084fcf3ce44SJohn Forte * Now get the actual value from the value handle 4085fcf3ce44SJohn Forte */ 4086fcf3ce44SJohn Forte if (scf_value_get_count(value, &blockCnt) == -1) { 408786b7dbefSPeter Gill syslog(LOG_ERR, "get integer value %s/%s failed - %s", 408886b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4089fcf3ce44SJohn Forte scf_strerror(scf_error())); 4090fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4091fcf3ce44SJohn Forte goto out; 4092fcf3ce44SJohn Forte } 4093fcf3ce44SJohn Forte 4094fcf3ce44SJohn Forte /* Has the caller requested the token to be set? */ 4095fcf3ce44SJohn Forte if (setToken) { 4096fcf3ce44SJohn Forte /* 4097fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT property 4098fcf3ce44SJohn Forte * If it doesn't exist, we assume it to be zero. 4099fcf3ce44SJohn Forte */ 4100fcf3ce44SJohn Forte *setToken = 0; 4101fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4102fcf3ce44SJohn Forte prop) == -1) { 4103fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 4104fcf3ce44SJohn Forte foundSetCnt = B_FALSE; 4105fcf3ce44SJohn Forte } else { 410686b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s " 410786b7dbefSPeter Gill "failed - %s", pgName, 410886b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_SET_COUNT, 4109fcf3ce44SJohn Forte scf_strerror(scf_error())); 4110fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4111fcf3ce44SJohn Forte goto out; 4112fcf3ce44SJohn Forte } 4113fcf3ce44SJohn Forte } 4114fcf3ce44SJohn Forte 4115fcf3ce44SJohn Forte if (foundSetCnt) { 4116fcf3ce44SJohn Forte /* 4117fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT value 4118fcf3ce44SJohn Forte */ 4119fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 4120fcf3ce44SJohn Forte syslog(LOG_ERR, 412186b7dbefSPeter Gill "get property value %s/%s failed - %s", 412286b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4123fcf3ce44SJohn Forte scf_strerror(scf_error())); 4124fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4125fcf3ce44SJohn Forte goto out; 4126fcf3ce44SJohn Forte } 4127fcf3ce44SJohn Forte 4128fcf3ce44SJohn Forte /* 4129fcf3ce44SJohn Forte * Now get the actual value from the value handle 4130fcf3ce44SJohn Forte * and set the caller's token 4131fcf3ce44SJohn Forte */ 4132fcf3ce44SJohn Forte if (scf_value_get_count(value, setToken) == -1) { 4133fcf3ce44SJohn Forte syslog(LOG_ERR, 413486b7dbefSPeter Gill "get integer value %s/%s failed - %s", 413586b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4136fcf3ce44SJohn Forte scf_strerror(scf_error())); 4137fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4138fcf3ce44SJohn Forte goto out; 4139fcf3ce44SJohn Forte } 4140fcf3ce44SJohn Forte } 4141fcf3ce44SJohn Forte } 4142fcf3ce44SJohn Forte 4143fcf3ce44SJohn Forte nvlistEncoded = (char *)calloc(1, 4144fcf3ce44SJohn Forte blockCnt * STMF_PROVIDER_DATA_PROP_SIZE); 4145fcf3ce44SJohn Forte if (nvlistEncoded == NULL) { 4146fcf3ce44SJohn Forte syslog(LOG_ERR, "nvlistEncoded alloc failed"); 4147fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4148fcf3ce44SJohn Forte goto out; 4149fcf3ce44SJohn Forte } 4150fcf3ce44SJohn Forte 4151fcf3ce44SJohn Forte for (i = 0; i < blockCnt; i++) { 4152fcf3ce44SJohn Forte bzero(dataPropertyName, sizeof (dataPropertyName)); 4153fcf3ce44SJohn Forte /* 4154fcf3ce44SJohn Forte * create the name to use for the property 4155fcf3ce44SJohn Forte */ 4156fcf3ce44SJohn Forte (void) snprintf(dataPropertyName, sizeof (dataPropertyName), 4157fcf3ce44SJohn Forte "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i); 4158fcf3ce44SJohn Forte 4159fcf3ce44SJohn Forte if (scf_pg_get_property(pg, dataPropertyName, prop) == -1) { 416086b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 416186b7dbefSPeter Gill pgName, dataPropertyName, 4162fcf3ce44SJohn Forte scf_strerror(scf_error())); 4163fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4164fcf3ce44SJohn Forte goto out; 4165fcf3ce44SJohn Forte } 4166fcf3ce44SJohn Forte 4167fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 416886b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 416986b7dbefSPeter Gill pgName, dataPropertyName, 4170fcf3ce44SJohn Forte scf_strerror(scf_error())); 4171fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4172fcf3ce44SJohn Forte goto out; 4173fcf3ce44SJohn Forte } 4174fcf3ce44SJohn Forte 4175fcf3ce44SJohn Forte /* 4176fcf3ce44SJohn Forte * Set the data block offset 4177fcf3ce44SJohn Forte */ 4178fcf3ce44SJohn Forte blockOffset = STMF_PROVIDER_DATA_PROP_SIZE * i; 4179fcf3ce44SJohn Forte actualBlockSize = scf_value_get_opaque(value, 4180fcf3ce44SJohn Forte &nvlistEncoded[blockOffset], STMF_PROVIDER_DATA_PROP_SIZE); 4181fcf3ce44SJohn Forte if (actualBlockSize == -1) { 418286b7dbefSPeter Gill syslog(LOG_ERR, "get opaque property value %s/%s " 418386b7dbefSPeter Gill "failed - %s", pgName, dataPropertyName, 4184fcf3ce44SJohn Forte scf_strerror(scf_error())); 4185fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4186fcf3ce44SJohn Forte goto out; 4187fcf3ce44SJohn Forte } 4188fcf3ce44SJohn Forte nvlistEncodedSize += actualBlockSize; 4189fcf3ce44SJohn Forte } 4190fcf3ce44SJohn Forte 4191fcf3ce44SJohn Forte if (nvlist_unpack(nvlistEncoded, nvlistEncodedSize, nvl, 0) != 0) { 4192fcf3ce44SJohn Forte syslog(LOG_ERR, "unable to unpack nvlist"); 4193fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4194fcf3ce44SJohn Forte goto out; 4195fcf3ce44SJohn Forte } 4196fcf3ce44SJohn Forte 4197fcf3ce44SJohn Forte 4198fcf3ce44SJohn Forte out: 4199fcf3ce44SJohn Forte /* 4200fcf3ce44SJohn Forte * Free resources 4201fcf3ce44SJohn Forte */ 4202fcf3ce44SJohn Forte if (handle != NULL) { 4203fcf3ce44SJohn Forte scf_handle_destroy(handle); 4204fcf3ce44SJohn Forte } 4205fcf3ce44SJohn Forte if (svc != NULL) { 4206fcf3ce44SJohn Forte scf_service_destroy(svc); 4207fcf3ce44SJohn Forte } 4208fcf3ce44SJohn Forte if (pg != NULL) { 4209fcf3ce44SJohn Forte scf_pg_destroy(pg); 4210fcf3ce44SJohn Forte } 4211fcf3ce44SJohn Forte if (prop != NULL) { 4212fcf3ce44SJohn Forte scf_property_destroy(prop); 4213fcf3ce44SJohn Forte } 4214fcf3ce44SJohn Forte if (value != NULL) { 4215fcf3ce44SJohn Forte scf_value_destroy(value); 4216fcf3ce44SJohn Forte } 4217fcf3ce44SJohn Forte if (nvlistEncoded != NULL) { 4218fcf3ce44SJohn Forte free(nvlistEncoded); 4219fcf3ce44SJohn Forte } 4220fcf3ce44SJohn Forte 4221fcf3ce44SJohn Forte return (ret); 4222fcf3ce44SJohn Forte 4223fcf3ce44SJohn Forte } 4224fcf3ce44SJohn Forte /* 4225fcf3ce44SJohn Forte * psGetProviderDataList 4226fcf3ce44SJohn Forte * 4227fcf3ce44SJohn Forte * Retrieves the list of providers that currently store persistent data 4228fcf3ce44SJohn Forte * 4229fcf3ce44SJohn Forte * providerList - pointer to a pointer to an stmfProviderList structure 4230fcf3ce44SJohn Forte * On success, this will contain the list of providers 4231fcf3ce44SJohn Forte * currently storing persistent data. 4232fcf3ce44SJohn Forte */ 4233fcf3ce44SJohn Forte int 4234fcf3ce44SJohn Forte psGetProviderDataList(stmfProviderList **providerList) 4235fcf3ce44SJohn Forte { 4236fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 4237fcf3ce44SJohn Forte scf_service_t *svc = NULL; 4238fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 4239fcf3ce44SJohn Forte scf_property_t *prop = NULL; 4240fcf3ce44SJohn Forte scf_value_t *value = NULL; 4241fcf3ce44SJohn Forte scf_iter_t *pgIter = NULL; 4242fcf3ce44SJohn Forte char buf[MAXNAMELEN]; 4243fcf3ce44SJohn Forte int providerCnt = 0; 4244fcf3ce44SJohn Forte int64_t providerType; 4245fcf3ce44SJohn Forte int i = 0, j; 4246fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 4247fcf3ce44SJohn Forte 4248fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 4249fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 4250fcf3ce44SJohn Forte goto out; 4251fcf3ce44SJohn Forte } 4252fcf3ce44SJohn Forte 4253fcf3ce44SJohn Forte *providerList = NULL; 4254fcf3ce44SJohn Forte 4255fcf3ce44SJohn Forte /* 4256fcf3ce44SJohn Forte * Allocate scf resources 4257fcf3ce44SJohn Forte */ 4258fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 4259fcf3ce44SJohn Forte ((value = scf_value_create(handle)) == NULL) || 4260fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 4261fcf3ce44SJohn Forte ((pgIter = scf_iter_create(handle)) == NULL)) { 4262fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 4263fcf3ce44SJohn Forte scf_strerror(scf_error())); 4264fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4265fcf3ce44SJohn Forte goto out; 4266fcf3ce44SJohn Forte } 4267fcf3ce44SJohn Forte 4268fcf3ce44SJohn Forte /* 4269fcf3ce44SJohn Forte * pgIter is the iterator handle 4270fcf3ce44SJohn Forte */ 4271fcf3ce44SJohn Forte if (scf_iter_service_pgs(pgIter, svc) == -1) { 4272fcf3ce44SJohn Forte syslog(LOG_ERR, "iter property groups failed - %s", 4273fcf3ce44SJohn Forte scf_strerror(scf_error())); 4274fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4275fcf3ce44SJohn Forte goto out; 4276fcf3ce44SJohn Forte } 4277fcf3ce44SJohn Forte 4278fcf3ce44SJohn Forte while (scf_iter_next_pg(pgIter, pg) == 1) { 4279fcf3ce44SJohn Forte if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) { 4280fcf3ce44SJohn Forte syslog(LOG_ERR, "get name failed - %s", 4281fcf3ce44SJohn Forte scf_strerror(scf_error())); 4282fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4283fcf3ce44SJohn Forte break; 4284fcf3ce44SJohn Forte } 4285fcf3ce44SJohn Forte /* 4286fcf3ce44SJohn Forte * Only count LU property groups 4287fcf3ce44SJohn Forte */ 4288fcf3ce44SJohn Forte if (strncmp(buf, STMF_PROVIDER_DATA_PREFIX, 4289fcf3ce44SJohn Forte strlen(STMF_PROVIDER_DATA_PREFIX)) == 0) { 4290fcf3ce44SJohn Forte providerCnt++; 4291fcf3ce44SJohn Forte } 4292fcf3ce44SJohn Forte } 4293fcf3ce44SJohn Forte 4294fcf3ce44SJohn Forte /* 4295fcf3ce44SJohn Forte * pgIter is the iterator handle 4296fcf3ce44SJohn Forte */ 4297fcf3ce44SJohn Forte if (scf_iter_service_pgs(pgIter, svc) == -1) { 4298fcf3ce44SJohn Forte syslog(LOG_ERR, "iter property groups failed - %s", 4299fcf3ce44SJohn Forte scf_strerror(scf_error())); 4300fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4301fcf3ce44SJohn Forte goto out; 4302fcf3ce44SJohn Forte } 4303fcf3ce44SJohn Forte 4304fcf3ce44SJohn Forte *providerList = (stmfProviderList *)calloc(1, 4305fcf3ce44SJohn Forte sizeof (stmfProviderList) + providerCnt * sizeof (stmfProvider)); 4306fcf3ce44SJohn Forte if (*providerList == NULL) { 4307fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4308fcf3ce44SJohn Forte goto out; 4309fcf3ce44SJohn Forte } 4310fcf3ce44SJohn Forte 4311fcf3ce44SJohn Forte /* 4312fcf3ce44SJohn Forte * it's possible for entries to be added/removed while we're retrieving 4313fcf3ce44SJohn Forte * the property groups. Just make sure we don't write beyond our 4314fcf3ce44SJohn Forte * allocated buffer by checking to ensure i < providerCnt. 4315fcf3ce44SJohn Forte */ 4316fcf3ce44SJohn Forte while ((scf_iter_next_pg(pgIter, pg) == 1) && (i < providerCnt)) { 4317fcf3ce44SJohn Forte if (scf_pg_get_name(pg, buf, sizeof (buf)) == -1) { 4318fcf3ce44SJohn Forte syslog(LOG_ERR, "get name failed - %s", 4319fcf3ce44SJohn Forte scf_strerror(scf_error())); 4320fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4321fcf3ce44SJohn Forte break; 4322fcf3ce44SJohn Forte } 4323fcf3ce44SJohn Forte /* 4324fcf3ce44SJohn Forte * Only use provider data property groups 4325fcf3ce44SJohn Forte */ 4326fcf3ce44SJohn Forte if (strncmp(buf, STMF_PROVIDER_DATA_PREFIX, 4327fcf3ce44SJohn Forte strlen(STMF_PROVIDER_DATA_PREFIX)) != 0) { 4328fcf3ce44SJohn Forte continue; 4329fcf3ce44SJohn Forte } 4330fcf3ce44SJohn Forte 4331fcf3ce44SJohn Forte /* 4332fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_TYPE property 4333fcf3ce44SJohn Forte */ 4334fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_TYPE, 4335fcf3ce44SJohn Forte prop) == -1) { 433686b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 433786b7dbefSPeter Gill buf, STMF_PROVIDER_DATA_PROP_TYPE, 4338fcf3ce44SJohn Forte scf_strerror(scf_error())); 4339fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4340fcf3ce44SJohn Forte break; 4341fcf3ce44SJohn Forte } 4342fcf3ce44SJohn Forte 4343fcf3ce44SJohn Forte /* 4344fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_TYPE value 4345fcf3ce44SJohn Forte */ 4346fcf3ce44SJohn Forte if (scf_property_get_value(prop, value) == -1) { 434786b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 434886b7dbefSPeter Gill buf, STMF_PROVIDER_DATA_PROP_TYPE, 4349fcf3ce44SJohn Forte scf_strerror(scf_error())); 4350fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4351fcf3ce44SJohn Forte break; 4352fcf3ce44SJohn Forte } 4353fcf3ce44SJohn Forte 4354fcf3ce44SJohn Forte /* 4355fcf3ce44SJohn Forte * Now get the actual value from the value handle 4356fcf3ce44SJohn Forte */ 4357fcf3ce44SJohn Forte if (scf_value_get_integer(value, &providerType) == -1) { 435886b7dbefSPeter Gill syslog(LOG_ERR, "get integer value %s/%s failed - %s", 435986b7dbefSPeter Gill buf, STMF_PROVIDER_DATA_PROP_TYPE, 4360fcf3ce44SJohn Forte scf_strerror(scf_error())); 4361fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4362fcf3ce44SJohn Forte break; 4363fcf3ce44SJohn Forte } 4364fcf3ce44SJohn Forte 4365fcf3ce44SJohn Forte (*providerList)->provider[i].providerType = providerType; 4366fcf3ce44SJohn Forte 4367fcf3ce44SJohn Forte /* determine offset for copy of provider name */ 4368fcf3ce44SJohn Forte j = strlen(STMF_PROVIDER_DATA_PREFIX); 4369fcf3ce44SJohn Forte 4370fcf3ce44SJohn Forte /* copy provider name to caller's list */ 4371fcf3ce44SJohn Forte (void) strncpy((*providerList)->provider[i].name, buf + j, 4372fcf3ce44SJohn Forte sizeof ((*providerList)->provider[i].name)); 4373fcf3ce44SJohn Forte i++; 4374fcf3ce44SJohn Forte (*providerList)->cnt++; 4375fcf3ce44SJohn Forte } 4376fcf3ce44SJohn Forte 4377fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 4378fcf3ce44SJohn Forte free(*providerList); 4379fcf3ce44SJohn Forte goto out; 4380fcf3ce44SJohn Forte } 4381fcf3ce44SJohn Forte 4382fcf3ce44SJohn Forte out: 4383fcf3ce44SJohn Forte /* 4384fcf3ce44SJohn Forte * Free resources 4385fcf3ce44SJohn Forte */ 4386fcf3ce44SJohn Forte if (handle != NULL) { 4387fcf3ce44SJohn Forte scf_handle_destroy(handle); 4388fcf3ce44SJohn Forte } 4389fcf3ce44SJohn Forte if (svc != NULL) { 4390fcf3ce44SJohn Forte scf_service_destroy(svc); 4391fcf3ce44SJohn Forte } 4392fcf3ce44SJohn Forte if (pg != NULL) { 4393fcf3ce44SJohn Forte scf_pg_destroy(pg); 4394fcf3ce44SJohn Forte } 4395fcf3ce44SJohn Forte if (value != NULL) { 4396fcf3ce44SJohn Forte scf_value_destroy(value); 4397fcf3ce44SJohn Forte } 4398fcf3ce44SJohn Forte if (prop != NULL) { 4399fcf3ce44SJohn Forte scf_property_destroy(prop); 4400fcf3ce44SJohn Forte } 4401fcf3ce44SJohn Forte if (pgIter != NULL) { 4402fcf3ce44SJohn Forte scf_iter_destroy(pgIter); 4403fcf3ce44SJohn Forte } 4404fcf3ce44SJohn Forte 4405fcf3ce44SJohn Forte return (ret); 4406fcf3ce44SJohn Forte } 4407fcf3ce44SJohn Forte 4408fcf3ce44SJohn Forte 4409fcf3ce44SJohn Forte /* 4410fcf3ce44SJohn Forte * psSetProviderData 4411fcf3ce44SJohn Forte * 4412fcf3ce44SJohn Forte * Stores a packed nvlist on a per provider basis 4413fcf3ce44SJohn Forte * 4414fcf3ce44SJohn Forte * providerName - property group name to use 4415fcf3ce44SJohn Forte * nvl - nvlist to store 4416fcf3ce44SJohn Forte * providerType - type of provider (logical unit or port) 4417fcf3ce44SJohn Forte * 4418fcf3ce44SJohn Forte */ 4419fcf3ce44SJohn Forte int 4420fcf3ce44SJohn Forte psSetProviderData(char *providerName, nvlist_t *nvl, int providerType, 4421fcf3ce44SJohn Forte uint64_t *setToken) 4422fcf3ce44SJohn Forte { 4423fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 4424fcf3ce44SJohn Forte scf_service_t *svc = NULL; 4425fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 4426fcf3ce44SJohn Forte scf_property_t *prop = NULL; 4427fcf3ce44SJohn Forte scf_transaction_t *tran = NULL; 4428fcf3ce44SJohn Forte /* represents arrays of entry and value pointers for scf */ 4429fcf3ce44SJohn Forte scf_transaction_entry_t **addEntry = NULL; 4430fcf3ce44SJohn Forte scf_transaction_entry_t **deleteEntry = NULL; 4431fcf3ce44SJohn Forte scf_value_t **addValue = NULL; 4432fcf3ce44SJohn Forte 4433fcf3ce44SJohn Forte /* 4434fcf3ce44SJohn Forte * These declarations are for known entry and value set/get 4435fcf3ce44SJohn Forte * operations 4436fcf3ce44SJohn Forte */ 4437fcf3ce44SJohn Forte scf_transaction_entry_t *entry1 = NULL; 4438fcf3ce44SJohn Forte scf_transaction_entry_t *entry2 = NULL; 4439fcf3ce44SJohn Forte scf_transaction_entry_t *entry3 = NULL; 4440fcf3ce44SJohn Forte scf_transaction_entry_t *entry5 = NULL; 4441fcf3ce44SJohn Forte scf_value_t *value1 = NULL; 4442fcf3ce44SJohn Forte scf_value_t *value2 = NULL; 4443fcf3ce44SJohn Forte scf_value_t *value3 = NULL; 4444fcf3ce44SJohn Forte scf_value_t *value4 = NULL; 4445fcf3ce44SJohn Forte scf_value_t *value5 = NULL; 4446fcf3ce44SJohn Forte 4447fcf3ce44SJohn Forte boolean_t newPg = B_FALSE; 4448fcf3ce44SJohn Forte char pgName[MAXPATHLEN]; 4449fcf3ce44SJohn Forte char dataPropertyName[STMF_PROVIDER_DATA_PROP_NAME_SIZE]; 4450fcf3ce44SJohn Forte char *nvlistEncoded = NULL; 4451fcf3ce44SJohn Forte size_t nvlistEncodedSize; 4452fcf3ce44SJohn Forte size_t blockSize; 4453fcf3ce44SJohn Forte int i, j = 0; 4454fcf3ce44SJohn Forte int addEntryAlloc = 0, deleteEntryAlloc = 0, addValueAlloc = 0; 4455fcf3ce44SJohn Forte int blockOffset; 4456fcf3ce44SJohn Forte uint64_t oldBlockCnt = 0; 4457fcf3ce44SJohn Forte uint64_t blockCnt = 0; 4458fcf3ce44SJohn Forte uint64_t setCnt = 0; 4459fcf3ce44SJohn Forte boolean_t foundSetCnt = B_TRUE; 4460fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 4461fcf3ce44SJohn Forte int commitRet; 4462fcf3ce44SJohn Forte 4463fcf3ce44SJohn Forte if (providerName == NULL || (providerType != STMF_LU_PROVIDER_TYPE && 4464fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE)) { 4465fcf3ce44SJohn Forte ret = STMF_PS_ERROR_INVALID_ARG; 4466fcf3ce44SJohn Forte goto out; 4467fcf3ce44SJohn Forte } 4468fcf3ce44SJohn Forte 4469fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 4470fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 4471fcf3ce44SJohn Forte goto out; 4472fcf3ce44SJohn Forte } 4473fcf3ce44SJohn Forte 4474fcf3ce44SJohn Forte bzero(pgName, sizeof (pgName)); 4475fcf3ce44SJohn Forte /* 4476fcf3ce44SJohn Forte * create the property group name 4477fcf3ce44SJohn Forte */ 4478fcf3ce44SJohn Forte (void) snprintf(pgName, sizeof (pgName), "%s%s", 4479fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PREFIX, providerName); 4480fcf3ce44SJohn Forte 4481fcf3ce44SJohn Forte /* 4482fcf3ce44SJohn Forte * Allocate scf resources 4483fcf3ce44SJohn Forte */ 4484fcf3ce44SJohn Forte if (((pg = scf_pg_create(handle)) == NULL) || 4485fcf3ce44SJohn Forte ((entry1 = scf_entry_create(handle)) == NULL) || 4486fcf3ce44SJohn Forte ((entry2 = scf_entry_create(handle)) == NULL) || 4487fcf3ce44SJohn Forte ((entry3 = scf_entry_create(handle)) == NULL) || 4488fcf3ce44SJohn Forte ((entry5 = scf_entry_create(handle)) == NULL) || 4489fcf3ce44SJohn Forte ((value1 = scf_value_create(handle)) == NULL) || 4490fcf3ce44SJohn Forte ((value2 = scf_value_create(handle)) == NULL) || 4491fcf3ce44SJohn Forte ((value3 = scf_value_create(handle)) == NULL) || 4492fcf3ce44SJohn Forte ((value4 = scf_value_create(handle)) == NULL) || 4493fcf3ce44SJohn Forte ((value5 = scf_value_create(handle)) == NULL) || 4494fcf3ce44SJohn Forte ((prop = scf_property_create(handle)) == NULL) || 4495fcf3ce44SJohn Forte ((tran = scf_transaction_create(handle)) == NULL)) { 4496fcf3ce44SJohn Forte syslog(LOG_ERR, "scf alloc resource failed - %s", 4497fcf3ce44SJohn Forte scf_strerror(scf_error())); 4498fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4499fcf3ce44SJohn Forte goto out; 4500fcf3ce44SJohn Forte } 4501fcf3ce44SJohn Forte 4502fcf3ce44SJohn Forte /* 4503fcf3ce44SJohn Forte * Get the existing property group 4504fcf3ce44SJohn Forte */ 4505fcf3ce44SJohn Forte if (scf_service_get_pg(svc, pgName, pg) == -1) { 4506fcf3ce44SJohn Forte if (scf_error() != SCF_ERROR_NOT_FOUND) { 450786b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 450886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4509fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4510fcf3ce44SJohn Forte goto out; 4511fcf3ce44SJohn Forte } else { 4512fcf3ce44SJohn Forte /* 4513fcf3ce44SJohn Forte * create the property group. 4514fcf3ce44SJohn Forte */ 4515fcf3ce44SJohn Forte if (scf_service_add_pg(svc, pgName, 4516fcf3ce44SJohn Forte SCF_GROUP_APPLICATION, 0, pg) == -1) { 451786b7dbefSPeter Gill syslog(LOG_ERR, "add pg %s failed - %s", 451886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4519fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4520fcf3ce44SJohn Forte goto out; 4521fcf3ce44SJohn Forte } 4522fcf3ce44SJohn Forte newPg = B_TRUE; 4523fcf3ce44SJohn Forte } 4524fcf3ce44SJohn Forte } 4525fcf3ce44SJohn Forte 4526fcf3ce44SJohn Forte /* 4527fcf3ce44SJohn Forte * Begin the transaction 4528fcf3ce44SJohn Forte */ 4529fcf3ce44SJohn Forte if (scf_transaction_start(tran, pg) == -1) { 453086b7dbefSPeter Gill syslog(LOG_ERR, "start transaction for %s failed - %s", 453186b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4532fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4533fcf3ce44SJohn Forte goto out; 4534fcf3ce44SJohn Forte } 4535fcf3ce44SJohn Forte 4536fcf3ce44SJohn Forte if (!newPg) { 4537fcf3ce44SJohn Forte /* 4538fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_COUNT property 4539fcf3ce44SJohn Forte */ 4540fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_COUNT, 4541fcf3ce44SJohn Forte prop) == -1) { 454286b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 454386b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4544fcf3ce44SJohn Forte scf_strerror(scf_error())); 4545fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4546fcf3ce44SJohn Forte goto out; 4547fcf3ce44SJohn Forte } 4548fcf3ce44SJohn Forte 4549fcf3ce44SJohn Forte /* 4550fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_COUNT value 4551fcf3ce44SJohn Forte */ 4552fcf3ce44SJohn Forte if (scf_property_get_value(prop, value4) == -1) { 455386b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 455486b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4555fcf3ce44SJohn Forte scf_strerror(scf_error())); 4556fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4557fcf3ce44SJohn Forte goto out; 4558fcf3ce44SJohn Forte } 4559fcf3ce44SJohn Forte 4560fcf3ce44SJohn Forte /* 4561fcf3ce44SJohn Forte * Now get the actual value from the value handle 4562fcf3ce44SJohn Forte */ 4563fcf3ce44SJohn Forte if (scf_value_get_count(value4, &oldBlockCnt) == -1) { 456486b7dbefSPeter Gill syslog(LOG_ERR, "get integer value %s/%s failed - %s", 456586b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4566fcf3ce44SJohn Forte scf_strerror(scf_error())); 4567fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4568fcf3ce44SJohn Forte goto out; 4569fcf3ce44SJohn Forte } 4570fcf3ce44SJohn Forte } 4571fcf3ce44SJohn Forte 4572fcf3ce44SJohn Forte /* 4573fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT property 4574fcf3ce44SJohn Forte * If it doesn't exist, we'll create it later after successfully 4575fcf3ce44SJohn Forte * setting the data. 4576fcf3ce44SJohn Forte */ 4577fcf3ce44SJohn Forte if (scf_pg_get_property(pg, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4578fcf3ce44SJohn Forte prop) == -1) { 4579fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 4580fcf3ce44SJohn Forte foundSetCnt = B_FALSE; 4581fcf3ce44SJohn Forte } else { 458286b7dbefSPeter Gill syslog(LOG_ERR, "get property %s/%s failed - %s", 458386b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4584fcf3ce44SJohn Forte scf_strerror(scf_error())); 4585fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4586fcf3ce44SJohn Forte goto out; 4587fcf3ce44SJohn Forte } 4588fcf3ce44SJohn Forte } 4589fcf3ce44SJohn Forte 4590fcf3ce44SJohn Forte if (foundSetCnt) { 4591fcf3ce44SJohn Forte /* 4592fcf3ce44SJohn Forte * Get the STMF_PROVIDER_DATA_PROP_SET_COUNT value 4593fcf3ce44SJohn Forte */ 4594fcf3ce44SJohn Forte if (scf_property_get_value(prop, value5) == -1) { 459586b7dbefSPeter Gill syslog(LOG_ERR, "get property value %s/%s failed - %s", 459686b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4597fcf3ce44SJohn Forte scf_strerror(scf_error())); 4598fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4599fcf3ce44SJohn Forte goto out; 4600fcf3ce44SJohn Forte } 4601fcf3ce44SJohn Forte 4602fcf3ce44SJohn Forte /* 4603fcf3ce44SJohn Forte * Now get the actual value from the value handle 4604fcf3ce44SJohn Forte */ 4605fcf3ce44SJohn Forte if (scf_value_get_count(value5, &setCnt) == -1) { 460686b7dbefSPeter Gill syslog(LOG_ERR, "get integer value %s/%s failed - %s", 460786b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4608fcf3ce44SJohn Forte scf_strerror(scf_error())); 4609fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4610fcf3ce44SJohn Forte goto out; 4611fcf3ce44SJohn Forte } 4612fcf3ce44SJohn Forte 4613fcf3ce44SJohn Forte /* 4614fcf3ce44SJohn Forte * Compare the setCnt prop to the caller's. 4615fcf3ce44SJohn Forte */ 4616fcf3ce44SJohn Forte if (setToken && (*setToken != setCnt)) { 4617fcf3ce44SJohn Forte ret = STMF_PS_ERROR_PROV_DATA_STALE; 4618fcf3ce44SJohn Forte goto out; 4619fcf3ce44SJohn Forte } 4620fcf3ce44SJohn Forte } 4621fcf3ce44SJohn Forte 4622fcf3ce44SJohn Forte setCnt++; 4623fcf3ce44SJohn Forte 4624fcf3ce44SJohn Forte /* 4625fcf3ce44SJohn Forte * prepare the list for writing 4626fcf3ce44SJohn Forte */ 4627fcf3ce44SJohn Forte if (nvlist_pack(nvl, &nvlistEncoded, &nvlistEncodedSize, 4628fcf3ce44SJohn Forte NV_ENCODE_XDR, 0) != 0) { 462986b7dbefSPeter Gill syslog(LOG_ERR, "nvlist_pack for %s failed", 463086b7dbefSPeter Gill pgName); 4631fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4632fcf3ce44SJohn Forte goto out; 4633fcf3ce44SJohn Forte } 4634fcf3ce44SJohn Forte 4635fcf3ce44SJohn Forte /* Determine how many chunks we need to write */ 4636fcf3ce44SJohn Forte blockCnt = nvlistEncodedSize/STMF_PROVIDER_DATA_PROP_SIZE; 4637fcf3ce44SJohn Forte if (nvlistEncodedSize % STMF_PROVIDER_DATA_PROP_SIZE) 4638fcf3ce44SJohn Forte blockCnt++; 4639fcf3ce44SJohn Forte 4640fcf3ce44SJohn Forte /* allocate entry and value resources for writing those chunks */ 4641fcf3ce44SJohn Forte addEntry = (scf_transaction_entry_t **)calloc(1, sizeof (*addEntry) 4642fcf3ce44SJohn Forte * blockCnt); 4643fcf3ce44SJohn Forte if (addEntry == NULL) { 464486b7dbefSPeter Gill syslog(LOG_ERR, "addEntry alloc for %s failed", pgName); 4645fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4646fcf3ce44SJohn Forte goto out; 4647fcf3ce44SJohn Forte } 4648fcf3ce44SJohn Forte 4649fcf3ce44SJohn Forte addValue = (scf_value_t **)calloc(1, sizeof (*addValue) 4650fcf3ce44SJohn Forte * blockCnt); 4651fcf3ce44SJohn Forte if (addValue == NULL) { 465286b7dbefSPeter Gill syslog(LOG_ERR, "value alloc for %s failed", pgName); 4653fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4654fcf3ce44SJohn Forte goto out; 4655fcf3ce44SJohn Forte } 4656fcf3ce44SJohn Forte 4657fcf3ce44SJohn Forte /* 4658fcf3ce44SJohn Forte * allocate entry delete resources for deleting anything existing 4659fcf3ce44SJohn Forte * that is more than the new block count. We could leave them around 4660fcf3ce44SJohn Forte * without suffering any ill effects but it will be cleaner to look at 4661fcf3ce44SJohn Forte * in smf tools if they are deleted. 4662fcf3ce44SJohn Forte */ 4663fcf3ce44SJohn Forte if (oldBlockCnt > blockCnt) { 4664fcf3ce44SJohn Forte deleteEntry = (scf_transaction_entry_t **)calloc(1, 4665fcf3ce44SJohn Forte sizeof (*deleteEntry) * (oldBlockCnt - blockCnt)); 4666fcf3ce44SJohn Forte if (deleteEntry == NULL) { 466786b7dbefSPeter Gill syslog(LOG_ERR, "deleteEntry alloc for %s failed", 466886b7dbefSPeter Gill pgName); 4669fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOMEM; 4670fcf3ce44SJohn Forte goto out; 4671fcf3ce44SJohn Forte } 4672fcf3ce44SJohn Forte deleteEntryAlloc = oldBlockCnt - blockCnt; 4673fcf3ce44SJohn Forte } 4674fcf3ce44SJohn Forte 4675fcf3ce44SJohn Forte 4676fcf3ce44SJohn Forte for (i = 0; i < blockCnt; i++) { 4677fcf3ce44SJohn Forte /* 4678fcf3ce44SJohn Forte * Create the entry resource for the prop 4679fcf3ce44SJohn Forte */ 4680fcf3ce44SJohn Forte addEntry[i] = scf_entry_create(handle); 4681fcf3ce44SJohn Forte if (addEntry[i] == NULL) { 468286b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s failed - %s", 468386b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4684fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4685fcf3ce44SJohn Forte goto out; 4686fcf3ce44SJohn Forte } 4687fcf3ce44SJohn Forte 4688fcf3ce44SJohn Forte /* bump alloc count for addEntry allocation */ 4689fcf3ce44SJohn Forte addEntryAlloc++; 4690fcf3ce44SJohn Forte 4691fcf3ce44SJohn Forte /* 4692fcf3ce44SJohn Forte * create the name to use for the property 4693fcf3ce44SJohn Forte */ 4694fcf3ce44SJohn Forte (void) snprintf(dataPropertyName, sizeof (dataPropertyName), 4695fcf3ce44SJohn Forte "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i); 4696fcf3ce44SJohn Forte 4697fcf3ce44SJohn Forte /* 4698fcf3ce44SJohn Forte * Create the new property 4699fcf3ce44SJohn Forte */ 4700fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, addEntry[i], 4701fcf3ce44SJohn Forte dataPropertyName, SCF_TYPE_OPAQUE) == -1) { 4702fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 4703fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, 4704fcf3ce44SJohn Forte addEntry[i], dataPropertyName, 4705fcf3ce44SJohn Forte SCF_TYPE_OPAQUE) == -1) { 4706fcf3ce44SJohn Forte syslog(LOG_ERR, "transaction property " 470786b7dbefSPeter Gill "change %s/%s failed - %s", 470886b7dbefSPeter Gill pgName, dataPropertyName, 4709fcf3ce44SJohn Forte scf_strerror(scf_error())); 4710fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4711fcf3ce44SJohn Forte goto out; 4712fcf3ce44SJohn Forte } 4713fcf3ce44SJohn Forte } else { 4714fcf3ce44SJohn Forte syslog(LOG_ERR, 471586b7dbefSPeter Gill "transaction property new %s/%s " 471686b7dbefSPeter Gill "failed - %s", pgName, dataPropertyName, 4717fcf3ce44SJohn Forte scf_strerror(scf_error())); 4718fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4719fcf3ce44SJohn Forte goto out; 4720fcf3ce44SJohn Forte } 4721fcf3ce44SJohn Forte } 4722fcf3ce44SJohn Forte /* 4723fcf3ce44SJohn Forte * Create the value resource for the prop 4724fcf3ce44SJohn Forte */ 4725fcf3ce44SJohn Forte addValue[i] = scf_value_create(handle); 4726fcf3ce44SJohn Forte if (addValue[i] == NULL) { 472786b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s failed - %s", 472886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4729fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4730fcf3ce44SJohn Forte goto out; 4731fcf3ce44SJohn Forte } 4732fcf3ce44SJohn Forte 4733fcf3ce44SJohn Forte /* bump alloc count for addValue allocation */ 4734fcf3ce44SJohn Forte addValueAlloc++; 4735fcf3ce44SJohn Forte 4736fcf3ce44SJohn Forte /* 4737fcf3ce44SJohn Forte * Set the data block offset and size 4738fcf3ce44SJohn Forte */ 4739fcf3ce44SJohn Forte if ((STMF_PROVIDER_DATA_PROP_SIZE * (i + 1)) 4740fcf3ce44SJohn Forte > nvlistEncodedSize) { 4741fcf3ce44SJohn Forte blockSize = nvlistEncodedSize 4742fcf3ce44SJohn Forte - STMF_PROVIDER_DATA_PROP_SIZE * i; 4743fcf3ce44SJohn Forte } else { 4744fcf3ce44SJohn Forte blockSize = STMF_PROVIDER_DATA_PROP_SIZE; 4745fcf3ce44SJohn Forte } 4746fcf3ce44SJohn Forte 4747fcf3ce44SJohn Forte blockOffset = STMF_PROVIDER_DATA_PROP_SIZE * i; 4748fcf3ce44SJohn Forte if (scf_value_set_opaque(addValue[i], 4749fcf3ce44SJohn Forte &nvlistEncoded[blockOffset], blockSize) == -1) { 475086b7dbefSPeter Gill syslog(LOG_ERR, "set value for %s failed - %s", 475186b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4752fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4753fcf3ce44SJohn Forte goto out; 4754fcf3ce44SJohn Forte } 4755fcf3ce44SJohn Forte 4756fcf3ce44SJohn Forte /* 4757fcf3ce44SJohn Forte * Add the data block to the transaction entry 4758fcf3ce44SJohn Forte */ 4759fcf3ce44SJohn Forte if (scf_entry_add_value(addEntry[i], addValue[i]) == -1) { 476086b7dbefSPeter Gill syslog(LOG_ERR, "add value for %s failed - %s", 476186b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4762fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4763fcf3ce44SJohn Forte goto out; 4764fcf3ce44SJohn Forte } 4765fcf3ce44SJohn Forte } 4766fcf3ce44SJohn Forte 4767fcf3ce44SJohn Forte /* 4768fcf3ce44SJohn Forte * Now we need to delete any chunks (properties) that are no longer 4769fcf3ce44SJohn Forte * needed. Iterate through the rest of the chunks deleting each. 4770fcf3ce44SJohn Forte */ 4771fcf3ce44SJohn Forte for (i = blockCnt; i < oldBlockCnt; i++) { 4772fcf3ce44SJohn Forte /* 4773fcf3ce44SJohn Forte * Create the entry resource for the prop 4774fcf3ce44SJohn Forte */ 4775fcf3ce44SJohn Forte deleteEntry[j] = scf_entry_create(handle); 4776fcf3ce44SJohn Forte if (deleteEntry[j] == NULL) { 477786b7dbefSPeter Gill syslog(LOG_ERR, "scf value alloc for %s failed - %s", 477886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4779fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4780fcf3ce44SJohn Forte goto out; 4781fcf3ce44SJohn Forte } 4782fcf3ce44SJohn Forte 4783fcf3ce44SJohn Forte /* 4784fcf3ce44SJohn Forte * create the name to use for the property 4785fcf3ce44SJohn Forte */ 4786fcf3ce44SJohn Forte (void) snprintf(dataPropertyName, sizeof (dataPropertyName), 4787fcf3ce44SJohn Forte "%s-%d", STMF_PROVIDER_DATA_PROP_PREFIX, i); 4788fcf3ce44SJohn Forte 4789fcf3ce44SJohn Forte /* 4790fcf3ce44SJohn Forte * Delete the existing property 4791fcf3ce44SJohn Forte */ 4792fcf3ce44SJohn Forte if (scf_transaction_property_delete(tran, deleteEntry[j++], 4793fcf3ce44SJohn Forte dataPropertyName) == -1) { 479486b7dbefSPeter Gill syslog(LOG_ERR, "delete property %s/%s failed - %s", 479586b7dbefSPeter Gill pgName, dataPropertyName, 4796fcf3ce44SJohn Forte scf_strerror(scf_error())); 4797fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4798fcf3ce44SJohn Forte goto out; 4799fcf3ce44SJohn Forte } 4800fcf3ce44SJohn Forte } 4801fcf3ce44SJohn Forte 4802fcf3ce44SJohn Forte if (newPg) { 4803fcf3ce44SJohn Forte /* 4804fcf3ce44SJohn Forte * Ensure the read_authorization property is set 4805fcf3ce44SJohn Forte * for the group 4806fcf3ce44SJohn Forte */ 4807fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry1, 4808fcf3ce44SJohn Forte "read_authorization", SCF_TYPE_ASTRING) == -1) { 480986b7dbefSPeter Gill syslog(LOG_ERR, "transaction property %s/%s new " 481086b7dbefSPeter Gill "failed - %s", pgName, "read_authorization", 4811fcf3ce44SJohn Forte scf_strerror(scf_error())); 4812fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4813fcf3ce44SJohn Forte goto out; 4814fcf3ce44SJohn Forte } 4815fcf3ce44SJohn Forte 4816fcf3ce44SJohn Forte if (scf_value_set_astring(value1, STMF_SMF_READ_ATTR) == -1) { 481786b7dbefSPeter Gill syslog(LOG_ERR, "set value %s/%s failed - %s", 481886b7dbefSPeter Gill pgName, "read_authorization", 4819fcf3ce44SJohn Forte scf_strerror(scf_error())); 4820fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4821fcf3ce44SJohn Forte goto out; 4822fcf3ce44SJohn Forte } 4823fcf3ce44SJohn Forte 4824fcf3ce44SJohn Forte if (scf_entry_add_value(entry1, value1) == -1) { 482586b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 482686b7dbefSPeter Gill pgName, "read_authorization", 4827fcf3ce44SJohn Forte scf_strerror(scf_error())); 4828fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4829fcf3ce44SJohn Forte goto out; 4830fcf3ce44SJohn Forte } 4831fcf3ce44SJohn Forte } 4832fcf3ce44SJohn Forte 4833fcf3ce44SJohn Forte /* create or change the count property */ 4834fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry2, 4835fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_COUNT, SCF_TYPE_COUNT) == -1) { 4836fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 4837fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, entry2, 4838fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_COUNT, 4839fcf3ce44SJohn Forte SCF_TYPE_COUNT) == -1) { 484086b7dbefSPeter Gill syslog(LOG_ERR, "transaction property change " 484186b7dbefSPeter Gill "%s/%s failed - %s", pgName, 484286b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_COUNT, 4843fcf3ce44SJohn Forte scf_strerror(scf_error())); 4844fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4845fcf3ce44SJohn Forte goto out; 4846fcf3ce44SJohn Forte } 4847fcf3ce44SJohn Forte } else { 484886b7dbefSPeter Gill syslog(LOG_ERR, "transaction property %s/%s new " 484986b7dbefSPeter Gill "failed - %s", pgName, 485086b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_COUNT, 4851fcf3ce44SJohn Forte scf_strerror(scf_error())); 4852fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4853fcf3ce44SJohn Forte goto out; 4854fcf3ce44SJohn Forte } 4855fcf3ce44SJohn Forte } 4856fcf3ce44SJohn Forte 4857fcf3ce44SJohn Forte scf_value_set_count(value2, blockCnt); 4858fcf3ce44SJohn Forte 4859fcf3ce44SJohn Forte if (scf_entry_add_value(entry2, value2) == -1) { 486086b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 486186b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_COUNT, 4862fcf3ce44SJohn Forte scf_strerror(scf_error())); 4863fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4864fcf3ce44SJohn Forte goto out; 4865fcf3ce44SJohn Forte } 4866fcf3ce44SJohn Forte 4867fcf3ce44SJohn Forte /* create or change the set count property */ 4868fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry5, 4869fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_SET_COUNT, SCF_TYPE_COUNT) == -1) { 4870fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 4871fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, entry5, 4872fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_SET_COUNT, 4873fcf3ce44SJohn Forte SCF_TYPE_COUNT) == -1) { 4874fcf3ce44SJohn Forte syslog(LOG_ERR, 487586b7dbefSPeter Gill "transaction property change %s/%s " 487686b7dbefSPeter Gill "failed - %s", pgName, 487786b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_SET_COUNT, 4878fcf3ce44SJohn Forte scf_strerror(scf_error())); 4879fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4880fcf3ce44SJohn Forte goto out; 4881fcf3ce44SJohn Forte } 4882fcf3ce44SJohn Forte } else { 488386b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 488486b7dbefSPeter Gill "failed - %s", pgName, 488586b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_SET_COUNT, 4886fcf3ce44SJohn Forte scf_strerror(scf_error())); 4887fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4888fcf3ce44SJohn Forte goto out; 4889fcf3ce44SJohn Forte } 4890fcf3ce44SJohn Forte } 4891fcf3ce44SJohn Forte 4892fcf3ce44SJohn Forte 4893fcf3ce44SJohn Forte 4894fcf3ce44SJohn Forte scf_value_set_count(value5, setCnt); 4895fcf3ce44SJohn Forte 4896fcf3ce44SJohn Forte if (scf_entry_add_value(entry5, value5) == -1) { 489786b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", 489886b7dbefSPeter Gill pgName, STMF_PROVIDER_DATA_PROP_SET_COUNT, 4899fcf3ce44SJohn Forte scf_strerror(scf_error())); 4900fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4901fcf3ce44SJohn Forte goto out; 4902fcf3ce44SJohn Forte } 4903fcf3ce44SJohn Forte 4904fcf3ce44SJohn Forte /* create or change the provider type property */ 4905fcf3ce44SJohn Forte if (scf_transaction_property_new(tran, entry3, 4906fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_TYPE, SCF_TYPE_INTEGER) == -1) { 4907fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_EXISTS) { 4908fcf3ce44SJohn Forte if (scf_transaction_property_change(tran, entry3, 4909fcf3ce44SJohn Forte STMF_PROVIDER_DATA_PROP_TYPE, 4910fcf3ce44SJohn Forte SCF_TYPE_INTEGER) == -1) { 4911fcf3ce44SJohn Forte syslog(LOG_ERR, 491286b7dbefSPeter Gill "transaction property change %s/%s " 491386b7dbefSPeter Gill "failed - %s", pgName, 491486b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_TYPE, 4915fcf3ce44SJohn Forte scf_strerror(scf_error())); 4916fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4917fcf3ce44SJohn Forte goto out; 4918fcf3ce44SJohn Forte } 4919fcf3ce44SJohn Forte } else { 492086b7dbefSPeter Gill syslog(LOG_ERR, "transaction property new %s/%s " 492186b7dbefSPeter Gill "failed - %s", pgName, STMF_PROVIDER_DATA_PROP_TYPE, 4922fcf3ce44SJohn Forte scf_strerror(scf_error())); 4923fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4924fcf3ce44SJohn Forte goto out; 4925fcf3ce44SJohn Forte } 4926fcf3ce44SJohn Forte } 4927fcf3ce44SJohn Forte 4928fcf3ce44SJohn Forte switch (providerType) { 4929fcf3ce44SJohn Forte case STMF_PORT_PROVIDER_TYPE: 4930fcf3ce44SJohn Forte case STMF_LU_PROVIDER_TYPE: 4931fcf3ce44SJohn Forte scf_value_set_integer(value3, providerType); 4932fcf3ce44SJohn Forte break; 4933fcf3ce44SJohn Forte default: 4934fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4935fcf3ce44SJohn Forte goto out; 4936fcf3ce44SJohn Forte } 4937fcf3ce44SJohn Forte 4938fcf3ce44SJohn Forte if (scf_entry_add_value(entry3, value3) == -1) { 493986b7dbefSPeter Gill syslog(LOG_ERR, "add value %s/%s failed - %s", pgName, 494086b7dbefSPeter Gill STMF_PROVIDER_DATA_PROP_TYPE, scf_strerror(scf_error())); 4941fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4942fcf3ce44SJohn Forte goto out; 4943fcf3ce44SJohn Forte } 4944fcf3ce44SJohn Forte 4945fcf3ce44SJohn Forte 4946fcf3ce44SJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) { 494786b7dbefSPeter Gill syslog(LOG_ERR, "transaction commit for %s failed - %s", 494886b7dbefSPeter Gill pgName, scf_strerror(scf_error())); 4949fcf3ce44SJohn Forte if (commitRet == 0) { 4950fcf3ce44SJohn Forte ret = STMF_PS_ERROR_BUSY; 4951fcf3ce44SJohn Forte } else { 4952fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 4953fcf3ce44SJohn Forte } 4954fcf3ce44SJohn Forte goto out; 4955fcf3ce44SJohn Forte } 4956fcf3ce44SJohn Forte 4957fcf3ce44SJohn Forte /* pass the new token back to the caller if requested */ 4958fcf3ce44SJohn Forte if (ret == STMF_PS_SUCCESS && setToken) { 4959fcf3ce44SJohn Forte *setToken = setCnt; 4960fcf3ce44SJohn Forte } 4961fcf3ce44SJohn Forte 4962fcf3ce44SJohn Forte out: 4963fcf3ce44SJohn Forte /* 4964fcf3ce44SJohn Forte * Free resources 4965fcf3ce44SJohn Forte */ 4966fcf3ce44SJohn Forte if (handle != NULL) { 4967fcf3ce44SJohn Forte scf_handle_destroy(handle); 4968fcf3ce44SJohn Forte } 4969fcf3ce44SJohn Forte if (svc != NULL) { 4970fcf3ce44SJohn Forte scf_service_destroy(svc); 4971fcf3ce44SJohn Forte } 4972fcf3ce44SJohn Forte if (pg != NULL) { 4973fcf3ce44SJohn Forte scf_pg_destroy(pg); 4974fcf3ce44SJohn Forte } 4975fcf3ce44SJohn Forte if (prop != NULL) { 4976fcf3ce44SJohn Forte scf_property_destroy(prop); 4977fcf3ce44SJohn Forte } 4978fcf3ce44SJohn Forte if (tran != NULL) { 4979fcf3ce44SJohn Forte scf_transaction_destroy(tran); 4980fcf3ce44SJohn Forte } 4981fcf3ce44SJohn Forte for (i = 0; i < addEntryAlloc; i++) { 4982fcf3ce44SJohn Forte scf_entry_destroy(addEntry[i]); 4983fcf3ce44SJohn Forte } 4984fcf3ce44SJohn Forte for (i = 0; i < addValueAlloc; i++) { 4985fcf3ce44SJohn Forte scf_value_destroy(addValue[i]); 4986fcf3ce44SJohn Forte } 4987fcf3ce44SJohn Forte free(addValue); 4988fcf3ce44SJohn Forte free(addEntry); 4989fcf3ce44SJohn Forte for (i = 0; i < deleteEntryAlloc; i++) { 4990fcf3ce44SJohn Forte scf_entry_destroy(deleteEntry[i]); 4991fcf3ce44SJohn Forte } 4992fcf3ce44SJohn Forte free(deleteEntry); 4993fcf3ce44SJohn Forte if (entry1 != NULL) { 4994fcf3ce44SJohn Forte scf_entry_destroy(entry1); 4995fcf3ce44SJohn Forte } 4996fcf3ce44SJohn Forte if (entry2 != NULL) { 4997fcf3ce44SJohn Forte scf_entry_destroy(entry2); 4998fcf3ce44SJohn Forte } 4999fcf3ce44SJohn Forte if (entry3 != NULL) { 5000fcf3ce44SJohn Forte scf_entry_destroy(entry3); 5001fcf3ce44SJohn Forte } 5002fcf3ce44SJohn Forte if (entry5 != NULL) { 5003fcf3ce44SJohn Forte scf_entry_destroy(entry5); 5004fcf3ce44SJohn Forte } 5005fcf3ce44SJohn Forte if (value1 != NULL) { 5006fcf3ce44SJohn Forte scf_value_destroy(value1); 5007fcf3ce44SJohn Forte } 5008fcf3ce44SJohn Forte if (value2 != NULL) { 5009fcf3ce44SJohn Forte scf_value_destroy(value2); 5010fcf3ce44SJohn Forte } 5011fcf3ce44SJohn Forte if (value3 != NULL) { 5012fcf3ce44SJohn Forte scf_value_destroy(value3); 5013fcf3ce44SJohn Forte } 5014fcf3ce44SJohn Forte if (value4 != NULL) { 5015fcf3ce44SJohn Forte scf_value_destroy(value4); 5016fcf3ce44SJohn Forte } 5017fcf3ce44SJohn Forte if (value5 != NULL) { 5018fcf3ce44SJohn Forte scf_value_destroy(value5); 5019fcf3ce44SJohn Forte } 5020fcf3ce44SJohn Forte if (nvlistEncoded != NULL) { 5021fcf3ce44SJohn Forte free(nvlistEncoded); 5022fcf3ce44SJohn Forte } 5023fcf3ce44SJohn Forte 5024fcf3ce44SJohn Forte return (ret); 5025fcf3ce44SJohn Forte } 5026fcf3ce44SJohn Forte 5027fcf3ce44SJohn Forte /* 5028fcf3ce44SJohn Forte * psGetViewEntry 5029fcf3ce44SJohn Forte * 5030fcf3ce44SJohn Forte * Purpose: Get a single view entry based on the logical unit identifier and 5031fcf3ce44SJohn Forte * view entry index 5032fcf3ce44SJohn Forte * 5033fcf3ce44SJohn Forte * lu - logical unit identifier 5034fcf3ce44SJohn Forte * viewEntryIndex - index of view entry 5035fcf3ce44SJohn Forte * ve - caller allocated stmfViewEntry structure. On success, this will 5036fcf3ce44SJohn Forte * contain the retrieved view entry 5037fcf3ce44SJohn Forte */ 5038fcf3ce44SJohn Forte int 5039fcf3ce44SJohn Forte psGetViewEntry(stmfGuid *lu, uint32_t viewEntryIndex, stmfViewEntry *ve) 5040fcf3ce44SJohn Forte { 5041fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 5042fcf3ce44SJohn Forte scf_service_t *svc = NULL; 5043fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 5044fcf3ce44SJohn Forte char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */ 5045fcf3ce44SJohn Forte char viewEntryPgName[VIEW_ENTRY_PG_SIZE]; 5046fcf3ce44SJohn Forte char luPgName[LOGICAL_UNIT_PG_SIZE]; 5047fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 5048fcf3ce44SJohn Forte 5049fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 5050fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 5051fcf3ce44SJohn Forte goto out; 5052fcf3ce44SJohn Forte } 5053fcf3ce44SJohn Forte 5054fcf3ce44SJohn Forte pg = scf_pg_create(handle); 5055fcf3ce44SJohn Forte if (pg == NULL) { 5056fcf3ce44SJohn Forte syslog(LOG_ERR, "scf pg alloc failed - %s", 5057fcf3ce44SJohn Forte scf_strerror(scf_error())); 5058fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5059fcf3ce44SJohn Forte goto out; 5060fcf3ce44SJohn Forte } 5061fcf3ce44SJohn Forte 5062fcf3ce44SJohn Forte /* Convert to ASCII uppercase hexadecimal string */ 5063fcf3ce44SJohn Forte (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 5064fcf3ce44SJohn Forte "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 5065fcf3ce44SJohn Forte lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4], 5066fcf3ce44SJohn Forte lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9], 5067fcf3ce44SJohn Forte lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13], 5068fcf3ce44SJohn Forte lu->guid[14], lu->guid[15]); 5069fcf3ce44SJohn Forte 5070fcf3ce44SJohn Forte (void) snprintf(luPgName, sizeof (luPgName), "%s-%s", 5071fcf3ce44SJohn Forte STMF_LU_PREFIX, guidAsciiBuf); 5072fcf3ce44SJohn Forte 5073fcf3ce44SJohn Forte /* 5074fcf3ce44SJohn Forte * Format of view entry property group name: 5075fcf3ce44SJohn Forte * VE-<view_entry_index>-<lu_name> 5076fcf3ce44SJohn Forte */ 5077fcf3ce44SJohn Forte (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName), 5078fcf3ce44SJohn Forte "%s-%d-%s", STMF_VE_PREFIX, viewEntryIndex, guidAsciiBuf); 5079fcf3ce44SJohn Forte 5080fcf3ce44SJohn Forte if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) { 5081fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 5082fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 5083fcf3ce44SJohn Forte } else { 508486b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 508586b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 5086fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5087fcf3ce44SJohn Forte } 5088fcf3ce44SJohn Forte goto out; 5089fcf3ce44SJohn Forte } 5090fcf3ce44SJohn Forte 5091fcf3ce44SJohn Forte 5092fcf3ce44SJohn Forte if ((ret = iPsGetViewEntry(viewEntryPgName, ve)) != STMF_PS_SUCCESS) { 5093fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5094fcf3ce44SJohn Forte goto out; 5095fcf3ce44SJohn Forte } 5096fcf3ce44SJohn Forte 5097fcf3ce44SJohn Forte out: 5098fcf3ce44SJohn Forte /* 5099fcf3ce44SJohn Forte * Free resources 5100fcf3ce44SJohn Forte */ 5101fcf3ce44SJohn Forte if (handle != NULL) { 5102fcf3ce44SJohn Forte scf_handle_destroy(handle); 5103fcf3ce44SJohn Forte } 5104fcf3ce44SJohn Forte if (svc != NULL) { 5105fcf3ce44SJohn Forte scf_service_destroy(svc); 5106fcf3ce44SJohn Forte } 5107fcf3ce44SJohn Forte if (pg != NULL) { 5108fcf3ce44SJohn Forte scf_pg_destroy(pg); 5109fcf3ce44SJohn Forte } 5110fcf3ce44SJohn Forte 5111fcf3ce44SJohn Forte return (ret); 5112fcf3ce44SJohn Forte } 5113fcf3ce44SJohn Forte 5114fcf3ce44SJohn Forte /* 5115fcf3ce44SJohn Forte * psRemoveViewEntry 5116fcf3ce44SJohn Forte * 5117fcf3ce44SJohn Forte * Remove a view entry 5118fcf3ce44SJohn Forte * 5119fcf3ce44SJohn Forte * luGuid - identifier of logical unit from which to remove view entry 5120fcf3ce44SJohn Forte * viewEntryIndex - view entry name to remove 5121fcf3ce44SJohn Forte * 5122fcf3ce44SJohn Forte * returns: 5123fcf3ce44SJohn Forte * STMF_PS_SUCCESS on success 5124fcf3ce44SJohn Forte * STMF_PS_ERROR_* on failure 5125fcf3ce44SJohn Forte */ 5126fcf3ce44SJohn Forte int 5127fcf3ce44SJohn Forte psRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex) 5128fcf3ce44SJohn Forte { 5129fcf3ce44SJohn Forte scf_handle_t *handle = NULL; 5130fcf3ce44SJohn Forte scf_service_t *svc = NULL; 5131fcf3ce44SJohn Forte scf_propertygroup_t *pg = NULL; 5132fcf3ce44SJohn Forte char guidAsciiBuf[33]; /* size of ascii hex 16 byte guid with NULL */ 5133fcf3ce44SJohn Forte char viewEntryPgName[VIEW_ENTRY_PG_SIZE]; 5134fcf3ce44SJohn Forte char luPgName[LOGICAL_UNIT_PG_SIZE]; 5135fcf3ce44SJohn Forte int ret = STMF_PS_SUCCESS; 5136fcf3ce44SJohn Forte sigset_t sigmaskRestore; 5137fcf3ce44SJohn Forte 5138fcf3ce44SJohn Forte /* grab the signal hold lock */ 5139fcf3ce44SJohn Forte (void) pthread_mutex_lock(&sigSetLock); 5140fcf3ce44SJohn Forte 5141fcf3ce44SJohn Forte /* 5142fcf3ce44SJohn Forte * hold signals until we're done 5143fcf3ce44SJohn Forte */ 5144fcf3ce44SJohn Forte if (holdSignal(&sigmaskRestore) != 0) { 5145fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&sigSetLock); 5146fcf3ce44SJohn Forte return (STMF_PS_ERROR); 5147fcf3ce44SJohn Forte } 5148fcf3ce44SJohn Forte 5149fcf3ce44SJohn Forte ret = iPsInit(&handle, &svc); 5150fcf3ce44SJohn Forte if (ret != STMF_PS_SUCCESS) { 5151fcf3ce44SJohn Forte goto out; 5152fcf3ce44SJohn Forte } 5153fcf3ce44SJohn Forte 5154fcf3ce44SJohn Forte pg = scf_pg_create(handle); 5155fcf3ce44SJohn Forte if (pg == NULL) { 5156fcf3ce44SJohn Forte syslog(LOG_ERR, "scf pg alloc failed - %s", 5157fcf3ce44SJohn Forte scf_strerror(scf_error())); 5158fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5159fcf3ce44SJohn Forte goto out; 5160fcf3ce44SJohn Forte } 5161fcf3ce44SJohn Forte 5162fcf3ce44SJohn Forte /* Convert to ASCII uppercase hexadecimal string */ 5163fcf3ce44SJohn Forte (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 5164fcf3ce44SJohn Forte "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 5165fcf3ce44SJohn Forte lu->guid[0], lu->guid[1], lu->guid[2], lu->guid[3], lu->guid[4], 5166fcf3ce44SJohn Forte lu->guid[5], lu->guid[6], lu->guid[7], lu->guid[8], lu->guid[9], 5167fcf3ce44SJohn Forte lu->guid[10], lu->guid[11], lu->guid[12], lu->guid[13], 5168fcf3ce44SJohn Forte lu->guid[14], lu->guid[15]); 5169fcf3ce44SJohn Forte 5170fcf3ce44SJohn Forte (void) snprintf(luPgName, sizeof (luPgName), "%s-%s", 5171fcf3ce44SJohn Forte STMF_LU_PREFIX, guidAsciiBuf); 5172fcf3ce44SJohn Forte 5173fcf3ce44SJohn Forte /* 5174fcf3ce44SJohn Forte * Format of view entry property group name: 5175fcf3ce44SJohn Forte * VE-<view_entry_index>-<lu_name> 5176fcf3ce44SJohn Forte */ 5177fcf3ce44SJohn Forte (void) snprintf(viewEntryPgName, sizeof (viewEntryPgName), 5178fcf3ce44SJohn Forte "%s-%d-%s", STMF_VE_PREFIX, viewEntryIndex, guidAsciiBuf); 5179fcf3ce44SJohn Forte 5180fcf3ce44SJohn Forte if (scf_service_get_pg(svc, viewEntryPgName, pg) == -1) { 5181fcf3ce44SJohn Forte if (scf_error() == SCF_ERROR_NOT_FOUND) { 5182fcf3ce44SJohn Forte ret = STMF_PS_ERROR_NOT_FOUND; 5183fcf3ce44SJohn Forte } else { 518486b7dbefSPeter Gill syslog(LOG_ERR, "get pg %s failed - %s", 518586b7dbefSPeter Gill viewEntryPgName, scf_strerror(scf_error())); 5186fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5187fcf3ce44SJohn Forte } 5188fcf3ce44SJohn Forte goto out; 5189fcf3ce44SJohn Forte } 5190fcf3ce44SJohn Forte 5191fcf3ce44SJohn Forte /* 5192fcf3ce44SJohn Forte * update the logical unit property group to remove 5193fcf3ce44SJohn Forte * the view entry and update the view entry count 5194fcf3ce44SJohn Forte * If it fails, we won't delete the property group so that 5195fcf3ce44SJohn Forte * we maintain consistency. 5196fcf3ce44SJohn Forte */ 5197fcf3ce44SJohn Forte if ((ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName, 5198fcf3ce44SJohn Forte REMOVE)) != STMF_PS_SUCCESS) { 5199fcf3ce44SJohn Forte goto out; 5200fcf3ce44SJohn Forte } 5201fcf3ce44SJohn Forte 5202fcf3ce44SJohn Forte /* 5203fcf3ce44SJohn Forte * Delete the view entry. If this fails, we should try to add 5204fcf3ce44SJohn Forte * the logical unit view entry property group back otherwise 5205fcf3ce44SJohn Forte * we're inconsistent. 5206fcf3ce44SJohn Forte */ 5207fcf3ce44SJohn Forte if (scf_pg_delete(pg) == -1) { 520886b7dbefSPeter Gill syslog(LOG_ERR, "delete pg %s failed - %s", viewEntryPgName, 5209fcf3ce44SJohn Forte scf_strerror(scf_error())); 5210fcf3ce44SJohn Forte if ((ret = iPsAddRemoveLuViewEntry(luPgName, viewEntryPgName, 5211fcf3ce44SJohn Forte ADD)) != STMF_PS_SUCCESS) { 521286b7dbefSPeter Gill syslog(LOG_ERR, "add of view entry %s failed, possible" 521386b7dbefSPeter Gill "inconsistency - %s", viewEntryPgName, 521486b7dbefSPeter Gill scf_strerror(scf_error())); 5215fcf3ce44SJohn Forte } 5216fcf3ce44SJohn Forte ret = STMF_PS_ERROR; 5217fcf3ce44SJohn Forte goto out; 5218fcf3ce44SJohn Forte } 5219fcf3ce44SJohn Forte 5220fcf3ce44SJohn Forte out: 5221fcf3ce44SJohn Forte /* 5222fcf3ce44SJohn Forte * Okay, we're done. Release the signals 5223fcf3ce44SJohn Forte */ 5224fcf3ce44SJohn Forte if (releaseSignal(&sigmaskRestore) != 0) { 5225fcf3ce44SJohn Forte /* 5226fcf3ce44SJohn Forte * Don't set this as an STMF_PS_ERROR_*. We succeeded 5227fcf3ce44SJohn Forte * the requested operation. But we do need to log it. 5228fcf3ce44SJohn Forte */ 5229fcf3ce44SJohn Forte syslog(LOG_ERR, "Unable to release one or more signals - %s", 5230fcf3ce44SJohn Forte strerror(errno)); 5231fcf3ce44SJohn Forte } 5232fcf3ce44SJohn Forte 5233fcf3ce44SJohn Forte /* 5234fcf3ce44SJohn Forte * Free resources 5235fcf3ce44SJohn Forte */ 5236fcf3ce44SJohn Forte if (handle != NULL) { 5237fcf3ce44SJohn Forte scf_handle_destroy(handle); 5238fcf3ce44SJohn Forte } 5239fcf3ce44SJohn Forte if (svc != NULL) { 5240fcf3ce44SJohn Forte scf_service_destroy(svc); 5241fcf3ce44SJohn Forte } 5242fcf3ce44SJohn Forte if (pg != NULL) { 5243fcf3ce44SJohn Forte scf_pg_destroy(pg); 5244fcf3ce44SJohn Forte } 5245fcf3ce44SJohn Forte 5246fcf3ce44SJohn Forte /* release the signal hold lock */ 5247fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&sigSetLock); 5248fcf3ce44SJohn Forte 5249fcf3ce44SJohn Forte return (ret); 5250fcf3ce44SJohn Forte } 5251fcf3ce44SJohn Forte 5252fcf3ce44SJohn Forte 5253fcf3ce44SJohn Forte 5254fcf3ce44SJohn Forte /* 5255fcf3ce44SJohn Forte * holdSignal 5256fcf3ce44SJohn Forte * 5257fcf3ce44SJohn Forte * Hold SIGINT, SIGTERM, SIGQUIT until further notice. 5258fcf3ce44SJohn Forte * 5259fcf3ce44SJohn Forte * Saves old signal mask on a per thread basis 5260fcf3ce44SJohn Forte * and saves action for the process. 5261fcf3ce44SJohn Forte * 5262fcf3ce44SJohn Forte * Installs action for above signals. 5263fcf3ce44SJohn Forte * 5264fcf3ce44SJohn Forte * locks held: sigSetLock 5265fcf3ce44SJohn Forte * 5266fcf3ce44SJohn Forte * returns: 5267fcf3ce44SJohn Forte * 0 on success 5268fcf3ce44SJohn Forte * non-zero otherwise 5269fcf3ce44SJohn Forte */ 5270fcf3ce44SJohn Forte static int 5271fcf3ce44SJohn Forte holdSignal(sigset_t *sigmaskRestore) 5272fcf3ce44SJohn Forte { 5273fcf3ce44SJohn Forte struct sigaction act; 5274fcf3ce44SJohn Forte sigset_t sigmask; 5275fcf3ce44SJohn Forte 5276fcf3ce44SJohn Forte /* 5277fcf3ce44SJohn Forte * Return existing signal mask for this thread 5278fcf3ce44SJohn Forte */ 5279fcf3ce44SJohn Forte if (pthread_sigmask(0, NULL, sigmaskRestore) != 0) { 5280fcf3ce44SJohn Forte return (1); 5281fcf3ce44SJohn Forte } 5282fcf3ce44SJohn Forte 5283fcf3ce44SJohn Forte (void) sigemptyset(&act.sa_mask); 5284fcf3ce44SJohn Forte act.sa_handler = sigHandler; 5285fcf3ce44SJohn Forte act.sa_flags = 0; 5286fcf3ce44SJohn Forte 5287fcf3ce44SJohn Forte /* 5288fcf3ce44SJohn Forte * Have we set the actions for the signals we want to catch? 5289fcf3ce44SJohn Forte */ 5290fcf3ce44SJohn Forte if (!actionSet) { 5291fcf3ce44SJohn Forte if (sigaction(SIGQUIT, &act, ¤tActionQuit) != 0) { 5292fcf3ce44SJohn Forte return (1); 5293fcf3ce44SJohn Forte } 5294fcf3ce44SJohn Forte 5295fcf3ce44SJohn Forte if (sigaction(SIGINT, &act, ¤tActionInt) != 0) { 5296fcf3ce44SJohn Forte return (1); 5297fcf3ce44SJohn Forte } 5298fcf3ce44SJohn Forte 5299fcf3ce44SJohn Forte if (sigaction(SIGTERM, &act, ¤tActionTerm) != 0) { 5300fcf3ce44SJohn Forte return (1); 5301fcf3ce44SJohn Forte } 5302fcf3ce44SJohn Forte 5303fcf3ce44SJohn Forte actionSet = B_TRUE; 5304fcf3ce44SJohn Forte } 5305fcf3ce44SJohn Forte 5306fcf3ce44SJohn Forte /* 5307fcf3ce44SJohn Forte * We still need to change the mask for the current thread 5308fcf3ce44SJohn Forte */ 5309fcf3ce44SJohn Forte if (sigfillset(&sigmask) != 0) { 5310fcf3ce44SJohn Forte return (1); 5311fcf3ce44SJohn Forte } 5312fcf3ce44SJohn Forte 5313fcf3ce44SJohn Forte (void) sigdelset(&sigmask, SIGQUIT); 5314fcf3ce44SJohn Forte 5315fcf3ce44SJohn Forte (void) sigdelset(&sigmask, SIGINT); 5316fcf3ce44SJohn Forte 5317fcf3ce44SJohn Forte (void) sigdelset(&sigmask, SIGTERM); 5318fcf3ce44SJohn Forte 5319fcf3ce44SJohn Forte if (pthread_sigmask(SIG_SETMASK, &sigmask, NULL) != 0) { 5320fcf3ce44SJohn Forte return (1); 5321fcf3ce44SJohn Forte } 5322fcf3ce44SJohn Forte 5323fcf3ce44SJohn Forte return (0); 5324fcf3ce44SJohn Forte } 5325fcf3ce44SJohn Forte 5326fcf3ce44SJohn Forte /* 5327fcf3ce44SJohn Forte * releaseSignal 5328fcf3ce44SJohn Forte * 5329fcf3ce44SJohn Forte * Re-install the original signal mask and signal actions 5330fcf3ce44SJohn Forte * 5331fcf3ce44SJohn Forte * Also, raise any signals that were caught during the hold period and clear 5332fcf3ce44SJohn Forte * the signal from the caught set (signalsCaught). 5333fcf3ce44SJohn Forte * 5334fcf3ce44SJohn Forte * locks held: sigSetLock 5335fcf3ce44SJohn Forte * 5336fcf3ce44SJohn Forte * Returns 5337fcf3ce44SJohn Forte * 0 on success 5338fcf3ce44SJohn Forte * non-zero otherwise 5339fcf3ce44SJohn Forte */ 5340fcf3ce44SJohn Forte static int 5341fcf3ce44SJohn Forte releaseSignal(sigset_t *sigmaskRestore) 5342fcf3ce44SJohn Forte { 5343fcf3ce44SJohn Forte int ret = 0; 5344fcf3ce44SJohn Forte 5345fcf3ce44SJohn Forte if (sigaction(SIGQUIT, ¤tActionQuit, NULL) != 0) { 5346fcf3ce44SJohn Forte ret = 1; 5347fcf3ce44SJohn Forte } 5348fcf3ce44SJohn Forte 5349fcf3ce44SJohn Forte if (sigaction(SIGINT, ¤tActionInt, NULL) != 0) { 5350fcf3ce44SJohn Forte ret = 1; 5351fcf3ce44SJohn Forte } 5352fcf3ce44SJohn Forte 5353fcf3ce44SJohn Forte if (sigaction(SIGTERM, ¤tActionTerm, NULL) != 0) { 5354fcf3ce44SJohn Forte ret = 1; 5355fcf3ce44SJohn Forte } 5356fcf3ce44SJohn Forte 5357fcf3ce44SJohn Forte actionSet = B_FALSE; 5358fcf3ce44SJohn Forte 5359fcf3ce44SJohn Forte /* 5360fcf3ce44SJohn Forte * Restore previous signal mask for this thread 5361fcf3ce44SJohn Forte */ 5362fcf3ce44SJohn Forte if (pthread_sigmask(SIG_SETMASK, sigmaskRestore, NULL) != 0) { 5363fcf3ce44SJohn Forte syslog(LOG_ERR, "Unable to restore sigmask"); 5364fcf3ce44SJohn Forte } 5365fcf3ce44SJohn Forte 5366fcf3ce44SJohn Forte /* 5367fcf3ce44SJohn Forte * Now raise signals that were raised while we were held 5368fcf3ce44SJohn Forte */ 5369fcf3ce44SJohn Forte if (sigismember(&signalsCaught, SIGTERM)) { 5370fcf3ce44SJohn Forte (void) sigdelset(&signalsCaught, SIGTERM); 5371fcf3ce44SJohn Forte (void) raise(SIGTERM); 5372fcf3ce44SJohn Forte } 5373fcf3ce44SJohn Forte 5374fcf3ce44SJohn Forte if (sigismember(&signalsCaught, SIGINT)) { 5375fcf3ce44SJohn Forte (void) sigdelset(&signalsCaught, SIGINT); 5376fcf3ce44SJohn Forte (void) raise(SIGINT); 5377fcf3ce44SJohn Forte } 5378fcf3ce44SJohn Forte 5379fcf3ce44SJohn Forte if (sigismember(&signalsCaught, SIGQUIT)) { 5380fcf3ce44SJohn Forte (void) sigdelset(&signalsCaught, SIGQUIT); 5381fcf3ce44SJohn Forte (void) raise(SIGQUIT); 5382fcf3ce44SJohn Forte } 5383fcf3ce44SJohn Forte 5384fcf3ce44SJohn Forte return (ret); 5385fcf3ce44SJohn Forte } 5386