nfs-ganesha 1.4

mfsl_async_read_conf.c

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00007  *
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 3 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  * ---------------------------------------
00024  */
00025 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 /* fsal_types contains constants and type definitions for FSAL */
00041 #include "fsal_types.h"
00042 #include "fsal.h"
00043 #include "mfsl_types.h"
00044 #include "mfsl.h"
00045 #include "log.h"
00046 #include "config_parsing.h"
00047 
00048 #include <strings.h>
00049 #include <string.h>
00050 
00051 /******************************************************
00052  *            Attribute mask management.
00053  ******************************************************/
00054 
00067 int mfsl_async_clean_pending_request(LRU_entry_t * pentry, void *addparam)
00068 {
00069   //nfs_request_data_t ** preqnfspool = (nfs_request_data_t **)addparam ;
00070   //nfs_request_data_t *  preqnfs     = (nfs_request_data_t *)(pentry->buffdata.pdata) ;
00071 
00072   /* Send the entry back to the pool */
00073   //pool_free(preqnfspool, preqnfs) ;
00074 
00075   return 0;
00076 }                               /* mfsl_async_clean_pending_request */
00077 
00090 int mfsl_async_print_pending_request(LRU_data_t data, char *str)
00091 {
00092   return snprintf(str, LRU_DISPLAY_STRLEN, "not implemented for now");
00093 }                               /* print_pending_request */
00094 
00102 fsal_status_t MFSL_SetDefault_parameter(mfsl_parameter_t * out_parameter)
00103 {
00104   out_parameter->nb_pre_async_op_desc = 50;
00105   out_parameter->nb_synclet = 1;
00106   out_parameter->async_window_sec = 1;
00107   out_parameter->async_window_usec = 0;
00108   out_parameter->nb_before_gc = 500;
00109   out_parameter->nb_pre_create_dirs = 10;
00110   out_parameter->nb_pre_create_files = 10;
00111   strncpy(out_parameter->pre_create_obj_dir, "/tmp", MAXPATHLEN);
00112   strncpy(out_parameter->tmp_symlink_dir, "/tmp", MAXPATHLEN);
00113 
00114   out_parameter->lru_param.nb_entry_prealloc = 100;
00115   out_parameter->lru_param.nb_call_gc_invalid = 30;
00116   out_parameter->lru_param.clean_entry = mfsl_async_clean_pending_request;
00117   out_parameter->lru_param.entry_to_str = mfsl_async_print_pending_request;
00118 
00119   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00120 }                               /* MFSL_SetDefault_parameter */
00121 
00140 fsal_status_t MFSL_load_parameter_from_conf(config_file_t in_config,
00141                                             mfsl_parameter_t * pparam)
00142 {
00143   int err;
00144   int var_max, var_index;
00145   char *key_name;
00146   char *key_value;
00147   config_item_t block;
00148 
00149   int DebugLevel = -1;
00150   char *LogFile = NULL;
00151 
00152   /* Is the config tree initialized ? */
00153   if(in_config == NULL || pparam == NULL)
00154     MFSL_return(ERR_FSAL_INVAL, 0);
00155 
00156   /* Get the config BLOCK */
00157   if((block = config_FindItemByName(in_config, CONF_LABEL_MFSL_ASYNC)) == NULL)
00158     {
00159       LogMajor(COMPONENT_MFSL, "/!\\ Cannot read item \"%s\" from configuration file\n",
00160                  CONF_LABEL_MFSL_ASYNC);
00161       MFSL_return(ERR_FSAL_NOENT, 0);
00162     }
00163   var_max = config_GetNbItems(block);
00164 
00165   for(var_index = 0; var_index < var_max; var_index++)
00166     {
00167       config_item_t item;
00168 
00169       item = config_GetItemByIndex(block, var_index);
00170 
00171       if((err = config_GetKeyValue(item, &key_name, &key_value)) > 0)
00172         {
00173           LogMajor(COMPONENT_MFSL,
00174               "MFSL ASYNC LOAD PARAMETER: ERROR reading key[%d] from section \"%s\" of configuration file.",
00175                var_index, CONF_LABEL_MFSL_ASYNC);
00176           MFSL_return(ERR_FSAL_SERVERFAULT, err);
00177         }
00178 
00179       if(!strcasecmp(key_name, "Nb_Synclet"))
00180         {
00181           LogCrit(COMPONENT_MFSL,
00182               "MFSL ASYNC LOAD PARAMETER: the asyncop scheduler is not yet implemented. Only one synclet managed");
00183           LogCrit(COMPONENT_MFSL,
00184               "MFSL ASYNC LOAD PARAMETER: Parameter Nb_Synclet = %s will be ignored",
00185                key_value);
00186           //pparam->nb_synclet = atoi( key_value ) ;
00187           pparam->nb_synclet = 1;
00188         }
00189       else if(!strcasecmp(key_name, "Async_Window_sec"))
00190         {
00191           pparam->async_window_sec = atoi(key_value);   /* Asynchronous Task Dispatcher sleeping time */
00192         }
00193       else if(!strcasecmp(key_name, "Async_Window_usec"))
00194         {
00195           pparam->async_window_usec = atoi(key_value);  /* Asynchronous Task Dispatcher sleeping time */
00196         }
00197       else if(!strcasecmp(key_name, "Nb_Sync_Before_GC"))
00198         {
00199           pparam->nb_before_gc = atoi(key_value);
00200         }
00201       else if(!strcasecmp(key_name, "PreCreatedObject_Directory"))
00202         {
00203           strncpy(pparam->pre_create_obj_dir, key_value, MAXPATHLEN);
00204         }
00205       else if(!strcasecmp(key_name, "Tmp_Symlink_Directory"))
00206         {
00207           strncpy(pparam->tmp_symlink_dir, key_value, MAXPATHLEN);
00208         }
00209       else if(!strcasecmp(key_name, "Nb_PreCreated_Directories"))
00210         {
00211           pparam->nb_pre_create_dirs = atoi(key_value);
00212         }
00213       else if(!strcasecmp(key_name, "Nb_PreCreated_Files"))
00214         {
00215           pparam->nb_pre_create_files = atoi(key_value);
00216         }
00217       else if(!strcasecmp(key_name, "LRU_Nb_Call_Gc_invalid"))
00218         {
00219           pparam->lru_param.nb_call_gc_invalid = atoi(key_value);
00220         }
00221       else if(!strcasecmp(key_name, "DebugLevel"))
00222         {
00223           DebugLevel = ReturnLevelAscii(key_value);
00224 
00225           if(DebugLevel == -1)
00226             {
00227               LogMajor(COMPONENT_MFSL,
00228                   "cache_content_read_conf: ERROR: Invalid debug level name: \"%s\".",
00229                    key_value);
00230               MFSL_return(ERR_FSAL_INVAL, 0);
00231             }
00232         }
00233       else if(!strcasecmp(key_name, "LogFile"))
00234         {
00235           LogFile = key_value;
00236         }
00237 
00238       else
00239         {
00240           LogMajor(COMPONENT_MFSL,
00241               "MFSL ASYNC LOAD PARAMETER: Unknown or unsettable key %s from section \"%s\" of configuration file.",
00242                key_name, CONF_LABEL_MFSL_ASYNC);
00243           MFSL_return(ERR_FSAL_INVAL, 0);
00244         }
00245 
00246     }                           /* for */
00247 
00248   if(LogFile)
00249     SetComponentLogFile(COMPONENT_FSAL, LogFile);
00250 
00251   if(DebugLevel != -1)
00252     SetComponentLogLevel(COMPONENT_FSAL, DebugLevel);
00253 
00254   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00255 }                               /* MFSL_load_parameter_from_conf */