aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/vfs/vfsimpl.h
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-09-20 15:22:03 +0200
committerGitHub <[email protected]>2023-09-20 15:22:03 +0200
commit14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f (patch)
treebf24ac15759385cea339f7e1cf5380f984f5699a /src/zenserver/vfs/vfsimpl.h
parentchangelog version bump (diff)
downloadzen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.tar.xz
zen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.zip
VFS implementation for local storage service (#396)
currently, only Windows (using Projected File System) is supported
Diffstat (limited to 'src/zenserver/vfs/vfsimpl.h')
-rw-r--r--src/zenserver/vfs/vfsimpl.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/zenserver/vfs/vfsimpl.h b/src/zenserver/vfs/vfsimpl.h
new file mode 100644
index 000000000..9e4fdfe99
--- /dev/null
+++ b/src/zenserver/vfs/vfsimpl.h
@@ -0,0 +1,100 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "vfsservice.h"
+
+#include "projectstore/projectstore.h"
+
+#include <zencore/logging.h>
+#include <zenvfs/vfs.h>
+
+#if ZEN_WITH_VFS
+
+# include <memory>
+
+namespace zen {
+
+struct VfsOplogDataSource : public VfsTreeDataSource
+{
+ VfsOplogDataSource(std::string_view ProjectId, std::string_view OplogId, Ref<ProjectStore> InProjectStore);
+
+ virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override;
+
+private:
+ std::string m_ProjectId;
+ std::string m_OplogId;
+ Ref<ProjectStore> m_ProjectStore;
+};
+
+struct VfsCacheDataSource : public VfsTreeDataSource
+{
+ VfsCacheDataSource(std::string_view NamespaceId, std::string_view BucketId, Ref<ZenCacheStore> InCacheStore);
+ ~VfsCacheDataSource();
+
+ virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override;
+
+private:
+ std::string m_NamespaceId;
+ std::string m_BucketId;
+ Ref<ZenCacheStore> m_CacheStore;
+};
+
+struct VfsServiceDataSource : public VfsTreeDataSource
+{
+ VfsServiceDataSource(VfsService::Impl* VfsImpl) : m_VfsImpl(VfsImpl) {}
+
+ virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override;
+ virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override;
+
+private:
+ VfsService::Impl* m_VfsImpl = nullptr;
+
+ RwLock m_Lock;
+ std::unordered_map<std::string, Ref<VfsOplogDataSource>> m_OplogSourceMap;
+ std::unordered_map<std::string, Ref<VfsCacheDataSource>> m_CacheSourceMap;
+
+ Ref<VfsOplogDataSource> GetOplogDataSource(std::string_view ProjectId, std::string_view OplogId);
+ Ref<VfsCacheDataSource> GetCacheDataSource(std::string_view NamespaceId, std::string_view BucketId);
+};
+
+//////////////////////////////////////////////////////////////////////////
+
+struct VfsService::Impl
+{
+ Impl();
+ ~Impl();
+
+ void Mount(std::string_view MountPoint);
+ void Unmount();
+ void AddService(Ref<ProjectStore>&&);
+ void AddService(Ref<ZenCacheStore>&&);
+
+ inline std::string GetMountpointPath() { return m_MountpointPath; }
+ inline bool IsVfsRunning() const { return !!m_VfsHost.get(); }
+
+private:
+ Ref<ProjectStore> m_ProjectStore;
+ Ref<ZenCacheStore> m_ZenCacheStore;
+ Ref<VfsServiceDataSource> m_VfsDataSource;
+ std::string m_MountpointPath;
+
+ std::unique_ptr<VfsHost> m_VfsHost;
+ std::thread m_VfsThread;
+ Event m_VfsThreadRunning;
+ std::exception_ptr m_VfsThreadException;
+
+ void RefreshVfs();
+ void VfsThread();
+
+ friend struct VfsServiceDataSource;
+};
+
+} // namespace zen
+
+#endif