GFS2: Make write size hinting code common
From c798798bb81ca1eb0b2680545740475984290dcb Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Thu, 26 Jul 2012 11:30:54 +0100
Subject: 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 Steven Whitehouse <[email protected]>
fs/gfs2/file.c +27 -4
@@ -323,6 +323,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) }/** +* 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 * @page: The (locked) page to allocate backing for *
@@ -383,8 +406,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)if (ret)return ret; -atomic_set (&ip->i_res->rs_sizehint, -PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift); +gfs2_size_hint (vma->vm_file, pos,PAGE_CACHE_SIZE );gfs2_holder_init (ip->i_gl,LM_ST_EXCLUSIVE ,0 , &gh); ret =gfs2_glock_nq (&gh);
@@ -669,7 +691,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,if (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 ) {struct gfs2_holder gh;
@@ -795,7 +818,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,if (unlikely (error)) 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 ) {if (len < bytes)
Signature · 1 line
1.7.4