Skip to content

Commit

Permalink
Simplify time handling logic in zfs_settattr
Browse files Browse the repository at this point in the history
Simplify time handling in zfs_setattr by mimicking the logic in
setattr_copy from the linux kernel. In order to achieve this
in the case when ZFS' log is being replayed it is necessary
to unconditionally set the ctime in zfs_replay_setattr.

Also use the timespec_trunc function when assigning values to the
generic inode struct. This is currently a noop since zfs sets
s_time_gran to 1, however in the future rules about precision might
change.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Nikolay Borisov <n.borisov.lkml@gmail.com>
Closes openzfs#4916
  • Loading branch information
Nikolay Borisov authored and behlendorf committed Sep 13, 2016
1 parent 9f5f001 commit 87f9371
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 2 additions & 0 deletions module/zfs/zfs_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ zfs_replay_setattr(zfs_sb_t *zsb, lr_setattr_t *lr, boolean_t byteswap)
vap->va_size = lr->lr_size;
ZFS_TIME_DECODE(&vap->va_atime, lr->lr_atime);
ZFS_TIME_DECODE(&vap->va_mtime, lr->lr_mtime);
gethrestime(&vap->va_ctime);
vap->va_mask |= ATTR_CTIME;

/*
* Fill in xvattr_t portions if necessary.
Expand Down
33 changes: 15 additions & 18 deletions module/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,6 @@ zfs_setattr(struct inode *ip, vattr_t *vap, int flags, cred_t *cr)
aclp = NULL;
}


if ((mask & ATTR_ATIME) || zp->z_atime_dirty) {
zp->z_atime_dirty = 0;
ZFS_TIME_ENCODE(&ip->i_atime, atime);
Expand All @@ -3011,29 +3010,27 @@ zfs_setattr(struct inode *ip, vattr_t *vap, int flags, cred_t *cr)

if (mask & ATTR_MTIME) {
ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
ZTOI(zp)->i_mtime = timespec_trunc(vap->va_mtime,
ZTOI(zp)->i_sb->s_time_gran);

SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL,
mtime, sizeof (mtime));
}

/* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
if (mask & ATTR_SIZE && !(mask & ATTR_MTIME)) {
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb),
NULL, mtime, sizeof (mtime));
if (mask & ATTR_CTIME) {
ZFS_TIME_ENCODE(&vap->va_ctime, ctime);
ZTOI(zp)->i_ctime = timespec_trunc(vap->va_ctime,
ZTOI(zp)->i_sb->s_time_gran);
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL,
&ctime, sizeof (ctime));
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime);
} else if (mask != 0) {
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL,
&ctime, sizeof (ctime));
zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime);
if (attrzp) {
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
SA_ZPL_CTIME(zsb), NULL,
&ctime, sizeof (ctime));
zfs_tstamp_update_setup(attrzp, STATE_CHANGED,
mtime, ctime);
}
ctime, sizeof (ctime));
}

if (attrzp && mask) {
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
SA_ZPL_CTIME(zsb), NULL, &ctime,
sizeof (ctime));
}

/*
* Do this after setting timestamps to prevent timestamp
* update from toggling bit
Expand Down
3 changes: 2 additions & 1 deletion module/zfs/zpl_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
vap->va_ctime = ia->ia_ctime;

if (vap->va_mask & ATTR_ATIME)
ip->i_atime = ia->ia_atime;
ip->i_atime = timespec_trunc(ia->ia_atime,
ip->i_sb->s_time_gran);

cookie = spl_fstrans_mark();
error = -zfs_setattr(ip, vap, 0, cr);
Expand Down

0 comments on commit 87f9371

Please sign in to comment.