From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change()
Date: Wed, 12 Jan 2022 19:26:39 +0000 [thread overview]
Message-ID: <20220112192650.1426415-8-anprice@redhat.com> (raw)
In-Reply-To: <20220112192650.1426415-1-anprice@redhat.com>
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 <anprice@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 | 18 +++++-------------
gfs2/mkfs/main_mkfs.c | 12 ++++++++----
6 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1cb2d6fa..0953d2a7 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2103,7 +2103,6 @@ static int build_per_node(struct gfs2_sbd *sdp)
{
struct gfs2_inode *per_node;
unsigned int j;
- int err;
per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
GFS2_DIF_SYSTEM);
@@ -2130,12 +2129,13 @@ static int build_per_node(struct gfs2_sbd *sdp)
}
inode_put(&ip);
- err = build_quota_change(per_node, j);
- if (err) {
+ ip = build_quota_change(per_node, j);
+ if (ip == NULL) {
log_crit(_("Error building '%s': %s\n"), "quota_change",
strerror(errno));
- return err;
+ return 1;
}
+ inode_put(&ip);
}
inode_put(&per_node);
return 0;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 3df64de7..a016f2a4 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1581,7 +1581,6 @@ int build_per_node(struct gfs2_sbd *sdp)
{
struct gfs2_inode *per_node;
unsigned int j;
- int err;
per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
GFS2_DIF_SYSTEM);
@@ -1608,12 +1607,13 @@ int build_per_node(struct gfs2_sbd *sdp)
}
inode_put(&ip);
- err = build_quota_change(per_node, j);
- if (err) {
+ ip = build_quota_change(per_node, j);
+ if (ip == NULL) {
log_err(_("Error building '%s': %s\n"), "quota_change",
strerror(errno));
- return err;
+ return 1;
}
+ inode_put(&ip);
}
inode_put(&per_node);
return 0;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2e0c1bb7..d82380a1 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1895,6 +1895,16 @@ static int fsck_build_statfs_change(struct gfs2_inode *per_node, unsigned int n)
return 0;
}
+static int fsck_build_quota_change(struct gfs2_inode *per_node, unsigned int n)
+{
+ struct gfs2_inode *ip = build_quota_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,
@@ -1986,7 +1996,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
sprintf(fn, "quota_change%d", j);
error += check_pernode_for(j, sysinode, fn, 1048576, 1,
"a_change_fxns,
- build_quota_change);
+ fsck_build_quota_change);
}
}
return error;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 0c702df0..a928e1ab 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -789,7 +789,7 @@ 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 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);
+extern struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, unsigned int j);
/* super.c */
extern int check_sb(void *sbp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index bd226e6d..1d4635ab 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -313,7 +313,7 @@ struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned int
return ip;
}
-int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, unsigned int j)
{
struct gfs2_sbd *sdp = per_node->i_sbd;
struct gfs2_meta_header mh;
@@ -331,9 +331,8 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
sprintf(name, "quota_change%u", j);
ip = createi(per_node, name, S_IFREG | 0600, GFS2_DIF_SYSTEM);
- if (ip == NULL) {
- return errno;
- }
+ if (ip == NULL)
+ return NULL;
hgt = calc_tree_height(ip, (blocks + 1) * sdp->sd_bsize);
build_height(ip, hgt);
@@ -341,21 +340,14 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
for (x = 0; x < blocks; x++) {
bh = get_file_buf(ip, x, 0);
if (!bh)
- return -1;
+ return NULL;
memset(bh->b_data, 0, sdp->sd_bsize);
memcpy(bh->b_data, &mh, sizeof(mh));
bmodified(bh);
brelse(bh);
}
-
- if (cfg_debug) {
- printf("\nQuota Change %u:\n", j);
- lgfs2_dinode_print(ip->i_bh->b_data);
- }
-
- inode_put(&ip);
- return 0;
+ return ip;
}
int build_inum(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e0f42c5a..c4415ee3 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -685,7 +685,6 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
{
struct gfs2_inode *per_node;
unsigned int j;
- int err;
per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
GFS2_DIF_SYSTEM);
@@ -720,12 +719,17 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
}
inode_put(&ip);
- err = build_quota_change(per_node, j);
- if (err) {
+ ip = build_quota_change(per_node, j);
+ if (ip == NULL) {
fprintf(stderr, _("Error building '%s': %s\n"), "quota_change",
strerror(errno));
- return err;
+ return 1;
+ }
+ if (opts->debug) {
+ printf("\nQuota Change %u:\n", j);
+ lgfs2_dinode_print(ip->i_bh->b_data);
}
+ inode_put(&ip);
}
if (opts->debug) {
printf("\nper_node:\n");
--
2.34.1
next prev parent reply other threads:[~2022-01-12 19:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change() Andrew Price
2022-01-12 19:26 ` Andrew Price [this message]
2022-01-12 19:26 ` [Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch] Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement Andrew Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220112192650.1426415-8-anprice@redhat.com \
--to=anprice@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).