Changeset 8919

Show
Ignore:
Timestamp:
07/06/11 16:25:50 (23 months ago)
Author:
jdenton
Message:

updated functions

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/Orange-Branch/src/client/usrint/ucache.c

    r8918 r8919  
    157157} 
    158158 
    159 /** Hash Function -  
    160  * Also in quickhash library in: pvfs2/src/common/quickhash/quickhash.h 
    161  * derived from an algorithm found in Aho, Sethi and Ullman's 
    162  * {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  
    182159static struct mem_table *lookup_file(uint32_t fs_id, uint64_t handle) 
    183160{ 
    184161        struct file_table_s *ftbl = &(ucache->ftbl); 
    185162        struct file_ent_s *current;     /* Current ptr for iteration    */ 
    186         char ids_as_string[25]; /*      (32+64)/4 + 1 (for null byte)   */ 
    187163        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; 
    195165        current = &(ftbl->file[index]); 
    196166        if(current->mtbl_blk!=NIL && current->mtbl_ent!=NIL){ 
     
    240210} 
    241211 
    242 static struct mem_ent_s *insert_file(uint32_t fs_id, uint64_t handle) 
     212static struct mem_table_s *insert_file(uint32_t fs_id, uint64_t handle) 
    243213{ 
    244214        struct file_table_s *ftbl = &(ucache->ftbl); 
    245215        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; 
    255218        current = &(ftbl->file[index]);  
    256219        /*      Insert at index, relocating head data if necessary.     */ 
     
    271234                else{   /*      No free file entries available: policy? */ 
    272235                        /*      Evict or return NIL     */ 
    273                         return (struct mem_ent_s *)NIL; 
     236                        return (struct mem_table_s *)NIL; 
    274237                } 
    275238        } 
     
    278241        uint16_t free_mtbl_ent;  
    279242        /* 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){ 
    281244                /*      Update fent with it's new mtbl: blk and ent */ 
    282245                current->mtbl_blk = free_mtbl_blk; 
     
    284247                /*      Initialize Memory Table */ 
    285248                init_memory_table(free_mtbl_blk, free_mtbl_ent); 
    286  
    287                 /* Copy data from file into mem entries */ 
    288                 //... then return 
    289  
    290  
    291  
    292249                return &(ucache->b[current->mtbl_blk].mtbl[ 
    293                         current->mtbl_ent].mem[0]); 
     250                        current->mtbl_ent]); 
    294251        } 
    295252        else{   /*      No free mtbl available: policy? */ 
    296253                /*      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 
    301259static int remove_file(uint32_t fs_id, uint64_t handle) 
    302260{ 
    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); 
    306304} 
    307305 
    308306static void *lookup_mem(struct mem_table_s *mtbl, uint64_t offset) 
    309307{ 
     308 
     309 
     310 
    310311} 
    311312