Commit e6a2562f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gfs2-4.20.fixes3' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull bfs2 fixes from Andreas Gruenbacher:
 "Fix two bugs leading to leaked buffer head references:

   - gfs2: Put bitmap buffers in put_super
   - gfs2: Fix iomap buffer head reference counting bug

  And one bug leading to significant slow-downs when deleting large
  files:

   - gfs2: Fix metadata read-ahead during truncate (2)"

* tag 'gfs2-4.20.fixes3' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
  gfs2: Fix iomap buffer head reference counting bug
  gfs2: Fix metadata read-ahead during truncate (2)
  gfs2: Put bitmap buffers in put_super
parents 32e2524a c26b5aa8
...@@ -826,7 +826,7 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, ...@@ -826,7 +826,7 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
ret = gfs2_meta_inode_buffer(ip, &dibh); ret = gfs2_meta_inode_buffer(ip, &dibh);
if (ret) if (ret)
goto unlock; goto unlock;
iomap->private = dibh; mp->mp_bh[0] = dibh;
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
if (flags & IOMAP_WRITE) { if (flags & IOMAP_WRITE) {
...@@ -863,9 +863,6 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, ...@@ -863,9 +863,6 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
len = lblock_stop - lblock + 1; len = lblock_stop - lblock + 1;
iomap->length = len << inode->i_blkbits; iomap->length = len << inode->i_blkbits;
get_bh(dibh);
mp->mp_bh[0] = dibh;
height = ip->i_height; height = ip->i_height;
while ((lblock + 1) * sdp->sd_sb.sb_bsize > sdp->sd_heightsize[height]) while ((lblock + 1) * sdp->sd_sb.sb_bsize > sdp->sd_heightsize[height])
height++; height++;
...@@ -898,8 +895,6 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, ...@@ -898,8 +895,6 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
iomap->bdev = inode->i_sb->s_bdev; iomap->bdev = inode->i_sb->s_bdev;
unlock: unlock:
up_read(&ip->i_rw_mutex); up_read(&ip->i_rw_mutex);
if (ret && dibh)
brelse(dibh);
return ret; return ret;
do_alloc: do_alloc:
...@@ -980,9 +975,9 @@ static void gfs2_iomap_journaled_page_done(struct inode *inode, loff_t pos, ...@@ -980,9 +975,9 @@ static void gfs2_iomap_journaled_page_done(struct inode *inode, loff_t pos,
static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
loff_t length, unsigned flags, loff_t length, unsigned flags,
struct iomap *iomap) struct iomap *iomap,
struct metapath *mp)
{ {
struct metapath mp = { .mp_aheight = 1, };
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_sbd *sdp = GFS2_SB(inode);
unsigned int data_blocks = 0, ind_blocks = 0, rblocks; unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
...@@ -996,9 +991,9 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -996,9 +991,9 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
unstuff = gfs2_is_stuffed(ip) && unstuff = gfs2_is_stuffed(ip) &&
pos + length > gfs2_max_stuffed_size(ip); pos + length > gfs2_max_stuffed_size(ip);
ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp); ret = gfs2_iomap_get(inode, pos, length, flags, iomap, mp);
if (ret) if (ret)
goto out_release; goto out_unlock;
alloc_required = unstuff || iomap->type == IOMAP_HOLE; alloc_required = unstuff || iomap->type == IOMAP_HOLE;
...@@ -1013,7 +1008,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1013,7 +1008,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
ret = gfs2_quota_lock_check(ip, &ap); ret = gfs2_quota_lock_check(ip, &ap);
if (ret) if (ret)
goto out_release; goto out_unlock;
ret = gfs2_inplace_reserve(ip, &ap); ret = gfs2_inplace_reserve(ip, &ap);
if (ret) if (ret)
...@@ -1038,17 +1033,15 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1038,17 +1033,15 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
ret = gfs2_unstuff_dinode(ip, NULL); ret = gfs2_unstuff_dinode(ip, NULL);
if (ret) if (ret)
goto out_trans_end; goto out_trans_end;
release_metapath(&mp); release_metapath(mp);
brelse(iomap->private);
iomap->private = NULL;
ret = gfs2_iomap_get(inode, iomap->offset, iomap->length, ret = gfs2_iomap_get(inode, iomap->offset, iomap->length,
flags, iomap, &mp); flags, iomap, mp);
if (ret) if (ret)
goto out_trans_end; goto out_trans_end;
} }
if (iomap->type == IOMAP_HOLE) { if (iomap->type == IOMAP_HOLE) {
ret = gfs2_iomap_alloc(inode, iomap, flags, &mp); ret = gfs2_iomap_alloc(inode, iomap, flags, mp);
if (ret) { if (ret) {
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
gfs2_inplace_release(ip); gfs2_inplace_release(ip);
...@@ -1056,7 +1049,6 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1056,7 +1049,6 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
goto out_qunlock; goto out_qunlock;
} }
} }
release_metapath(&mp);
if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip)) if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip))
iomap->page_done = gfs2_iomap_journaled_page_done; iomap->page_done = gfs2_iomap_journaled_page_done;
return 0; return 0;
...@@ -1069,10 +1061,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1069,10 +1061,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
out_qunlock: out_qunlock:
if (alloc_required) if (alloc_required)
gfs2_quota_unlock(ip); gfs2_quota_unlock(ip);
out_release: out_unlock:
if (iomap->private)
brelse(iomap->private);
release_metapath(&mp);
gfs2_write_unlock(inode); gfs2_write_unlock(inode);
return ret; return ret;
} }
...@@ -1088,10 +1077,10 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, ...@@ -1088,10 +1077,10 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
trace_gfs2_iomap_start(ip, pos, length, flags); trace_gfs2_iomap_start(ip, pos, length, flags);
if ((flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT)) { if ((flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT)) {
ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap); ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap, &mp);
} else { } else {
ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp); ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
release_metapath(&mp);
/* /*
* Silently fall back to buffered I/O for stuffed files or if * Silently fall back to buffered I/O for stuffed files or if
* we've hot a hole (see gfs2_file_direct_write). * we've hot a hole (see gfs2_file_direct_write).
...@@ -1100,6 +1089,11 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, ...@@ -1100,6 +1089,11 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
iomap->type != IOMAP_MAPPED) iomap->type != IOMAP_MAPPED)
ret = -ENOTBLK; ret = -ENOTBLK;
} }
if (!ret) {
get_bh(mp.mp_bh[0]);
iomap->private = mp.mp_bh[0];
}
release_metapath(&mp);
trace_gfs2_iomap_end(ip, iomap, ret); trace_gfs2_iomap_end(ip, iomap, ret);
return ret; return ret;
} }
...@@ -1908,10 +1902,16 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length) ...@@ -1908,10 +1902,16 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
if (ret < 0) if (ret < 0)
goto out; goto out;
/* issue read-ahead on metadata */ /* On the first pass, issue read-ahead on metadata. */
if (mp.mp_aheight > 1) { if (mp.mp_aheight > 1 && strip_h == ip->i_height - 1) {
for (; ret > 1; ret--) { unsigned int height = mp.mp_aheight - 1;
metapointer_range(&mp, mp.mp_aheight - ret,
/* No read-ahead for data blocks. */
if (mp.mp_aheight - 1 == strip_h)
height--;
for (; height >= mp.mp_aheight - ret; height--) {
metapointer_range(&mp, height,
start_list, start_aligned, start_list, start_aligned,
end_list, end_aligned, end_list, end_aligned,
&start, &end); &start, &end);
......
...@@ -733,6 +733,7 @@ void gfs2_clear_rgrpd(struct gfs2_sbd *sdp) ...@@ -733,6 +733,7 @@ void gfs2_clear_rgrpd(struct gfs2_sbd *sdp)
if (gl) { if (gl) {
glock_clear_object(gl, rgd); glock_clear_object(gl, rgd);
gfs2_rgrp_brelse(rgd);
gfs2_glock_put(gl); gfs2_glock_put(gl);
} }
...@@ -1174,7 +1175,7 @@ static u32 count_unlinked(struct gfs2_rgrpd *rgd) ...@@ -1174,7 +1175,7 @@ static u32 count_unlinked(struct gfs2_rgrpd *rgd)
* @rgd: the struct gfs2_rgrpd describing the RG to read in * @rgd: the struct gfs2_rgrpd describing the RG to read in
* *
* Read in all of a Resource Group's header and bitmap blocks. * Read in all of a Resource Group's header and bitmap blocks.
* Caller must eventually call gfs2_rgrp_relse() to free the bitmaps. * Caller must eventually call gfs2_rgrp_brelse() to free the bitmaps.
* *
* Returns: errno * Returns: errno
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment