nfs-ganesha 1.4
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #ifdef _SOLARIS 00006 #include "solaris_port.h" 00007 #endif 00008 00009 #include <stdio.h> 00010 #include <string.h> 00011 #include <pthread.h> 00012 #include <fcntl.h> 00013 #include <sys/file.h> /* for having FNDELAY */ 00014 #include <sys/socket.h> 00015 #include <netinet/in.h> 00016 #include <arpa/inet.h> 00017 #include <netdb.h> 00018 #include <ctype.h> 00019 #include "log.h" 00020 #include "ganesha_rpc.h" 00021 #include "fsal.h" 00022 #include "nfs23.h" 00023 #include "nfs4.h" 00024 #include "pnfs.h" 00025 #include "pnfs_internal.h" 00026 #include "mount.h" 00027 #include "nfs_core.h" 00028 #include "cache_inode.h" 00029 #include "nfs_file_handle.h" 00030 #include "nfs_exports.h" 00031 #include "nfs_tools.h" 00032 #include "nfs_proto_functions.h" 00033 #include "nfs_dupreq.h" 00034 #include "config_parsing.h" 00035 00036 pnfs_parameter_t pnfs_param ; 00037 00038 int pnfs_read_ds_conf(config_item_t subblock, 00039 pnfs_ds_parameter_t * pds_conf) 00040 { 00041 unsigned int nb_subitem = config_GetNbItems(subblock); 00042 unsigned int i; 00043 int err; 00044 int var_index; 00045 struct hostent *hp = NULL; 00046 00047 for(i = 0; i < nb_subitem; i++) 00048 { 00049 char *key_name; 00050 char *key_value; 00051 config_item_t item; 00052 item = config_GetItemByIndex(subblock, i); 00053 00054 /* Here, we are managing a configuration sub block, it has nothing but CONFIG_ITEM_VAR in it */ 00055 if(config_ItemType(item) != CONFIG_ITEM_VAR) 00056 { 00057 LogCrit(COMPONENT_CONFIG, "No sub-block expected "); 00058 return -EINVAL; 00059 } 00060 00061 /* recuperation du couple clef-valeur */ 00062 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00063 { 00064 LogCrit(COMPONENT_CONFIG, 00065 "Error reading key[%d] from section \"%s\" of configuration file.", 00066 var_index, CONF_LABEL_NFS_WORKER); 00067 return CACHE_INODE_INVALID_ARGUMENT; 00068 } 00069 else if(!strcasecmp(key_name, "DS_Addr")) 00070 { 00071 if(isdigit(key_value[0])) 00072 { 00073 /* Address begin with a digit, it is a address in the dotted form, translate it */ 00074 pds_conf->ipaddr = inet_addr(key_value); 00075 00076 /* Keep this address in the ascii format as well (for GETDEVICEINFO) */ 00077 strncpy(pds_conf->ipaddr_ascii, key_value, MAXNAMLEN); 00078 } 00079 else 00080 { 00081 /* This is a serveur name that is to be resolved. Use gethostbyname */ 00082 if((hp = gethostbyname(key_value)) == NULL) 00083 { 00084 LogCrit(COMPONENT_CONFIG, 00085 "PNFS LOAD PARAMETER: ERROR: Unexpected value for %s", 00086 key_name); 00087 return -1; 00088 } 00089 memcpy(&pds_conf->ipaddr, (char *)hp->h_addr, hp->h_length); 00090 snprintf(pds_conf->ipaddr_ascii, MAXNAMLEN, 00091 "%u.%u.%u.%u", 00092 ((unsigned int)ntohl(pds_conf->ipaddr) & 00093 0xFF000000) >> 24, 00094 ((unsigned int)ntohl(pds_conf->ipaddr) & 00095 0x00FF0000) >> 16, 00096 ((unsigned int)ntohl(pds_conf->ipaddr) & 00097 0x0000FF00) >> 8, 00098 (unsigned int)ntohl(pds_conf->ipaddr) & 0x000000FF); 00099 } 00100 } 00101 else if(!strcasecmp(key_name, "DS_Ip_Port")) 00102 { 00103 pds_conf->ipport = htons((unsigned short)atoi(key_value)); 00104 } 00105 else if(!strcasecmp(key_name, "DS_ProgNum")) 00106 { 00107 pds_conf->prognum = atoi(key_value); 00108 } 00109 else if(!strcasecmp(key_name, "DS_Root_Path")) 00110 { 00111 } 00112 else if(!strcasecmp(key_name, "DS_Id")) 00113 { 00114 pds_conf->id = atoi(key_value); 00115 } 00116 else if(!strcasecmp(key_name, "DS_Is_Ganesha")) 00117 { 00118 pds_conf->is_ganesha = StrToBoolean(key_value); 00119 } 00120 else 00121 { 00122 LogCrit(COMPONENT_CONFIG, 00123 "Unknown or unsettable key: %s (item %s)", 00124 key_name, CONF_LABEL_PNFS); 00125 return -1; 00126 } 00127 } /* for */ 00128 00129 return 0; 00130 } /* nfs_read_pnfs_ds_conf */ 00131 00132 int pnfs_read_conf(config_file_t in_config, pnfs_parameter_t * pparam) 00133 { 00134 int var_max; 00135 int var_index; 00136 int err; 00137 char *key_name; 00138 char *key_value; 00139 char *block_name; 00140 config_item_t block; 00141 int unique; 00142 00143 unsigned int ds_count = 0; 00144 00145 /* Is the config tree initialized ? */ 00146 if(in_config == NULL || pparam == NULL) 00147 return -1; 00148 00149 /* Get the config BLOCK */ 00150 if((block = config_FindItemByName_CheckUnique(in_config, CONF_LABEL_PNFS, &unique)) == NULL) 00151 { 00152 LogCrit(COMPONENT_CONFIG, 00153 "Cannot read item \"%s\" from configuration file: %s", 00154 CONF_LABEL_PNFS, config_GetErrorMsg() ); 00155 return 1; 00156 } 00157 else if (!unique) 00158 { 00159 LogCrit(COMPONENT_CONFIG, 00160 "Only a single \"%s\" block is expected in config file: %s", 00161 CONF_LABEL_PNFS, config_GetErrorMsg() ); 00162 return -1; 00163 } 00164 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00165 { 00166 /* Expected to be a block */ 00167 return -1; 00168 } 00169 00170 var_max = config_GetNbItems(block); 00171 00172 for(var_index = 0; var_index < var_max; var_index++) 00173 { 00174 config_item_t item; 00175 config_item_type item_type ; 00176 00177 item = config_GetItemByIndex(block, var_index); 00178 item_type = config_ItemType(item) ; 00179 00180 switch( item_type ) 00181 { 00182 case CONFIG_ITEM_VAR: 00183 00184 /* Get key's name */ 00185 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00186 { 00187 LogCrit(COMPONENT_CONFIG, 00188 "Error reading key[%d] from section \"%s\" of configuration file.", 00189 var_index, CONF_LABEL_PNFS); 00190 return -1; 00191 } 00192 else if(!strcasecmp(key_name, "Stripe_Size")) 00193 { 00194 pparam->stripe_size = StrToBoolean(key_value); 00195 } 00196 else if(!strcasecmp(key_name, "Stripe_Width")) 00197 { 00198 pparam->stripe_width = atoi(key_value); 00199 } 00200 else 00201 { 00202 LogCrit(COMPONENT_CONFIG, 00203 "Unknown or unsettable key: %s (item %s)", key_name, 00204 CONF_LABEL_PNFS); 00205 return -1; 00206 } 00207 00208 break; 00209 00210 case CONFIG_ITEM_BLOCK: 00211 block_name = config_GetBlockName(item); 00212 00213 if(!strcasecmp(block_name, "DataServer")) 00214 if(pnfs_read_ds_conf(item, &pparam->ds_param[ds_count]) != 00215 0) 00216 { 00217 LogCrit(COMPONENT_CONFIG, 00218 "Unknown or unsettable key: %s (item %s)", key_name, 00219 CONF_LABEL_PNFS); 00220 return -1; 00221 } 00222 00223 ds_count += 1; 00224 break; 00225 00226 default: 00227 LogCrit(COMPONENT_CONFIG, 00228 "Error reading key[%d] from section \"%s\" of configuration file.", 00229 var_index, CONF_LABEL_PNFS); 00230 return -1; 00231 break; 00232 } /* switch( config_ItemType(item) ) */ 00233 00234 } /* for */ 00235 00236 /* Sanity check : as much or less DS configured than stripe_size */ 00237 if(ds_count < pparam->stripe_width) 00238 { 00239 LogCrit(COMPONENT_CONFIG, 00240 "You must define more pNFS data server for strip_width=%u (only %u defined)", 00241 pparam->stripe_width, ds_count); 00242 return -1; 00243 } 00244 00245 return 0; 00246 } /* pnfs_read_ds_conf */ 00247 00248