Commit da1dfb6a authored by Steven Whitehouse's avatar Steven Whitehouse

GFS2: Make write size hinting code common

This collects up the write size hinting code which is used by the
block reservation subsystem into a single function. At the same
time this also corrects the rounding for this calculation.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 0d7614f0
...@@ -322,6 +322,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -322,6 +322,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return -ENOTTY; return -ENOTTY;
} }
/**
* gfs2_size_hint - Give a hint to the size of a write request
* @file: The struct file
* @offset: The file offset of the write
* @size: The length of the write
*
* When we are about to do a write, this function records the total
* write size in order to provide a suitable hint to the lower layers
* about how many blocks will be required.
*
*/
static void gfs2_size_hint(struct file *filep, loff_t offset, size_t size)
{
struct inode *inode = filep->f_dentry->d_inode;
struct gfs2_sbd *sdp = GFS2_SB(inode);
struct gfs2_inode *ip = GFS2_I(inode);
size_t blks = (size + sdp->sd_sb.sb_bsize - 1) >> sdp->sd_sb.sb_bsize_shift;
int hint = min_t(size_t, INT_MAX, blks);
atomic_set(&ip->i_res->rs_sizehint, hint);
}
/** /**
* gfs2_allocate_page_backing - Use bmap to allocate blocks * gfs2_allocate_page_backing - Use bmap to allocate blocks
* @page: The (locked) page to allocate backing for * @page: The (locked) page to allocate backing for
...@@ -382,8 +405,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -382,8 +405,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
if (ret) if (ret)
return ret; return ret;
atomic_set(&ip->i_res->rs_sizehint, gfs2_size_hint(vma->vm_file, pos, PAGE_CACHE_SIZE);
PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift);
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); ret = gfs2_glock_nq(&gh);
...@@ -663,7 +685,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -663,7 +685,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
if (ret) if (ret)
return ret; return ret;
atomic_set(&ip->i_res->rs_sizehint, writesize >> sdp->sd_sb.sb_bsize_shift); gfs2_size_hint(file, pos, writesize);
if (file->f_flags & O_APPEND) { if (file->f_flags & O_APPEND) {
struct gfs2_holder gh; struct gfs2_holder gh;
...@@ -789,7 +812,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset, ...@@ -789,7 +812,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
if (unlikely(error)) if (unlikely(error))
goto out_uninit; goto out_uninit;
atomic_set(&ip->i_res->rs_sizehint, len >> sdp->sd_sb.sb_bsize_shift); gfs2_size_hint(file, offset, len);
while (len > 0) { while (len > 0) {
if (len < bytes) if (len < bytes)
......
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