Skip to contentSkip to conversation

03/44 libgfs1: Add a centralized gfs1 variable to superblock variables

Cluster-devel Bob Peterson 1 participant 1 message Aug 25, 2011

lore
Share & tools
lore
#0 lore raw

From 9b808af98b25a97cdfa71afc0066565d7c74e758 Mon Sep 17 00:00:00 2001
From: Bob Peterson <[email protected]>
Date: Mon, 8 Aug 2011 09:45:36 -0500
Subject: [PATCH 03/56] libgfs1: Add gfs1 variable to superblock structure

This patch adds a "gfs1" variable to the in-core superblock structure for utils that can operate on both gfs and gfs2 file systems and need to determine which is which.

rhbz#675723

---
 gfs2/edit/extended.c   |   10 ++--
 gfs2/edit/gfs2hex.c    |   13 +++---
 gfs2/edit/hexedit.c    |  111 ++++++++++++++++++++++++------------------------
 gfs2/edit/hexedit.h    |    3 +-
 gfs2/edit/savemeta.c   |   30 ++++++------
 gfs2/libgfs2/libgfs2.h |    1 +
 6 files changed, 84 insertions(+), 84 deletions(-)
gfs2/edit/extended.c +5 -5
index 3cf6f8b..575c387 100644
@@ -66,7 +66,7 @@ static int _do_indirect_extended(char *diebuf, struct iinfo *iinf, int hgt)
 		iinf->ii[x].dirents = 0;
 		memset(&iinf->ii[x].dirent, 0, sizeof(struct gfs2_dirents));
 	}
-	for (x = (gfs1 ? sizeof(struct gfs_indirect):
+	for (x = (sbd.gfs1 ? sizeof(struct gfs_indirect):
 			  sizeof(struct gfs2_meta_header)), y = 0;
 		 x < sbd.bsize;
 		 x += sizeof(uint64_t), y++) {
@@ -251,7 +251,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level,
 /* ------------------------------------------------------------------------ */
 static void print_inode_type(__be16 de_type)
 {
-	if (gfs1) {
+	if (sbd.gfs1) {
 		switch(de_type) {
 		case GFS_FILE_NON:
 			print_gfs2("Unknown");
@@ -515,7 +515,7 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
 
 		roff = print_entry_ndx * risize();
 
-		if (gfs1)
+		if (sbd.gfs1)
 			error = gfs1_readi(dip, (void *)&rbuf, roff, risize());
 		else
 			error = gfs2_readi(dip, (void *)&rbuf, roff, risize());
@@ -543,7 +543,7 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
 				struct gfs2_buffer_head *tmp_bh;
 
 				tmp_bh = bread(&sbd, ri.ri_addr);
-				if (gfs1) {
+				if (sbd.gfs1) {
 					struct gfs_rgrp rg1;
 					gfs_rgrp_in(&rg1, tmp_bh);
 					gfs_rgrp_print(&rg1);
@@ -664,7 +664,7 @@ int display_extended(void)
 	else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0)
 		return -1;
 	else if (block_is_rglist()) {
-		if (gfs1)
+		if (sbd.gfs1)
 			tmp_bh = bread(&sbd, sbd1->sb_rindex_di.no_addr);
 		else
 			tmp_bh = bread(&sbd, masterblock("rindex"));
gfs2/edit/gfs2hex.c +6 -7
index 8dbd7e5..40959c7 100644
@@ -45,7 +45,6 @@ uint64_t block = 0;
 int blockhist = 0;
 struct iinfo *indirect;
 int indirect_blocks;
-int gfs1  = 0;
 uint64_t block_in_mem = -1;
 struct gfs2_sbd sbd;
 uint64_t starting_blk;
@@ -277,7 +276,7 @@ void do_dinode_extended(struct gfs2_dinode *dine, struct gfs2_buffer_head *lbh)
 	unsigned int x, y, ptroff = 0;
 	uint64_t p, last;
 	int isdir = !!(S_ISDIR(dine->di_mode)) || 
-		(gfs1 && dine->__pad1 == GFS_FILE_DIR);
+		(sbd.gfs1 && dine->__pad1 == GFS_FILE_DIR);
 
 	indirect_blocks = 0;
 	memset(indirect, 0, sizeof(indirect));
@@ -468,11 +467,11 @@ static void gfs2_sb_print2(struct gfs2_sb *sbp2)
 	pv(sbp2, sb_fs_format, "%u", "0x%x");
 	pv(sbp2, sb_multihost_format, "%u", "0x%x");
 
-	if (gfs1)
+	if (sbd.gfs1)
 		pv(sbd1, sb_flags, "%u", "0x%x");
 	pv(sbp2, sb_bsize, "%u", "0x%x");
 	pv(sbp2, sb_bsize_shift, "%u", "0x%x");
-	if (gfs1) {
+	if (sbd.gfs1) {
 		pv(sbd1, sb_seg_size, "%u", "0x%x");
 		gfs2_inum_print2("jindex ino", &sbd1->sb_jindex_di);
 		gfs2_inum_print2("rindex ino", &sbd1->sb_rindex_di);
@@ -483,7 +482,7 @@ static void gfs2_sb_print2(struct gfs2_sb *sbp2)
 
 	pv(sbp2, sb_lockproto, "%s", NULL);
 	pv(sbp2, sb_locktable, "%s", NULL);
-	if (gfs1) {
+	if (sbd.gfs1) {
 		gfs2_inum_print2("quota ino ", &gfs1_quota_di);
 		gfs2_inum_print2("license   ", &gfs1_license_di);
 	}
@@ -575,7 +574,7 @@ int display_gfs2(void)
 			break;
 
 		case GFS2_METATYPE_RG:
-			if (gfs1) {
+			if (sbd.gfs1) {
 				struct gfs1_rgrp rg1;
 
 				gfs1_rgrp_in(&rg1, bh);
@@ -608,7 +607,7 @@ int display_gfs2(void)
 			break;
 
 		case GFS2_METATYPE_LH:
-			if (gfs1) {
+			if (sbd.gfs1) {
 				gfs_log_header_in(&lh1, bh);
 				gfs_log_header_print(&lh1);
 			} else {
gfs2/edit/hexedit.c +56 -55

381 lines not on this page · raw message

gfs2/edit/hexedit.h +1 -2
index cc87925..8a3c615 100644
@@ -81,7 +81,6 @@ extern char device[NAME_MAX];
 extern int identify;
 extern int color_scheme;
 extern WINDOW *wind;
-extern int gfs1;
 extern int editing;
 extern uint64_t temp_blk;
 extern uint64_t starting_blk;
@@ -231,7 +230,7 @@ extern enum dsp_mode dmode;
 /* ------------------------------------------------------------------------ */
 static inline int risize(void)
 {
-	if (gfs1)
+	if (sbd.gfs1)
 		return sizeof(struct gfs_rindex);
 	else
 		return sizeof(struct gfs2_rindex);
gfs2/edit/savemeta.c +15 -15
index 0c567da..e8bcf8f 100644
@@ -122,12 +122,12 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
 		*gstruct_len = sbd.bsize;
 		break;
 	case GFS2_METATYPE_DI:   /* 4 (disk inode) */
-		if (gfs1)
+		if (sbd.gfs1)
 			inode = inode_get(&sbd, lbh);
 		else
 			inode = gfs_inode_get(&sbd, lbh);
 		if (S_ISDIR(inode->i_di.di_mode) ||
-		     (gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
+		     (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
 			*gstruct_len = sbd.bsize;
 		else if (!inode->i_di.di_height && !block_is_systemfile() &&
 			 !S_ISDIR(inode->i_di.di_mode))
@@ -145,7 +145,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
 		*gstruct_len = sbd.bsize;
 		break;
 	case GFS2_METATYPE_LH:   /* 8 (log header) */
-		if (gfs1)
+		if (sbd.gfs1)
 			*gstruct_len = 512; /* gfs copies the log header
 					       twice and compares the copy,
 					       so we need to save all 512
@@ -456,7 +456,7 @@ static void save_inode_data(struct metafd *mfd)
 	for (i = 0; i < GFS2_MAX_META_HEIGHT; i++)
 		osi_list_init(&metalist[i]);
 	metabh = bread(&sbd, block);
-	if (gfs1)
+	if (sbd.gfs1)
 		inode = inode_get(&sbd, metabh);
 	else
 		inode = gfs_inode_get(&sbd, metabh);
@@ -468,7 +468,7 @@ static void save_inode_data(struct metafd *mfd)
 	   the hash table exists, and we have to save the directory data. */
 	if (inode->i_di.di_flags & GFS2_DIF_EXHASH &&
 	    (S_ISDIR(inode->i_di.di_mode) ||
-	     (gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR)))
+	     (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR)))
 		height++;
 	else if (height && !(inode->i_di.di_flags & GFS2_DIF_SYSTEM) &&
 		 !block_is_systemfile() && !S_ISDIR(inode->i_di.di_mode))
@@ -565,7 +565,7 @@ static void get_journal_inode_blocks(void)
 		int amt;
 		struct gfs2_inode *j_inode = NULL;
 
-		if (gfs1) {
+		if (sbd.gfs1) {
 			struct gfs_jindex ji;
 			char jbuf[sizeof(struct gfs_jindex)];
 
@@ -649,7 +649,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 
 	lseek(sbd.device_fd, 0, SEEK_SET);
 	blks_saved = total_out = last_reported_block = 0;
-	if (!gfs1)
+	if (!sbd.gfs1)
 		sbd.bsize = BUFSIZE;
 	if (!slow) {
 		if (device_geometry(&sbd)) {
@@ -662,13 +662,13 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 			exit(-1);
 		}
 		osi_list_init(&sbd.rglist);
-		if (!gfs1)
+		if (!sbd.gfs1)
 			sbd.sd_sb.sb_bsize = GFS2_DEFAULT_BSIZE;
 		if (compute_constants(&sbd)) {
 			fprintf(stderr, "Bad constants (1)\n");
 			exit(-1);
 		}
-		if(gfs1) {
+		if(sbd.gfs1) {
 			sbd.bsize = sbd.sd_sb.sb_bsize;
 			sbd.sd_inptrs = (sbd.bsize -
 					 sizeof(struct gfs_indirect)) /
@@ -693,7 +693,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 	printf("There are %llu blocks of %u bytes in the destination "
 	       "device.\n", (unsigned long long)last_fs_block, sbd.bsize);
 	if (!slow) {
-		if (gfs1) {
+		if (sbd.gfs1) {
 			sbd.md.riinode = inode_read(&sbd,
 						sbd1->sb_rindex_di.no_addr);
 			jindex_block = sbd1->sb_jindex_di.no_addr;
@@ -708,7 +708,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 		}
 		lbh = bread(&sbd, jindex_block);
 		gfs2_dinode_in(&di, lbh);
-		if (!gfs1)
+		if (!sbd.gfs1)
 			do_dinode_extended(&di, lbh);
 		brelse(lbh);
 	}
@@ -718,7 +718,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 
 		printf("Reading resource groups...");
 		fflush(stdout);
-		if (gfs1)
+		if (sbd.gfs1)
 			slow = gfs1_ri_update(&sbd, 0, &rgcount, 0);
 		else
 			slow = ri_update(&sbd, 0, &rgcount, &sane);
@@ -740,7 +740,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 		save_block(sbd.device_fd, &mfd, 0x10 * (4096 / sbd.bsize));
 		/* If this is gfs1, save off the rindex because it's not
 		   part of the file system as it is in gfs2. */
-		if (gfs1) {
+		if (sbd.gfs1) {
 			int j;
 
 			block = sbd1->sb_rindex_di.no_addr;
@@ -922,7 +922,7 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,
 			    sbd1->sb_header.mh_type == GFS_METATYPE_SB &&
 			    sbd1->sb_header.mh_format == GFS_FORMAT_SB &&
 			    sbd1->sb_multihost_format == GFS_FORMAT_MULTI) {
-				gfs1 = TRUE;
+				sbd.gfs1 = TRUE;
 			} else if (check_sb(&sbd.sd_sb)) {
 				fprintf(stderr,"Error: Invalid superblock data.\n");
 				return -1;
@@ -937,7 +937,7 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,
 				       "the destination device.\n\n",
 				       (unsigned long long)last_fs_block, sbd.bsize);
 			} else {
-				printf("This is %s metadata\n", gfs1 ?
+				printf("This is %s metadata\n", sbd.gfs1 ?
 				       "gfs (not gfs2)" : "gfs2");
 			}
 			first = 0;
gfs2/libgfs2/libgfs2.h +1 -0
index 73431fa..5f66312 100644
@@ -243,6 +243,7 @@ struct gfs2_sbd {
 	uint32_t physical_block_size;
 	uint64_t rg_one_length;
 	uint64_t rg_length;
+	int gfs1;
 };
 
 struct metapath {
Signature · 1 line
1.7.4.4