diff options
author | Dean Deng <deandeng@google.com> | 2020-04-08 14:38:09 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-04-08 14:39:25 -0700 |
commit | 357f136e42de81b033b65b7f39a4a555275a17e3 (patch) | |
tree | 95790edd487d20e888d6d20ab945d1c8d66390ce /pkg | |
parent | 2907e6da5e9fc7eeda51644db7bec4d15691b384 (diff) |
Handle utimes correctly for shared gofer filesystems.
Determine system time from within the sentry rather than relying on the remote
filesystem to prevent inconsistencies.
Resolve related TODOs; the time discrepancies in question don't exist anymore.
PiperOrigin-RevId: 305557099
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/sentry/fs/gofer/util.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pkg/sentry/fs/gofer/util.go b/pkg/sentry/fs/gofer/util.go index 2d8d3a2ea..47a6c69bf 100644 --- a/pkg/sentry/fs/gofer/util.go +++ b/pkg/sentry/fs/gofer/util.go @@ -20,17 +20,29 @@ import ( "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/p9" "gvisor.dev/gvisor/pkg/sentry/fs" + ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time" ) func utimes(ctx context.Context, file contextFile, ts fs.TimeSpec) error { if ts.ATimeOmit && ts.MTimeOmit { return nil } + + // Replace requests to use the "system time" with the current time to + // ensure that timestamps remain consistent with the remote + // filesystem. + now := ktime.NowFromContext(ctx) + if ts.ATimeSetSystemTime { + ts.ATime = now + } + if ts.MTimeSetSystemTime { + ts.MTime = now + } mask := p9.SetAttrMask{ ATime: !ts.ATimeOmit, - ATimeNotSystemTime: !ts.ATimeSetSystemTime, + ATimeNotSystemTime: true, MTime: !ts.MTimeOmit, - MTimeNotSystemTime: !ts.MTimeSetSystemTime, + MTimeNotSystemTime: true, } as, ans := ts.ATime.Unix() ms, mns := ts.MTime.Unix() |