Skip to content

Commit 61d13e1

Browse files
robnlundman
authored andcommitted
ZIL: pass commit errors back to ITX callbacks
ITX callbacks are used to signal that something can be cleaned up after a itx is committed. Presently that's only used when syncing out mapped pages (msync()) to mark dirty pages clean. This extends the callback interface so it can be passed an error, and take a different cleanup action if necessary. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Rob Norris <rob.norris@klarasystems.com> Closes openzfs#17398
1 parent 085f86e commit 61d13e1

7 files changed

Lines changed: 18 additions & 16 deletions

File tree

cmd/ztest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ ztest_log_write(ztest_ds_t *zd, dmu_tx_t *tx, lr_write_t *lr)
19951995
dmu_read(zd->zd_os, lr->lr_foid, lr->lr_offset, lr->lr_length,
19961996
((lr_write_t *)&itx->itx_lr) + 1, DMU_READ_NO_PREFETCH |
19971997
DMU_KEEP_CACHING) != 0) {
1998-
zil_itx_destroy(itx);
1998+
zil_itx_destroy(itx, 0);
19991999
itx = zil_itx_create(TX_WRITE, sizeof (*lr));
20002000
write_state = WR_NEED_COPY;
20012001
}

include/sys/zil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ typedef enum {
456456
WR_NUM_STATES /* number of states */
457457
} itx_wr_state_t;
458458

459-
typedef void (*zil_callback_t)(void *data);
459+
typedef void (*zil_callback_t)(void *data, int err);
460460

461461
typedef struct itx {
462462
list_node_t itx_node; /* linkage on zl_itx_list */
@@ -606,7 +606,7 @@ extern boolean_t zil_destroy(zilog_t *zilog, boolean_t keep_first);
606606
extern void zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
607607

608608
extern itx_t *zil_itx_create(uint64_t txtype, size_t lrsize);
609-
extern void zil_itx_destroy(itx_t *itx);
609+
extern void zil_itx_destroy(itx_t *itx, int err);
610610
extern void zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
611611

612612
extern void zil_async_to_sync(zilog_t *zilog, uint64_t oid);

module/os/freebsd/zfs/zfs_vnops_os.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4312,8 +4312,9 @@ typedef struct {
43124312
} putpage_commit_arg_t;
43134313

43144314
static void
4315-
zfs_putpage_commit_cb(void *arg)
4315+
zfs_putpage_commit_cb(void *arg, int err)
43164316
{
4317+
(void) err;
43174318
putpage_commit_arg_t *pca = arg;
43184319
vm_object_t object = pca->pca_pages[0]->object;
43194320

module/os/linux/zfs/zfs_vnops_os.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,6 +3697,7 @@ zfs_link(znode_t *tdzp, znode_t *szp, char *name, cred_t *cr,
36973697
static void
36983698
zfs_putpage_commit_cb(void *arg)
36993699
{
3700+
(void) err;
37003701
struct page *pp = arg;
37013702

37023703
ClearPageError(pp);

module/zfs/zfs_log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
638638
if (zil_replaying(zilog, tx) || zp->z_unlinked ||
639639
zfs_xattr_owner_unlinked(zp)) {
640640
if (callback != NULL)
641-
callback(callback_data);
641+
callback(callback_data, 0);
642642
return;
643643
}
644644

@@ -683,7 +683,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
683683
DMU_KEEP_CACHING);
684684
DB_DNODE_EXIT(db);
685685
if (err != 0) {
686-
zil_itx_destroy(itx);
686+
zil_itx_destroy(itx, 0);
687687
itx = zil_itx_create(txtype, sizeof (*lr));
688688
lr = (lr_write_t *)&itx->itx_lr;
689689
wr_state = WR_NEED_COPY;

module/zfs/zil.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ zil_lwb_flush_vdevs_done(zio_t *zio)
14821482
}
14831483

14841484
while ((itx = list_remove_head(&lwb->lwb_itxs)) != NULL)
1485-
zil_itx_destroy(itx);
1485+
zil_itx_destroy(itx, 0);
14861486

14871487
while ((zcw = list_remove_head(&lwb->lwb_waiters)) != NULL) {
14881488
mutex_enter(&zcw->zcw_lock);
@@ -2468,7 +2468,7 @@ zil_itx_clone(itx_t *oitx)
24682468
}
24692469

24702470
void
2471-
zil_itx_destroy(itx_t *itx)
2471+
zil_itx_destroy(itx_t *itx, int err)
24722472
{
24732473
ASSERT3U(itx->itx_size, >=, sizeof (itx_t));
24742474
ASSERT3U(itx->itx_lr.lrc_reclen, ==,
@@ -2477,7 +2477,7 @@ zil_itx_destroy(itx_t *itx)
24772477
IMPLY(itx->itx_callback != NULL, itx->itx_lr.lrc_txtype != TX_COMMIT);
24782478

24792479
if (itx->itx_callback != NULL)
2480-
itx->itx_callback(itx->itx_callback_data);
2480+
itx->itx_callback(itx->itx_callback_data, err);
24812481

24822482
zio_data_buf_free(itx, itx->itx_size);
24832483
}
@@ -2520,7 +2520,7 @@ zil_itxg_clean(void *arg)
25202520
if (itx->itx_lr.lrc_txtype == TX_COMMIT)
25212521
zil_commit_waiter_skip(itx->itx_private);
25222522

2523-
zil_itx_destroy(itx);
2523+
zil_itx_destroy(itx, 0);
25242524
}
25252525

25262526
cookie = NULL;
@@ -2530,7 +2530,7 @@ zil_itxg_clean(void *arg)
25302530
while ((itx = list_remove_head(list)) != NULL) {
25312531
/* commit itxs should never be on the async lists. */
25322532
ASSERT3U(itx->itx_lr.lrc_txtype, !=, TX_COMMIT);
2533-
zil_itx_destroy(itx);
2533+
zil_itx_destroy(itx, 0);
25342534
}
25352535
list_destroy(list);
25362536
kmem_free(ian, sizeof (itx_async_node_t));
@@ -2592,7 +2592,7 @@ zil_remove_async(zilog_t *zilog, uint64_t oid)
25922592
while ((itx = list_remove_head(&clean_list)) != NULL) {
25932593
/* commit itxs should never be on the async lists. */
25942594
ASSERT3U(itx->itx_lr.lrc_txtype, !=, TX_COMMIT);
2595-
zil_itx_destroy(itx);
2595+
zil_itx_destroy(itx, 0);
25962596
}
25972597
list_destroy(&clean_list);
25982598
}
@@ -2883,7 +2883,7 @@ zil_prune_commit_list(zilog_t *zilog)
28832883
mutex_exit(&zilog->zl_lock);
28842884

28852885
list_remove(&zilog->zl_itx_commit_list, itx);
2886-
zil_itx_destroy(itx);
2886+
zil_itx_destroy(itx, 0);
28872887
}
28882888

28892889
IMPLY(itx != NULL, itx->itx_lr.lrc_txtype != TX_COMMIT);
@@ -3082,7 +3082,7 @@ zil_process_commit_list(zilog_t *zilog, zil_commit_waiter_t *zcw, list_t *ilwbs)
30823082
} else {
30833083
ASSERT3S(lrc->lrc_txtype, !=, TX_COMMIT);
30843084
zilog->zl_cur_left -= zil_itx_full_size(itx);
3085-
zil_itx_destroy(itx);
3085+
zil_itx_destroy(itx, 0);
30863086
}
30873087
}
30883088

@@ -3113,7 +3113,7 @@ zil_process_commit_list(zilog_t *zilog, zil_commit_waiter_t *zcw, list_t *ilwbs)
31133113
* the itx's callback if one exists for the itx.
31143114
*/
31153115
while ((itx = list_remove_head(&nolwb_itxs)) != NULL)
3116-
zil_itx_destroy(itx);
3116+
zil_itx_destroy(itx, 0);
31173117
} else {
31183118
ASSERT(list_is_empty(&nolwb_waiters));
31193119
ASSERT3P(lwb, !=, NULL);

module/zfs/zvol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
903903
if (wr_state == WR_COPIED &&
904904
dmu_read_by_dnode(zv->zv_dn, offset, len, lr + 1,
905905
DMU_READ_NO_PREFETCH | DMU_KEEP_CACHING) != 0) {
906-
zil_itx_destroy(itx);
906+
zil_itx_destroy(itx, 0);
907907
itx = zil_itx_create(TX_WRITE, sizeof (*lr));
908908
lr = (lr_write_t *)&itx->itx_lr;
909909
wr_state = WR_NEED_COPY;

0 commit comments

Comments
 (0)