From 1977a720dfafea3c894c76f91a419ea159a105c5 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sun, 4 Oct 2015 17:20:14 +0200 Subject: [PATCH] Introduced ParallelAccessFsBlobStore to avoid race conditions when accessing the same FsBlob in parallel --- biicode.conf | 1 + src/filesystem/CryDevice.cpp | 42 +++++---- src/filesystem/CryDevice.h | 22 ++--- src/filesystem/CryDir.cpp | 12 ++- src/filesystem/CryDir.h | 6 +- src/filesystem/CryFile.cpp | 10 +-- src/filesystem/CryFile.h | 8 +- src/filesystem/CryNode.cpp | 8 +- src/filesystem/CryNode.h | 8 +- src/filesystem/CryOpenFile.cpp | 4 +- src/filesystem/CryOpenFile.h | 6 +- src/filesystem/CrySymlink.cpp | 12 +-- src/filesystem/CrySymlink.h | 8 +- src/filesystem/fsblobstore/DirBlob.cpp | 20 +++-- src/filesystem/fsblobstore/DirBlob.h | 10 +-- src/filesystem/fsblobstore/FileBlob.cpp | 13 ++- src/filesystem/fsblobstore/FileBlob.h | 6 +- src/filesystem/fsblobstore/FsBlob.h | 13 ++- src/filesystem/fsblobstore/FsBlobStore.cpp | 31 +++---- src/filesystem/fsblobstore/FsBlobStore.h | 5 +- src/filesystem/fsblobstore/SymlinkBlob.cpp | 8 +- src/filesystem/fsblobstore/SymlinkBlob.h | 5 +- .../parallelaccessfsblobstore/DirBlobRef.cpp | 1 + .../parallelaccessfsblobstore/DirBlobRef.h | 80 +++++++++++++++++ .../parallelaccessfsblobstore/FileBlobRef.cpp | 1 + .../parallelaccessfsblobstore/FileBlobRef.h | 49 ++++++++++ .../parallelaccessfsblobstore/FsBlobRef.cpp | 1 + .../parallelaccessfsblobstore/FsBlobRef.h | 25 ++++++ .../ParallelAccessFsBlobStore.cpp | 89 +++++++++++++++++++ .../ParallelAccessFsBlobStore.h | 36 ++++++++ .../ParallelAccessFsBlobStoreAdapter.cpp | 1 + .../ParallelAccessFsBlobStoreAdapter.h | 34 +++++++ .../SymlinkBlobRef.cpp | 1 + .../SymlinkBlobRef.h | 33 +++++++ src/main.cpp | 1 + 35 files changed, 475 insertions(+), 135 deletions(-) create mode 100644 src/filesystem/parallelaccessfsblobstore/DirBlobRef.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/DirBlobRef.h create mode 100644 src/filesystem/parallelaccessfsblobstore/FileBlobRef.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/FileBlobRef.h create mode 100644 src/filesystem/parallelaccessfsblobstore/FsBlobRef.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/FsBlobRef.h create mode 100644 src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h create mode 100644 src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h create mode 100644 src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.cpp create mode 100644 src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h diff --git a/biicode.conf b/biicode.conf index 6c382b9e..3c621490 100644 --- a/biicode.conf +++ b/biicode.conf @@ -8,6 +8,7 @@ messmer/cpp-utils: 2 messmer/fspp: 0 messmer/gitversion: 5 + messmer/parallelaccessstore: 0 [parent] messmer/cryfs: 0 diff --git a/src/filesystem/CryDevice.cpp b/src/filesystem/CryDevice.cpp index a069b5b8..b5816eb0 100644 --- a/src/filesystem/CryDevice.cpp +++ b/src/filesystem/CryDevice.cpp @@ -1,6 +1,6 @@ #include #include -#include "fsblobstore/DirBlob.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" #include "CryDevice.h" #include "CryDir.h" @@ -11,7 +11,7 @@ #include "messmer/blobstore/implementations/onblocks/BlobStoreOnBlocks.h" #include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h" #include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h" -#include "fsblobstore/FsBlobStore.h" +#include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h" using std::string; @@ -32,10 +32,11 @@ using cpputils::dynamic_pointer_move; using boost::optional; using boost::none; using cryfs::fsblobstore::FsBlobStore; -using cryfs::fsblobstore::FileBlob; -using cryfs::fsblobstore::DirBlob; -using cryfs::fsblobstore::SymlinkBlob; -using cryfs::fsblobstore::FsBlob; +using cryfs::parallelaccessfsblobstore::ParallelAccessFsBlobStore; +using cryfs::parallelaccessfsblobstore::FileBlobRef; +using cryfs::parallelaccessfsblobstore::DirBlobRef; +using cryfs::parallelaccessfsblobstore::SymlinkBlobRef; +using cryfs::parallelaccessfsblobstore::FsBlobRef; namespace bf = boost::filesystem; @@ -44,11 +45,14 @@ namespace cryfs { constexpr uint32_t CryDevice::BLOCKSIZE_BYTES; CryDevice::CryDevice(unique_ref config, unique_ref blockStore) -: _fsBlobStore(make_unique_ref( - make_unique_ref( - make_unique_ref( - CreateEncryptedBlockStore(*config, std::move(blockStore)) - ), BLOCKSIZE_BYTES))), +: _fsBlobStore( + make_unique_ref( + make_unique_ref( + make_unique_ref( + make_unique_ref( + CreateEncryptedBlockStore(*config, std::move(blockStore)) + ), BLOCKSIZE_BYTES))) + ), _rootKey(GetOrCreateRootKey(config.get())) { } @@ -80,21 +84,21 @@ optional> CryDevice::Load(const bf::path &path) { } } -unique_ref CryDevice::LoadDirBlob(const bf::path &path) { +unique_ref CryDevice::LoadDirBlob(const bf::path &path) { auto blob = LoadBlob(path); - auto dir = dynamic_pointer_move(blob); + auto dir = dynamic_pointer_move(blob); if (dir == none) { throw FuseErrnoException(ENOTDIR); // Loaded blob is not a directory } return std::move(*dir); } -unique_ref CryDevice::LoadBlob(const bf::path &path) { +unique_ref CryDevice::LoadBlob(const bf::path &path) { auto currentBlob = _fsBlobStore->load(_rootKey); ASSERT(currentBlob != none, "rootDir not found"); for (const bf::path &component : path.relative_path()) { - auto currentDir = dynamic_pointer_move(*currentBlob); + auto currentDir = dynamic_pointer_move(*currentBlob); if (currentDir == none) { throw FuseErrnoException(ENOTDIR); // Path component is not a dir } @@ -117,19 +121,19 @@ void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) { throw FuseErrnoException(ENOTSUP); } -unique_ref CryDevice::CreateFileBlob() { +unique_ref CryDevice::CreateFileBlob() { return _fsBlobStore->createFileBlob(); } -unique_ref CryDevice::CreateDirBlob() { +unique_ref CryDevice::CreateDirBlob() { return _fsBlobStore->createDirBlob(); } -unique_ref CryDevice::CreateSymlinkBlob(const bf::path &target) { +unique_ref CryDevice::CreateSymlinkBlob(const bf::path &target) { return _fsBlobStore->createSymlinkBlob(target); } -unique_ref CryDevice::LoadBlob(const blockstore::Key &key) { +unique_ref CryDevice::LoadBlob(const blockstore::Key &key) { auto blob = _fsBlobStore->load(key); ASSERT(blob != none, "Blob not found"); return std::move(*blob); diff --git a/src/filesystem/CryDevice.h b/src/filesystem/CryDevice.h index 03289732..63025357 100644 --- a/src/filesystem/CryDevice.h +++ b/src/filesystem/CryDevice.h @@ -8,10 +8,10 @@ #include #include -#include "fsblobstore/FsBlobStore.h" -#include "fsblobstore/DirBlob.h" -#include "fsblobstore/FileBlob.h" -#include "fsblobstore/SymlinkBlob.h" +#include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" +#include "parallelaccessfsblobstore/FileBlobRef.h" +#include "parallelaccessfsblobstore/SymlinkBlobRef.h" namespace cryfs { @@ -24,12 +24,12 @@ public: void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override; - cpputils::unique_ref CreateFileBlob(); - cpputils::unique_ref CreateDirBlob(); - cpputils::unique_ref CreateSymlinkBlob(const boost::filesystem::path &target); - cpputils::unique_ref LoadBlob(const blockstore::Key &key); //TODO Do I still need this function? - cpputils::unique_ref LoadBlob(const boost::filesystem::path &path); - cpputils::unique_ref LoadDirBlob(const boost::filesystem::path &path); + cpputils::unique_ref CreateFileBlob(); + cpputils::unique_ref CreateDirBlob(); + cpputils::unique_ref CreateSymlinkBlob(const boost::filesystem::path &target); + cpputils::unique_ref LoadBlob(const blockstore::Key &key); //TODO Do I still need this function? + cpputils::unique_ref LoadBlob(const boost::filesystem::path &path); + cpputils::unique_ref LoadDirBlob(const boost::filesystem::path &path); void RemoveBlob(const blockstore::Key &key); boost::optional> Load(const boost::filesystem::path &path) override; @@ -37,7 +37,7 @@ public: private: - cpputils::unique_ref _fsBlobStore; + cpputils::unique_ref _fsBlobStore; blockstore::Key _rootKey; diff --git a/src/filesystem/CryDir.cpp b/src/filesystem/CryDir.cpp index 955fa488..a26fab7b 100644 --- a/src/filesystem/CryDir.cpp +++ b/src/filesystem/CryDir.cpp @@ -9,7 +9,6 @@ #include "CryDevice.h" #include "CryFile.h" #include "CryOpenFile.h" -#include "fsblobstore/SymlinkBlob.h" //TODO Get rid of this in favor of exception hierarchy using fspp::fuse::CHECK_RETVAL; @@ -26,11 +25,11 @@ using cpputils::make_unique_ref; using cpputils::dynamic_pointer_move; using boost::optional; using boost::none; -using cryfs::fsblobstore::DirBlob; +using cryfs::parallelaccessfsblobstore::DirBlobRef; namespace cryfs { -CryDir::CryDir(CryDevice *device, boost::optional> parent, const Key &key) +CryDir::CryDir(CryDevice *device, boost::optional> parent, const Key &key) : CryNode(device, std::move(parent), key) { } @@ -38,9 +37,8 @@ CryDir::~CryDir() { } unique_ref CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) { - auto blob = LoadBlob(); auto child = device()->CreateFileBlob(); - blob->AddChildFile(name, child->key(), mode, uid, gid); + LoadBlob()->AddChildFile(name, child->key(), mode, uid, gid); return make_unique_ref(std::move(child)); } @@ -50,9 +48,9 @@ void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) { blob->AddChildDir(name, child->key(), mode, uid, gid); } -unique_ref CryDir::LoadBlob() const { +unique_ref CryDir::LoadBlob() const { auto blob = CryNode::LoadBlob(); - auto dir_blob = dynamic_pointer_move(blob); + auto dir_blob = dynamic_pointer_move(blob); ASSERT(dir_blob != none, "Blob does not store a directory"); return std::move(*dir_blob); } diff --git a/src/filesystem/CryDir.h b/src/filesystem/CryDir.h index 834bb129..41345271 100644 --- a/src/filesystem/CryDir.h +++ b/src/filesystem/CryDir.h @@ -4,13 +4,13 @@ #include #include "CryNode.h" -#include "fsblobstore/DirBlob.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" namespace cryfs { class CryDir: public fspp::Dir, CryNode { public: - CryDir(CryDevice *device, boost::optional> parent, const blockstore::Key &key); + CryDir(CryDevice *device, boost::optional> parent, const blockstore::Key &key); virtual ~CryDir(); //TODO return type variance to CryFile/CryDir? @@ -24,7 +24,7 @@ public: fspp::Dir::EntryType getType() const override; private: - cpputils::unique_ref LoadBlob() const; + cpputils::unique_ref LoadBlob() const; DISALLOW_COPY_AND_ASSIGN(CryDir); }; diff --git a/src/filesystem/CryFile.cpp b/src/filesystem/CryFile.cpp index bb4538f9..9e902d39 100644 --- a/src/filesystem/CryFile.cpp +++ b/src/filesystem/CryFile.cpp @@ -15,21 +15,21 @@ using boost::none; using cpputils::unique_ref; using cpputils::make_unique_ref; using cpputils::dynamic_pointer_move; -using cryfs::fsblobstore::DirBlob; -using cryfs::fsblobstore::FileBlob; +using cryfs::parallelaccessfsblobstore::DirBlobRef; +using cryfs::parallelaccessfsblobstore::FileBlobRef; namespace cryfs { -CryFile::CryFile(CryDevice *device, unique_ref parent, const Key &key) +CryFile::CryFile(CryDevice *device, unique_ref parent, const Key &key) : CryNode(device, std::move(parent), key) { } CryFile::~CryFile() { } -unique_ref CryFile::LoadBlob() const { +unique_ref CryFile::LoadBlob() const { auto blob = CryNode::LoadBlob(); - auto file_blob = dynamic_pointer_move(blob); + auto file_blob = dynamic_pointer_move(blob); ASSERT(file_blob != none, "Blob does not store a file"); return std::move(*file_blob); } diff --git a/src/filesystem/CryFile.h b/src/filesystem/CryFile.h index 29470a5b..dc76fdd2 100644 --- a/src/filesystem/CryFile.h +++ b/src/filesystem/CryFile.h @@ -2,8 +2,8 @@ #ifndef CRYFS_LIB_CRYFILE_H_ #define CRYFS_LIB_CRYFILE_H_ -#include "fsblobstore/FileBlob.h" -#include "fsblobstore/DirBlob.h" +#include "parallelaccessfsblobstore/FileBlobRef.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" #include #include "CryNode.h" @@ -11,7 +11,7 @@ namespace cryfs { class CryFile: public fspp::File, CryNode { public: - CryFile(CryDevice *device, cpputils::unique_ref parent, const blockstore::Key &key); + CryFile(CryDevice *device, cpputils::unique_ref parent, const blockstore::Key &key); virtual ~CryFile(); cpputils::unique_ref open(int flags) const override; @@ -19,7 +19,7 @@ public: fspp::Dir::EntryType getType() const override; private: - cpputils::unique_ref LoadBlob() const; + cpputils::unique_ref LoadBlob() const; DISALLOW_COPY_AND_ASSIGN(CryFile); }; diff --git a/src/filesystem/CryNode.cpp b/src/filesystem/CryNode.cpp index fd7e3e77..bbe39773 100644 --- a/src/filesystem/CryNode.cpp +++ b/src/filesystem/CryNode.cpp @@ -16,8 +16,8 @@ using cpputils::dynamic_pointer_move; using cpputils::unique_ref; using boost::optional; using boost::none; -using cryfs::fsblobstore::FsBlob; -using cryfs::fsblobstore::DirBlob; +using cryfs::parallelaccessfsblobstore::FsBlobRef; +using cryfs::parallelaccessfsblobstore::DirBlobRef; //TODO Get rid of this in favor of an exception hierarchy using fspp::fuse::CHECK_RETVAL; @@ -25,7 +25,7 @@ using fspp::fuse::FuseErrnoException; namespace cryfs { -CryNode::CryNode(CryDevice *device, optional> parent, const Key &key) +CryNode::CryNode(CryDevice *device, optional> parent, const Key &key) : _device(device), _parent(std::move(parent)), _key(key) { @@ -82,7 +82,7 @@ const CryDevice *CryNode::device() const { return _device; } -unique_ref CryNode::LoadBlob() const { +unique_ref CryNode::LoadBlob() const { return _device->LoadBlob(_key); } diff --git a/src/filesystem/CryNode.h b/src/filesystem/CryNode.h index 6bfe505b..3e66eb22 100644 --- a/src/filesystem/CryNode.h +++ b/src/filesystem/CryNode.h @@ -5,14 +5,14 @@ #include #include "messmer/cpp-utils/macros.h" #include -#include "fsblobstore/DirBlob.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" #include "CryDevice.h" namespace cryfs { class CryNode: public virtual fspp::Node { public: - CryNode(CryDevice *device, boost::optional> parent, const blockstore::Key &key); + CryNode(CryDevice *device, boost::optional> parent, const blockstore::Key &key); void access(int mask) const override; void stat(struct ::stat *result) const override; void chmod(mode_t mode) override; @@ -27,13 +27,13 @@ protected: CryDevice *device(); const CryDevice *device() const; - cpputils::unique_ref LoadBlob() const; + cpputils::unique_ref LoadBlob() const; virtual fspp::Dir::EntryType getType() const = 0; private: CryDevice *_device; - boost::optional> _parent; + boost::optional> _parent; blockstore::Key _key; DISALLOW_COPY_AND_ASSIGN(CryNode); diff --git a/src/filesystem/CryOpenFile.cpp b/src/filesystem/CryOpenFile.cpp index a1f1c6fe..72c60fe9 100644 --- a/src/filesystem/CryOpenFile.cpp +++ b/src/filesystem/CryOpenFile.cpp @@ -9,7 +9,7 @@ namespace bf = boost::filesystem; using cpputils::unique_ref; -using cryfs::fsblobstore::FileBlob; +using cryfs::parallelaccessfsblobstore::FileBlobRef; //TODO Get rid of this in favor of a exception hierarchy using fspp::fuse::CHECK_RETVAL; @@ -17,7 +17,7 @@ using fspp::fuse::FuseErrnoException; namespace cryfs { -CryOpenFile::CryOpenFile(unique_ref fileBlob) +CryOpenFile::CryOpenFile(unique_ref fileBlob) : _fileBlob(std::move(fileBlob)) { } diff --git a/src/filesystem/CryOpenFile.h b/src/filesystem/CryOpenFile.h index d0d08f4c..88cb052c 100644 --- a/src/filesystem/CryOpenFile.h +++ b/src/filesystem/CryOpenFile.h @@ -3,14 +3,14 @@ #define CRYFS_LIB_CRYOPENFILE_H_ #include "messmer/fspp/fs_interface/OpenFile.h" -#include "fsblobstore/FileBlob.h" +#include "parallelaccessfsblobstore/FileBlobRef.h" namespace cryfs { class CryDevice; class CryOpenFile: public fspp::OpenFile { public: - explicit CryOpenFile(cpputils::unique_ref fileBlob); + explicit CryOpenFile(cpputils::unique_ref fileBlob); virtual ~CryOpenFile(); void stat(struct ::stat *result) const override; @@ -22,7 +22,7 @@ public: void fdatasync() override; private: - cpputils::unique_ref _fileBlob; + cpputils::unique_ref _fileBlob; DISALLOW_COPY_AND_ASSIGN(CryOpenFile); }; diff --git a/src/filesystem/CrySymlink.cpp b/src/filesystem/CrySymlink.cpp index dfe8c8e3..a1b8c9be 100644 --- a/src/filesystem/CrySymlink.cpp +++ b/src/filesystem/CrySymlink.cpp @@ -3,7 +3,7 @@ #include "messmer/fspp/fuse/FuseErrnoException.h" #include "CryDevice.h" #include "CrySymlink.h" -#include "fsblobstore/SymlinkBlob.h" +#include "parallelaccessfsblobstore/SymlinkBlobRef.h" //TODO Get rid of this in favor of exception hierarchy using fspp::fuse::CHECK_RETVAL; @@ -20,21 +20,21 @@ using boost::optional; using cpputils::unique_ref; using cpputils::make_unique_ref; using cpputils::dynamic_pointer_move; -using cryfs::fsblobstore::SymlinkBlob; -using cryfs::fsblobstore::DirBlob; +using cryfs::parallelaccessfsblobstore::SymlinkBlobRef; +using cryfs::parallelaccessfsblobstore::DirBlobRef; namespace cryfs { -CrySymlink::CrySymlink(CryDevice *device, unique_ref parent, const Key &key) +CrySymlink::CrySymlink(CryDevice *device, unique_ref parent, const Key &key) : CryNode(device, std::move(parent), key) { } CrySymlink::~CrySymlink() { } -unique_ref CrySymlink::LoadBlob() const { +unique_ref CrySymlink::LoadBlob() const { auto blob = CryNode::LoadBlob(); - auto symlink_blob = dynamic_pointer_move(blob); + auto symlink_blob = dynamic_pointer_move(blob); ASSERT(symlink_blob != none, "Blob does not store a symlink"); return std::move(*symlink_blob); } diff --git a/src/filesystem/CrySymlink.h b/src/filesystem/CrySymlink.h index dbaa069c..9205a4b0 100644 --- a/src/filesystem/CrySymlink.h +++ b/src/filesystem/CrySymlink.h @@ -4,14 +4,14 @@ #include #include "CryNode.h" -#include "fsblobstore/SymlinkBlob.h" -#include "fsblobstore/DirBlob.h" +#include "parallelaccessfsblobstore/SymlinkBlobRef.h" +#include "parallelaccessfsblobstore/DirBlobRef.h" namespace cryfs { class CrySymlink: public fspp::Symlink, CryNode { public: - CrySymlink(CryDevice *device, cpputils::unique_ref parent, const blockstore::Key &key); + CrySymlink(CryDevice *device, cpputils::unique_ref parent, const blockstore::Key &key); virtual ~CrySymlink(); boost::filesystem::path target() const override; @@ -19,7 +19,7 @@ public: fspp::Dir::EntryType getType() const override; private: - cpputils::unique_ref LoadBlob() const; + cpputils::unique_ref LoadBlob() const; DISALLOW_COPY_AND_ASSIGN(CrySymlink); }; diff --git a/src/filesystem/fsblobstore/DirBlob.cpp b/src/filesystem/fsblobstore/DirBlob.cpp index 609e4ca2..542cc5be 100644 --- a/src/filesystem/fsblobstore/DirBlob.cpp +++ b/src/filesystem/fsblobstore/DirBlob.cpp @@ -26,10 +26,10 @@ using boost::none; namespace cryfs { namespace fsblobstore { - //TODO Factor out a DirEntryList class +//TODO Factor out a DirEntryList class -DirBlob::DirBlob(unique_ref blob, FsBlobStore *fsBlobStore, std::function onDestruct) : - FsBlob(std::move(blob), onDestruct), _fsBlobStore(fsBlobStore), _entries(), _changed(false) { +DirBlob::DirBlob(unique_ref blob, std::function getLstatSize) : + FsBlob(std::move(blob)), _getLstatSize(getLstatSize), _entries(), _changed(false) { ASSERT(magicNumber() == MagicNumbers::DIR, "Loaded blob is not a directory"); _readEntriesFromBlob(); } @@ -43,9 +43,9 @@ void DirBlob::flush() { baseBlob().flush(); } -unique_ref DirBlob::InitializeEmptyDir(unique_ref blob, FsBlobStore *fsBlobStore, std::function onDestruct) { +unique_ref DirBlob::InitializeEmptyDir(unique_ref blob, std::function getLstatSize) { InitializeBlobWithMagicNumber(blob.get(), MagicNumbers::DIR); - return make_unique_ref(std::move(blob), fsBlobStore, onDestruct); + return make_unique_ref(std::move(blob), getLstatSize); } void DirBlob::_writeEntriesToBlob() { @@ -205,12 +205,10 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const { result->st_nlink = 1; //TODO Handle file access times result->st_mtime = result->st_ctime = result->st_atime = 0; - auto blob = _fsBlobStore->load(key); - ASSERT(blob != none, "Blob for directory entry not found"); - result->st_size = (*blob)->lstat_size(); + result->st_size = _getLstatSize(key); //TODO Move ceilDivision to general utils which can be used by cryfs as well result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, 512); - result->st_blksize = CryDevice::BLOCKSIZE_BYTES; //TODO _fsBlobStore->BLOCKSIZE_BYTES would be cleaner + result->st_blksize = CryDevice::BLOCKSIZE_BYTES; //TODO FsBlobStore::BLOCKSIZE_BYTES would be cleaner } void DirBlob::chmodChild(const Key &key, mode_t mode) { @@ -232,5 +230,9 @@ void DirBlob::chownChild(const Key &key, uid_t uid, gid_t gid) { } } +void DirBlob::setLstatSizeGetter(std::function getLstatSize) { + _getLstatSize = getLstatSize; +} + } } diff --git a/src/filesystem/fsblobstore/DirBlob.h b/src/filesystem/fsblobstore/DirBlob.h index 686ac1ff..22ccf793 100644 --- a/src/filesystem/fsblobstore/DirBlob.h +++ b/src/filesystem/fsblobstore/DirBlob.h @@ -6,7 +6,6 @@ #include #include #include "FsBlob.h" - #include namespace cryfs { @@ -43,10 +42,9 @@ namespace cryfs { }; static cpputils::unique_ref InitializeEmptyDir(cpputils::unique_ref blob, - FsBlobStore *fsBlobStore, - std::function onDestruct); + std::function getLstatSize); - DirBlob(cpputils::unique_ref blob, FsBlobStore *fsBlobStore, std::function onDestruct); + DirBlob(cpputils::unique_ref blob, std::function getLstatSize); virtual ~DirBlob(); @@ -80,6 +78,8 @@ namespace cryfs { void chownChild(const blockstore::Key &key, uid_t uid, gid_t gid); + void setLstatSizeGetter(std::function getLstatSize); + private: const char *readAndAddNextChild(const char *pos, std::vector *result) const; @@ -92,7 +92,7 @@ namespace cryfs { std::vector::iterator _findChild(const blockstore::Key &key); - FsBlobStore *_fsBlobStore; + std::function _getLstatSize; std::vector _entries; bool _changed; diff --git a/src/filesystem/fsblobstore/FileBlob.cpp b/src/filesystem/fsblobstore/FileBlob.cpp index 479bae33..c8d3834e 100644 --- a/src/filesystem/fsblobstore/FileBlob.cpp +++ b/src/filesystem/fsblobstore/FileBlob.cpp @@ -7,17 +7,18 @@ using blobstore::Blob; using cpputils::unique_ref; using cpputils::make_unique_ref; +using blockstore::Key; namespace cryfs { namespace fsblobstore { -FileBlob::FileBlob(unique_ref blob, std::function onDestruct) -: FsBlob(std::move(blob), onDestruct) { +FileBlob::FileBlob(unique_ref blob) +: FsBlob(std::move(blob)) { } -unique_ref FileBlob::InitializeEmptyFile(unique_ref blob, std::function onDestruct) { +unique_ref FileBlob::InitializeEmptyFile(unique_ref blob) { InitializeBlobWithMagicNumber(blob.get(), MagicNumbers::FILE); - return make_unique_ref(std::move(blob), onDestruct); + return make_unique_ref(std::move(blob)); } ssize_t FileBlob::read(void *target, uint64_t offset, uint64_t count) const { @@ -32,10 +33,6 @@ void FileBlob::flush() { baseBlob().flush(); } -blockstore::Key FileBlob::key() const { - return baseBlob().key(); -} - void FileBlob::resize(off_t size) { baseBlob().resize(size+1); } diff --git a/src/filesystem/fsblobstore/FileBlob.h b/src/filesystem/fsblobstore/FileBlob.h index 0886f887..c214fd01 100644 --- a/src/filesystem/fsblobstore/FileBlob.h +++ b/src/filesystem/fsblobstore/FileBlob.h @@ -9,9 +9,9 @@ namespace cryfs { class FileBlob: public FsBlob { public: - static cpputils::unique_ref InitializeEmptyFile(cpputils::unique_ref blob, std::function onDestruct); + static cpputils::unique_ref InitializeEmptyFile(cpputils::unique_ref blob); - FileBlob(cpputils::unique_ref blob, std::function onDestruct); + FileBlob(cpputils::unique_ref blob); ssize_t read(void *target, uint64_t offset, uint64_t count) const; @@ -25,8 +25,6 @@ namespace cryfs { off_t size() const; - blockstore::Key key() const; - }; } } diff --git a/src/filesystem/fsblobstore/FsBlob.h b/src/filesystem/fsblobstore/FsBlob.h index 8196700d..7afb3bbb 100644 --- a/src/filesystem/fsblobstore/FsBlob.h +++ b/src/filesystem/fsblobstore/FsBlob.h @@ -3,7 +3,6 @@ #include #include -#include namespace cryfs { namespace fsblobstore { @@ -12,10 +11,10 @@ namespace cryfs { virtual ~FsBlob(); virtual off_t lstat_size() const = 0; - blockstore::Key key() const; + const blockstore::Key &key() const; protected: - FsBlob(cpputils::unique_ref baseBlob, std::function onDestruct); + FsBlob(cpputils::unique_ref baseBlob); blobstore::Blob &baseBlob(); const blobstore::Blob &baseBlob() const; @@ -30,20 +29,18 @@ namespace cryfs { cpputils::unique_ref releaseBaseBlob(); cpputils::unique_ref _baseBlob; - std::function _onDestruct; DISALLOW_COPY_AND_ASSIGN(FsBlob); }; - inline FsBlob::FsBlob(cpputils::unique_ref baseBlob, std::function onDestruct) - : _baseBlob(std::move(baseBlob)), _onDestruct(onDestruct) { + inline FsBlob::FsBlob(cpputils::unique_ref baseBlob) + : _baseBlob(std::move(baseBlob)) { } inline FsBlob::~FsBlob() { - _onDestruct(); } - inline blockstore::Key FsBlob::key() const { + inline const blockstore::Key &FsBlob::key() const { return _baseBlob->key(); } diff --git a/src/filesystem/fsblobstore/FsBlobStore.cpp b/src/filesystem/fsblobstore/FsBlobStore.cpp index 05a5e305..7ed5c088 100644 --- a/src/filesystem/fsblobstore/FsBlobStore.cpp +++ b/src/filesystem/fsblobstore/FsBlobStore.cpp @@ -8,6 +8,7 @@ namespace bf = boost::filesystem; using cpputils::unique_ref; using cpputils::make_unique_ref; using blobstore::BlobStore; +using blockstore::Key; using boost::none; using std::function; @@ -19,41 +20,31 @@ FsBlobStore::FsBlobStore(unique_ref baseBlobStore): _baseBlobStore(st unique_ref FsBlobStore::createFileBlob() { auto blob = _baseBlobStore->create(); - auto key = blob->key(); - _openBlobs.lock(key); - return FileBlob::InitializeEmptyFile(std::move(blob), freeLockFunction(key)); + return FileBlob::InitializeEmptyFile(std::move(blob)); } unique_ref FsBlobStore::createDirBlob() { auto blob = _baseBlobStore->create(); - auto key = blob->key(); - _openBlobs.lock(key); - //TODO Passed in fsBlobStore should be ParallelAccessFsBlobStore later - return DirBlob::InitializeEmptyDir(std::move(blob), this, freeLockFunction(key)); + return DirBlob::InitializeEmptyDir(std::move(blob), _getLstatSize()); } unique_ref FsBlobStore::createSymlinkBlob(const bf::path &target) { auto blob = _baseBlobStore->create(); - auto key = blob->key(); - _openBlobs.lock(key); - return SymlinkBlob::InitializeSymlink(std::move(blob), target, freeLockFunction(key)); + return SymlinkBlob::InitializeSymlink(std::move(blob), target); } boost::optional> FsBlobStore::load(const blockstore::Key &key) { - _openBlobs.lock(key); - auto blob = _baseBlobStore->load(key); if (blob == none) { return none; } unsigned char magicNumber = FsBlob::magicNumber(**blob); if (magicNumber == MagicNumbers::FILE) { - return unique_ref(make_unique_ref(std::move(*blob), freeLockFunction(key))); + return unique_ref(make_unique_ref(std::move(*blob))); } else if (magicNumber == MagicNumbers::DIR) { - //TODO Passed in fsBlobStore should be ParallelAccessFsBlobStore later - return unique_ref(make_unique_ref(std::move(*blob), this, freeLockFunction(key))); + return unique_ref(make_unique_ref(std::move(*blob), _getLstatSize())); } else if (magicNumber == MagicNumbers::SYMLINK) { - return unique_ref(make_unique_ref(std::move(*blob), freeLockFunction(key))); + return unique_ref(make_unique_ref(std::move(*blob))); } else { ASSERT(false, "Unknown magic number"); } @@ -63,9 +54,11 @@ void FsBlobStore::remove(cpputils::unique_ref blob) { _baseBlobStore->remove(blob->releaseBaseBlob()); } -function FsBlobStore::freeLockFunction(const blockstore::Key &key) { - return [this, key] { - _openBlobs.release(key); +function FsBlobStore::_getLstatSize() { + return [this] (const Key &key) { + auto blob = load(key); + ASSERT(blob != none, "Blob not found"); + return (*blob)->lstat_size(); }; } diff --git a/src/filesystem/fsblobstore/FsBlobStore.h b/src/filesystem/fsblobstore/FsBlobStore.h index 4565efd1..a4d04d7f 100644 --- a/src/filesystem/fsblobstore/FsBlobStore.h +++ b/src/filesystem/fsblobstore/FsBlobStore.h @@ -23,10 +23,9 @@ namespace cryfs { void remove(cpputils::unique_ref blob); private: - std::function freeLockFunction(const blockstore::Key &key); - //Instead of locking open blobs, it would be faster to allow parallel access similar to parallelaccessstore. - cpputils::LockPool _openBlobs; + std::function _getLstatSize(); + cpputils::unique_ref _baseBlobStore; }; } diff --git a/src/filesystem/fsblobstore/SymlinkBlob.cpp b/src/filesystem/fsblobstore/SymlinkBlob.cpp index c8d59451..44298da3 100644 --- a/src/filesystem/fsblobstore/SymlinkBlob.cpp +++ b/src/filesystem/fsblobstore/SymlinkBlob.cpp @@ -14,17 +14,17 @@ namespace bf = boost::filesystem; namespace cryfs { namespace fsblobstore { -SymlinkBlob::SymlinkBlob(unique_ref blob, std::function onDestruct) -: FsBlob(std::move(blob), onDestruct), _target(_readTargetFromBlob(baseBlob())) { +SymlinkBlob::SymlinkBlob(unique_ref blob) +: FsBlob(std::move(blob)), _target(_readTargetFromBlob(baseBlob())) { } -unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, const bf::path &target, std::function onDestruct) { +unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, const bf::path &target) { string targetStr = target.native(); blob->resize(1 + targetStr.size()); unsigned char magicNumber = MagicNumbers::SYMLINK; blob->write(&magicNumber, 0, 1); blob->write(targetStr.c_str(), 1, targetStr.size()); - return make_unique_ref(std::move(blob), onDestruct); + return make_unique_ref(std::move(blob)); } void SymlinkBlob::_checkMagicNumber(const Blob &blob) { diff --git a/src/filesystem/fsblobstore/SymlinkBlob.h b/src/filesystem/fsblobstore/SymlinkBlob.h index c9371e10..401326b1 100644 --- a/src/filesystem/fsblobstore/SymlinkBlob.h +++ b/src/filesystem/fsblobstore/SymlinkBlob.h @@ -11,10 +11,9 @@ namespace cryfs { class SymlinkBlob: public FsBlob { public: static cpputils::unique_ref InitializeSymlink(cpputils::unique_ref blob, - const boost::filesystem::path &target, - std::function onDestruct); + const boost::filesystem::path &target); - SymlinkBlob(cpputils::unique_ref blob, std::function onDestruct); + SymlinkBlob(cpputils::unique_ref blob); const boost::filesystem::path &target() const; diff --git a/src/filesystem/parallelaccessfsblobstore/DirBlobRef.cpp b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.cpp new file mode 100644 index 00000000..fc659084 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.cpp @@ -0,0 +1 @@ +#include "DirBlobRef.h" diff --git a/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h new file mode 100644 index 00000000..96d21415 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h @@ -0,0 +1,80 @@ +#ifndef CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_DIRBLOBREF_H +#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_DIRBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/DirBlob.h" + +namespace cryfs { +namespace parallelaccessfsblobstore { + +class DirBlobRef: public FsBlobRef { +public: + DirBlobRef(fsblobstore::DirBlob *base): _base(base) {} + + using Entry = fsblobstore::DirBlob::Entry; + + const Entry &GetChild(const std::string &name) const { + return _base->GetChild(name); + } + + const Entry &GetChild(const blockstore::Key &key) const { + return _base->GetChild(key); + } + + void RemoveChild(const blockstore::Key &key) { + return _base->RemoveChild(key); + } + + void flush() { + return _base->flush(); + } + + void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, + mode_t mode, uid_t uid, gid_t gid) { + return _base->AddChild(name, blobKey, type, mode, uid, gid); + } + + void statChild(const blockstore::Key &key, struct ::stat *result) const { + return _base->statChild(key, result); + } + + void chmodChild(const blockstore::Key &key, mode_t mode) { + return _base->chmodChild(key, mode); + } + + void chownChild(const blockstore::Key &key, uid_t uid, gid_t gid) { + return _base->chownChild(key, uid, gid); + } + + void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid) { + return _base->AddChildDir(name, blobKey, mode, uid, gid); + } + + void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid) { + return _base->AddChildFile(name, blobKey, mode, uid, gid); + } + + void AddChildSymlink(const std::string &name, const blockstore::Key &blobKey, uid_t uid, gid_t gid) { + return _base->AddChildSymlink(name, blobKey, uid, gid); + } + + void AppendChildrenTo(std::vector *result) const { + return _base->AppendChildrenTo(result); + } + + const blockstore::Key &key() const { + return _base->key(); + } + + off_t lstat_size() const { + return _base->lstat_size(); + } + +private: + fsblobstore::DirBlob *_base; +}; + +} +} + +#endif diff --git a/src/filesystem/parallelaccessfsblobstore/FileBlobRef.cpp b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.cpp new file mode 100644 index 00000000..dfa50902 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.cpp @@ -0,0 +1 @@ +#include "FileBlobRef.h" diff --git a/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h new file mode 100644 index 00000000..8078e502 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h @@ -0,0 +1,49 @@ +#ifndef CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_FILEBLOBREF_H +#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_FILEBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/FileBlob.h" + +namespace cryfs { +namespace parallelaccessfsblobstore { + +class FileBlobRef: public FsBlobRef { +public: + FileBlobRef(fsblobstore::FileBlob *base) : _base(base) {} + + void resize(off_t size) { + return _base->resize(size); + } + + off_t size() const { + return _base->size(); + } + + ssize_t read(void *target, uint64_t offset, uint64_t count) const { + return _base->read(target, offset, count); + } + + void write(const void *source, uint64_t offset, uint64_t count) { + return _base->write(source, offset, count); + } + + void flush() { + return _base->flush(); + } + + const blockstore::Key &key() const { + return _base->key(); + } + + off_t lstat_size() const { + return _base->lstat_size(); + } + +private: + fsblobstore::FileBlob *_base; +}; + +} +} + +#endif diff --git a/src/filesystem/parallelaccessfsblobstore/FsBlobRef.cpp b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.cpp new file mode 100644 index 00000000..91dad82b --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.cpp @@ -0,0 +1 @@ +#include "FsBlobRef.h" diff --git a/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h new file mode 100644 index 00000000..0b60c9e1 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h @@ -0,0 +1,25 @@ +#ifndef CRYFS_PARALLELACCESSFSBLOBSTORE_FSBLOBREF_H +#define CRYFS_PARALLELACCESSFSBLOBSTORE_FSBLOBREF_H + +#include +#include "../fsblobstore/FsBlob.h" + +namespace cryfs { +namespace parallelaccessfsblobstore { + +class FsBlobRef: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { +public: + virtual const blockstore::Key &key() const = 0; + virtual off_t lstat_size() const = 0; + +protected: + FsBlobRef() {} + +private: + DISALLOW_COPY_AND_ASSIGN(FsBlobRef); +}; + +} +} + +#endif diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp new file mode 100644 index 00000000..d6089637 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp @@ -0,0 +1,89 @@ +#include "ParallelAccessFsBlobStore.h" +#include "ParallelAccessFsBlobStoreAdapter.h" +#include "../fsblobstore/FsBlobStore.h" + +namespace bf = boost::filesystem; +using cryfs::fsblobstore::FsBlobStore; +using cryfs::fsblobstore::FsBlob; +using cryfs::fsblobstore::FileBlob; +using cryfs::fsblobstore::DirBlob; +using cryfs::fsblobstore::SymlinkBlob; +using cpputils::unique_ref; +using cpputils::make_unique_ref; +using boost::optional; +using boost::none; +using blockstore::Key; + +namespace cryfs { +namespace parallelaccessfsblobstore { + +ParallelAccessFsBlobStore::ParallelAccessFsBlobStore(unique_ref baseBlobStore) + : _baseBlobStore(std::move(baseBlobStore)), + _parallelAccessStore(make_unique_ref(_baseBlobStore.get())) { +} + +optional> ParallelAccessFsBlobStore::load(const Key &key) { + return _parallelAccessStore.load(key, [this] (FsBlob *blob) { + FileBlob *fileBlob = dynamic_cast(blob); + if (fileBlob != nullptr) { + return unique_ref(make_unique_ref(fileBlob)); + } + DirBlob *dirBlob = dynamic_cast(blob); + if (dirBlob != nullptr) { + dirBlob->setLstatSizeGetter(_getLstatSize()); + return unique_ref(make_unique_ref(dirBlob)); + } + SymlinkBlob *symlinkBlob = dynamic_cast(blob); + if (symlinkBlob != nullptr) { + return unique_ref(make_unique_ref(symlinkBlob)); + } + ASSERT(false, "Unknown blob type loaded"); + }); +} + +void ParallelAccessFsBlobStore::remove(unique_ref blob) { + Key key = blob->key(); + return _parallelAccessStore.remove(key, std::move(blob)); +} + +unique_ref ParallelAccessFsBlobStore::createDirBlob() { + auto blob = _baseBlobStore->createDirBlob(); + blob->setLstatSizeGetter(_getLstatSize()); + Key key = blob->key(); + return _parallelAccessStore.add(key, std::move(blob), [] (FsBlob *resource) { + auto dirBlob = dynamic_cast(resource); + ASSERT(dirBlob != nullptr, "Wrong resource given"); + return make_unique_ref(dirBlob); + }); +} + +unique_ref ParallelAccessFsBlobStore::createFileBlob() { + auto blob = _baseBlobStore->createFileBlob(); + Key key = blob->key(); + return _parallelAccessStore.add(key, std::move(blob), [] (FsBlob *resource) { + auto fileBlob = dynamic_cast(resource); + ASSERT(fileBlob != nullptr, "Wrong resource given"); + return make_unique_ref(fileBlob); + }); +} + +unique_ref ParallelAccessFsBlobStore::createSymlinkBlob(const bf::path &target) { + auto blob = _baseBlobStore->createSymlinkBlob(target); + Key key = blob->key(); + return _parallelAccessStore.add(key, std::move(blob), [] (FsBlob *resource) { + auto symlinkBlob = dynamic_cast(resource); + ASSERT(symlinkBlob != nullptr, "Wrong resource given"); + return make_unique_ref(symlinkBlob); + }); +} + +std::function ParallelAccessFsBlobStore::_getLstatSize() { + return [this] (const blockstore::Key &key) { + auto blob = load(key); + ASSERT(blob != none, "Blob not found"); + return (*blob)->lstat_size(); + }; +} + +} +} diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h new file mode 100644 index 00000000..c5cfa879 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h @@ -0,0 +1,36 @@ +#ifndef CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_PARALLELACCESSFSBLOBSTORE_H +#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_PARALLELACCESSFSBLOBSTORE_H + +#include +#include "FileBlobRef.h" +#include "DirBlobRef.h" +#include "SymlinkBlobRef.h" +#include "../fsblobstore/FsBlobStore.h" + +namespace cryfs { + namespace parallelaccessfsblobstore { + //TODO Test classes in parallelaccessfsblobstore + + class ParallelAccessFsBlobStore { + public: + ParallelAccessFsBlobStore(cpputils::unique_ref baseBlobStore); + + cpputils::unique_ref createFileBlob(); + cpputils::unique_ref createDirBlob(); + cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target); + boost::optional> load(const blockstore::Key &key); + void remove(cpputils::unique_ref blob); + + private: + + cpputils::unique_ref _baseBlobStore; + parallelaccessstore::ParallelAccessStore _parallelAccessStore; + + std::function _getLstatSize(); + + DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStore); + }; + } +} + +#endif diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.cpp b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.cpp new file mode 100644 index 00000000..321ac3c0 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.cpp @@ -0,0 +1 @@ +#include "ParallelAccessFsBlobStoreAdapter.h" diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h new file mode 100644 index 00000000..5fa8531a --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h @@ -0,0 +1,34 @@ +#ifndef MESSMER_CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_PARALLELACCESSFSBLOBSTOREADAPTER_H_ +#define MESSMER_CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_PARALLELACCESSFSBLOBSTOREADAPTER_H_ + +#include +#include +#include "../fsblobstore/FsBlobStore.h" + +namespace cryfs { +namespace parallelaccessfsblobstore { + +class ParallelAccessFsBlobStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore { +public: + explicit ParallelAccessFsBlobStoreAdapter(fsblobstore::FsBlobStore *baseBlockStore) + :_baseBlockStore(std::move(baseBlockStore)) { + } + + boost::optional> loadFromBaseStore(const blockstore::Key &key) override { + return _baseBlockStore->load(key); + } + + void removeFromBaseStore(cpputils::unique_ref block) override { + return _baseBlockStore->remove(std::move(block)); + } + +private: + fsblobstore::FsBlobStore *_baseBlockStore; + + DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStoreAdapter); +}; + +} +} + +#endif diff --git a/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.cpp b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.cpp new file mode 100644 index 00000000..45f8b6a1 --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.cpp @@ -0,0 +1 @@ +#include "SymlinkBlobRef.h" diff --git a/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h new file mode 100644 index 00000000..ffc8282b --- /dev/null +++ b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h @@ -0,0 +1,33 @@ +#ifndef CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_SYMLINKBLOBREF_H +#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_SYMLINKBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/SymlinkBlob.h" + +namespace cryfs { +namespace parallelaccessfsblobstore { + +class SymlinkBlobRef: public FsBlobRef { +public: + SymlinkBlobRef(fsblobstore::SymlinkBlob *base) : _base(base) {} + + const boost::filesystem::path &target() const { + return _base->target(); + } + + const blockstore::Key &key() const { + return _base->key(); + } + + off_t lstat_size() const { + return _base->lstat_size(); + } + +private: + fsblobstore::SymlinkBlob *_base; +}; + +} +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index fd3ddabf..01d4f3f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ using std::vector; //TODO Support files > 4GB //TODO cryfs process doesn't seem to react to "kill". Needs "kill -9". Why? Furthermore, calling "fusermount -u" unmounts the fs, but the cryfs process keeps running. Why? +//TODO CryFS is only using 100% CPU (not parallel) when running bonnie. Furthermore, when calling "ls" in the mount/Bonnie.../ dir while bonnie runs, ls blocks and doesn't return. Probable reason: fsblobstore locks blobs instead of allowing parallel access. Use something like parallelaccessstore. Also generally improve parallelity. void showVersion() { cout << "CryFS Version " << version::VERSION_STRING << endl;