static int db_load_operation(db_thread_info_t * p_info, hash_table_t * p_hash) { /* the object id to be inserted to hash table */ uint64_t object_id; unsigned int handle_hash; const char *fsal_handle_str; fsal_handle_t fsal_handle; unsigned int nb_loaded = 0; int rc; struct timeval t1; struct timeval t2; struct timeval tdiff; gettimeofday(&t1, NULL); rc = sqlite3_step(p_info->prep_stmt[LOAD_ALL_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[LOAD_ALL_STATEMENT]); /* something to read */ while(rc == SQLITE_ROW) { object_id = sqlite3_column_int64(p_info->prep_stmt[LOAD_ALL_STATEMENT], 0); handle_hash = sqlite3_column_int(p_info->prep_stmt[LOAD_ALL_STATEMENT], 1); fsal_handle_str = sqlite3_column_text(p_info->prep_stmt[LOAD_ALL_STATEMENT], 2); /* convert hexa string representation to binary data */ sscanHandle(&fsal_handle, fsal_handle_str); /* now insert it to the hash table */ rc = handle_mapping_hash_add(p_hash, object_id, handle_hash, &fsal_handle); if(rc == 0) nb_loaded++; else LogCrit(COMPONENT_FSAL, "ERROR %d adding entry to hash table <object_id=%llu, FH_hash=%u, FSAL_Handle=%s>", rc, (unsigned long long)object_id, handle_hash, fsal_handle_str); rc = sqlite3_step(p_info->prep_stmt[LOAD_ALL_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[LOAD_ALL_STATEMENT]); } /* clear results */ sqlite3_reset(p_info->prep_stmt[LOAD_ALL_STATEMENT]); /* print time and item count */ gettimeofday(&t2, NULL); timersub(&t2, &t1, &tdiff); LogEvent(COMPONENT_FSAL, "Reloaded %u items in %d.%06ds", nb_loaded, (int)tdiff.tv_sec, (int)tdiff.tv_usec); return HANDLEMAP_SUCCESS; } /* db_load_operation */
static int db_insert_operation(db_thread_info_t *p_info, struct hdlmap_tuple *data) { int rc; char handle_str[2 * NFS4_FHSIZE + 1]; rc = sqlite3_bind_int64(p_info->prep_stmt[INSERT_STATEMENT], 1, data->nfs23_digest.object_id); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); rc = sqlite3_bind_int(p_info->prep_stmt[INSERT_STATEMENT], 2, data->nfs23_digest.handle_hash); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); snprintmem(handle_str, sizeof(handle_str), data->fh4_data, data->fh4_len); rc = sqlite3_bind_text(p_info->prep_stmt[INSERT_STATEMENT], 3, handle_str, -1, SQLITE_STATIC); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); rc = sqlite3_step(p_info->prep_stmt[INSERT_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); /* clear results */ sqlite3_reset(p_info->prep_stmt[INSERT_STATEMENT]); return HANDLEMAP_SUCCESS; } /* db_insert_operation */
static int db_insert_operation(db_thread_info_t * p_info, nfs23_map_handle_t * p_nfs23_digest, fsal_handle_t * p_handle) { int rc; char handle_str[2 * sizeof(fsal_handle_t) + 1]; rc = sqlite3_bind_int64(p_info->prep_stmt[INSERT_STATEMENT], 1, p_nfs23_digest->object_id); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); rc = sqlite3_bind_int(p_info->prep_stmt[INSERT_STATEMENT], 2, p_nfs23_digest->handle_hash); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); snprintHandle(handle_str, 2 * sizeof(fsal_handle_t) + 1, p_handle); rc = sqlite3_bind_text(p_info->prep_stmt[INSERT_STATEMENT], 3, handle_str, -1, SQLITE_STATIC); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); rc = sqlite3_step(p_info->prep_stmt[INSERT_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[INSERT_STATEMENT]); /* clear results */ sqlite3_reset(p_info->prep_stmt[INSERT_STATEMENT]); return HANDLEMAP_SUCCESS; } /* db_insert_operation */
static int db_delete_operation(db_thread_info_t *p_info, nfs23_map_handle_t *p_nfs23_digest) { int rc; rc = sqlite3_bind_int64(p_info->prep_stmt[DELETE_STATEMENT], 1, p_nfs23_digest->object_id); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[DELETE_STATEMENT]); rc = sqlite3_bind_int(p_info->prep_stmt[DELETE_STATEMENT], 2, p_nfs23_digest->handle_hash); CheckBind(p_info->db_conn, rc, p_info->prep_stmt[DELETE_STATEMENT]); rc = sqlite3_step(p_info->prep_stmt[DELETE_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[DELETE_STATEMENT]); /* clear results */ sqlite3_reset(p_info->prep_stmt[DELETE_STATEMENT]); return HANDLEMAP_SUCCESS; } /* db_delete_operation */
static int db_load_operation(db_thread_info_t *p_info, hash_table_t *p_hash) { /* the object id to be inserted to hash table */ uint64_t object_id; unsigned int handle_hash; const char *fsal_handle_str; char fh4_data[NFS4_FHSIZE]; unsigned int nb_loaded = 0; int rc; struct timeval t1; struct timeval t2; struct timeval tdiff; gettimeofday(&t1, NULL); rc = sqlite3_step(p_info->prep_stmt[LOAD_ALL_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[LOAD_ALL_STATEMENT]); /* something to read */ while (rc == SQLITE_ROW) { object_id = sqlite3_column_int64(p_info->prep_stmt[LOAD_ALL_STATEMENT], 0); handle_hash = sqlite3_column_int(p_info->prep_stmt[LOAD_ALL_STATEMENT], 1); fsal_handle_str = sqlite3_column_text(p_info->prep_stmt[LOAD_ALL_STATEMENT], 2); if (fsal_handle_str) { int len = strlen(fsal_handle_str); if ((len & 1) || len > NFS4_FHSIZE * 2) { LogEvent(COMPONENT_FSAL, "Bogus handle '%s' - wrong number of symbols", fsal_handle_str); } else { /* convert hexa string representation * to binary data */ if (sscanmem(fh4_data, len / 2, fsal_handle_str) != len) { LogEvent(COMPONENT_FSAL, "Bogus entry '%s' - cannot convert", fsal_handle_str); } else { /* now insert it to the hash table */ rc = handle_mapping_hash_add(p_hash, object_id, handle_hash, fh4_data, len / 2); if (rc == 0) nb_loaded++; else LogCrit(COMPONENT_FSAL, "ERROR %d adding entry to hash table <object_id=%llu, FH_hash=%u, FSAL_Handle=%s>", rc, (unsigned long long) object_id, handle_hash, fsal_handle_str); } } } else { LogEvent(COMPONENT_FSAL, "Empty handle in object %lld, hash %d", (unsigned long long)object_id, handle_hash); } rc = sqlite3_step(p_info->prep_stmt[LOAD_ALL_STATEMENT]); CheckStep(p_info->db_conn, rc, p_info->prep_stmt[LOAD_ALL_STATEMENT]); } /* clear results */ sqlite3_reset(p_info->prep_stmt[LOAD_ALL_STATEMENT]); /* print time and item count */ gettimeofday(&t2, NULL); timersub(&t2, &t1, &tdiff); LogEvent(COMPONENT_FSAL, "Reloaded %u items in %d.%06ds", nb_loaded, (int)tdiff.tv_sec, (int)tdiff.tv_usec); return HANDLEMAP_SUCCESS; } /* db_load_operation */