LLFIO v2.00
Loading...
Searching...
No Matches
llfio_v2_xxx::algorithm::summarize_visitor Struct Reference

A visitor for the filesystem traversal and summary algorithm. More...

#include "summarize.hpp"

Inheritance diagram for llfio_v2_xxx::algorithm::summarize_visitor:
llfio_v2_xxx::algorithm::traverse_visitor llfio_v2_xxx::algorithm::compare_visitor

Public Member Functions

virtual result< directory_handle > directory_open_failed (void *data, result< void >::error_type &&error, const directory_handle &dirh, path_view leaf, size_t depth) noexcept override
 This override ignores failures to traverse into the directory.
virtual result< void > post_enumeration (void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept override
 This override implements the summary.
virtual result< bool > pre_enumeration (void *data, const directory_handle &dirh, size_t depth) noexcept
 Called to decide whether to enumerate a directory.
virtual result< void > stack_updated (void *data, size_t dirs_processed, size_t known_dirs_remaining, size_t depth_processed, size_t known_depth_remaining) noexcept
 Called whenever the traversed stack of directory hierarchy is updated. This can act as an estimated progress indicator, or to give an accurate progress indicator by matching it against a previous traversal.
virtual result< size_t > finished (void *data, result< size_t > result) noexcept
 Called when a traversal finishes, whether due to success or failure. Always called from the original thread.

Static Public Member Functions

static void accumulate (traversal_summary &acc, traversal_summary *state, const directory_handle *dirh, directory_entry &entry, stat_t::want already_have_metadata)

Detailed Description

A visitor for the filesystem traversal and summary algorithm.

Note that at any time, returning a failure causes summarize() to exit as soon as possible with the same failure.

You can override the members here inherited from traverse_visitor, however note that summarize() is entirely implemented using traverse(), so not calling the implementations here will affect operation.

Member Function Documentation

◆ accumulate()

void llfio_v2_xxx::algorithm::summarize_visitor::accumulate ( traversal_summary & acc,
traversal_summary * state,
const directory_handle * dirh,
directory_entry & entry,
stat_t::want already_have_metadata )
inlinestatic
162 {
163 if((state->want & already_have_metadata) != state->want)
164 {
165 // Fetch any missing metadata
166 if(entry.stat.st_type == filesystem::file_type::directory)
167 {
168 if(auto fh = directory_handle::directory(*dirh, entry.leafname, file_handle::mode::attr_read))
169 {
170 if(!entry.stat.fill(fh.assume_value(), state->want & ~already_have_metadata))
171 {
172 acc.stats_failed++;
173 return;
174 }
175 }
176 else
177 {
178 acc.stats_failed++;
179 return;
180 }
181 }
182 else
183 {
184 if(auto fh = file_handle::file(*dirh, entry.leafname, file_handle::mode::attr_read))
185 {
186 if(!entry.stat.fill(fh.assume_value(), state->want & ~already_have_metadata))
187 {
188 acc.stats_failed++;
189 return;
190 }
191 }
192 else
193 {
194 acc.stats_failed++;
195 return;
196 }
197 }
198 }
199 if(state->want & stat_t::want::dev)
200 {
201 acc.devs[entry.stat.st_dev]++;
202 }
203 if(state->want & stat_t::want::type)
204 {
205 acc.types[entry.stat.st_type]++;
206 }
207 if(state->want & stat_t::want::size)
208 {
209 acc.size += entry.stat.st_size;
210 }
211 if(state->want & stat_t::want::allocated)
212 {
213 acc.allocated += entry.stat.st_allocated;
214 }
215 if(state->want & stat_t::want::blocks)
216 {
217 if(entry.stat.st_type == filesystem::file_type::directory)
218 {
219 acc.directory_blocks += entry.stat.st_blocks;
220 }
221 else
222 {
223 acc.file_blocks += entry.stat.st_blocks;
224 }
225 }
226 }
static result< directory_handle > directory(const path_handle &base, path_view_type path, mode _mode=mode::read, creation _creation=creation::open_existing, caching _caching=caching::all, flag flags=flag::none) noexcept
static result< file_handle > file(const path_handle &base, path_view_type path, mode _mode=mode::read, creation _creation=creation::open_existing, caching _caching=caching::all, flag flags=flag::none) noexcept

◆ directory_open_failed()

virtual result< directory_handle > llfio_v2_xxx::algorithm::summarize_visitor::directory_open_failed ( void * data,
result< void >::error_type && error,
const directory_handle & dirh,
path_view leaf,
size_t depth )
inlineoverridevirtualnoexcept

This override ignores failures to traverse into the directory.

Reimplemented from llfio_v2_xxx::algorithm::traverse_visitor.

231 {
232 (void) error;
233 (void) dirh;
234 (void) leaf;
235 (void) depth;
236 auto *state = (traversal_summary *) data;
237 lock_guard<spinlock> g(state->_lock);
238 state->directory_opens_failed++;
239 return success(); // ignore failure to enter
240 }

◆ finished()

virtual result< size_t > llfio_v2_xxx::algorithm::traverse_visitor::finished ( void * data,
result< size_t > result )
inlinevirtualnoexceptinherited

Called when a traversal finishes, whether due to success or failure. Always called from the original thread.

Reimplemented in llfio_v2_xxx::algorithm::contents_visitor.

129 {
130 (void) data;
131 return result;
132 }

◆ post_enumeration()

virtual result< void > llfio_v2_xxx::algorithm::summarize_visitor::post_enumeration ( void * data,
const directory_handle & dirh,
directory_handle::buffers_type & contents,
size_t depth )
inlineoverridevirtualnoexcept

This override implements the summary.

Reimplemented from llfio_v2_xxx::algorithm::traverse_visitor.

Reimplemented in llfio_v2_xxx::algorithm::compare_visitor.

243 {
244 LLFIO_EXCEPTION_TRY
245 {
246 auto *state = (traversal_summary *) data;
247 traversal_summary acc;
248 acc.max_depth = depth;
249 for(auto &entry : contents)
250 {
251 accumulate(acc, state, &dirh, entry, contents.metadata());
252 }
253 state->operator+=(acc);
254 return success();
255 }
256 LLFIO_EXCEPTION_CATCH_ALL
257 {
258 return error_from_exception();
259 }
260 }
result< contents_visitor::contents_type > contents(const path_handle &dirh, contents_visitor *visitor=nullptr, size_t threads=0, bool force_slow_path=false) noexcept
Calculate the contents of everything within and under dirh. What is returned is unordered.
Definition contents.hpp:271

◆ pre_enumeration()

virtual result< bool > llfio_v2_xxx::algorithm::traverse_visitor::pre_enumeration ( void * data,
const directory_handle & dirh,
size_t depth )
inlinevirtualnoexceptinherited

Called to decide whether to enumerate a directory.

Note that it is more efficient to ignore the directory entry in post_enumeration() than to ignore it here, as a handle is opened for the directory before this callback. Equally, if you need that handle to inspect the directory e.g. to check if one is entering a different filesystem from the root, here is best.

The default returns true.

Note
May be called from multiple kernel threads concurrently.
75 {
76 (void) data;
77 (void) dirh;
78 (void) depth;
79 return true;
80 }

◆ stack_updated()

virtual result< void > llfio_v2_xxx::algorithm::traverse_visitor::stack_updated ( void * data,
size_t dirs_processed,
size_t known_dirs_remaining,
size_t depth_processed,
size_t known_depth_remaining )
inlinevirtualnoexceptinherited

Called whenever the traversed stack of directory hierarchy is updated. This can act as an estimated progress indicator, or to give an accurate progress indicator by matching it against a previous traversal.

Parameters
dataThe third party data pointer passed to traverse().
dirs_processedThe total number of directories traversed so far.
known_dirs_remainingThe currently known number of directories awaiting traversal.
depth_processedHow many levels deep we have already completely traversed.
known_depth_remainingThe currently known number of levels we shall traverse.
Note
May be called from multiple kernel threads concurrently.
116 {
117 (void) data;
118 (void) dirs_processed;
119 (void) known_dirs_remaining;
120 (void) depth_processed;
121 (void) known_depth_remaining;
122 return success();
123 }

The documentation for this struct was generated from the following file: