Commit 8418dabd authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gfs2-v5.13-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 updates from Andreas Gruenbacher:
 "Various minor gfs2 cleanups and fixes"

* tag 'gfs2-v5.13-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
  gfs2: Clean up gfs2_unstuff_dinode
  gfs2: Unstuff before locking page in gfs2_page_mkwrite
  gfs2: Clean up the error handling in gfs2_page_mkwrite
  gfs2: Fix error handling in init_statfs
  gfs2: Fix underflow in gfs2_page_mkwrite
  gfs2: Use list_move_tail instead of list_del/list_add_tail
  gfs2: Fix do_gfs2_set_flags description
parents bbd91626 7a607a41
...@@ -56,14 +56,6 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -56,14 +56,6 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
u64 block, struct page *page) u64 block, struct page *page)
{ {
struct inode *inode = &ip->i_inode; struct inode *inode = &ip->i_inode;
int release = 0;
if (!page || page->index) {
page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
if (!page)
return -ENOMEM;
release = 1;
}
if (!PageUptodate(page)) { if (!PageUptodate(page)) {
void *kaddr = kmap(page); void *kaddr = kmap(page);
...@@ -97,26 +89,10 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -97,26 +89,10 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
gfs2_ordered_add_inode(ip); gfs2_ordered_add_inode(ip);
} }
if (release) {
unlock_page(page);
put_page(page);
}
return 0; return 0;
} }
/** static int __gfs2_unstuff_inode(struct gfs2_inode *ip, struct page *page)
* gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big
* @ip: The GFS2 inode to unstuff
* @page: The (optional) page. This is looked up if the @page is NULL
*
* This routine unstuffs a dinode and returns it to a "normal" state such
* that the height can be grown in the traditional way.
*
* Returns: errno
*/
int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
{ {
struct buffer_head *bh, *dibh; struct buffer_head *bh, *dibh;
struct gfs2_dinode *di; struct gfs2_dinode *di;
...@@ -124,11 +100,9 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) ...@@ -124,11 +100,9 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
int isdir = gfs2_is_dir(ip); int isdir = gfs2_is_dir(ip);
int error; int error;
down_write(&ip->i_rw_mutex);
error = gfs2_meta_inode_buffer(ip, &dibh); error = gfs2_meta_inode_buffer(ip, &dibh);
if (error) if (error)
goto out; return error;
if (i_size_read(&ip->i_inode)) { if (i_size_read(&ip->i_inode)) {
/* Get a free block, fill it with the stuffed data, /* Get a free block, fill it with the stuffed data,
...@@ -170,12 +144,38 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) ...@@ -170,12 +144,38 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
out_brelse: out_brelse:
brelse(dibh); brelse(dibh);
return error;
}
/**
* gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big
* @ip: The GFS2 inode to unstuff
*
* This routine unstuffs a dinode and returns it to a "normal" state such
* that the height can be grown in the traditional way.
*
* Returns: errno
*/
int gfs2_unstuff_dinode(struct gfs2_inode *ip)
{
struct inode *inode = &ip->i_inode;
struct page *page;
int error;
down_write(&ip->i_rw_mutex);
page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
error = -ENOMEM;
if (!page)
goto out;
error = __gfs2_unstuff_inode(ip, page);
unlock_page(page);
put_page(page);
out: out:
up_write(&ip->i_rw_mutex); up_write(&ip->i_rw_mutex);
return error; return error;
} }
/** /**
* find_metapath - Find path through the metadata tree * find_metapath - Find path through the metadata tree
* @sdp: The superblock * @sdp: The superblock
...@@ -1079,7 +1079,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1079,7 +1079,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
goto out_trans_fail; goto out_trans_fail;
if (unstuff) { if (unstuff) {
ret = gfs2_unstuff_dinode(ip, NULL); ret = gfs2_unstuff_dinode(ip);
if (ret) if (ret)
goto out_trans_end; goto out_trans_end;
release_metapath(mp); release_metapath(mp);
...@@ -2143,7 +2143,7 @@ static int do_grow(struct inode *inode, u64 size) ...@@ -2143,7 +2143,7 @@ static int do_grow(struct inode *inode, u64 size)
goto do_grow_release; goto do_grow_release;
if (unstuff) { if (unstuff) {
error = gfs2_unstuff_dinode(ip, NULL); error = gfs2_unstuff_dinode(ip);
if (error) if (error)
goto do_end_trans; goto do_end_trans;
} }
......
...@@ -46,7 +46,7 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip, ...@@ -46,7 +46,7 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
extern const struct iomap_ops gfs2_iomap_ops; extern const struct iomap_ops gfs2_iomap_ops;
extern const struct iomap_writeback_ops gfs2_writeback_ops; extern const struct iomap_writeback_ops gfs2_writeback_ops;
extern int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); extern int gfs2_unstuff_dinode(struct gfs2_inode *ip);
extern int gfs2_block_map(struct inode *inode, sector_t lblock, extern int gfs2_block_map(struct inode *inode, sector_t lblock,
struct buffer_head *bh, int create); struct buffer_head *bh, int create);
extern int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, extern int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
......
...@@ -172,7 +172,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, ...@@ -172,7 +172,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
return -EINVAL; return -EINVAL;
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
error = gfs2_unstuff_dinode(ip, NULL); error = gfs2_unstuff_dinode(ip);
if (error) if (error)
return error; return error;
} }
......
...@@ -210,7 +210,7 @@ void gfs2_set_inode_flags(struct inode *inode) ...@@ -210,7 +210,7 @@ void gfs2_set_inode_flags(struct inode *inode)
/** /**
* do_gfs2_set_flags - set flags on an inode * do_gfs2_set_flags - set flags on an inode
* @filp: file pointer * @inode: The inode
* @reqflags: The flags to set * @reqflags: The flags to set
* @mask: Indicates which flags are valid * @mask: Indicates which flags are valid
* @fsflags: The FS_* inode flags passed in * @fsflags: The FS_* inode flags passed in
...@@ -427,22 +427,25 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -427,22 +427,25 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
struct gfs2_alloc_parms ap = { .aflags = 0, }; struct gfs2_alloc_parms ap = { .aflags = 0, };
u64 offset = page_offset(page); u64 offset = page_offset(page);
unsigned int data_blocks, ind_blocks, rblocks; unsigned int data_blocks, ind_blocks, rblocks;
vm_fault_t ret = VM_FAULT_LOCKED;
struct gfs2_holder gh; struct gfs2_holder gh;
unsigned int length; unsigned int length;
loff_t size; loff_t size;
int ret; int err;
sb_start_pagefault(inode->i_sb); sb_start_pagefault(inode->i_sb);
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
ret = gfs2_glock_nq(&gh); err = gfs2_glock_nq(&gh);
if (ret) if (err) {
ret = block_page_mkwrite_return(err);
goto out_uninit; goto out_uninit;
}
/* Check page index against inode size */ /* Check page index against inode size */
size = i_size_read(inode); size = i_size_read(inode);
if (offset >= size) { if (offset >= size) {
ret = -EINVAL; ret = VM_FAULT_SIGBUS;
goto out_unlock; goto out_unlock;
} }
...@@ -450,8 +453,8 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -450,8 +453,8 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
file_update_time(vmf->vma->vm_file); file_update_time(vmf->vma->vm_file);
/* page is wholly or partially inside EOF */ /* page is wholly or partially inside EOF */
if (offset > size - PAGE_SIZE) if (size - offset < PAGE_SIZE)
length = offset_in_page(size); length = size - offset;
else else
length = PAGE_SIZE; length = PAGE_SIZE;
...@@ -469,24 +472,30 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -469,24 +472,30 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
!gfs2_write_alloc_required(ip, offset, length)) { !gfs2_write_alloc_required(ip, offset, length)) {
lock_page(page); lock_page(page);
if (!PageUptodate(page) || page->mapping != inode->i_mapping) { if (!PageUptodate(page) || page->mapping != inode->i_mapping) {
ret = -EAGAIN; ret = VM_FAULT_NOPAGE;
unlock_page(page); unlock_page(page);
} }
goto out_unlock; goto out_unlock;
} }
ret = gfs2_rindex_update(sdp); err = gfs2_rindex_update(sdp);
if (ret) if (err) {
ret = block_page_mkwrite_return(err);
goto out_unlock; goto out_unlock;
}
gfs2_write_calc_reserv(ip, length, &data_blocks, &ind_blocks); gfs2_write_calc_reserv(ip, length, &data_blocks, &ind_blocks);
ap.target = data_blocks + ind_blocks; ap.target = data_blocks + ind_blocks;
ret = gfs2_quota_lock_check(ip, &ap); err = gfs2_quota_lock_check(ip, &ap);
if (ret) if (err) {
ret = block_page_mkwrite_return(err);
goto out_unlock; goto out_unlock;
ret = gfs2_inplace_reserve(ip, &ap); }
if (ret) err = gfs2_inplace_reserve(ip, &ap);
if (err) {
ret = block_page_mkwrite_return(err);
goto out_quota_unlock; goto out_quota_unlock;
}
rblocks = RES_DINODE + ind_blocks; rblocks = RES_DINODE + ind_blocks;
if (gfs2_is_jdata(ip)) if (gfs2_is_jdata(ip))
...@@ -495,28 +504,38 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -495,28 +504,38 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
rblocks += RES_STATFS + RES_QUOTA; rblocks += RES_STATFS + RES_QUOTA;
rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
} }
ret = gfs2_trans_begin(sdp, rblocks, 0); err = gfs2_trans_begin(sdp, rblocks, 0);
if (ret) if (err) {
ret = block_page_mkwrite_return(err);
goto out_trans_fail; goto out_trans_fail;
}
/* Unstuff, if required, and allocate backing blocks for page */
if (gfs2_is_stuffed(ip)) {
err = gfs2_unstuff_dinode(ip);
if (err) {
ret = block_page_mkwrite_return(err);
goto out_trans_end;
}
}
lock_page(page); lock_page(page);
ret = -EAGAIN;
/* If truncated, we must retry the operation, we may have raced /* If truncated, we must retry the operation, we may have raced
* with the glock demotion code. * with the glock demotion code.
*/ */
if (!PageUptodate(page) || page->mapping != inode->i_mapping) if (!PageUptodate(page) || page->mapping != inode->i_mapping) {
goto out_trans_end; ret = VM_FAULT_NOPAGE;
goto out_page_locked;
}
/* Unstuff, if required, and allocate backing blocks for page */ err = gfs2_allocate_page_backing(page, length);
ret = 0; if (err)
if (gfs2_is_stuffed(ip)) ret = block_page_mkwrite_return(err);
ret = gfs2_unstuff_dinode(ip, page);
if (ret == 0)
ret = gfs2_allocate_page_backing(page, length);
out_trans_end: out_page_locked:
if (ret) if (ret != VM_FAULT_LOCKED)
unlock_page(page); unlock_page(page);
out_trans_end:
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
out_trans_fail: out_trans_fail:
gfs2_inplace_release(ip); gfs2_inplace_release(ip);
...@@ -526,12 +545,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -526,12 +545,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
gfs2_glock_dq(&gh); gfs2_glock_dq(&gh);
out_uninit: out_uninit:
gfs2_holder_uninit(&gh); gfs2_holder_uninit(&gh);
if (ret == 0) { if (ret == VM_FAULT_LOCKED) {
set_page_dirty(page); set_page_dirty(page);
wait_for_stable_page(page); wait_for_stable_page(page);
} }
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
return block_page_mkwrite_return(ret); return ret;
} }
static vm_fault_t gfs2_fault(struct vm_fault *vmf) static vm_fault_t gfs2_fault(struct vm_fault *vmf)
...@@ -962,7 +981,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, ...@@ -962,7 +981,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
gfs2_trans_add_meta(ip->i_gl, dibh); gfs2_trans_add_meta(ip->i_gl, dibh);
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
error = gfs2_unstuff_dinode(ip, NULL); error = gfs2_unstuff_dinode(ip);
if (unlikely(error)) if (unlikely(error))
goto out; goto out;
} }
......
...@@ -212,8 +212,7 @@ void gfs2_glock_add_to_lru(struct gfs2_glock *gl) ...@@ -212,8 +212,7 @@ void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
spin_lock(&lru_lock); spin_lock(&lru_lock);
list_del(&gl->gl_lru); list_move_tail(&gl->gl_lru, &lru_list);
list_add_tail(&gl->gl_lru, &lru_list);
if (!test_bit(GLF_LRU, &gl->gl_flags)) { if (!test_bit(GLF_LRU, &gl->gl_flags)) {
set_bit(GLF_LRU, &gl->gl_flags); set_bit(GLF_LRU, &gl->gl_flags);
......
...@@ -687,6 +687,7 @@ static int init_statfs(struct gfs2_sbd *sdp) ...@@ -687,6 +687,7 @@ static int init_statfs(struct gfs2_sbd *sdp)
} }
iput(pn); iput(pn);
pn = NULL;
ip = GFS2_I(sdp->sd_sc_inode); ip = GFS2_I(sdp->sd_sc_inode);
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0,
&sdp->sd_sc_gh); &sdp->sd_sc_gh);
......
...@@ -825,7 +825,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, ...@@ -825,7 +825,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
u64 size; u64 size;
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
err = gfs2_unstuff_dinode(ip, NULL); err = gfs2_unstuff_dinode(ip);
if (err) if (err)
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment