fusefs: forward UTIME_NOW to the server

If a user sets both atime and mtime to UTIME_NOW when calling a syscall like
utimensat(2), allow the server to choose what "now" means.  Due to the
design of FreeBSD's VFS, it's not possible to do this for just one of atime
or mtime; it's all or none.

PR:		237181
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Alan Somers 2019-05-16 23:17:39 +00:00
parent e7f73af118
commit fe221e0177
2 changed files with 11 additions and 4 deletions

View File

@ -834,11 +834,15 @@ int fuse_internal_setattr(struct vnode *vp, struct vattr *vap,
fsai->atime = vap->va_atime.tv_sec;
fsai->atimensec = vap->va_atime.tv_nsec;
fsai->valid |= FATTR_ATIME;
if (vap->va_vaflags & VA_UTIMES_NULL)
fsai->valid |= FATTR_ATIME_NOW;
}
if (vap->va_mtime.tv_sec != VNOVAL) {
fsai->mtime = vap->va_mtime.tv_sec;
fsai->mtimensec = vap->va_mtime.tv_nsec;
fsai->valid |= FATTR_MTIME;
if (vap->va_vaflags & VA_UTIMES_NULL)
fsai->valid |= FATTR_MTIME_NOW;
}
if (vap->va_mode != (mode_t)VNOVAL) {
fsai->mode = vap->va_mode & ALLPERMS;

View File

@ -661,9 +661,12 @@ TEST_F(Setattr, utimensat_mtime_only) {
<< strerror(errno);
}
/* Set a file's mtime and atime to now */
/* TODO: enable this test after updating protocol to version 7.9 */
#if 0
/*
* Set a file's mtime and atime to now
*
* The design of FreeBSD's VFS does not allow fusefs to set just one of atime
* or mtime to UTIME_NOW; it's both or neither.
*/
TEST_F(Setattr, utimensat_utime_now) {
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
@ -689,6 +692,7 @@ TEST_F(Setattr, utimensat_utime_now) {
out->body.entry.attr.mode = S_IFREG | 0644;
out->body.entry.nodeid = ino;
out->body.entry.attr_valid = UINT64_MAX;
out->body.entry.entry_valid = UINT64_MAX;
out->body.entry.attr.atime = oldtimes[0].tv_sec;
out->body.entry.attr.atimensec = oldtimes[0].tv_nsec;
out->body.entry.attr.mtime = oldtimes[1].tv_sec;
@ -723,7 +727,6 @@ TEST_F(Setattr, utimensat_utime_now) {
EXPECT_EQ(now[1].tv_sec, sb.st_mtim.tv_sec);
EXPECT_EQ(now[1].tv_nsec, sb.st_mtim.tv_nsec);
}
#endif
/* On a read-only mount, no attributes may be changed */
TEST_F(RofsSetattr, erofs)