Loading include/client/rpc/forward_metadata.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,12 @@ class Metadata; } namespace rpc { // enum definieren TODO enum class ForwardCreateStatus { ok, exists, error = -1 }; int forward_create(const std::string& path, mode_t mode); Loading include/daemon/backend/exceptions.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ public: explicit NotFoundException(const std::string& s) : DBException(s) {}; }; class CreateException : public DBException { public: CreateException(const std::string& s) : DBException(s) {}; }; } // namespace metadata } // namespace gkfs Loading src/client/gkfs_functions.cpp +48 −46 Original line number Diff line number Diff line Loading @@ -100,46 +100,49 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { return -1; } bool exists = true; auto md = gkfs::util::get_metadata(path); if (!md) { if (errno == ENOENT) { exists = false; } else { LOG(ERROR, "Error while retriving stat to file"); return -1; } } if (!exists) { if (!(flags & O_CREAT)) { // file doesn't exists and O_CREAT was not set errno = ENOENT; return -1; } /*** CREATION ***/ assert(flags & O_CREAT); // dummy metadata creation std::shared_ptr<gkfs::metadata::Metadata> md{}; if (flags & O_CREAT) { if (flags & O_DIRECTORY) { LOG(ERROR, "O_DIRECTORY use with O_CREAT. NOT SUPPORTED"); errno = ENOTSUP; return -1; } // no access check required here. If one is using our FS they have the permissions. if (gkfs_create(path, mode | S_IFREG)) { LOG(ERROR, "Error creating non-existent file: '{}'", strerror(errno)); int err_code = gkfs_create(path, mode | S_IFREG); if (err_code == (int) gkfs::rpc::ForwardCreateStatus::error) { LOG(ERROR, "Error creating file: '{}'", strerror(errno)); return -1; } } else { /* File already exists */ if (err_code == (int) gkfs::rpc::ForwardCreateStatus::exists) { // file exists, O_CREAT was set if (flags & O_EXCL) { // File exists and O_EXCL was set // File exists and O_EXCL & O_CREAT was set errno = EEXIST; return -1; } // file exists, O_CREAT was set O_EXCL wasnt, so function does not fail md = gkfs::util::get_metadata(path); } if (err_code == 0) { // file was created return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags)); } } else { md = gkfs::util::get_metadata(path); if (!md) { if (errno == ENOENT) { // file doesn't exists and O_CREAT was not set return -1; } else { LOG(ERROR, "Error statting existing file"); return -1; } } } // **file exists** #ifdef HAS_SYMLINKS if (md->is_link()) { Loading @@ -166,7 +169,6 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { return -1; } } } return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags)); } Loading src/client/rpc/forward_metadata.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -41,17 +41,21 @@ int forward_create(const std::string& path, const mode_t mode) { // result_set. When that happens we can remove the .at(0) :/ auto out = ld_network_service->post<gkfs::rpc::create>(endp, path, mode).get().at(0); err = out.err(); LOG(DEBUG, "Got response success: {}", err); LOG(ERROR, "Got response success: {}", err) if (out.err() == (int) gkfs::rpc::ForwardCreateStatus::exists) { errno = out.err(); return (int) gkfs::rpc::ForwardCreateStatus::exists; } if (out.err()) { errno = out.err(); return -1; return (int) gkfs::rpc::ForwardCreateStatus::error; } } catch (const std::exception& ex) { LOG(ERROR, "while getting rpc output"); errno = EBUSY; return -1; return (int) gkfs::rpc::ForwardCreateStatus::error; } return err; Loading src/daemon/daemon.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,7 @@ void init_environment() { GKFS_DATA->spdlogger()->debug("{}() Initializing metadata DB: '{}'", __func__, metadata_path); try { GKFS_DATA->mdb(std::make_shared<gkfs::metadata::MetadataDB>(metadata_path)); } catch (const CreateException& e) { } catch (const std::exception& e) { GKFS_DATA->spdlogger()->error("{}() Failed to initialize metadata DB: {}", __func__, e.what()); throw; Loading Loading
include/client/rpc/forward_metadata.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,12 @@ class Metadata; } namespace rpc { // enum definieren TODO enum class ForwardCreateStatus { ok, exists, error = -1 }; int forward_create(const std::string& path, mode_t mode); Loading
include/daemon/backend/exceptions.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ public: explicit NotFoundException(const std::string& s) : DBException(s) {}; }; class CreateException : public DBException { public: CreateException(const std::string& s) : DBException(s) {}; }; } // namespace metadata } // namespace gkfs Loading
src/client/gkfs_functions.cpp +48 −46 Original line number Diff line number Diff line Loading @@ -100,46 +100,49 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { return -1; } bool exists = true; auto md = gkfs::util::get_metadata(path); if (!md) { if (errno == ENOENT) { exists = false; } else { LOG(ERROR, "Error while retriving stat to file"); return -1; } } if (!exists) { if (!(flags & O_CREAT)) { // file doesn't exists and O_CREAT was not set errno = ENOENT; return -1; } /*** CREATION ***/ assert(flags & O_CREAT); // dummy metadata creation std::shared_ptr<gkfs::metadata::Metadata> md{}; if (flags & O_CREAT) { if (flags & O_DIRECTORY) { LOG(ERROR, "O_DIRECTORY use with O_CREAT. NOT SUPPORTED"); errno = ENOTSUP; return -1; } // no access check required here. If one is using our FS they have the permissions. if (gkfs_create(path, mode | S_IFREG)) { LOG(ERROR, "Error creating non-existent file: '{}'", strerror(errno)); int err_code = gkfs_create(path, mode | S_IFREG); if (err_code == (int) gkfs::rpc::ForwardCreateStatus::error) { LOG(ERROR, "Error creating file: '{}'", strerror(errno)); return -1; } } else { /* File already exists */ if (err_code == (int) gkfs::rpc::ForwardCreateStatus::exists) { // file exists, O_CREAT was set if (flags & O_EXCL) { // File exists and O_EXCL was set // File exists and O_EXCL & O_CREAT was set errno = EEXIST; return -1; } // file exists, O_CREAT was set O_EXCL wasnt, so function does not fail md = gkfs::util::get_metadata(path); } if (err_code == 0) { // file was created return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags)); } } else { md = gkfs::util::get_metadata(path); if (!md) { if (errno == ENOENT) { // file doesn't exists and O_CREAT was not set return -1; } else { LOG(ERROR, "Error statting existing file"); return -1; } } } // **file exists** #ifdef HAS_SYMLINKS if (md->is_link()) { Loading @@ -166,7 +169,6 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { return -1; } } } return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags)); } Loading
src/client/rpc/forward_metadata.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -41,17 +41,21 @@ int forward_create(const std::string& path, const mode_t mode) { // result_set. When that happens we can remove the .at(0) :/ auto out = ld_network_service->post<gkfs::rpc::create>(endp, path, mode).get().at(0); err = out.err(); LOG(DEBUG, "Got response success: {}", err); LOG(ERROR, "Got response success: {}", err) if (out.err() == (int) gkfs::rpc::ForwardCreateStatus::exists) { errno = out.err(); return (int) gkfs::rpc::ForwardCreateStatus::exists; } if (out.err()) { errno = out.err(); return -1; return (int) gkfs::rpc::ForwardCreateStatus::error; } } catch (const std::exception& ex) { LOG(ERROR, "while getting rpc output"); errno = EBUSY; return -1; return (int) gkfs::rpc::ForwardCreateStatus::error; } return err; Loading
src/daemon/daemon.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,7 @@ void init_environment() { GKFS_DATA->spdlogger()->debug("{}() Initializing metadata DB: '{}'", __func__, metadata_path); try { GKFS_DATA->mdb(std::make_shared<gkfs::metadata::MetadataDB>(metadata_path)); } catch (const CreateException& e) { } catch (const std::exception& e) { GKFS_DATA->spdlogger()->error("{}() Failed to initialize metadata DB: {}", __func__, e.what()); throw; Loading