Skip to content

Commit

Permalink
torn writes: merge validate functions and return errors when fault ca…
Browse files Browse the repository at this point in the history
…nnot be added in runtime
  • Loading branch information
mj-ramos committed Jun 18, 2024
1 parent af2c7b8 commit 90ed258
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 123 deletions.
10 changes: 6 additions & 4 deletions lazyfs/include/lazyfs/lazyfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,25 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
string crash_regex_to);

/**
* @brief Adds a torn-seq fault to the faults map.
* @brief Adds a torn-seq fault to the faults map. Returns a vector with errors if any.
*
* @param path path of the fault
* @param op system call
* @param persist which parts of the write to persist
* @return errors
*/
bool add_torn_seq_fault(string path, string op, string persist);
vector<string> add_torn_seq_fault(string path, string op, string persist);

/**
* @brief Adds a torn-op fault to the faults map.
* @brief Adds a torn-op fault to the faults map. Returns a vector with errors if any.
*
* @param path path of the fault
* @param parts which parts of the write to persist
* @param parts_bytes division of the write in bytes
* @param persist which parts of the write to persist
* @return errors
*/
bool add_torn_op_fault(string path, string parts, string parts_bytes, string persist);
vector<string> add_torn_op_fault(string path, string parts, string parts_bytes, string persist);

/**
* @brief Kills lazyfs with SIGKILL if any fault condition verifies
Expand Down
53 changes: 35 additions & 18 deletions lazyfs/src/lazyfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void LazyFS::add_crash_fault (string crash_timing,
}
}

bool LazyFS::add_torn_op_fault(string path, string parts, string parts_bytes, string persist) {
vector<string> LazyFS::add_torn_op_fault(string path, string parts, string parts_bytes, string persist) {
regex number ("\\d+");
sregex_token_iterator iter(persist.begin(), persist.end(), number);
sregex_token_iterator end;
Expand All @@ -263,13 +263,22 @@ bool LazyFS::add_torn_op_fault(string path, string parts, string parts_bytes, st
if (parts != "none") {
partsi = stoi(parts);
}

bool VF = (partsi != -1) ? faults::SplitWriteF::check(persistv, partsi) : faults::SplitWriteF::check(persistv, parts_bytes_v);

if (VF) {
faults::SplitWriteF* fault;
if (partsi != -1) fault = new faults::SplitWriteF(1, persistv, partsi);
else fault = new faults::SplitWriteF(1, persistv, parts_bytes_v);
int occurrence=1;

faults::SplitWriteF* fault;
vector<string> errors;

if (partsi != -1) {
fault = new faults::SplitWriteF(occurrence, persistv, partsi);
errors = faults::SplitWriteF::validate(occurrence, persistv, partsi, std::nullopt);
} else {
fault = new faults::SplitWriteF(occurrence, persistv, parts_bytes_v);
errors = faults::SplitWriteF::validate(occurrence, persistv, std::nullopt, parts_bytes_v);
}

bool valid_fault = true;
if (errors.size() == 0) {

auto it = faults->find(path);
if (it == faults->end()) {
Expand All @@ -278,17 +287,20 @@ bool LazyFS::add_torn_op_fault(string path, string parts, string parts_bytes, st
//Only allows one fault per file
for (auto fault : it->second) {
if (dynamic_cast<faults::SplitWriteF*>(fault) != nullptr) {
return false;
errors.push_back("Only one torn-op fault per file is allowed.");
valid_fault = false;
}
}
it->second.push_back(fault);
if (valid_fault) it->second.push_back(fault);
}
}
}

if (!valid_fault) delete fault;

return VF;
return errors;
}

bool LazyFS::add_torn_seq_fault(string path, string op, string persist) {
vector<string> LazyFS::add_torn_seq_fault(string path, string op, string persist) {
regex number ("\\d+");
sregex_token_iterator iter(persist.begin(), persist.end(), number);
sregex_token_iterator end;
Expand All @@ -299,24 +311,29 @@ bool LazyFS::add_torn_seq_fault(string path, string op, string persist) {
++iter;
}

bool VF = faults::ReorderF::check(op, persistv);
faults::ReorderF* fault = new faults::ReorderF(op, persistv, 1);
vector<string> errors = fault->validate();

if (VF) {
faults::ReorderF* fault = new faults::ReorderF(op, persistv, 1);
bool valid_fault = true;
if (errors.size() == 0) {
auto it = faults->find(path);
if (it == faults->end())
faults->insert({path, {fault}});
else {
for (auto fault : it->second) {
//Only allows one fault per file
if (dynamic_cast<faults::ReorderF*>(fault) != nullptr) {
return false;
errors.push_back("Only one torn-seq fault per file is allowed.");
valid_fault = false;
}
}
it->second.push_back(fault);
if (valid_fault) it->second.push_back(fault);
}
}
return VF;

if (!valid_fault) delete fault;

return errors;
}

void LazyFS::command_unsynced_data_report (vector<string> paths_to_exclude) {
Expand Down
65 changes: 34 additions & 31 deletions lazyfs/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void fht_worker (LazyFS* filesystem) {
string parts_bytes = "none";
string persist = "none";

bool VF = true;
bool valid_fault = true;
vector<string> errors;

for (; iter_glob != end; ++iter_glob) {
Expand All @@ -218,8 +218,8 @@ void fht_worker (LazyFS* filesystem) {
if (tmp_file.length () != 0)
file = tmp_file;
else {
VF = false;
errors.push_back ("file not specified");
valid_fault = false;
}

} else if (current.rfind ("parts=", 0) == 0) {
Expand All @@ -229,7 +229,7 @@ void fht_worker (LazyFS* filesystem) {

if (!std::regex_match(tmp_parts, pattern)) {
errors.push_back ("parts should be a number");
VF = false;
valid_fault = false;
} else
parts = tmp_parts;

Expand All @@ -241,7 +241,7 @@ void fht_worker (LazyFS* filesystem) {

if (!std::regex_match(tmp_parts_bytes, pattern)) {
errors.push_back ("parts_bytes should be a list of numbers separated by commas");
VF = false;
valid_fault = false;
} else
parts_bytes = tmp_parts_bytes;

Expand All @@ -253,34 +253,36 @@ void fht_worker (LazyFS* filesystem) {

if (!std::regex_match(tmp_persist, pattern)) {
errors.push_back ("persist should be a list of numbers separated by commas");
VF = false;
valid_fault = false;
} else
persist = tmp_persist;

} else if (current != "lazyfs" && current != "torn-op") {
errors.push_back ("unknown attribute");
VF = false;
valid_fault = false;
}
}

if (parts=="none" && parts_bytes=="none") {
errors.push_back ("should specify 'parts' or 'parts_bytes', not both");
VF = false;
valid_fault = false;
}

vector<string> errors_add_torn_op;
if (valid_fault)
errors_add_torn_op = filesystem->add_torn_op_fault (file, parts, parts_bytes, persist);

if (VF) {
if (filesystem->add_torn_op_fault (file, parts, parts_bytes, persist))
if (errors_add_torn_op.size() == 0)
spdlog::info ("[lazyfs.faults.worker]: configured successfully '{}'", string (buffer));
else
spdlog::warn ("[lazyfs.faults.worker]: failed to configure '{}'. Check if fault values are correct.", string (buffer));

} else {

else {
spdlog::warn ("[lazyfs.faults.worker]: received: INVALID torn-op fault:");

errors.insert(errors.end(), errors_add_torn_op.begin(), errors_add_torn_op.end());

for (auto const err : errors) {
spdlog::warn ("[lazyfs.faults.worker]: {}", err);
}

}

} else if (command_str.rfind ("lazyfs::torn-seq", 0) == 0) {
Expand All @@ -298,7 +300,7 @@ void fht_worker (LazyFS* filesystem) {
string op = "none";
string persist = "none";

bool VF = true;
bool valid_fault = true;
vector<string> errors;

for (; iter_glob != end; ++iter_glob) {
Expand All @@ -312,8 +314,8 @@ void fht_worker (LazyFS* filesystem) {
if (tmp_file.length () != 0)
file = tmp_file;
else {
VF = false;
errors.push_back ("bad file specification");
valid_fault = false;
}

} else if(current.rfind ("op=", 0) == 0) {
Expand All @@ -323,8 +325,8 @@ void fht_worker (LazyFS* filesystem) {
if (tmp_op.length () != 0)
op = tmp_op;
else {
VF = false;
errors.push_back ("operation not available");
valid_fault = false;
}
} else if (current.rfind ("persist=", 0) == 0) {

Expand All @@ -333,30 +335,31 @@ void fht_worker (LazyFS* filesystem) {

if (!std::regex_match(tmp_per, pattern)) {
errors.push_back ("persist should be a list of numbers separated by commas");
VF = false;
valid_fault = false;
} else
persist = tmp_per;

} else if (current != "lazyfs" && current != "torn-seq") {
errors.push_back ("unknown attribute");
VF = false;
valid_fault = false;
}
}

if (VF) {
if (filesystem->add_torn_seq_fault (file, op, persist))
spdlog::info ("[lazyfs.faults.worker]: configured successfully '{}'", string (buffer));
else
spdlog::warn ("[lazyfs.faults.worker]: failed to configure '{}'. Check if fault values are correct.", string (buffer));

} else {
vector<string> errors_add_torn_seq;
if (valid_fault)
errors_add_torn_seq = filesystem->add_torn_seq_fault(file, op, persist);

spdlog::warn ("[lazyfs.faults.worker]: received: INVALID torn-seq fault:");
if (errors_add_torn_seq.size() == 0)
spdlog::info ("[lazyfs.faults.worker]: configured successfully '{}'", string (buffer));
else {
errors.insert(errors.end(), errors_add_torn_seq.begin(), errors_add_torn_seq.end());

for (auto const err : errors) {
spdlog::warn ("[lazyfs.faults.worker]: {}", err);
}
}
spdlog::warn ("[lazyfs.faults.worker]: received: INVALID torn-seq fault:");

for (auto const err : errors) {
spdlog::warn ("[lazyfs.faults.worker]: {}", err);
}
}

} else if (!strcmp (buffer, "lazyfs::display-cache-usage")) {

Expand Down
24 changes: 0 additions & 24 deletions libs/libpcache/include/faults/faults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ class SplitWriteF : public Fault {
*/
~SplitWriteF();

/**
* @brief Check if the parameters have correct values for the fault.
*
* @param persist Which parts of the write to persist.
* @param parts_bytes Division of the write in bytes.
*/
static bool check(vector<int> persist, vector<int> parts);

/**
* @brief Check if the parameters have correct values for the fault.
*
* @param persist Which parts of the write to persist.
* @param parts Number of same-sixed parts to divide the write.
*/
static bool check(vector<int> persist, int parts);

/**
* @brief Check if the parameters have correct values for the fault.
*
Expand Down Expand Up @@ -179,14 +163,6 @@ class ReorderF : public Fault {

~ReorderF ();

/**
* @brief Check if the parameters have correct values for the fault.
*
* @param persist Which parts of the write to persist.
* @param op System call (i.e. "write", ...).
*/
static bool check(string op, vector<int> persist);

/**
* @brief Check if the parameters have correct values for the fault.
*
Expand Down
6 changes: 5 additions & 1 deletion libs/libpcache/src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ unordered_map<string,vector<faults::Fault*>> Config::load_config (string filenam
error_msg += "\t" + error + "\n";
}
spdlog::error(error_msg);
delete fault;

} else {

Expand Down Expand Up @@ -271,7 +272,7 @@ unordered_map<string,vector<faults::Fault*>> Config::load_config (string filenam
error_msg += "\tKeys 'parts' and 'key_parts' for some injection of type \"torn-op\" are exclusive in the configuration file. Please define at most one of them.\n";
}

faults::SplitWriteF * fault = NULL;
faults::SplitWriteF * fault = nullptr;
vector<string> errors;

//A split write fault either contains the parameter "parts" or the "pats_bytes"
Expand Down Expand Up @@ -302,6 +303,7 @@ unordered_map<string,vector<faults::Fault*>> Config::load_config (string filenam
error_msg += "\t" + error + "\n";
}
spdlog::error(error_msg);
delete fault;

} else {

Expand Down Expand Up @@ -376,6 +378,8 @@ unordered_map<string,vector<faults::Fault*>> Config::load_config (string filenam
error_msg += "\t" + error + "\n";
}
spdlog::error(error_msg);
delete fault;

} else {

auto it = faults.find(from);
Expand Down
Loading

0 comments on commit 90ed258

Please sign in to comment.