|
@@ -322,6 +322,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
|
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
|
|
|
* @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)
|
|
|
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);
|
|
@@ -663,7 +685,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;
|
|
|
|
|
@@ -789,7 +812,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)
|