Changeset 8919
- Timestamp:
- 07/06/11 16:25:50 (23 months ago)
- Files:
-
- 1 modified
-
branches/Orange-Branch/src/client/usrint/ucache.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Orange-Branch/src/client/usrint/ucache.c
r8918 r8919 157 157 } 158 158 159 /** Hash Function -160 * Also in quickhash library in: pvfs2/src/common/quickhash/quickhash.h161 * derived from an algorithm found in Aho, Sethi and Ullman's162 * {Compilers: Principles, Techniques and Tools}, published by Addison-Wesley.163 * This algorithm comes from P.J. Weinberger's C compiler.164 */165 static inline int hash(void *k, int table_size)166 {167 const char *str = (char *)k;168 uint32_t g, h = 0;169 while(*str)170 {171 h = (h << 4) + *str++;172 if((g = (h & 0xF0UL)))173 {174 h ^= g >> 24;175 h ^= g;176 }177 }178 return (int)(h & ((uint64_t)(table_size - 1)));179 }180 181 182 159 static struct mem_table *lookup_file(uint32_t fs_id, uint64_t handle) 183 160 { 184 161 struct file_table_s *ftbl = &(ucache->ftbl); 185 162 struct file_ent_s *current; /* Current ptr for iteration */ 186 char ids_as_string[25]; /* (32+64)/4 + 1 (for null byte) */187 163 int index; /* index into file hash table */ 188 /* convert identifiers into concatenated hex string to be sent 189 * to hash function 190 */ 191 sprintf(ids_as_string, "%08lX%016llX",(long unsigned int)fs_id, 192 (long long unsigned int)handle); 193 /* Determine index into hash table */ 194 index = hash(ids_as_string, FILE_TABLE_HASH_MAX); 164 index = handle % FILE_TABLE_HASH_MAX; 195 165 current = &(ftbl->file[index]); 196 166 if(current->mtbl_blk!=NIL && current->mtbl_ent!=NIL){ … … 240 210 } 241 211 242 static struct mem_ ent_s *insert_file(uint32_t fs_id, uint64_t handle)212 static struct mem_table_s *insert_file(uint32_t fs_id, uint64_t handle) 243 213 { 244 214 struct file_table_s *ftbl = &(ucache->ftbl); 245 215 struct file_ent_s *current; /* Current ptr for iteration */ 246 char ids_as_string[25]; /* (32+64)/4 + 1 (for null byte) */ 247 int index; /* index into file hash table */ 248 /* convert identifiers into concatenated hex string to be sent 249 * to hash function 250 */ 251 sprintf(ids_as_string, "%08lX%016llX", (long unsigned int)fs_id, 252 (long long unsigned int)handle); 253 /* Determine index into hash table */ 254 index = hash(ids_as_string, FILE_TABLE_HASH_MAX); 216 /* index into file hash table */ 217 int index = handle % FILE_TABLE_HASH_MAX; 255 218 current = &(ftbl->file[index]); 256 219 /* Insert at index, relocating head data if necessary. */ … … 271 234 else{ /* No free file entries available: policy? */ 272 235 /* Evict or return NIL */ 273 return (struct mem_ ent_s *)NIL;236 return (struct mem_table_s *)NIL; 274 237 } 275 238 } … … 278 241 uint16_t free_mtbl_ent; 279 242 /* Is there a free memory table available? */ 280 if(get_next_free_mtbl(&free_mtbl_blk, &free_mtbl_ent) ){243 if(get_next_free_mtbl(&free_mtbl_blk, &free_mtbl_ent)==1){ 281 244 /* Update fent with it's new mtbl: blk and ent */ 282 245 current->mtbl_blk = free_mtbl_blk; … … 284 247 /* Initialize Memory Table */ 285 248 init_memory_table(free_mtbl_blk, free_mtbl_ent); 286 287 /* Copy data from file into mem entries */288 //... then return289 290 291 292 249 return &(ucache->b[current->mtbl_blk].mtbl[ 293 current->mtbl_ent] .mem[0]);250 current->mtbl_ent]); 294 251 } 295 252 else{ /* No free mtbl available: policy? */ 296 253 /* Evict or return NIL */ 297 return (struct mem_ent_s *)NIL; 298 } 299 } 300 254 return (struct mem_table_s *)NIL; 255 } 256 } 257 258 //Needs work 301 259 static int remove_file(uint32_t fs_id, uint64_t handle) 302 260 { 303 //remove the link from the linked list 304 305 261 struct file_table_s *ftbl = &(ucache->ftbl); 262 struct file_ent_s *current; /* Current ptr for iteration */ 263 uint32_t file_mtbl_blk = NIL; 264 uint16_t file_mtbl_ent = NIL; 265 /* index into file hash table */ 266 int index = handle % FILE_TABLE_HASH_MAX; 267 current = &(ftbl->file[index]); 268 if(current->mtbl_blk!=NIL && current->mtbl_ent!=NIL){ /* links present */ 269 /* Iterate and examine the fs_id and handle. 270 * stop when matched or next is NIL */ 271 while((int)current!=NIL){ 272 if(current->tag_id==fs_id && 273 current->tag_handle==handle){ 274 file_mtbl_blk = current->mtbl_blk; 275 file_mtbl_ent = current->mtbl_ent; 276 } 277 current = &(ftbl->file[current->next]); 278 } 279 } 280 else{ /* No links present */ 281 if(current->tag_id==fs_id && current->tag_handle==handle){ 282 file_mtbl_blk = current->mtbl_blk; 283 file_mtbl_ent = current->mtbl_ent; 284 } 285 } 286 //Verify we've recieved the necesasry info 287 if(file_mtbl_blk==NIL || file_mtbl_ent==NIL){ 288 return NIL; 289 } 290 /* add mem_table back to free list */ 291 /* First: store temp copy of current head */ 292 uint32_t tmp_blk = ftbl->free_mtbl_blk; 293 uint16_t tmp_ent = ftbl->free_mtbl_ent; 294 295 //Need current block and ent corresponding to file to be removed 296 ftbl->free_mtbl_blk = file_mtbl_blk; 297 ftbl->free_mtbl_ent = file_mtbl_ent; 298 299 //Set nexts 300 // ftbl->free_mtbl_blk 301 302 //put_free_fent(index); 303 return(1); 306 304 } 307 305 308 306 static void *lookup_mem(struct mem_table_s *mtbl, uint64_t offset) 309 307 { 308 309 310 310 311 } 311 312
