This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anpr...@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  8 +++++---
 gfs2/fsck/pass1.c           |  8 +++++---
 gfs2/fsck/pass2.c           | 12 +++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 16 +++++-----------
 gfs2/mkfs/main_mkfs.c       | 12 +++++++++---
 6 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index dd809e48..1cb2d6fa 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2122,12 +2122,14 @@ static int build_per_node(struct gfs2_sbd *sdp)
                }
                inode_put(&ip);
 
-               err = build_statfs_change(per_node, j);
-               if (err) {
+               ip = build_statfs_change(per_node, j);
+               if (ip == NULL) {
                        log_crit(_("Error building '%s': %s\n"), 
"statfs_change",
                                 strerror(errno));
-                       return err;
+                       return 1;
                }
+               inode_put(&ip);
+
                err = build_quota_change(per_node, j);
                if (err) {
                        log_crit(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 8f576fe2..3df64de7 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1600,12 +1600,14 @@ int build_per_node(struct gfs2_sbd *sdp)
                }
                inode_put(&ip);
 
-               err = build_statfs_change(per_node, j);
-               if (err) {
+               ip = build_statfs_change(per_node, j);
+               if (ip == NULL) {
                        log_err(_("Error building '%s': %s\n"), "statfs_change",
                                strerror(errno));
-                       return err;
+                       return 1;
                }
+               inode_put(&ip);
+
                err = build_quota_change(per_node, j);
                if (err) {
                        log_err(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 229667fb..2e0c1bb7 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1885,6 +1885,16 @@ static int fsck_build_inum_range(struct gfs2_inode 
*per_node, unsigned int n)
        return 0;
 }
 
+static int fsck_build_statfs_change(struct gfs2_inode *per_node, unsigned int 
n)
+{
+       struct gfs2_inode *ip = build_statfs_change(per_node, n);
+
+       if (ip == NULL)
+               return 1;
+       inode_put(&ip);
+       return 0;
+}
+
 /* Check system directory inode                                           */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1972,7 +1982,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, 
const char *dirname,
                                                   NULL, fsck_build_inum_range);
                        sprintf(fn, "statfs_change%d", j);
                        error += check_pernode_for(j, sysinode, fn, 24, 0,
-                                                  NULL, build_statfs_change);
+                                                  NULL, 
fsck_build_statfs_change);
                        sprintf(fn, "quota_change%d", j);
                        error += check_pernode_for(j, sysinode, fn, 1048576, 1,
                                                   &quota_change_fxns,
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e9c51054..0c702df0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -788,7 +788,7 @@ extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
                              uint64_t *buf, uint8_t state);
 extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, 
unsigned int n);
-extern int build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, 
unsigned int j);
 extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
 /* super.c */
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 96a62475..bd226e6d 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -296,7 +296,7 @@ struct gfs2_inode *build_inum_range(struct gfs2_inode 
*per_node, unsigned int j)
        return ip;
 }
 
-int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned 
int j)
 {
        char name[256];
        struct gfs2_inode *ip;
@@ -304,19 +304,13 @@ int build_statfs_change(struct gfs2_inode *per_node, 
unsigned int j)
        sprintf(name, "statfs_change%u", j);
        ip = createi(per_node, name, S_IFREG | 0600,
                     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-       if (ip == NULL) {
-               return errno;
-       }
+       if (ip == NULL)
+               return NULL;
+
        ip->i_size = sizeof(struct gfs2_statfs_change);
        lgfs2_dinode_out(ip, ip->i_bh->b_data);
        bmodified(ip->i_bh);
-       if (cfg_debug) {
-               printf("\nStatFS Change %u:\n", j);
-               lgfs2_dinode_print(ip->i_bh->b_data);
-       }
-
-       inode_put(&ip);
-       return 0;
+       return ip;
 }
 
 int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index ea4a653f..e0f42c5a 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -708,12 +708,18 @@ static int build_per_node(struct gfs2_sbd *sdp, struct 
mkfs_opts *opts)
                }
                inode_put(&ip);
 
-               err = build_statfs_change(per_node, j);
-               if (err) {
+               ip = build_statfs_change(per_node, j);
+               if (ip == NULL) {
                        fprintf(stderr, _("Error building '%s': %s\n"), 
"statfs_change",
                                strerror(errno));
-                       return err;
+                       return 1;
                }
+               if (opts->debug) {
+                       printf("\nStatFS Change %u:\n", j);
+                       lgfs2_dinode_print(ip->i_bh->b_data);
+               }
+               inode_put(&ip);
+
                err = build_quota_change(per_node, j);
                if (err) {
                        fprintf(stderr, _("Error building '%s': %s\n"), 
"quota_change",
-- 
2.34.1

Reply via email to