From 52007a1793d1991d053f1d88d7f130b6e66b1c82 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 14 Aug 2015 16:23:38 +0000 Subject: [PATCH] Collect leaked inode references in extfs. --- ext/fsmarshall.cpp | 13 ++++++++++--- ext/fuse.cpp | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ext/fsmarshall.cpp b/ext/fsmarshall.cpp index 27e8292d..04f2c0f7 100644 --- a/ext/fsmarshall.cpp +++ b/ext/fsmarshall.cpp @@ -781,12 +781,19 @@ int fsmarshall_main(const char* argv0, } } + // Garbage collect all open inode references. + while ( fs->mru_inode ) + { + Inode* inode = fs->mru_inode; + if ( inode->remote_reference_count ) + inode->RemoteUnref(); + else if ( inode->reference_count ) + inode->Unref(); + } + // Sync the filesystem before shutting down. if ( dev->write ) - { - // TODO: Need to close all open inodes here, and in the fuse backend too. fs->Sync(); - } close(serverfd); diff --git a/ext/fuse.cpp b/ext/fuse.cpp index 51a9a825..4ac594da 100644 --- a/ext/fuse.cpp +++ b/ext/fuse.cpp @@ -67,6 +67,14 @@ void* ext2_fuse_init(struct fuse_conn_info* /*conn*/) void ext2_fuse_destroy(void* fs_private) { struct ext2_fuse_ctx* ext2_fuse_ctx = (struct ext2_fuse_ctx*) fs_private; + while ( ext2_fuse_ctx->fs->mru_inode ) + { + Inode* inode = ext2_fuse_ctx->fs->mru_inode; + if ( inode->remote_reference_count ) + inode->RemoteUnref(); + else if ( inode->reference_count ) + inode->Unref(); + } ext2_fuse_ctx->fs->Sync(); ext2_fuse_ctx->dev->Sync(); delete ext2_fuse_ctx->fs; ext2_fuse_ctx->fs = NULL;