From 4c155c1e6323e7a54f3fd89e8c4f769de7a4b337 Mon Sep 17 00:00:00 2001 From: asomers Date: Sun, 2 Apr 2017 03:08:25 +0000 Subject: MFC r313483: Fix setting birthtime in ZFS sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c * In zfs_freebsd_setattr, if the caller wants to set the birthtime, set the bits that zfs_settattr expects * In zfs_setattr, if XAT_CREATETIME is set, set xoa_createtime, expected by zfs_xvattr_set. The two levels of indirection seem excessive, but it minimizes diffs vs OpenZFS. * In zfs_setattr, check for overflow of va_birthtime (from delphij) * Remove red herring in zfs_getattr sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h * Un-booby-trap some macros New tests are under review at https://github.com/pjd/pjdfstest/pull/6 Reviewed by: avg MFC after: 3 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D9353 --- .../opensolaris/uts/common/fs/zfs/zfs_vnops.c | 20 +++++++++++--------- sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h | 15 +++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c index dff6c8c..38c1334 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c @@ -2797,15 +2797,6 @@ zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, zfs_sa_get_scanstamp(zp, xvap); } - if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { - uint64_t times[2]; - - (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs), - times, sizeof (times)); - ZFS_TIME_DECODE(&xoap->xoa_createtime, times); - XVA_SET_RTN(xvap, XAT_CREATETIME); - } - if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) { xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0); XVA_SET_RTN(xvap, XAT_REPARSE); @@ -2967,6 +2958,11 @@ zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, return (SET_ERROR(EOVERFLOW)); } } + if (xoap && (mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME) && + TIMESPEC_OVERFLOW(&vap->va_birthtime)) { + ZFS_EXIT(zfsvfs); + return (SET_ERROR(EOVERFLOW)); + } attrzp = NULL; aclp = NULL; @@ -3411,6 +3407,8 @@ zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, if (xoap && (mask & AT_XVATTR)) { + if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) + xoap->xoa_createtime = vap->va_birthtime; /* * restore trimmed off masks * so that return masks can be set for caller. @@ -5262,6 +5260,10 @@ zfs_freebsd_setattr(ap) xvap.xva_xoptattrs.xoa_sparse); #undef FLAG_CHANGE } + if (vap->va_birthtime.tv_sec != VNOVAL) { + xvap.xva_vattr.va_mask |= AT_XVATTR; + XVA_SET_REQ(&xvap, XAT_CREATETIME); + } return (zfs_setattr(vp, (vattr_t *)&xvap, 0, cred, NULL)); } diff --git a/sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h b/sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h index 974c915..fd5b6fc 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h +++ b/sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h @@ -268,27 +268,30 @@ typedef struct xvattr { * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap * of requested attributes (xva_reqattrmap[]). */ -#define XVA_SET_REQ(xvap, attr) \ +#define XVA_SET_REQ(xvap, attr) { \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) + (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ +} /* * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap * of requested attributes (xva_reqattrmap[]). */ -#define XVA_CLR_REQ(xvap, attr) \ +#define XVA_CLR_REQ(xvap, attr) { \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr) + (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr); \ +} /* * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap * of returned attributes (xva_rtnattrmap[]). */ -#define XVA_SET_RTN(xvap, attr) \ +#define XVA_SET_RTN(xvap, attr) { \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) + (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ +} /* * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[]) -- cgit v1.1