gfs2: gfs2_setattr_size error path fix
authorAndreas Gruenbacher <agruenba@redhat.com>
Fri, 10 Dec 2021 13:43:36 +0000 (14:43 +0100)
committerAndreas Gruenbacher <agruenba@redhat.com>
Tue, 15 Feb 2022 14:01:40 +0000 (15:01 +0100)
When gfs2_setattr_size() fails, it calls gfs2_rs_delete(ip, NULL) to get
rid of any reservations the inode may have.  Instead, it should pass in
the inode's write count as the second parameter to allow
gfs2_rs_delete() to figure out if the inode has any writers left.

In a next step, there are two instances of gfs2_rs_delete(ip, NULL) left
where we know that there can be no other users of the inode.  Replace
those with gfs2_rs_deltree(&ip->i_res) to avoid the unnecessary write
count check.

With that, gfs2_rs_delete() is only called with the inode's actual write
count, so get rid of the second parameter.

Fixes: a097dc7e24cb ("GFS2: Make rgrp reservations part of the gfs2_inode structure")
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/bmap.c
fs/gfs2/file.c
fs/gfs2/inode.c
fs/gfs2/rgrp.c
fs/gfs2/rgrp.h
fs/gfs2/super.c

index d67108489148eef281128c6841c52135abf74050..fbdb7a30470a39f7c246adc3a0ab5706d80f1fda 100644 (file)
@@ -2146,7 +2146,7 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
 
        ret = do_shrink(inode, newsize);
 out:
-       gfs2_rs_delete(ip, NULL);
+       gfs2_rs_delete(ip);
        gfs2_qa_put(ip);
        return ret;
 }
index 8c39a8571b1fa9bf4db49405dfcbdd73184181bb..5bac4f6e8e057f551a26be8d6685488d29627c00 100644 (file)
@@ -706,7 +706,7 @@ static int gfs2_release(struct inode *inode, struct file *file)
 
        if (file->f_mode & FMODE_WRITE) {
                if (gfs2_rs_active(&ip->i_res))
-                       gfs2_rs_delete(ip, &inode->i_writecount);
+                       gfs2_rs_delete(ip);
                gfs2_qa_put(ip);
        }
        return 0;
index 89905f4f29bb6de91e181373c4f168431f3e8e74..66a123306aecb04b48a8f8de0aae43e3c91b238b 100644 (file)
@@ -793,7 +793,7 @@ fail_free_inode:
                if (free_vfs_inode) /* else evict will do the put for us */
                        gfs2_glock_put(ip->i_gl);
        }
-       gfs2_rs_delete(ip, NULL);
+       gfs2_rs_deltree(&ip->i_res);
        gfs2_qa_put(ip);
 fail_free_acls:
        posix_acl_release(default_acl);
index 9b04a570c58263707ac99d19eb55bc480389cd3c..9df8a84f85a649bf82c83c7a4d85d1c5f8c8cd00 100644 (file)
@@ -680,13 +680,14 @@ void gfs2_rs_deltree(struct gfs2_blkreserv *rs)
 /**
  * gfs2_rs_delete - delete a multi-block reservation
  * @ip: The inode for this reservation
- * @wcount: The inode's write count, or NULL
  *
  */
-void gfs2_rs_delete(struct gfs2_inode *ip, atomic_t *wcount)
+void gfs2_rs_delete(struct gfs2_inode *ip)
 {
+       struct inode *inode = &ip->i_inode;
+
        down_write(&ip->i_rw_mutex);
-       if ((wcount == NULL) || (atomic_read(wcount) <= 1))
+       if (atomic_read(&inode->i_writecount) <= 1)
                gfs2_rs_deltree(&ip->i_res);
        up_write(&ip->i_rw_mutex);
 }
index 3e2ca1fb43056c6520913357ec5ba10d9fdf7566..46dd94e9e085c20748e744c1eaa13340d959060a 100644 (file)
@@ -45,7 +45,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
                             bool dinode, u64 *generation);
 
 extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs);
-extern void gfs2_rs_delete(struct gfs2_inode *ip, atomic_t *wcount);
+extern void gfs2_rs_delete(struct gfs2_inode *ip);
 extern void __gfs2_free_blocks(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
                               u64 bstart, u32 blen, int meta);
 extern void gfs2_free_meta(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
index 64c67090f50362a788fd33691dec3fff484d91ab..143a47359d1b881e97b72268f9bde70abf5ec672 100644 (file)
@@ -1396,7 +1396,7 @@ out:
        truncate_inode_pages_final(&inode->i_data);
        if (ip->i_qadata)
                gfs2_assert_warn(sdp, ip->i_qadata->qa_ref == 0);
-       gfs2_rs_delete(ip, NULL);
+       gfs2_rs_deltree(&ip->i_res);
        gfs2_ordered_del_inode(ip);
        clear_inode(inode);
        gfs2_dir_hash_inval(ip);