From 069f0d1191bad82009653bbd00dea40137d47a46 Mon Sep 17 00:00:00 2001 From: Jean Luca Bez Date: Thu, 21 May 2020 10:27:21 -0300 Subject: [PATCH 1/2] Check for statx support --- CMakeLists.txt | 12 ++++++++++++ include/client/gkfs_functions.hpp | 2 ++ include/client/hooks.hpp | 2 ++ src/client/gkfs_functions.cpp | 3 ++- src/client/hooks.cpp | 6 ++---- src/client/intercept.cpp | 2 +- tests/integration/CMakeLists.txt | 16 ++++++++++------ tests/integration/harness/gkfs.io/commands.hpp | 2 ++ tests/integration/harness/gkfs.io/main.cpp | 2 ++ tests/integration/harness/gkfs.io/serialize.hpp | 6 ++++-- tests/integration/harness/gkfs.io/statx.cpp | 3 ++- 11 files changed, 41 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e6d61290..60f9230b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,18 @@ include_directories( ) include(GNUInstallDirs) +include(CheckSymbolExists) + +check_cxx_source_compiles(" + #include + #include + + int main() { + struct statx buf; + statx(AT_FDCWD, \"/foo\", AT_EMPTY_PATH, STATX_BASIC_STATS, &buf); + return 0; + } +" GLIBC_HAS_STATX) # Global components add_subdirectory(src/global) diff --git a/include/client/gkfs_functions.hpp b/include/client/gkfs_functions.hpp index bda2fc57a..86ec30448 100644 --- a/include/client/gkfs_functions.hpp +++ b/include/client/gkfs_functions.hpp @@ -41,7 +41,9 @@ int gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = tru // Implementation of statx, it uses the normal stat and maps the information to the statx structure // Follow links is true by default +#ifdef STATX_TYPE int gkfs_statx(int dirfd, const std::string& path, int flags, unsigned int mask,struct statx* buf, bool follow_links = true ); +#endif int gkfs_statfs(struct statfs* buf); diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index 2f2a65463..9af366dd4 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -30,7 +30,9 @@ int hook_close(int fd); int hook_stat(const char* path, struct stat* buf); +#ifdef STATX_TYPE int hook_statx(int dirfd, const char* path, int flags, unsigned int mask,struct statx* buf); +#endif int hook_lstat(const char* path, struct stat* buf); diff --git a/src/client/gkfs_functions.cpp b/src/client/gkfs_functions.cpp index 29854a518..c944e6fc4 100644 --- a/src/client/gkfs_functions.cpp +++ b/src/client/gkfs_functions.cpp @@ -232,7 +232,7 @@ int gkfs_stat(const string& path, struct stat* buf, bool follow_links) { return 0; } - +#ifdef STATX_TYPE int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, struct statx* buf, bool follow_links) { auto md = gkfs::util::get_metadata(path, follow_links); if (!md) { @@ -268,6 +268,7 @@ int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, return 0; } +#endif int gkfs_statfs(struct statfs* buf) { auto blk_stat = gkfs::rpc::forward_get_chunk_stat(); diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index b84f6f1d7..7ca89a4fe 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -98,7 +98,7 @@ int hook_stat(const char* path, struct stat* buf) { return syscall_no_intercept(SYS_stat, rel_path.c_str(), buf); } - +#ifdef STATX_TYPE int hook_statx(int dirfd, const char* path, int flags, unsigned int mask, struct ::statx* buf) { LOG(DEBUG, "{}() called with dirfd: '{}', path: \"{}\", flags: '{}', mask: '{}', buf: '{}'", @@ -127,9 +127,7 @@ int hook_statx(int dirfd, const char* path, int flags, unsigned int mask, struct return syscall_no_intercept(SYS_statx, dirfd, path, flags, mask, buf); } - - - +#endif int hook_lstat(const char* path, struct stat* buf) { diff --git a/src/client/intercept.cpp b/src/client/intercept.cpp index fe1a766e0..708cafe6d 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -466,7 +466,7 @@ int hook(long syscall_number, reinterpret_cast(arg1)); break; -#ifdef SYS_statx +#ifdef STATX_TYPE case SYS_statx: *result = gkfs::hook::hook_statx(static_cast(arg0), reinterpret_cast(arg1), diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 3ba045901..fe550aebe 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -16,12 +16,14 @@ gkfs_add_python_test( SOURCE directories/test_directories.py ) -gkfs_add_python_test( - NAME test_status - PYTHON_VERSION 3.6 - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/integration - SOURCE status/test_status.py -) +if (GLIBC_HAS_STATX) + gkfs_add_python_test( + NAME test_status + PYTHON_VERSION 3.6 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/integration + SOURCE status/test_status.py + ) +endif() gkfs_add_python_test( NAME test_operations @@ -30,12 +32,14 @@ gkfs_add_python_test( SOURCE operations/ ) +if (GLIBC_HAS_STATX) gkfs_add_python_test( NAME test_lseek PYTHON_VERSION 3.6 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/integration SOURCE position/test_lseek.py ) +endif() gkfs_add_python_test( NAME test_shell diff --git a/tests/integration/harness/gkfs.io/commands.hpp b/tests/integration/harness/gkfs.io/commands.hpp index edda1c289..7d111c609 100644 --- a/tests/integration/harness/gkfs.io/commands.hpp +++ b/tests/integration/harness/gkfs.io/commands.hpp @@ -59,8 +59,10 @@ writev_init(CLI::App& app); void pwritev_init(CLI::App& app); +#ifdef STATX_TYPE void statx_init(CLI::App& app); +#endif void lseek_init(CLI::App& app); diff --git a/tests/integration/harness/gkfs.io/main.cpp b/tests/integration/harness/gkfs.io/main.cpp index 0cde949db..e946d1b11 100644 --- a/tests/integration/harness/gkfs.io/main.cpp +++ b/tests/integration/harness/gkfs.io/main.cpp @@ -34,7 +34,9 @@ init_commands(CLI::App& app) { pwrite_init(app); writev_init(app); pwritev_init(app); + #ifdef STATX_TYPE statx_init(app); + #endif lseek_init(app); } diff --git a/tests/integration/harness/gkfs.io/serialize.hpp b/tests/integration/harness/gkfs.io/serialize.hpp index ceb22db80..df1a7b1db 100644 --- a/tests/integration/harness/gkfs.io/serialize.hpp +++ b/tests/integration/harness/gkfs.io/serialize.hpp @@ -105,6 +105,7 @@ struct adl_serializer { } }; +#ifdef STATX_TYPE // ADL specialization for struct ::statx_timestamp type template <> struct adl_serializer { @@ -116,8 +117,7 @@ struct adl_serializer { }; } }; - - +#endif // ADL specialization for struct ::dirent type template <> @@ -162,6 +162,7 @@ struct adl_serializer { } }; +#ifdef STATX_TYPE // ADL specialization for struct ::statx type template <> struct adl_serializer { @@ -192,6 +193,7 @@ struct adl_serializer { }; } }; +#endif } // namespace nlohmann diff --git a/tests/integration/harness/gkfs.io/statx.cpp b/tests/integration/harness/gkfs.io/statx.cpp index 0ffe481ba..1882b1c8c 100644 --- a/tests/integration/harness/gkfs.io/statx.cpp +++ b/tests/integration/harness/gkfs.io/statx.cpp @@ -32,6 +32,7 @@ using json = nlohmann::json; unsigned int mask, struct statx *statxbuf); */ +#ifdef STATX_TYPE struct statx_options { bool verbose; int dirfd; @@ -135,4 +136,4 @@ statx_init(CLI::App& app) { statx_exec(*opts); }); } - +#endif -- GitLab From 1fcc8bf9960a5b5c8bdffd54bbcf619c16b9d0bc Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Thu, 21 May 2020 16:28:36 +0200 Subject: [PATCH 2/2] removed statx from lseek test --- tests/integration/CMakeLists.txt | 2 -- tests/integration/position/test_lseek.py | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index fe550aebe..b3a084766 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -32,14 +32,12 @@ gkfs_add_python_test( SOURCE operations/ ) -if (GLIBC_HAS_STATX) gkfs_add_python_test( NAME test_lseek PYTHON_VERSION 3.6 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/integration SOURCE position/test_lseek.py ) -endif() gkfs_add_python_test( NAME test_shell diff --git a/tests/integration/position/test_lseek.py b/tests/integration/position/test_lseek.py index 51b9b05c6..daf357c7a 100644 --- a/tests/integration/position/test_lseek.py +++ b/tests/integration/position/test_lseek.py @@ -53,12 +53,12 @@ def test_lseek(gkfs_daemon, gkfs_client): assert ret.retval == 0 assert ret.errno == 115 #FIXME: Should be 0! - # test statx on existing dir - ret = gkfs_client.statx(0, topdir, 0, 0) + # test stat on existing dir + ret = gkfs_client.stat(topdir) assert ret.retval == 0 assert ret.errno == 115 #FIXME: Should be 0! - assert stat.S_ISDIR(ret.statbuf.stx_mode) + assert stat.S_ISDIR(ret.statbuf.st_mode) ret = gkfs_client.open(file_a, os.O_CREAT, @@ -83,11 +83,11 @@ def test_lseek(gkfs_daemon, gkfs_client): assert ret.errno == 115 #FIXME: Should be 0 # Size needs to be 0 - ret = gkfs_client.statx(0, file_a, 0, 0) + ret = gkfs_client.stat(file_a) assert ret.retval == 0 - assert (stat.S_ISDIR(ret.statbuf.stx_mode)==0) - assert (ret.statbuf.stx_size == 0) + assert (stat.S_ISDIR(ret.statbuf.st_mode)==0) + assert (ret.statbuf.st_size == 0) # next commands write at the end of the file (pos0), as the filedescriptor is not shared @@ -97,11 +97,13 @@ def test_lseek(gkfs_daemon, gkfs_client): assert ret.retval == 2 # Size should be 2 - ret = gkfs_client.statx(0, file_a, 0, 0) + ret = gkfs_client.stat(file_a) assert ret.retval == 0 - assert (ret.statbuf.stx_size == 2) - + assert (stat.S_ISDIR(ret.statbuf.st_mode)==0) + assert (ret.statbuf.st_size == 2) + + ret = gkfs_client.lseek(file_a, 0, os.SEEK_END) assert ret.retval == 2 #FAILS assert ret.errno == 115 #FIXME: Should be 0 -- GitLab