[Cluster-devel] [PATCH 18/19] libgfs2: Create jindex directory separately from journals

Andrew Price anprice at redhat.com
Tue Sep 2 12:07:35 UTC 2014


Previously journals were created indirectly via build_jindex and the
jindex inode (and therefore the master inode) was created before the
journals. Now that we're allocating the journals in whole resource
groups at the start of the mkfs process we need a way to create the
jindex after the journals are created. This adds lgfs2_build_jindex
which takes a list of inums relating to journals and builds the jindex
from them.

The old build_jindex function is left in place until the other tools
have been switched to use the new function.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/libgfs2/libgfs2.h    |  1 +
 gfs2/libgfs2/structures.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 406fbbe..831d45b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -729,6 +729,7 @@ extern int lgfs2_sb_write(const struct gfs2_sb *sb, int fd, const unsigned bsize
 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 gfs2_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 c4b9ebc..87ffde7 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -255,6 +255,46 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
 	return ret;
 }
 
+/**
+ * Write a jindex file given a list of journal inums.
+ * master: Inode of the master directory
+ * jnls: List of inum structures relating to previously created journals.
+ * 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 gfs2_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;
+	}
+	jindex = createi(master, "jindex", S_IFDIR | 0700, GFS2_DIF_SYSTEM);
+	if (jindex == NULL)
+		return 1;
+
+	fname[GFS2_FNAMESIZE] = '\0';
+
+	for (j = 0; j < nmemb; j++) {
+		snprintf(fname, GFS2_FNAMESIZE, "journal%u", j);
+		ret = dir_add(jindex, fname, strlen(fname), &jnls[j], IF2DT(S_IFREG | 0600));
+		if (ret)
+			return 1;
+	}
+
+	if (cfg_debug) {
+		printf("\nJindex:\n");
+		gfs2_dinode_print(&jindex->i_di);
+	}
+
+	inode_put(&jindex);
+	return 0;
+}
+
 int build_jindex(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *jindex;
-- 
1.9.3




More information about the Cluster-devel mailing list