diff options
Diffstat (limited to 'fs/gfs2/file.c')
-rw-r--r-- | fs/gfs2/file.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index d1d791ef38de..0def0504afc1 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -323,6 +323,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
323 | } | 323 | } |
324 | 324 | ||
325 | /** | 325 | /** |
326 | * gfs2_size_hint - Give a hint to the size of a write request | ||
327 | * @file: The struct file | ||
328 | * @offset: The file offset of the write | ||
329 | * @size: The length of the write | ||
330 | * | ||
331 | * When we are about to do a write, this function records the total | ||
332 | * write size in order to provide a suitable hint to the lower layers | ||
333 | * about how many blocks will be required. | ||
334 | * | ||
335 | */ | ||
336 | |||
337 | static void gfs2_size_hint(struct file *filep, loff_t offset, size_t size) | ||
338 | { | ||
339 | struct inode *inode = filep->f_dentry->d_inode; | ||
340 | struct gfs2_sbd *sdp = GFS2_SB(inode); | ||
341 | struct gfs2_inode *ip = GFS2_I(inode); | ||
342 | size_t blks = (size + sdp->sd_sb.sb_bsize - 1) >> sdp->sd_sb.sb_bsize_shift; | ||
343 | int hint = min_t(size_t, INT_MAX, blks); | ||
344 | |||
345 | atomic_set(&ip->i_res->rs_sizehint, hint); | ||
346 | } | ||
347 | |||
348 | /** | ||
326 | * gfs2_allocate_page_backing - Use bmap to allocate blocks | 349 | * gfs2_allocate_page_backing - Use bmap to allocate blocks |
327 | * @page: The (locked) page to allocate backing for | 350 | * @page: The (locked) page to allocate backing for |
328 | * | 351 | * |
@@ -382,8 +405,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
382 | if (ret) | 405 | if (ret) |
383 | return ret; | 406 | return ret; |
384 | 407 | ||
385 | atomic_set(&ip->i_res->rs_sizehint, | 408 | gfs2_size_hint(vma->vm_file, pos, PAGE_CACHE_SIZE); |
386 | PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift); | ||
387 | 409 | ||
388 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 410 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
389 | ret = gfs2_glock_nq(&gh); | 411 | ret = gfs2_glock_nq(&gh); |
@@ -419,7 +441,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
419 | rblocks += data_blocks ? data_blocks : 1; | 441 | rblocks += data_blocks ? data_blocks : 1; |
420 | if (ind_blocks || data_blocks) { | 442 | if (ind_blocks || data_blocks) { |
421 | rblocks += RES_STATFS + RES_QUOTA; | 443 | rblocks += RES_STATFS + RES_QUOTA; |
422 | rblocks += gfs2_rg_blocks(ip); | 444 | rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
423 | } | 445 | } |
424 | ret = gfs2_trans_begin(sdp, rblocks, 0); | 446 | ret = gfs2_trans_begin(sdp, rblocks, 0); |
425 | if (ret) | 447 | if (ret) |
@@ -470,6 +492,7 @@ out: | |||
470 | static const struct vm_operations_struct gfs2_vm_ops = { | 492 | static const struct vm_operations_struct gfs2_vm_ops = { |
471 | .fault = filemap_fault, | 493 | .fault = filemap_fault, |
472 | .page_mkwrite = gfs2_page_mkwrite, | 494 | .page_mkwrite = gfs2_page_mkwrite, |
495 | .remap_pages = generic_file_remap_pages, | ||
473 | }; | 496 | }; |
474 | 497 | ||
475 | /** | 498 | /** |
@@ -504,7 +527,6 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) | |||
504 | return error; | 527 | return error; |
505 | } | 528 | } |
506 | vma->vm_ops = &gfs2_vm_ops; | 529 | vma->vm_ops = &gfs2_vm_ops; |
507 | vma->vm_flags |= VM_CAN_NONLINEAR; | ||
508 | 530 | ||
509 | return 0; | 531 | return 0; |
510 | } | 532 | } |
@@ -663,7 +685,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
663 | if (ret) | 685 | if (ret) |
664 | return ret; | 686 | return ret; |
665 | 687 | ||
666 | atomic_set(&ip->i_res->rs_sizehint, writesize >> sdp->sd_sb.sb_bsize_shift); | 688 | gfs2_size_hint(file, pos, writesize); |
689 | |||
667 | if (file->f_flags & O_APPEND) { | 690 | if (file->f_flags & O_APPEND) { |
668 | struct gfs2_holder gh; | 691 | struct gfs2_holder gh; |
669 | 692 | ||
@@ -789,7 +812,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset, | |||
789 | if (unlikely(error)) | 812 | if (unlikely(error)) |
790 | goto out_uninit; | 813 | goto out_uninit; |
791 | 814 | ||
792 | atomic_set(&ip->i_res->rs_sizehint, len >> sdp->sd_sb.sb_bsize_shift); | 815 | gfs2_size_hint(file, offset, len); |
793 | 816 | ||
794 | while (len > 0) { | 817 | while (len > 0) { |
795 | if (len < bytes) | 818 | if (len < bytes) |
@@ -822,7 +845,7 @@ retry: | |||
822 | &max_bytes, &data_blocks, &ind_blocks); | 845 | &max_bytes, &data_blocks, &ind_blocks); |
823 | 846 | ||
824 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + | 847 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + |
825 | RES_RG_HDR + gfs2_rg_blocks(ip); | 848 | RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
826 | if (gfs2_is_jdata(ip)) | 849 | if (gfs2_is_jdata(ip)) |
827 | rblocks += data_blocks ? data_blocks : 1; | 850 | rblocks += data_blocks ? data_blocks : 1; |
828 | 851 | ||