nfs-ganesha 1.4

LRU_List.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
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
00022  * 02110-1301 USA
00023  *
00024  * ---------------------------------------
00025  */
00026 
00039 #ifndef _LRU_LIST_H
00040 #define _LRU_LIST_H
00041 
00042 #include <unistd.h>
00043 #include <sys/types.h>
00044 #include <sys/param.h>
00045 #include <pthread.h>
00046 #include "abstract_mem.h"
00047 
00048 typedef enum LRU_List_state__
00049 { LRU_ENTRY_BLANK = 0,
00050   LRU_ENTRY_VALID = 1,
00051   LRU_ENTRY_INVALID = 2
00052 } LRU_List_state_t;
00053 
00054 typedef struct LRU_data__
00055 {
00056   caddr_t pdata;
00057   size_t len;
00058 } LRU_data_t;
00059 
00060 typedef struct lru_entry__
00061 {
00062   struct lru_entry__ *next;
00063   struct lru_entry__ *prev;
00064   LRU_List_state_t valid_state;
00065   LRU_data_t buffdata;
00066 } LRU_entry_t;
00067 
00068 typedef struct lru_param__
00069 {
00070   unsigned int nb_entry_prealloc;                  
00071   unsigned int nb_call_gc_invalid;                 
00072   int (*entry_to_str) (LRU_data_t, char *);        
00073   int (*clean_entry) (LRU_entry_t *, void *);      
00074   char *lp_name;                                      
00075 } LRU_parameter_t;
00076 
00077 typedef struct lru_list__
00078 {
00079   LRU_entry_t *LRU;
00080   LRU_entry_t *MRU;
00081   unsigned int nb_entry;
00082   unsigned int nb_invalid;
00083   unsigned int nb_call_gc;
00084   LRU_parameter_t parameter;
00085   pool_t *lru_entry_pool;
00086 } LRU_list_t;
00087 
00088 typedef int LRU_status_t;
00089 
00090 LRU_entry_t *LRU_new_entry(LRU_list_t * plru, LRU_status_t * pstatus);
00091 int LRU_pop_entry (LRU_list_t * plru, LRU_entry_t  *out_entry);
00092 LRU_list_t *LRU_Init(LRU_parameter_t lru_param, LRU_status_t * pstatus);
00093 int LRU_gc_invalid(LRU_list_t * plru, void *cleanparam);
00094 int LRU_invalidate(LRU_list_t * plru, LRU_entry_t * pentry);
00095 int LRU_invalidate_by_function(LRU_list_t * plru,
00096                                int (*testfunc) (LRU_entry_t *, void *addparam),
00097                                void *addparam);
00098 int LRU_apply_function(LRU_list_t * plru, int (*myfunc) (LRU_entry_t *, void *addparam),
00099                        void *addparam);
00100 void LRU_Print(LRU_list_t * plru);
00101 
00102 /* How many character used to display a key or value */
00103 #define LRU_DISPLAY_STRLEN 1024
00104 
00105 /* Possible errors */
00106 #define LRU_LIST_SUCCESS           0
00107 #define LRU_LIST_MALLOC_ERROR      1
00108 #define LRU_LIST_EMPTY_LIST        2
00109 #define LRU_LIST_BAD_RELEASE_ENTRY 3
00110 
00111 #define LRU_LIST_SET_INVALID        0
00112 #define LRU_LIST_DO_NOT_SET_INVALID 1
00113 #endif                          /* _LRU_LIST_H */