Add a CachingFsBlobStore

This commit is contained in:
Sebastian Messmer 2015-10-05 16:58:33 +02:00
parent 2a938730e7
commit 44fb3011ed
19 changed files with 415 additions and 38 deletions

View File

@ -12,6 +12,7 @@
#include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h" #include "messmer/blobstore/implementations/onblocks/BlobOnBlocks.h"
#include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h" #include "messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h"
#include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h" #include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h"
#include "cachingfsblobstore/CachingFsBlobStore.h"
using std::string; using std::string;
@ -32,6 +33,7 @@ using cpputils::dynamic_pointer_move;
using boost::optional; using boost::optional;
using boost::none; using boost::none;
using cryfs::fsblobstore::FsBlobStore; using cryfs::fsblobstore::FsBlobStore;
using cryfs::cachingfsblobstore::CachingFsBlobStore;
using cryfs::parallelaccessfsblobstore::ParallelAccessFsBlobStore; using cryfs::parallelaccessfsblobstore::ParallelAccessFsBlobStore;
using cryfs::parallelaccessfsblobstore::FileBlobRef; using cryfs::parallelaccessfsblobstore::FileBlobRef;
using cryfs::parallelaccessfsblobstore::DirBlobRef; using cryfs::parallelaccessfsblobstore::DirBlobRef;
@ -47,11 +49,13 @@ constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ref<BlockStore> blockStore) CryDevice::CryDevice(unique_ref<CryConfig> config, unique_ref<BlockStore> blockStore)
: _fsBlobStore( : _fsBlobStore(
make_unique_ref<ParallelAccessFsBlobStore>( make_unique_ref<ParallelAccessFsBlobStore>(
make_unique_ref<FsBlobStore>( make_unique_ref<CachingFsBlobStore>(
make_unique_ref<BlobStoreOnBlocks>( make_unique_ref<FsBlobStore>(
make_unique_ref<CachingBlockStore>( make_unique_ref<BlobStoreOnBlocks>(
CreateEncryptedBlockStore(*config, std::move(blockStore)) make_unique_ref<CachingBlockStore>(
), BLOCKSIZE_BYTES))) CreateEncryptedBlockStore(*config, std::move(blockStore))
), BLOCKSIZE_BYTES)))
)
), ),
_rootKey(GetOrCreateRootKey(config.get())) { _rootKey(GetOrCreateRootKey(config.get())) {
} }

View File

@ -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<FsBlobStore> baseBlobStore)
: _baseBlobStore(std::move(baseBlobStore)) {
}
CachingFsBlobStore::~CachingFsBlobStore() {
std::cerr << "Destruct CachingFsBlobStore with "<<_cache.size() << " entries" << std::endl;
}
unique_ref<FileBlobRef> 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<FileBlobRef>(_baseBlobStore->createFileBlob(), this);
}
unique_ref<DirBlobRef> 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<DirBlobRef>(_baseBlobStore->createDirBlob(), this);
}
unique_ref<SymlinkBlobRef> 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<SymlinkBlobRef>(_baseBlobStore->createSymlinkBlob(target), this);
}
optional<unique_ref<FsBlobRef>> 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<FsBlobRef> CachingFsBlobStore::_makeRef(unique_ref<FsBlob> baseBlob) {
auto fileBlob = dynamic_pointer_move<FileBlob>(baseBlob);
if (fileBlob != none) {
return make_unique_ref<FileBlobRef>(std::move(*fileBlob), this);
}
auto dirBlob = dynamic_pointer_move<DirBlob>(baseBlob);
if (dirBlob != none) {
return make_unique_ref<DirBlobRef>(std::move(*dirBlob), this);
}
auto symlinkBlob = dynamic_pointer_move<SymlinkBlob>(baseBlob);
if (symlinkBlob != none) {
return make_unique_ref<SymlinkBlobRef>(std::move(*symlinkBlob), this);
}
ASSERT(false, "Unknown blob type");
}
void CachingFsBlobStore::remove(unique_ref<FsBlobRef> blob) {
auto baseBlob = blob->releaseBaseBlob();
return _baseBlobStore->remove(std::move(baseBlob));
}
void CachingFsBlobStore::releaseForCache(cpputils::unique_ref<fsblobstore::FsBlob> baseBlob) {
Key key = baseBlob->key();
_cache.push(key, std::move(baseBlob));
}
}
}

View File

@ -0,0 +1,43 @@
#ifndef CRYFS_CACHINGFSBLOBSTORE_CACHINGFSBLOBSTORE_H
#define CRYFS_CACHINGFSBLOBSTORE_CACHINGFSBLOBSTORE_H
#include <messmer/cpp-utils/pointer/unique_ref.h>
#include "../fsblobstore/FsBlobStore.h"
#include <messmer/blockstore/implementations/caching/cache/Cache.h>
#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<fsblobstore::FsBlobStore> baseBlobStore);
virtual ~CachingFsBlobStore();
cpputils::unique_ref<FileBlobRef> createFileBlob();
cpputils::unique_ref<DirBlobRef> createDirBlob();
cpputils::unique_ref<SymlinkBlobRef> createSymlinkBlob(const boost::filesystem::path &target);
boost::optional<cpputils::unique_ref<FsBlobRef>> load(const blockstore::Key &key);
void remove(cpputils::unique_ref<FsBlobRef> blob);
void releaseForCache(cpputils::unique_ref<fsblobstore::FsBlob> baseBlob);
private:
cpputils::unique_ref<FsBlobRef> _makeRef(cpputils::unique_ref<fsblobstore::FsBlob> baseBlob);
cpputils::unique_ref<fsblobstore::FsBlobStore> _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<blockstore::Key, cpputils::unique_ref<fsblobstore::FsBlob>> _cache;
DISALLOW_COPY_AND_ASSIGN(CachingFsBlobStore);
};
}
}
#endif

View File

@ -0,0 +1 @@
#include "DirBlobRef.h"

View File

@ -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<fsblobstore::DirBlob> base, CachingFsBlobStore *fsBlobStore):
FsBlobRef(std::move(base), fsBlobStore),
_base(dynamic_cast<fsblobstore::DirBlob*>(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<fspp::Dir::Entry> *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<off_t(const blockstore::Key&)> getLstatSize) {
return _base->setLstatSizeGetter(getLstatSize);
}
private:
fsblobstore::DirBlob *_base;
};
}
}
#endif

View File

@ -0,0 +1 @@
#include "FileBlobRef.h"

View File

@ -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<fsblobstore::FileBlob> base, CachingFsBlobStore *fsBlobStore)
:FsBlobRef(std::move(base), fsBlobStore),
_base(dynamic_cast<fsblobstore::FileBlob*>(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

View File

@ -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));
}
}
}
}

View File

@ -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<fsblobstore::FsBlob> releaseBaseBlob() {
return std::move(_baseBlob);
}
protected:
FsBlobRef(cpputils::unique_ref<fsblobstore::FsBlob> baseBlob, cachingfsblobstore::CachingFsBlobStore *fsBlobStore): _fsBlobStore(fsBlobStore), _baseBlob(std::move(baseBlob)) {}
fsblobstore::FsBlob *baseBlob() {
return _baseBlob.get();
}
private:
CachingFsBlobStore *_fsBlobStore;
cpputils::unique_ref<fsblobstore::FsBlob> _baseBlob;
DISALLOW_COPY_AND_ASSIGN(FsBlobRef);
};
}
}
#endif

View File

@ -0,0 +1 @@
#include "SymlinkBlobRef.h"

View File

@ -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<fsblobstore::SymlinkBlob> base, CachingFsBlobStore *fsBlobStore)
:FsBlobRef(std::move(base), fsBlobStore),
_base(dynamic_cast<fsblobstore::SymlinkBlob*>(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

View File

@ -27,6 +27,8 @@ namespace cryfs {
std::function<off_t(const blockstore::Key &)> _getLstatSize(); std::function<off_t(const blockstore::Key &)> _getLstatSize();
cpputils::unique_ref<blobstore::BlobStore> _baseBlobStore; cpputils::unique_ref<blobstore::BlobStore> _baseBlobStore;
DISALLOW_COPY_AND_ASSIGN(FsBlobStore);
}; };
} }
} }

View File

@ -2,14 +2,14 @@
#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_DIRBLOBREF_H #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_DIRBLOBREF_H
#include "FsBlobRef.h" #include "FsBlobRef.h"
#include "../fsblobstore/DirBlob.h" #include "../cachingfsblobstore/DirBlobRef.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
class DirBlobRef: public FsBlobRef { class DirBlobRef: public FsBlobRef {
public: public:
DirBlobRef(fsblobstore::DirBlob *base): _base(base) {} DirBlobRef(cachingfsblobstore::DirBlobRef *base): _base(base) {}
using Entry = fsblobstore::DirBlob::Entry; using Entry = fsblobstore::DirBlob::Entry;
@ -71,7 +71,7 @@ public:
} }
private: private:
fsblobstore::DirBlob *_base; cachingfsblobstore::DirBlobRef *_base;
}; };
} }

View File

@ -2,14 +2,14 @@
#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_FILEBLOBREF_H #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_FILEBLOBREF_H
#include "FsBlobRef.h" #include "FsBlobRef.h"
#include "../fsblobstore/FileBlob.h" #include "../cachingfsblobstore/FileBlobRef.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
class FileBlobRef: public FsBlobRef { class FileBlobRef: public FsBlobRef {
public: public:
FileBlobRef(fsblobstore::FileBlob *base) : _base(base) {} FileBlobRef(cachingfsblobstore::FileBlobRef *base) : _base(base) {}
void resize(off_t size) { void resize(off_t size) {
return _base->resize(size); return _base->resize(size);
@ -40,7 +40,7 @@ public:
} }
private: private:
fsblobstore::FileBlob *_base; cachingfsblobstore::FileBlobRef *_base;
}; };
} }

View File

@ -2,13 +2,14 @@
#define CRYFS_PARALLELACCESSFSBLOBSTORE_FSBLOBREF_H #define CRYFS_PARALLELACCESSFSBLOBSTORE_FSBLOBREF_H
#include <messmer/parallelaccessstore/ParallelAccessStore.h> #include <messmer/parallelaccessstore/ParallelAccessStore.h>
#include "../fsblobstore/FsBlob.h" #include "../cachingfsblobstore/FsBlobRef.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
class FsBlobRef: public parallelaccessstore::ParallelAccessStore<fsblobstore::FsBlob, FsBlobRef, blockstore::Key>::ResourceRefBase { class FsBlobRef: public parallelaccessstore::ParallelAccessStore<cachingfsblobstore::FsBlobRef, FsBlobRef, blockstore::Key>::ResourceRefBase {
public: public:
virtual ~FsBlobRef() {}
virtual const blockstore::Key &key() const = 0; virtual const blockstore::Key &key() const = 0;
virtual off_t lstat_size() const = 0; virtual off_t lstat_size() const = 0;

View File

@ -3,7 +3,7 @@
#include "../fsblobstore/FsBlobStore.h" #include "../fsblobstore/FsBlobStore.h"
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
using cryfs::fsblobstore::FsBlobStore; using cryfs::cachingfsblobstore::CachingFsBlobStore;
using cryfs::fsblobstore::FsBlob; using cryfs::fsblobstore::FsBlob;
using cryfs::fsblobstore::FileBlob; using cryfs::fsblobstore::FileBlob;
using cryfs::fsblobstore::DirBlob; using cryfs::fsblobstore::DirBlob;
@ -17,23 +17,23 @@ using blockstore::Key;
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
ParallelAccessFsBlobStore::ParallelAccessFsBlobStore(unique_ref<FsBlobStore> baseBlobStore) ParallelAccessFsBlobStore::ParallelAccessFsBlobStore(unique_ref<CachingFsBlobStore> baseBlobStore)
: _baseBlobStore(std::move(baseBlobStore)), : _baseBlobStore(std::move(baseBlobStore)),
_parallelAccessStore(make_unique_ref<ParallelAccessFsBlobStoreAdapter>(_baseBlobStore.get())) { _parallelAccessStore(make_unique_ref<ParallelAccessFsBlobStoreAdapter>(_baseBlobStore.get())) {
} }
optional<unique_ref<FsBlobRef>> ParallelAccessFsBlobStore::load(const Key &key) { optional<unique_ref<FsBlobRef>> ParallelAccessFsBlobStore::load(const Key &key) {
return _parallelAccessStore.load(key, [this] (FsBlob *blob) { return _parallelAccessStore.load(key, [this] (cachingfsblobstore::FsBlobRef *blob) {
FileBlob *fileBlob = dynamic_cast<FileBlob*>(blob); cachingfsblobstore::FileBlobRef *fileBlob = dynamic_cast<cachingfsblobstore::FileBlobRef*>(blob);
if (fileBlob != nullptr) { if (fileBlob != nullptr) {
return unique_ref<FsBlobRef>(make_unique_ref<FileBlobRef>(fileBlob)); return unique_ref<FsBlobRef>(make_unique_ref<FileBlobRef>(fileBlob));
} }
DirBlob *dirBlob = dynamic_cast<DirBlob*>(blob); cachingfsblobstore::DirBlobRef *dirBlob = dynamic_cast<cachingfsblobstore::DirBlobRef*>(blob);
if (dirBlob != nullptr) { if (dirBlob != nullptr) {
dirBlob->setLstatSizeGetter(_getLstatSize()); dirBlob->setLstatSizeGetter(_getLstatSize());
return unique_ref<FsBlobRef>(make_unique_ref<DirBlobRef>(dirBlob)); return unique_ref<FsBlobRef>(make_unique_ref<DirBlobRef>(dirBlob));
} }
SymlinkBlob *symlinkBlob = dynamic_cast<SymlinkBlob*>(blob); cachingfsblobstore::SymlinkBlobRef *symlinkBlob = dynamic_cast<cachingfsblobstore::SymlinkBlobRef*>(blob);
if (symlinkBlob != nullptr) { if (symlinkBlob != nullptr) {
return unique_ref<FsBlobRef>(make_unique_ref<SymlinkBlobRef>(symlinkBlob)); return unique_ref<FsBlobRef>(make_unique_ref<SymlinkBlobRef>(symlinkBlob));
} }
@ -50,8 +50,8 @@ unique_ref<DirBlobRef> ParallelAccessFsBlobStore::createDirBlob() {
auto blob = _baseBlobStore->createDirBlob(); auto blob = _baseBlobStore->createDirBlob();
blob->setLstatSizeGetter(_getLstatSize()); blob->setLstatSizeGetter(_getLstatSize());
Key key = blob->key(); Key key = blob->key();
return _parallelAccessStore.add<DirBlobRef>(key, std::move(blob), [] (FsBlob *resource) { return _parallelAccessStore.add<DirBlobRef>(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) {
auto dirBlob = dynamic_cast<DirBlob*>(resource); auto dirBlob = dynamic_cast<cachingfsblobstore::DirBlobRef*>(resource);
ASSERT(dirBlob != nullptr, "Wrong resource given"); ASSERT(dirBlob != nullptr, "Wrong resource given");
return make_unique_ref<DirBlobRef>(dirBlob); return make_unique_ref<DirBlobRef>(dirBlob);
}); });
@ -60,8 +60,8 @@ unique_ref<DirBlobRef> ParallelAccessFsBlobStore::createDirBlob() {
unique_ref<FileBlobRef> ParallelAccessFsBlobStore::createFileBlob() { unique_ref<FileBlobRef> ParallelAccessFsBlobStore::createFileBlob() {
auto blob = _baseBlobStore->createFileBlob(); auto blob = _baseBlobStore->createFileBlob();
Key key = blob->key(); Key key = blob->key();
return _parallelAccessStore.add<FileBlobRef>(key, std::move(blob), [] (FsBlob *resource) { return _parallelAccessStore.add<FileBlobRef>(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) {
auto fileBlob = dynamic_cast<FileBlob*>(resource); auto fileBlob = dynamic_cast<cachingfsblobstore::FileBlobRef*>(resource);
ASSERT(fileBlob != nullptr, "Wrong resource given"); ASSERT(fileBlob != nullptr, "Wrong resource given");
return make_unique_ref<FileBlobRef>(fileBlob); return make_unique_ref<FileBlobRef>(fileBlob);
}); });
@ -70,8 +70,8 @@ unique_ref<FileBlobRef> ParallelAccessFsBlobStore::createFileBlob() {
unique_ref<SymlinkBlobRef> ParallelAccessFsBlobStore::createSymlinkBlob(const bf::path &target) { unique_ref<SymlinkBlobRef> ParallelAccessFsBlobStore::createSymlinkBlob(const bf::path &target) {
auto blob = _baseBlobStore->createSymlinkBlob(target); auto blob = _baseBlobStore->createSymlinkBlob(target);
Key key = blob->key(); Key key = blob->key();
return _parallelAccessStore.add<SymlinkBlobRef>(key, std::move(blob), [] (FsBlob *resource) { return _parallelAccessStore.add<SymlinkBlobRef>(key, std::move(blob), [] (cachingfsblobstore::FsBlobRef *resource) {
auto symlinkBlob = dynamic_cast<SymlinkBlob*>(resource); auto symlinkBlob = dynamic_cast<cachingfsblobstore::SymlinkBlobRef*>(resource);
ASSERT(symlinkBlob != nullptr, "Wrong resource given"); ASSERT(symlinkBlob != nullptr, "Wrong resource given");
return make_unique_ref<SymlinkBlobRef>(symlinkBlob); return make_unique_ref<SymlinkBlobRef>(symlinkBlob);
}); });

View File

@ -5,15 +5,19 @@
#include "FileBlobRef.h" #include "FileBlobRef.h"
#include "DirBlobRef.h" #include "DirBlobRef.h"
#include "SymlinkBlobRef.h" #include "SymlinkBlobRef.h"
#include "../fsblobstore/FsBlobStore.h" #include "../cachingfsblobstore/CachingFsBlobStore.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
//TODO Test classes in 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 { class ParallelAccessFsBlobStore {
public: public:
ParallelAccessFsBlobStore(cpputils::unique_ref<fsblobstore::FsBlobStore> baseBlobStore); ParallelAccessFsBlobStore(cpputils::unique_ref<cachingfsblobstore::CachingFsBlobStore> baseBlobStore);
cpputils::unique_ref<FileBlobRef> createFileBlob(); cpputils::unique_ref<FileBlobRef> createFileBlob();
cpputils::unique_ref<DirBlobRef> createDirBlob(); cpputils::unique_ref<DirBlobRef> createDirBlob();
@ -23,8 +27,8 @@ namespace cryfs {
private: private:
cpputils::unique_ref<fsblobstore::FsBlobStore> _baseBlobStore; cpputils::unique_ref<cachingfsblobstore::CachingFsBlobStore> _baseBlobStore;
parallelaccessstore::ParallelAccessStore<fsblobstore::FsBlob, FsBlobRef, blockstore::Key> _parallelAccessStore; parallelaccessstore::ParallelAccessStore<cachingfsblobstore::FsBlobRef, FsBlobRef, blockstore::Key> _parallelAccessStore;
std::function<off_t (const blockstore::Key &)> _getLstatSize(); std::function<off_t (const blockstore::Key &)> _getLstatSize();

View File

@ -3,27 +3,27 @@
#include <messmer/cpp-utils/macros.h> #include <messmer/cpp-utils/macros.h>
#include <messmer/parallelaccessstore/ParallelAccessStore.h> #include <messmer/parallelaccessstore/ParallelAccessStore.h>
#include "../fsblobstore/FsBlobStore.h" #include "../cachingfsblobstore/CachingFsBlobStore.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
class ParallelAccessFsBlobStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore<fsblobstore::FsBlob, blockstore::Key> { class ParallelAccessFsBlobStoreAdapter: public parallelaccessstore::ParallelAccessBaseStore<cachingfsblobstore::FsBlobRef, blockstore::Key> {
public: public:
explicit ParallelAccessFsBlobStoreAdapter(fsblobstore::FsBlobStore *baseBlockStore) explicit ParallelAccessFsBlobStoreAdapter(cachingfsblobstore::CachingFsBlobStore *baseBlockStore)
:_baseBlockStore(std::move(baseBlockStore)) { :_baseBlockStore(std::move(baseBlockStore)) {
} }
boost::optional<cpputils::unique_ref<fsblobstore::FsBlob>> loadFromBaseStore(const blockstore::Key &key) override { boost::optional<cpputils::unique_ref<cachingfsblobstore::FsBlobRef>> loadFromBaseStore(const blockstore::Key &key) override {
return _baseBlockStore->load(key); return _baseBlockStore->load(key);
} }
void removeFromBaseStore(cpputils::unique_ref<fsblobstore::FsBlob> block) override { void removeFromBaseStore(cpputils::unique_ref<cachingfsblobstore::FsBlobRef> block) override {
return _baseBlockStore->remove(std::move(block)); return _baseBlockStore->remove(std::move(block));
} }
private: private:
fsblobstore::FsBlobStore *_baseBlockStore; cachingfsblobstore::CachingFsBlobStore *_baseBlockStore;
DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStoreAdapter); DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStoreAdapter);
}; };

View File

@ -2,14 +2,14 @@
#define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_SYMLINKBLOBREF_H #define CRYFS_FILESYSTEM_PARALLELACCESSFSBLOBSTORE_SYMLINKBLOBREF_H
#include "FsBlobRef.h" #include "FsBlobRef.h"
#include "../fsblobstore/SymlinkBlob.h" #include "../cachingfsblobstore/SymlinkBlobRef.h"
namespace cryfs { namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
class SymlinkBlobRef: public FsBlobRef { class SymlinkBlobRef: public FsBlobRef {
public: public:
SymlinkBlobRef(fsblobstore::SymlinkBlob *base) : _base(base) {} SymlinkBlobRef(cachingfsblobstore::SymlinkBlobRef *base) : _base(base) {}
const boost::filesystem::path &target() const { const boost::filesystem::path &target() const {
return _base->target(); return _base->target();
@ -24,7 +24,7 @@ public:
} }
private: private:
fsblobstore::SymlinkBlob *_base; cachingfsblobstore::SymlinkBlobRef *_base;
}; };
} }