When the user specifies a block size for the file system, this is taken as the physical block size, not virtual block size.

This commit is contained in:
Sebastian Messmer 2016-03-16 19:30:26 +00:00
parent 037b59634e
commit 1c0199e147
14 changed files with 45 additions and 30 deletions

View File

@ -27,8 +27,8 @@ using datanodestore::DataNodeStore;
using datatreestore::DataTreeStore; using datatreestore::DataTreeStore;
using parallelaccessdatatreestore::ParallelAccessDataTreeStore; using parallelaccessdatatreestore::ParallelAccessDataTreeStore;
BlobStoreOnBlocks::BlobStoreOnBlocks(unique_ref<BlockStore> blockStore, uint64_t blocksizeBytes) BlobStoreOnBlocks::BlobStoreOnBlocks(unique_ref<BlockStore> blockStore, uint64_t physicalBlocksizeBytes)
: _dataTreeStore(make_unique_ref<ParallelAccessDataTreeStore>(make_unique_ref<DataTreeStore>(make_unique_ref<DataNodeStore>(make_unique_ref<ParallelAccessBlockStore>(std::move(blockStore)), blocksizeBytes)))) { : _dataTreeStore(make_unique_ref<ParallelAccessDataTreeStore>(make_unique_ref<DataTreeStore>(make_unique_ref<DataNodeStore>(make_unique_ref<ParallelAccessBlockStore>(std::move(blockStore)), physicalBlocksizeBytes)))) {
} }
BlobStoreOnBlocks::~BlobStoreOnBlocks() { BlobStoreOnBlocks::~BlobStoreOnBlocks() {
@ -52,8 +52,8 @@ void BlobStoreOnBlocks::remove(unique_ref<Blob> blob) {
_dataTreeStore->remove((*_blob)->releaseTree()); _dataTreeStore->remove((*_blob)->releaseTree());
} }
uint64_t BlobStoreOnBlocks::blocksizeBytes() const { uint64_t BlobStoreOnBlocks::virtualBlocksizeBytes() const {
return _dataTreeStore->blocksizeBytes(); return _dataTreeStore->virtualBlocksizeBytes();
} }
uint64_t BlobStoreOnBlocks::numBlocks() const { uint64_t BlobStoreOnBlocks::numBlocks() const {

View File

@ -16,7 +16,7 @@ class ParallelAccessDataTreeStore;
class BlobStoreOnBlocks final: public BlobStore { class BlobStoreOnBlocks final: public BlobStore {
public: public:
BlobStoreOnBlocks(cpputils::unique_ref<blockstore::BlockStore> blockStore, uint64_t blocksizeBytes); BlobStoreOnBlocks(cpputils::unique_ref<blockstore::BlockStore> blockStore, uint64_t physicalBlocksizeBytes);
~BlobStoreOnBlocks(); ~BlobStoreOnBlocks();
cpputils::unique_ref<Blob> create() override; cpputils::unique_ref<Blob> create() override;
@ -25,7 +25,8 @@ public:
void remove(cpputils::unique_ref<Blob> blob) override; void remove(cpputils::unique_ref<Blob> blob) override;
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
uint64_t blocksizeBytes() const override; //virtual means "space we can use" as opposed to "space it takes on the disk" (i.e. virtual is without headers, checksums, ...)
uint64_t virtualBlocksizeBytes() const override;
uint64_t numBlocks() const override; uint64_t numBlocks() const override;
uint64_t estimateSpaceForNumBlocksLeft() const override; uint64_t estimateSpaceForNumBlocksLeft() const override;

View File

@ -20,8 +20,8 @@ namespace blobstore {
namespace onblocks { namespace onblocks {
namespace datanodestore { namespace datanodestore {
DataNodeStore::DataNodeStore(unique_ref<BlockStore> blockstore, uint64_t blocksizeBytes) DataNodeStore::DataNodeStore(unique_ref<BlockStore> blockstore, uint64_t physicalBlocksizeBytes)
: _blockstore(std::move(blockstore)), _layout(blocksizeBytes) { : _blockstore(std::move(blockstore)), _layout(_blockstore->blockSizeFromPhysicalBlockSize(physicalBlocksizeBytes)) {
} }
DataNodeStore::~DataNodeStore() { DataNodeStore::~DataNodeStore() {
@ -96,7 +96,7 @@ uint64_t DataNodeStore::estimateSpaceForNumNodesLeft() const {
return _blockstore->estimateNumFreeBytes() / _layout.blocksizeBytes(); return _blockstore->estimateNumFreeBytes() / _layout.blocksizeBytes();
} }
uint64_t DataNodeStore::blocksizeBytes() const { uint64_t DataNodeStore::virtualBlocksizeBytes() const {
return _layout.blocksizeBytes(); return _layout.blocksizeBytes();
} }

View File

@ -21,7 +21,7 @@ class DataInnerNode;
class DataNodeStore final { class DataNodeStore final {
public: public:
DataNodeStore(cpputils::unique_ref<blockstore::BlockStore> blockstore, uint64_t blocksizeBytes); DataNodeStore(cpputils::unique_ref<blockstore::BlockStore> blockstore, uint64_t physicalBlocksizeBytes);
~DataNodeStore(); ~DataNodeStore();
static constexpr uint8_t MAX_DEPTH = 10; static constexpr uint8_t MAX_DEPTH = 10;
@ -42,7 +42,7 @@ public:
void removeSubtree(cpputils::unique_ref<DataNode> node); void removeSubtree(cpputils::unique_ref<DataNode> node);
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
uint64_t numNodes() const; uint64_t numNodes() const;
uint64_t estimateSpaceForNumNodesLeft() const; uint64_t estimateSpaceForNumNodesLeft() const;
//TODO Test overwriteNodeWith(), createNodeAsCopyFrom(), removeSubtree() //TODO Test overwriteNodeWith(), createNodeAsCopyFrom(), removeSubtree()

View File

@ -26,7 +26,7 @@ public:
void remove(cpputils::unique_ref<DataTree> tree); void remove(cpputils::unique_ref<DataTree> tree);
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
uint64_t numNodes() const; uint64_t numNodes() const;
uint64_t estimateSpaceForNumNodesLeft() const; uint64_t estimateSpaceForNumNodesLeft() const;
@ -44,8 +44,8 @@ inline uint64_t DataTreeStore::estimateSpaceForNumNodesLeft() const {
return _nodeStore->estimateSpaceForNumNodesLeft(); return _nodeStore->estimateSpaceForNumNodesLeft();
} }
inline uint64_t DataTreeStore::blocksizeBytes() const { inline uint64_t DataTreeStore::virtualBlocksizeBytes() const {
return _nodeStore->blocksizeBytes(); return _nodeStore->virtualBlocksizeBytes();
} }
} }

View File

@ -27,7 +27,7 @@ public:
void remove(cpputils::unique_ref<DataTreeRef> tree); void remove(cpputils::unique_ref<DataTreeRef> tree);
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft //TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
uint64_t numNodes() const; uint64_t numNodes() const;
uint64_t estimateSpaceForNumNodesLeft() const; uint64_t estimateSpaceForNumNodesLeft() const;
@ -38,8 +38,8 @@ private:
DISALLOW_COPY_AND_ASSIGN(ParallelAccessDataTreeStore); DISALLOW_COPY_AND_ASSIGN(ParallelAccessDataTreeStore);
}; };
inline uint64_t ParallelAccessDataTreeStore::blocksizeBytes() const { inline uint64_t ParallelAccessDataTreeStore::virtualBlocksizeBytes() const {
return _dataTreeStore->blocksizeBytes(); return _dataTreeStore->virtualBlocksizeBytes();
} }
inline uint64_t ParallelAccessDataTreeStore::numNodes() const { inline uint64_t ParallelAccessDataTreeStore::numNodes() const {

View File

@ -22,7 +22,8 @@ public:
virtual uint64_t numBlocks() const = 0; virtual uint64_t numBlocks() const = 0;
virtual uint64_t estimateSpaceForNumBlocksLeft() const = 0; virtual uint64_t estimateSpaceForNumBlocksLeft() const = 0;
virtual uint64_t blocksizeBytes() const = 0; //virtual means "space we can use" as opposed to "space it takes on the disk" (i.e. virtual is without headers, checksums, ...)
virtual uint64_t virtualBlocksizeBytes() const = 0;
}; };
} }

View File

@ -33,7 +33,7 @@ CryConfig CryConfig::load(const Data &data) {
cfg._encKey = pt.get("cryfs.key", ""); cfg._encKey = pt.get("cryfs.key", "");
cfg._cipher = pt.get("cryfs.cipher", ""); cfg._cipher = pt.get("cryfs.cipher", "");
cfg._version = pt.get("cryfs.version", "0.8"); // CryFS 0.8 didn't specify this field, so if the field doesn't exist, it's 0.8. cfg._version = pt.get("cryfs.version", "0.8"); // CryFS 0.8 didn't specify this field, so if the field doesn't exist, it's 0.8.
cfg._blocksizeBytes = pt.get<uint64_t>("cryfs.blocksizeBytes", 32 * 1024); // CryFS <= 0.9.2 used a 32KB block size. cfg._blocksizeBytes = pt.get<uint64_t>("cryfs.blocksizeBytes", 32832); // CryFS <= 0.9.2 used a 32KB block size which was this physical block size.
return cfg; return cfg;
} }

View File

@ -138,7 +138,7 @@ void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
callFsActionCallbacks(); callFsActionCallbacks();
uint64_t numUsedBlocks = _fsBlobStore->numBlocks(); uint64_t numUsedBlocks = _fsBlobStore->numBlocks();
uint64_t numFreeBlocks = _fsBlobStore->estimateSpaceForNumBlocksLeft(); uint64_t numFreeBlocks = _fsBlobStore->estimateSpaceForNumBlocksLeft();
fsstat->f_bsize = _fsBlobStore->blocksizeBytes(); fsstat->f_bsize = _fsBlobStore->virtualBlocksizeBytes();
fsstat->f_blocks = numUsedBlocks + numFreeBlocks; fsstat->f_blocks = numUsedBlocks + numFreeBlocks;
fsstat->f_bfree = numFreeBlocks; fsstat->f_bfree = numFreeBlocks;
fsstat->f_bavail = numFreeBlocks; fsstat->f_bavail = numFreeBlocks;

View File

@ -24,7 +24,7 @@ namespace cryfs {
cpputils::unique_ref<SymlinkBlobRef> createSymlinkBlob(const boost::filesystem::path &target); cpputils::unique_ref<SymlinkBlobRef> createSymlinkBlob(const boost::filesystem::path &target);
boost::optional<cpputils::unique_ref<FsBlobRef>> load(const blockstore::Key &key); boost::optional<cpputils::unique_ref<FsBlobRef>> load(const blockstore::Key &key);
void remove(cpputils::unique_ref<FsBlobRef> blob); void remove(cpputils::unique_ref<FsBlobRef> blob);
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
uint64_t numBlocks() const; uint64_t numBlocks() const;
uint64_t estimateSpaceForNumBlocksLeft() const; uint64_t estimateSpaceForNumBlocksLeft() const;
@ -81,8 +81,8 @@ namespace cryfs {
_cache.push(key, std::move(baseBlob)); _cache.push(key, std::move(baseBlob));
} }
inline uint64_t CachingFsBlobStore::blocksizeBytes() const { inline uint64_t CachingFsBlobStore::virtualBlocksizeBytes() const {
return _baseBlobStore->blocksizeBytes(); return _baseBlobStore->virtualBlocksizeBytes();
} }
inline uint64_t CachingFsBlobStore::numBlocks() const { inline uint64_t CachingFsBlobStore::numBlocks() const {

View File

@ -138,7 +138,7 @@ void DirBlob::statChildExceptSize(const Key &key, struct ::stat *result) const {
#endif #endif
//TODO Move ceilDivision to general utils which can be used by cryfs as well //TODO Move ceilDivision to general utils which can be used by cryfs as well
result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, (off_t)512); result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, (off_t)512);
result->st_blksize = _fsBlobStore->blocksizeBytes(); result->st_blksize = _fsBlobStore->virtualBlocksizeBytes();
} }
void DirBlob::chmodChild(const Key &key, mode_t mode) { void DirBlob::chmodChild(const Key &key, mode_t mode) {

View File

@ -25,7 +25,7 @@ namespace cryfs {
uint64_t numBlocks() const; uint64_t numBlocks() const;
uint64_t estimateSpaceForNumBlocksLeft() const; uint64_t estimateSpaceForNumBlocksLeft() const;
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
private: private:
@ -75,8 +75,8 @@ namespace cryfs {
}; };
} }
inline uint64_t FsBlobStore::blocksizeBytes() const { inline uint64_t FsBlobStore::virtualBlocksizeBytes() const {
return _baseBlobStore->blocksizeBytes(); return _baseBlobStore->virtualBlocksizeBytes();
} }
} }
} }

View File

@ -26,7 +26,7 @@ namespace cryfs {
cpputils::unique_ref<SymlinkBlobRef> createSymlinkBlob(const boost::filesystem::path &target); cpputils::unique_ref<SymlinkBlobRef> createSymlinkBlob(const boost::filesystem::path &target);
boost::optional<cpputils::unique_ref<FsBlobRef>> load(const blockstore::Key &key); boost::optional<cpputils::unique_ref<FsBlobRef>> load(const blockstore::Key &key);
void remove(cpputils::unique_ref<FsBlobRef> blob); void remove(cpputils::unique_ref<FsBlobRef> blob);
uint64_t blocksizeBytes() const; uint64_t virtualBlocksizeBytes() const;
uint64_t numBlocks() const; uint64_t numBlocks() const;
uint64_t estimateSpaceForNumBlocksLeft() const; uint64_t estimateSpaceForNumBlocksLeft() const;
@ -58,8 +58,8 @@ namespace cryfs {
}; };
} }
inline uint64_t ParallelAccessFsBlobStore::blocksizeBytes() const { inline uint64_t ParallelAccessFsBlobStore::virtualBlocksizeBytes() const {
return _baseBlobStore->blocksizeBytes(); return _baseBlobStore->virtualBlocksizeBytes();
} }
inline uint64_t ParallelAccessFsBlobStore::numBlocks() const { inline uint64_t ParallelAccessFsBlobStore::numBlocks() const {

View File

@ -135,3 +135,16 @@ TEST_F(DataNodeStoreTest, NumNodesIsCorrectAfterRemovingANode) {
nodeStore->remove(std::move(node)); nodeStore->remove(std::move(node));
EXPECT_EQ(1u, nodeStore->numNodes()); EXPECT_EQ(1u, nodeStore->numNodes());
} }
TEST_F(DataNodeStoreTest, PhysicalBlockSize_Leaf) {
auto leaf = nodeStore->createNewLeafNode();
auto block = blockStore->load(leaf->key()).value();
EXPECT_EQ(BLOCKSIZE_BYTES, block->size());
}
TEST_F(DataNodeStoreTest, PhysicalBlockSize_Inner) {
auto leaf = nodeStore->createNewLeafNode();
auto node = nodeStore->createNewInnerNode(*leaf);
auto block = blockStore->load(node->key()).value();
EXPECT_EQ(BLOCKSIZE_BYTES, block->size());
}