Skip to content

Commit

Permalink
Walk: open directories with io_uring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Dec 6, 2024
1 parent cc43a5f commit 0c62924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Walk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "io/Open.hxx"
#include "io/uring/CoOperation.hxx"
#include "co/InvokeTask.hxx"
#include "co/Task.hxx"
#include "util/DeleteDisposer.hxx"

#include <fcntl.h> // for O_DIRECTORY
Expand Down Expand Up @@ -76,7 +77,7 @@ Walk::StatItem::Run(Uring::Queue &uring_)
while (walk.stat.size() > MAX_STAT)
co_await walk.resume_stat;

walk.AddDirectory(*directory, std::move(name));
co_await walk.AddDirectory(*directory, std::move(name));
} else if (S_ISREG(stx.stx_mode)) {
walk.AddFile(*directory, std::move(name), FileTime{stx.stx_atime.tv_sec},
stx.stx_blocks * 512ULL);
Expand Down Expand Up @@ -150,10 +151,14 @@ Walk::ScanDirectory(WalkDirectory &directory)
}
}

inline void
inline Co::Task<void>
Walk::AddDirectory(WalkDirectory &parent, std::string &&name)
try {
WalkDirectoryRef directory{WalkDirectoryRef::Adopt{}, *new WalkDirectory(uring, parent, OpenPath(parent.fd, name.c_str(), O_DIRECTORY))};
WalkDirectoryRef directory{
WalkDirectoryRef::Adopt{},
*new WalkDirectory(uring, parent, co_await Uring::CoOpen(uring, parent.fd, name.c_str(), O_PATH|O_DIRECTORY, 0)),
};

ScanDirectory(*directory);
} catch (...) {
fmt::print(stderr, "Failed to scan directory: {}\n", std::current_exception());
Expand Down
3 changes: 2 additions & 1 deletion src/Walk.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class FileDescriptor;
namespace Uring { class Queue; }
namespace Co { template <typename T> class Task; }
class WalkHandler;

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ public:
void Start(FileDescriptor root_fd);

private:
void AddDirectory(WalkDirectory &parent, std::string &&name);
Co::Task<void> AddDirectory(WalkDirectory &parent, std::string &&name);
void AddFile(WalkDirectory &parent, std::string &&name,
FileTime atime, uint_least64_t size);

Expand Down

0 comments on commit 0c62924

Please sign in to comment.