LLFIO  v2.00
llfio_v2_xxx::algorithm::reduce_visitor Struct Reference

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

#include "reduce.hpp"

Inheritance diagram for llfio_v2_xxx::algorithm::reduce_visitor:
llfio_v2_xxx::algorithm::traverse_visitor

Public Member Functions

constexpr reduce_visitor ()
 Constructs an instance with the default timeout of ten seconds.
 
constexpr reduce_visitor (std::chrono::steady_clock::duration _timeout)
 Constructs an instance with the specified timeout.
 
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, and tries renaming the item into the base directory.
 
virtual result< void > post_enumeration (void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept override
 This override invokes deletion of all non-directory items. If there are no directory items, also deletes the directory.
 
virtual result< bool > unlink_failed (void *data, result< void >::error_type &&error, const directory_handle &dirh, directory_entry &entry, size_t depth) noexcept
 Called when the unlink of a file entry failed. The default implementation attempts to rename the entry into the base directory. If your reimplementation achieves the unlink, return true. More...
 
virtual result< bool > rename_failed (void *data, result< void >::error_type &&error, const directory_handle &dirh, directory_entry &entry, size_t depth) noexcept
 Called when the rename of a file entry into the base directory failed. The default implementation ignores the failure. If your reimplementation achieves the rename, return true. More...
 
virtual result< void > reduction_round (void *data, size_t round_completed, size_t items_unlinked, size_t items_remaining) noexcept
 Called when we have performed a single full round of reduction. More...
 
virtual result< bool > pre_enumeration (void *data, const directory_handle &dirh, size_t depth) noexcept
 Called to decide whether to enumerate a directory. More...
 
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. More...
 
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.
 

Public Attributes

std::chrono::steady_clock::duration timeout {std::chrono::seconds(10)}
 
std::chrono::steady_clock::time_point begin
 

Detailed Description

A visitor for the filesystem traversal and reduction algorithm.

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

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

Member Function Documentation

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

◆ reduction_round()

virtual result<void> llfio_v2_xxx::algorithm::reduce_visitor::reduction_round ( void *  data,
size_t  round_completed,
size_t  items_unlinked,
size_t  items_remaining 
)
inlinevirtualnoexcept

Called when we have performed a single full round of reduction.

Note
Always called from the original kernel thread.
95  {
96  (void) data;
97  (void) round_completed;
98  (void) items_unlinked;
99  if(items_remaining > 0)
100  {
101  if(begin == std::chrono::steady_clock::time_point())
102  {
103  begin = std::chrono::steady_clock::now();
104  }
105  else if((std::chrono::steady_clock::now() - begin) > timeout)
106  {
107  return errc::timed_out;
108  }
109  }
110  return success();
111  }

◆ rename_failed()

virtual result<bool> llfio_v2_xxx::algorithm::reduce_visitor::rename_failed ( void *  data,
result< void >::error_type &&  error,
const directory_handle dirh,
directory_entry entry,
size_t  depth 
)
inlinevirtualnoexcept

Called when the rename of a file entry into the base directory failed. The default implementation ignores the failure. If your reimplementation achieves the rename, return true.

Note
May be called from multiple kernel threads concurrently.
82  {
83  (void) data;
84  (void) error;
85  (void) dirh;
86  (void) entry;
87  (void) depth;
88  return false;
89  }

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

◆ unlink_failed()

virtual result<bool> llfio_v2_xxx::algorithm::reduce_visitor::unlink_failed ( void *  data,
result< void >::error_type &&  error,
const directory_handle dirh,
directory_entry entry,
size_t  depth 
)
virtualnoexcept

Called when the unlink of a file entry failed. The default implementation attempts to rename the entry into the base directory. If your reimplementation achieves the unlink, return true.

Note
May be called from multiple kernel threads concurrently.

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