diff --git a/src/filesystem/CryDevice.cpp b/src/filesystem/CryDevice.cpp index b5816eb0..25bc901c 100644 --- a/src/filesystem/CryDevice.cpp +++ b/src/filesystem/CryDevice.cpp @@ -12,6 +12,7 @@ #include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h" #include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h" #include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h" +#include "cachingfsblobstore/CachingFsBlobStore.h" using std::string; @@ -32,6 +33,7 @@ using cpputils::dynamic_pointer_move; using boost::optional; using boost::none; using cryfs::fsblobstore::FsBlobStore; +using cryfs::cachingfsblobstore::CachingFsBlobStore; using cryfs::parallelaccessfsblobstore::ParallelAccessFsBlobStore; using cryfs::parallelaccessfsblobstore::FileBlobRef; using cryfs::parallelaccessfsblobstore::DirBlobRef; @@ -47,11 +49,13 @@ constexpr uint32_t CryDevice::BLOCKSIZE_BYTES; CryDevice::CryDevice(unique_ref config, unique_ref blockStore) : _fsBlobStore( make_unique_ref( - make_unique_ref( - make_unique_ref( - make_unique_ref( - CreateEncryptedBlockStore(*config, std::move(blockStore)) - ), BLOCKSIZE_BYTES))) + make_unique_ref( + make_unique_ref( + make_unique_ref( + make_unique_ref( + CreateEncryptedBlockStore(*config, std::move(blockStore)) + ), BLOCKSIZE_BYTES))) + ) ), _rootKey(GetOrCreateRootKey(config.get())) { } diff --git a/src/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp b/src/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp new file mode 100644 index 00000000..c7a2f28f --- /dev/null +++ b/src/filesystem/cachingfsblobstore/CachingFsBlobStore.cpp @@ -0,0 +1,90 @@ +#include "CachingFsBlobStore.h" +#include "../fsblobstore/FsBlobStore.h" + +namespace bf = boost::filesystem; +using cpputils::unique_ref; +using cpputils::make_unique_ref; +using cpputils::dynamic_pointer_move; +using blobstore::BlobStore; +using blockstore::Key; +using boost::optional; +using boost::none; +using std::function; +using cryfs::fsblobstore::FsBlobStore; +using cryfs::fsblobstore::FsBlob; +using cryfs::fsblobstore::FileBlob; +using cryfs::fsblobstore::DirBlob; +using cryfs::fsblobstore::SymlinkBlob; + +namespace cryfs { +namespace cachingfsblobstore { + + CachingFsBlobStore::CachingFsBlobStore(unique_ref baseBlobStore) + : _baseBlobStore(std::move(baseBlobStore)) { + } + + CachingFsBlobStore::~CachingFsBlobStore() { + std::cerr << "Destruct CachingFsBlobStore with "<<_cache.size() << " entries" << std::endl; + } + + unique_ref CachingFsBlobStore::createFileBlob() { + // This already creates the file blob in the underlying blobstore. + // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) + // and probably not worth it here. + return make_unique_ref(_baseBlobStore->createFileBlob(), this); + } + + unique_ref CachingFsBlobStore::createDirBlob() { + // This already creates the file blob in the underlying blobstore. + // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) + // and probably not worth it here. + return make_unique_ref(_baseBlobStore->createDirBlob(), this); + } + + unique_ref CachingFsBlobStore::createSymlinkBlob(const bf::path &target) { + // This already creates the file blob in the underlying blobstore. + // We could also cache this operation, but that is more complicated (blockstore::CachingBlockStore does it) + // and probably not worth it here. + return make_unique_ref(_baseBlobStore->createSymlinkBlob(target), this); + } + + optional> CachingFsBlobStore::load(const Key &key) { + auto fromCache = _cache.pop(key); + if (fromCache != none) { + return _makeRef(std::move(*fromCache)); + } + auto fromBaseStore = _baseBlobStore->load(key); + if (fromBaseStore != none) { + return _makeRef(std::move(*fromBaseStore)); + } + return none; + } + + unique_ref CachingFsBlobStore::_makeRef(unique_ref baseBlob) { + auto fileBlob = dynamic_pointer_move(baseBlob); + if (fileBlob != none) { + return make_unique_ref(std::move(*fileBlob), this); + } + auto dirBlob = dynamic_pointer_move(baseBlob); + if (dirBlob != none) { + return make_unique_ref(std::move(*dirBlob), this); + } + auto symlinkBlob = dynamic_pointer_move(baseBlob); + if (symlinkBlob != none) { + return make_unique_ref(std::move(*symlinkBlob), this); + } + ASSERT(false, "Unknown blob type"); + } + + void CachingFsBlobStore::remove(unique_ref blob) { + auto baseBlob = blob->releaseBaseBlob(); + return _baseBlobStore->remove(std::move(baseBlob)); + } + + void CachingFsBlobStore::releaseForCache(cpputils::unique_ref baseBlob) { + Key key = baseBlob->key(); + _cache.push(key, std::move(baseBlob)); + } + +} +} \ No newline at end of file diff --git a/src/filesystem/cachingfsblobstore/CachingFsBlobStore.h b/src/filesystem/cachingfsblobstore/CachingFsBlobStore.h new file mode 100644 index 00000000..5cdd2fca --- /dev/null +++ b/src/filesystem/cachingfsblobstore/CachingFsBlobStore.h @@ -0,0 +1,43 @@ +#ifndef CRYFS_CACHINGFSBLOBSTORE_CACHINGFSBLOBSTORE_H +#define CRYFS_CACHINGFSBLOBSTORE_CACHINGFSBLOBSTORE_H + +#include +#include "../fsblobstore/FsBlobStore.h" +#include +#include "FileBlobRef.h" +#include "DirBlobRef.h" +#include "SymlinkBlobRef.h" + +namespace cryfs { + namespace cachingfsblobstore { + //TODO Test classes in cachingfsblobstore + + //TODO Inherit from same interface as FsBlobStore? + class CachingFsBlobStore { + public: + CachingFsBlobStore(cpputils::unique_ref baseBlobStore); + virtual ~CachingFsBlobStore(); + + 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); + + void releaseForCache(cpputils::unique_ref baseBlob); + + private: + cpputils::unique_ref _makeRef(cpputils::unique_ref baseBlob); + + cpputils::unique_ref _baseBlobStore; + + //TODO Move Cache to some common location, not in blockstore + //TODO Use other cache config (i.e. smaller max number of entries) here than in blockstore + blockstore::caching::Cache> _cache; + + DISALLOW_COPY_AND_ASSIGN(CachingFsBlobStore); + }; + } +} + +#endif diff --git a/src/filesystem/cachingfsblobstore/DirBlobRef.cpp b/src/filesystem/cachingfsblobstore/DirBlobRef.cpp new file mode 100644 index 00000000..fc659084 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/DirBlobRef.cpp @@ -0,0 +1 @@ +#include "DirBlobRef.h" diff --git a/src/filesystem/cachingfsblobstore/DirBlobRef.h b/src/filesystem/cachingfsblobstore/DirBlobRef.h new file mode 100644 index 00000000..acd5fc9d --- /dev/null +++ b/src/filesystem/cachingfsblobstore/DirBlobRef.h @@ -0,0 +1,88 @@ +#ifndef CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_DIRBLOBREF_H +#define CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_DIRBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/DirBlob.h" + +namespace cryfs { +namespace cachingfsblobstore { + +class DirBlobRef: public FsBlobRef { +public: + DirBlobRef(cpputils::unique_ref base, CachingFsBlobStore *fsBlobStore): + FsBlobRef(std::move(base), fsBlobStore), + _base(dynamic_cast(baseBlob())) { + ASSERT(_base != nullptr, "We just initialized this with a pointer to DirBlob. Can't be something else now."); + } + + 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(); + } + + void setLstatSizeGetter(std::function getLstatSize) { + return _base->setLstatSizeGetter(getLstatSize); + } + +private: + fsblobstore::DirBlob *_base; +}; + +} +} + +#endif diff --git a/src/filesystem/cachingfsblobstore/FileBlobRef.cpp b/src/filesystem/cachingfsblobstore/FileBlobRef.cpp new file mode 100644 index 00000000..dfa50902 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/FileBlobRef.cpp @@ -0,0 +1 @@ +#include "FileBlobRef.h" diff --git a/src/filesystem/cachingfsblobstore/FileBlobRef.h b/src/filesystem/cachingfsblobstore/FileBlobRef.h new file mode 100644 index 00000000..2cf45477 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/FileBlobRef.h @@ -0,0 +1,53 @@ +#ifndef CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_FILEBLOBREF_H +#define CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_FILEBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/FileBlob.h" + +namespace cryfs { +namespace cachingfsblobstore { + +class FileBlobRef: public FsBlobRef { +public: + FileBlobRef(cpputils::unique_ref base, CachingFsBlobStore *fsBlobStore) + :FsBlobRef(std::move(base), fsBlobStore), + _base(dynamic_cast(baseBlob())) { + ASSERT(_base != nullptr, "We just initialized this with a pointer to FileBlob. Can't be something else now."); + } + + 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/cachingfsblobstore/FsBlobRef.cpp b/src/filesystem/cachingfsblobstore/FsBlobRef.cpp new file mode 100644 index 00000000..8d899410 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/FsBlobRef.cpp @@ -0,0 +1,14 @@ +#include "FsBlobRef.h" +#include "CachingFsBlobStore.h" + +namespace cryfs { +namespace cachingfsblobstore { + +FsBlobRef::~FsBlobRef() { + if (_baseBlob.get() != nullptr) { + _fsBlobStore->releaseForCache(std::move(_baseBlob)); + } +} + +} +} \ No newline at end of file diff --git a/src/filesystem/cachingfsblobstore/FsBlobRef.h b/src/filesystem/cachingfsblobstore/FsBlobRef.h new file mode 100644 index 00000000..df168033 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/FsBlobRef.h @@ -0,0 +1,38 @@ +#ifndef CRYFS_CACHINGFSBLOBSTORE_FSBLOBREF_H +#define CRYFS_CACHINGFSBLOBSTORE_FSBLOBREF_H + +#include "../fsblobstore/FsBlob.h" + +namespace cryfs { +namespace cachingfsblobstore { +class CachingFsBlobStore; + +//TODO Rename to CachedFsBlob, CachedFileBlob, CachedDirBlob to avoid confusion with parallelaccessfsblobstore +class FsBlobRef { +public: + virtual ~FsBlobRef(); + virtual const blockstore::Key &key() const = 0; + virtual off_t lstat_size() const = 0; + + cpputils::unique_ref releaseBaseBlob() { + return std::move(_baseBlob); + } + +protected: + FsBlobRef(cpputils::unique_ref baseBlob, cachingfsblobstore::CachingFsBlobStore *fsBlobStore): _fsBlobStore(fsBlobStore), _baseBlob(std::move(baseBlob)) {} + + fsblobstore::FsBlob *baseBlob() { + return _baseBlob.get(); + } + +private: + CachingFsBlobStore *_fsBlobStore; + cpputils::unique_ref _baseBlob; + + DISALLOW_COPY_AND_ASSIGN(FsBlobRef); +}; + +} +} + +#endif diff --git a/src/filesystem/cachingfsblobstore/SymlinkBlobRef.cpp b/src/filesystem/cachingfsblobstore/SymlinkBlobRef.cpp new file mode 100644 index 00000000..45f8b6a1 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/SymlinkBlobRef.cpp @@ -0,0 +1 @@ +#include "SymlinkBlobRef.h" diff --git a/src/filesystem/cachingfsblobstore/SymlinkBlobRef.h b/src/filesystem/cachingfsblobstore/SymlinkBlobRef.h new file mode 100644 index 00000000..0f5e4b48 --- /dev/null +++ b/src/filesystem/cachingfsblobstore/SymlinkBlobRef.h @@ -0,0 +1,37 @@ +#ifndef CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_SYMLINKBLOBREF_H +#define CRYFS_FILESYSTEM_CACHINGFSBLOBSTORE_SYMLINKBLOBREF_H + +#include "FsBlobRef.h" +#include "../fsblobstore/SymlinkBlob.h" + +namespace cryfs { +namespace cachingfsblobstore { + +class SymlinkBlobRef: public FsBlobRef { +public: + SymlinkBlobRef(cpputils::unique_ref base, CachingFsBlobStore *fsBlobStore) + :FsBlobRef(std::move(base), fsBlobStore), + _base(dynamic_cast(baseBlob())) { + ASSERT(_base != nullptr, "We just initialized this with a pointer to SymlinkBlob. Can't be something else now."); + } + + 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/filesystem/fsblobstore/FsBlobStore.h b/src/filesystem/fsblobstore/FsBlobStore.h index a4d04d7f..05f8ea33 100644 --- a/src/filesystem/fsblobstore/FsBlobStore.h +++ b/src/filesystem/fsblobstore/FsBlobStore.h @@ -27,6 +27,8 @@ namespace cryfs { std::function _getLstatSize(); cpputils::unique_ref _baseBlobStore; + + DISALLOW_COPY_AND_ASSIGN(FsBlobStore); }; } } diff --git a/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h index 96d21415..adf20234 100644 --- a/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h +++ b/src/filesystem/parallelaccessfsblobstore/DirBlobRef.h @@ -2,14 +2,14 @@ #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_DIRBLOBREF_H #include "FsBlobRef.h" -#include "../fsblobstore/DirBlob.h" +#include "../cachingfsblobstore/DirBlobRef.h" namespace cryfs { namespace parallelaccessfsblobstore { class DirBlobRef: public FsBlobRef { public: - DirBlobRef(fsblobstore::DirBlob *base): _base(base) {} + DirBlobRef(cachingfsblobstore::DirBlobRef *base): _base(base) {} using Entry = fsblobstore::DirBlob::Entry; @@ -71,7 +71,7 @@ public: } private: - fsblobstore::DirBlob *_base; + cachingfsblobstore::DirBlobRef *_base; }; } diff --git a/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h index 8078e502..191f3337 100644 --- a/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h +++ b/src/filesystem/parallelaccessfsblobstore/FileBlobRef.h @@ -2,14 +2,14 @@ #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_FILEBLOBREF_H #include "FsBlobRef.h" -#include "../fsblobstore/FileBlob.h" +#include "../cachingfsblobstore/FileBlobRef.h" namespace cryfs { namespace parallelaccessfsblobstore { class FileBlobRef: public FsBlobRef { public: - FileBlobRef(fsblobstore::FileBlob *base) : _base(base) {} + FileBlobRef(cachingfsblobstore::FileBlobRef *base) : _base(base) {} void resize(off_t size) { return _base->resize(size); @@ -40,7 +40,7 @@ public: } private: - fsblobstore::FileBlob *_base; + cachingfsblobstore::FileBlobRef *_base; }; } diff --git a/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h index 0b60c9e1..8c3cd538 100644 --- a/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h +++ b/src/filesystem/parallelaccessfsblobstore/FsBlobRef.h @@ -2,13 +2,14 @@ #define CRYFS_PARALLELACCESSFSBLOBSTORE_FSBLOBREF_H #include -#include "../fsblobstore/FsBlob.h" +#include "../cachingfsblobstore/FsBlobRef.h" namespace cryfs { namespace parallelaccessfsblobstore { -class FsBlobRef: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { +class FsBlobRef: public parallelaccessstore::ParallelAccessStore::ResourceRefBase { public: + virtual ~FsBlobRef() {} virtual const blockstore::Key &key() const = 0; virtual off_t lstat_size() const = 0; diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp index d6089637..f182053a 100644 --- a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp @@ -3,7 +3,7 @@ #include "../fsblobstore/FsBlobStore.h" namespace bf = boost::filesystem; -using cryfs::fsblobstore::FsBlobStore; +using cryfs::cachingfsblobstore::CachingFsBlobStore; using cryfs::fsblobstore::FsBlob; using cryfs::fsblobstore::FileBlob; using cryfs::fsblobstore::DirBlob; @@ -17,23 +17,23 @@ using blockstore::Key; namespace cryfs { namespace parallelaccessfsblobstore { -ParallelAccessFsBlobStore::ParallelAccessFsBlobStore(unique_ref baseBlobStore) +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); + return _parallelAccessStore.load(key, [this] (cachingfsblobstore::FsBlobRef *blob) { + cachingfsblobstore::FileBlobRef *fileBlob = dynamic_cast(blob); if (fileBlob != nullptr) { return unique_ref(make_unique_ref(fileBlob)); } - DirBlob *dirBlob = dynamic_cast(blob); + cachingfsblobstore::DirBlobRef *dirBlob = dynamic_cast(blob); if (dirBlob != nullptr) { dirBlob->setLstatSizeGetter(_getLstatSize()); return unique_ref(make_unique_ref(dirBlob)); } - SymlinkBlob *symlinkBlob = dynamic_cast(blob); + cachingfsblobstore::SymlinkBlobRef *symlinkBlob = dynamic_cast(blob); if (symlinkBlob != nullptr) { return unique_ref(make_unique_ref(symlinkBlob)); } @@ -50,8 +50,8 @@ 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); + return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + auto dirBlob = dynamic_cast(resource); ASSERT(dirBlob != nullptr, "Wrong resource given"); return make_unique_ref(dirBlob); }); @@ -60,8 +60,8 @@ unique_ref ParallelAccessFsBlobStore::createDirBlob() { 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); + return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + auto fileBlob = dynamic_cast(resource); ASSERT(fileBlob != nullptr, "Wrong resource given"); return make_unique_ref(fileBlob); }); @@ -70,8 +70,8 @@ unique_ref ParallelAccessFsBlobStore::createFileBlob() { 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); + return _parallelAccessStore.add(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) { + auto symlinkBlob = dynamic_cast(resource); ASSERT(symlinkBlob != nullptr, "Wrong resource given"); return make_unique_ref(symlinkBlob); }); diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h index c5cfa879..7bca9a7b 100644 --- a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.h @@ -5,15 +5,19 @@ #include "FileBlobRef.h" #include "DirBlobRef.h" #include "SymlinkBlobRef.h" -#include "../fsblobstore/FsBlobStore.h" +#include "../cachingfsblobstore/CachingFsBlobStore.h" namespace cryfs { namespace parallelaccessfsblobstore { //TODO Test classes in parallelaccessfsblobstore + //TODO Race condition: Thread 1 destructs CachingFsBlobStore element from ParallelAccessFsBlobStore, but + // it didn't get written into cache yet, when Thread 2 requests it. + // Same race condition in Caching/ParallelAccessBlockStore? + class ParallelAccessFsBlobStore { public: - ParallelAccessFsBlobStore(cpputils::unique_ref baseBlobStore); + ParallelAccessFsBlobStore(cpputils::unique_ref baseBlobStore); cpputils::unique_ref createFileBlob(); cpputils::unique_ref createDirBlob(); @@ -23,8 +27,8 @@ namespace cryfs { private: - cpputils::unique_ref _baseBlobStore; - parallelaccessstore::ParallelAccessStore _parallelAccessStore; + cpputils::unique_ref _baseBlobStore; + parallelaccessstore::ParallelAccessStore _parallelAccessStore; std::function _getLstatSize(); diff --git a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h index 5fa8531a..27a542e8 100644 --- a/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h +++ b/src/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStoreAdapter.h @@ -3,27 +3,27 @@ #include #include -#include "../fsblobstore/FsBlobStore.h" +#include "../cachingfsblobstore/CachingFsBlobStore.h" namespace cryfs { namespace parallelaccessfsblobstore { -class ParallelAccessFsBlobStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore { +class ParallelAccessFsBlobStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore { public: - explicit ParallelAccessFsBlobStoreAdapter(fsblobstore::FsBlobStore *baseBlockStore) + explicit ParallelAccessFsBlobStoreAdapter(cachingfsblobstore::CachingFsBlobStore *baseBlockStore) :_baseBlockStore(std::move(baseBlockStore)) { } - boost::optional> loadFromBaseStore(const blockstore::Key &key) override { + boost::optional> loadFromBaseStore(const blockstore::Key &key) override { return _baseBlockStore->load(key); } - void removeFromBaseStore(cpputils::unique_ref block) override { + void removeFromBaseStore(cpputils::unique_ref block) override { return _baseBlockStore->remove(std::move(block)); } private: - fsblobstore::FsBlobStore *_baseBlockStore; + cachingfsblobstore::CachingFsBlobStore *_baseBlockStore; DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStoreAdapter); }; diff --git a/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h index ffc8282b..c9378266 100644 --- a/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h +++ b/src/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.h @@ -2,14 +2,14 @@ #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_SYMLINKBLOBREF_H #include "FsBlobRef.h" -#include "../fsblobstore/SymlinkBlob.h" +#include "../cachingfsblobstore/SymlinkBlobRef.h" namespace cryfs { namespace parallelaccessfsblobstore { class SymlinkBlobRef: public FsBlobRef { public: - SymlinkBlobRef(fsblobstore::SymlinkBlob *base) : _base(base) {} + SymlinkBlobRef(cachingfsblobstore::SymlinkBlobRef *base) : _base(base) {} const boost::filesystem::path &target() const { return _base->target(); @@ -24,7 +24,7 @@ public: } private: - fsblobstore::SymlinkBlob *_base; + cachingfsblobstore::SymlinkBlobRef *_base; }; }