Skip to content

Commit

Permalink
fix some assign arc buf with brt clone and O_TRUNC
Browse files Browse the repository at this point in the history
this fixes some bugs when opening a file wiht O_TRUNC
and writing to the same file at the same time with
`dd` for example. O_TRUNC in the VFS calls
set_attr and set_attr will figure out a trunc
based on the O_TRUNC flag.
dmu_free_long_range_impl will free the data after
that. If a reflink is and write is running at the
same time it will fail with:
kernel:VERIFY(db->db_state == DB_CACHED ||
db->db_state == DB_UNCACHED) failed
kernel:PANIC at dbuf.c:2925:dbuf_assign_arcbuf()

Signed-off-by: Kay Pedersen <[email protected]>
  • Loading branch information
oromenahar committed Aug 1, 2023
1 parent a5fdba1 commit a1a87b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,19 +915,6 @@ dmu_free_long_range_impl(objset_t *os, dnode_t *dn, uint64_t offset,
dp->dp_long_free_dirty_pertxg[txg & TXG_MASK];
mutex_exit(&dp->dp_lock);

/*
* To avoid filling up a TXG with just frees, wait for
* the next TXG to open before freeing more chunks if
* we have reached the threshold of frees.
*/
if (dirty_frees_threshold != 0 &&
long_free_dirty >= dirty_frees_threshold) {
DMU_TX_STAT_BUMP(dmu_tx_dirty_frees_delay);
dmu_tx_commit(tx);
txg_wait_open(dp, 0, B_TRUE);
continue;
}

/*
* In order to prevent unnecessary write throttling, for each
* TXG, we track the cumulative size of L1 blocks being dirtied
Expand All @@ -947,6 +934,19 @@ dmu_free_long_range_impl(objset_t *os, dnode_t *dn, uint64_t offset,
uint64_t, txg);
dnode_free_range(dn, chunk_begin, chunk_len, tx);

/*
* To avoid filling up a TXG with just frees, wait for
* the next TXG to open before freeing more chunks if
* we have reached the threshold of frees.
*/
if (dirty_frees_threshold != 0 &&
long_free_dirty >= dirty_frees_threshold) {
DMU_TX_STAT_BUMP(dmu_tx_dirty_frees_delay);
dmu_tx_commit(tx);
txg_wait_open(dp, 0, B_TRUE);
continue;
}

dmu_tx_commit(tx);

length -= chunk_len;
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/cmd/clonefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ main(int argc, char **argv)
return (1);
}

int dfd = open(argv[optind+1], O_WRONLY|O_CREAT,
int dfd = open(argv[optind+1], O_WRONLY|O_TRUNC,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (dfd < 0) {
fprintf(stderr, "open: %s: %s\n",
Expand Down

0 comments on commit a1a87b2

Please sign in to comment.