mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
Kernel: Remove unused artifacts of the Custody cache
We'll probably want some kind of Custody caching in the future, but as it's not used at the moment, let's simplify things a bit.
This commit is contained in:
parent
987dbedf4a
commit
d5fe839166
3 changed files with 1 additions and 81 deletions
|
@ -24,63 +24,23 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/HashTable.h>
|
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/FileSystem/Custody.h>
|
#include <Kernel/FileSystem/Custody.h>
|
||||||
#include <Kernel/FileSystem/Inode.h>
|
#include <Kernel/FileSystem/Inode.h>
|
||||||
#include <Kernel/Lock.h>
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
static Lockable<InlineLinkedList<Custody>>& all_custodies()
|
|
||||||
{
|
|
||||||
static Lockable<InlineLinkedList<Custody>>* list;
|
|
||||||
if (!list)
|
|
||||||
list = new Lockable<InlineLinkedList<Custody>>;
|
|
||||||
return *list;
|
|
||||||
}
|
|
||||||
|
|
||||||
Custody* Custody::get_if_cached(Custody* parent, const StringView& name)
|
|
||||||
{
|
|
||||||
LOCKER(all_custodies().lock());
|
|
||||||
for (auto& custody : all_custodies().resource()) {
|
|
||||||
if (custody.is_deleted())
|
|
||||||
continue;
|
|
||||||
if (custody.is_mounted_on())
|
|
||||||
continue;
|
|
||||||
if (custody.parent() == parent && custody.name() == name)
|
|
||||||
return &custody;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
|
||||||
{
|
|
||||||
if (RefPtr<Custody> cached_custody = get_if_cached(parent, name)) {
|
|
||||||
if (&cached_custody->inode() != &inode) {
|
|
||||||
dbg() << "WTF! Cached custody for name '" << name << "' has inode=" << cached_custody->inode().identifier() << ", new inode=" << inode.identifier();
|
|
||||||
}
|
|
||||||
ASSERT(&cached_custody->inode() == &inode);
|
|
||||||
return *cached_custody;
|
|
||||||
}
|
|
||||||
return create(parent, name, inode, mount_flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
Custody::Custody(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
Custody::Custody(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
||||||
: m_parent(parent)
|
: m_parent(parent)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_inode(inode)
|
, m_inode(inode)
|
||||||
, m_mount_flags(mount_flags)
|
, m_mount_flags(mount_flags)
|
||||||
{
|
{
|
||||||
LOCKER(all_custodies().lock());
|
|
||||||
all_custodies().resource().append(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Custody::~Custody()
|
Custody::~Custody()
|
||||||
{
|
{
|
||||||
LOCKER(all_custodies().lock());
|
|
||||||
all_custodies().resource().remove(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String Custody::absolute_path() const
|
String Custody::absolute_path() const
|
||||||
|
@ -98,19 +58,4 @@ String Custody::absolute_path() const
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Custody::did_delete(Badge<VFS>)
|
|
||||||
{
|
|
||||||
m_deleted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Custody::did_mount_on(Badge<VFS>)
|
|
||||||
{
|
|
||||||
m_mounted_on = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Custody::did_rename(Badge<VFS>, const String& name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/InlineLinkedList.h>
|
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
@ -37,15 +36,9 @@ namespace Kernel {
|
||||||
|
|
||||||
// FIXME: Custody needs some locking.
|
// FIXME: Custody needs some locking.
|
||||||
|
|
||||||
class Custody
|
class Custody : public RefCounted<Custody> {
|
||||||
: public RefCounted<Custody>
|
|
||||||
, public InlineLinkedListNode<Custody> {
|
|
||||||
|
|
||||||
MAKE_SLAB_ALLOCATED(Custody)
|
MAKE_SLAB_ALLOCATED(Custody)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Custody* get_if_cached(Custody* parent, const StringView& name);
|
|
||||||
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&, int mount_flags);
|
|
||||||
static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
||||||
{
|
{
|
||||||
return adopt(*new Custody(parent, name, inode, mount_flags));
|
return adopt(*new Custody(parent, name, inode, mount_flags));
|
||||||
|
@ -60,27 +53,14 @@ public:
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
String absolute_path() const;
|
String absolute_path() const;
|
||||||
|
|
||||||
bool is_deleted() const { return m_deleted; }
|
|
||||||
bool is_mounted_on() const { return m_mounted_on; }
|
|
||||||
|
|
||||||
int mount_flags() const { return m_mount_flags; }
|
int mount_flags() const { return m_mount_flags; }
|
||||||
|
|
||||||
void did_delete(Badge<VFS>);
|
|
||||||
void did_mount_on(Badge<VFS>);
|
|
||||||
void did_rename(Badge<VFS>, const String& name);
|
|
||||||
|
|
||||||
// For InlineLinkedListNode.
|
|
||||||
Custody* m_next { nullptr };
|
|
||||||
Custody* m_prev { nullptr };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Custody(Custody* parent, const StringView& name, Inode&, int mount_flags);
|
Custody(Custody* parent, const StringView& name, Inode&, int mount_flags);
|
||||||
|
|
||||||
RefPtr<Custody> m_parent;
|
RefPtr<Custody> m_parent;
|
||||||
String m_name;
|
String m_name;
|
||||||
NonnullRefPtr<Inode> m_inode;
|
NonnullRefPtr<Inode> m_inode;
|
||||||
bool m_deleted { false };
|
|
||||||
bool m_mounted_on { false };
|
|
||||||
int m_mount_flags { 0 };
|
int m_mount_flags { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,6 @@ KResult VFS::mount(FS& file_system, Custody& mount_point, int flags)
|
||||||
// FIXME: check that this is not already a mount point
|
// FIXME: check that this is not already a mount point
|
||||||
Mount mount { file_system, &mount_point, flags };
|
Mount mount { file_system, &mount_point, flags };
|
||||||
m_mounts.append(move(mount));
|
m_mounts.append(move(mount));
|
||||||
mount_point.did_mount_on({});
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +83,6 @@ KResult VFS::bind_mount(Custody& source, Custody& mount_point, int flags)
|
||||||
// FIXME: check that this is not already a mount point
|
// FIXME: check that this is not already a mount point
|
||||||
Mount mount { source.inode(), mount_point, flags };
|
Mount mount { source.inode(), mount_point, flags };
|
||||||
m_mounts.append(move(mount));
|
m_mounts.append(move(mount));
|
||||||
mount_point.did_mount_on({});
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,7 +469,6 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
|
||||||
auto result = new_parent_inode.remove_child(new_basename);
|
auto result = new_parent_inode.remove_child(new_basename);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
new_custody.did_delete({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = new_parent_inode.add_child(old_inode.identifier(), new_basename, old_inode.mode());
|
auto result = new_parent_inode.add_child(old_inode.identifier(), new_basename, old_inode.mode());
|
||||||
|
@ -481,7 +478,6 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
|
||||||
result = old_parent_inode.remove_child(FileSystemPath(old_path).basename());
|
result = old_parent_inode.remove_child(FileSystemPath(old_path).basename());
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
old_custody.did_rename({}, new_basename);
|
|
||||||
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
@ -582,7 +578,6 @@ KResult VFS::unlink(StringView path, Custody& base)
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
custody.did_delete({});
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue