Decouple statvfs

This commit is contained in:
Sebastian Messmer 2018-09-11 18:26:33 -07:00
parent 121de7d7ab
commit 4afe1eb780
7 changed files with 47 additions and 18 deletions

View File

@ -235,21 +235,27 @@ CryDevice::BlobWithParent CryDevice::LoadBlobWithParent(const bf::path &path) {
// Possible reason: Many parallel changes to a directory blob are a race condition. Need something like ParallelAccessStore!
}
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
CryDevice::statvfs CryDevice::statfs(const bf::path &path) {
// TODO Do we need path for something? What does it represent from fuse side?
UNUSED(path);
callFsActionCallbacks();
uint64_t numUsedBlocks = _fsBlobStore->numBlocks();
uint64_t numFreeBlocks = _fsBlobStore->estimateSpaceForNumBlocksLeft();
fsstat->f_bsize = _fsBlobStore->virtualBlocksizeBytes();
fsstat->f_blocks = numUsedBlocks + numFreeBlocks;
fsstat->f_bfree = numFreeBlocks;
fsstat->f_bavail = numFreeBlocks;
fsstat->f_files = numUsedBlocks + numFreeBlocks;
fsstat->f_ffree = numFreeBlocks;
fsstat->f_namemax = 255; // We theoretically support unlimited file name length, but this is default for many Linux file systems, so probably also makes sense for CryFS.
//f_frsize, f_favail, f_fsid and f_flag are ignored in fuse, see http://fuse.sourcearchive.com/documentation/2.7.0/structfuse__operations_4e765e29122e7b6b533dc99849a52655.html#4e765e29122e7b6b533dc99849a52655
fsstat->f_frsize = fsstat->f_bsize; // even though this is supposed to be ignored, osxfuse needs it.
statvfs result;
result.max_filename_length = 255; // We theoretically support unlimited file name length, but this is default for many Linux file systems, so probably also makes sense for CryFS.
result.blocksize = _fsBlobStore->virtualBlocksizeBytes();
result.num_total_blocks = numUsedBlocks + numFreeBlocks;
result.num_free_blocks = numFreeBlocks;
result.num_available_blocks = numFreeBlocks;
result.num_total_inodes = numUsedBlocks + numFreeBlocks;
result.num_free_inodes = numFreeBlocks;
result.num_available_inodes = numFreeBlocks;
return result;
}
unique_ref<FileBlobRef> CryDevice::CreateFileBlob(const blockstore::BlockId &parent) {

View File

@ -21,7 +21,7 @@ class CryDevice final: public fspp::Device {
public:
CryDevice(CryConfigFile config, cpputils::unique_ref<blockstore::BlockStore2> blockStore, const LocalStateDir& localStateDir, uint32_t myClientId, bool allowIntegrityViolations, bool missingBlockIsIntegrityViolation);
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
statvfs statfs(const boost::filesystem::path &path) override;
cpputils::unique_ref<parallelaccessfsblobstore::FileBlobRef> CreateFileBlob(const blockstore::BlockId &parent);
cpputils::unique_ref<parallelaccessfsblobstore::DirBlobRef> CreateDirBlob(const blockstore::BlockId &parent);

View File

@ -4,7 +4,6 @@
#include <boost/filesystem.hpp>
#include <cpp-utils/pointer/unique_ref.h>
#include <sys/statvfs.h>
namespace fspp {
class Node;
@ -16,7 +15,20 @@ class Device {
public:
virtual ~Device() {}
virtual void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) = 0;
struct statvfs final {
uint32_t max_filename_length;
uint32_t blocksize;
uint64_t num_total_blocks;
uint64_t num_free_blocks;
uint64_t num_available_blocks; // free blocks for unprivileged users
uint64_t num_total_inodes;
uint64_t num_free_inodes;
uint64_t num_available_inodes; // free inodes for unprivileged users
};
virtual statvfs statfs(const boost::filesystem::path &path) = 0;
virtual boost::optional<cpputils::unique_ref<Node>> Load(const boost::filesystem::path &path) = 0;
//TODO Test default implementation (Device.cpp)

View File

@ -38,7 +38,7 @@ public:
virtual void unlink(const boost::filesystem::path &path) = 0;
virtual void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) = 0;
virtual void utimens(const boost::filesystem::path &path, timespec lastAccessTime, timespec lastModificationTime) = 0;
virtual void statfs(const boost::filesystem::path &path, struct statvfs *fsstat) = 0;
virtual void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) = 0;
//TODO We shouldn't use Dir::Entry here, that's in another layer
virtual cpputils::unique_ref<std::vector<Dir::Entry>> readDir(const boost::filesystem::path &path) = 0;
//TODO Test createSymlink

View File

@ -276,9 +276,21 @@ void FilesystemImpl::utimens(const bf::path &path, timespec lastAccessTime, time
}
}
void FilesystemImpl::statfs(const bf::path &path, struct statvfs *fsstat) {
void FilesystemImpl::statfs(const bf::path &path, struct ::statvfs *fsstat) {
PROFILE(_statfsNanosec);
_device->statfs(path, fsstat);
Device::statvfs stat = _device->statfs(path);
fsstat->f_bsize = stat.blocksize;
fsstat->f_blocks = stat.num_total_blocks;
fsstat->f_bfree = stat.num_free_blocks;
fsstat->f_bavail = stat.num_available_blocks;
fsstat->f_files = stat.num_total_inodes;
fsstat->f_ffree = stat.num_free_inodes;
fsstat->f_favail = stat.num_available_inodes;
fsstat->f_namemax = stat.max_filename_length;
//f_frsize, f_favail, f_fsid and f_flag are ignored in fuse, see http://fuse.sourcearchive.com/documentation/2.7.0/structfuse__operations_4e765e29122e7b6b533dc99849a52655.html#4e765e29122e7b6b533dc99849a52655
fsstat->f_frsize = fsstat->f_bsize; // even though this is supposed to be ignored, osxfuse needs it.
}
void FilesystemImpl::createSymlink(const bf::path &to, const bf::path &from, uid_t uid, gid_t gid) {

View File

@ -45,7 +45,7 @@ public:
void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) override;
cpputils::unique_ref<std::vector<Dir::Entry>> readDir(const boost::filesystem::path &path) override;
void utimens(const boost::filesystem::path &path, timespec lastAccessTime, timespec lastModificationTime) override;
void statfs(const boost::filesystem::path &path, struct statvfs *fsstat) override;
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, uid_t uid, gid_t gid) override;
void readSymlink(const boost::filesystem::path &path, char *buf, size_t size) override;

View File

@ -4,7 +4,6 @@
#include <string>
#include <functional>
#include <sys/statvfs.h>
#include "../../../testutils/FuseTest.h"