99#include " system/SetupProcess.hxx"
1010#include " io/Open.hxx"
1111#include " io/uring/Queue.hxx"
12- #include " util/IterableSplitString.hxx"
1312#include " util/PrintException.hxx"
1413#include " util/SpanCast.hxx"
15- #include " util/StringSplit.hxx"
1614#include " config.h"
1715
1816#include < fmt/core.h>
@@ -55,15 +53,13 @@ OpenDevCachefiles(const Config &config)
5553
5654inline
5755Instance::Instance (const Config &config)
58- :brun(config.brun), frun(config.frun),
56+ :dev_cachefiles(event_loop, OpenDevCachefiles(config), BIND_THIS_METHOD(OnCull)),
57+ brun(config.brun), frun(config.frun),
5958 culling_disabled(config.culling_disabled)
6059{
6160 event_loop.EnableUring (16384 , IORING_SETUP_SINGLE_ISSUER|IORING_SETUP_COOP_TASKRUN);
6261 event_loop.GetUring ()->SetMaxWorkers (16 , 16 );
6362
64- dev_cachefiles.Open (OpenDevCachefiles (config).Release ());
65- dev_cachefiles.ScheduleRead ();
66-
6763 const auto fscache_fd = OpenPath (config.dir .c_str (), O_DIRECTORY);
6864 cache_fd = OpenPath (fscache_fd, " cache" , O_DIRECTORY);
6965 graveyard_fd = OpenPath (fscache_fd, " graveyard" , O_DIRECTORY);
@@ -76,7 +72,6 @@ Instance::Instance(const Config &config)
7672inline
7773Instance::~Instance () noexcept
7874{
79- dev_cachefiles.Close ();
8075}
8176
8277inline void
@@ -101,7 +96,7 @@ Instance::StartCull()
10196 fmt::print (stderr, " Cull: start files={} bytes={}\n " , cull_files, cull_bytes);
10297
10398 cull.emplace (event_loop, *event_loop.GetUring (),
104- dev_cachefiles. GetFileDescriptor () ,
99+ dev_cachefiles,
105100 cull_files, cull_bytes, BIND_THIS_METHOD (OnCullComplete));
106101 cull->Start (cache_fd);
107102}
@@ -110,31 +105,12 @@ inline void
110105Instance::OnCullComplete () noexcept
111106{
112107 cull.reset ();
113-
114- dev_cachefiles.ScheduleRead ();
115108}
116109
117110inline void
118- Instance::OnDevCachefiles ([[maybe_unused]] unsigned events ) noexcept
111+ Instance::OnCull ( ) noexcept
119112{
120- char buffer[1024 ];
121- ssize_t nbytes = dev_cachefiles.GetFileDescriptor ().Read (std::as_writable_bytes (std::span{buffer}));
122- if (nbytes <= 0 ) {
123- // TODO
124- dev_cachefiles.CancelRead ();
125- return ;
126- }
127-
128- const std::string_view line{buffer, static_cast <std::size_t >(nbytes)};
129-
130- bool start_cull = false ;
131- for (const std::string_view i : IterableSplitString (line, ' ' )) {
132- const auto [name, value] = Split (i, ' =' );
133- if (name == " cull" sv)
134- start_cull = value != " 0" sv;
135- }
136-
137- if (start_cull && !cull && !culling_disabled)
113+ if (!cull && !culling_disabled)
138114 StartCull ();
139115}
140116
0 commit comments