Loading lfs/src/adafs_ops/db_ops.cpp +29 −7 Original line number Diff line number Diff line Loading @@ -7,14 +7,36 @@ using namespace rocksdb; using namespace std; bool db_put(const string key, const time_t val) { inline const string db_get_mdata_helper(const char* key) { auto db = ADAFS_DATA->rdb().get(); return db->Put(WriteOptions(), key, fmt::FormatInt(val).c_str()).ok(); string val_str; db->Get(ReadOptions(), key, &val_str); return val_str; } time_t db_get(const string key) { template<> unsigned long db_get_mdata<unsigned long>(const char* key) { return stoul(db_get_mdata_helper(key)); } template<> long db_get_mdata<long>(const char* key) { return stol(db_get_mdata_helper(key)); } template<> unsigned int db_get_mdata<unsigned int>(const char* key) { return static_cast<unsigned int>(stoul(db_get_mdata_helper(key))); } bool db_dentry_exists(const char* key) { // auto db = ADAFS_DATA->rdb().get(); //TODO return true; } bool db_mdata_exists(const char* key) { auto db = ADAFS_DATA->rdb().get(); string val_s; db->Get(ReadOptions(), key, &val_s); return static_cast<time_t>(stol(val_s)); string val_str; return db->Get(ReadOptions(), key, &val_str).ok(); } lfs/src/adafs_ops/db_ops.hpp +9 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,16 @@ #include "../main.hpp" template<typename T> bool db_put_mdata(const char* key, const T val) { auto db = ADAFS_DATA->rdb().get(); auto val_str = fmt::FormatInt(val).c_str(); return db->Put(rocksdb::WriteOptions(), key, val_str).ok(); } bool db_put(const std::string key, const time_t val); template<typename T> T db_get_mdata(const char* key); time_t db_get(const std::string key); bool db_mdata_exists(const char* key); #endif //LFS_DB_OPS_HPP lfs/src/adafs_ops/mdata_ops.cpp +26 −24 Original line number Diff line number Diff line Loading @@ -9,34 +9,35 @@ // TODO error handling. Each read_metadata_field should check for boolean, i.e., if I/O failed. bool write_all_metadata(const Metadata& md, const fuse_ino_t inode) { db_put(fmt::FormatInt(inode).str(), md.atime()); write_metadata_field(md.atime(), std::get<to_underlying(Md_fields::atime)>(md_field_map), inode); write_metadata_field(md.mtime(), std::get<to_underlying(Md_fields::mtime)>(md_field_map), inode); write_metadata_field(md.ctime(), std::get<to_underlying(Md_fields::ctime)>(md_field_map), inode); write_metadata_field(md.uid(), std::get<to_underlying(Md_fields::uid)>(md_field_map), inode); write_metadata_field(md.gid(), std::get<to_underlying(Md_fields::gid)>(md_field_map), inode); write_metadata_field(md.mode(), std::get<to_underlying(Md_fields::mode)>(md_field_map), inode); write_metadata_field(md.inode_no(), std::get<to_underlying(Md_fields::inode_no)>(md_field_map), inode); write_metadata_field(md.link_count(), std::get<to_underlying(Md_fields::link_count)>(md_field_map), inode); write_metadata_field(md.size(), std::get<to_underlying(Md_fields::size)>(md_field_map), inode); write_metadata_field(md.blocks(), std::get<to_underlying(Md_fields::blocks)>(md_field_map), inode); auto inode_key = fmt::FormatInt(inode).str(); db_put_mdata((inode_key + "atime"s).c_str(), md.atime()); db_put_mdata((inode_key + "mtime"s).c_str(), md.mtime()); db_put_mdata((inode_key + "ctime"s).c_str(), md.ctime()); db_put_mdata((inode_key + "uid"s).c_str(), md.uid()); db_put_mdata((inode_key + "gid"s).c_str(), md.gid()); db_put_mdata((inode_key + "mode"s).c_str(), md.mode()); db_put_mdata((inode_key + "inodeno"s).c_str(), md.inode_no()); db_put_mdata((inode_key + "linkcnt"s).c_str(), md.link_count()); db_put_mdata((inode_key + "size"s).c_str(), md.size()); db_put_mdata((inode_key + "blocks"s).c_str(), md.blocks()); return true; } // TODO error handling. Each read_metadata_field should check for nullptr, i.e., if I/O failed. bool read_all_metadata(Metadata& md, const fuse_ino_t inode) { auto re = db_get(fmt::FormatInt(inode).str()); md.atime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::atime)>(md_field_map), inode)); md.mtime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::mtime)>(md_field_map), inode)); md.ctime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::ctime)>(md_field_map), inode)); md.uid(*read_metadata_field<uid_t>(std::get<to_underlying(Md_fields::uid)>(md_field_map), inode)); md.gid(*read_metadata_field<gid_t>(std::get<to_underlying(Md_fields::gid)>(md_field_map), inode)); md.mode(*read_metadata_field<mode_t>(std::get<to_underlying(Md_fields::mode)>(md_field_map), inode)); md.inode_no(*read_metadata_field<fuse_ino_t>(std::get<to_underlying(Md_fields::inode_no)>(md_field_map), inode)); md.link_count(*read_metadata_field<nlink_t>(std::get<to_underlying(Md_fields::link_count)>(md_field_map), inode)); md.size(*read_metadata_field<off_t>(std::get<to_underlying(Md_fields::size)>(md_field_map), inode)); md.blocks(*read_metadata_field<blkcnt_t>(std::get<to_underlying(Md_fields::blocks)>(md_field_map), inode)); auto inode_key = fmt::FormatInt(inode).str(); md.atime(db_get_mdata<time_t>((inode_key + "atime"s).c_str())); md.mtime(db_get_mdata<time_t>((inode_key + "mtime"s).c_str())); md.ctime(db_get_mdata<time_t>((inode_key + "ctime"s).c_str())); md.uid(db_get_mdata<uid_t>((inode_key + "uid"s).c_str())); md.gid(db_get_mdata<gid_t>((inode_key + "gid"s).c_str())); md.mode(db_get_mdata<mode_t>((inode_key + "mode"s).c_str())); md.inode_no(db_get_mdata<fuse_ino_t>((inode_key + "inodeno"s).c_str())); md.link_count(db_get_mdata<nlink_t>((inode_key + "linkcnt"s).c_str())); md.size(db_get_mdata<off_t>((inode_key + "size"s).c_str())); md.blocks(db_get_mdata<blkcnt_t>((inode_key + "blocks"s).c_str())); return true; } Loading @@ -51,7 +52,8 @@ int get_metadata(Metadata& md, const fuse_ino_t inode) { // Verify that the file's inode exists auto path = bfs::path(ADAFS_DATA->inode_path()); path /= fmt::FormatInt(inode).c_str(); if (bfs::exists(path)) { // TODO CHECK FOR DENTRY INSTEAD and remove the db_mdata_exists function! if (db_mdata_exists((fmt::FormatInt(inode).str() + "mtime"s).c_str())) { read_all_metadata(md, inode); return 0; } else Loading lfs/src/configure.hpp +2 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ #define FS_CONFIGURE_H // To enabled logging with info level #define LOG_INFO //#define LOG_DEBUG //#define LOG_INFO #define LOG_DEBUG //#define LOG_TRACE // If ACM time should be considered Loading lfs/src/main.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ extern "C" { #include <fuse3/fuse_lowlevel.h> }; } // std libs #include <string> #include <iostream> Loading Loading
lfs/src/adafs_ops/db_ops.cpp +29 −7 Original line number Diff line number Diff line Loading @@ -7,14 +7,36 @@ using namespace rocksdb; using namespace std; bool db_put(const string key, const time_t val) { inline const string db_get_mdata_helper(const char* key) { auto db = ADAFS_DATA->rdb().get(); return db->Put(WriteOptions(), key, fmt::FormatInt(val).c_str()).ok(); string val_str; db->Get(ReadOptions(), key, &val_str); return val_str; } time_t db_get(const string key) { template<> unsigned long db_get_mdata<unsigned long>(const char* key) { return stoul(db_get_mdata_helper(key)); } template<> long db_get_mdata<long>(const char* key) { return stol(db_get_mdata_helper(key)); } template<> unsigned int db_get_mdata<unsigned int>(const char* key) { return static_cast<unsigned int>(stoul(db_get_mdata_helper(key))); } bool db_dentry_exists(const char* key) { // auto db = ADAFS_DATA->rdb().get(); //TODO return true; } bool db_mdata_exists(const char* key) { auto db = ADAFS_DATA->rdb().get(); string val_s; db->Get(ReadOptions(), key, &val_s); return static_cast<time_t>(stol(val_s)); string val_str; return db->Get(ReadOptions(), key, &val_str).ok(); }
lfs/src/adafs_ops/db_ops.hpp +9 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,16 @@ #include "../main.hpp" template<typename T> bool db_put_mdata(const char* key, const T val) { auto db = ADAFS_DATA->rdb().get(); auto val_str = fmt::FormatInt(val).c_str(); return db->Put(rocksdb::WriteOptions(), key, val_str).ok(); } bool db_put(const std::string key, const time_t val); template<typename T> T db_get_mdata(const char* key); time_t db_get(const std::string key); bool db_mdata_exists(const char* key); #endif //LFS_DB_OPS_HPP
lfs/src/adafs_ops/mdata_ops.cpp +26 −24 Original line number Diff line number Diff line Loading @@ -9,34 +9,35 @@ // TODO error handling. Each read_metadata_field should check for boolean, i.e., if I/O failed. bool write_all_metadata(const Metadata& md, const fuse_ino_t inode) { db_put(fmt::FormatInt(inode).str(), md.atime()); write_metadata_field(md.atime(), std::get<to_underlying(Md_fields::atime)>(md_field_map), inode); write_metadata_field(md.mtime(), std::get<to_underlying(Md_fields::mtime)>(md_field_map), inode); write_metadata_field(md.ctime(), std::get<to_underlying(Md_fields::ctime)>(md_field_map), inode); write_metadata_field(md.uid(), std::get<to_underlying(Md_fields::uid)>(md_field_map), inode); write_metadata_field(md.gid(), std::get<to_underlying(Md_fields::gid)>(md_field_map), inode); write_metadata_field(md.mode(), std::get<to_underlying(Md_fields::mode)>(md_field_map), inode); write_metadata_field(md.inode_no(), std::get<to_underlying(Md_fields::inode_no)>(md_field_map), inode); write_metadata_field(md.link_count(), std::get<to_underlying(Md_fields::link_count)>(md_field_map), inode); write_metadata_field(md.size(), std::get<to_underlying(Md_fields::size)>(md_field_map), inode); write_metadata_field(md.blocks(), std::get<to_underlying(Md_fields::blocks)>(md_field_map), inode); auto inode_key = fmt::FormatInt(inode).str(); db_put_mdata((inode_key + "atime"s).c_str(), md.atime()); db_put_mdata((inode_key + "mtime"s).c_str(), md.mtime()); db_put_mdata((inode_key + "ctime"s).c_str(), md.ctime()); db_put_mdata((inode_key + "uid"s).c_str(), md.uid()); db_put_mdata((inode_key + "gid"s).c_str(), md.gid()); db_put_mdata((inode_key + "mode"s).c_str(), md.mode()); db_put_mdata((inode_key + "inodeno"s).c_str(), md.inode_no()); db_put_mdata((inode_key + "linkcnt"s).c_str(), md.link_count()); db_put_mdata((inode_key + "size"s).c_str(), md.size()); db_put_mdata((inode_key + "blocks"s).c_str(), md.blocks()); return true; } // TODO error handling. Each read_metadata_field should check for nullptr, i.e., if I/O failed. bool read_all_metadata(Metadata& md, const fuse_ino_t inode) { auto re = db_get(fmt::FormatInt(inode).str()); md.atime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::atime)>(md_field_map), inode)); md.mtime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::mtime)>(md_field_map), inode)); md.ctime(*read_metadata_field<time_t>(std::get<to_underlying(Md_fields::ctime)>(md_field_map), inode)); md.uid(*read_metadata_field<uid_t>(std::get<to_underlying(Md_fields::uid)>(md_field_map), inode)); md.gid(*read_metadata_field<gid_t>(std::get<to_underlying(Md_fields::gid)>(md_field_map), inode)); md.mode(*read_metadata_field<mode_t>(std::get<to_underlying(Md_fields::mode)>(md_field_map), inode)); md.inode_no(*read_metadata_field<fuse_ino_t>(std::get<to_underlying(Md_fields::inode_no)>(md_field_map), inode)); md.link_count(*read_metadata_field<nlink_t>(std::get<to_underlying(Md_fields::link_count)>(md_field_map), inode)); md.size(*read_metadata_field<off_t>(std::get<to_underlying(Md_fields::size)>(md_field_map), inode)); md.blocks(*read_metadata_field<blkcnt_t>(std::get<to_underlying(Md_fields::blocks)>(md_field_map), inode)); auto inode_key = fmt::FormatInt(inode).str(); md.atime(db_get_mdata<time_t>((inode_key + "atime"s).c_str())); md.mtime(db_get_mdata<time_t>((inode_key + "mtime"s).c_str())); md.ctime(db_get_mdata<time_t>((inode_key + "ctime"s).c_str())); md.uid(db_get_mdata<uid_t>((inode_key + "uid"s).c_str())); md.gid(db_get_mdata<gid_t>((inode_key + "gid"s).c_str())); md.mode(db_get_mdata<mode_t>((inode_key + "mode"s).c_str())); md.inode_no(db_get_mdata<fuse_ino_t>((inode_key + "inodeno"s).c_str())); md.link_count(db_get_mdata<nlink_t>((inode_key + "linkcnt"s).c_str())); md.size(db_get_mdata<off_t>((inode_key + "size"s).c_str())); md.blocks(db_get_mdata<blkcnt_t>((inode_key + "blocks"s).c_str())); return true; } Loading @@ -51,7 +52,8 @@ int get_metadata(Metadata& md, const fuse_ino_t inode) { // Verify that the file's inode exists auto path = bfs::path(ADAFS_DATA->inode_path()); path /= fmt::FormatInt(inode).c_str(); if (bfs::exists(path)) { // TODO CHECK FOR DENTRY INSTEAD and remove the db_mdata_exists function! if (db_mdata_exists((fmt::FormatInt(inode).str() + "mtime"s).c_str())) { read_all_metadata(md, inode); return 0; } else Loading
lfs/src/configure.hpp +2 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ #define FS_CONFIGURE_H // To enabled logging with info level #define LOG_INFO //#define LOG_DEBUG //#define LOG_INFO #define LOG_DEBUG //#define LOG_TRACE // If ACM time should be considered Loading
lfs/src/main.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ extern "C" { #include <fuse3/fuse_lowlevel.h> }; } // std libs #include <string> #include <iostream> Loading