Skip to content

Commit

Permalink
Crashing after return of current system call
Browse files Browse the repository at this point in the history
  • Loading branch information
martap372 committed Jul 31, 2024
1 parent a47a5ba commit f6a0939
Show file tree
Hide file tree
Showing 71 changed files with 217 additions and 56 deletions.
Empty file modified lazyfs/build.sh
100755 → 100644
Empty file.
6 changes: 4 additions & 2 deletions lazyfs/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ blocks_per_page=1
# page_size=4096
# no_pages=10
[filesystem]
log_all_operations=false
logfile=""
log_all_operations=true
logfile=""

# /home/kianda/Desktop/root/ex.txt
10 changes: 6 additions & 4 deletions lazyfs/include/lazyfs/lazyfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
* @param path path of the fault
* @param op system call
* @param persist which parts of the write to persist
* @param ret_ if the current system call is finished before crashing
* @return errors
*/
vector<string> add_torn_seq_fault(string path, string op, string persist);
vector<string> add_torn_seq_fault(string path, string op, string persist, string ret_);

/**
* @brief Adds a torn-op fault to the faults map. Returns a vector with errors if any.
Expand All @@ -392,9 +393,10 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
* @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
* @param ret_ if the current system call is finished before crashing
* @return errors
*/
vector<string> 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, string ret_);

/**
* @brief Kills lazyfs with SIGKILL if any fault condition verifies
Expand All @@ -405,7 +407,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
* @param dest_op_path destination path specified in the operation
* @param fault_type type of fault that triggered the crash
*/
void trigger_crash_fault (string opname, string optiming, string from_op_path, string to_op_path, string fault_type);
bool trigger_crash_fault (string opname, string optiming, string from_op_path, string to_op_path, string fault_type);

/**
* @brief Triggers a clear fault if condition is verified.
Expand All @@ -415,7 +417,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
* @param from_op_path source path specified in the operation
* @param dest_op_path destination path specified in the operation
*/
void trigger_configured_clear_fault (string opname, string optiming, string from_path, string to_path);
bool trigger_configured_clear_fault (string opname, string optiming, string from_path, string to_path);
};

} // namespace lazyfs
Expand Down
Empty file modified lazyfs/scripts/mount-lazyfs.sh
100755 → 100644
Empty file.
Empty file modified lazyfs/scripts/run-tests.sh
100755 → 100644
Empty file.
Empty file modified lazyfs/scripts/umount-lazyfs.sh
100755 → 100644
Empty file.
130 changes: 105 additions & 25 deletions lazyfs/src/lazyfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <tuple>
#include <unistd.h>
#include <vector>
#include<algorithm>
#include <algorithm>


// LazyFS specific imports
Expand All @@ -38,6 +38,9 @@ using namespace std;
using namespace cache;
using namespace cache::engine::backends::custom;

bool kill_before = false;
std::shared_mutex kill_lock;

std::shared_mutex cache_command_lock;

namespace lazyfs {
Expand Down Expand Up @@ -94,7 +97,7 @@ vector<string> LazyFS::get_injecting_fault() {
return injecting_fault;
}

void LazyFS::trigger_crash_fault (string opname,
bool LazyFS::trigger_crash_fault (string opname,
string optiming,
string from_op_path,
string to_op_path,
Expand All @@ -115,6 +118,18 @@ void LazyFS::trigger_crash_fault (string opname,
status = lstat(char_array, &buffer);
*/

bool ret = true;
auto it = faults->find(from_op_path);
if (it != faults->end()) {
auto& v_faults = it->second;
for (auto fault : v_faults) {
faults::ReorderF* faultR = dynamic_cast<faults::ReorderF*>(fault);
if (faultR && faultR->op == opname && ret) ret = faultR->ret;
faults::SplitWriteF* faultS = dynamic_cast<faults::SplitWriteF*>(fault);
if (faultS && opname == "write" && ret) ret = faultS->ret;
}
}

if (optiming == "before") {
opfaults = this->crash_faults_before_map.at (opname);
} else {
Expand Down Expand Up @@ -157,17 +172,18 @@ void LazyFS::trigger_crash_fault (string opname,
this_ ()->command_unsynced_data_report (this->injecting_fault);
this->injecting_fault_lock.unlock();

pid_t lazyfs_pid = getpid ();
if (ret) return true;

pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);

kill (lazyfs_pid, SIGKILL);
}
}
}
return false;
}

void LazyFS::trigger_configured_clear_fault (string opname,
bool LazyFS::trigger_configured_clear_fault (string opname,
string optiming,
string from_path,
string to_path) {
Expand Down Expand Up @@ -202,10 +218,12 @@ void LazyFS::trigger_configured_clear_fault (string opname,
this->injecting_fault_lock.unlock();

if (clear_fault->crash) {

if (optiming == "after" && clear_fault->ret) return true;

pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
kill (lazyfs_pid, SIGKILL);

} else {
this_ ()->command_fault_clear_cache ();
Expand All @@ -214,8 +232,9 @@ void LazyFS::trigger_configured_clear_fault (string opname,
}
}
}
}
}
}
return false;
}

void LazyFS::add_crash_fault (string crash_timing,
Expand All @@ -237,7 +256,7 @@ void LazyFS::add_crash_fault (string crash_timing,
}
}

vector<string> 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, string ret_) {
regex number ("\\d+");
sregex_token_iterator iter(persist.begin(), persist.end(), number);
sregex_token_iterator end;
Expand Down Expand Up @@ -266,14 +285,21 @@ vector<string> LazyFS::add_torn_op_fault(string path, string parts, string parts

int occurrence=1;

bool ret;
std::regex pattern_true(R"([Tt]rue)");
std::regex pattern_false(R"([Ff]alse)");
if (std::regex_match(ret_, pattern_true)) ret = true;
else if(std::regex_match(ret_, pattern_false)) ret = false;
else ret = true;

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

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

Expand All @@ -300,7 +326,7 @@ vector<string> LazyFS::add_torn_op_fault(string path, string parts, string parts
return errors;
}

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

faults::ReorderF* fault = new faults::ReorderF(op, persistv, 1);
bool ret;
std::regex pattern_true(R"([Tt]rue)");
std::regex pattern_false(R"([Ff]alse)");
if (std::regex_match(ret_, pattern_true)) ret = true;
else if(std::regex_match(ret_, pattern_false)) ret = false;
else ret = true;

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

bool valid_fault = true;
Expand Down Expand Up @@ -810,6 +843,14 @@ int LazyFS::lfs_readdir (const char* path,

int LazyFS::lfs_open (const char* path, struct fuse_file_info* fi) {

kill_lock.lock();
if (kill_before) {
pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
}
kill_lock.unlock();

this_ ()->trigger_crash_fault ("open", "before", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("open", "before", path, "");

Expand Down Expand Up @@ -854,14 +895,24 @@ int LazyFS::lfs_open (const char* path, struct fuse_file_info* fi) {
if (fi->flags & O_TRUNC)
lfs_truncate (path, 0, fi);

this_ ()->trigger_crash_fault ("open", "after", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("open", "after", path, "");
kill_lock.lock();
if (!kill_before) kill_before = this_()->trigger_crash_fault ("open", "after", path, "", CLEAR) || this_()->trigger_configured_clear_fault ("open", "after", path, "");
if (kill_before) spdlog::critical("Open returned. LazyFS will crash before the next system call.");
kill_lock.unlock();

return 0;
}

int LazyFS::lfs_create (const char* path, mode_t mode, struct fuse_file_info* fi) {

kill_lock.lock();
if (kill_before) {
pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
}
kill_lock.unlock();

this_ ()->trigger_crash_fault ("create", "before", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("create", "before", path, "");

Expand Down Expand Up @@ -929,8 +980,10 @@ int LazyFS::lfs_create (const char* path, mode_t mode, struct fuse_file_info* fi
this_ ()->FSCache->unlockItem (inode);
}

this_ ()->trigger_crash_fault ("create", "after", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("create", "after", path, "");
kill_lock.lock();
if (!kill_before) kill_before = this_ ()->trigger_crash_fault ("create", "after", path, "", CLEAR) || this_ ()->trigger_configured_clear_fault ("create", "after", path, "");
if (kill_before) spdlog::critical("Create returned. LazyFS will crash before the next system call.");
kill_lock.unlock();

return 0;
}
Expand All @@ -941,6 +994,14 @@ int LazyFS::lfs_write (const char* path,
off_t offset,
struct fuse_file_info* fi) {

kill_lock.lock();
if (kill_before) {
pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
}
kill_lock.unlock();

this_ ()->trigger_crash_fault ("write", "before", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("write", "before", path, "");

Expand Down Expand Up @@ -1286,10 +1347,10 @@ int LazyFS::lfs_write (const char* path,
if (fi == NULL)
close (fd);



this_ ()->trigger_crash_fault ("write", "after", path, "",fault_type);
this_ ()->trigger_configured_clear_fault ("write", "after", path, "");
kill_lock.lock();
if (!kill_before) kill_before = this_ ()->trigger_crash_fault ("write", "after", path, "",fault_type) || this_ ()->trigger_configured_clear_fault ("write", "after", path, "");
if (kill_before) spdlog::critical("Write returned. LazyFS will crash before the next system call.");
kill_lock.unlock();

return res;
}
Expand All @@ -1300,6 +1361,14 @@ int LazyFS::lfs_read (const char* path,
off_t offset,
struct fuse_file_info* fi) {

kill_lock.lock();
if (kill_before) {
pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
}
kill_lock.unlock();

this_ ()->trigger_crash_fault ("read", "before", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("read", "before", path, "");

Expand Down Expand Up @@ -1532,14 +1601,24 @@ int LazyFS::lfs_read (const char* path,
if (fi == NULL)
close (fd);

this_ ()->trigger_crash_fault ("read", "after", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("read", "after", path, "");
kill_lock.lock();
if (!kill_before) kill_before = this_ ()->trigger_crash_fault ("read", "after", path, "", CLEAR) || this_ ()->trigger_configured_clear_fault ("read", "after", path, "");
if (kill_before) spdlog::critical("Read returned. LazyFS will crash before the next system call.");
kill_lock.unlock();

return res;
}

int LazyFS::lfs_fsync (const char* path, int isdatasync, struct fuse_file_info* fi) {

kill_lock.lock();
if (kill_before) {
pid_t lazyfs_pid = getpid ();
spdlog::critical ("Killing LazyFS pid {}!", lazyfs_pid);
kill (lazyfs_pid, SIGKILL);
}
kill_lock.unlock();

this_ ()->trigger_crash_fault ("fsync", "before", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("fsync", "before", path, "");

Expand Down Expand Up @@ -1570,9 +1649,10 @@ int LazyFS::lfs_fsync (const char* path, int isdatasync, struct fuse_file_info*
res = is_owner_cached ? this_ ()->FSCache->sync_owner (inode, false, (char*)path)
: fsync (fi->fh);


this_ ()->trigger_crash_fault ("fsync", "after", path, "", CLEAR);
this_ ()->trigger_configured_clear_fault ("fsync", "after", path, "");
kill_lock.lock();
if (!kill_before) kill_before = this_ ()->trigger_crash_fault ("fsync", "after", path, "", CLEAR) || this_ ()->trigger_configured_clear_fault ("fsync", "after", path, "");
if (kill_before) spdlog::critical("Fsync returned. LazyFS will crash before the next system call.");
kill_lock.unlock();

return res;
}
Expand Down
Loading

0 comments on commit f6a0939

Please sign in to comment.