Exemple #1
0
/**
 * Work queue wrapper for tdb_file_open() (real file open).
 */
static void
tdb_open_db(struct work_struct *work)
{
	TdbWork *tw = (TdbWork *)work;
	TDB *db = tw->db;

	if (tdb_file_open(db, tw->fsize))
		TDB_ERR("Cannot open db\n");

	db->hdr = tdb_htrie_init(db->hdr, db->filp->f_inode->i_size, tw->rsize);
	if (!db->hdr)
		TDB_ERR("Cannot initialize db header\n");

	kmem_cache_free(tw_cache, tw);
}
Exemple #2
0
/**
 * Open database file and @return its descriptor.
 * If the database is already opened, then returns the handler.
 *
 * The function must not be called from softirq!
 */
TDB *
tdb_open(const char *path, size_t fsize, unsigned int rec_size, int node)
{
	TDB *db;

	if ((fsize & ~TDB_EXT_MASK) || fsize < TDB_EXT_SZ) {
		TDB_ERR("Bad table size: %lu\n", fsize);
		return NULL;
	}

	db = tdb_get_db(path, node);
	if (!db)
		return NULL;

	db->node = node;

	if (tdb_file_open(db, fsize)) {
		TDB_ERR("Cannot open db\n");
		goto err;
	}

	db->hdr = tdb_htrie_init(db->hdr, db->filp->f_inode->i_size, rec_size);
	if (!db->hdr) {
		TDB_ERR("Cannot initialize db header\n");
		goto err_init;
	}

	tdb_tbl_enumerate(db);

	TDB_LOG("Opened table %s: size=%lu rec_size=%u base=%p\n",
		path, fsize, rec_size, db->hdr);

	return db;
err_init:
	tdb_file_close(db);
err:
	tdb_put(db);
	return NULL;
}