nfs-ganesha 1.4
|
00001 /* 00002 * 00003 * Copyright CEA/DAM/DIF (2008) 00004 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00005 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00006 * 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 3 of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * --------------------------------------- 00023 */ 00024 00070 #ifdef HAVE_CONFIG_H 00071 #include "config.h" 00072 #endif 00073 00074 #ifdef _SOLARIS 00075 #include "solaris_port.h" 00076 #endif 00077 00078 #include <stdio.h> 00079 #include <string.h> 00080 #include <pthread.h> 00081 #include <fcntl.h> 00082 #include <sys/file.h> /* for having FNDELAY */ 00083 #include <sys/socket.h> 00084 #include <netinet/in.h> 00085 #include <arpa/inet.h> 00086 #include <netdb.h> 00087 #include <ctype.h> 00088 #include "log.h" 00089 #include "ganesha_rpc.h" 00090 #include "fsal.h" 00091 #include "nfs23.h" 00092 #include "nfs4.h" 00093 #include "mount.h" 00094 #include "nfs_core.h" 00095 #include "cache_inode.h" 00096 #include "nfs_file_handle.h" 00097 #include "nfs_exports.h" 00098 #include "nfs_tools.h" 00099 #include "nfs_proto_functions.h" 00100 #include "nfs_dupreq.h" 00101 #include "config_parsing.h" 00102 00115 int nfs_read_worker_conf(config_file_t in_config, nfs_worker_parameter_t * pparam) 00116 { 00117 int var_max; 00118 int var_index; 00119 int err; 00120 char *key_name; 00121 char *key_value; 00122 config_item_t block; 00123 00124 /* Is the config tree initialized ? */ 00125 if(in_config == NULL || pparam == NULL) 00126 return CACHE_INODE_INVALID_ARGUMENT; 00127 00128 /* Get the config BLOCK */ 00129 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_WORKER)) == NULL) 00130 { 00131 LogDebug(COMPONENT_CONFIG, 00132 "Cannot read item \"%s\" from configuration file", 00133 CONF_LABEL_NFS_WORKER); 00134 return 1; 00135 } 00136 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00137 { 00138 /* Expected to be a block */ 00139 LogCrit(COMPONENT_CONFIG, 00140 "Item \"%s\" is expected to be a block", 00141 CONF_LABEL_NFS_WORKER); 00142 return 1; 00143 } 00144 00145 var_max = config_GetNbItems(block); 00146 00147 for(var_index = 0; var_index < var_max; var_index++) 00148 { 00149 config_item_t item; 00150 00151 item = config_GetItemByIndex(block, var_index); 00152 00153 /* Get key's name */ 00154 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00155 { 00156 LogCrit(COMPONENT_CONFIG, 00157 "Error reading key[%d] from section \"%s\" of configuration file.", 00158 var_index, CONF_LABEL_NFS_WORKER); 00159 return CACHE_INODE_INVALID_ARGUMENT; 00160 } 00161 00162 else if(!strcasecmp(key_name, "Nb_Before_GC")) 00163 { 00164 pparam->nb_before_gc = atoi(key_value); 00165 } 00166 else 00167 { 00168 LogCrit(COMPONENT_CONFIG, 00169 "Unknown or unsettable key: %s (item %s)", 00170 key_name, CONF_LABEL_NFS_WORKER); 00171 return -1; 00172 } 00173 00174 } 00175 00176 return 0; 00177 } /* nfs_read_worker_conf */ 00178 00191 int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam) 00192 { 00193 int var_max; 00194 int var_index; 00195 int err; 00196 char *key_name; 00197 char *key_value; 00198 config_item_t block; 00199 00200 /* Is the config tree initialized ? */ 00201 if(in_config == NULL || pparam == NULL) 00202 return CACHE_INODE_INVALID_ARGUMENT; 00203 00204 /* Get the config BLOCK */ 00205 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL) 00206 { 00207 LogDebug(COMPONENT_CONFIG, 00208 "Cannot read item \"%s\" from configuration file", 00209 CONF_LABEL_NFS_CORE); 00210 return 1; 00211 } 00212 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00213 { 00214 /* Expected to be a block */ 00215 LogDebug(COMPONENT_CONFIG, 00216 "Item \"%s\" is expected to be a block", 00217 CONF_LABEL_NFS_CORE); 00218 return 1; 00219 } 00220 00221 var_max = config_GetNbItems(block); 00222 00223 for(var_index = 0; var_index < var_max; var_index++) 00224 { 00225 config_item_t item; 00226 00227 item = config_GetItemByIndex(block, var_index); 00228 00229 /* Get key's name */ 00230 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00231 { 00232 LogCrit(COMPONENT_CONFIG, 00233 "Error reading key[%d] from section \"%s\" of configuration file.", 00234 var_index, CONF_LABEL_NFS_CORE); 00235 return CACHE_INODE_INVALID_ARGUMENT; 00236 } 00237 00238 if(!strcasecmp(key_name, "Nb_Worker")) 00239 { 00240 pparam->nb_worker = atoi(key_value); 00241 } 00242 else if(!strcasecmp(key_name, "Nb_Call_Before_Queue_Avg")) 00243 { 00244 pparam->nb_call_before_queue_avg = atoi(key_value); 00245 } 00246 else if(!strcasecmp(key_name, "Nb_MaxConcurrentGC")) 00247 { 00248 pparam->nb_max_concurrent_gc = atoi(key_value); 00249 } 00250 else if(!strcasecmp(key_name, "DupReq_Expiration")) 00251 { 00252 pparam->expiration_dupreq = atoi(key_value); 00253 } 00254 else if(!strcasecmp(key_name, "Dispatch_Multi_Xprt_Max")) 00255 { 00256 pparam->dispatch_multi_xprt_max = atoi(key_value); 00257 } 00258 else if(!strcasecmp(key_name, "Dispatch_Multi_Worker_Hiwat")) 00259 { 00260 pparam->dispatch_multi_worker_hiwat = atoi(key_value); 00261 } 00262 else if(!strcasecmp(key_name, "Drop_IO_Errors")) 00263 { 00264 pparam->drop_io_errors = StrToBoolean(key_value); 00265 } 00266 else if(!strcasecmp(key_name, "Drop_Inval_Errors")) 00267 { 00268 pparam->drop_inval_errors = StrToBoolean(key_value); 00269 } 00270 else if(!strcasecmp(key_name, "Drop_Delay_Errors")) 00271 { 00272 pparam->drop_delay_errors = StrToBoolean(key_value); 00273 } 00274 else if(!strcasecmp(key_name, "NFS_Port")) 00275 { 00276 pparam->port[P_NFS] = (unsigned short)atoi(key_value); 00277 } 00278 else if(!strcasecmp(key_name, "MNT_Port")) 00279 { 00280 pparam->port[P_MNT] = (unsigned short)atoi(key_value); 00281 } 00282 else if(!strcasecmp(key_name, "NLM_Port")) 00283 { 00284 #ifdef _USE_NLM 00285 pparam->port[P_NLM] = (unsigned short)atoi(key_value); 00286 #endif 00287 } 00288 else if(!strcasecmp(key_name, "Rquota_Port")) 00289 { 00290 #ifdef _USE_RQUOTA 00291 pparam->port[P_RQUOTA] = (unsigned short)atoi(key_value); 00292 #endif 00293 } 00294 else if(!strcasecmp(key_name, "NFS_Program")) 00295 { 00296 pparam->program[P_NFS] = atoi(key_value); 00297 } 00298 else if(!strcasecmp(key_name, "MNT_Program")) 00299 { 00300 pparam->program[P_MNT] = atoi(key_value); 00301 } 00302 else if(!strcasecmp(key_name, "NLM_Program")) 00303 { 00304 #ifdef _USE_NLM 00305 pparam->program[P_NLM] = atoi(key_value); 00306 #endif 00307 } 00308 else if(!strcasecmp(key_name, "Rquota_Program")) 00309 { 00310 #ifdef _USE_RQUOTA 00311 pparam->program[P_RQUOTA] = atoi(key_value); 00312 #endif 00313 } 00314 else if(!strcasecmp(key_name, "NFS_Protocols")) 00315 { 00316 00317 # define MAX_NFSPROTO 10 /* large enough !!! */ 00318 # define MAX_NFSPROTO_LEN 256 /* so is it !!! */ 00319 00320 char *nfsvers_list[MAX_NFSPROTO]; 00321 int idx, count; 00322 00323 /* reset nfs versions flags (clean defaults) */ 00324 pparam->core_options &= ~(CORE_OPTION_ALL_VERS); 00325 00326 /* allocate nfs vers strings */ 00327 for(idx = 0; idx < MAX_NFSPROTO; idx++) 00328 nfsvers_list[idx] = gsh_malloc(MAX_NFSPROTO_LEN); 00329 00330 /* 00331 * Search for coma-separated list of nfsprotos 00332 */ 00333 count = nfs_ParseConfLine(nfsvers_list, MAX_NFSPROTO, 00334 key_value, find_comma, find_endLine); 00335 00336 if(count < 0) 00337 { 00338 LogCrit(COMPONENT_CONFIG, 00339 "NFS_Protocols list too long (>%d)", 00340 MAX_NFSPROTO); 00341 00342 /* free sec strings */ 00343 for(idx = 0; idx < MAX_NFSPROTO; idx++) 00344 gsh_free(nfsvers_list[idx]); 00345 00346 return -1; 00347 } 00348 00349 /* add each Nfs protocol flag to the option field. */ 00350 00351 for(idx = 0; idx < count; idx++) 00352 { 00353 if(!strcmp(nfsvers_list[idx], "4")) 00354 { 00355 pparam->core_options |= CORE_OPTION_NFSV4; 00356 } 00357 else if(!strcmp(nfsvers_list[idx], "2")) 00358 { 00359 pparam->core_options |= CORE_OPTION_NFSV2; 00360 } 00361 else if(!strcmp(nfsvers_list[idx], "3")) 00362 { 00363 pparam->core_options |= CORE_OPTION_NFSV3; 00364 } 00365 else 00366 { 00367 LogCrit(COMPONENT_CONFIG, 00368 "Invalid NFS Protocol \"%s\". Values can be: 2, 3, 4.", 00369 nfsvers_list[idx]); 00370 return -1; 00371 } 00372 } 00373 00374 /* free sec strings */ 00375 for(idx = 0; idx < MAX_NFSPROTO; idx++) 00376 gsh_free(nfsvers_list[idx]); 00377 00378 /* check that at least one nfs protocol has been specified */ 00379 if((pparam->core_options & (CORE_OPTION_ALL_VERS)) == 0) 00380 { 00381 LogCrit(COMPONENT_CONFIG, "Empty NFS_Protocols list"); 00382 return -1; 00383 } 00384 } 00385 else if(!strcasecmp(key_name, "Bind_Addr")) 00386 { 00387 int rc; 00388 memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr)); 00389 rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr); 00390 if(rc <= 0) 00391 { 00392 /* Revert to INADDR_ANY in case of any error */ 00393 pparam->bind_addr.sin_addr.s_addr = INADDR_ANY; /* All the interfaces on the machine are used */ 00394 } 00395 } 00396 else if(!strcasecmp(key_name, "Core_Dump_Size")) 00397 { 00398 pparam->core_dump_size = atol(key_value); 00399 } 00400 else if(!strcasecmp(key_name, "Nb_Max_Fd")) 00401 { 00402 pparam->nb_max_fd = atoi(key_value); 00403 } 00404 else if(!strcasecmp(key_name, "Stats_File_Path")) 00405 { 00406 strncpy(pparam->stats_file_path, key_value, MAXPATHLEN); 00407 } 00408 else if(!strcasecmp(key_name, "Stats_Update_Delay")) 00409 { 00410 pparam->stats_update_delay = atoi(key_value); 00411 } 00412 else if(!strcasecmp(key_name, "Long_Processing_Threshold")) 00413 { 00414 pparam->long_processing_threshold = atoi(key_value); 00415 } 00416 else if(!strcasecmp( key_name, "TCP_Fridge_Expiration_Delay" ) ) 00417 { 00418 pparam->tcp_fridge_expiration_delay = atoi(key_value); 00419 } 00420 else if(!strcasecmp(key_name, "Dump_Stats_Per_Client")) 00421 { 00422 pparam->dump_stats_per_client = StrToBoolean(key_value); 00423 } 00424 else if(!strcasecmp(key_name, "Stats_Per_Client_Directory")) 00425 { 00426 strncpy(pparam->stats_per_client_directory, key_value, MAXPATHLEN); 00427 } 00428 else if(!strcasecmp(key_name, "FSAL_Shared_Library")) 00429 { 00430 strncpy(pparam->fsal_shared_library, key_value, MAXPATHLEN); 00431 } 00432 else if(!strcasecmp( key_name, "MaxRPCSendBufferSize" ) ) 00433 { 00434 pparam->max_send_buffer_size = atoi(key_value); 00435 } 00436 else if(!strcasecmp( key_name, "MaxRPCRecvBufferSize" ) ) 00437 { 00438 pparam->max_recv_buffer_size = atoi(key_value); 00439 } 00440 #ifdef _USE_NLM 00441 else if(!strcasecmp( key_name, "NSM_Use_Caller_Name" ) ) 00442 { 00443 pparam->nsm_use_caller_name = StrToBoolean(key_value); 00444 } 00445 #endif 00446 else if(!strcasecmp(key_name, "Clustered")) 00447 { 00448 pparam->clustered = StrToBoolean(key_value); 00449 } 00450 else 00451 { 00452 LogCrit(COMPONENT_CONFIG, 00453 "Unknown or unsettable key: %s (item %s)", 00454 key_name, CONF_LABEL_NFS_CORE); 00455 return -1; 00456 } 00457 00458 } 00459 00460 return 0; 00461 } /* nfs_read_core_conf */ 00462 00475 int nfs_read_dupreq_hash_conf(config_file_t in_config, 00476 nfs_rpc_dupreq_parameter_t * pparam) 00477 { 00478 int var_max; 00479 int var_index; 00480 int err; 00481 char *key_name; 00482 char *key_value; 00483 config_item_t block; 00484 00485 /* Is the config tree initialized ? */ 00486 if(in_config == NULL || pparam == NULL) 00487 return -1; 00488 00489 /* Get the config BLOCK */ 00490 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_DUPREQ)) == NULL) 00491 { 00492 LogDebug(COMPONENT_CONFIG, 00493 "Cannot read item \"%s\" from configuration file", 00494 CONF_LABEL_NFS_DUPREQ); 00495 return 1; 00496 } 00497 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00498 { 00499 /* Expected to be a block */ 00500 LogDebug(COMPONENT_CONFIG, 00501 "Item \"%s\" is expected to be a block", 00502 CONF_LABEL_NFS_DUPREQ); 00503 return 1; 00504 } 00505 00506 var_max = config_GetNbItems(block); 00507 00508 for(var_index = 0; var_index < var_max; var_index++) 00509 { 00510 config_item_t item; 00511 00512 item = config_GetItemByIndex(block, var_index); 00513 00514 /* Get key's name */ 00515 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00516 { 00517 LogCrit(COMPONENT_CONFIG, 00518 "Error reading key[%d] from section \"%s\" of configuration file.", 00519 var_index, CONF_LABEL_NFS_DUPREQ); 00520 return -1; 00521 } 00522 00523 if(!strcasecmp(key_name, "Index_Size")) 00524 { 00525 pparam->hash_param.index_size = atoi(key_value); 00526 } 00527 else if(!strcasecmp(key_name, "Alphabet_Length")) 00528 { 00529 pparam->hash_param.alphabet_length = atoi(key_value); 00530 } 00531 else 00532 { 00533 LogCrit(COMPONENT_CONFIG, 00534 "Unknown or unsettable key: %s (item %s)", 00535 key_name, CONF_LABEL_NFS_DUPREQ); 00536 return -1; 00537 } 00538 } 00539 00540 return 0; 00541 } /* nfs_read_dupreq_hash_conf */ 00542 00555 int nfs_read_ip_name_conf(config_file_t in_config, nfs_ip_name_parameter_t * pparam) 00556 { 00557 int var_max; 00558 int var_index; 00559 int err; 00560 char *key_name; 00561 char *key_value; 00562 config_item_t block; 00563 00564 /* Is the config tree initialized ? */ 00565 if(in_config == NULL || pparam == NULL) 00566 return -1; 00567 00568 /* Get the config BLOCK */ 00569 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_IP_NAME)) == NULL) 00570 { 00571 LogDebug(COMPONENT_CONFIG, 00572 "Cannot read item \"%s\" from configuration file", CONF_LABEL_NFS_IP_NAME); 00573 return 1; 00574 } 00575 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00576 { 00577 /* Expected to be a block */ 00578 LogDebug(COMPONENT_CONFIG, 00579 "Item \"%s\" is expected to be a block", CONF_LABEL_NFS_IP_NAME); 00580 return 1; 00581 } 00582 00583 var_max = config_GetNbItems(block); 00584 00585 for(var_index = 0; var_index < var_max; var_index++) 00586 { 00587 config_item_t item; 00588 00589 item = config_GetItemByIndex(block, var_index); 00590 00591 /* Get key's name */ 00592 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00593 { 00594 LogCrit(COMPONENT_CONFIG, 00595 "Error reading key[%d] from section \"%s\" of configuration file.", 00596 var_index, CONF_LABEL_NFS_IP_NAME); 00597 return -1; 00598 } 00599 00600 if(!strcasecmp(key_name, "Index_Size")) 00601 { 00602 pparam->hash_param.index_size = atoi(key_value); 00603 } 00604 else if(!strcasecmp(key_name, "Alphabet_Length")) 00605 { 00606 pparam->hash_param.alphabet_length = atoi(key_value); 00607 } 00608 else if(!strcasecmp(key_name, "Expiration_Time")) 00609 { 00610 pparam->expiration_time = atoi(key_value); 00611 } 00612 else if(!strcasecmp(key_name, "Map")) 00613 { 00614 strncpy(pparam->mapfile, key_value, MAXPATHLEN); 00615 } 00616 else 00617 { 00618 LogCrit(COMPONENT_CONFIG, 00619 "Unknown or unsettable key: %s (item %s)", 00620 key_name, CONF_LABEL_NFS_IP_NAME); 00621 return -1; 00622 } 00623 } 00624 00625 return 0; 00626 } /* nfs_read_ip_name_conf */ 00627 00640 int nfs_read_client_id_conf(config_file_t in_config, nfs_client_id_parameter_t * pparam) 00641 { 00642 int var_max; 00643 int var_index; 00644 int err; 00645 char *key_name; 00646 char *key_value; 00647 config_item_t block; 00648 00649 /* Is the config tree initialized ? */ 00650 if(in_config == NULL || pparam == NULL) 00651 return -1; 00652 00653 /* Get the config BLOCK */ 00654 if((block = config_FindItemByName(in_config, CONF_LABEL_CLIENT_ID)) == NULL) 00655 { 00656 LogDebug(COMPONENT_CONFIG, 00657 "Cannot read item \"%s\" from configuration file", CONF_LABEL_CLIENT_ID); 00658 return 1; 00659 } 00660 00661 var_max = config_GetNbItems(block); 00662 00663 for(var_index = 0; var_index < var_max; var_index++) 00664 { 00665 config_item_t item; 00666 00667 item = config_GetItemByIndex(block, var_index); 00668 00669 /* Get key's name */ 00670 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00671 { 00672 LogCrit(COMPONENT_CONFIG, 00673 "Error reading key[%d] from section \"%s\" of configuration file.", 00674 var_index, CONF_LABEL_CLIENT_ID); 00675 return -1; 00676 } 00677 00678 if(!strcasecmp(key_name, "Index_Size")) 00679 { 00680 pparam->cid_unconfirmed_hash_param.index_size = atoi(key_value); 00681 pparam->cid_confirmed_hash_param.index_size = atoi(key_value); 00682 pparam->cr_hash_param.index_size = atoi(key_value); 00683 } 00684 else if(!strcasecmp(key_name, "Alphabet_Length")) 00685 { 00686 pparam->cid_unconfirmed_hash_param.alphabet_length = atoi(key_value); 00687 pparam->cid_confirmed_hash_param.alphabet_length = atoi(key_value); 00688 pparam->cr_hash_param.alphabet_length = atoi(key_value); 00689 } 00690 else 00691 { 00692 LogCrit(COMPONENT_CONFIG, 00693 "Unknown or unsettable key: %s (item %s)", 00694 key_name, CONF_LABEL_CLIENT_ID); 00695 return -1; 00696 } 00697 } 00698 00699 return 0; 00700 } /* nfs_client_id_conf */ 00701 00714 int nfs_read_state_id_conf(config_file_t in_config, nfs_state_id_parameter_t * pparam) 00715 { 00716 int var_max; 00717 int var_index; 00718 int err; 00719 char *key_name; 00720 char *key_value; 00721 config_item_t block; 00722 00723 /* Is the config tree initialized ? */ 00724 if(in_config == NULL || pparam == NULL) 00725 return -1; 00726 00727 /* Get the config BLOCK */ 00728 if((block = config_FindItemByName(in_config, CONF_LABEL_STATE_ID)) == NULL) 00729 { 00730 LogDebug(COMPONENT_CONFIG, 00731 "Cannot read item \"%s\" from configuration file", CONF_LABEL_STATE_ID); 00732 return 1; 00733 } 00734 00735 var_max = config_GetNbItems(block); 00736 00737 for(var_index = 0; var_index < var_max; var_index++) 00738 { 00739 config_item_t item; 00740 00741 item = config_GetItemByIndex(block, var_index); 00742 00743 /* Get key's name */ 00744 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00745 { 00746 LogCrit(COMPONENT_CONFIG, 00747 "Error reading key[%d] from section \"%s\" of configuration file.", 00748 var_index, CONF_LABEL_STATE_ID); 00749 return -1; 00750 } 00751 00752 if(!strcasecmp(key_name, "Index_Size")) 00753 { 00754 pparam->hash_param.index_size = atoi(key_value); 00755 } 00756 else if(!strcasecmp(key_name, "Alphabet_Length")) 00757 { 00758 pparam->hash_param.alphabet_length = atoi(key_value); 00759 } 00760 else 00761 { 00762 LogCrit(COMPONENT_CONFIG, 00763 "Unknown or unsettable key: %s (item %s)", 00764 key_name, CONF_LABEL_STATE_ID); 00765 return -1; 00766 } 00767 } 00768 00769 return 0; 00770 } /* nfs_state_id_conf */ 00771 00772 #ifdef _USE_NFS4_1 00773 int nfs_read_session_id_conf(config_file_t in_config, nfs_session_id_parameter_t * pparam) 00774 { 00775 int var_max; 00776 int var_index; 00777 int err; 00778 char *key_name; 00779 char *key_value; 00780 config_item_t block; 00781 00782 /* Is the config tree initialized ? */ 00783 if(in_config == NULL || pparam == NULL) 00784 return -1; 00785 00786 /* Get the config BLOCK */ 00787 if((block = config_FindItemByName(in_config, CONF_LABEL_SESSION_ID)) == NULL) 00788 { 00789 LogDebug(COMPONENT_CONFIG, 00790 "Cannot read item \"%s\" from configuration file", CONF_LABEL_STATE_ID); 00791 return 1; 00792 } 00793 00794 var_max = config_GetNbItems(block); 00795 00796 for(var_index = 0; var_index < var_max; var_index++) 00797 { 00798 config_item_t item; 00799 00800 item = config_GetItemByIndex(block, var_index); 00801 00802 /* Get key's name */ 00803 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00804 { 00805 LogCrit(COMPONENT_CONFIG, 00806 "Error reading key[%d] from section \"%s\" of configuration file.", 00807 var_index, CONF_LABEL_SESSION_ID); 00808 return -1; 00809 } 00810 00811 if(!strcasecmp(key_name, "Index_Size")) 00812 { 00813 pparam->hash_param.index_size = atoi(key_value); 00814 } 00815 else if(!strcasecmp(key_name, "Alphabet_Length")) 00816 { 00817 pparam->hash_param.alphabet_length = atoi(key_value); 00818 } 00819 else 00820 { 00821 LogCrit(COMPONENT_CONFIG, 00822 "Unknown or unsettable key: %s (item %s)", 00823 key_name, CONF_LABEL_SESSION_ID); 00824 return -1; 00825 } 00826 } 00827 00828 return 0; 00829 } /* nfs_session_id_conf */ 00830 00831 #endif 00832 00845 int nfs_read_uidmap_conf(config_file_t in_config, nfs_idmap_cache_parameter_t * pparam) 00846 { 00847 int var_max; 00848 int var_index; 00849 int err; 00850 char *key_name; 00851 char *key_value; 00852 config_item_t block; 00853 00854 /* Is the config tree initialized ? */ 00855 if(in_config == NULL || pparam == NULL) 00856 return -1; 00857 00858 /* Get the config BLOCK */ 00859 if((block = config_FindItemByName(in_config, CONF_LABEL_UID_MAPPER)) == NULL) 00860 { 00861 LogDebug(COMPONENT_CONFIG, 00862 "Cannot read item \"%s\" from configuration file", 00863 CONF_LABEL_CLIENT_ID); 00864 return 1; 00865 } 00866 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00867 { 00868 /* Expected to be a block */ 00869 LogDebug(COMPONENT_CONFIG, 00870 "Item \"%s\" is expected to be a block", 00871 CONF_LABEL_CLIENT_ID); 00872 return 1; 00873 } 00874 00875 var_max = config_GetNbItems(block); 00876 00877 for(var_index = 0; var_index < var_max; var_index++) 00878 { 00879 config_item_t item; 00880 00881 item = config_GetItemByIndex(block, var_index); 00882 00883 /* Get key's name */ 00884 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00885 { 00886 LogCrit(COMPONENT_CONFIG, 00887 "Error reading key[%d] from section \"%s\" of configuration file.", 00888 var_index, CONF_LABEL_UID_MAPPER); 00889 return -1; 00890 } 00891 00892 if(!strcasecmp(key_name, "Index_Size")) 00893 { 00894 pparam->hash_param.index_size = atoi(key_value); 00895 } 00896 else if(!strcasecmp(key_name, "Alphabet_Length")) 00897 { 00898 pparam->hash_param.alphabet_length = atoi(key_value); 00899 } 00900 else if(!strcasecmp(key_name, "Map")) 00901 { 00902 strncpy(pparam->mapfile, key_value, MAXPATHLEN); 00903 } 00904 else 00905 { 00906 LogCrit(COMPONENT_CONFIG, 00907 "Unknown or unsettable key: %s (item %s)", 00908 key_name, CONF_LABEL_UID_MAPPER); 00909 return -1; 00910 } 00911 } 00912 00913 return 0; 00914 } /* nfs_read_uidmap_conf */ 00915 00928 int nfs_read_gidmap_conf(config_file_t in_config, nfs_idmap_cache_parameter_t * pparam) 00929 { 00930 int var_max; 00931 int var_index; 00932 int err; 00933 char *key_name; 00934 char *key_value; 00935 config_item_t block; 00936 00937 /* Is the config tree initialized ? */ 00938 if(in_config == NULL || pparam == NULL) 00939 return -1; 00940 00941 /* Get the config BLOCK */ 00942 if((block = config_FindItemByName(in_config, CONF_LABEL_GID_MAPPER)) == NULL) 00943 { 00944 LogDebug(COMPONENT_CONFIG, 00945 "Cannot read item \"%s\" from configuration file", 00946 CONF_LABEL_CLIENT_ID); 00947 return 1; 00948 } 00949 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 00950 { 00951 /* Expected to be a block */ 00952 LogDebug(COMPONENT_CONFIG, 00953 "Item \"%s\" is expected to be a block", 00954 CONF_LABEL_CLIENT_ID); 00955 return 1; 00956 } 00957 00958 var_max = config_GetNbItems(block); 00959 00960 for(var_index = 0; var_index < var_max; var_index++) 00961 { 00962 config_item_t item; 00963 00964 item = config_GetItemByIndex(block, var_index); 00965 00966 /* Get key's name */ 00967 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 00968 { 00969 LogCrit(COMPONENT_CONFIG, 00970 "Error reading key[%d] from section \"%s\" of configuration file.", 00971 var_index, CONF_LABEL_GID_MAPPER); 00972 return -1; 00973 } 00974 00975 if(!strcasecmp(key_name, "Index_Size")) 00976 { 00977 pparam->hash_param.index_size = atoi(key_value); 00978 } 00979 else if(!strcasecmp(key_name, "Alphabet_Length")) 00980 { 00981 pparam->hash_param.alphabet_length = atoi(key_value); 00982 } 00983 else if(!strcasecmp(key_name, "Map")) 00984 { 00985 strncpy(pparam->mapfile, key_value, MAXPATHLEN); 00986 } 00987 else 00988 { 00989 LogCrit(COMPONENT_CONFIG, 00990 "Unknown or unsettable key: %s (item %s)", 00991 key_name, CONF_LABEL_GID_MAPPER); 00992 return -1; 00993 } 00994 } 00995 00996 return 0; 00997 } /* nfs_read_gidmap_conf */ 00998 00999 #ifdef _HAVE_GSSAPI 01000 01012 int nfs_read_krb5_conf(config_file_t in_config, nfs_krb5_parameter_t * pparam) 01013 { 01014 int var_max; 01015 int var_index; 01016 int err; 01017 char *key_name; 01018 char *key_value; 01019 config_item_t block; 01020 01021 /* Is the config tree initialized ? */ 01022 if(in_config == NULL || pparam == NULL) 01023 return -1; 01024 01025 /* Get the config BLOCK */ 01026 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_KRB5)) == NULL) 01027 { 01028 LogDebug(COMPONENT_CONFIG, 01029 "Cannot read item \"%s\" from configuration file", 01030 CONF_LABEL_NFS_KRB5); 01031 return 1; 01032 } 01033 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 01034 { 01035 /* Expected to be a block */ 01036 LogDebug(COMPONENT_CONFIG, 01037 "Item \"%s\" is expected to be a block", 01038 CONF_LABEL_NFS_KRB5); 01039 return 1; 01040 } 01041 01042 var_max = config_GetNbItems(block); 01043 01044 for(var_index = 0; var_index < var_max; var_index++) 01045 { 01046 config_item_t item; 01047 01048 item = config_GetItemByIndex(block, var_index); 01049 01050 /* Get key's name */ 01051 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 01052 { 01053 LogCrit(COMPONENT_CONFIG, 01054 "Error reading key[%d] from section \"%s\" of configuration file.", 01055 var_index, CONF_LABEL_NFS_KRB5); 01056 return -1; 01057 } 01058 01059 if(!strcasecmp(key_name, "PrincipalName")) 01060 { 01061 strlcpy(pparam->svc.principal, key_value, 01062 sizeof(pparam->svc.principal)); 01063 } 01064 else if(!strcasecmp(key_name, "KeytabPath")) 01065 { 01066 strlcpy(pparam->keytab, key_value, sizeof(pparam->keytab)); 01067 } 01068 else if(!strcasecmp(key_name, "Active_krb5")) 01069 { 01070 pparam->active_krb5 = StrToBoolean(key_value); 01071 } 01072 else 01073 { 01074 LogCrit(COMPONENT_CONFIG, 01075 "Unknown or unsettable key: %s (item %s)", 01076 key_name, CONF_LABEL_NFS_KRB5); 01077 return -1; 01078 } 01079 } 01080 01081 return 0; 01082 } /* nfs_read_krb5_conf */ 01083 #endif 01084 01097 int nfs_read_version4_conf(config_file_t in_config, nfs_version4_parameter_t * pparam) 01098 { 01099 int var_max; 01100 int var_index; 01101 int err; 01102 char *key_name; 01103 char *key_value; 01104 config_item_t block; 01105 01106 /* Is the config tree initialized ? */ 01107 if(in_config == NULL || pparam == NULL) 01108 return -1; 01109 01110 /* Get the config BLOCK */ 01111 if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_VERSION4)) == NULL) 01112 { 01113 LogDebug(COMPONENT_CONFIG, 01114 "Cannot read item \"%s\" from configuration file", 01115 CONF_LABEL_NFS_VERSION4); 01116 return 1; 01117 } 01118 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 01119 { 01120 /* Expected to be a block */ 01121 LogDebug(COMPONENT_CONFIG, 01122 "Item \"%s\" is expected to be a block", 01123 CONF_LABEL_NFS_VERSION4); 01124 return 1; 01125 } 01126 01127 var_max = config_GetNbItems(block); 01128 01129 for(var_index = 0; var_index < var_max; var_index++) 01130 { 01131 config_item_t item; 01132 01133 item = config_GetItemByIndex(block, var_index); 01134 01135 /* Get key's name */ 01136 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 01137 { 01138 LogCrit(COMPONENT_CONFIG, 01139 "Error reading key[%d] from section \"%s\" of configuration file.", 01140 var_index, CONF_LABEL_NFS_VERSION4); 01141 return -1; 01142 } 01143 01144 if(!strcasecmp(key_name, "Lease_Lifetime")) 01145 { 01146 pparam->lease_lifetime = atoi(key_value); 01147 } 01148 else if(!strcasecmp(key_name, "DomainName")) 01149 { 01150 strncpy(pparam->domainname, key_value, MAXNAMLEN); 01151 } 01152 else if(!strcasecmp(key_name, "IdmapConf")) 01153 { 01154 strncpy(pparam->idmapconf, key_value, MAXPATHLEN); 01155 } 01156 else if(!strcasecmp(key_name, "FH_Expire")) 01157 { 01158 pparam->fh_expire = StrToBoolean(key_value); 01159 } 01160 else if(!strcasecmp(key_name, "Returns_ERR_FH_EXPIRED")) 01161 { 01162 pparam->returns_err_fh_expired = StrToBoolean(key_value); 01163 } 01164 else if(!strcasecmp(key_name, "Return_Bad_Stateid")) 01165 { 01166 pparam->return_bad_stateid = StrToBoolean(key_value); 01167 } 01168 else 01169 { 01170 LogCrit(COMPONENT_CONFIG, 01171 "Unknown or unsettable key: %s (item %s)", 01172 key_name, CONF_LABEL_NFS_VERSION4); 01173 return -1; 01174 } 01175 } 01176 01177 return 0; 01178 } /* nfs_read_version4_conf */ 01179 01191 void Print_param_worker_in_log(nfs_worker_parameter_t * pparam) 01192 { 01193 LogInfo(COMPONENT_INIT, 01194 "NFS PARAM : worker_param.nb_before_gc = %d", 01195 pparam->nb_before_gc); 01196 } /* Print_param_worker_in_log */ 01197 01209 void Print_param_in_log() 01210 { 01211 LogInfo(COMPONENT_INIT, 01212 "NFS PARAM : core_param.nb_worker = %d", 01213 nfs_param.core_param.nb_worker); 01214 Print_param_worker_in_log(&nfs_param.worker_param); 01215 } /* Print_param_in_log */ 01216 01217 int nfs_get_fsalpathlib_conf(char *configPath, path_str_t * PathLib, unsigned int *plen) 01218 { 01219 int var_max; 01220 int var_index; 01221 int err; 01222 char *key_name; 01223 char *key_value; 01224 config_item_t block; 01225 unsigned int found = FALSE; 01226 config_file_t config_struct; 01227 unsigned int index = 0 ; 01228 01229 /* Is the config tree initialized ? */ 01230 if(configPath == NULL || PathLib == NULL) 01231 LogFatal(COMPONENT_CONFIG, 01232 "nfs_get_fsalpathlib_conf configPath=%p PathLib=%p", 01233 configPath, PathLib); 01234 01235 config_struct = config_ParseFile(configPath); 01236 01237 if(!config_struct) 01238 LogFatal(COMPONENT_CONFIG, 01239 "Error while parsing %s: %s", 01240 configPath, config_GetErrorMsg()); 01241 01242 /* Get the config BLOCK */ 01243 if((block = config_FindItemByName(config_struct, CONF_LABEL_NFS_CORE)) == NULL) 01244 { 01245 LogFatal(COMPONENT_CONFIG, 01246 "Cannot read item \"%s\" from configuration file", 01247 CONF_LABEL_NFS_CORE); 01248 } 01249 else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) 01250 { 01251 /* Expected to be a block */ 01252 LogFatal(COMPONENT_CONFIG, 01253 "Item \"%s\" is expected to be a block", 01254 CONF_LABEL_NFS_CORE); 01255 } 01256 01257 var_max = config_GetNbItems(block); 01258 01259 for(var_index = 0; var_index < var_max; var_index++) 01260 { 01261 config_item_t item; 01262 01263 item = config_GetItemByIndex(block, var_index); 01264 01265 /* Get key's name */ 01266 if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) 01267 { 01268 LogFatal(COMPONENT_CONFIG, 01269 "Error reading key[%d] from section \"%s\" of configuration file.", 01270 var_index, CONF_LABEL_NFS_CORE); 01271 } 01272 01273 if(!strcasecmp(key_name, "FSAL_Shared_Library")) 01274 { 01275 strncpy(PathLib[index], key_value, MAXPATHLEN); 01276 index += 1 ; 01277 01278 found = TRUE; 01279 01280 /* Do not exceed array size */ 01281 if( index == *plen ) 01282 break ; 01283 } 01284 01285 } 01286 01287 if(!found) 01288 { 01289 LogFatal(COMPONENT_CONFIG, 01290 "FSAL_Shared_Library not found"); 01291 return 1; 01292 } 01293 01294 *plen = index ; 01295 return 0; 01296 } /* nfs_get_fsalpathlib_conf */