/** * Submit a db 'delete' request. * The request is inserted in the appropriate db queue. * (always asynchronous) */ int handlemap_db_delete(nfs23_map_handle_t *p_in_nfs23_digest) { unsigned int i; db_op_item_t *new_task; int rc; /* which thread is going to handle this inode ? */ i = select_db_queue(p_in_nfs23_digest); /* get a new db operation */ pthread_mutex_lock(&db_thread[i].pool_mutex); new_task = pool_alloc(db_thread[i].dbop_pool, NULL); pthread_mutex_unlock(&db_thread[i].pool_mutex); if (!new_task) return HANDLEMAP_SYSTEM_ERROR; /* fill the task info */ new_task->op_type = DELETE; new_task->op_arg.fh_info.nfs23_digest = *p_in_nfs23_digest; rc = dbop_push(&db_thread[i].work_queue, new_task); if (rc) return rc; return HANDLEMAP_SUCCESS; }
/** * Gives the order to each DB thread to reload * the content of its database and insert it * to the hash table. * The function blocks until all threads have loaded their data. */ int handlemap_db_reaload_all(hash_table_t * target_hash) { unsigned int i; db_op_item_t *new_task; int rc; /* give the job to all threads */ for(i = 0; i < nb_db_threads; i++) { /* get a new db operation */ P(db_thread[i].pool_mutex); new_task = pool_alloc(&db_thread[i].dbop_pool, NULL); V(db_thread[i].pool_mutex); if(!new_task) return HANDLEMAP_SYSTEM_ERROR; /* can you fill it ? */ new_task->op_type = LOAD; new_task->op_arg.hash = target_hash; rc = dbop_push(&db_thread[i].work_queue, new_task); if(rc) return rc; } /* wait for all threads to finish their job */ for(i = 0; i < nb_db_threads; i++) { wait_thread_jobs_finished(&db_thread[i]); } return HANDLEMAP_SUCCESS; } /* handlemap_db_reaload_all */
/** * Submit a db 'insert' request. * The request is inserted in the appropriate db queue. */ int handlemap_db_insert(nfs23_map_handle_t *p_in_nfs23_digest, const void *data, uint32_t len) { unsigned int i; db_op_item_t *new_task; int rc; if (!synchronous) { /* which thread is going to handle this inode ? */ i = select_db_queue(p_in_nfs23_digest); /* get a new db operation */ pthread_mutex_lock(&db_thread[i].pool_mutex); new_task = pool_alloc(db_thread[i].dbop_pool, NULL); pthread_mutex_unlock(&db_thread[i].pool_mutex); if (!new_task) return HANDLEMAP_SYSTEM_ERROR; /* fill the task info */ new_task->op_type = INSERT; new_task->op_arg.fh_info.nfs23_digest = *p_in_nfs23_digest; memcpy(new_task->op_arg.fh_info.fh4_data, data, len); new_task->op_arg.fh_info.fh4_len = len; rc = dbop_push(&db_thread[i].work_queue, new_task); if (rc) return rc; } /* else: @todo not supported yet */ return HANDLEMAP_SUCCESS; }