mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Support MS_STRICTATIME flag for the syscall mount.
PiperOrigin-RevId: 560207305
This commit is contained in:
@@ -46,8 +46,7 @@ func Mount(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr,
|
||||
|
||||
// Silently allow MS_NOSUID, since we don't implement set-id bits anyway.
|
||||
const unsupported = linux.MS_REMOUNT | linux.MS_SLAVE |
|
||||
linux.MS_UNBINDABLE | linux.MS_MOVE | linux.MS_REC | linux.MS_NODIRATIME |
|
||||
linux.MS_STRICTATIME
|
||||
linux.MS_UNBINDABLE | linux.MS_MOVE | linux.MS_REC | linux.MS_NODIRATIME
|
||||
|
||||
// Linux just allows passing any flags to mount(2) - it won't fail when
|
||||
// unknown or unsupported flags are passed. Since we don't implement
|
||||
@@ -109,7 +108,7 @@ func Mount(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr,
|
||||
}
|
||||
}
|
||||
var opts vfs.MountOptions
|
||||
if flags&linux.MS_NOATIME == linux.MS_NOATIME {
|
||||
if flags&(linux.MS_NOATIME|linux.MS_STRICTATIME) == linux.MS_NOATIME {
|
||||
opts.Flags.NoATime = true
|
||||
}
|
||||
if flags&linux.MS_NOEXEC == linux.MS_NOEXEC {
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "test/util/capability_util.h"
|
||||
#include "test/util/file_descriptor.h"
|
||||
@@ -389,6 +390,34 @@ TEST(MountTest, MountNoAtime) {
|
||||
EXPECT_EQ(before, after);
|
||||
}
|
||||
|
||||
TEST(MountTest, MountWithStrictAtime) {
|
||||
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
|
||||
|
||||
auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
|
||||
auto const mount = ASSERT_NO_ERRNO_AND_VALUE(Mount(
|
||||
"", dir.path(), "tmpfs", MS_NOATIME | MS_STRICTATIME, "mode=0777", 0));
|
||||
|
||||
std::string const contents = "No no no, don't follow the instructions!";
|
||||
auto const file = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
TempPath::CreateFileWith(dir.path(), contents, 0777));
|
||||
|
||||
absl::Time const before = ASSERT_NO_ERRNO_AND_VALUE(ATime(file.path()));
|
||||
|
||||
absl::SleepFor(absl::Milliseconds(100));
|
||||
|
||||
// MS_STRICTATIME should override MS_NOATIME and update the file's atime.
|
||||
auto const fd = ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_RDWR));
|
||||
char buf[100];
|
||||
int read_n;
|
||||
ASSERT_THAT(read_n = read(fd.get(), buf, sizeof(buf)), SyscallSucceeds());
|
||||
EXPECT_EQ(std::string(buf, read_n), contents);
|
||||
|
||||
absl::Time const after = ASSERT_NO_ERRNO_AND_VALUE(ATime(file.path()));
|
||||
|
||||
// The after atime is expected to be larger than the before atime.
|
||||
EXPECT_LT(before, after);
|
||||
}
|
||||
|
||||
TEST(MountTest, MountNoExec) {
|
||||
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user