From 50c99a86d1c6807c67cdc52102b1fc570426669f Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 10 Sep 2020 10:38:19 -0700 Subject: [vfs] Disable nlink tests for overlayfs. Overlayfs intentionally does not compute nlink for directories (because it can be really expensive). Linux returns 1, VFS2 returns 2 and VFS1 actually calculates the correct value. PiperOrigin-RevId: 330967139 --- test/util/fs_util.cc | 14 ++++++++++++++ test/util/fs_util.h | 7 +++++++ 2 files changed, 21 insertions(+) (limited to 'test/util') diff --git a/test/util/fs_util.cc b/test/util/fs_util.cc index 572675622..b16055dd8 100644 --- a/test/util/fs_util.cc +++ b/test/util/fs_util.cc @@ -649,5 +649,19 @@ PosixErrorOr IsTmpfs(const std::string& path) { } #endif // __linux__ +PosixErrorOr IsOverlayfs(const std::string& path) { + struct statfs stat; + if (statfs(path.c_str(), &stat)) { + if (errno == ENOENT) { + // Nothing at path, don't raise this as an error. Instead, just report no + // overlayfs at path. + return false; + } + return PosixError(errno, + absl::StrFormat("statfs(\"%s\", %#p)", path, &stat)); + } + return stat.f_type == OVERLAYFS_SUPER_MAGIC; +} + } // namespace testing } // namespace gvisor diff --git a/test/util/fs_util.h b/test/util/fs_util.h index 314637de0..c99cf5eb7 100644 --- a/test/util/fs_util.h +++ b/test/util/fs_util.h @@ -38,6 +38,10 @@ constexpr int kOLargeFile = 00400000; #error "Unknown architecture" #endif +// From linux/magic.h. For some reason, not defined in the headers for some +// build environments. +#define OVERLAYFS_SUPER_MAGIC 0x794c7630 + // Returns a status or the current working directory. PosixErrorOr GetCWD(); @@ -184,6 +188,9 @@ PosixErrorOr ProcessExePath(int pid); PosixErrorOr IsTmpfs(const std::string& path); #endif // __linux__ +// IsOverlayfs returns true if the file at path is backed by overlayfs. +PosixErrorOr IsOverlayfs(const std::string& path); + namespace internal { // Not part of the public API. std::string JoinPathImpl(std::initializer_list paths); -- cgit v1.2.3