#include <stdlib.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "odb.h"
#include "op_string.h"
#include "op_libiberty.h"
Go to the source code of this file.
Defines | |
#define | _GNU_SOURCE |
#define | DEFAULT_NODE_NR(offset_node) 128 |
#define | FILES_HASH_SIZE 512 |
Functions | |
static __inline odb_descr_t * | odb_to_descr (odb_data_t *data) |
static __inline odb_node_t * | odb_to_node_base (odb_data_t *data) |
static __inline odb_index_t * | odb_to_hash_base (odb_data_t *data) |
static unsigned int | tables_size (odb_data_t const *data, odb_node_nr_t node_nr) |
int | odb_grow_hashtable (odb_data_t *data) |
void | odb_init (odb_t *odb) |
static void | init_hash () |
static odb_data_t * | find_samples_data (size_t hash, char const *filename) |
int | odb_open (odb_t *odb, char const *filename, enum odb_rw rw, size_t sizeof_header) |
void | odb_close (odb_t *odb) |
int | odb_open_count (odb_t const *odb) |
void * | odb_get_data (odb_t *odb) |
void | odb_sync (odb_t const *odb) |
Variables | |
static struct list_head | files_hash [FILES_HASH_SIZE] |
Management of a DB file
Definition in file db_manage.c.
#define _GNU_SOURCE |
Definition at line 11 of file db_manage.c.
#define DEFAULT_NODE_NR | ( | offset_node | ) | 128 |
Definition at line 127 of file db_manage.c.
Referenced by odb_open().
#define FILES_HASH_SIZE 512 |
Definition at line 128 of file db_manage.c.
Referenced by init_hash(), and odb_open().
static odb_data_t* find_samples_data | ( | size_t | hash, | |
char const * | filename | |||
) | [static] |
Definition at line 142 of file db_manage.c.
References odb_data::filename, files_hash, init_hash(), list_entry, list_for_each, and list_head::next.
Referenced by odb_open().
static void init_hash | ( | ) | [static] |
Definition at line 133 of file db_manage.c.
References files_hash, FILES_HASH_SIZE, and list_init().
Referenced by find_samples_data().
void odb_close | ( | odb_t * | odb | ) |
Close the given ODB file
Definition at line 263 of file db_manage.c.
References odb_data::base_memory, odb_t::data, odb_data::descr, odb_data::fd, odb_data::filename, odb_data::list, list_del(), odb_data::ref_count, odb_descr_t::size, and tables_size().
Referenced by close_sfile(), ibs_sfile_close(), main(), opd_24_sfile_lru_clear(), opd_close_image_samples_files(), sanity_check(), speed_test(), and test().
void* odb_get_data | ( | odb_t * | odb | ) |
return the start of the mapped data
Definition at line 291 of file db_manage.c.
References odb_data::base_memory, and odb_t::data.
Referenced by import_from_abi(), main(), opd_open_24_sample_file(), opd_open_sample_file(), and operf_open_sample_file().
int odb_grow_hashtable | ( | odb_data_t * | data | ) |
grow the hashtable in such way current_size is the index of the first free node. Take care all node pointer can be invalidated by this call.
Node allocation is done in a two step way 1st) ensure a free node exist eventually, caller can setup it, 2nd) commit the node allocation with odb_commit_reservation(). This is done in this way to ensure node setup is visible from another process like pp tools in an atomic way.
returns 0 on success, non zero on failure in this case this function do nothing and errno is set by the first libc call failure allowing to retry after cleanup some program resource.
Definition at line 63 of file db_manage.c.
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_data::descr, odb_data::fd, odb_data::hash_base, odb_data::hash_mask, odb_node_t::key, odb_node_t::next, odb_data::node_base, odb_do_hash(), odb_to_descr(), odb_to_hash_base(), odb_to_node_base(), odb_descr_t::size, and tables_size().
Referenced by add_node().
void odb_init | ( | odb_t * | odb | ) |
odb_init - initialize a DB file
odb | the DB file to init |
Definition at line 120 of file db_manage.c.
References odb_t::data.
Referenced by create_sfile(), ibs_sfile_create(), ibs_sfile_dup(), opd_open_24_sample_file(), operf_sfile_dup(), and sfile_dup().
Definition at line 162 of file db_manage.c.
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, DEFAULT_NODE_NR, odb_data::descr, odb_data::fd, odb_data::filename, files_hash, FILES_HASH_SIZE, find_samples_data(), odb_data::hash_base, odb_data::hash_mask, odb_data::list, list_add(), list_init(), odb_data::node_base, ODB_RDONLY, ODB_RDWR, odb_to_descr(), odb_to_hash_base(), odb_to_node_base(), odb_data::offset_node, op_hash_string(), odb_data::ref_count, odb_descr_t::size, odb_data::sizeof_header, and tables_size().
Referenced by main(), opd_open_24_sample_file(), opd_open_sample_file(), operf_open_sample_file(), sanity_check(), speed_test(), and test().
int odb_open_count | ( | odb_t const * | odb | ) |
return the number of times this sample file is open
Definition at line 283 of file db_manage.c.
References odb_t::data, and odb_data::ref_count.
Referenced by get_file(), ibs_sfile_get(), and opd_put_image_sample().
void odb_sync | ( | odb_t const * | odb | ) |
issue a msync on the used size of the mmaped file
Definition at line 297 of file db_manage.c.
References odb_data::base_memory, odb_t::data, odb_data::descr, odb_descr_t::size, and tables_size().
Referenced by ibs_sfile_sync(), opd_sync_samples_files(), and sync_sfile().
static __inline odb_descr_t* odb_to_descr | ( | odb_data_t * | data | ) | [static] |
Definition at line 28 of file db_manage.c.
References odb_data::base_memory, and odb_data::sizeof_header.
Referenced by odb_grow_hashtable(), and odb_open().
static __inline odb_index_t* odb_to_hash_base | ( | odb_data_t * | data | ) | [static] |
Definition at line 40 of file db_manage.c.
References odb_data::base_memory, odb_data::descr, odb_data::offset_node, and odb_descr_t::size.
Referenced by odb_grow_hashtable(), and odb_open().
static __inline odb_node_t* odb_to_node_base | ( | odb_data_t * | data | ) | [static] |
Definition at line 34 of file db_manage.c.
References odb_data::base_memory, and odb_data::offset_node.
Referenced by odb_grow_hashtable(), and odb_open().
static unsigned int tables_size | ( | odb_data_t const * | data, | |
odb_node_nr_t | node_nr | |||
) | [static] |
return the number of bytes used by hash table, node table and header.
Definition at line 51 of file db_manage.c.
References BUCKET_FACTOR, and odb_data::offset_node.
Referenced by odb_close(), odb_grow_hashtable(), odb_open(), and odb_sync().
struct list_head files_hash[FILES_HASH_SIZE] [static] |
Definition at line 130 of file db_manage.c.
Referenced by find_samples_data(), init_hash(), and odb_open().