Skip to content

Commit

Permalink
fs/ext2: Use ext2_put_page
Browse files Browse the repository at this point in the history
There are 3 places in namei.c where the equivalent of ext2_put_page() is
open coded on a page which was returned from the ext2_get_page() call
[through the use of ext2_find_entry() and ext2_dotdot()].

Move ext2_get_page() and ext2_put_page() to ext2.h in order to help
clarify the use of the get/put and then use ext2_put_page() in namei.c

Also add a comment regarding the proper way to release the page returned
from ext2_find_entry() and ext2_dotdot().

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
  • Loading branch information
weiny2 authored and intel-lab-lkp committed Nov 11, 2020
1 parent 22435b2 commit d24a7d5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
33 changes: 8 additions & 25 deletions fs/ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ static inline unsigned ext2_chunk_size(struct inode *inode)
return inode->i_sb->s_blocksize;
}

static inline void ext2_put_page(struct page *page)
{
kunmap(page);
put_page(page);
}

/*
* Return the offset into page `page_nr' of the last valid
* byte in that page, plus one.
Expand Down Expand Up @@ -196,25 +190,6 @@ static bool ext2_check_page(struct page *page, int quiet)
return false;
}

static struct page * ext2_get_page(struct inode *dir, unsigned long n,
int quiet)
{
struct address_space *mapping = dir->i_mapping;
struct page *page = read_mapping_page(mapping, n, NULL);
if (!IS_ERR(page)) {
kmap(page);
if (unlikely(!PageChecked(page))) {
if (PageError(page) || !ext2_check_page(page, quiet))
goto fail;
}
}
return page;

fail:
ext2_put_page(page);
return ERR_PTR(-EIO);
}

/*
* NOTE! unlike strncmp, ext2_match returns 1 for success, 0 for failure.
*
Expand Down Expand Up @@ -336,6 +311,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
* returns the page in which the entry was found (as a parameter - res_page),
* and the entry itself. Page is returned mapped and unlocked.
* Entry is guaranteed to be valid.
*
* On Success ext2_put_page() should be called on *res_page.
*/
struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
const struct qstr *child, struct page **res_page)
Expand Down Expand Up @@ -401,6 +378,12 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
return de;
}

/**
* Return the '..' directory entry and the page in which the entry was found
* (as a parameter - p).
*
* On Success ext2_put_page() should be called on *p.
*/
struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
{
struct page *page = ext2_get_page(dir, 0, 0);
Expand Down
27 changes: 27 additions & 0 deletions fs/ext2/ext2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <linux/blockgroup_lock.h>
#include <linux/percpu_counter.h>
#include <linux/rbtree.h>
#include <linux/mm.h>
#include <linux/highmem.h>

/* XXX Here for now... not interested in restructing headers JUST now */

Expand Down Expand Up @@ -745,6 +747,31 @@ extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
extern int ext2_empty_dir (struct inode *);
extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
static inline void ext2_put_page(struct page *page)
{
kunmap(page);
put_page(page);
}

static inline struct page * ext2_get_page(struct inode *dir, unsigned long n,
int quiet)
{
struct address_space *mapping = dir->i_mapping;
struct page *page = read_mapping_page(mapping, n, NULL);
if (!IS_ERR(page)) {
kmap(page);
if (unlikely(!PageChecked(page))) {
if (PageError(page) || !ext2_check_page(page, quiet))
goto fail;
}
}
return page;

fail:
ext2_put_page(page);
return ERR_PTR(-EIO);
}


/* ialloc.c */
extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
Expand Down
15 changes: 5 additions & 10 deletions fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,18 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
if (dir_de) {
if (old_dir != new_dir)
ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
else {
kunmap(dir_page);
put_page(dir_page);
}
else
ext2_put_page(dir_page);
inode_dec_link_count(old_dir);
}
return 0;


out_dir:
if (dir_de) {
kunmap(dir_page);
put_page(dir_page);
}
if (dir_de)
ext2_put_page(dir_page);
out_old:
kunmap(old_page);
put_page(old_page);
ext2_put_page(old_page);
out:
return err;
}
Expand Down

0 comments on commit d24a7d5

Please sign in to comment.