#include <sys/spa.h>
#include <sys/zfs_fuid.h>
#include <sys/ddi.h>
+#include <sys/dsl_dataset.h>
+
+#define ZFS_HANDLE_REPLAY(zilog, tx) \
+ if (zilog->zl_replay) { \
+ dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx); \
+ zilog->zl_replayed_seq[dmu_tx_get_txg(tx) & TXG_MASK] = \
+ zilog->zl_replaying_seq; \
+ return; \
+ }
/*
- * All the functions in this file are used to construct the log entries
- * to record transactions. They allocate * an intent log transaction
- * structure (itx_t) and save within it all the information necessary to
- * possibly replay the transaction. The itx is then assigned a sequence
- * number and inserted in the in-memory list anchored in the zilog.
+ * These zfs_log_* functions must be called within a dmu tx, in one
+ * of 2 contexts depending on zilog->z_replay:
+ *
+ * Non replay mode
+ * ---------------
+ * We need to record the transaction so that if it is committed to
+ * the Intent Log then it can be replayed. An intent log transaction
+ * structure (itx_t) is allocated and all the information necessary to
+ * possibly replay the transaction is saved in it. The itx is then assigned
+ * a sequence number and inserted in the in-memory list anchored in the zilog.
+ *
+ * Replay mode
+ * -----------
+ * We need to mark the intent log record as replayed in the log header.
+ * This is done in the same transaction as the replay so that they
+ * commit atomically.
*/
int
if (zilog == NULL)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
/*
* If we have FUIDs present then add in space for
* domains and ACE fuid's if any.
if (zilog == NULL)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
lr = (lr_remove_t *)&itx->itx_lr;
lr->lr_doid = dzp->z_id;
if (zilog == NULL)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
lr = (lr_link_t *)&itx->itx_lr;
lr->lr_doid = dzp->z_id;
if (zilog == NULL)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
lr = (lr_create_t *)&itx->itx_lr;
lr->lr_doid = dzp->z_id;
if (zilog == NULL)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
lr = (lr_rename_t *)&itx->itx_lr;
lr->lr_sdoid = sdzp->z_id;
if (zilog == NULL || zp->z_unlinked)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
/*
* Writes are handled in three different ways:
*
if (zilog == NULL || zp->z_unlinked)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
itx = zil_itx_create(txtype, sizeof (*lr));
lr = (lr_truncate_t *)&itx->itx_lr;
lr->lr_foid = zp->z_id;
if (zilog == NULL || zp->z_unlinked)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
/*
* If XVATTR set, then log record size needs to allow
* for lr_attr_t + xvattr mask, mapsize and create time
if (zilog == NULL || zp->z_unlinked)
return;
+ ZFS_HANDLE_REPLAY(zilog, tx); /* exits if replay */
+
txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
TX_ACL_V0 : TX_ACL;