From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils
Date: Wed, 12 Jan 2022 19:26:36 +0000 [thread overview]
Message-ID: <20220112192650.1426415-5-anprice@redhat.com> (raw)
In-Reply-To: <20220112192650.1426415-1-anprice@redhat.com>
The trouble with having this function in libgfs2 is that it creates
per_node and everything inside it, which means that it's difficult to
know where an error occurred and we don't have any control over how
debug/error messages are printed. It's also not necessarily the order
that we want to create the inodes in all utilities. Move
build_per_node() down into the utils and add error reporting to match.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/convert/gfs2_convert.c | 36 +++++++++++++++++++++++++++
gfs2/fsck/fsck.h | 1 +
gfs2/fsck/pass1.c | 36 +++++++++++++++++++++++++++
gfs2/libgfs2/libgfs2.h | 1 -
gfs2/libgfs2/structures.c | 36 ---------------------------
gfs2/mkfs/main_mkfs.c | 49 +++++++++++++++++++++++++++++++++----
6 files changed, 117 insertions(+), 42 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 237160af..9a326e7f 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2099,6 +2099,42 @@ static int check_fit(struct gfs2_sbd *sdp)
return blks_avail > blks_need;
}
+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);
+ if (per_node == NULL) {
+ log_crit(_("Error building '%s': %s\n"), "per_node", strerror(errno));
+ return -1;
+ }
+ for (j = 0; j < sdp->md.journals; j++) {
+ err = build_inum_range(per_node, j);
+ if (err) {
+ log_crit(_("Error building '%s': %s\n"), "inum_range",
+ strerror(errno));
+ return err;
+ }
+ err = build_statfs_change(per_node, j);
+ if (err) {
+ log_crit(_("Error building '%s': %s\n"), "statfs_change",
+ strerror(errno));
+ return err;
+ }
+ err = build_quota_change(per_node, j);
+ if (err) {
+ log_crit(_("Error building '%s': %s\n"), "quota_change",
+ strerror(errno));
+ return err;
+ }
+ }
+ inode_put(&per_node);
+ return 0;
+}
+
/* We fetch the old quota inode block and copy the contents of the block
* (minus the struct gfs2_dinode) into the new quota block. We update the
* inode height/size of the new quota file to that of the old one and set the
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index f6c7d1dd..7b991614 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -200,5 +200,6 @@ extern struct special_blocks *blockfind(struct special_blocks *blist, uint64_t n
extern void gfs2_special_set(struct special_blocks *blocklist, uint64_t block);
extern void gfs2_special_free(struct special_blocks *blist);
extern int sb_fixed;
+extern int build_per_node(struct gfs2_sbd *sdp);
#endif /* _FSCK_H */
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index e976149c..38da46a6 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1577,6 +1577,42 @@ static int build_a_journal(struct gfs2_sbd *sdp)
return 0;
}
+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);
+ if (per_node == NULL) {
+ log_err(_("Error building '%s': %s\n"), "per_node", strerror(errno));
+ return -1;
+ }
+ for (j = 0; j < sdp->md.journals; j++) {
+ err = build_inum_range(per_node, j);
+ if (err) {
+ log_err(_("Error building '%s': %s\n"), "inum_range",
+ strerror(errno));
+ return err;
+ }
+ err = build_statfs_change(per_node, j);
+ if (err) {
+ log_err(_("Error building '%s': %s\n"), "statfs_change",
+ strerror(errno));
+ return err;
+ }
+ err = build_quota_change(per_node, j);
+ if (err) {
+ log_err(_("Error building '%s': %s\n"), "quota_change",
+ strerror(errno));
+ return err;
+ }
+ }
+ inode_put(&per_node);
+ return 0;
+}
+
static int check_system_inodes(struct gfs2_sbd *sdp)
{
int journal_count;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 9a66b5b3..863b84e6 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,6 @@ extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
extern int build_journal(struct gfs2_sbd *sdp, int j,
struct gfs2_inode *jindex);
extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
-extern int build_per_node(struct gfs2_sbd *sdp);
extern int build_inum(struct gfs2_sbd *sdp);
extern int build_statfs(struct gfs2_sbd *sdp);
extern int build_rindex(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 09d7041e..c9c31dd2 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -370,42 +370,6 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
return 0;
}
-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);
- if (per_node == NULL) {
- return errno;
- }
-
- for (j = 0; j < sdp->md.journals; j++) {
- err = build_inum_range(per_node, j);
- if (err) {
- return err;
- }
- err = build_statfs_change(per_node, j);
- if (err) {
- return err;
- }
- err = build_quota_change(per_node, j);
- if (err) {
- return err;
- }
- }
-
- if (cfg_debug) {
- printf("\nper_node:\n");
- lgfs2_dinode_print(per_node->i_bh->b_data);
- }
-
- inode_put(&per_node);
- return 0;
-}
-
int build_inum(struct gfs2_sbd *sdp)
{
struct gfs2_inode *ip;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 17284976..9c9c3752 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -681,6 +681,46 @@ static int warn_of_destruction(const char *path)
return 0;
}
+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);
+ if (per_node == NULL) {
+ fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
+ return -1;
+ }
+ for (j = 0; j < sdp->md.journals; j++) {
+ err = build_inum_range(per_node, j);
+ if (err) {
+ fprintf(stderr, _("Error building '%s': %s\n"), "inum_range",
+ strerror(errno));
+ return err;
+ }
+ err = build_statfs_change(per_node, j);
+ if (err) {
+ fprintf(stderr, _("Error building '%s': %s\n"), "statfs_change",
+ strerror(errno));
+ return err;
+ }
+ err = build_quota_change(per_node, j);
+ if (err) {
+ fprintf(stderr, _("Error building '%s': %s\n"), "quota_change",
+ strerror(errno));
+ return err;
+ }
+ }
+ if (opts->debug) {
+ printf("\nper_node:\n");
+ lgfs2_dinode_print(per_node->i_bh->b_data);
+ }
+ inode_put(&per_node);
+ return 0;
+}
+
static int zero_gap(struct gfs2_sbd *sdp, uint64_t addr, size_t blocks)
{
struct iovec *iov;
@@ -1234,11 +1274,10 @@ int main(int argc, char *argv[])
if (error != 0)
exit(1);
- error = build_per_node(&sbd);
- if (error) {
- fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ error = build_per_node(&sbd, &opts);
+ if (error != 0)
+ exit(1);
+
error = build_inum(&sbd);
if (error) {
fprintf(stderr, _("Error building '%s': %s\n"), "inum", strerror(errno));
--
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 ` Andrew Price [this message]
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 ` [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change() Andrew Price
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-5-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).