Skip to content

Commit

Permalink
5314 Remove "dbuf phys" db->db_data pointer aliases in ZFS
Browse files Browse the repository at this point in the history
Reviewed by: Andriy Gapon <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: Will Andrews <[email protected]>
Approved by: Dan McDonald <[email protected]>
  • Loading branch information
Justin T. Gibbs authored and Dan McDonald committed Dec 4, 2014
1 parent 2dc692e commit c137962
Show file tree
Hide file tree
Showing 43 changed files with 968 additions and 809 deletions.
32 changes: 32 additions & 0 deletions usr/src/cmd/mdb/common/modules/zfs/Makefile.zfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2014 Spectra Logic Corporation. All rights reserved.
# Use is subject to license terms.
#

# lint complains about unused inline functions, even though
# they are "inline", not "static inline", with "extern inline"
# implementations provided where needed in libraries and the
# kernel.
LINTFLAGS += -erroff=E_STATIC_UNUSED
LINTFLAGS64 += -erroff=E_STATIC_UNUSED
4 changes: 3 additions & 1 deletion usr/src/cmd/mdb/common/modules/zfs/zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
char buf[16*1024];
int verbose = B_FALSE;
int four = B_FALSE;
dmu_buf_t l_dbuf;
zap_leaf_t l;
zap_leaf_phys_t *zlp = (void *)buf;
int i;
Expand All @@ -601,7 +602,8 @@ zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
NULL) != argc)
return (DCMD_USAGE);

l.l_phys = zlp;
l_dbuf.db_data = zlp;
l.l_dbuf = &l_dbuf;
l.l_bs = 14; /* assume 16k blocks */
if (four)
l.l_bs = 12;
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/intel/amd64/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include ../../../../Makefile.cmd
include ../../../../Makefile.cmd.64
include ../../Makefile.amd64
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/intel/amd64/zfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include ../../../../Makefile.cmd
include ../../../../Makefile.cmd.64
include ../../Makefile.amd64
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

CPPFLAGS += -I../../../../../uts/common/fs/zfs

Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/intel/ia32/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ MODSRCS = zfs.c list.c
include ../../../../Makefile.cmd
include ../../Makefile.ia32
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/intel/ia32/zfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ MODSRCS = zfs.c
include ../../../../Makefile.cmd
include ../../Makefile.ia32
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

CPPFLAGS += -I../../../../../uts/common/fs/zfs

Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/sparc/v7/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ MODSRCS = zfs.c list.c
include ../../../../Makefile.cmd
include ../../Makefile.sparcv7
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/sparc/v9/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include ../../../../Makefile.cmd
include ../../../../Makefile.cmd.64
include ../../Makefile.sparcv9
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/mdb/sparc/v9/zfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include ../../../../Makefile.cmd
include ../../../../Makefile.cmd.64
include ../../Makefile.sparcv9
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

CPPFLAGS += -I../../../../../uts/common/fs/zfs

Expand Down
6 changes: 6 additions & 0 deletions usr/src/cmd/zdb/Makefile.com
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ CERRWARN += -_gcc=-Wno-uninitialized
LINTFLAGS += -xerroff=E_NAME_DEF_NOT_USED2
LINTFLAGS64 += -xerroff=E_NAME_DEF_NOT_USED2

# lint complains about unused inline functions, even though
# they are "inline", not "static inline", with "extern inline"
# implementations and usage in libzpool.
LINTFLAGS += -erroff=E_STATIC_UNUSED
LINTFLAGS64 += -erroff=E_STATIC_UNUSED

.KEEP_STATE:

all: $(PROG)
Expand Down
4 changes: 2 additions & 2 deletions usr/src/cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1857,8 +1857,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
6 changes: 6 additions & 0 deletions usr/src/cmd/ztest/Makefile.com
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT $(INCS) -DDEBUG
LINTFLAGS += -xerroff=E_NAME_DEF_NOT_USED2
LINTFLAGS64 += -xerroff=E_NAME_DEF_NOT_USED2

# lint complains about unused inline functions, even though
# they are "inline", not "static inline", with "extern inline"
# implementations and usage in libzpool.
LINTFLAGS += -erroff=E_STATIC_UNUSED
LINTFLAGS64 += -erroff=E_STATIC_UNUSED

CERRWARN += -_gcc=-Wno-switch

.KEEP_STATE:
Expand Down
32 changes: 5 additions & 27 deletions usr/src/uts/common/fs/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,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 @@ -417,16 +414,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 @@ -437,7 +424,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 @@ -543,7 +529,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;
Expand Down Expand Up @@ -1726,7 +1711,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 @@ -1971,7 +1955,6 @@ dbuf_hold_impl(dnode_t *dn, uint8_t level, uint64_t blkid, int fail_sparse,
}

(void) refcount_add(&db->db_holds, tag);
dbuf_update_data(db);
DBUF_VERIFY(db);
mutex_exit(&db->db_mtx);

Expand Down Expand Up @@ -2182,27 +2165,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 @@ -2213,10 +2194,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 usr/src/uts/common/fs/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
30 changes: 17 additions & 13 deletions usr/src/uts/common/fs/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,12 @@ dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen,
dsl_dataset_t *ds = os->os_dsl_dataset;
uint64_t ignored;

if (ds->ds_phys->ds_snapnames_zapobj == 0)
if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0)
return (SET_ERROR(ENOENT));

return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset,
ds->ds_phys->ds_snapnames_zapobj, name, 8, 1, &ignored, MT_FIRST,
real, maxlen, conflict));
dsl_dataset_phys(ds)->ds_snapnames_zapobj, name, 8, 1, &ignored,
MT_FIRST, real, maxlen, conflict));
}

int
Expand All @@ -1497,12 +1497,12 @@ dmu_snapshot_list_next(objset_t *os, int namelen, char *name,

ASSERT(dsl_pool_config_held(dmu_objset_pool(os)));

if (ds->ds_phys->ds_snapnames_zapobj == 0)
if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0)
return (SET_ERROR(ENOENT));

zap_cursor_init_serialized(&cursor,
ds->ds_dir->dd_pool->dp_meta_objset,
ds->ds_phys->ds_snapnames_zapobj, *offp);
dsl_dataset_phys(ds)->ds_snapnames_zapobj, *offp);

if (zap_cursor_retrieve(&cursor, &attr) != 0) {
zap_cursor_fini(&cursor);
Expand Down Expand Up @@ -1536,12 +1536,12 @@ dmu_dir_list_next(objset_t *os, int namelen, char *name,

/* there is no next dir on a snapshot! */
if (os->os_dsl_dataset->ds_object !=
dd->dd_phys->dd_head_dataset_obj)
dsl_dir_phys(dd)->dd_head_dataset_obj)
return (SET_ERROR(ENOENT));

zap_cursor_init_serialized(&cursor,
dd->dd_pool->dp_meta_objset,
dd->dd_phys->dd_child_dir_zapobj, *offp);
dsl_dir_phys(dd)->dd_child_dir_zapobj, *offp);

if (zap_cursor_retrieve(&cursor, &attr) != 0) {
zap_cursor_fini(&cursor);
Expand Down Expand Up @@ -1589,15 +1589,15 @@ dmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj,
return (0);
}

thisobj = dd->dd_phys->dd_head_dataset_obj;
thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);

/*
* Iterate over all children.
*/
if (flags & DS_FIND_CHILDREN) {
for (zap_cursor_init(&zc, dp->dp_meta_objset,
dd->dd_phys->dd_child_dir_zapobj);
dsl_dir_phys(dd)->dd_child_dir_zapobj);
zap_cursor_retrieve(&zc, attr) == 0;
(void) zap_cursor_advance(&zc)) {
ASSERT3U(attr->za_integer_length, ==,
Expand Down Expand Up @@ -1626,7 +1626,9 @@ dmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj,
err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);

if (err == 0) {
uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj;
uint64_t snapobj;

snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj;
dsl_dataset_rele(ds, FTAG);

for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
Expand Down Expand Up @@ -1701,15 +1703,15 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
return (0);
}

thisobj = dd->dd_phys->dd_head_dataset_obj;
thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);

/*
* Iterate over all children.
*/
if (flags & DS_FIND_CHILDREN) {
for (zap_cursor_init(&zc, dp->dp_meta_objset,
dd->dd_phys->dd_child_dir_zapobj);
dsl_dir_phys(dd)->dd_child_dir_zapobj);
zap_cursor_retrieve(&zc, attr) == 0;
(void) zap_cursor_advance(&zc)) {
ASSERT3U(attr->za_integer_length, ==,
Expand Down Expand Up @@ -1742,7 +1744,9 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);

if (err == 0) {
uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj;
uint64_t snapobj;

snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj;
dsl_dataset_rele(ds, FTAG);

for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
Expand Down
Loading

0 comments on commit c137962

Please sign in to comment.