FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c
/*
 * Insert an entry into the hash table.  If there is already an element
 * equal to elem in the hash table, then the already existing element
 * will be returned and the new element will not be inserted.
 * Otherwise returns NULL.
 */
Insert an entry into the hash table.  If there is already an element
equal to elem in the hash table, then the already existing element
will be returned and the new element will not be inserted.
Otherwise returns NULL.
Insert an entry into the hash table . If there is already an element equal to elem in the hash table then the already existing element will be returned and the new element will not be inserted . Otherwise returns NULL .
static dmu_buf_impl_t *
dbuf_hash_insert(dmu_buf_impl_t *db)
{
	dbuf_hash_table_t *h = &dbuf_hash_table;
	objset_t *os = db->db_objset;
	uint64_t obj = db->db.db_object;
	int level = db->db_level;
	uint64_t blkid = db->db_blkid;
	uint64_t hv = DBUF_HASH(os, obj, level, blkid);
	uint64_t idx = hv & h->hash_table_mask;
	dmu_buf_impl_t *dbf;
	mutex_enter(DBUF_HASH_MUTEX(h, idx));
	for (dbf = h->hash_table[idx]; dbf != NULL; dbf = dbf->db_hash_next) {
		if (DBUF_EQUAL(dbf, os, obj, level, blkid)) {
			mutex_enter(&dbf->db_mtx);
			if (dbf->db_state != DB_EVICTING) {
				mutex_exit(DBUF_HASH_MUTEX(h, idx));
				return (dbf);
			}
			mutex_exit(&dbf->db_mtx);
		}
	}
	mutex_enter(&db->db_mtx);
	db->db_hash_next = h->hash_table[idx];
	h->hash_table[idx] = db;
	mutex_exit(DBUF_HASH_MUTEX(h, idx));
	atomic_inc_64(&dbuf_hash_count);
	return (NULL);
}
static dmu_buf_impl_t * dbuf_hash_insert ( dmu_buf_impl_t * db ) { dbuf_hash_table_t * h = & dbuf_hash_table ; objset_t * os = db -> db_objset ; uint64_t obj = db -> db . db_object ; int level = db -> db_level ; uint64_t blkid = db -> db_blkid ; uint64_t hv = DBUF_HASH ( os , obj , level , blkid ) ; uint64_t idx = hv & h -> hash_table_mask ; dmu_buf_impl_t * dbf ; mutex_enter ( DBUF_HASH_MUTEX ( h , idx ) ) ; for ( dbf = h -> hash_table [ idx ] ; dbf != NULL ; dbf = dbf -> db_hash_next ) { if ( DBUF_EQUAL ( dbf , os , obj , level , blkid ) ) { mutex_enter ( & dbf -> db_mtx ) ; if ( dbf -> db_state != DB_EVICTING ) { mutex_exit ( DBUF_HASH_MUTEX ( h , idx ) ) ; return ( dbf ) ; } mutex_exit ( & dbf -> db_mtx ) ; } } mutex_enter ( & db -> db_mtx ) ; db -> db_hash_next = h -> hash_table [ idx ] ; h -> hash_table [ idx ] = db ; mutex_exit ( DBUF_HASH_MUTEX ( h , idx ) ) ; atomic_inc_64 ( & dbuf_hash_count ) ; return ( NULL ) ; }
Insert an entry into the hash table.
Insert an entry into the hash table .