mirror_zfs/module/os/freebsd/zfs
Jitendra Patidar 361a7e8211
log xattr=sa create/remove/update to ZIL
As such, there are no specific synchronous semantics defined for
the xattrs. But for xattr=on, it does log to ZIL and zil_commit() is
done, if sync=always is set on dataset. This provides sync semantics
for xattr=on with sync=always set on dataset.

For the xattr=sa implementation, it doesn't log to ZIL, so, even with
sync=always, xattrs are not guaranteed to be synced before xattr call
returns to caller. So, xattr can be lost if system crash happens, before
txg carrying xattr transaction is synced.

This change adds xattr=sa logging to ZIL on xattr create/remove/update
and xattrs are synced to ZIL (zil_commit() done) for sync=always.
This makes xattr=sa behavior similar to xattr=on.

Implementation notes:
The actual logging is fairly straight-forward and does not warrant
additional explanation.
However, it has been 14 years since we last added new TX types
to the ZIL [1], hence this is the first time we do it after the
introduction of zpool features. Therefore, here is an overview of the
feature activation and deactivation workflow:

1. The feature must be enabled. Otherwise, we don't log the new
    record type. This ensures compatibility with older software.
2. The feature is activated per-dataset, since the ZIL is per-dataset.
3. If the feature is enabled and dataset is not for zvol, any append to
    the ZIL chain will activate the feature for the dataset. Likewise
    for starting a new ZIL chain.
4. A dataset that doesn't have a ZIL chain has the feature deactivated.

We ensure (3) by activating on the first zil_commit() after the feature
was enabled. Since activating the features requires waiting for txg
sync, the first zil_commit() after enabling the feature will be slower
than usual. The downside is that this is really a conservative
approximation: even if we never append a 'TX_SETSAXATTR' to the ZIL
chain, we pay the penalty for feature activation. The upside is that the
user is in control of when we pay the penalty, i.e., upon enabling the
feature.

We ensure (4) by hooking into zil_sync(), where ZIL destroy actually
happens.

One more piece on feature activation, since it's spread across
multiple functions:

zil_commit()
  zil_process_commit_list()
    if lwb == NULL // first zil_commit since zil_open
      zil_create()
        if no log block pointer in ZIL header:
          if feature enabled and not active:
	    // CASE 1
            enable, COALESCE txg wait with dmu_tx that allocated the
	    log block
         else // log block was allocated earlier than this zil_open
          if feature enabled and not active:
	    // CASE 2
            enable, EXPLICIT txg wait
    else // already have an in-DRAM LWB
      if feature enabled and not active:
        // this happens when we enable the feature after zil_create
	// CASE 3
        enable, EXPLICIT txg wait

[1] da6c28aaf6

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Christian Schwarz <christian.schwarz@nutanix.com>
Reviewed-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Ryan Moeller <freqlabs@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Jitendra Patidar <jitendra.patidar@nutanix.com>
Closes #8768 
Closes #9078
2022-02-22 13:06:43 -08:00
..
abd_os.c module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
arc_os.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
crypto_os.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
dmu_os.c Remove FreeBSD's local copy of the dmu_buf_hold_array() function 2021-10-13 11:01:01 -07:00
hkdf.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
kmod_core.c zfs: add missed dependency of zfs module on zlib 2021-08-13 13:42:45 -07:00
spa_os.c Add spa _os() hooks 2022-02-15 15:54:25 -08:00
sysctl_os.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
vdev_file.c module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
vdev_geom.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
vdev_label_os.c FreeBSD: Clean up ASSERT/VERIFY use in module 2021-04-30 16:36:10 -07:00
zfs_acl.c module: mark arguments used 2022-02-18 09:34:03 -08:00
zfs_ctldir.c module: mark arguments used 2022-02-18 09:34:03 -08:00
zfs_debug.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
zfs_dir.c Clean up use of zfs_log_create in zfs_dir 2021-05-07 15:13:10 -07:00
zfs_file_os.c FreeBSD: Catch up with recent VFS changes 2021-10-25 09:46:28 -07:00
zfs_ioctl_compat.c FreeBSD: Fix legacy compat for platform IOCs 2020-09-30 13:25:50 -07:00
zfs_ioctl_os.c libzfs: On FreeBSD, use MNT_NOWAIT with getfsstat 2021-06-08 07:36:43 -06:00
zfs_racct.c module: zfs: fix unused, remove argsused 2021-12-23 09:42:47 -08:00
zfs_vfsops.c module: mark arguments used 2022-02-18 09:34:03 -08:00
zfs_vnops_os.c log xattr=sa create/remove/update to ZIL 2022-02-22 13:06:43 -08:00
zfs_znode.c module: mark arguments used 2022-02-18 09:34:03 -08:00
zio_crypt.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
zvol_os.c module: mark arguments used 2022-02-18 09:34:03 -08:00