diff options
author | Bob Peterson <rpeterso@redhat.com> | 2013-05-28 10:04:44 -0400 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2013-06-03 11:38:58 -0400 |
commit | 2b3dcf35810ff02ad0e785527a25c1b13bf82b19 (patch) | |
tree | 0ab2a2f709290e2eb4d74d385a7d832929e3768c /fs/gfs2 | |
parent | 4a586812055dbd2588b0836ab758f6b9670c3949 (diff) |
GFS2: Increase i_writecount during gfs2_setattr_size
This patch calls get_write_access in a few functions. This
merely increases inode->i_writecount for the duration of the function.
That will ensure that any file closes won't delete the inode's
multi-block reservation while the function is running.
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2')
-rw-r--r-- | fs/gfs2/bmap.c | 17 | ||||
-rw-r--r-- | fs/gfs2/file.c | 19 | ||||
-rw-r--r-- | fs/gfs2/rgrp.c | 4 |
3 files changed, 29 insertions, 11 deletions
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 1dc9a13ce6bb..93b5809c20bb 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
@@ -1286,17 +1286,26 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize) | |||
1286 | if (ret) | 1286 | if (ret) |
1287 | return ret; | 1287 | return ret; |
1288 | 1288 | ||
1289 | ret = get_write_access(inode); | ||
1290 | if (ret) | ||
1291 | return ret; | ||
1292 | |||
1289 | inode_dio_wait(inode); | 1293 | inode_dio_wait(inode); |
1290 | 1294 | ||
1291 | ret = gfs2_rs_alloc(GFS2_I(inode)); | 1295 | ret = gfs2_rs_alloc(GFS2_I(inode)); |
1292 | if (ret) | 1296 | if (ret) |
1293 | return ret; | 1297 | goto out; |
1294 | 1298 | ||
1295 | oldsize = inode->i_size; | 1299 | oldsize = inode->i_size; |
1296 | if (newsize >= oldsize) | 1300 | if (newsize >= oldsize) { |
1297 | return do_grow(inode, newsize); | 1301 | ret = do_grow(inode, newsize); |
1302 | goto out; | ||
1303 | } | ||
1298 | 1304 | ||
1299 | return do_shrink(inode, oldsize, newsize); | 1305 | ret = do_shrink(inode, oldsize, newsize); |
1306 | out: | ||
1307 | put_write_access(inode); | ||
1308 | return ret; | ||
1300 | } | 1309 | } |
1301 | 1310 | ||
1302 | int gfs2_truncatei_resume(struct gfs2_inode *ip) | 1311 | int gfs2_truncatei_resume(struct gfs2_inode *ip) |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index acd16764b133..ad0dc38d87ab 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -402,16 +402,20 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
402 | /* Update file times before taking page lock */ | 402 | /* Update file times before taking page lock */ |
403 | file_update_time(vma->vm_file); | 403 | file_update_time(vma->vm_file); |
404 | 404 | ||
405 | ret = get_write_access(inode); | ||
406 | if (ret) | ||
407 | goto out; | ||
408 | |||
405 | ret = gfs2_rs_alloc(ip); | 409 | ret = gfs2_rs_alloc(ip); |
406 | if (ret) | 410 | if (ret) |
407 | return ret; | 411 | goto out_write_access; |
408 | 412 | ||
409 | gfs2_size_hint(vma->vm_file, pos, PAGE_CACHE_SIZE); | 413 | gfs2_size_hint(vma->vm_file, pos, PAGE_CACHE_SIZE); |
410 | 414 | ||
411 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 415 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
412 | ret = gfs2_glock_nq(&gh); | 416 | ret = gfs2_glock_nq(&gh); |
413 | if (ret) | 417 | if (ret) |
414 | goto out; | 418 | goto out_uninit; |
415 | 419 | ||
416 | set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); | 420 | set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); |
417 | set_bit(GIF_SW_PAGED, &ip->i_flags); | 421 | set_bit(GIF_SW_PAGED, &ip->i_flags); |
@@ -480,12 +484,15 @@ out_quota_unlock: | |||
480 | gfs2_quota_unlock(ip); | 484 | gfs2_quota_unlock(ip); |
481 | out_unlock: | 485 | out_unlock: |
482 | gfs2_glock_dq(&gh); | 486 | gfs2_glock_dq(&gh); |
483 | out: | 487 | out_uninit: |
484 | gfs2_holder_uninit(&gh); | 488 | gfs2_holder_uninit(&gh); |
485 | if (ret == 0) { | 489 | if (ret == 0) { |
486 | set_page_dirty(page); | 490 | set_page_dirty(page); |
487 | wait_for_stable_page(page); | 491 | wait_for_stable_page(page); |
488 | } | 492 | } |
493 | out_write_access: | ||
494 | put_write_access(inode); | ||
495 | out: | ||
489 | sb_end_pagefault(inode->i_sb); | 496 | sb_end_pagefault(inode->i_sb); |
490 | return block_page_mkwrite_return(ret); | 497 | return block_page_mkwrite_return(ret); |
491 | } | 498 | } |
@@ -594,10 +601,10 @@ static int gfs2_release(struct inode *inode, struct file *file) | |||
594 | kfree(file->private_data); | 601 | kfree(file->private_data); |
595 | file->private_data = NULL; | 602 | file->private_data = NULL; |
596 | 603 | ||
597 | if ((file->f_mode & FMODE_WRITE) && | 604 | if (!(file->f_mode & FMODE_WRITE)) |
598 | (atomic_read(&inode->i_writecount) == 1)) | 605 | return 0; |
599 | gfs2_rs_delete(ip); | ||
600 | 606 | ||
607 | gfs2_rs_delete(ip); | ||
601 | return 0; | 608 | return 0; |
602 | } | 609 | } |
603 | 610 | ||
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 5232525934ae..9809156e3d04 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -638,8 +638,10 @@ void gfs2_rs_deltree(struct gfs2_blkreserv *rs) | |||
638 | */ | 638 | */ |
639 | void gfs2_rs_delete(struct gfs2_inode *ip) | 639 | void gfs2_rs_delete(struct gfs2_inode *ip) |
640 | { | 640 | { |
641 | struct inode *inode = &ip->i_inode; | ||
642 | |||
641 | down_write(&ip->i_rw_mutex); | 643 | down_write(&ip->i_rw_mutex); |
642 | if (ip->i_res) { | 644 | if (ip->i_res && atomic_read(&inode->i_writecount) <= 1) { |
643 | gfs2_rs_deltree(ip->i_res); | 645 | gfs2_rs_deltree(ip->i_res); |
644 | BUG_ON(ip->i_res->rs_free); | 646 | BUG_ON(ip->i_res->rs_free); |
645 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); | 647 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); |