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