Skip to content

Commit 1446eae

Browse files
committed
faults-handler: move fht_worker from main
1 parent 59774e7 commit 1446eae

5 files changed

Lines changed: 266 additions & 268 deletions

File tree

lazyfs/include/faults_handler.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#ifndef FAULTS_HANDLER_HPP
22
#define FAULTS_HANDLER_HPP
33

4+
#include "cache/config/config.hpp"
5+
#include "faults/faults.hpp"
6+
#include "lazyfs/lazyfs.hpp"
47
#include <string>
58
#include <vector>
69

10+
#define MAX_READ_CHUNK 100
711

812
/**
913
* @brief Parses a clear-cache command string.
10-
*
14+
*
1115
* @param command_str the command string to parse
1216
* @param crash_timing reference to the crash timing
1317
* @param crash_operation reference to the crash operation
@@ -19,11 +23,11 @@ bool parse_crash(std::string command_str, std::string &crash_timing, std::string
1923

2024
/**
2125
* @brief Parses a torn-op command string.
22-
*
26+
*
2327
* @param command_str the command string to parse
2428
* @param file reference to the file path
2529
* @param parts reference to the parts of the write
26-
* @param parts_bytes reference to parts of the write
30+
* @param parts_bytes reference to parts of the write
2731
* @param persist reference to which parts to persist
2832
* @param ret reference to if the operation should return before crashing
2933
* @return true if parsing was successful, false otherwise
@@ -32,7 +36,7 @@ bool parse_torn_op(std::string command_str, std::string &file, std::string &part
3236

3337
/**
3438
* @brief Parses a torn-seq command string.
35-
*
39+
*
3640
* @param command_str the command string to parse
3741
* @param file reference to the file path
3842
* @param op reference to the operation type
@@ -44,16 +48,16 @@ bool parse_torn_seq(std::string command_str, std::string &file, std::string &op,
4448

4549
/**
4650
* @brief Parses a snapshot command string.
47-
*
51+
*
4852
* @param command_str the command string to parse
4953
* @param files reference to the files to include in the snapshot
5054
* @param files_rgx reference to the regex for files to include in the snapshot
5155
* @param save reference to the path where the snapshot should be saved
5256
* @return true if parsing was successful, false otherwise
5357
*/
54-
bool parse_snapshot (std::string command_str,
58+
bool parse_snapshot (std::string command_str,
5559
std::string& files,
56-
std::regex& files_rgx,
60+
std::regex& files_rgx,
5761
std::string& save);
5862

5963

@@ -62,7 +66,6 @@ bool parse_snapshot (std::string command_str,
6266
*/
6367
FaultParamsMap parse_fault_command (const std::string command_str);
6468

65-
66-
69+
void fht_worker (lazyfs::LazyFS* filesystem, cache::config::Config* std_config);
6770

6871
#endif // FAULTS_HANDLER_HPP

lazyfs/include/lazyfs/lazyfs.hpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Write {
6666
/**
6767
* @brief Destroy the Write object
6868
*
69-
*/
69+
*/
7070
~Write ();
7171

7272
};
@@ -95,24 +95,18 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
9595
*/
9696
std::thread* faults_handler_thread;
9797

98-
/**
99-
* @brief Faults handler method to run inside the thread.
100-
*
101-
*/
102-
void (*fht_worker) (LazyFS* filesystem);
103-
10498
/**
10599
* @brief Faults programmed in the configuration file.
106100
*/
107-
unordered_map<string,vector<faults::Fault*>>* faults;
101+
unordered_map<string,vector<faults::Fault*>>* faults;
108102

109103
/**
110104
* @brief FUSE mount directory.
111105
*/
112106
string mount_dir;
113107

114108
/**
115-
* @brief FUSE root directory.
109+
* @brief FUSE root directory.
116110
*/
117111
string root_dir;
118112

@@ -174,7 +168,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
174168
"link",
175169
"symlink"};
176170
*/
177-
171+
178172
/**
179173
* @brief Map of operations that have two paths
180174
*
@@ -201,7 +195,6 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
201195
LazyFS (Cache* cache,
202196
cache::config::Config* config,
203197
std::thread* faults_handler_thread,
204-
void (*fht_worker) (LazyFS* filesystem),
205198
unordered_map<string,vector<faults::Fault*>>* faults,
206199
string mount_dir,
207200
string root_dir);
@@ -219,7 +212,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
219212

220213
/**
221214
* @brief Fifo: (fault) Clear the cached contents
222-
*
215+
*
223216
* @param lock_needed Indicates if the cache_command_lock should be locked. When this function is called inside a filesystem operation, it should be false, because all filesystem operations are already locked. When called from the fault handler, it should be true.
224217
*/
225218
void command_fault_clear_cache (bool lock_needed = true);
@@ -229,22 +222,22 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
229222
/**
230223
* @brief Fifo: (fault) Persist the cached pages requested.
231224
* Only use after obtaining lock on cache_command_lock.
232-
*
225+
*
233226
* @param sync_pages The sync-pages fault to be injected.
234227
*/
235228
void command_fault_sync_pages (faults::SyncPagesF &sync_pages);
236229

237230
/**
238231
* @brief Fifo: (info) Display the cache usage
239-
*
232+
*
240233
* @param lock_needed Indicates if the cache_command_lock should be locked. When this function is called inside a filesystem operation, it should be false, because all filesystem operations are already locked. When called from the fault handler, it should be true.
241234
*
242235
*/
243236
void command_display_cache_usage (bool lock_needed = true);
244237

245238
/**
246239
* @brief Fifo: (sync) Sync all cached data with the underlying FS
247-
*
240+
*
248241
* @param lock_needed Indicates if the cache_command_lock should be locked. When this function is called inside a filesystem operation, it should be false, because all filesystem operations are already locked. When called from the fault handler, it should be true.
249242
*
250243
*/
@@ -267,7 +260,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
267260

268261
/**
269262
* @brief Checks if a programmed reorder fault for the given path and operation exists. If so, updates the counter and returns the fault.
270-
* @param path Path of the file
263+
* @param path Path of the file
271264
* @param op Operation ('write','fsync',...)
272265
* @return Pointer to the ReorderF object
273266
*/
@@ -291,7 +284,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
291284
void restart_counter(string path, string op);
292285

293286
/**
294-
* @brief Checks the existence of a pending write (a write that could be persisted if it is followed by another one) and deletes it if it exists.
287+
* @brief Checks the existence of a pending write (a write that could be persisted if it is followed by another one) and deletes it if it exists.
295288
* @param path Path of the file
296289
*/
297290
bool check_and_delete_pendingwrite(const char* path);
@@ -419,15 +412,15 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
419412
string crash_operation,
420413
string crash_regex_from,
421414
string crash_regex_to);
422-
415+
423416

424417
void add_sync_pages_fault(const FaultParamsMap& params_map);
425418

426419
/**
427420
* @brief Adds a torn-seq fault to the faults map. Returns a vector with errors if any.
428-
*
421+
*
429422
* @param path path of the fault
430-
* @param op system call
423+
* @param op system call
431424
* @param persist which parts of the write to persist
432425
* @param ret_ if the current system call is finished before crashing
433426
* @return errors
@@ -436,7 +429,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
436429

437430
/**
438431
* @brief Adds a torn-op fault to the faults map. Returns a vector with errors if any.
439-
*
432+
*
440433
* @param path path of the fault
441434
* @param parts which parts of the write to persist
442435
* @param parts_bytes division of the write in bytes

0 commit comments

Comments
 (0)