Skip to contentSkip to conversation

libgfs2: New function lgfs2_rindex_read_one()

PATCH New Andrew Price 1 participant 3 messages Mar 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 libgfs2: New function lgfs2_rindex_read_one()

Add a simple function to read an rindex entry into a set of resource groups.

---
 gfs2/libgfs2/libgfs2.h |  2 ++
 gfs2/libgfs2/rgrp.c    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
gfs2/libgfs2/libgfs2.h +2 -0
index 7c87884..d6c54b3 100644
@@ -177,6 +177,7 @@ struct gfs2_bitmap
 };
 
 struct gfs2_sbd;
+struct gfs2_inode;
 typedef struct _lgfs2_rgrps *lgfs2_rgrps_t;
 
 struct rgrp_tree {
@@ -196,6 +197,7 @@ extern lgfs2_rgrps_t lgfs2_rgrps_init(struct gfs2_sbd *sdp, uint64_t align, uint
 extern void lgfs2_rgrps_free(lgfs2_rgrps_t *rgs);
 extern uint64_t lgfs2_rindex_entry_new(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry, uint64_t addr, uint32_t len);
 extern unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs);
+extern const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip, lgfs2_rgrps_t rgs, unsigned i);
 extern uint64_t lgfs2_rgrp_align_addr(const lgfs2_rgrps_t rgs, uint64_t addr);
 extern uint32_t lgfs2_rgrp_align_len(const lgfs2_rgrps_t rgs, uint32_t len);
 extern unsigned lgfs2_rgsize_for_data(uint64_t blksreq, unsigned bsize);
gfs2/libgfs2/rgrp.c +32 -0
index 766bdfc..7066a5c 100644
@@ -430,6 +430,38 @@ unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs)
 }
 
 /**
+ * Read a rindex entry into a set of resource groups
+ * rip: The inode of the rindex file
+ * rgs: The set of resource groups.
+ * i: The index of the entry to read from the rindex file
+ * Returns the new rindex entry added to the set or NULL on error with errno
+ * set.
+ */
+const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip, lgfs2_rgrps_t rgs, unsigned i)
+{
+	uint64_t off = i * sizeof(struct gfs2_rindex);
+	char buf[sizeof(struct gfs2_rindex)];
+	struct gfs2_rindex ri;
+	lgfs2_rgrp_t rg;
+	int ret;
+
+	errno = EINVAL;
+	if (rip == NULL || rgs == NULL)
+		return NULL;
+
+	ret = gfs2_readi(rip, buf, off, sizeof(struct gfs2_rindex));
+	if (ret != sizeof(struct gfs2_rindex))
+		return NULL;
+
+	gfs2_rindex_in(&ri, buf);
+	rg = lgfs2_rgrps_append(rgs, &ri);
+	if (rg == NULL)
+		return NULL;
+
+	return &rg->ri;
+}
+
+/**
  * Free a set of resource groups created with lgfs2_rgrps_append() etc. This
  * does not write any dirty buffers to disk. See lgfs2_rgrp_write().
  * rgs: A pointer to the set of resource groups to be freed.
Signature · 1 line
2.4.3
#1 lore raw

PATCH 2/3 gfs2-utils tests: Add helper program to damage rgrps

Add a small program named nukerg, based on Bob Peterson's program of the same name, which can be used to scribble over resource groups and rindex entries to test resource group repair in fsck.gfs2.

---
 .gitignore        |   1 +
 tests/Makefile.am |  13 ++
 tests/nukerg.c    | 348 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 362 insertions(+)
 create mode 100644 tests/nukerg.c
.gitignore +1 -0
index bc8236e..b615b87 100644
@@ -47,6 +47,7 @@ gfs2/tune/tunegfs2
 test-driver
 tests/check_meta
 tests/check_rgrp
+tests/nukerg
 tests/testvol
 tests/testsuite.log
 tests/testsuite.dir
tests/Makefile.am +13 -0
index 5a37319..1f98cb4 100644
@@ -11,6 +11,19 @@ DISTCLEANFILES = \
 
 CLEANFILES = testvol
 
+noinst_PROGRAMS = nukerg
+
+nukerg_SOURCES = nukerg.c
+nukerg_CPPFLAGS = \
+	-D_FILE_OFFSET_BITS=64 \
+	-D_LARGEFILE64_SOURCE \
+	-D_GNU_SOURCE
+nukerg_CFLAGS = \
+	-I$(top_srcdir)/gfs2/libgfs2 \
+	-I$(top_srcdir)/gfs2/include
+nukerg_LDADD = \
+	$(top_builddir)/gfs2/libgfs2/libgfs2.la
+
 if HAVE_CHECK
 UNIT_TESTS = \
 	check_meta \
tests/nukerg.c new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
2.4.3
#2 lore raw

PATCH 3/3 gfs2-utils tests: Add fsck.gfs2 rgrp/rindex repair tests

In reply to Andrew Price

Add some tests which exercise fsck.gfs2's resource group and rindex repair code. Two of the tests currently fail (more work to do there) so they're left commented out.

Adds a GFS_NUKERG_CHECK macro to make writing tests like these simpler.

---
 tests/fsck.at      | 20 ++++++++++++++++++++
 tests/testsuite.at | 11 ++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
tests/fsck.at +20 -0
index 4d25f40..5e49985 100644
@@ -14,3 +14,23 @@ AT_SETUP([Fix invalid goal blocks])
 AT_KEYWORDS(fsck.gfs2 fsck)
 GFS_LANG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [set '/' { di_goal_meta: 0 }])
 AT_CLEANUP
+
+AT_SETUP([Fix bad resource group #0])
+AT_KEYWORDS(fsck.gfs2 fsck)
+GFS_NUKERG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [-r 0])
+AT_CLEANUP
+
+#AT_SETUP([Fix bad resource group #1])
+#AT_KEYWORDS(fsck.gfs2 fsck)
+#GFS_NUKERG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [-r 1])
+#AT_CLEANUP
+
+#AT_SETUP([Fix bad rindex entry #0])
+#AT_KEYWORDS(fsck.gfs2 fsck)
+#GFS_NUKERG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [-i 0])
+#AT_CLEANUP
+
+AT_SETUP([Fix bad rindex entry #1])
+AT_KEYWORDS(fsck.gfs2 fsck)
+GFS_NUKERG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [-i 1])
+AT_CLEANUP
tests/testsuite.at +10 -1
index 0422b02..cc1bd54 100644
@@ -12,7 +12,7 @@ AT_CHECK($1, 0, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])])
 
 # Regenerate, mkfs, modify fs with gfs2l, fsck
-# Usage: GFS_TGT_REGEN ([<mkfs.gfs2 command>], [<gfs2l script>])
+# Usage: GFS_LANG_CHECK ([<mkfs.gfs2 command>], [<gfs2l script>])
 m4_define([GFS_LANG_CHECK],
 [GFS_TGT_REGEN
 AT_CHECK($1, 0, [ignore], [ignore])
@@ -20,6 +20,15 @@ AT_CHECK([echo "$2" | gfs2l ${GFS_TGT}], 0, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -y $GFS_TGT], 1, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])])
 
+# Regenerate, mkfs, modify fs with nukerg, fsck
+# Usage: GFS_NUKERG_CHECK ([<mkfs.gfs2 command>], [<gfs2l script>])
+m4_define([GFS_NUKERG_CHECK],
+[GFS_TGT_REGEN
+AT_CHECK($1, 0, [ignore], [ignore])
+AT_CHECK([nukerg $2 $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -y $GFS_TGT], 1, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])])
+
 # Set up a unit test, skipping if unit tests are disabled
 # Usage: GFS_UNIT_TEST ([name], [keywords])
 m4_define([GFS_UNIT_TEST],
Signature · 1 line
2.4.3