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 |  5 +++--
 gfs2/fsck/initialize.c      | 17 +++++++++--------
 gfs2/fsck/pass1.c           | 11 ++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 20 +++++++-------------
 gfs2/mkfs/main_mkfs.c       |  9 +++++++--
 6 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5a542e29..8667d8fb 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2368,12 +2368,13 @@ int main(int argc, char **argv)
                }
                inode_put(&ip);
                /* Create the quota file */
-               error = build_quota(&sb2);
-               if (error) {
+               ip = build_quota(&sb2);
+               if (ip == NULL) {
                        log_crit(_("Error building quota inode: %s\n"),
                                 strerror(error));
                        exit(-1);
                }
+               inode_put(&ip);
 
                /* Copy out the master dinode */
                if (sb2.master_dir->i_bh->b_modified)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e1c71fc8..a2bc44c0 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -562,11 +562,12 @@ static int rebuild_master(struct gfs2_sbd *sdp)
                        exit(FSCK_ERROR);
                }
        } else {
-               err = build_quota(sdp);
-               if (err) {
-                       log_crit(_("Error %d building quota inode\n"), err);
+               struct gfs2_inode *qip = build_quota(sdp);
+               if (qip == NULL) {
+                       log_crit(_("Error building quota inode: %s\n"), 
strerror(errno));
                        exit(FSCK_ERROR);
                }
+               inode_put(&qip);
        }
 
        log_err(_("Master directory rebuilt.\n"));
@@ -911,13 +912,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
                                   "rebuilt.  Aborting.\n"));
                        goto fail;
                }
-               err = build_quota(sdp);
-               if (err) {
-                       log_crit(_("Error %d rebuilding quota inode\n"), err);
+               sdp->md.qinode = build_quota(sdp);
+               if (sdp->md.qinode == NULL) {
+                       log_crit(_("Error rebuilding quota inode: %s\n"), 
strerror(errno));
                        exit(FSCK_ERROR);
                }
-               gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
-               if (!sdp->md.qinode) {
+               lgfs2_dinode_out(sdp->md.qinode, sdp->md.qinode->i_bh->b_data);
+               if (bwrite(sdp->md.qinode->i_bh) != 0) {
                        log_crit(_("Unable to rebuild system quota file "
                                   "inode.  Aborting.\n"));
                        goto fail;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 389cfbe5..ad16971e 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1646,6 +1646,15 @@ static int fsck_build_rindex(struct gfs2_sbd *sdp)
        return 0;
 }
 
+static int fsck_build_quota(struct gfs2_sbd *sdp)
+{
+       struct gfs2_inode *ip = build_quota(sdp);
+       if (ip == NULL)
+               return -1;
+       inode_put(&ip);
+       return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
        int journal_count;
@@ -1696,7 +1705,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
                stack;
                return -1;
        }
-       if (check_system_inode(sdp, &sdp->md.qinode, "quota", build_quota,
+       if (check_system_inode(sdp, &sdp->md.qinode, "quota", fsck_build_quota,
                               0, sdp->master_dir, !sdp->gfs1)) {
                stack;
                return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3c1ec9b2..3396ddb0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -780,7 +780,7 @@ extern struct gfs2_inode *lgfs2_build_jindex(struct 
gfs2_inode *metafs, struct l
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
-extern int build_quota(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
 extern int do_init_statfs(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index eb4bbe01..6cc0a8dd 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -402,7 +402,7 @@ struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp)
        return ip;
 }
 
-int build_quota(struct gfs2_sbd *sdp)
+struct gfs2_inode *build_quota(struct gfs2_sbd *sdp)
 {
        struct gfs2_inode *ip;
        struct gfs2_quota qu;
@@ -410,9 +410,9 @@ int build_quota(struct gfs2_sbd *sdp)
 
        ip = createi(sdp->master_dir, "quota", S_IFREG | 0600,
                     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-       if (ip == NULL) {
-               return errno;
-       }
+       if (ip == NULL)
+               return NULL;
+
        ip->i_payload_format = GFS2_FORMAT_QU;
        bmodified(ip->i_bh);
 
@@ -421,18 +421,12 @@ int build_quota(struct gfs2_sbd *sdp)
 
        count = gfs2_writei(ip, &qu, ip->i_size, sizeof(struct gfs2_quota));
        if (count != sizeof(struct gfs2_quota))
-               return -1;
+               return NULL;
        count = gfs2_writei(ip, &qu, ip->i_size, sizeof(struct gfs2_quota));
        if (count != sizeof(struct gfs2_quota))
-               return -1;
-
-       if (cfg_debug) {
-               printf("\nRoot quota:\n");
-               lgfs2_quota_print(&qu);
-       }
+               return NULL;
 
-       inode_put(&ip);
-       return 0;
+       return ip;
 }
 
 int build_root(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 23d9f1ec..56a3b7d2 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1329,11 +1329,16 @@ int main(int argc, char *argv[])
                printf("%s", _("Creating quota file: "));
                fflush(stdout);
        }
-       error = build_quota(&sbd);
-       if (error) {
+       ip = build_quota(&sbd);
+       if (ip == NULL) {
                fprintf(stderr, _("Error building '%s': %s\n"), "quota", 
strerror(errno));
                exit(EXIT_FAILURE);
        }
+       if (opts.debug) {
+               printf("\nQuota:\n");
+               lgfs2_dinode_print(ip->i_bh->b_data);
+       }
+       inode_put(&ip);
        if (!opts.quiet)
                printf("%s", _("Done\n"));
 
-- 
2.34.1

Reply via email to