From de3bb58078cdcaf357a9a0c37648596c85615bc2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 27 Jul 2021 15:45:27 +0200 Subject: [PATCH] Send the result value of the stat to the callback. --- access_rx_cache.cpp | 2 +- io_uring_engine.cpp | 6 +++--- io_uring_engine.h | 14 ++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/access_rx_cache.cpp b/access_rx_cache.cpp index b6db4ea..7633c31 100644 --- a/access_rx_cache.cpp +++ b/access_rx_cache.cpp @@ -55,7 +55,7 @@ void AccessRXCache::check_access(const char *filename, bool allow_async, functio it->second.emplace_back(PendingStat{ filename, move(cb) }); } else { it = pending_stats.emplace(filename, vector{}).first; - engine->submit_stat(filename, [this, it, filename{ strdup(filename) }, cb{ move(cb) }] { + engine->submit_stat(filename, [this, it, filename{ strdup(filename) }, cb{ move(cb) }](bool) { // The stat returned, so now do the actual access() calls. // All of them should be in cache, so don't fire off new statx() // calls during that check. diff --git a/io_uring_engine.cpp b/io_uring_engine.cpp index ab9f411..116cf85 100644 --- a/io_uring_engine.cpp +++ b/io_uring_engine.cpp @@ -46,7 +46,7 @@ IOUringEngine::IOUringEngine(size_t slop_bytes) #endif } -void IOUringEngine::submit_stat(const char *path, std::function cb) +void IOUringEngine::submit_stat(const char *path, std::function cb) { assert(supports_stat); @@ -115,7 +115,7 @@ void IOUringEngine::submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, ++pending_reads; } -void IOUringEngine::submit_stat_internal(io_uring_sqe *sqe, char *path, std::function cb) +void IOUringEngine::submit_stat_internal(io_uring_sqe *sqe, char *path, std::function cb) { PendingRead *pending = new PendingRead; pending->op = OP_STAT; @@ -166,7 +166,7 @@ void IOUringEngine::finish() --pending_reads; size_t old_pending_reads = pending_reads; - pending->stat_cb(); + pending->stat_cb(cqe->res == 0); free(pending->stat.pathname); delete pending->stat.buf; delete pending; diff --git a/io_uring_engine.h b/io_uring_engine.h index 470bacf..688a6ae 100644 --- a/io_uring_engine.h +++ b/io_uring_engine.h @@ -18,11 +18,9 @@ public: IOUringEngine(size_t slop_bytes); void submit_read(int fd, size_t len, off_t offset, std::function cb); - // NOTE: We just do the stat() to get the data into the dentry cache for fast access; - // we don't care about the return value. Thus, the callback has no parameter lists. - // If we have no io_uring, the callback will be made immediately, with no stat() call - // being done. - void submit_stat(const char *path, std::function cb); + // NOTE: We just do the stat() to get the data into the dentry cache for fast access, + // or to check whether the file exists. Thus, the callback has only an OK/not OK boolean. + void submit_stat(const char *path, std::function cb); bool get_supports_stat() { return supports_stat; } void finish(); @@ -31,7 +29,7 @@ public: private: #ifndef WITHOUT_URING void submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, std::function cb); - void submit_stat_internal(io_uring_sqe *sqe, char *path, std::function cb); + void submit_stat_internal(io_uring_sqe *sqe, char *path, std::function cb); io_uring ring; #endif @@ -49,7 +47,7 @@ private: struct QueuedStat { char *pathname; // Owned by us. - std::function cb; + std::function cb; }; std::queue queued_stats; @@ -60,7 +58,7 @@ private: Op op; std::function read_cb; - std::function stat_cb; + std::function stat_cb; union { struct { -- 2.39.2