Skip to content

Commit 8bea981

Browse files
ahrensbehlendorf
authored andcommitted
OpenZFS 7003 - zap_lockdir() should tag hold
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. Signed-off-by: Matthew Ahrens <mahrens@delphix.com> Signed-off-by: Pavel Zakharov <pavel.zakha@gmail.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> OpenZFS-issue: https://www.illumos.org/issues/7003 OpenZFS-commit: openzfs/openzfs#108 Closes #4972
1 parent ee6370a commit 8bea981

File tree

5 files changed

+154
-106
lines changed

5 files changed

+154
-106
lines changed

include/sys/dmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ void *dmu_buf_remove_user(dmu_buf_t *db, dmu_buf_user_t *user);
619619
*/
620620
void *dmu_buf_get_user(dmu_buf_t *db);
621621

622+
objset_t *dmu_buf_get_objset(dmu_buf_t *db);
623+
622624
/* Block until any in-progress dmu buf user evictions complete. */
623625
void dmu_buf_user_evict_wait(void);
624626

include/sys/zap_impl.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/*
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2323
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
24+
* Copyright (c) 2013, 2016 by Delphix. All rights reserved.
2425
*/
2526

2627
#ifndef _SYS_ZAP_IMPL_H
@@ -195,8 +196,8 @@ typedef struct zap_name {
195196

196197
boolean_t zap_match(zap_name_t *zn, const char *matchname);
197198
int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
198-
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
199-
void zap_unlockdir(zap_t *zap);
199+
krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp);
200+
void zap_unlockdir(zap_t *zap, void *tag);
200201
void zap_evict(void *dbu);
201202
zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
202203
void zap_name_free(zap_name_t *zn);
@@ -215,9 +216,10 @@ void fzap_prefetch(zap_name_t *zn);
215216
int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
216217
uint64_t *tooverwrite);
217218
int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
218-
const void *val, dmu_tx_t *tx);
219+
const void *val, void *tag, dmu_tx_t *tx);
219220
int fzap_update(zap_name_t *zn,
220-
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
221+
int integer_size, uint64_t num_integers, const void *val,
222+
void *tag, dmu_tx_t *tx);
221223
int fzap_length(zap_name_t *zn,
222224
uint64_t *integer_size, uint64_t *num_integers);
223225
int fzap_remove(zap_name_t *zn, dmu_tx_t *tx);
@@ -227,7 +229,7 @@ void zap_put_leaf(struct zap_leaf *l);
227229

228230
int fzap_add_cd(zap_name_t *zn,
229231
uint64_t integer_size, uint64_t num_integers,
230-
const void *val, uint32_t cd, dmu_tx_t *tx);
232+
const void *val, uint32_t cd, void *tag, dmu_tx_t *tx);
231233
void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags);
232234

233235
#ifdef __cplusplus

module/zfs/dbuf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,13 @@ dmu_buf_get_blkptr(dmu_buf_t *db)
28362836
return (dbi->db_blkptr);
28372837
}
28382838

2839+
objset_t *
2840+
dmu_buf_get_objset(dmu_buf_t *db)
2841+
{
2842+
dmu_buf_impl_t *dbi = (dmu_buf_impl_t *)db;
2843+
return (dbi->db_objset);
2844+
}
2845+
28392846
static void
28402847
dbuf_check_blkptr(dnode_t *dn, dmu_buf_impl_t *db)
28412848
{

module/zfs/zap.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
/*
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23-
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
23+
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
2424
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
2525
*/
2626

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

607607
static int
608-
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
608+
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
609+
void *tag, dmu_tx_t *tx, zap_leaf_t **lp)
609610
{
610611
zap_t *zap = zn->zn_zap;
611612
uint64_t hash = zn->zn_hash;
@@ -627,9 +628,9 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
627628
uint64_t object = zap->zap_object;
628629

629630
zap_put_leaf(l);
630-
zap_unlockdir(zap);
631+
zap_unlockdir(zap, tag);
631632
err = zap_lockdir(os, object, tx, RW_WRITER,
632-
FALSE, FALSE, &zn->zn_zap);
633+
FALSE, FALSE, tag, &zn->zn_zap);
633634
zap = zn->zn_zap;
634635
if (err)
635636
return (err);
@@ -692,7 +693,8 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
692693
}
693694

694695
static void
695-
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
696+
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
697+
void *tag, dmu_tx_t *tx)
696698
{
697699
zap_t *zap = zn->zn_zap;
698700
int shift = zap_f_phys(zap)->zap_ptrtbl.zt_shift;
@@ -712,9 +714,9 @@ zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
712714
objset_t *os = zap->zap_objset;
713715
uint64_t zapobj = zap->zap_object;
714716

715-
zap_unlockdir(zap);
717+
zap_unlockdir(zap, tag);
716718
err = zap_lockdir(os, zapobj, tx,
717-
RW_WRITER, FALSE, FALSE, &zn->zn_zap);
719+
RW_WRITER, FALSE, FALSE, tag, &zn->zn_zap);
718720
zap = zn->zn_zap;
719721
if (err)
720722
return;
@@ -804,7 +806,7 @@ fzap_lookup(zap_name_t *zn,
804806
int
805807
fzap_add_cd(zap_name_t *zn,
806808
uint64_t integer_size, uint64_t num_integers,
807-
const void *val, uint32_t cd, dmu_tx_t *tx)
809+
const void *val, uint32_t cd, void *tag, dmu_tx_t *tx)
808810
{
809811
zap_leaf_t *l;
810812
int err;
@@ -833,34 +835,35 @@ fzap_add_cd(zap_name_t *zn,
833835
if (err == 0) {
834836
zap_increment_num_entries(zap, 1, tx);
835837
} else if (err == EAGAIN) {
836-
err = zap_expand_leaf(zn, l, tx, &l);
838+
err = zap_expand_leaf(zn, l, tag, tx, &l);
837839
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */
838840
if (err == 0)
839841
goto retry;
840842
}
841843

842844
out:
843845
if (zap != NULL)
844-
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
846+
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
845847
return (err);
846848
}
847849

848850
int
849851
fzap_add(zap_name_t *zn,
850852
uint64_t integer_size, uint64_t num_integers,
851-
const void *val, dmu_tx_t *tx)
853+
const void *val, void *tag, dmu_tx_t *tx)
852854
{
853855
int err = fzap_check(zn, integer_size, num_integers);
854856
if (err != 0)
855857
return (err);
856858

857859
return (fzap_add_cd(zn, integer_size, num_integers,
858-
val, ZAP_NEED_CD, tx));
860+
val, ZAP_NEED_CD, tag, tx));
859861
}
860862

861863
int
862864
fzap_update(zap_name_t *zn,
863-
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
865+
int integer_size, uint64_t num_integers, const void *val,
866+
void *tag, dmu_tx_t *tx)
864867
{
865868
zap_leaf_t *l;
866869
int err, create;
@@ -890,14 +893,14 @@ fzap_update(zap_name_t *zn,
890893
}
891894

892895
if (err == EAGAIN) {
893-
err = zap_expand_leaf(zn, l, tx, &l);
896+
err = zap_expand_leaf(zn, l, tag, tx, &l);
894897
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */
895898
if (err == 0)
896899
goto retry;
897900
}
898901

899902
if (zap != NULL)
900-
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
903+
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
901904
return (err);
902905
}
903906

0 commit comments

Comments
 (0)