it->second.emplace_back(PendingStat{ filename, move(cb) });
} else {
it = pending_stats.emplace(filename, vector<PendingStat>{}).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.
#endif
}
-void IOUringEngine::submit_stat(const char *path, std::function<void()> cb)
+void IOUringEngine::submit_stat(const char *path, std::function<void(bool)> cb)
{
assert(supports_stat);
++pending_reads;
}
-void IOUringEngine::submit_stat_internal(io_uring_sqe *sqe, char *path, std::function<void()> cb)
+void IOUringEngine::submit_stat_internal(io_uring_sqe *sqe, char *path, std::function<void(bool)> cb)
{
PendingRead *pending = new PendingRead;
pending->op = OP_STAT;
--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;
IOUringEngine(size_t slop_bytes);
void submit_read(int fd, size_t len, off_t offset, std::function<void(std::string_view)> 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<void()> 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<void(bool ok)> cb);
bool get_supports_stat() { return supports_stat; }
void finish();
private:
#ifndef WITHOUT_URING
void submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, std::function<void(std::string_view)> cb);
- void submit_stat_internal(io_uring_sqe *sqe, char *path, std::function<void()> cb);
+ void submit_stat_internal(io_uring_sqe *sqe, char *path, std::function<void(bool)> cb);
io_uring ring;
#endif
struct QueuedStat {
char *pathname; // Owned by us.
- std::function<void()> cb;
+ std::function<void(bool)> cb;
};
std::queue<QueuedStat> queued_stats;
Op op;
std::function<void(std::string_view)> read_cb;
- std::function<void()> stat_cb;
+ std::function<void(bool)> stat_cb;
union {
struct {