[Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex()
Andrew Price
anprice at redhat.com
Wed Jan 12 19:26:34 UTC 2022
Return the inode instead of freeing it and move the debug printfs out of
libgfs2.
Signed-off-by: Andrew Price <anprice at redhat.com>
---
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/structures.c | 23 ++++++++---------------
gfs2/mkfs/main_mkfs.c | 27 ++++++++++++++++++++++-----
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 04e6ec0f..990a9d9e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,7 @@ 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 int build_jindex(struct gfs2_sbd *sdp);
-extern int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb);
+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);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 95ad3ac9..de36c4e3 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -251,39 +251,32 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
* nmemb: The number of entries in the list (number of journals).
* Returns 0 on success or non-zero on error with errno set.
*/
-int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb)
+struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb)
{
char fname[GFS2_FNAMESIZE + 1];
struct gfs2_inode *jindex;
- unsigned j;
- int ret;
if (nmemb == 0 || jnls == NULL) {
errno = EINVAL;
- return 1;
+ return NULL;
}
jindex = createi(master, "jindex", S_IFDIR | 0700, GFS2_DIF_SYSTEM);
if (jindex == NULL)
- return 1;
+ return NULL;
fname[GFS2_FNAMESIZE] = '\0';
- for (j = 0; j < nmemb; j++) {
+ for (unsigned j = 0; j < nmemb; j++) {
+ int ret;
+
snprintf(fname, GFS2_FNAMESIZE, "journal%u", j);
ret = dir_add(jindex, fname, strlen(fname), &jnls[j], IF2DT(S_IFREG | 0600));
if (ret) {
inode_put(&jindex);
- return 1;
+ return NULL;
}
}
-
- if (cfg_debug) {
- printf("\nJindex:\n");
- lgfs2_dinode_print(jindex->i_bh->b_data);
- }
-
- inode_put(&jindex);
- return 0;
+ return jindex;
}
int build_jindex(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index dbee5cab..17284976 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -941,6 +941,24 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, uint64_t *rgaddr
return 0;
}
+static int create_jindex(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_inum *jnls)
+{
+ struct gfs2_inode *jindex;
+
+ jindex = lgfs2_build_jindex(sdp->master_dir, jnls, opts->journals);
+ if (jindex == NULL) {
+ fprintf(stderr, _("Error building '%s': %s\n"), "jindex", strerror(errno));
+ return 1;
+ }
+ if (opts->debug) {
+ printf("Jindex:\n");
+ lgfs2_dinode_print(jindex->i_bh->b_data);
+ }
+ inode_put(&jindex);
+ return 0;
+}
+
+
/*
* Find a reasonable journal file size (in blocks) given the number of blocks
* in the filesystem. For very small filesystems, it is not reasonable to
@@ -1211,12 +1229,11 @@ int main(int argc, char *argv[])
}
sbd.sd_meta_dir = sbd.master_dir->i_num;
- error = lgfs2_build_jindex(sbd.master_dir, mkfs_journals, opts.journals);
- if (error) {
- fprintf(stderr, _("Error building '%s': %s\n"), "jindex", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ error = create_jindex(&sbd, &opts, mkfs_journals);
free(mkfs_journals);
+ if (error != 0)
+ exit(1);
+
error = build_per_node(&sbd);
if (error) {
fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
--
2.34.1
More information about the Cluster-devel
mailing list