Skip to content

Commit

Permalink
nilfs2: move cleanup code of metadata file from inode routines
Browse files Browse the repository at this point in the history
Refactor nilfs_clear_inode() and nilfs_i_callback() so that cleanup
code or resource deallocation related to metadata file will be moved
out to mdt.c.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ryusuke Konishi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
konis authored and torvalds committed May 24, 2016
1 parent 24e20ea commit 2d19961
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
5 changes: 2 additions & 3 deletions fs/nilfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ void nilfs_truncate(struct inode *inode)
static void nilfs_clear_inode(struct inode *inode)
{
struct nilfs_inode_info *ii = NILFS_I(inode);
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);

/*
* Free resources allocated in nilfs_read_inode(), here.
Expand All @@ -764,8 +763,8 @@ static void nilfs_clear_inode(struct inode *inode)
brelse(ii->i_bh);
ii->i_bh = NULL;

if (mdi && mdi->mi_palloc_cache)
nilfs_palloc_destroy_cache(inode);
if (nilfs_is_metadata_file_inode(inode))
nilfs_mdt_clear(inode);

if (test_bit(NILFS_I_BMAP, &ii->i_state))
nilfs_bmap_clear(ii->i_bmap);
Expand Down
25 changes: 25 additions & 0 deletions fs/nilfs2/mdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "segment.h"
#include "page.h"
#include "mdt.h"
#include "alloc.h" /* nilfs_palloc_destroy_cache() */

#include <trace/events/nilfs2.h>

Expand Down Expand Up @@ -465,6 +466,30 @@ int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz)
return 0;
}

/**
* nilfs_mdt_clear - do cleanup for the metadata file
* @inode: inode of the metadata file
*/
void nilfs_mdt_clear(struct inode *inode)
{
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);

if (mdi->mi_palloc_cache)
nilfs_palloc_destroy_cache(inode);
}

/**
* nilfs_mdt_destroy - release resources used by the metadata file
* @inode: inode of the metadata file
*/
void nilfs_mdt_destroy(struct inode *inode)
{
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);

kfree(mdi->mi_bgl); /* kfree(NULL) is safe */
kfree(mdi);
}

void nilfs_mdt_set_entry_size(struct inode *inode, unsigned entry_size,
unsigned header_size)
{
Expand Down
8 changes: 8 additions & 0 deletions fs/nilfs2/mdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
return inode->i_private;
}

static inline int nilfs_is_metadata_file_inode(const struct inode *inode)
{
return inode->i_private != NULL;
}

/* Default GFP flags using highmem */
#define NILFS_MDT_GFP (__GFP_RECLAIM | __GFP_IO | __GFP_HIGHMEM)

Expand All @@ -82,6 +87,9 @@ int nilfs_mdt_forget_block(struct inode *, unsigned long);
int nilfs_mdt_fetch_dirty(struct inode *);

int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz);
void nilfs_mdt_clear(struct inode *inode);
void nilfs_mdt_destroy(struct inode *inode);

void nilfs_mdt_set_entry_size(struct inode *, unsigned, unsigned);

int nilfs_mdt_setup_shadow_map(struct inode *inode,
Expand Down
8 changes: 3 additions & 5 deletions fs/nilfs2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,10 @@ struct inode *nilfs_alloc_inode(struct super_block *sb)
static void nilfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);

if (mdi) {
kfree(mdi->mi_bgl); /* kfree(NULL) is safe */
kfree(mdi);
}
if (nilfs_is_metadata_file_inode(inode))
nilfs_mdt_destroy(inode);

kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode));
}

Expand Down

0 comments on commit 2d19961

Please sign in to comment.