Implement relatime behavior for performance

This commit is contained in:
Sebastian Messmer 2017-08-23 20:32:36 +01:00
parent 679b14a4d8
commit 5fb4098c8b
12 changed files with 47 additions and 16 deletions

View File

@ -83,6 +83,9 @@ ProgramOptions Parser::parse(const vector<string> &supportedCiphers) const {
if (vm.count("fuse-option")) {
auto options = vm["fuse-option"].as<vector<string>>();
for (const auto& option: options) {
if (option == "noatime" || option == "atime") {
LOG(WARN, "CryFS currently doesn't support noatime/atime flags. Using relatime behavior.");
}
fuseOptions.push_back("-o");
fuseOptions.push_back(option);
}

View File

@ -10,6 +10,7 @@
#include "CryFile.h"
#include "CryOpenFile.h"
#include <cpp-utils/system/time.h>
#include "fsblobstore/utils/TimestampUpdateBehavior.h"
//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;
@ -73,7 +74,7 @@ unique_ref<vector<fspp::Dir::Entry>> CryDir::children() {
device()->callFsActionCallbacks();
if (!isRootDir()) {
//TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function)
parent()->updateAccessTimestampForChild(key());
parent()->updateAccessTimestampForChild(key(), fsblobstore::TimestampUpdateBehavior::RELATIME);
}
auto children = make_unique_ref<vector<fspp::Dir::Entry>>();
children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "."));

View File

@ -47,7 +47,7 @@ void CryOpenFile::truncate(off_t size) const {
size_t CryOpenFile::read(void *buf, size_t count, off_t offset) const {
_device->callFsActionCallbacks();
//_parent->updateAccessTimestampForChild(_fileBlob->key());
_parent->updateAccessTimestampForChild(_fileBlob->key(), fsblobstore::TimestampUpdateBehavior::RELATIME);
return _fileBlob->read(buf, offset, count);
}

View File

@ -4,6 +4,7 @@
#include "CryDevice.h"
#include "CrySymlink.h"
#include "parallelaccessfsblobstore/SymlinkBlobRef.h"
#include "fsblobstore/utils/TimestampUpdateBehavior.h"
//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;
@ -46,7 +47,7 @@ fspp::Dir::EntryType CrySymlink::getType() const {
bf::path CrySymlink::target() {
device()->callFsActionCallbacks();
parent()->updateAccessTimestampForChild(key());
parent()->updateAccessTimestampForChild(key(), fsblobstore::TimestampUpdateBehavior::RELATIME);
auto blob = LoadBlob();
return blob->target();
}

View File

@ -4,6 +4,7 @@
#include "FsBlobRef.h"
#include "../fsblobstore/DirBlob.h"
#include "../fsblobstore/utils/TimestampUpdateBehavior.h"
namespace cryfs {
namespace cachingfsblobstore {
@ -60,8 +61,8 @@ public:
return _base->statChildWithSizeAlreadySet(key, result);
}
void updateAccessTimestampForChild(const blockstore::Key &key) {
return _base->updateAccessTimestampForChild(key);
void updateAccessTimestampForChild(const blockstore::Key &key, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) {
return _base->updateAccessTimestampForChild(key, timestampUpdateBehavior);
}
void updateModificationTimestampForChild(const blockstore::Key &key) {

View File

@ -158,9 +158,9 @@ void DirBlob::statChildWithSizeAlreadySet(const Key &key, struct ::stat *result)
result->st_blksize = _fsBlobStore->virtualBlocksizeBytes();
}
void DirBlob::updateAccessTimestampForChild(const Key &key) {
void DirBlob::updateAccessTimestampForChild(const Key &key, TimestampUpdateBehavior timestampUpdateBehavior) {
std::unique_lock<std::mutex> lock(_mutex);
_entries.updateAccessTimestampForChild(key);
_entries.updateAccessTimestampForChild(key, timestampUpdateBehavior);
_changed = true;
}

View File

@ -60,7 +60,7 @@ namespace cryfs {
void statChildWithSizeAlreadySet(const blockstore::Key &key, struct ::stat *result) const;
void updateAccessTimestampForChild(const blockstore::Key &key);
void updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior);
void updateModificationTimestampForChild(const blockstore::Key &key);

View File

@ -7,8 +7,6 @@
#include <cpp-utils/system/time.h>
#include <sys/stat.h>
// TODO Implement (and test) atime, noatime, strictatime, relatime mount options
namespace cryfs {
namespace fsblobstore {

View File

@ -228,10 +228,18 @@ void DirEntryList::setAccessTimes(const blockstore::Key &key, timespec lastAcces
found->setLastModificationTime(lastModificationTime);
}
void DirEntryList::updateAccessTimestampForChild(const blockstore::Key &key) {
void DirEntryList::updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior) {
ASSERT(timestampUpdateBehavior == TimestampUpdateBehavior::RELATIME, "Currently only relatime supported");
auto found = _findByKey(key);
// TODO Think about implementing relatime behavior. Currently, CryFS follows strictatime.
found->setLastAccessTime(cpputils::time::now());
const timespec lastAccessTime = found->lastAccessTime();
const timespec lastModificationTime = found->lastModificationTime();
const timespec now = cpputils::time::now();
const timespec yesterday {
.tv_sec = now.tv_sec - 60*60*24,
.tv_nsec = now.tv_nsec
};
if (lastAccessTime < lastModificationTime || lastAccessTime < yesterday)
found->setLastAccessTime(now);
}
void DirEntryList::updateModificationTimestampForChild(const blockstore::Key &key) {

View File

@ -6,6 +6,7 @@
#include "DirEntry.h"
#include <vector>
#include <string>
#include "TimestampUpdateBehavior.h"
//TODO Address elements by name instead of by key when accessing them. Who knows whether there is two hard links for the same blob.
@ -39,7 +40,7 @@ namespace cryfs {
void setMode(const blockstore::Key &key, mode_t mode);
bool setUidGid(const blockstore::Key &key, uid_t uid, gid_t gid);
void setAccessTimes(const blockstore::Key &key, timespec lastAccessTime, timespec lastModificationTime);
void updateAccessTimestampForChild(const blockstore::Key &key);
void updateAccessTimestampForChild(const blockstore::Key &key, TimestampUpdateBehavior timestampUpdateBehavior);
void updateModificationTimestampForChild(const blockstore::Key &key);
private:

View File

@ -0,0 +1,17 @@
#pragma once
#ifndef CRYFS_TIMESTAMPUPDATEBEHAVIOR_H
#define CRYFS_TIMESTAMPUPDATEBEHAVIOR_H
namespace cryfs {
namespace fsblobstore {
enum class TimestampUpdateBehavior : uint8_t {
// currently only relatime supported
RELATIME
};
}
}
#endif

View File

@ -4,6 +4,7 @@
#include "FsBlobRef.h"
#include "../cachingfsblobstore/DirBlobRef.h"
#include "../fsblobstore/utils/TimestampUpdateBehavior.h"
namespace cryfs {
namespace parallelaccessfsblobstore {
@ -56,8 +57,8 @@ public:
return _base->statChildWithSizeAlreadySet(key, result);
}
void updateAccessTimestampForChild(const blockstore::Key &key) {
return _base->updateAccessTimestampForChild(key);
void updateAccessTimestampForChild(const blockstore::Key &key, fsblobstore::TimestampUpdateBehavior timestampUpdateBehavior) {
return _base->updateAccessTimestampForChild(key, timestampUpdateBehavior);
}
void updateModificationTimestampForChild(const blockstore::Key &key) {