Skip to content

Commit af5c269

Browse files
committed
GFS2: Clean up reservation removal
The reservation for an inode should be cleared when it is truncated so that we can start again at a different offset for future allocations. We could try and do better than that, by resetting the search based on where the truncation started from, but this is only a first step. In addition, there are three callers of gfs2_rs_delete() but only one of those should really be testing the value of i_writecount. While we get away with that in the other cases currently, I think it would be better if we made that test specific to the one case which requires it. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 5ca1db4 commit af5c269

6 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎fs/gfs2/bmap.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ static int do_grow(struct inode *inode, u64 size)
12791279

12801280
int gfs2_setattr_size(struct inode *inode, u64 newsize)
12811281
{
1282+
struct gfs2_inode *ip = GFS2_I(inode);
12821283
int ret;
12831284
u64 oldsize;
12841285

@@ -1294,7 +1295,7 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
12941295

12951296
inode_dio_wait(inode);
12961297

1297-
ret = gfs2_rs_alloc(GFS2_I(inode));
1298+
ret = gfs2_rs_alloc(ip);
12981299
if (ret)
12991300
goto out;
13001301

@@ -1304,6 +1305,7 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
13041305
goto out;
13051306
}
13061307

1308+
gfs2_rs_deltree(ip->i_res);
13071309
ret = do_shrink(inode, oldsize, newsize);
13081310
out:
13091311
put_write_access(inode);

‎fs/gfs2/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static int gfs2_release(struct inode *inode, struct file *file)
620620
if (!(file->f_mode & FMODE_WRITE))
621621
return 0;
622622

623-
gfs2_rs_delete(ip);
623+
gfs2_rs_delete(ip, &inode->i_writecount);
624624
return 0;
625625
}
626626

‎fs/gfs2/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
711711
fail_free_inode:
712712
if (ip->i_gl)
713713
gfs2_glock_put(ip->i_gl);
714-
gfs2_rs_delete(ip);
714+
gfs2_rs_delete(ip, NULL);
715715
free_inode_nonrcu(inode);
716716
inode = NULL;
717717
fail_gunlock:

‎fs/gfs2/rgrp.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,13 @@ void gfs2_rs_deltree(struct gfs2_blkreserv *rs)
661661
/**
662662
* gfs2_rs_delete - delete a multi-block reservation
663663
* @ip: The inode for this reservation
664+
* @wcount: The inode's write count, or NULL
664665
*
665666
*/
666-
void gfs2_rs_delete(struct gfs2_inode *ip)
667+
void gfs2_rs_delete(struct gfs2_inode *ip, atomic_t *wcount)
667668
{
668-
struct inode *inode = &ip->i_inode;
669-
670669
down_write(&ip->i_rw_mutex);
671-
if (ip->i_res && atomic_read(&inode->i_writecount) <= 1) {
670+
if (ip->i_res && ((wcount == NULL) || (atomic_read(wcount) <= 1))) {
672671
gfs2_rs_deltree(ip->i_res);
673672
BUG_ON(ip->i_res->rs_free);
674673
kmem_cache_free(gfs2_rsrv_cachep, ip->i_res);

‎fs/gfs2/rgrp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
4848

4949
extern int gfs2_rs_alloc(struct gfs2_inode *ip);
5050
extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs);
51-
extern void gfs2_rs_delete(struct gfs2_inode *ip);
51+
extern void gfs2_rs_delete(struct gfs2_inode *ip, atomic_t *wcount);
5252
extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
5353
extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
5454
extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);

‎fs/gfs2/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ static void gfs2_evict_inode(struct inode *inode)
15261526
out:
15271527
/* Case 3 starts here */
15281528
truncate_inode_pages(&inode->i_data, 0);
1529-
gfs2_rs_delete(ip);
1529+
gfs2_rs_delete(ip, NULL);
15301530
gfs2_ordered_del_inode(ip);
15311531
clear_inode(inode);
15321532
gfs2_dir_hash_inval(ip);

0 commit comments

Comments
 (0)