Skip to content

Commit d683ddb

Browse files
Justin T. Gibbsbehlendorf
authored andcommitted
Illumos 5314 - Remove "dbuf phys" db->db_data pointer aliases in ZFS
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> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
1 parent 945dd93 commit d683ddb

32 files changed

+914
-808
lines changed

cmd/zdb/zdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,8 +1928,8 @@ dump_dir(objset_t *os)
19281928
if (dds.dds_type == DMU_OST_META) {
19291929
dds.dds_creation_txg = TXG_INITIAL;
19301930
usedobjs = BP_GET_FILL(os->os_rootbp);
1931-
refdbytes = os->os_spa->spa_dsl_pool->
1932-
dp_mos_dir->dd_phys->dd_used_bytes;
1931+
refdbytes = dsl_dir_phys(os->os_spa->spa_dsl_pool->dp_mos_dir)->
1932+
dd_used_bytes;
19331933
} else {
19341934
dmu_objset_space(os, &refdbytes, &scratch, &usedobjs, &scratch);
19351935
}

include/sys/dbuf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ typedef struct dmu_buf_impl {
228228

229229
/* stuff we store for the user (see dmu_buf_set_user) */
230230
void *db_user_ptr;
231-
void **db_user_data_ptr_ptr;
232231
dmu_buf_evict_func_t *db_evict_func;
233232

234233
uint8_t db_immediate_evict;

include/sys/dmu.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,30 +481,23 @@ void dmu_buf_rele_array(dmu_buf_t **, int numbufs, void *tag);
481481
*
482482
* user_ptr is for use by the user and can be obtained via dmu_buf_get_user().
483483
*
484-
* user_data_ptr_ptr should be NULL, or a pointer to a pointer which
485-
* will be set to db->db_data when you are allowed to access it. Note
486-
* that db->db_data (the pointer) can change when you do dmu_buf_read(),
487-
* dmu_buf_tryupgrade(), dmu_buf_will_dirty(), or dmu_buf_will_fill().
488-
* *user_data_ptr_ptr will be set to the new value when it changes.
489-
*
490484
* If non-NULL, pageout func will be called when this buffer is being
491485
* excised from the cache, so that you can clean up the data structure
492486
* pointed to by user_ptr.
493487
*
494488
* dmu_evict_user() will call the pageout func for all buffers in a
495489
* objset with a given pageout func.
496490
*/
497-
void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr, void *user_data_ptr_ptr,
491+
void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr,
498492
dmu_buf_evict_func_t *pageout_func);
499493
/*
500494
* set_user_ie is the same as set_user, but request immediate eviction
501495
* when hold count goes to zero.
502496
*/
503497
void *dmu_buf_set_user_ie(dmu_buf_t *db, void *user_ptr,
504-
void *user_data_ptr_ptr, dmu_buf_evict_func_t *pageout_func);
505-
void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr,
506-
void *user_ptr, void *user_data_ptr_ptr,
507498
dmu_buf_evict_func_t *pageout_func);
499+
void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr,
500+
void *user_ptr, dmu_buf_evict_func_t *pageout_func);
508501
void dmu_evict_user(objset_t *os, dmu_buf_evict_func_t *func);
509502

510503
/*

include/sys/dsl_dataset.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct dsl_pool;
4848

4949
#define DS_FLAG_INCONSISTENT (1ULL<<0)
5050
#define DS_IS_INCONSISTENT(ds) \
51-
((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
51+
(dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT)
5252

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

7373
/*
7474
* DS_FIELD_* are strings that are used in the "extensified" dataset zap object.
@@ -127,7 +127,6 @@ typedef struct dsl_dataset_phys {
127127
typedef struct dsl_dataset {
128128
/* Immutable: */
129129
struct dsl_dir *ds_dir;
130-
dsl_dataset_phys_t *ds_phys;
131130
dmu_buf_t *ds_dbuf;
132131
uint64_t ds_object;
133132
uint64_t ds_fsid_guid;
@@ -177,17 +176,26 @@ typedef struct dsl_dataset {
177176
char ds_snapname[MAXNAMELEN];
178177
} dsl_dataset_t;
179178

179+
static inline dsl_dataset_phys_t *
180+
dsl_dataset_phys(dsl_dataset_t *ds)
181+
{
182+
return (ds->ds_dbuf->db_data);
183+
}
184+
180185
/*
181186
* The max length of a temporary tag prefix is the number of hex digits
182187
* required to express UINT64_MAX plus one for the hyphen.
183188
*/
184189
#define MAX_TAG_PREFIX_LEN 17
185190

186-
#define dsl_dataset_is_snapshot(ds) \
187-
((ds)->ds_phys->ds_num_children != 0)
191+
static inline boolean_t
192+
dsl_dataset_is_snapshot(dsl_dataset_t *ds)
193+
{
194+
return (dsl_dataset_phys(ds)->ds_num_children != 0);
195+
}
188196

189197
#define DS_UNIQUE_IS_ACCURATE(ds) \
190-
(((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
198+
((dsl_dataset_phys(ds)->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
191199

192200
int dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
193201
dsl_dataset_t **dsp);

include/sys/dsl_dir.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ typedef struct dsl_dir_phys {
8686
struct dsl_dir {
8787
/* These are immutable; no lock needed: */
8888
uint64_t dd_object;
89-
dsl_dir_phys_t *dd_phys;
90-
dmu_buf_t *dd_dbuf;
9189
dsl_pool_t *dd_pool;
9290

91+
/* Stable until user eviction; no lock needed: */
92+
dmu_buf_t *dd_dbuf;
93+
9394
/* protected by lock on pool's dp_dirty_dirs list */
9495
txg_node_t dd_dirty_link;
9596

@@ -111,6 +112,12 @@ struct dsl_dir {
111112
char dd_myname[MAXNAMELEN];
112113
};
113114

115+
static inline dsl_dir_phys_t *
116+
dsl_dir_phys(dsl_dir_t *dd)
117+
{
118+
return (dd->dd_dbuf->db_data);
119+
}
120+
114121
void dsl_dir_rele(dsl_dir_t *dd, void *tag);
115122
int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
116123
dsl_dir_t **, const char **tail);

include/sys/zap_impl.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef struct mzap_ent {
7070
} mzap_ent_t;
7171

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

7575
/*
7676
* The (fat) zap is stored in one object. It is an array of
@@ -104,7 +104,7 @@ struct zap_leaf;
104104
* word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
105105
*/
106106
#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
107-
((uint64_t *)(zap)->zap_f.zap_phys) \
107+
((uint64_t *)zap_f_phys(zap)) \
108108
[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
109109

110110
/*
@@ -149,8 +149,6 @@ typedef struct zap {
149149
uint64_t zap_salt;
150150
union {
151151
struct {
152-
zap_phys_t *zap_phys;
153-
154152
/*
155153
* zap_num_entries_mtx protects
156154
* zap_num_entries
@@ -159,7 +157,6 @@ typedef struct zap {
159157
int zap_block_shift;
160158
} zap_fat;
161159
struct {
162-
mzap_phys_t *zap_phys;
163160
int16_t zap_num_entries;
164161
int16_t zap_num_chunks;
165162
int16_t zap_alloc_next;
@@ -168,6 +165,18 @@ typedef struct zap {
168165
} zap_u;
169166
} zap_t;
170167

168+
static inline zap_phys_t *
169+
zap_f_phys(zap_t *zap)
170+
{
171+
return (zap->zap_dbuf->db_data);
172+
}
173+
174+
static inline mzap_phys_t *
175+
zap_m_phys(zap_t *zap)
176+
{
177+
return (zap->zap_dbuf->db_data);
178+
}
179+
171180
typedef struct zap_name {
172181
zap_t *zn_zap;
173182
int zn_key_intlen;

include/sys/zap_leaf.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct zap_stats;
8383
*/
8484
#define ZAP_LEAF_CHUNK(l, idx) \
8585
((zap_leaf_chunk_t *) \
86-
((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
86+
(zap_leaf_phys(l)->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
8787
#define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry)
8888

8989
typedef enum zap_chunk_type {
@@ -156,9 +156,13 @@ typedef struct zap_leaf {
156156
uint64_t l_blkid; /* 1<<ZAP_BLOCK_SHIFT byte block off */
157157
int l_bs; /* block size shift */
158158
dmu_buf_t *l_dbuf;
159-
zap_leaf_phys_t *l_phys;
160159
} zap_leaf_t;
161160

161+
static inline zap_leaf_phys_t *
162+
zap_leaf_phys(zap_leaf_t *l)
163+
{
164+
return (l->l_dbuf->db_data);
165+
}
162166

163167
typedef struct zap_entry_handle {
164168
/* Set by zap_leaf and public to ZAP */

module/zfs/dbuf.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,8 @@ dbuf_evict_user(dmu_buf_impl_t *db)
255255
if (db->db_level != 0 || db->db_evict_func == NULL)
256256
return;
257257

258-
if (db->db_user_data_ptr_ptr)
259-
*db->db_user_data_ptr_ptr = db->db.db_data;
260258
db->db_evict_func(&db->db, db->db_user_ptr);
261259
db->db_user_ptr = NULL;
262-
db->db_user_data_ptr_ptr = NULL;
263260
db->db_evict_func = NULL;
264261
}
265262

@@ -473,16 +470,6 @@ dbuf_verify(dmu_buf_impl_t *db)
473470
}
474471
#endif
475472

476-
static void
477-
dbuf_update_data(dmu_buf_impl_t *db)
478-
{
479-
ASSERT(MUTEX_HELD(&db->db_mtx));
480-
if (db->db_level == 0 && db->db_user_data_ptr_ptr) {
481-
ASSERT(!refcount_is_zero(&db->db_holds));
482-
*db->db_user_data_ptr_ptr = db->db.db_data;
483-
}
484-
}
485-
486473
static void
487474
dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
488475
{
@@ -493,7 +480,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
493480
db->db.db_data = buf->b_data;
494481
if (!arc_released(buf))
495482
arc_set_callback(buf, dbuf_do_evict, db);
496-
dbuf_update_data(db);
497483
} else {
498484
dbuf_evict_user(db);
499485
db->db.db_data = NULL;
@@ -600,7 +586,6 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t *flags)
600586
if (bonuslen)
601587
bcopy(DN_BONUS(dn->dn_phys), db->db.db_data, bonuslen);
602588
DB_DNODE_EXIT(db);
603-
dbuf_update_data(db);
604589
db->db_state = DB_CACHED;
605590
mutex_exit(&db->db_mtx);
606591
return (0);
@@ -1801,7 +1786,6 @@ dbuf_create(dnode_t *dn, uint8_t level, uint64_t blkid,
18011786
db->db_blkptr = blkptr;
18021787

18031788
db->db_user_ptr = NULL;
1804-
db->db_user_data_ptr_ptr = NULL;
18051789
db->db_evict_func = NULL;
18061790
db->db_immediate_evict = 0;
18071791
db->db_freed_in_flight = 0;
@@ -2052,7 +2036,6 @@ __dbuf_hold_impl(struct dbuf_hold_impl_data *dh)
20522036
}
20532037

20542038
(void) refcount_add(&dh->dh_db->db_holds, dh->dh_tag);
2055-
dbuf_update_data(dh->dh_db);
20562039
DBUF_VERIFY(dh->dh_db);
20572040
mutex_exit(&dh->dh_db->db_mtx);
20582041

@@ -2342,27 +2325,25 @@ dbuf_refcount(dmu_buf_impl_t *db)
23422325
}
23432326

23442327
void *
2345-
dmu_buf_set_user(dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr,
2328+
dmu_buf_set_user(dmu_buf_t *db_fake, void *user_ptr,
23462329
dmu_buf_evict_func_t *evict_func)
23472330
{
2348-
return (dmu_buf_update_user(db_fake, NULL, user_ptr,
2349-
user_data_ptr_ptr, evict_func));
2331+
return (dmu_buf_update_user(db_fake, NULL, user_ptr, evict_func));
23502332
}
23512333

23522334
void *
2353-
dmu_buf_set_user_ie(dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr,
2335+
dmu_buf_set_user_ie(dmu_buf_t *db_fake, void *user_ptr,
23542336
dmu_buf_evict_func_t *evict_func)
23552337
{
23562338
dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
23572339

23582340
db->db_immediate_evict = TRUE;
2359-
return (dmu_buf_update_user(db_fake, NULL, user_ptr,
2360-
user_data_ptr_ptr, evict_func));
2341+
return (dmu_buf_update_user(db_fake, NULL, user_ptr, evict_func));
23612342
}
23622343

23632344
void *
23642345
dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr, void *user_ptr,
2365-
void *user_data_ptr_ptr, dmu_buf_evict_func_t *evict_func)
2346+
dmu_buf_evict_func_t *evict_func)
23662347
{
23672348
dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
23682349
ASSERT(db->db_level == 0);
@@ -2373,10 +2354,7 @@ dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr, void *user_ptr,
23732354

23742355
if (db->db_user_ptr == old_user_ptr) {
23752356
db->db_user_ptr = user_ptr;
2376-
db->db_user_data_ptr_ptr = user_data_ptr_ptr;
23772357
db->db_evict_func = evict_func;
2378-
2379-
dbuf_update_data(db);
23802358
} else {
23812359
old_user_ptr = db->db_user_ptr;
23822360
}

module/zfs/dmu_diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ dmu_diff(const char *tosnap_name, const char *fromsnap_name,
194194
return (SET_ERROR(EXDEV));
195195
}
196196

197-
fromtxg = fromsnap->ds_phys->ds_creation_txg;
197+
fromtxg = dsl_dataset_phys(fromsnap)->ds_creation_txg;
198198
dsl_dataset_rele(fromsnap, FTAG);
199199

200200
dsl_dataset_long_hold(tosnap, FTAG);

0 commit comments

Comments
 (0)