Add snapshots_changed_nsecs dataset property (#17998) #18031
+85
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is in response to #17998
Motivation and Context
OpenZFS 2.2 introduced the
snapshots_changeddataset property as a cheap, persistent way to tell whether the snapshot set for a dataset has changed without having to runzfs list -t snapshoton every poll. Replication and monitoring tools use this as a cache key to avoid repeatedly walking large snapshot trees.Because
snapshots_changedis exposed only with integer-second granularity, multiple snapshot creations or deletions that occur within the same second share the same value. Tools that rely on it as a change detector can therefore miss snapshot updates that happen in the same second, causing cache-based fast paths to skipzfs list -t snapshotwhen they should refresh their snapshot metadata. This is particularly problematic for near real-time replication and monitoring systems that take frequent snapshots.This change adds a companion read-only dataset property,
snapshots_changed_nsecs, which exposes the nanosecond (tv_nsec) component of the same internal timestamp that backssnapshots_changed. Together,(snapshots_changed, snapshots_changed_nsecs)provide a reliable, nanosecond-granularity indicator of snapshot-set changes without requiring any on-disk format changes.The change is intentionally minimal and aligned with existing patterns:
inode_timespecwithtv_secandtv_nsec.ZEVENT_TIME_SECS/ZEVENT_TIME_NSECS).Description
snapshots_changed_nsecswith enumZFS_PROP_SNAPSHOTS_CHANGED_NSECSininclude/sys/fs/zfs.handlib/libzfs/libzfs.abi.module/zcommon/zfs_prop.cas a numeric, read-only dataset property for filesystems and volumes:snapshots_changed_nsecsPROP_TYPE_NUMBERSNAPSHOTS_CHANGED_NSECScolumn, no humanized formatting)dsl_dir_snap_cmtime()timestamp indsl_dataset_stats()(module/zfs/dsl_dataset.c):dsl_dir_snap_cmtime(ds->ds_dir)into a localinode_timespec_t snap_cmtime.snap_cmtime.tv_secassnapshots_changed.snap_cmtime.tv_sec != 0, exportsnap_cmtime.tv_nsecassnapshots_changed_nsecs.libzfs(lib/libzfs/libzfs_dataset.c):ZFS_PROP_SNAPSHOTS_CHANGED_NSECScase tozfs_prop_get()which retrieves the numeric value and formats it as a decimal string.module/zfs/zcp_get.c):get_special_prop()to returndsl_dir_snap_cmtime(ds->ds_dir).tv_nsecforZFS_PROP_SNAPSHOTS_CHANGED_NSECS.zfsprops(7)(man/man7/zfsprops.7):snapshots_changed_nsecsis the nanosecond component corresponding tosnapshots_changed.[0, 999999999]and is only meaningful whensnapshots_changedis not-.snapshots_changed * 1000000000 + snapshots_changed_nsecs.snapshot_018_pos(tests/zfs-tests/tests/functional/snapshot/snapshot_018_pos.ksh):snapshots_changedandsnapshots_changed_nsecsare-before any snapshots exist, via bothzfs getandzfs list -o.snapshots_changedis greater than or equal to the current time, and thatsnapshots_changed_nsecsis in[0, 1000000000).zfs getandzfs list -oreport identical values for both properties on the pool and filesystem.snapshots_changedandsnapshots_changed_nsecsand that the.zfs/snapshotdirectory mtime matchessnapshots_changed.How Has This Been Tested?
tests/zfs-tests/tests/functional/snapshot/snapshot_018_pos.kshto cover bothsnapshots_changedandsnapshots_changed_nsecsfor:snapshots_changedandsnapshots_changed_nsecsare-when no snapshots exist.snapshots_changed_nsecsis always in the range[0, 1000000000)whensnapshots_changedis set.zfs get -pandzfs list -p -oreturn consistent values for both properties..zfs/snapshotdirectory mtime remains consistent withsnapshots_changed.Types of changes
Checklist:
Signed-off-by.