minix: move releasing pages into unlink and rename

Instead of consuming the page reference and kmap in the low-level
minix_delete_entry and minix_set_link helpers, do it in the callers
where that code can be shared with the error cleanup path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Christoph Hellwig 2023-01-18 18:30:21 +01:00 committed by Al Viro
parent 4a29a1262a
commit 35bb6a092c
2 changed files with 10 additions and 11 deletions

View File

@ -306,7 +306,6 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
} else { } else {
unlock_page(page); unlock_page(page);
} }
dir_put_page(page);
inode->i_ctime = inode->i_mtime = current_time(inode); inode->i_ctime = inode->i_mtime = current_time(inode);
mark_inode_dirty(inode); mark_inode_dirty(inode);
return err; return err;
@ -430,7 +429,6 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page,
} else { } else {
unlock_page(page); unlock_page(page);
} }
dir_put_page(page);
dir->i_mtime = dir->i_ctime = current_time(dir); dir->i_mtime = dir->i_ctime = current_time(dir);
mark_inode_dirty(dir); mark_inode_dirty(dir);
} }

View File

@ -140,23 +140,23 @@ static int minix_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
static int minix_unlink(struct inode * dir, struct dentry *dentry) static int minix_unlink(struct inode * dir, struct dentry *dentry)
{ {
int err = -ENOENT;
struct inode * inode = d_inode(dentry); struct inode * inode = d_inode(dentry);
struct page * page; struct page * page;
struct minix_dir_entry * de; struct minix_dir_entry * de;
int err;
de = minix_find_entry(dentry, &page); de = minix_find_entry(dentry, &page);
if (!de) if (!de)
goto end_unlink; return -ENOENT;
err = minix_delete_entry(de, page); err = minix_delete_entry(de, page);
if (err) kunmap(page);
goto end_unlink; put_page(page);
if (err)
return err;
inode->i_ctime = dir->i_ctime; inode->i_ctime = dir->i_ctime;
inode_dec_link_count(inode); inode_dec_link_count(inode);
end_unlink: return 0;
return err;
} }
static int minix_rmdir(struct inode * dir, struct dentry *dentry) static int minix_rmdir(struct inode * dir, struct dentry *dentry)
@ -213,7 +213,10 @@ static int minix_rename(struct user_namespace *mnt_userns,
new_de = minix_find_entry(new_dentry, &new_page); new_de = minix_find_entry(new_dentry, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
err = 0;
minix_set_link(new_de, new_page, old_inode); minix_set_link(new_de, new_page, old_inode);
kunmap(new_page);
put_page(new_page);
new_inode->i_ctime = current_time(new_inode); new_inode->i_ctime = current_time(new_inode);
if (dir_de) if (dir_de)
drop_nlink(new_inode); drop_nlink(new_inode);
@ -233,8 +236,6 @@ static int minix_rename(struct user_namespace *mnt_userns,
minix_set_link(dir_de, dir_page, new_dir); minix_set_link(dir_de, dir_page, new_dir);
inode_dec_link_count(old_dir); inode_dec_link_count(old_dir);
} }
return 0;
out_dir: out_dir:
if (dir_de) { if (dir_de) {
kunmap(dir_page); kunmap(dir_page);