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 */
/** * Save the handle association if it was unknown. */ int HandleMap_SetFH(nfs23_map_handle_t *p_in_nfs23_digest, const void *data, uint32_t len) { int rc; /* first, try to insert it to the hash table */ rc = handle_mapping_hash_add(handle_map_hash, p_in_nfs23_digest->object_id, p_in_nfs23_digest->handle_hash, data, len); if ((rc != 0) && (rc != HANDLEMAP_EXISTS)) /* error */ return rc; else if (rc == HANDLEMAP_EXISTS) /* already in database */ return HANDLEMAP_EXISTS; else { /* insert it to DB */ return handlemap_db_insert(p_in_nfs23_digest, data, len); } }
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 */