Skip to content

Commit

Permalink
Updates for snapshots_changed property
Browse files Browse the repository at this point in the history
Currently, snapshots_changed property is stored in dd_props_zapobj, due
to which the property is assumed to be local. This causes a difference
in behavior with respect to other readonly properties.

This commit stores the snapshots_changed property in dd_object. Source
is not set to local in this case, which makes it consistent with other
readonly properties.

This commit also updates the date string format to include seconds.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
Closes openzfs#13785
  • Loading branch information
usaleem-ix committed Aug 25, 2022
1 parent 2f16803 commit 7969acf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,

if (literal ||
localtime_r(&time, &t) == NULL ||
strftime(propbuf, proplen, "%a %b %e %k:%M %Y",
strftime(propbuf, proplen, "%a %b %e %k:%M:%S %Y",
&t) == 0)
(void) snprintf(propbuf, proplen, "%llu",
(u_longlong_t)val);
Expand Down
3 changes: 3 additions & 0 deletions man/man7/zfsprops.7
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ Specifies the time at which a snapshot for a dataset was last
created or deleted.
.Pp
This allows us to be more efficient how often we query snapshots.
The property is persistent across mount and unmount operations only if the
.Sy extensible_dataset
feature is enabled.
.It Sy volblocksize
For volumes, specifies the block size of the volume.
The
Expand Down
35 changes: 22 additions & 13 deletions module/zfs/dsl_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,15 @@ dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
}
}

inode_timespec_t t = {0};
zap_lookup(dd->dd_pool->dp_meta_objset,
dsl_dir_phys(dd)->dd_props_zapobj,
zfs_prop_to_name(ZFS_PROP_SNAPSHOTS_CHANGED),
sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t), &t);
dd->dd_snap_cmtime = t;
if (dsl_dir_is_zapified(dd)) {
inode_timespec_t t = {0};
zap_lookup(dp->dp_meta_objset, ddobj,
zfs_prop_to_name(ZFS_PROP_SNAPSHOTS_CHANGED),
sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t),
&t);
dd->dd_snap_cmtime = t;
}

dmu_buf_init_user(&dd->dd_dbu, NULL, dsl_dir_evict_async,
&dd->dd_dbuf);
Expand Down Expand Up @@ -2251,16 +2253,23 @@ dsl_dir_snap_cmtime(dsl_dir_t *dd)
void
dsl_dir_snap_cmtime_update(dsl_dir_t *dd, dmu_tx_t *tx)
{
dsl_pool_t *dp = dmu_tx_pool(tx);
inode_timespec_t t;
objset_t *mos = dd->dd_pool->dp_meta_objset;
uint64_t zapobj = dsl_dir_phys(dd)->dd_props_zapobj;
const char *prop_name = zfs_prop_to_name(ZFS_PROP_SNAPSHOTS_CHANGED);

gethrestime(&t);

mutex_enter(&dd->dd_lock);
dd->dd_snap_cmtime = t;
VERIFY0(zap_update(mos, zapobj, prop_name, sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t), &t, tx));
if (spa_feature_is_enabled(dp->dp_spa,
SPA_FEATURE_EXTENSIBLE_DATASET)) {
objset_t *mos = dd->dd_pool->dp_meta_objset;
uint64_t ddobj = dd->dd_object;
dsl_dir_zapify(dd, tx);
VERIFY0(zap_update(mos, ddobj,
zfs_prop_to_name(ZFS_PROP_SNAPSHOTS_CHANGED),
sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t),
&t, tx));
}
mutex_exit(&dd->dd_lock);
}

Expand Down

0 comments on commit 7969acf

Please sign in to comment.