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_handledirectory_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()

static 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
157 {
158 if((state->want & already_have_metadata) != state->want)
159 {
160 // Fetch any missing metadata
161 if(entry.stat.st_type == filesystem::file_type::directory)
162 {
163 if(auto fh = directory_handle::directory(*dirh, entry.leafname, file_handle::mode::attr_read))
164 {
165 if(!entry.stat.fill(fh.assume_value(), state->want & ~already_have_metadata))
166 {
167 acc.stats_failed++;
168 return;
169 }
170 }
171 else
172 {
173 acc.stats_failed++;
174 return;
175 }
176 }
177 else
178 {
179 if(auto fh = file_handle::file(*dirh, entry.leafname, file_handle::mode::attr_read))
180 {
181 if(!entry.stat.fill(fh.assume_value(), state->want & ~already_have_metadata))
182 {
183 acc.stats_failed++;
184 return;
185 }
186 }
187 else
188 {
189 acc.stats_failed++;
190 return;
191 }
192 }
193 }
194 if(state->want & stat_t::want::dev)
195 {
196 acc.devs[entry.stat.st_dev]++;
197 }
198 if(state->want & stat_t::want::type)
199 {
200 acc.types[entry.stat.st_type]++;
201 }
202 if(state->want & stat_t::want::size)
203 {
204 acc.size += entry.stat.st_size;
205 }
206 if(state->want & stat_t::want::allocated)
207 {
208 acc.allocated += entry.stat.st_allocated;
209 }
210 if(state->want & stat_t::want::blocks)
211 {
212 if(entry.stat.st_type == filesystem::file_type::directory)
213 {
214 acc.directory_blocks += entry.stat.st_blocks;
215 }
216 else
217 {
218 acc.file_blocks += entry.stat.st_blocks;
219 }
220 }
221 }
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.

226 {
227 (void) error;
228 (void) dirh;
229 (void) leaf;
230 (void) depth;
231 auto *state = (traversal_summary *) data;
232 lock_guard<spinlock> g(state->_lock);
233 state->directory_opens_failed++;
234 return success(); // ignore failure to enter
235 }

◆ 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.

238 {
239 LLFIO_EXCEPTION_TRY
240 {
241 auto *state = (traversal_summary *) data;
242 traversal_summary acc;
243 acc.max_depth = depth;
244 for(auto &entry : contents)
245 {
246 accumulate(acc, state, &dirh, entry, contents.metadata());
247 }
248 state->operator+=(acc);
249 return success();
250 }
251 LLFIO_EXCEPTION_CATCH_ALL
252 {
253 return error_from_exception();
254 }
255 }
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:223

◆ 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: