Skip to content

Commit

Permalink
OpenZFS 7580 - ztest failure in dbuf_read_impl
Browse files Browse the repository at this point in the history
Authored by: George Wilson <[email protected]>
Reviewed by: Pavel Zakharov <[email protected]>
Reviewed by: Steve Gonczi <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
We need to prevent any reader whenever we're about the zero out all the
blkptrs. To do this we need to grab the dn_struct_rwlock as writer in
dbuf_write_children_ready and free_children just prior to calling bzero.
Closes openzfs#237
Ported-by: George Melikov <[email protected]>

OpenZFS-issue: https://www.illumos.org/issues/7580
OpenZFS-commit: openzfs/openzfs@3105d95
  • Loading branch information
grwilson authored and gmelikov committed Jan 27, 2017
1 parent 258553d commit 46c4d7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 9 additions & 3 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3514,13 +3514,13 @@ dbuf_write_children_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
dmu_buf_impl_t *db = vdb;
dnode_t *dn;
blkptr_t *bp;
uint64_t i;
int epbs;
unsigned int epbs, i;

ASSERT3U(db->db_level, >, 0);
DB_DNODE_ENTER(db);
dn = DB_DNODE(db);
epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
ASSERT3U(epbs, <, 31);

/* Determine if all our children are holes */
for (i = 0, bp = db->db.db_data; i < 1ULL << epbs; i++, bp++) {
Expand All @@ -3533,8 +3533,14 @@ dbuf_write_children_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
* we may get compressed away.
*/
if (i == 1ULL << epbs) {
/* didn't find any non-holes */
/*
* We only found holes. Grab the rwlock to prevent
* anybody from reading the blocks we're about to
* zero out.
*/
rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
bzero(db->db.db_data, db->db.db_size);
rw_exit(&dn->dn_struct_rwlock);
}
DB_DNODE_EXIT(db);
}
Expand Down
18 changes: 13 additions & 5 deletions module/zfs/dnode_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
dnode_t *dn;
blkptr_t *bp;
dmu_buf_impl_t *subdb;
uint64_t start, end, dbstart, dbend, i;
int epbs, shift;
uint64_t start, end, dbstart, dbend;
unsigned int epbs, shift, i;
uint64_t id;

/*
* There is a small possibility that this block will not be cached:
Expand All @@ -258,6 +259,7 @@ free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
DB_DNODE_ENTER(db);
dn = DB_DNODE(db);
epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
ASSERT3U(epbs, <, 31);
shift = (db->db_level - 1) * epbs;
dbstart = db->db_blkid << epbs;
start = blkid >> shift;
Expand All @@ -277,12 +279,12 @@ free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
FREE_VERIFY(db, start, end, tx);
free_blocks(dn, bp, end-start+1, tx);
} else {
for (i = start; i <= end; i++, bp++) {
for (id = start; id <= end; id++, bp++) {
if (BP_IS_HOLE(bp))
continue;
rw_enter(&dn->dn_struct_rwlock, RW_READER);
VERIFY0(dbuf_hold_impl(dn, db->db_level - 1,
i, TRUE, FALSE, FTAG, &subdb));
id, TRUE, FALSE, FTAG, &subdb));
rw_exit(&dn->dn_struct_rwlock);
ASSERT3P(bp, ==, subdb->db_blkptr);

Expand All @@ -297,8 +299,14 @@ free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
break;
}
if (i == 1 << epbs) {
/* didn't find any non-holes */
/*
* We only found holes. Grab the rwlock to prevent
* anybody from reading the blocks we're about to
* zero out.
*/
rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
bzero(db->db.db_data, db->db.db_size);
rw_exit(&dn->dn_struct_rwlock);
free_blocks(dn, db->db_blkptr, 1, tx);
} else {
/*
Expand Down

0 comments on commit 46c4d7b

Please sign in to comment.