nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2005) 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 #ifdef _SOLARIS 00041 #include "solaris_port.h" 00042 #endif /* _SOLARIS */ 00043 00044 #include "log.h" 00045 #include "err_fsal.h" 00046 #include "err_cache_inode.h" 00047 #include "nfs_core.h" 00048 #include <unistd.h> /* for using gethostname */ 00049 #include <stdlib.h> /* for using exit */ 00050 #include <strings.h> 00051 #include <sys/types.h> 00052 00065 uint32_t cache_inode_fsal_hash_func(hash_parameter_t * p_hparam, 00066 hash_buffer_t * buffclef) 00067 { 00068 unsigned long h = 0; 00069 char printbuf[512]; 00070 fsal_handle_t *pfsal_handle = (fsal_handle_t *) (buffclef->pdata); 00071 00072 h = FSAL_Handle_to_HashIndex(pfsal_handle, 0, 00073 p_hparam->alphabet_length, 00074 p_hparam->index_size); 00075 00076 if(isFullDebug(COMPONENT_HASHTABLE) && isFullDebug(COMPONENT_CACHE_INODE)) 00077 { 00078 snprintHandle(printbuf, 512, pfsal_handle); 00079 LogFullDebug(COMPONENT_CACHE_INODE, 00080 "hash_func key: buff = (Handle=%s, Cookie=%"PRIu64"), hash value=%lu", 00081 printbuf, 0UL, h); 00082 } 00083 00084 return h; 00085 } /* cache_inode_fsal_hash_func */ 00086 00099 uint64_t cache_inode_fsal_rbt_func(hash_parameter_t * p_hparam, 00100 hash_buffer_t * buffclef) 00101 { 00102 /* 00103 * A polynomial function too, but reversed, to avoid 00104 * producing same value as decimal_simple_hash_func 00105 */ 00106 uint32_t h = 0; 00107 char printbuf[512]; 00108 fsal_handle_t *pfsal_handle = (fsal_handle_t *) (buffclef->pdata); 00109 00110 h = Lookup3_hash_buff((char *)pfsal_handle, buffclef->len ); 00111 00112 if(isFullDebug(COMPONENT_HASHTABLE) && isFullDebug(COMPONENT_CACHE_INODE)) 00113 { 00114 snprintHandle(printbuf, 512, pfsal_handle); 00115 LogFullDebug(COMPONENT_CACHE_INODE, 00116 "hash_func rbt: buff = (Handle=%s, Cookie=%"PRIu64"), value=%u", 00117 printbuf, 0UL, h); 00118 } 00119 return h; 00120 } /* cache_inode_fsal_rbt_func */ 00121 00122 unsigned long __cache_inode_fsal_rbt_func(hash_parameter_t * p_hparam, 00123 hash_buffer_t * buffclef) 00124 { 00125 /* 00126 * A polynomial function too, but reversed, to avoid 00127 * producing same value as decimal_simple_hash_func 00128 */ 00129 unsigned long h = 0; 00130 fsal_handle_t *pfsal_handle = (fsal_handle_t *) (buffclef->pdata); 00131 char printbuf[512]; 00132 00133 h = FSAL_Handle_to_RBTIndex(pfsal_handle, 0); 00134 00135 if(isFullDebug(COMPONENT_HASHTABLE) && isFullDebug(COMPONENT_CACHE_INODE)) 00136 { 00137 snprintHandle(printbuf, 512, pfsal_handle); 00138 LogFullDebug(COMPONENT_CACHE_INODE, 00139 "hash_func rbt: buff = (Handle=%s, Cookie=%"PRIu64"), value=%lu", 00140 printbuf, 0UL, h); 00141 } 00142 return h; 00143 } /* cache_inode_fsal_rbt_func */ 00144 00160 static int cache_inode_fsal_rbt_both_on_fsal(hash_parameter_t * p_hparam, 00161 hash_buffer_t * buffclef, 00162 uint32_t * phashval, 00163 uint64_t * prbtval) 00164 { 00165 char printbuf[512]; 00166 unsigned int rc = 0 ; 00167 /* ACE: This is a temporary hack so we don't have to change every FSAL 00168 right now. */ 00169 unsigned int FSALindex = 0; 00170 unsigned int FSALrbt = 0; 00171 00172 fsal_handle_t *pfsal_handle = (fsal_handle_t *) (buffclef->pdata); 00173 00179 rc = FSAL_Handle_to_Hash_both( pfsal_handle, 0, 00180 p_hparam->alphabet_length, p_hparam->index_size, 00181 &FSALindex, &FSALrbt); 00182 00183 *phashval = FSALindex; 00184 *prbtval = FSALrbt; 00185 if( rc == 0 ) 00186 { 00187 snprintHandle(printbuf, 512, pfsal_handle); 00188 LogMajor(COMPONENT_CACHE_INODE, 00189 "Unable to hash (Handle=%s)", 00190 printbuf); 00191 return 0 ; 00192 } 00193 00194 if(isFullDebug(COMPONENT_HASHTABLE) && isFullDebug(COMPONENT_CACHE_INODE)) 00195 { 00196 snprintHandle(printbuf, 512, buffclef->pdata); 00197 LogFullDebug(COMPONENT_CACHE_INODE, 00198 "hash_func rbt both: buff = (Handle=%s, Cookie=%"PRIu64"), hashvalue=%u rbtvalue=%u", 00199 printbuf, 0UL, FSALindex, FSALrbt); 00200 } 00201 00202 /* Success */ 00203 return 1 ; 00204 } /* cache_inode_fsal_rbt_both */ 00205 00206 static int cache_inode_fsal_rbt_both_locally(hash_parameter_t * p_hparam, 00207 hash_buffer_t * buffclef, 00208 uint32_t * phashval, 00209 uint64_t * prbtval) 00210 { 00211 char printbuf[512]; 00212 uint32_t h1 = 0 ; 00213 uint32_t h2 = 0 ; 00214 fsal_handle_t *pfsal_handle = (fsal_handle_t *) (buffclef->pdata); 00215 00216 Lookup3_hash_buff_dual((char *)pfsal_handle, buffclef->len, 00217 &h1, &h2 ); 00218 00219 h1 = h1 % p_hparam->index_size ; 00220 00221 *phashval = h1 ; 00222 *prbtval = h2 ; 00223 00224 if(isFullDebug(COMPONENT_HASHTABLE) && isFullDebug(COMPONENT_CACHE_INODE)) 00225 { 00226 snprintHandle(printbuf, 512, pfsal_handle); 00227 LogFullDebug(COMPONENT_CACHE_INODE, 00228 "hash_func rbt both: buff = (Handle=%s, Cookie=%"PRIu64"), hashvalue=%u rbtvalue=%u", 00229 printbuf, 0UL, h1, h2 ); 00230 } 00231 00232 /* Success */ 00233 return 1 ; 00234 } /* cache_inode_fsal_rbt_both */ 00235 00236 00237 int cache_inode_fsal_rbt_both( hash_parameter_t * p_hparam, 00238 hash_buffer_t * buffclef, 00239 uint32_t * phashval, uint64_t * prbtval ) 00240 { 00241 if(cache_inode_params.use_fsal_hash == FALSE ) 00242 return cache_inode_fsal_rbt_both_locally( p_hparam, buffclef, phashval, prbtval ) ; 00243 else 00244 return cache_inode_fsal_rbt_both_on_fsal( p_hparam, buffclef, phashval, prbtval ) ; 00245 } 00246 00247 00248 00249 int display_key(hash_buffer_t * pbuff, char *str) 00250 { 00251 char buffer[128]; 00252 00253 snprintHandle(buffer, 128, pbuff->pdata); 00254 00255 return snprintf(str, HASHTABLE_DISPLAY_STRLEN, 00256 "(Handle=%s, Cookie=%"PRIu64")", buffer, 0UL); 00257 } 00258 00259 int display_not_implemented(hash_buffer_t * pbuff, char *str) 00260 { 00261 00262 return snprintf(str, HASHTABLE_DISPLAY_STRLEN, 00263 "Print Not Implemented"); 00264 } 00265 00266 int display_value(hash_buffer_t * pbuff, char *str) 00267 { 00268 cache_entry_t *pentry; 00269 00270 pentry = (cache_entry_t *) pbuff->pdata; 00271 00272 return snprintf(str, HASHTABLE_DISPLAY_STRLEN, 00273 "(Type=%d, Address=%p)", 00274 pentry->type, pentry); 00275 }