/** * * nfs_read_core_conf: read the configuration ite; for the worker theads. * * Reads the configuration ite; for the worker theads. * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return 0 if ok, -1 if failed, 1 is stanza is not there. * */ int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return CACHE_INODE_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_NFS_CORE); return 1; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogDebug(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_NFS_CORE); return 1; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_NFS_CORE); return CACHE_INODE_INVALID_ARGUMENT; } if(!strcasecmp(key_name, "Nb_Worker")) { pparam->nb_worker = atoi(key_value); } else if(!strcasecmp(key_name, "Nb_Call_Before_Queue_Avg")) { pparam->nb_call_before_queue_avg = atoi(key_value); } else if(!strcasecmp(key_name, "Nb_MaxConcurrentGC")) { pparam->nb_max_concurrent_gc = atoi(key_value); } else if(!strcasecmp(key_name, "DupReq_Expiration")) { pparam->expiration_dupreq = atoi(key_value); } else if(!strcasecmp(key_name, "Drop_IO_Errors")) { pparam->drop_io_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Drop_Inval_Errors")) { pparam->drop_inval_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Drop_Delay_Errors")) { pparam->drop_delay_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "NFS_Port")) { pparam->port[P_NFS] = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "MNT_Port")) { pparam->port[P_MNT] = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "NLM_Port")) { #ifdef _USE_NLM pparam->port[P_NLM] = (unsigned short)atoi(key_value); #endif } else if(!strcasecmp(key_name, "Rquota_Port")) { #ifdef _USE_QUOTA pparam->port[P_RQUOTA] = (unsigned short)atoi(key_value); #endif } else if(!strcasecmp(key_name, "NFS_Program")) { pparam->program[P_NFS] = atoi(key_value); } else if(!strcasecmp(key_name, "MNT_Program")) { pparam->program[P_MNT] = atoi(key_value); } else if(!strcasecmp(key_name, "NLM_Program")) { #ifdef _USE_NLM pparam->program[P_NLM] = atoi(key_value); #endif } else if(!strcasecmp(key_name, "Rquota_Program")) { #ifdef _USE_QUOTA pparam->program[P_RQUOTA] = atoi(key_value); #endif } else if(!strcasecmp(key_name, "NFS_Protocols")) { # define MAX_NFSPROTO 10 /* large enough !!! */ # define MAX_NFSPROTO_LEN 256 /* so is it !!! */ char *nfsvers_list[MAX_NFSPROTO]; int idx, count; /* reset nfs versions flags (clean defaults) */ pparam->core_options &= ~(CORE_OPTION_ALL_VERS); /* allocate nfs vers strings */ for(idx = 0; idx < MAX_NFSPROTO; idx++) nfsvers_list[idx] = (char *)Mem_Alloc(MAX_NFSPROTO_LEN); /* * Search for coma-separated list of nfsprotos */ count = nfs_ParseConfLine(nfsvers_list, MAX_NFSPROTO, key_value, find_comma, find_endLine); if(count < 0) { LogCrit(COMPONENT_CONFIG, "NFS_Protocols list too long (>%d)", MAX_NFSPROTO); /* free sec strings */ for(idx = 0; idx < MAX_NFSPROTO; idx++) Mem_Free((caddr_t) nfsvers_list[idx]); return -1; } /* add each Nfs protocol flag to the option field. */ for(idx = 0; idx < count; idx++) { if(!strcmp(nfsvers_list[idx], "4")) { pparam->core_options |= CORE_OPTION_NFSV4; } /* only NFSv4 is supported for the FSAL_PROXY */ #if ! defined( _USE_PROXY ) || defined ( _HANDLE_MAPPING ) else if(!strcmp(nfsvers_list[idx], "2")) { pparam->core_options |= CORE_OPTION_NFSV2; } else if(!strcmp(nfsvers_list[idx], "3")) { pparam->core_options |= CORE_OPTION_NFSV3; } #endif /* _USE_PROXY */ else { LogCrit(COMPONENT_CONFIG, "Invalid NFS Protocol \"%s\". Values can be: 2, 3, 4.", nfsvers_list[idx]); return -1; } } /* free sec strings */ for(idx = 0; idx < MAX_NFSPROTO; idx++) Mem_Free((caddr_t) nfsvers_list[idx]); /* check that at least one nfs protocol has been specified */ if((pparam->core_options & (CORE_OPTION_ALL_VERS)) == 0) { LogCrit(COMPONENT_CONFIG, "Empty NFS_Protocols list"); return -1; } } else if(!strcasecmp(key_name, "Bind_Addr")) { int rc; memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr)); rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr); if(rc <= 0) { /* Revert to INADDR_ANY in case of any error */ pparam->bind_addr.sin_addr.s_addr = INADDR_ANY; /* All the interfaces on the machine are used */ } } else if(!strcasecmp(key_name, "Core_Dump_Size")) { pparam->core_dump_size = atol(key_value); } else if(!strcasecmp(key_name, "Nb_Max_Fd")) { pparam->nb_max_fd = atoi(key_value); } else if(!strcasecmp(key_name, "Stats_File_Path")) { strncpy(pparam->stats_file_path, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "Stats_Update_Delay")) { pparam->stats_update_delay = atoi(key_value); } else if(!strcasecmp(key_name, "Long_Processing_Threshold")) { pparam->long_processing_threshold = atoi(key_value); } else if(!strcasecmp( key_name, "TCP_Fridge_Expiration_Delay" ) ) { pparam->tcp_fridge_expiration_delay = atoi(key_value); } else if(!strcasecmp(key_name, "Dump_Stats_Per_Client")) { pparam->dump_stats_per_client = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Stats_Per_Client_Directory")) { strncpy(pparam->stats_per_client_directory, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "FSAL_Shared_Library")) { strncpy(pparam->fsal_shared_library, key_value, MAXPATHLEN); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_NFS_CORE); return -1; } } return 0; } /* nfs_read_core_conf */
/** * * nfs_read_krb5_conf: read the configuration for krb5 stuff * * Read the configuration for krb5 stuff. * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return 0 if ok, -1 if failed,1 is stanza is not there * */ int nfs_read_krb5_conf(config_file_t in_config, nfs_krb5_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return -1; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_KRB5)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_NFS_KRB5); return 1; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogDebug(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_NFS_KRB5); return 1; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_NFS_KRB5); return -1; } if(!strcasecmp(key_name, "PrincipalName")) { strncpy(pparam->principal, key_value, sizeof(pparam->principal)); } else if(!strcasecmp(key_name, "KeytabPath")) { strncpy(pparam->keytab, key_value, sizeof(pparam->keytab)); } else if(!strcasecmp(key_name, "Active_krb5")) { pparam->active_krb5 = StrToBoolean(key_value); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_NFS_KRB5); return -1; } } return 0; } /* nfs_read_krb5_conf */
/** * * nfs_read_version4_conf: read the configuration for NFSv4 stuff * * Read the configuration for NFSv4 stuff. * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return 0 if ok, -1 if failed,1 is stanza is not there * */ int nfs_read_version4_conf(config_file_t in_config, nfs_version4_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return -1; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_VERSION4)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_NFS_VERSION4); return 1; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogDebug(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_NFS_VERSION4); return 1; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_NFS_VERSION4); return -1; } if(!strcasecmp(key_name, "Lease_Lifetime")) { pparam->lease_lifetime = atoi(key_value); } else if(!strcasecmp(key_name, "DomainName")) { strncpy(pparam->domainname, key_value, MAXNAMLEN); } else if(!strcasecmp(key_name, "IdmapConf")) { strncpy(pparam->idmapconf, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "FH_Expire")) { pparam->fh_expire = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Returns_ERR_FH_EXPIRED")) { pparam->returns_err_fh_expired = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Use_OPEN_CONFIRM")) { pparam->use_open_confirm = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Return_Bad_Stateid")) { pparam->return_bad_stateid = StrToBoolean(key_value); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_NFS_VERSION4); return -1; } } return 0; } /* nfs_read_version4_conf */
static int nfs_read_conf_pnfs_ds_conf(config_item_t subblock, pnfs_ds_parameter_t * pds_conf) { unsigned int nb_subitem = config_GetNbItems(subblock); unsigned int i; int err; int var_index; struct hostent *hp = NULL; for(i = 0; i < nb_subitem; i++) { char *key_name; char *key_value; config_item_t item; item = config_GetItemByIndex(subblock, i); /* Here, we are managing a configuration sub block, it has nothing but CONFIG_ITEM_VAR in it */ if(config_ItemType(item) != CONFIG_ITEM_VAR) { LogCrit(COMPONENT_CONFIG, "No sub-block expected \n"); return -EINVAL; } /* recuperation du couple clef-valeur */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.\n", var_index, CONF_LABEL_NFS_WORKER); return CACHE_INODE_INVALID_ARGUMENT; } else if(!strcasecmp(key_name, "DS_Addr")) { if(isdigit(key_value[0])) { /* Address begin with a digit, it is a address in the dotted form, translate it */ pds_conf->ipaddr = inet_addr(key_value); /* Keep this address in the ascii format as well (for GETDEVICEINFO) */ strncpy(pds_conf->ipaddr_ascii, key_value, MAXNAMLEN); } else { /* This is a serveur name that is to be resolved. Use gethostbyname */ if((hp = gethostbyname(key_value)) == NULL) { LogCrit(COMPONENT_CONFIG, "PNFS LOAD PARAMETER: ERROR: Unexpected value for %s", key_name); return -1; } memcpy(&pds_conf->ipaddr, (char *)hp->h_addr, hp->h_length); snprintf(pds_conf->ipaddr_ascii, MAXNAMLEN, "%u.%u.%u.%u", ((unsigned int)ntohl(pds_conf->ipaddr) & 0xFF000000) >> 24, ((unsigned int)ntohl(pds_conf->ipaddr) & 0x00FF0000) >> 16, ((unsigned int)ntohl(pds_conf->ipaddr) & 0x0000FF00) >> 8, (unsigned int)ntohl(pds_conf->ipaddr) & 0x000000FF); } } else if(!strcasecmp(key_name, "DS_Ip_Port")) { pds_conf->ipport = htons((unsigned short)atoi(key_value)); } else if(!strcasecmp(key_name, "DS_ProgNum")) { pds_conf->prognum = atoi(key_value); } else if(!strcasecmp(key_name, "DS_Root_Path")) { strncpy(pds_conf->rootpath, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "DS_Id")) { pds_conf->id = atoi(key_value); } else if(!strcasecmp(key_name, "DS_Is_Ganesha")) { pds_conf->is_ganesha = StrToBoolean(key_value); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)\n", key_name, CONF_LABEL_PNFS); return -1; } } /* for */
/* * * cache_content_read_conf_client_parameter: read the configuration for a client to File Content layer. * * Reads the configuration for a client to File Content layer (typically a worker thread). * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return CACHE_CONTENT_SUCCESS if ok, CACHE_CONTENT_INVALID_ARGUMENT otherwise. * */ cache_content_status_t cache_content_read_conf_client_parameter(config_file_t in_config, cache_content_client_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; int DebugLevel = -1; char *LogFile = NULL; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return CACHE_CONTENT_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_CACHE_CONTENT_CLIENT)) == NULL) { /* fprintf(stderr, "Cannot read item \"%s\" from configuration file\n", CONF_LABEL_CACHE_CONTENT_CLIENT ) ; */ return CACHE_CONTENT_NOT_FOUND; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ return CACHE_CONTENT_INVALID_ARGUMENT; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { fprintf(stderr, "Error reading key[%d] from section \"%s\" of configuration file.\n", var_index, CONF_LABEL_CACHE_CONTENT_CLIENT); return CACHE_CONTENT_INVALID_ARGUMENT; } if(!strcasecmp(key_name, "LRU_Prealloc_PoolSize")) /** @todo: BUGAZOMEU: to be removed */ { //pparam->lru_param.nb_entry_prealloc = atoi( key_value ) ; } else if(!strcasecmp(key_name, "LRU_Nb_Call_Gc_invalid")) /** @todo: BUGAZOMEU: to be removed */ { //pparam->lru_param.nb_call_gc_invalid = atoi( key_value ) ; } else if(!strcasecmp(key_name, "Entry_Prealloc_PoolSize")) /** @todo: BUGAZOMEU: to be removed */ { pparam->nb_prealloc_entry = atoi(key_value); } else if(!strcasecmp(key_name, "Cache_Directory")) { strcpy(pparam->cache_dir, key_value); } else if(!strcasecmp(key_name, "Refresh_FSAL_Force")) { pparam->flush_force_fsal = atoi(key_value); } else if(!strcasecmp(key_name, "DebugLevel")) { DebugLevel = ReturnLevelAscii(key_value); if(DebugLevel == -1) { LogCrit(COMPONENT_CACHE_CONTENT, "cache_content_read_conf: ERROR: Invalid debug level name: \"%s\".", key_value); return CACHE_CONTENT_INVALID_ARGUMENT; } } else if(!strcasecmp(key_name, "LogFile")) { LogFile = key_value; } else if(!strcasecmp(key_name, "Max_Fd")) { pparam->max_fd = atoi(key_value); } else if(!strcasecmp(key_name, "OpenFile_Retention")) { pparam->retention = atoi(key_value); } else if(!strcasecmp(key_name, "Use_OpenClose_cache")) { pparam->use_fd_cache = StrToBoolean(key_value); } else { fprintf(stderr, "Unknown or unsettable key: %s (item %s)\n", key_name, CONF_LABEL_CACHE_CONTENT_CLIENT); return CACHE_CONTENT_INVALID_ARGUMENT; } } fcc_debug_level = DebugLevel; if(LogFile) { LogEvent(COMPONENT_INIT, "Setting log file of emergency cache flush thread to %s", LogFile); strncpy(fcc_log_path, LogFile, MAXPATHLEN); } else { LogDebug(COMPONENT_INIT, "No log file set for emergency cache flush thread in configuration. Setting to default.") ; strncpy(fcc_log_path, "/dev/null", MAXPATHLEN); } /* init logging */ if(LogFile) SetComponentLogFile(COMPONENT_CACHE_CONTENT, LogFile); if(DebugLevel > -1) SetComponentLogLevel(COMPONENT_CACHE_CONTENT, DebugLevel); return CACHE_CONTENT_SUCCESS; } /* cache_content_read_conf_client_parameter */
/** * * nfs_read_core_conf: read the configuration ite; for the worker theads. * * Reads the configuration ite; for the worker theads. * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return 0 if ok, -1 if failed, 1 is stanza is not there. * */ int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return CACHE_INODE_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL) { /* LogCrit(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file\n", CONF_LABEL_NFS_CORE ) ; */ return 1; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ return 1; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.\n", var_index, CONF_LABEL_NFS_CORE); return CACHE_INODE_INVALID_ARGUMENT; } if(!strcasecmp(key_name, "Nb_Worker")) { pparam->nb_worker = atoi(key_value); } else if(!strcasecmp(key_name, "Nb_MaxConcurrentGC")) { pparam->nb_max_concurrent_gc = atoi(key_value); } else if(!strcasecmp(key_name, "DupReq_Expiration")) { pparam->expiration_dupreq = atoi(key_value); } else if(!strcasecmp(key_name, "Use_NFS_Commit")) { pparam->use_nfs_commit = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "NFS_Port")) { pparam->nfs_port = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "Drop_IO_Errors")) { pparam->drop_io_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Drop_Inval_Errors")) { pparam->drop_inval_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "MNT_Port")) { pparam->mnt_port = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "NFS_Program")) { pparam->nfs_program = atoi(key_value); } else if(!strcasecmp(key_name, "MNT_Program")) { pparam->mnt_program = atoi(key_value); } else if(!strcasecmp(key_name, "NLM_Program")) { pparam->nlm_program = atoi(key_value); } else if(!strcasecmp(key_name, "Rquota_Program")) { pparam->rquota_program = atoi(key_value); } else if(!strcasecmp(key_name, "Rquota_Port")) { pparam->rquota_port = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "Bind_Addr")) { int rc; memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr)); rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr); if(rc <= 0) { /* Revert to INADDR_ANY in case of any error */ pparam->bind_addr.sin_addr.s_addr = INADDR_ANY; /* All the interfaces on the machine are used */ } } else if(!strcasecmp(key_name, "Core_Dump_Size")) { pparam->core_dump_size = atol(key_value); } else if(!strcasecmp(key_name, "Nb_Max_Fd")) { pparam->nb_max_fd = atoi(key_value); } else if(!strcasecmp(key_name, "Stats_File_Path")) { strncpy(pparam->stats_file_path, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "Stats_Update_Delay")) { pparam->stats_update_delay = atoi(key_value); } else if(!strcasecmp(key_name, "Dump_Stats_Per_Client")) { pparam->dump_stats_per_client = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Stats_Per_Client_Directory")) { strncpy(pparam->stats_per_client_directory, key_value, MAXPATHLEN); } else if(!strcasecmp(key_name, "FSAL_Shared_Library")) { strncpy(pparam->fsal_shared_library, key_value, MAXPATHLEN); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)\n", key_name, CONF_LABEL_NFS_CORE); return -1; } } return 0; } /* nfs_read_core_conf */
/** * * nfs_read_core_conf: read the configuration ite; for the worker theads. * * Reads the configuration ite; for the worker theads. * * @param in_config [IN] configuration file handle * @param pparam [OUT] read parameters * * @return 0 if ok, -1 if failed, 1 is stanza is not there. * */ int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(in_config == NULL || pparam == NULL) return CACHE_INODE_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_NFS_CORE); return 1; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogDebug(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_NFS_CORE); return 1; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_NFS_CORE); return CACHE_INODE_INVALID_ARGUMENT; } if(!strcasecmp(key_name, "Nb_Worker")) { pparam->nb_worker = atoi(key_value); } else if(!strcasecmp(key_name, "Nb_Call_Before_Queue_Avg")) { pparam->nb_call_before_queue_avg = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_Disabled")) { pparam->drc.disabled = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Npart")) { pparam->drc.tcp.npart = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Size")) { pparam->drc.tcp.size = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Cachesz")) { pparam->drc.tcp.cachesz = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Hiwat")) { pparam->drc.tcp.hiwat = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Recycle_Npart")) { pparam->drc.tcp.recycle_npart = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Recycle_Expire_S")) { pparam->drc.tcp.recycle_expire_s = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_TCP_Checksum")) { pparam->drc.tcp.checksum = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "DRC_UDP_Npart")) { pparam->drc.udp.npart = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_UDP_Size")) { pparam->drc.udp.size = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_UDP_Cachesz")) { pparam->drc.udp.cachesz = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_UDP_Hiwat")) { pparam->drc.udp.hiwat = atoi(key_value); } else if(!strcasecmp(key_name, "DRC_UDP_Checksum")) { pparam->drc.udp.checksum = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "DupReq_Expiration")) { pparam->expiration_dupreq = atoi(key_value); } else if(!strcasecmp(key_name, "Dispatch_Max_Reqs")) { pparam->dispatch_max_reqs = atoi(key_value); } else if(!strcasecmp(key_name, "Dispatch_Max_Reqs_Xprt")) { pparam->dispatch_max_reqs_xprt = atoi(key_value); } else if(!strcasecmp(key_name, "Drop_IO_Errors")) { pparam->drop_io_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Drop_Inval_Errors")) { pparam->drop_inval_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Drop_Delay_Errors")) { pparam->drop_delay_errors = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "NFS_Port")) { pparam->port[P_NFS] = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "MNT_Port")) { pparam->port[P_MNT] = (unsigned short)atoi(key_value); } else if(!strcasecmp(key_name, "NLM_Port")) { #ifdef _USE_NLM pparam->port[P_NLM] = (unsigned short)atoi(key_value); #endif } else if(!strcasecmp(key_name, "Rquota_Port")) { #ifdef _USE_RQUOTA pparam->port[P_RQUOTA] = (unsigned short)atoi(key_value); #endif } else if(!strcasecmp(key_name, "NFS_Program")) { pparam->program[P_NFS] = atoi(key_value); } else if(!strcasecmp(key_name, "MNT_Program")) { pparam->program[P_MNT] = atoi(key_value); } else if(!strcasecmp(key_name, "NLM_Program")) { #ifdef _USE_NLM pparam->program[P_NLM] = atoi(key_value); #endif } else if(!strcasecmp(key_name, "Rquota_Program")) { #ifdef _USE_RQUOTA pparam->program[P_RQUOTA] = atoi(key_value); #endif } else if(!strcasecmp(key_name, "NFS_Protocols")) { # define MAX_NFSPROTO 10 /* large enough !!! */ char *nfsvers_list[MAX_NFSPROTO]; int idx, count; /* reset nfs versions flags (clean defaults) */ pparam->core_options &= ~(CORE_OPTION_ALL_VERS); /* fill nfs vers list with NULL pointers */ memset(nfsvers_list, 0, sizeof(nfsvers_list)); /* * Search for coma-separated list of nfsprotos */ count = nfs_ParseConfLine(nfsvers_list, MAX_NFSPROTO, 0, key_value, ','); if(count < 0) { LogCrit(COMPONENT_CONFIG, "NFS_Protocols list too long (>%d)", MAX_NFSPROTO); return -1; } /* add each Nfs protocol flag to the option field. */ for(idx = 0; idx < count; idx++) { if(!strcmp(nfsvers_list[idx], "4")) { pparam->core_options |= CORE_OPTION_NFSV4; } else if(!strcmp(nfsvers_list[idx], "2")) { pparam->core_options |= CORE_OPTION_NFSV2; } else if(!strcmp(nfsvers_list[idx], "3")) { pparam->core_options |= CORE_OPTION_NFSV3; } else { LogCrit(COMPONENT_CONFIG, "Invalid NFS Protocol \"%s\". Values can be: 2, 3, 4.", nfsvers_list[idx]); return -1; } } /* check that at least one nfs protocol has been specified */ if((pparam->core_options & (CORE_OPTION_ALL_VERS)) == 0) { LogCrit(COMPONENT_CONFIG, "Empty NFS_Protocols list"); return -1; } } else if(!strcasecmp(key_name, "Bind_Addr")) { int rc; memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr)); rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr); if(rc <= 0) { /* Revert to INADDR_ANY in case of any error */ pparam->bind_addr.sin_addr.s_addr = INADDR_ANY; /* All the interfaces on the machine are used */ } } else if(!strcasecmp(key_name, "Core_Dump_Size")) { pparam->core_dump_size = atol(key_value); } else if(!strcasecmp(key_name, "Nb_Max_Fd")) { pparam->nb_max_fd = atoi(key_value); } else if(!strcasecmp(key_name, "Stats_File_Path")) { if(strmaxcpy(pparam->stats_file_path, key_value, sizeof(pparam->stats_file_path)) == -1) { LogCrit(COMPONENT_CONFIG, "%s=\"%s\" too long", key_name, key_value); } } else if(!strcasecmp(key_name, "Stats_Update_Delay")) { pparam->stats_update_delay = atoi(key_value); } else if(!strcasecmp(key_name, "Long_Processing_Threshold")) { pparam->long_processing_threshold = atoi(key_value); pparam->long_processing_threshold_msec = pparam->long_processing_threshold * MSEC_PER_SEC; } else if(!strcasecmp( key_name, "Decoder_Fridge_Expiration_Delay" ) ) { pparam->decoder_fridge_expiration_delay = atoi(key_value); } else if(!strcasecmp(key_name, "Dump_Stats_Per_Client")) { pparam->dump_stats_per_client = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Stats_Per_Client_Directory")) { if(strmaxcpy(pparam->stats_per_client_directory, key_value, sizeof(pparam->stats_per_client_directory)) == -1) { LogCrit(COMPONENT_CONFIG, "%s=\"%s\" too long", key_name, key_value); } } else if(!strcasecmp( key_name, "MaxRPCSendBufferSize" ) ) { pparam->max_send_buffer_size = atoi(key_value); } else if(!strcasecmp( key_name, "MaxRPCRecvBufferSize" ) ) { pparam->max_recv_buffer_size = atoi(key_value); } #ifdef _USE_NLM else if(!strcasecmp( key_name, "NSM_Use_Caller_Name" ) ) { pparam->nsm_use_caller_name = StrToBoolean(key_value); } #endif else if(!strcasecmp(key_name, "Clustered")) { pparam->clustered = StrToBoolean(key_value); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_NFS_CORE); return -1; } } return 0; } /* nfs_read_core_conf */
/** * * @brief Read the garbage collection policy * * This function reads the garbage collection policy from the * configuration file. * * @param[in] config Configuration file handle * @param[out] param Read parameters * * @retval CACHE_INODE_SUCCESS on success. * @retval CACHE_INODE_NOT_FOUND if stanza is not present. * @retval CACHE_INODE_INVALID_ARGUMENT otherwise. * */ cache_inode_status_t cache_inode_read_conf_gc_policy(config_file_t config, cache_inode_gc_policy_t *policy) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; /* Is the config tree initialized ? */ if(config == NULL || policy == NULL) return CACHE_INODE_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(config, CONF_LABEL_CACHE_INODE_GCPOL)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_CACHE_INODE_GCPOL); return CACHE_INODE_NOT_FOUND; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogCrit(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_CACHE_INODE_GCPOL); return CACHE_INODE_INVALID_ARGUMENT; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_CACHE_INODE_GCPOL); return CACHE_INODE_INVALID_ARGUMENT; } else if(!strcasecmp(key_name, "Entries_HWMark")) { policy->entries_hwmark = atoi(key_value); } else if(!strcasecmp(key_name, "Entries_LWMark")) { policy->entries_lwmark = atoi(key_value); } else if(!strcasecmp(key_name, "Cache_FDs")) { policy->use_fd_cache = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "LRU_Run_Interval")) { policy->lru_run_interval = atoi(key_value); } else if(!strcasecmp(key_name, "FD_Limit_Percent")) { policy->fd_limit_percent = atoi(key_value); } else if(!strcasecmp(key_name, "FD_HWMark_Percent")) { policy->fd_hwmark_percent = atoi(key_value); } else if(!strcasecmp(key_name, "FD_LWMark_Percent")) { policy->fd_lwmark_percent = atoi(key_value); } else if(!strcasecmp(key_name, "Reaper_Work")) { policy->reaper_work = atoi(key_value); } else if(!strcasecmp(key_name, "Biggest_Window")) { policy->biggest_window = atoi(key_value); } else if(!strcasecmp(key_name, "Required_Progress")) { policy->required_progress = atoi(key_value); } else if(!strcasecmp(key_name, "Futility_Count")) { policy->futility_count = atoi(key_value); } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_CACHE_INODE_GCPOL); return CACHE_INODE_INVALID_ARGUMENT; } } return CACHE_INODE_SUCCESS; } /* cache_inode_read_conf_gc_policy */
/** * @brief Read the configuration for the Cache inode layer * * @param[in] config Configuration file handle * @param[out] param Read parameters * * @retval CACHE_INODE_SUCCESS on success. * @retval CACHE_INODE_NOT_FOUND if stanza not present * @retval CACHE_INODE_INVALID_ARGUMENT otherwise */ cache_inode_status_t cache_inode_read_conf_parameter(config_file_t config, cache_inode_parameter_t *param) { int var_max; int var_index; int err; char *key_name; char *key_value; config_item_t block; int DebugLevel = -1; char *LogFile = NULL; /* Is the config tree initialized ? */ if(config == NULL || param == NULL) return CACHE_INODE_INVALID_ARGUMENT; /* Get the config BLOCK */ if((block = config_FindItemByName(config, CONF_LABEL_CACHE_INODE)) == NULL) { LogDebug(COMPONENT_CONFIG, "Cannot read item \"%s\" from configuration file", CONF_LABEL_CACHE_INODE); return CACHE_INODE_NOT_FOUND; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { /* Expected to be a block */ LogCrit(COMPONENT_CONFIG, "Item \"%s\" is expected to be a block", CONF_LABEL_CACHE_INODE); return CACHE_INODE_INVALID_ARGUMENT; } var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { config_item_t item; item = config_GetItemByIndex(block, var_index); /* Get key's name */ if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0) { LogCrit(COMPONENT_CONFIG, "Error reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_CACHE_INODE); return CACHE_INODE_INVALID_ARGUMENT; } else if(!strcasecmp(key_name, "Attr_Expiration_Time")) { err = parse_cache_expire(¶m->expire_type_attr, ¶m->grace_period_attr, key_value); if(err != CACHE_INODE_SUCCESS) return err; } else if(!strcasecmp(key_name, "Symlink_Expiration_Time")) { err = parse_cache_expire(¶m->expire_type_link, ¶m->grace_period_link, key_value); if(err != CACHE_INODE_SUCCESS) return err; } else if(!strcasecmp(key_name, "Directory_Expiration_Time")) { err = parse_cache_expire(¶m->expire_type_dirent, ¶m->grace_period_dirent, key_value); if(err != CACHE_INODE_SUCCESS) return err; } else if(!strcasecmp(key_name, "Use_Getattr_Directory_Invalidation")) { param->getattr_dir_invalidation = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "Use_Test_Access")) { param->use_test_access = atoi(key_value); } else if(!strcasecmp( key_name, "Use_FSAL_Hash" ) ) { param->use_fsal_hash = StrToBoolean(key_value); } else if(!strcasecmp(key_name, "DebugLevel")) { DebugLevel = ReturnLevelAscii(key_value); if(DebugLevel == -1) { LogDebug(COMPONENT_CACHE_INODE, "cache_inode_read_conf: ERROR: Invalid debug level name: \"%s\".", key_value); return CACHE_INODE_INVALID_ARGUMENT; } } else if(!strcasecmp(key_name, "LogFile")) { LogFile = key_value; } else { LogCrit(COMPONENT_CONFIG, "Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_CACHE_INODE); return CACHE_INODE_INVALID_ARGUMENT; } } /* init logging */ if(LogFile) SetComponentLogFile(COMPONENT_CACHE_INODE, LogFile); if(DebugLevel > -1) SetComponentLogLevel(COMPONENT_CACHE_INODE, DebugLevel); return CACHE_INODE_SUCCESS; } /* cache_inode_read_conf_parameter */
int get_snmpadm_conf(config_file_t in_config, external_tools_parameter_t * out_parameter) { int err; int var_max, var_index; char *key_name; char *key_value; config_item_t block; config_item_t item; /* Get the config BLOCK */ if((block = config_FindItemByName(in_config, CONF_SNMP_ADM_LABEL)) == NULL) { /* cannot read item */ LogCrit(COMPONENT_CONFIG, "SNMP_ADM: Cannot read item \"%s\" from configuration file", CONF_SNMP_ADM_LABEL); /* Expected to be a block */ return ENOENT; } else if(config_ItemType(block) != CONFIG_ITEM_BLOCK) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: Cannot read item \"%s\" from configuration file", CONF_SNMP_ADM_LABEL); /* Expected to be a block */ return ENOENT; } /* makes an iteration on the (key, value) couplets */ var_max = config_GetNbItems(block); for(var_index = 0; var_index < var_max; var_index++) { /* retrieve key's name */ item = config_GetItemByIndex(block, var_index); err = config_GetKeyValue(item, &key_name, &key_value); if(err) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR reading key[%d] from section \"%s\" of configuration file.", var_index, CONF_LABEL_FS_SPECIFIC); return err; } /* what parameter is it ? */ if(!STRCMP(key_name, "Snmp_Agentx_Socket")) { if(strmaxcpy(out_parameter->snmp_adm.snmp_agentx_socket, key_value, sizeof(out_parameter->snmp_adm.snmp_agentx_socket)) == -1) LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: value \"%s\" for %s is too long", key_name, key_value); } else if(!STRCMP(key_name, "Product_Id")) { out_parameter->snmp_adm.product_id = atoi(key_value); } else if(!STRCMP(key_name, "Snmp_adm_log")) { if(strmaxcpy(out_parameter->snmp_adm.snmp_log_file, key_value, sizeof(out_parameter->snmp_adm.snmp_log_file)) == -1) LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: value \"%s\" for %s is too long", key_name, key_value); } else if(!STRCMP(key_name, "Export_cache_stats")) { int nbool = StrToBoolean(key_value); if(nbool == -1) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: Unexpected value for %s: boolean expected.", key_name); return EINVAL; } out_parameter->snmp_adm.export_cache_stats = nbool; } else if(!STRCMP(key_name, "Export_requests_stats")) { int nbool = StrToBoolean(key_value); if(nbool == -1) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: Unexpected value for %s: boolean expected.", key_name); return EINVAL; } out_parameter->snmp_adm.export_requests_stats = nbool; } else if(!STRCMP(key_name, "Export_maps_stats")) { int nbool = StrToBoolean(key_value); if(nbool == -1) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: Unexpected value for %s: boolean expected.", key_name); return EINVAL; } out_parameter->snmp_adm.export_maps_stats = nbool; } else if(!STRCMP(key_name, "Export_nfs_calls_detail")) { int nbool = StrToBoolean(key_value); if(nbool == -1) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: Unexpected value for %s: boolean expected.", key_name); return EINVAL; } out_parameter->snmp_adm.export_nfs_calls_detail = nbool; } else if(!STRCMP(key_name, "Export_FSAL_calls_detail")) { int nbool = StrToBoolean(key_value); if(nbool == -1) { LogCrit(COMPONENT_CONFIG, "SNMP_ADM: ERROR: Unexpected value for %s: boolean expected.", key_name); return EINVAL; } out_parameter->snmp_adm.export_fsal_calls_detail = nbool; } else { LogCrit(COMPONENT_CONFIG, "SNMP_ADM LOAD PARAMETER: ERROR: Unknown or unsettable key: %s (item %s)", key_name, CONF_LABEL_FS_SPECIFIC); return EINVAL; } } config_ok = 1; return 0; }