Skip to content

Commit

Permalink
Illumos 5314 - Remove "dbuf phys" db->db_data pointer aliases in ZFS
Browse files Browse the repository at this point in the history
5314 Remove "dbuf phys" db->db_data pointer aliases in ZFS
Author: Justin T. Gibbs <justing@spectralogic.com>
Reviewed by: Andriy Gapon <avg@freebsd.org>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Will Andrews <willa@spectralogic.com>
Approved by: Dan McDonald <danmcd@omniti.com>

References:
  https://www.illumos.org/issues/5314
  illumos/illumos-gate@c137962

Ported-by: Chris Dunlop <chris@onthe.net.au>
  • Loading branch information
chrisrd committed Mar 31, 2015
1 parent 5bc0460 commit 29a5ed6
Show file tree
Hide file tree
Showing 32 changed files with 914 additions and 809 deletions.
4 changes: 2 additions & 2 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1928,8 +1928,8 @@ dump_dir(objset_t *os)
if (dds.dds_type == DMU_OST_META) {
dds.dds_creation_txg = TXG_INITIAL;
usedobjs = BP_GET_FILL(os->os_rootbp);
refdbytes = os->os_spa->spa_dsl_pool->
dp_mos_dir->dd_phys->dd_used_bytes;
refdbytes = dsl_dir_phys(os->os_spa->spa_dsl_pool->dp_mos_dir)->
dd_used_bytes;
} else {
dmu_objset_space(os, &refdbytes, &scratch, &usedobjs, &scratch);
}
Expand Down
1 change: 0 additions & 1 deletion include/sys/dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ typedef struct dmu_buf_impl {

/* stuff we store for the user (see dmu_buf_set_user) */
void *db_user_ptr;
void **db_user_data_ptr_ptr;
dmu_buf_evict_func_t *db_evict_func;

uint8_t db_immediate_evict;
Expand Down
13 changes: 3 additions & 10 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,30 +481,23 @@ void dmu_buf_rele_array(dmu_buf_t **, int numbufs, void *tag);
*
* user_ptr is for use by the user and can be obtained via dmu_buf_get_user().
*
* user_data_ptr_ptr should be NULL, or a pointer to a pointer which
* will be set to db->db_data when you are allowed to access it. Note
* that db->db_data (the pointer) can change when you do dmu_buf_read(),
* dmu_buf_tryupgrade(), dmu_buf_will_dirty(), or dmu_buf_will_fill().
* *user_data_ptr_ptr will be set to the new value when it changes.
*
* If non-NULL, pageout func will be called when this buffer is being
* excised from the cache, so that you can clean up the data structure
* pointed to by user_ptr.
*
* dmu_evict_user() will call the pageout func for all buffers in a
* objset with a given pageout func.
*/
void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr, void *user_data_ptr_ptr,
void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr,
dmu_buf_evict_func_t *pageout_func);
/*
* set_user_ie is the same as set_user, but request immediate eviction
* when hold count goes to zero.
*/
void *dmu_buf_set_user_ie(dmu_buf_t *db, void *user_ptr,
void *user_data_ptr_ptr, dmu_buf_evict_func_t *pageout_func);
void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr,
void *user_ptr, void *user_data_ptr_ptr,
dmu_buf_evict_func_t *pageout_func);
void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr,
void *user_ptr, dmu_buf_evict_func_t *pageout_func);
void dmu_evict_user(objset_t *os, dmu_buf_evict_func_t *func);

/*
Expand Down
20 changes: 14 additions & 6 deletions include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct dsl_pool;

#define DS_FLAG_INCONSISTENT (1ULL<<0)
#define DS_IS_INCONSISTENT(ds) \
((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
(dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT)

/*
* Do not allow this dataset to be promoted.
Expand All @@ -68,7 +68,7 @@ struct dsl_pool;
*/
#define DS_FLAG_DEFER_DESTROY (1ULL<<3)
#define DS_IS_DEFER_DESTROY(ds) \
((ds)->ds_phys->ds_flags & DS_FLAG_DEFER_DESTROY)
(dsl_dataset_phys(ds)->ds_flags & DS_FLAG_DEFER_DESTROY)

/*
* DS_FIELD_* are strings that are used in the "extensified" dataset zap object.
Expand Down Expand Up @@ -127,7 +127,6 @@ typedef struct dsl_dataset_phys {
typedef struct dsl_dataset {
/* Immutable: */
struct dsl_dir *ds_dir;
dsl_dataset_phys_t *ds_phys;
dmu_buf_t *ds_dbuf;
uint64_t ds_object;
uint64_t ds_fsid_guid;
Expand Down Expand Up @@ -177,17 +176,26 @@ typedef struct dsl_dataset {
char ds_snapname[MAXNAMELEN];
} dsl_dataset_t;

static inline dsl_dataset_phys_t *
dsl_dataset_phys(dsl_dataset_t *ds)
{
return (ds->ds_dbuf->db_data);
}

/*
* The max length of a temporary tag prefix is the number of hex digits
* required to express UINT64_MAX plus one for the hyphen.
*/
#define MAX_TAG_PREFIX_LEN 17

#define dsl_dataset_is_snapshot(ds) \
((ds)->ds_phys->ds_num_children != 0)
static inline boolean_t
dsl_dataset_is_snapshot(dsl_dataset_t *ds)
{
return (dsl_dataset_phys(ds)->ds_num_children != 0);
}

#define DS_UNIQUE_IS_ACCURATE(ds) \
(((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
((dsl_dataset_phys(ds)->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)

int dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
dsl_dataset_t **dsp);
Expand Down
11 changes: 9 additions & 2 deletions include/sys/dsl_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ typedef struct dsl_dir_phys {
struct dsl_dir {
/* These are immutable; no lock needed: */
uint64_t dd_object;
dsl_dir_phys_t *dd_phys;
dmu_buf_t *dd_dbuf;
dsl_pool_t *dd_pool;

/* Stable until user eviction; no lock needed: */
dmu_buf_t *dd_dbuf;

/* protected by lock on pool's dp_dirty_dirs list */
txg_node_t dd_dirty_link;

Expand All @@ -111,6 +112,12 @@ struct dsl_dir {
char dd_myname[MAXNAMELEN];
};

static inline dsl_dir_phys_t *
dsl_dir_phys(dsl_dir_t *dd)
{
return (dd->dd_dbuf->db_data);
}

void dsl_dir_rele(dsl_dir_t *dd, void *tag);
int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
dsl_dir_t **, const char **tail);
Expand Down
19 changes: 14 additions & 5 deletions include/sys/zap_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef struct mzap_ent {
} mzap_ent_t;

#define MZE_PHYS(zap, mze) \
(&(zap)->zap_m.zap_phys->mz_chunk[(mze)->mze_chunkid])
(&zap_m_phys(zap)->mz_chunk[(mze)->mze_chunkid])

/*
* The (fat) zap is stored in one object. It is an array of
Expand Down Expand Up @@ -104,7 +104,7 @@ struct zap_leaf;
* word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
*/
#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
((uint64_t *)(zap)->zap_f.zap_phys) \
((uint64_t *)zap_f_phys(zap)) \
[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]

/*
Expand Down Expand Up @@ -149,8 +149,6 @@ typedef struct zap {
uint64_t zap_salt;
union {
struct {
zap_phys_t *zap_phys;

/*
* zap_num_entries_mtx protects
* zap_num_entries
Expand All @@ -159,7 +157,6 @@ typedef struct zap {
int zap_block_shift;
} zap_fat;
struct {
mzap_phys_t *zap_phys;
int16_t zap_num_entries;
int16_t zap_num_chunks;
int16_t zap_alloc_next;
Expand All @@ -168,6 +165,18 @@ typedef struct zap {
} zap_u;
} zap_t;

static inline zap_phys_t *
zap_f_phys(zap_t *zap)
{
return (zap->zap_dbuf->db_data);
}

static inline mzap_phys_t *
zap_m_phys(zap_t *zap)
{
return (zap->zap_dbuf->db_data);
}

typedef struct zap_name {
zap_t *zn_zap;
int zn_key_intlen;
Expand Down
8 changes: 6 additions & 2 deletions include/sys/zap_leaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct zap_stats;
*/
#define ZAP_LEAF_CHUNK(l, idx) \
((zap_leaf_chunk_t *) \
((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
(zap_leaf_phys(l)->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
#define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry)

typedef enum zap_chunk_type {
Expand Down Expand Up @@ -156,9 +156,13 @@ typedef struct zap_leaf {
uint64_t l_blkid; /* 1<<ZAP_BLOCK_SHIFT byte block off */
int l_bs; /* block size shift */
dmu_buf_t *l_dbuf;
zap_leaf_phys_t *l_phys;
} zap_leaf_t;

static inline zap_leaf_phys_t *
zap_leaf_phys(zap_leaf_t *l)
{
return (l->l_dbuf->db_data);
}

typedef struct zap_entry_handle {
/* Set by zap_leaf and public to ZAP */
Expand Down
33 changes: 5 additions & 28 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ dbuf_cons(void *vdb, void *unused, int kmflag)
mutex_init(&db->db_mtx, NULL, MUTEX_DEFAULT, NULL);
cv_init(&db->db_changed, NULL, CV_DEFAULT, NULL);
refcount_create(&db->db_holds);
list_link_init(&db->db_link);

return (0);
}
Expand Down Expand Up @@ -256,11 +255,8 @@ dbuf_evict_user(dmu_buf_impl_t *db)
if (db->db_level != 0 || db->db_evict_func == NULL)
return;

if (db->db_user_data_ptr_ptr)
*db->db_user_data_ptr_ptr = db->db.db_data;
db->db_evict_func(&db->db, db->db_user_ptr);
db->db_user_ptr = NULL;
db->db_user_data_ptr_ptr = NULL;
db->db_evict_func = NULL;
}

Expand Down Expand Up @@ -474,16 +470,6 @@ dbuf_verify(dmu_buf_impl_t *db)
}
#endif

static void
dbuf_update_data(dmu_buf_impl_t *db)
{
ASSERT(MUTEX_HELD(&db->db_mtx));
if (db->db_level == 0 && db->db_user_data_ptr_ptr) {
ASSERT(!refcount_is_zero(&db->db_holds));
*db->db_user_data_ptr_ptr = db->db.db_data;
}
}

static void
dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
{
Expand All @@ -494,7 +480,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
db->db.db_data = buf->b_data;
if (!arc_released(buf))
arc_set_callback(buf, dbuf_do_evict, db);
dbuf_update_data(db);
} else {
dbuf_evict_user(db);
db->db.db_data = NULL;
Expand Down Expand Up @@ -601,7 +586,6 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t *flags)
if (bonuslen)
bcopy(DN_BONUS(dn->dn_phys), db->db.db_data, bonuslen);
DB_DNODE_EXIT(db);
dbuf_update_data(db);
db->db_state = DB_CACHED;
mutex_exit(&db->db_mtx);
return (0);
Expand Down Expand Up @@ -1806,7 +1790,6 @@ dbuf_create(dnode_t *dn, uint8_t level, uint64_t blkid,
db->db_blkptr = blkptr;

db->db_user_ptr = NULL;
db->db_user_data_ptr_ptr = NULL;
db->db_evict_func = NULL;
db->db_immediate_evict = 0;
db->db_freed_in_flight = 0;
Expand Down Expand Up @@ -2057,7 +2040,6 @@ __dbuf_hold_impl(struct dbuf_hold_impl_data *dh)
}

(void) refcount_add(&dh->dh_db->db_holds, dh->dh_tag);
dbuf_update_data(dh->dh_db);
DBUF_VERIFY(dh->dh_db);
mutex_exit(&dh->dh_db->db_mtx);

Expand Down Expand Up @@ -2347,27 +2329,25 @@ dbuf_refcount(dmu_buf_impl_t *db)
}

void *
dmu_buf_set_user(dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr,
dmu_buf_set_user(dmu_buf_t *db_fake, void *user_ptr,
dmu_buf_evict_func_t *evict_func)
{
return (dmu_buf_update_user(db_fake, NULL, user_ptr,
user_data_ptr_ptr, evict_func));
return (dmu_buf_update_user(db_fake, NULL, user_ptr, evict_func));
}

void *
dmu_buf_set_user_ie(dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr,
dmu_buf_set_user_ie(dmu_buf_t *db_fake, void *user_ptr,
dmu_buf_evict_func_t *evict_func)
{
dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;

db->db_immediate_evict = TRUE;
return (dmu_buf_update_user(db_fake, NULL, user_ptr,
user_data_ptr_ptr, evict_func));
return (dmu_buf_update_user(db_fake, NULL, user_ptr, evict_func));
}

void *
dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr, void *user_ptr,
void *user_data_ptr_ptr, dmu_buf_evict_func_t *evict_func)
dmu_buf_evict_func_t *evict_func)
{
dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
ASSERT(db->db_level == 0);
Expand All @@ -2378,10 +2358,7 @@ dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr, void *user_ptr,

if (db->db_user_ptr == old_user_ptr) {
db->db_user_ptr = user_ptr;
db->db_user_data_ptr_ptr = user_data_ptr_ptr;
db->db_evict_func = evict_func;

dbuf_update_data(db);
} else {
old_user_ptr = db->db_user_ptr;
}
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dmu_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ dmu_diff(const char *tosnap_name, const char *fromsnap_name,
return (SET_ERROR(EXDEV));
}

fromtxg = fromsnap->ds_phys->ds_creation_txg;
fromtxg = dsl_dataset_phys(fromsnap)->ds_creation_txg;
dsl_dataset_rele(fromsnap, FTAG);

dsl_dataset_long_hold(tosnap, FTAG);
Expand Down
Loading

0 comments on commit 29a5ed6

Please sign in to comment.