int do_new(LRU_list_t * plru, int key) { char *tmpkey = NULL; LRU_entry_t *pentry = NULL; LRU_status_t status; if((tmpkey = (char *)malloc(STRSIZE)) == NULL) return -1; sprintf(tmpkey, "%d", key); if((pentry = LRU_new_entry(plru, &status)) == NULL) { free(tmpkey); return status; } pentry->buffdata.len = strlen(tmpkey); pentry->buffdata.pdata = tmpkey; tabentry[key] = pentry; return status; }
int nfs_dupreq_finish(long xid, struct svc_req *ptr_req, SVCXPRT *xprt, nfs_res_t * p_res_nfs, LRU_list_t * lru_dupreq) { hash_buffer_t buffkey; hash_buffer_t buffval; LRU_entry_t *pentry = NULL; LRU_status_t lru_status; dupreq_key_t dupkey; dupreq_entry_t *pdupreq; hash_table_t * ht_dupreq = NULL ; /* Get correct HT depending on proto used */ ht_dupreq = get_ht_by_xprt( xprt ) ; /* Get the socket address for the key */ if(copy_xprt_addr(&dupkey.addr, xprt) == 0) return DUPREQ_NOT_FOUND; dupkey.xid = xid; dupkey.checksum = 0; /* I have to keep an integer as key, I wil use the pointer buffkey->pdata for this, * this also means that buffkey->len will be 0 */ buffkey.pdata = (caddr_t) &dupkey; buffkey.len = sizeof(dupreq_key_t); if(HashTable_Get(ht_dupreq, &buffkey, &buffval) != HASHTABLE_SUCCESS) return DUPREQ_NOT_FOUND; pdupreq = (dupreq_entry_t *)buffval.pdata; LogDupReq("Finish", &pdupreq->addr, pdupreq->xid, pdupreq->rq_prog); P(pdupreq->dupreq_mutex); pdupreq->res_nfs = *p_res_nfs; pdupreq->timestamp = time(NULL); pdupreq->processing = 0; V(pdupreq->dupreq_mutex); /* Add it to lru list */ if((pentry = LRU_new_entry(lru_dupreq, &lru_status)) == NULL) return DUPREQ_INSERT_MALLOC_ERROR; pentry->buffdata.pdata = buffval.pdata; pentry->buffdata.len = buffval.len; return DUPREQ_SUCCESS; } /* nfs_dupreq_finish */
int main(int argc, char *argv[]) { SetDefaultLogging("TEST"); SetNamePgm("test_lru"); LRU_list_t *plru; LRU_parameter_t param; LRU_entry_t *entry = NULL; LRU_entry_t *kept_entry = NULL; LRU_status_t status = 0; int i = 0; char strtab[MAXTEST][10]; param.nb_entry_prealloc = PREALLOC; param.entry_to_str = print_entry; param.clean_entry = clean_entry; param.lp_name = "Test"; BuddyInit(NULL); if((plru = LRU_Init(param, &status)) == NULL) { LogTest("Test FAILED: Bad Init"); exit(1); } for(i = 0; i < MAXTEST; i++) { LogTest("Added entry %d", i); sprintf(strtab[i], "%d", i); if((entry = LRU_new_entry(plru, &status)) == NULL) { LogTest("Test FAILED: bad entry add, status = %d", status); exit(1); } entry->buffdata.pdata = strtab[i]; entry->buffdata.len = strlen(strtab[i]); if(i == KEPT_ENTRY) kept_entry = entry; } /* printing the table */ LRU_Print(plru); LRU_invalidate(plru, kept_entry); if(isFullDebug(COMPONENT_LRU)) LRU_Print(plru); if(LRU_gc_invalid(plru, NULL) != LRU_LIST_SUCCESS) { LogTest("Test FAILED: bad gc"); exit(1); } LRU_Print(plru); /* Tous les tests sont ok */ LogTest("\n-----------------------------------------"); LogTest("Test succeeded: all tests pass successfully"); exit(0); } /* main */