libshare_upgrade.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * This file converts shares in libshare v1 format to libshare v2 format. 2N/A * The configuration of libshare v1 shares is stored in the 2N/A * This configuration is read and converted into nvlist format of 2N/A * libshare v2. Additionally, libshare v1 has the concept of groups, shares and 2N/A * resources. Groups can contain shares and shares can have different resource 2N/A * names. Properties can be defined at each of the 3 levels described above. 2N/A * The group properties are inherited by shares and the share properties are 2N/A * inherited by resources. 2N/A * We start out by parsing out the SMF configuration of the share into a 2N/A * nvlist format. We then merge the group and share properties 2N/A * into the newly defined nvlist share for libshare v2. 2N/A * Consider a share defined in libshare v1 format. The share belongs to group 2N/A * named "smb". This group has "rw=*" property setting. The shared path is 2N/A * /export/home and it has "none=*" property setting. The share is 2N/A * named with resource name "exp" and has a description of "comment". 2N/A * Additionally the resource has "rw=.CIFSDEVDC, abe=true, csc=manual" 2N/A * exp=/export/home smb=(rw=".CIFSDEVDC" abe="true" csc="manual") "comment" 2N/A * Format of the share in SMF configuration 2N/A * ---------------------------------------- 2N/A * Group names start with "optionset" and share and resource names 2N/A * start with "S-". The share (with path "/export/home") with resource name 2N/A * "exp" belongs to the "smb" group. 2N/A * optionset_smb application 2N/A * S-d49965d5-a91b-4b40-996d-bff3e535e582 application 2N/A * S-d49965d5-a91b-4b40-996d-bff3e535e582_smb_1 application 2N/A * S-d49965d5-a91b-4b40-996d-bff3e535e582_smb application 2N/A * Format of the nvlist that is created from the share in SMF 2N/A * ---------------------------------------------------------- 2N/A * The SMF configuration is parsed into a nvlist. Below is the output of the 2N/A * nvlist created by parsing the SMF configuration of the share. 2N/A * S-d49965d5-a91b-4b40-996d-bff3e535e582: 2N/A * id: S-d49965d5-a91b-4b40-996d-bff3e535e582 2N/A * Format of libshare v2 nvlist 2N/A * ----------------------------- 2N/A * The above nvlist is converted in to libshare v2 nvlist by merging the 2N/A * properties of groups and share into nvlist for libshare2. 2N/A * The above nvlist configuration is written to persistent repository defined 2N/A * Shares are held in a property group with name of the form 2N/A * S-<GUID>. The total length of the name is 38 characters. 2N/A * service instance related defines 2N/A * The SMF facility uses some properties that must exist. We want to 2N/A * skip over these when processing protocol options. 2N/A "modify_authorization",
2N/A "action_authorization",
2N/A "value_authorization",
2N/A * sa_upgrade_scf_fini 2N/A * Must be called when done. Called with the handle allocated in 2N/A * sa_upgrade_scf_init(), it cleans up the state and frees any SCF resources 2N/A * sa_upgrade_scf_init 2N/A * Must be called before using any of the SCF functions. It initializes and 2N/A * returns handle to SCF database. 2N/A "libshare could not access SMF repository: %s",
2N/A "libshare SMF initialization problem: %s",
2N/A * sa_upgrade_get_scf_limit 2N/A * Since we use scf_limit a lot and do the same check and return the 2N/A * same value if it fails, implement as a function for code 2N/A * simplification. Basically, if name isn't found, return MAXPATHLEN 2N/A * (1024) so we have a reasonable default buffer size. 2N/A * sa_upgrade_skip_property 2N/A * Internal function to check to see if a property is an SMF magic 2N/A * property that needs to be skipped. 2N/A * sa_upgrade_dump_list 2N/A * Debug routine to dump nvlist. Called from sa_upgrade_dump method. 2N/A * Debug routine to dump nvlist. Optionally, an header can be provided before 2N/A * dumping the list. If is_log_smb is set to true, the output is logged to SMF 2N/A * sa_upgrade_get_nvlist 2N/A * Get nvlist associated with the passed "name" parameter. 2N/A * sa_upgrade_map_nvlist_errcodes 2N/A * This routine maps nvlist API error codes to libshare v2 error codes. 2N/A * sa_upgrade_nvlist_merge 2N/A * This method provides a wrapper around nvlist_merge API and returns 2N/A * libshare v2 error codes. 2N/A * sa_upgrade_add_nvlist 2N/A * This method provides a wrapper around nvlist_add_nvlist API and returns 2N/A * libshare v2 error codes. 2N/A * sa_upgrade_extract_resource 2N/A * Extract a resource node from the share node. The resource node is 2N/A * stored in "valuestr" whose format is, 2N/A * "<id1>:<name1>:<description1>" "<id2>:<name2>:<description2>" 2N/A * S-{uuid}/resource astring "1:exp:" "2:exp1:test-descrip" 2N/A "error parsing resource for %s",
path);
2N/A * sa_upgrade_extract_share_prop 2N/A * Extract share properties from the SMF property group. 2N/A * If sectype[0] is a digit, then it is an index into 2N/A * the resource names. We need to find a resource 2N/A * record and then get the properties into an 2N/A * optionset. The optionset becomes the "node" and the 2N/A * rest is hung off of the share. 2N/A "error parsing properties for share id %s.",
id);
2N/A * sa_upgrade_extract_share 2N/A * Extract the share definition from the share property group. 2N/A * Some nfs shares do not have resource names. The resource names 2N/A * for these shares are made up using the share path. 2N/A * sa_upgrade_extract_group_prop 2N/A * Extract the name property group and create the specified type of 2N/A * nvlist from the provided group. The nvlist will be of type "optionset" 2N/A "error while parsing group properties.");
2N/A * sa_upgrade_extract_group 2N/A * Get the config info for the instance of a group and create an 2N/A * Iterate through all the property groups. Property groups 2N/A * starting with "optionset" prefixes are for groups. Property 2N/A * groups starting with "S-" prefix are for shares and 2N/A * A share group in a libshare configuration must have a 2N/A * protocol specified. If we cannot get a group protocol, 2N/A * mark it as an error. If no share and protocol is defined 2N/A * for a group, then just delete that group. 2N/A "GROUP CONFIGURATION");
2N/A * needed as property groups are not sorted in SMF manifest. 2N/A * sa_upgrade_instance_is_enabled 2N/A * Returns B_TRUE if SMF group instance is in online or offline state. 2N/A * The offline state is required as the start method of the SMF manifest 2N/A * will call the upgrade function. 2N/A * sa_upgrade_get_config 2N/A * This method gets the upgrade libshare v1 configuration from a SMF group 2N/A * It skips the "zfs" group instances. 2N/A "error getting configuration for group %s",
gname);
2N/A * sa_upgrade_delete_config 2N/A * which stores the upgrade libshare v1 configuration. 2N/A * sa_upgrade_merge_sec 2N/A * This method merges the "security" properties for a group and/or a share 2N/A * with the "security" properties for a resource. 2N/A * sa_upgrade_merge_prot 2N/A * This method merges the "protocol" properties for a group and/or a share 2N/A * with the "protocol" properties for a resource. It also calls the 2N/A * sa_upgrade_merge_sec() method to merge the "security" properties. 2N/A * sa_upgrade_walk_group 2N/A * This method walks a group (and the nested shares and resources) nvlist, 2N/A * and adds the newly created libshare v2 formatted nvlist(s) in "nvl_new" 2N/A * sa_upgrade_convert_config 2N/A * Converts libshare v1 configuration into libshare v2 configuration. 2N/A * The nvlist configuration for libshare v1 is stored in the nvl_old param. 2N/A * The converted nvlist configuration for libshare v2 is returned in nvl_new 2N/A "error converting group %s to libshare v2 format.",
gname);
2N/A * sa_upgrade_sharing_set 2N/A * does not support these properties, then SA_NOT_SUPPORTED error is returned. 2N/A "error setting sharesmb property for share " 2N/A "error getting mountpoint for share %s in group %s.",
2N/A * in order to preserve share properties, only 2N/A * set this if currently set to off. 2N/A "error setting share%s property " 2N/A "for share %s in group %s",
2N/A * sa_upgrade_write_config 2N/A * This method validates the new libshare v2 config and writes shares 2N/A * in the new SMF instance for libshare v2. It also publishes the new share. 2N/A "error validating share for group %s",
gname);
2N/A * Ignore SA_DUPLICATE_PATH & SA_INVALID_ACCLIST_PROP_VAL 2N/A * errors on upgrade. 2N/A "error validating share %s for group " 2N/A /* add a mountpoint for legacy */ 2N/A "on share %s for group %s",
2N/A "error writing share for group %s",
gname);
2N/A "error writing share %s for group %s",
2N/A "error writing share %s for group %s",
2N/A * This method will log the error message to both syslog and SMF log of the 2N/A * associated SMF service. 2N/A * sa_upgrade_smf_share_group 2N/A * This method upgrades non-zfs shares from libshare v1 format to 2N/A * libshare v2 format. All shares (and resources) in the passed group 2N/A * name are converted. If force_upgrade is B_TRUE, then the state of 2N/A * legacy group service instances will be ignored.