Made writing back DirBlobs faster by writing whole entries at once (speedup factor of 3)
This commit is contained in:
parent
0367df004e
commit
af70891d27
@ -4,7 +4,6 @@
|
|||||||
//TODO Remove and replace with exception hierarchy
|
//TODO Remove and replace with exception hierarchy
|
||||||
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
||||||
|
|
||||||
#include <messmer/cpp-utils/data/Data.h>
|
|
||||||
#include <messmer/blobstore/implementations/onblocks/utils/Math.h>
|
#include <messmer/blobstore/implementations/onblocks/utils/Math.h>
|
||||||
#include "MagicNumbers.h"
|
#include "MagicNumbers.h"
|
||||||
#include "../CryDevice.h"
|
#include "../CryDevice.h"
|
||||||
@ -48,6 +47,36 @@ unique_ref<DirBlob> DirBlob::InitializeEmptyDir(unique_ref<Blob> blob, std::func
|
|||||||
return make_unique_ref<DirBlob>(std::move(blob), getLstatSize);
|
return make_unique_ref<DirBlob>(std::move(blob), getLstatSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Data DirBlob::_writeEntry(const DirBlob::Entry & entry) {
|
||||||
|
string keystr = entry.key.ToString();
|
||||||
|
|
||||||
|
unsigned int size = 1 + (entry.name.size() + 1) + (keystr.size() + 1) + sizeof(uid_t) + sizeof(gid_t) + sizeof(mode_t);
|
||||||
|
Data result(size);
|
||||||
|
unsigned int offset = 0;
|
||||||
|
|
||||||
|
*static_cast<uint8_t*>(result.dataOffset(offset)) = static_cast<uint8_t>(entry.type);
|
||||||
|
offset += 1;
|
||||||
|
|
||||||
|
std::memcpy(result.dataOffset(offset), entry.name.c_str(), entry.name.size()+1);
|
||||||
|
offset += entry.name.size() + 1;
|
||||||
|
|
||||||
|
std::memcpy(result.dataOffset(offset), keystr.c_str(), keystr.size() + 1);
|
||||||
|
offset += keystr.size() + 1;
|
||||||
|
|
||||||
|
*reinterpret_cast<uid_t*>(result.dataOffset(offset)) = entry.uid;
|
||||||
|
offset += sizeof(uid_t);
|
||||||
|
|
||||||
|
*reinterpret_cast<gid_t*>(result.dataOffset(offset)) = entry.gid;
|
||||||
|
offset += sizeof(gid_t);
|
||||||
|
|
||||||
|
*reinterpret_cast<mode_t*>(result.dataOffset(offset)) = entry.mode;
|
||||||
|
offset += sizeof(mode_t);
|
||||||
|
|
||||||
|
ASSERT(offset == size, "Didn't write correct number of elements");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void DirBlob::_writeEntriesToBlob() {
|
void DirBlob::_writeEntriesToBlob() {
|
||||||
std::unique_lock<std::mutex> lock(_mutex);
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
if (_changed) {
|
if (_changed) {
|
||||||
@ -55,21 +84,9 @@ void DirBlob::_writeEntriesToBlob() {
|
|||||||
baseBlob().resize(1);
|
baseBlob().resize(1);
|
||||||
unsigned int offset = 1;
|
unsigned int offset = 1;
|
||||||
for (const auto &entry : _entries) {
|
for (const auto &entry : _entries) {
|
||||||
uint8_t entryTypeMagicNumber = static_cast<uint8_t>(entry.type);
|
Data serializedEntry = _writeEntry(entry);
|
||||||
baseBlob().write(&entryTypeMagicNumber, offset, 1);
|
baseBlob().write(serializedEntry.data(), offset, serializedEntry.size());
|
||||||
offset += 1;
|
offset += serializedEntry.size();
|
||||||
baseBlob().write(entry.name.c_str(), offset, entry.name.size() + 1);
|
|
||||||
offset += entry.name.size() + 1;
|
|
||||||
string keystr = entry.key.ToString();
|
|
||||||
baseBlob().write(keystr.c_str(), offset, keystr.size() + 1);
|
|
||||||
offset += keystr.size() + 1;
|
|
||||||
baseBlob().write(&entry.uid, offset, sizeof(uid_t));
|
|
||||||
//TODO Writing them all in separate write calls is maybe imperformant. We could write the whole entry in one write call instead.
|
|
||||||
offset += sizeof(uid_t);
|
|
||||||
baseBlob().write(&entry.gid, offset, sizeof(gid_t));
|
|
||||||
offset += sizeof(gid_t);
|
|
||||||
baseBlob().write(&entry.mode, offset, sizeof(mode_t));
|
|
||||||
offset += sizeof(mode_t);
|
|
||||||
}
|
}
|
||||||
_changed = false;
|
_changed = false;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <messmer/blockstore/utils/Key.h>
|
#include <messmer/blockstore/utils/Key.h>
|
||||||
#include <messmer/cpp-utils/macros.h>
|
#include <messmer/cpp-utils/macros.h>
|
||||||
|
#include <messmer/cpp-utils/data/Data.h>
|
||||||
#include <messmer/fspp/fs_interface/Dir.h>
|
#include <messmer/fspp/fs_interface/Dir.h>
|
||||||
#include "FsBlob.h"
|
#include "FsBlob.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -90,6 +91,7 @@ namespace cryfs {
|
|||||||
void _readEntriesFromBlob();
|
void _readEntriesFromBlob();
|
||||||
|
|
||||||
void _writeEntriesToBlob();
|
void _writeEntriesToBlob();
|
||||||
|
static cpputils::Data _writeEntry(const DirBlob::Entry & entry);
|
||||||
|
|
||||||
std::vector<DirBlob::Entry>::iterator _findChild(const blockstore::Key &key);
|
std::vector<DirBlob::Entry>::iterator _findChild(const blockstore::Key &key);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user