From 8fb126bec69c295574d2da690be0581654b9edbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sun, 2 Jul 2023 14:23:53 +0200 Subject: [PATCH] Kernel/FileSystem: Pass last mount point guest inode to unmount prepare This will be important later on when we check file system busyness. --- Kernel/FileSystem/Ext2FS/FileSystem.cpp | 3 ++- Kernel/FileSystem/Ext2FS/FileSystem.h | 2 +- Kernel/FileSystem/FATFS/FileSystem.h | 2 +- Kernel/FileSystem/FileBackedFileSystem.h | 2 +- Kernel/FileSystem/FileSystem.cpp | 4 ++-- Kernel/FileSystem/FileSystem.h | 4 ++-- Kernel/FileSystem/ISO9660FS/FileSystem.cpp | 2 +- Kernel/FileSystem/ISO9660FS/FileSystem.h | 2 +- Kernel/FileSystem/Plan9FS/FileSystem.cpp | 2 +- Kernel/FileSystem/Plan9FS/FileSystem.h | 2 +- Kernel/FileSystem/VirtualFileSystem.cpp | 2 +- 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.cpp b/Kernel/FileSystem/Ext2FS/FileSystem.cpp index d0f3e75038..359e1a1213 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FS/FileSystem.cpp @@ -532,8 +532,9 @@ unsigned Ext2FS::free_inode_count() const return super_block().s_free_inodes_count; } -ErrorOr Ext2FS::prepare_to_clear_last_mount() +ErrorOr Ext2FS::prepare_to_clear_last_mount(Inode& mount_guest_inode) { + (void)mount_guest_inode; MutexLocker locker(m_lock); for (auto& it : m_inode_cache) { if (it.value->ref_count() > 1) diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.h b/Kernel/FileSystem/Ext2FS/FileSystem.h index 40096e1723..37f6b4b2f0 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.h +++ b/Kernel/FileSystem/Ext2FS/FileSystem.h @@ -70,7 +70,7 @@ private: virtual ErrorOr initialize_while_locked() override; virtual bool is_initialized_while_locked() override; - virtual ErrorOr prepare_to_clear_last_mount() override; + virtual ErrorOr prepare_to_clear_last_mount(Inode& mount_guest_inode) override; ErrorOr> get_inode(InodeIdentifier) const; ErrorOr> create_inode(Ext2FSInode& parent_inode, StringView name, mode_t, dev_t, UserID, GroupID); ErrorOr> create_directory(Ext2FSInode& parent_inode, StringView name, mode_t, UserID, GroupID); diff --git a/Kernel/FileSystem/FATFS/FileSystem.h b/Kernel/FileSystem/FATFS/FileSystem.h index f6620600ea..23220e4f8e 100644 --- a/Kernel/FileSystem/FATFS/FileSystem.h +++ b/Kernel/FileSystem/FATFS/FileSystem.h @@ -33,7 +33,7 @@ private: virtual bool is_initialized_while_locked() override; // FIXME: This is not a proper way to clear last mount of a FAT filesystem, // but for now we simply have no other way to properly do it. - virtual ErrorOr prepare_to_clear_last_mount() override { return {}; } + virtual ErrorOr prepare_to_clear_last_mount(Inode&) override { return {}; } FATFS(OpenFileDescription&); diff --git a/Kernel/FileSystem/FileBackedFileSystem.h b/Kernel/FileSystem/FileBackedFileSystem.h index 254a4e860e..70a82cc133 100644 --- a/Kernel/FileSystem/FileBackedFileSystem.h +++ b/Kernel/FileSystem/FileBackedFileSystem.h @@ -28,7 +28,7 @@ protected: // Note: We require all FileBackedFileSystem to implement something that actually // takes into account the fact that we will clean the last mount of the filesystem, // therefore, removing the file system with it from the Kernel memory. - virtual ErrorOr prepare_to_clear_last_mount() override = 0; + virtual ErrorOr prepare_to_clear_last_mount(Inode& mount_guest_inode) override = 0; virtual ErrorOr initialize_while_locked() = 0; virtual bool is_initialized_while_locked() = 0; diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index 9657382a6a..fa1a363470 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -27,11 +27,11 @@ FileSystem::~FileSystem() { } -ErrorOr FileSystem::prepare_to_unmount() +ErrorOr FileSystem::prepare_to_unmount(Inode& mount_guest_inode) { return m_attach_count.with([&](auto& attach_count) -> ErrorOr { if (attach_count == 1) - return prepare_to_clear_last_mount(); + return prepare_to_clear_last_mount(mount_guest_inode); return {}; }); } diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index f4b54d9d83..c80d34432e 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -41,7 +41,7 @@ public: virtual unsigned total_inode_count() const { return 0; } virtual unsigned free_inode_count() const { return 0; } - ErrorOr prepare_to_unmount(); + ErrorOr prepare_to_unmount(Inode& mount_guest_inode); struct DirectoryEntryView { DirectoryEntryView(StringView name, InodeIdentifier, u8 file_type); @@ -69,7 +69,7 @@ protected: void set_block_size(u64 size) { m_block_size = size; } void set_fragment_size(size_t size) { m_fragment_size = size; } - virtual ErrorOr prepare_to_clear_last_mount() { return {}; } + virtual ErrorOr prepare_to_clear_last_mount([[maybe_unused]] Inode& mount_guest_inode) { return {}; } mutable Mutex m_lock { "FS"sv }; diff --git a/Kernel/FileSystem/ISO9660FS/FileSystem.cpp b/Kernel/FileSystem/ISO9660FS/FileSystem.cpp index e7b17617f2..a6b18fe391 100644 --- a/Kernel/FileSystem/ISO9660FS/FileSystem.cpp +++ b/Kernel/FileSystem/ISO9660FS/FileSystem.cpp @@ -80,7 +80,7 @@ u8 ISO9660FS::internal_file_type_to_directory_entry_type(DirectoryEntryView cons return DT_REG; } -ErrorOr ISO9660FS::prepare_to_clear_last_mount() +ErrorOr ISO9660FS::prepare_to_clear_last_mount(Inode&) { // FIXME: Do proper cleaning here. BlockBasedFileSystem::remove_disk_cache_before_last_unmount(); diff --git a/Kernel/FileSystem/ISO9660FS/FileSystem.h b/Kernel/FileSystem/ISO9660FS/FileSystem.h index 3b3842573b..1cf60cb9b3 100644 --- a/Kernel/FileSystem/ISO9660FS/FileSystem.h +++ b/Kernel/FileSystem/ISO9660FS/FileSystem.h @@ -45,7 +45,7 @@ public: private: ISO9660FS(OpenFileDescription&); - virtual ErrorOr prepare_to_clear_last_mount() override; + virtual ErrorOr prepare_to_clear_last_mount(Inode&) override; virtual bool is_initialized_while_locked() override; virtual ErrorOr initialize_while_locked() override; diff --git a/Kernel/FileSystem/Plan9FS/FileSystem.cpp b/Kernel/FileSystem/Plan9FS/FileSystem.cpp index 47be6a64ac..bd1f70b895 100644 --- a/Kernel/FileSystem/Plan9FS/FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FS/FileSystem.cpp @@ -21,7 +21,7 @@ Plan9FS::Plan9FS(OpenFileDescription& file_description) { } -ErrorOr Plan9FS::prepare_to_clear_last_mount() +ErrorOr Plan9FS::prepare_to_clear_last_mount(Inode&) { // FIXME: Do proper cleaning here. return {}; diff --git a/Kernel/FileSystem/Plan9FS/FileSystem.h b/Kernel/FileSystem/Plan9FS/FileSystem.h index f6bb5a8bb7..b1a48b9644 100644 --- a/Kernel/FileSystem/Plan9FS/FileSystem.h +++ b/Kernel/FileSystem/Plan9FS/FileSystem.h @@ -40,7 +40,7 @@ public: private: Plan9FS(OpenFileDescription&); - virtual ErrorOr prepare_to_clear_last_mount() override; + virtual ErrorOr prepare_to_clear_last_mount(Inode&) override; virtual bool is_initialized_while_locked() override; virtual ErrorOr initialize_while_locked() override; diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 619bfe89e8..8199c80b07 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -275,7 +275,7 @@ ErrorOr VirtualFileSystem::unmount(Custody& mountpoint_custody) if (custody_path->view() != mountpoint_path->view()) continue; NonnullRefPtr fs = mount.guest_fs(); - TRY(fs->prepare_to_unmount()); + TRY(fs->prepare_to_unmount(mount.guest())); fs->mounted_count({}).with([&](auto& mounted_count) { VERIFY(mounted_count > 0); if (mounted_count == 1) {