Skip to content

Commit

Permalink
7003 zap_lockdir() should tag hold
Browse files Browse the repository at this point in the history
zap_lockdir() / zap_unlockdir() should take a "void *tag" argument which
tags the hold on the zap. This will help diagnose programming errors
which misuse the hold on the ZAP.

Sponsored by: Intel Corp.
  • Loading branch information
ahrens committed Aug 15, 2016
1 parent 6d836e6 commit e1a4e9c
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 105 deletions.
2 changes: 2 additions & 0 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ void *dmu_buf_remove_user(dmu_buf_t *db, dmu_buf_user_t *user);
*/
void *dmu_buf_get_user(dmu_buf_t *db);

objset_t *dmu_buf_get_objset(dmu_buf_t *db);

/* Block until any in-progress dmu buf user evictions complete. */
void dmu_buf_user_evict_wait(void);

Expand Down
12 changes: 7 additions & 5 deletions include/sys/zap_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
* Copyright (c) 2013, 2016 by Delphix. All rights reserved.
*/

#ifndef _SYS_ZAP_IMPL_H
Expand Down Expand Up @@ -195,8 +196,8 @@ typedef struct zap_name {

boolean_t zap_match(zap_name_t *zn, const char *matchname);
int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
void zap_unlockdir(zap_t *zap);
krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp);
void zap_unlockdir(zap_t *zap, void *tag);
void zap_evict(void *dbu);
zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
void zap_name_free(zap_name_t *zn);
Expand All @@ -215,9 +216,10 @@ void fzap_prefetch(zap_name_t *zn);
int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
uint64_t *tooverwrite);
int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx);
const void *val, void *tag, dmu_tx_t *tx);
int fzap_update(zap_name_t *zn,
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
int integer_size, uint64_t num_integers, const void *val,
void *tag, dmu_tx_t *tx);
int fzap_length(zap_name_t *zn,
uint64_t *integer_size, uint64_t *num_integers);
int fzap_remove(zap_name_t *zn, dmu_tx_t *tx);
Expand All @@ -227,7 +229,7 @@ void zap_put_leaf(struct zap_leaf *l);

int fzap_add_cd(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, dmu_tx_t *tx);
const void *val, uint32_t cd, void *tag, dmu_tx_t *tx);
void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags);

#ifdef __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,13 @@ dmu_buf_get_blkptr(dmu_buf_t *db)
return (dbi->db_blkptr);
}

objset_t *
dmu_buf_get_objset(dmu_buf_t *db)
{
dmu_buf_impl_t *dbi = (dmu_buf_impl_t *)db;
return (dbi->db_objset);
}

static void
dbuf_check_blkptr(dnode_t *dn, dmu_buf_impl_t *db)
{
Expand Down
33 changes: 18 additions & 15 deletions module/zfs/zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
*/

Expand Down Expand Up @@ -605,7 +605,8 @@ zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
}

static int
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
void *tag, dmu_tx_t *tx, zap_leaf_t **lp)
{
zap_t *zap = zn->zn_zap;
uint64_t hash = zn->zn_hash;
Expand All @@ -627,9 +628,9 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
uint64_t object = zap->zap_object;

zap_put_leaf(l);
zap_unlockdir(zap);
zap_unlockdir(zap, tag);
err = zap_lockdir(os, object, tx, RW_WRITER,
FALSE, FALSE, &zn->zn_zap);
FALSE, FALSE, tag, &zn->zn_zap);
zap = zn->zn_zap;
if (err)
return (err);
Expand Down Expand Up @@ -692,7 +693,8 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
}

static void
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
void *tag, dmu_tx_t *tx)
{
zap_t *zap = zn->zn_zap;
int shift = zap_f_phys(zap)->zap_ptrtbl.zt_shift;
Expand All @@ -712,9 +714,9 @@ zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
objset_t *os = zap->zap_objset;
uint64_t zapobj = zap->zap_object;

zap_unlockdir(zap);
zap_unlockdir(zap, tag);
err = zap_lockdir(os, zapobj, tx,
RW_WRITER, FALSE, FALSE, &zn->zn_zap);
RW_WRITER, FALSE, FALSE, tag, &zn->zn_zap);
zap = zn->zn_zap;
if (err)
return;
Expand Down Expand Up @@ -804,7 +806,7 @@ fzap_lookup(zap_name_t *zn,
int
fzap_add_cd(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, dmu_tx_t *tx)
const void *val, uint32_t cd, void *tag, dmu_tx_t *tx)
{
zap_leaf_t *l;
int err;
Expand Down Expand Up @@ -833,34 +835,35 @@ fzap_add_cd(zap_name_t *zn,
if (err == 0) {
zap_increment_num_entries(zap, 1, tx);
} else if (err == EAGAIN) {
err = zap_expand_leaf(zn, l, tx, &l);
err = zap_expand_leaf(zn, l, tag, tx, &l);
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */
if (err == 0)
goto retry;
}

out:
if (zap != NULL)
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
return (err);
}

int
fzap_add(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx)
const void *val, void *tag, dmu_tx_t *tx)
{
int err = fzap_check(zn, integer_size, num_integers);
if (err != 0)
return (err);

return (fzap_add_cd(zn, integer_size, num_integers,
val, ZAP_NEED_CD, tx));
val, ZAP_NEED_CD, tag, tx));
}

int
fzap_update(zap_name_t *zn,
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
int integer_size, uint64_t num_integers, const void *val,
void *tag, dmu_tx_t *tx)
{
zap_leaf_t *l;
int err, create;
Expand Down Expand Up @@ -890,14 +893,14 @@ fzap_update(zap_name_t *zn,
}

if (err == EAGAIN) {
err = zap_expand_leaf(zn, l, tx, &l);
err = zap_expand_leaf(zn, l, tag, tx, &l);
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */
if (err == 0)
goto retry;
}

if (zap != NULL)
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
return (err);
}

Expand Down
Loading

0 comments on commit e1a4e9c

Please sign in to comment.