nfs-ganesha 1.4

cache_content.h

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 License
00011  * as published by the Free Software Foundation; either version 3 of
00012  * the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * 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
00022  * 02110-1301 USA
00023  *
00024  * ---------------------------------------
00025  */
00026 
00039 #ifndef _CACHE_CONTENT_H
00040 #define _CACHE_CONTENT_H
00041 
00042 #include <unistd.h>
00043 #include <sys/types.h>
00044 #include <sys/param.h>
00045 #include <time.h>
00046 #include <pthread.h>
00047 #include <dirent.h>
00048 #include <sys/stat.h>
00049 #include <unistd.h>
00050 
00051 #include "LRU_List.h"
00052 #include "HashData.h"
00053 #include "HashTable.h"
00054 #include "fsal.h"
00055 #include "cache_inode.h"
00056 
00057 typedef int cache_content_status_t;
00058 
00059 typedef struct cache_content_gc_policy__
00060 {
00061   time_t lifetime;
00062   time_t emergency_grace_delay;
00063   unsigned int run_interval;
00064   unsigned int nb_call_before_gc;
00065   unsigned int hwmark_df;
00066   unsigned int lwmark_df;
00067 } cache_content_gc_policy_t;
00068 
00069 #define CONF_LABEL_CACHE_CONTENT_GCPOL  "FileContent_GC_Policy"
00070 #define CONF_LABEL_CACHE_CONTENT_CLIENT "FileContent_Client"
00071 #define CONF_LABEL_CACHE_CONTENT_PARAM  "FileContent_Param"
00072 
00073 #define CACHE_CONTENT_NEW_ENTRY     0
00074 #define CACHE_CONTENT_RELEASE_ENTRY 1
00075 #define CACHE_CONTENT_READ_ENTRY    2
00076 #define CACHE_CONTENT_WRITE_ENTRY   3
00077 #define CACHE_CONTENT_TRUNCATE      4
00078 #define CACHE_CONTENT_FLUSH         5
00079 #define CACHE_CONTENT_REFRESH       6
00080 
00081 #define CACHE_CONTENT_NB_COMMAND    7
00082 
00083 #define CACHE_CONTENT_FLAGS_READ       0x0000001
00084 #define CACHE_CONTENT_FLAGS_WRITE      0x0000002
00085 #define CACHE_CONTENT_FLAGS_READ_WRITE 0x0000003
00086 
00087 typedef struct cache_content_opened_file__
00088 {
00089   int local_fd;
00090   time_t last_op;
00091 } cache_content_opened_file_t;
00092 
00093 typedef enum cache_content_sync_state__
00094 { JUST_CREATED = 1,
00095   SYNC_OK = 2,
00096   FLUSH_NEEDED = 3,
00097   REFRESH_NEEDED = 4
00098 } cache_content_sync_state_t;
00099 
00100 typedef enum cache_content_entry_valid_state__
00101 { STATE_OK = 1,
00102   TO_BE_GARBAGGED = 2
00103 } cache_content_entry_valid_state_t;
00104 
00105 typedef enum cache_content_flush_behaviour__
00106 { CACHE_CONTENT_FLUSH_AND_DELETE = 1,
00107   CACHE_CONTENT_FLUSH_SYNC_ONLY = 2
00108 } cache_content_flush_behaviour_t;
00109 typedef struct cache_content_client_parameter__
00110 {
00111   unsigned int nb_prealloc_entry;             
00112   char cache_dir[MAXPATHLEN];                 
00113   unsigned int flush_force_fsal;              
00114   unsigned int max_fd;                        
00115   unsigned int use_fd_cache;                  
00116 } cache_content_client_parameter_t;
00117 
00118 #define CACHE_CONTENT_SPEC_DATA_SIZE 400
00119 typedef char cache_content_spec_data_t[CACHE_CONTENT_SPEC_DATA_SIZE];
00120 
00121 typedef struct cache_content_internal_md__
00122 {
00123   time_t read_time;                                       
00124   time_t mod_time;                                        
00125   time_t refresh_time;                                    
00126   time_t alloc_time;                                      
00127   time_t last_flush_time;                                 
00128   time_t last_refresh_time;                               
00129   cache_content_entry_valid_state_t valid_state;          
00130   cache_content_spec_data_t *pspecdata;                   
00132 } cache_content_internal_md_t;
00133 
00134 typedef struct cache_content_local_entry__
00135 {
00136   char cache_path_data[MAXPATHLEN];                                
00137   char cache_path_index[MAXPATHLEN];                               
00138   cache_content_opened_file_t opened_file;                         
00139   cache_content_sync_state_t sync_state;                           
00140 } cache_content_local_entry_t;
00141 
00142 typedef struct cache_content_entry__
00143 {
00144   cache_content_internal_md_t internal_md;              
00145   cache_content_local_entry_t local_fs_entry;           
00146   cache_entry_t *pentry_inode;                          
00147 } cache_content_entry_t;
00148 
00149 typedef struct cache_content_stat__
00150 {
00151   unsigned int nb_gc_lru_active;  
00152   unsigned int nb_gc_lru_total;   
00154   struct func_inode_stats
00155   {
00156     unsigned int nb_call[CACHE_CONTENT_NB_COMMAND];             
00157     unsigned int nb_success[CACHE_CONTENT_NB_COMMAND];          
00158     unsigned int nb_err_retryable[CACHE_CONTENT_NB_COMMAND];    
00159     unsigned int nb_err_unrecover[CACHE_CONTENT_NB_COMMAND];    
00160   } func_stats;
00161 
00162   unsigned int nb_call_total;                                   
00163 } cache_content_stat_t;
00164 
00165 typedef struct cache_content_client__
00166 {
00167   pool_t *content_pool;                             
00168   unsigned int nb_prealloc;                         
00169   cache_content_stat_t stat;                        
00170   char cache_dir[MAXPATHLEN];                       
00171   unsigned int flush_force_fsal;                    
00172   unsigned int max_fd;                              
00173   time_t retention;                                 
00174   unsigned int use_fd_cache;                        
00175   int fd_gc_needed;                                 
00176 } cache_content_client_t;
00177 
00178 typedef enum cache_content_op__
00179 { CACHE_CONTENT_OP_GET = 1,
00180   CACHE_CONTENT_OP_SET = 2,
00181   CACHE_CONTENT_OP_FLUSH = 3
00182 } cache_content_op_t;
00183 
00184 typedef struct cache_content_dirinfo__
00185 {
00186   DIR *level0_dir;
00187   DIR *level1_dir;
00188   DIR *level2_dir;
00189 
00190   unsigned int level1_cnt;
00191 
00192   char level0_path[MAXPATHLEN];
00193   char level1_name[MAXNAMLEN];
00194   char level2_name[MAXNAMLEN];
00195 
00196   struct dirent *cookie0;
00197   struct dirent *cookie1;
00198   struct dirent *cookie2;
00199 
00200   unsigned int level0_opened;
00201   unsigned int level1_opened;
00202   unsigned int level2_opened;
00203 } cache_content_dirinfo_t;
00204 
00205 #define CACHE_CONTENT_DIR_INITIALIZER   NULL
00206 
00207 /*
00208  * Possible errors 
00209  */
00210 #define CACHE_CONTENT_SUCCESS               0
00211 #define CACHE_CONTENT_INVALID_ARGUMENT      1
00212 #define CACHE_CONTENT_UNAPPROPRIATED_KEY    2
00213 #define CACHE_CONTENT_BAD_CACHE_INODE_ENTRY 3
00214 #define CACHE_CONTENT_ENTRY_EXISTS          4
00215 #define CACHE_CONTENT_FSAL_ERROR            5
00216 #define CACHE_CONTENT_LOCAL_CACHE_ERROR     6
00217 #define CACHE_CONTENT_MALLOC_ERROR          7
00218 #define CACHE_CONTENT_LRU_ERROR             8
00219 #define CACHE_CONTENT_NOT_FOUND             9
00220 #define CACHE_CONTENT_LOCAL_CACHE_NOT_FOUND 10
00221 #define CACHE_CONTENT_TOO_LARGE_FOR_CACHE   11
00222 
00223 typedef enum cache_content_nametype__
00224 { CACHE_CONTENT_UNASSIGNED = 1,
00225   CACHE_CONTENT_DATA_FILE = 2,
00226   CACHE_CONTENT_INDEX_FILE = 3,
00227   CACHE_CONTENT_DIR = 4
00228 } cache_content_nametype_t;
00229 
00230 typedef enum cache_content_create_behaviour__
00231 { ADD_ENTRY = 1,
00232   RECOVER_ENTRY = 2,
00233   RENEW_ENTRY
00234 } cache_content_add_behaviour_t;
00235 
00236 typedef enum cache_content_refresh_how__
00237 { KEEP_LOCAL = 1,
00238   FORCE_FROM_FSAL = 2,
00239   DEFAULT_REFRESH
00240 } cache_content_refresh_how_t;
00241 
00242 typedef struct cache_content_flush_thread_data__
00243 {
00244   unsigned int thread_pos;
00245   unsigned int thread_number;
00246 } cache_content_flush_thread_data_t;
00247 
00248 int cache_content_client_init(cache_content_client_t * pclient,
00249                               cache_content_client_parameter_t param,
00250                               char *name);
00251 
00252 cache_content_status_t cache_content_create_name(char *path,
00253                                                  cache_content_nametype_t type,
00254                                                  fsal_op_context_t * pcontext,
00255                                                  cache_entry_t * pentry_inode,
00256                                                  cache_content_client_t * pclient);
00257 
00258 int cache_content_init(cache_content_client_parameter_t param,
00259                        cache_content_status_t * pstatus);
00260 
00261 int cache_content_init_dir(cache_content_client_parameter_t param,
00262                            unsigned short export_id);
00263 
00264 cache_content_entry_t *cache_content_new_entry(cache_entry_t * pentry_inode,
00265                                                cache_content_spec_data_t * pspecdata,
00266                                                cache_content_client_t * pclient,
00267                                                cache_content_add_behaviour_t how,
00268                                                fsal_op_context_t * pcontext,
00269                                                cache_content_status_t * pstatus);
00270 
00271 cache_content_status_t cache_content_release_entry(cache_content_entry_t * pentry,
00272                                                    cache_content_client_t * pclient,
00273                                                    cache_content_status_t * pstatus);
00274 
00275 cache_content_status_t cache_content_open(cache_content_entry_t * pentry,
00276                                           cache_content_client_t * pclient,
00277                                           cache_content_status_t * pstatus);
00278 
00279 cache_content_status_t cache_content_close(cache_content_entry_t * pentry,
00280                                            cache_content_client_t * pclient,
00281                                            cache_content_status_t * pstatus);
00282 
00283 cache_content_status_t cache_content_rdwr(cache_content_entry_t * pentry,
00284                                           cache_inode_io_direction_t read_or_write,
00285                                           uint64_t offset,
00286                                           size_t *pio_size_in,
00287                                           size_t *pio_size_out,
00288                                           void *buffer,
00289                                           fsal_boolean_t * p_fsal_eof,
00290                                           struct stat *pbuffstat,
00291                                           cache_content_client_t * pclient,
00292                                           fsal_op_context_t * pcontext,
00293                                           cache_content_status_t * pstatus);
00294 
00295 #define cache_content_read( a, b, c, d, e, f, g, h, i ) cache_content_rdwr( a, CACHE_CONTENT_READ, b, c, d, e, f, g, h, i )
00296 #define cache_content_write( a, b, c, d, e, f, g, h, i ) cache_content_rdwr( a, CACHE_CONTENT_WRITE, b, c, d, e, f, g, h, i )
00297 
00298 cache_content_status_t cache_content_truncate(cache_content_entry_t * pentry,
00299                                               fsal_size_t length,
00300                                               cache_content_client_t * pclient,
00301                                               cache_content_status_t * pstatus);
00302 
00303 cache_content_status_t cache_content_flush(cache_content_entry_t * pentry,
00304                                            cache_content_flush_behaviour_t flushhow,
00305                                            cache_content_client_t * pclient,
00306                                            fsal_op_context_t * pcontext,
00307                                            cache_content_status_t * pstatus);
00308 
00309 cache_content_status_t cache_content_refresh(cache_content_entry_t * pentry,
00310                                              cache_content_client_t * pclient,
00311                                              fsal_op_context_t * pcontext,
00312                                              cache_content_refresh_how_t how,
00313                                              cache_content_status_t * pstatus);
00314 
00315 cache_content_status_t cache_content_sync_all(cache_content_client_t * pclient,
00316                                               fsal_op_context_t * pcontext,
00317                                               cache_content_status_t * pstatus);
00318 
00319 cache_content_status_t cache_content_read_conf_client_parameter(config_file_t in_config,
00320                                                                 cache_content_client_parameter_t
00321                                                                 * pparam);
00322 
00323 void cache_content_print_conf_client_parameter(FILE * output,
00324                                                cache_content_client_parameter_t param);
00325 
00326 off_t cache_content_fsal_seek_convert(fsal_seek_t seek, cache_content_status_t * pstatus);
00327 size_t cache_content_fsal_size_convert(fsal_size_t size,
00328                                        cache_content_status_t * pstatus);
00329 
00330 cache_content_status_t cache_content_crash_recover(unsigned short exportid,
00331                                                    unsigned int index,
00332                                                    unsigned int mod,
00333                                                    cache_content_client_t * pclient_data,
00334                                                    fsal_op_context_t * pcontext,
00335                                                    cache_content_status_t * pstatus);
00336 
00337 int cache_content_get_export_id(char *dirname);
00338 u_int64_t cache_content_get_inum(char *filename);
00339 int cache_content_get_datapath(char *basepath, u_int64_t inum, char *datapath);
00340 off_t cache_content_recover_size(char *basepath, u_int64_t inum);
00341 
00342 cache_inode_status_t cache_content_error_convert(cache_content_status_t status);
00343 
00344 cache_content_status_t cache_content_read_conf_gc_policy(config_file_t in_config,
00345                                                          cache_content_gc_policy_t *
00346                                                          ppolicy);
00347 
00348 void cache_content_print_conf_gc_policy(FILE * output,
00349                                         cache_content_gc_policy_t gcpolicy);
00350 
00351 void cache_content_set_gc_policy(cache_content_gc_policy_t policy);
00352 
00353 cache_content_gc_policy_t cache_content_get_gc_policy(void);
00354 
00355 cache_content_status_t cache_content_gc(cache_content_client_t * pclient,
00356                                         cache_content_status_t * pstatus);
00357 
00358 cache_content_status_t cache_content_emergency_flush(char *cachedir,
00359                                                      cache_content_flush_behaviour_t
00360                                                      flushhow,
00361                                                      unsigned int lw_mark_trigger_flag,
00362                                                      time_t grace_period,
00363                                                      unsigned int index, unsigned int mod,
00364                                                      unsigned int *p_nb_flushed,
00365                                                      unsigned int *p_nb_too_young,
00366                                                      unsigned int *p_nb_errors,
00367                                                      unsigned int *p_nb_orphans,
00368                                                      fsal_op_context_t * pcontext,
00369                                                      cache_content_status_t * pstatus);
00370 
00371 cache_content_status_t cache_content_check_threshold(char *datacache_path,
00372                                                      unsigned int threshold_min,
00373                                                      unsigned int threshold_max,
00374                                                      int *p_bool_overflow,
00375                                                      unsigned long *p_blocks_to_lwm);
00376 
00377 int cache_content_local_cache_opendir(char *cache_dir,
00378                                       cache_content_dirinfo_t * pdirectory);
00379 
00380 int cache_content_local_cache_dir_iter(cache_content_dirinfo_t * directory,
00381                                        struct dirent *dir_entry,
00382                                        unsigned int index, unsigned int mod);
00383 
00384 void cache_content_local_cache_closedir(cache_content_dirinfo_t * directory);
00385 
00386 int cache_content_invalidate_flushed(LRU_entry_t * plru_entry, void *addparam);
00387 cache_content_status_t cache_content_test_cached(cache_entry_t * pentry_inode,
00388                                                  cache_content_client_t * pclient,
00389                                                  fsal_op_context_t * pcontext,
00390                                                  cache_content_status_t * pstatus);
00391 off_t cache_content_get_cached_size(cache_content_entry_t * pentry);
00392 
00393 #endif                          /* _CACHE_CONTENT_H */