mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
VFS: vnode cache
This commit is contained in:
@@ -56,11 +56,13 @@ void ktask_main() {
|
|||||||
(new Task(Task::TaskMode::TASKMODE_KERN, templates_tester, "templates_tester2"))->start();
|
(new Task(Task::TaskMode::TASKMODE_KERN, templates_tester, "templates_tester2"))->start();
|
||||||
// (new Task(Task::TaskMode::TASKMODE_KERN, vfs_tester, "vfs_tester"))->start();
|
// (new Task(Task::TaskMode::TASKMODE_KERN, vfs_tester, "vfs_tester"))->start();
|
||||||
|
|
||||||
|
VFSGlobals::root = SharedPtr<RootNode>(new RootNode());
|
||||||
|
|
||||||
for (int i = 0; i < saved_modules_size; i++) {
|
for (int i = 0; i < saved_modules_size; i++) {
|
||||||
auto &mod = saved_modules[i];
|
auto &mod = saved_modules[i];
|
||||||
|
|
||||||
if (strcmp(saved_modules_names[i], "/sysroot.tar") == 0) {
|
if (strcmp(saved_modules_names[i], "/sysroot.tar") == 0) {
|
||||||
VFSGlobals::mounts.add_mount(new TarFs((char *) mod.address, mod.size, &VFSGlobals::root));
|
VFSGlobals::mounts.add_mount(new TarFs((char *) mod.address, mod.size))->set_root(static_ptr_cast<NodeDir>(VFSGlobals::root));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalTtyManager.all_tty_putstr("Setup finished \n");
|
GlobalTtyManager.all_tty_putstr("Setup finished \n");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
|
|
||||||
FDT::FD FDT::open(const Path &p, int opts) {
|
FDT::FD FDT::open(const Path &p, int opts) {
|
||||||
if (auto n = VFSGlobals::root.traverse(p); n.get() != nullptr) {
|
if (auto n = VFSGlobals::root->traverse(p); n.get() != nullptr) {
|
||||||
LockGuard l(_mtx);
|
LockGuard l(_mtx);
|
||||||
_files.emplace(_cur_fd++, UniquePtr<File>(new File(n, opts)));
|
_files.emplace(_cur_fd++, UniquePtr<File>(new File(n, opts)));
|
||||||
return _cur_fd - 1;
|
return _cur_fd - 1;
|
||||||
|
|||||||
@@ -4,8 +4,33 @@
|
|||||||
|
|
||||||
#include "Filesystem.hpp"
|
#include "Filesystem.hpp"
|
||||||
|
|
||||||
Filesystem::~Filesystem() = default;
|
Filesystem::~Filesystem() {
|
||||||
Filesystem::Filesystem(NodeDir *mounted_on) : _mounted_on(mounted_on) {
|
if (_mounted_on.get()) {
|
||||||
|
_mounted_on->set_mounted(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Filesystem::set_root(SharedPtr<NodeDir> node) {
|
||||||
|
_mounted_on = std::move(node);
|
||||||
assert(_mounted_on->type() == Node::DIR);
|
assert(_mounted_on->type() == Node::DIR);
|
||||||
_mounted_on->set_mounted(this);
|
_mounted_on->set_mounted(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedPtr<Node> Filesystem::get_node(ino_t inode) {
|
||||||
|
{
|
||||||
|
LockGuard l(_vnode_cache_lock);
|
||||||
|
if (auto p = _vnode_cache.find(inode); p != _vnode_cache.end())
|
||||||
|
if (auto l = p->second.lock()) return *l;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto found = get_node_impl(inode);
|
||||||
|
|
||||||
|
{
|
||||||
|
LockGuard l(_vnode_cache_lock);
|
||||||
|
if (auto p = _vnode_cache.find(inode); p != _vnode_cache.end())
|
||||||
|
if (auto l = p->second.lock()) return *l;
|
||||||
|
|
||||||
|
_vnode_cache.emplace(inode, found);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,16 +8,29 @@
|
|||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
|
|
||||||
#include "PointersCollection.hpp"
|
#include "PointersCollection.hpp"
|
||||||
|
#include "SkipList.hpp"
|
||||||
|
|
||||||
class Filesystem {
|
class Filesystem {
|
||||||
public:
|
public:
|
||||||
Filesystem(NodeDir *mounted_on);
|
Filesystem() = default;
|
||||||
virtual ~Filesystem() = 0;
|
virtual ~Filesystem() = 0;
|
||||||
|
|
||||||
virtual SharedPtr<NodeDir> root() = 0;
|
Filesystem(Filesystem const &other) = delete;
|
||||||
virtual SharedPtr<Node> get_node(ino_t inode) = 0;
|
Filesystem &operator=(Filesystem const &other) = delete;
|
||||||
|
|
||||||
NodeDir *_mounted_on;
|
virtual SharedPtr<NodeDir> root() = 0;
|
||||||
|
virtual SharedPtr<Node> get_node(ino_t inode);
|
||||||
|
|
||||||
|
void set_root(SharedPtr<NodeDir> node_dir);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual SharedPtr<Node> get_node_impl(ino_t inode) = 0;
|
||||||
|
|
||||||
|
SharedPtr<NodeDir> _mounted_on;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SkipListMap<ino_t, WeakPtr<Node>> _vnode_cache;
|
||||||
|
Mutex _vnode_cache_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ size_t MemFs::MemFsNodeFile::size() {
|
|||||||
LockGuard l2(_fs_node->lock);
|
LockGuard l2(_fs_node->lock);
|
||||||
return _fs_node->data.size();
|
return _fs_node->data.size();
|
||||||
}
|
}
|
||||||
MemFs::MemFs(NodeDir *mounted_on) : Filesystem(mounted_on) {
|
MemFs::MemFs() {
|
||||||
_files.emplace(1, new DirInode{1});
|
_files.emplace(1, new DirInode{1});
|
||||||
_top_inode = 2;
|
_top_inode = 2;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ SharedPtr<NodeDir> MemFs::root() {
|
|||||||
return static_ptr_cast<NodeDir>(MemFsNodeDir::create(this, static_ptr_cast<DirInode>(root)));
|
return static_ptr_cast<NodeDir>(MemFsNodeDir::create(this, static_ptr_cast<DirInode>(root)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SharedPtr<Node> MemFs::get_node(ino_t inode) {
|
SharedPtr<Node> MemFs::get_node_impl(ino_t inode) {
|
||||||
LockGuard l(_files_lock);
|
LockGuard l(_files_lock);
|
||||||
auto found = _files.find(inode);
|
auto found = _files.find(inode);
|
||||||
if (found == _files.end()) return nullptr;
|
if (found == _files.end()) return nullptr;
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MemFs(NodeDir *mounted_on);
|
MemFs();
|
||||||
|
|
||||||
SharedPtr<NodeDir> root() override;
|
SharedPtr<NodeDir> root() override;
|
||||||
SharedPtr<Node> get_node(ino_t inode) override;
|
SharedPtr<Node> get_node_impl(ino_t inode) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ino_t _top_inode;
|
ino_t _top_inode;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "MountTable.hpp"
|
#include "MountTable.hpp"
|
||||||
void MountTable::add_mount(Filesystem *fs) {
|
Filesystem *MountTable::add_mount(Filesystem *fs) {
|
||||||
_mounts.emplace_front(fs);
|
_mounts.emplace_front(fs);
|
||||||
|
return fs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
class MountTable {
|
class MountTable {
|
||||||
public:
|
public:
|
||||||
void add_mount(Filesystem *fs);
|
Filesystem *add_mount(Filesystem *fs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
List<Filesystem *> _mounts;
|
List<Filesystem *> _mounts;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <TtyManager.hpp>
|
#include <TtyManager.hpp>
|
||||||
|
|
||||||
|
|
||||||
TarFs::TarFs(char *backing, size_t backing_size, NodeDir *mounted_on) : Filesystem(mounted_on), _backing((tar_header *) backing), _backing_size(backing_size) {
|
TarFs::TarFs(char *backing, size_t backing_size) : _backing((tar_header *) backing), _backing_size(backing_size) {
|
||||||
int i = 2;
|
int i = 2;
|
||||||
|
|
||||||
const tar_header *header = _backing;
|
const tar_header *header = _backing;
|
||||||
@@ -89,7 +89,7 @@ SharedPtr<NodeDir> TarFs::root() {
|
|||||||
return static_ptr_cast<NodeDir>(get_node(1));
|
return static_ptr_cast<NodeDir>(get_node(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<Node> TarFs::get_node(ino_t inode) {
|
SharedPtr<Node> TarFs::get_node_impl(ino_t inode) {
|
||||||
if (_dir_map.find(inode) != _dir_map.end()) {
|
if (_dir_map.find(inode) != _dir_map.end()) {
|
||||||
return static_ptr_cast<Node>(TarFsNodeDir::create(this, inode));
|
return static_ptr_cast<Node>(TarFsNodeDir::create(this, inode));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
class TarFs : public Filesystem {
|
class TarFs : public Filesystem {
|
||||||
public:
|
public:
|
||||||
TarFs(char *backing, size_t backing_size, NodeDir *mounted_on);
|
TarFs(char *backing, size_t backing_size);
|
||||||
~TarFs() override = default;
|
~TarFs() override = default;
|
||||||
|
|
||||||
SharedPtr<NodeDir> root() override;
|
SharedPtr<NodeDir> root() override;
|
||||||
SharedPtr<Node> get_node(ino_t inode) override;
|
SharedPtr<Node> get_node_impl(ino_t inode) override;
|
||||||
|
|
||||||
|
|
||||||
struct TarFsNodeDir : public ::NodeDir {
|
struct TarFsNodeDir : public ::NodeDir {
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ ino_t RootNode::mkfile(const String &name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RootNode VFSGlobals::root;
|
SharedPtr<RootNode> VFSGlobals::root;
|
||||||
MountTable VFSGlobals::mounts;
|
MountTable VFSGlobals::mounts;
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace VFSGlobals {
|
namespace VFSGlobals {
|
||||||
extern RootNode root;
|
extern SharedPtr<RootNode> root;
|
||||||
extern MountTable mounts;
|
extern MountTable mounts;
|
||||||
} // namespace VFSGlobals
|
} // namespace VFSGlobals
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user