Commit 8dcb2dab authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch 'rnou/308-syscall-436-not-logged-processed' into 'master'

Resolve "syscall 436 not logged / processed"

Closes #308 #307 

This MR adds support for close_range. However, as the upper limit could be "infinite"... we should stop once ge get to GKFS_****_FD. Close_range actually returns always 0, although there is some fd that does not exist.

We add support for all the new syscalls from last kernels (Although not implemented), on the other hand we include the number of syscalls to complete the logging information as in the case of unknown syscall we don't have this information.
 
We remove also the O_PATH check in gkfs_open, as this is used on last kernels (in cp *). It seems that it does not break anything and allows copy with *

Closes #308 and #307

See merge request !201
parents 9dd9d21c 3c0dc598
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -9,6 +9,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### New
### Changed
- Unify dependency scripts (dl and compile): Unify `-d` and `-p` flags ([!174](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/174)).
- Support for `close_range` syscall. ([!201](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/201)).
  - Removal of `O_PATH` check in `gkfs_open`, allows cp with asterisk. This is for newer kernels.
  - Support to print newer syscall (although not implemented). Added syscall number to log for easy capture missing ones.
- Unify dependency scripts (dl and compile): Unify `-d` and `-p` flags ([!174](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/174)).
- Increased merge assert for files with size 0, specific for DLIO with GekkoFS in Debug ([!208])(https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/208)).
### Removed
### Fixed
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ decode(FmtBuffer& buffer, const long syscall_number,

    const auto sc = lookup_by_number(syscall_number, argv);

    fmt::format_to(std::back_inserter(buffer), "{}(", sc.name());
    fmt::format_to(std::back_inserter(buffer), "{} {}(", sc.name(),
                   syscall_number);

    for(int i = 0; i < sc.num_args(); ++i) {
        const auto arg = sc.args().at(i);
+3 −7
Original line number Diff line number Diff line
@@ -140,12 +140,6 @@ namespace gkfs::syscall {
int
gkfs_open(const std::string& path, mode_t mode, int flags) {

    if(flags & O_PATH) {
        LOG(ERROR, "`O_PATH` flag is not supported");
        errno = ENOTSUP;
        return -1;
    }

    // metadata object filled during create or stat
    gkfs::metadata::Metadata md{};
    if(flags & O_CREAT) {
@@ -1643,7 +1637,9 @@ gkfs_close(unsigned int fd) {
    if(CTX->is_internal_fd(fd)) {
        // the client application (for some reason) is trying to close an
        // internal fd: ignore it
        return 0;
        LOG(ERROR, "{}() closing an internal fd '{}'", __func__, fd);
        errno = EACCES;
        return -1;
    }

    return -1;
+34 −6
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
#include <client/preload.hpp>
#include <client/hooks.hpp>
#include <client/logging.hpp>

#include <client/gkfs_functions.hpp>
#include <optional>
#include <fmt/format.h>

@@ -408,11 +408,25 @@ hook_internal(long syscall_number, long arg0, long arg1, long arg2, long arg3,
                CTX->unregister_internal_fd(arg0);
            }
            break;

#ifdef SYS_close_range
        case SYS_close_range:
            *result = syscall_no_intercept_wrapper(
                    syscall_number, static_cast<int>(arg0),
                    static_cast<int>(arg1), static_cast<int>(arg2));
            if(*result >= 0) {
                for(auto i = arg0; i < arg1; i++) {
                    if(arg1 == INT_MAX or i >= GKFS_MAX_INTERNAL_FDS) {
                        break;
                    }
                    CTX->unregister_internal_fd(i);
                }
            }
            break;
#endif
        default:
            // ignore any other syscalls, i.e.: pass them on to the kernel
            // (syscalls forwarded to the kernel that return are logged in
            // hook_forwarded_syscall())
            // ignore any other syscalls, i.e.: pass them on to the
            // kernel (syscalls forwarded to the kernel that return are
            // logged in hook_forwarded_syscall())
            ::save_current_syscall_info(gkfs::syscall::from_internal_code |
                                        gkfs::syscall::to_kernel |
                                        gkfs::syscall::not_executed);
@@ -430,7 +444,8 @@ hook_internal(long syscall_number, long arg0, long arg1, long arg2, long arg3,
/*
 * hook -- interception hook for application syscalls
 *
 * This hook is used to implement any application filesystem-related syscalls.
 * This hook is used to implement any application filesystem-related
 * syscalls.
 */
inline int
hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4,
@@ -486,6 +501,19 @@ hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4,
        case SYS_close:
            *result = gkfs::hook::hook_close(static_cast<int>(arg0));
            break;
#ifdef SYS_close_range
        case SYS_close_range:
            for(auto i = arg0; i <= arg1; i++) {
                if(i >= GKFS_MAX_OPEN_FDS)
                    break;
                if(CTX->file_map()->exist(i)) {
                    gkfs::syscall::gkfs_close(i);
                }
                *result = 0;
            }
            *result = 0;
            break;
#endif // SYS_close_range
#ifdef SYS_stat
        case SYS_stat:
            *result =
+2 −1
Original line number Diff line number Diff line
@@ -541,7 +541,8 @@ PreloadContext::register_internal_fd(int fd) {
void
PreloadContext::unregister_internal_fd(int fd) {

    LOG(DEBUG, "unregistering internal fd {}", fd);
    LOG(DEBUG, "unregistering internal fd {} >= {} -> {}'", fd, MIN_INTERNAL_FD,
        fd >= MIN_INTERNAL_FD);

    assert(fd >= MIN_INTERNAL_FD);

Loading