[Ocfs2-tools-devel] [PATCH 09/11] ocfs2-tools: Small cleanup for hb device support

Sunil Mushran sunil.mushran at oracle.com
Thu Sep 27 17:14:32 PDT 2007


mkfs, tunefs need a bit of polishing to support the hb device.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh at oracle.com>
---
 libocfs2/checkhb.c       |   14 ++++++++++++--
 libocfs2/include/ocfs2.h |    1 +
 mkfs.ocfs2/mkfs.c        |   24 ++++++++++++++----------
 mounted.ocfs2/mounted.c  |    4 ++++
 tunefs.ocfs2/tunefs.c    |   29 +++++++++++++++++++++--------
 5 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/libocfs2/checkhb.c b/libocfs2/checkhb.c
index c8794f3..8431a65 100644
--- a/libocfs2/checkhb.c
+++ b/libocfs2/checkhb.c
@@ -93,6 +93,7 @@ errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int ignore_local)
 	struct list_head *pos;
 	ocfs2_devices *dev = NULL;
 	char *device= NULL;
+	int open_flags;
 
 	list_for_each(pos, dev_list) {
 		dev = list_entry(pos, ocfs2_devices, list);
@@ -100,15 +101,20 @@ errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int ignore_local)
 
 		/* open	fs */
 		fs = NULL;
-		ret = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
+		open_flags = OCFS2_FLAG_RO | OCFS2_FLAG_HEARTBEAT_DEV_OK;
+		ret = ocfs2_open(device, open_flags, 0, 0, &fs);
 		if (ret) {
 			ret = 0;
 			continue;
 		} else
 			dev->fs_type = 2;
 
+		if (OCFS2_HAS_INCOMPAT_FEATURE(OCFS2_RAW_SB(fs->fs_super),
+					  OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV))
+			dev->hb_dev = 1;
+
 		/* is it locally mounted */
-		if (!ignore_local) {
+		if (!ignore_local || !dev->hb_dev) {
 			ret = ocfs2_check_mount_point(device, &dev->mount_flags,
 						      NULL, 0);
 			if (ret)
@@ -130,6 +136,9 @@ errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int ignore_local)
 		memset(dev->node_nums, OCFS2_MAX_SLOTS,
 		       (sizeof(uint8_t) * dev->max_slots));
 
+		if (dev->hb_dev)
+			goto close;
+
 		/* read slotmap to get nodes on which the volume is mounted */
 		ret = ocfs2_read_slotmap(fs, dev->node_nums);
 		if (ret) {
@@ -139,6 +148,7 @@ errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int ignore_local)
 			if (dev->node_nums[0] != OCFS2_MAX_SLOTS)
 				dev->mount_flags |= OCFS2_MF_MOUNTED_CLUSTER;
 		}
+close:
 		ocfs2_close(fs);
 	}
 
diff --git a/libocfs2/include/ocfs2.h b/libocfs2/include/ocfs2.h
index 610993b..7984f35 100644
--- a/libocfs2/include/ocfs2.h
+++ b/libocfs2/include/ocfs2.h
@@ -240,6 +240,7 @@ struct _ocfs2_devices {
 	uint8_t uuid[16];
 	int mount_flags;
 	int fs_type;			/* 0=unknown, 1=ocfs, 2=ocfs2 */
+	int hb_dev;
 	uint32_t maj_num;		/* major number of the device */
 	uint32_t min_num;		/* minor number of the device */
 	errcode_t errcode;		/* error encountered reading device */
diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index 6b37a39..df910e5 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -443,15 +443,6 @@ main(int argc, char **argv)
 	if (!s->quiet)
 		printf("done\n");
 
-	if (!s->no_backup_super) {
-		if (!s->quiet)
-			printf("Writing backup superblock: ");
-
-		num = format_backup_super(s);
-		if (!s->quiet)
-			printf("%d block(s)\n", num);
-	}
-
 	if (!s->hb_dev) {
 		/* These routines use libocfs2 to do their work. We
 		 * don't share an ocfs2_filesys context between the
@@ -459,6 +450,15 @@ main(int argc, char **argv)
 		 * the library can use the journal for the latter in
 		 * future revisions. */
 
+		if (!s->no_backup_super) {
+			if (!s->quiet)
+				printf("Writing backup superblock: ");
+
+			num = format_backup_super(s);
+			if (!s->quiet)
+				printf("%d block(s)\n", num);
+		}
+
 		if (!s->quiet)
 			printf("Formatting Journals: ");
 
@@ -1144,7 +1144,11 @@ fill_defaults(State *s)
 	printf("nr_cluster_groups = %u\n", s->nr_cluster_groups);
 	printf("tail_group_bits = %u\n", s->tail_group_bits);
 #endif
-	if (!s->initial_slots) {
+
+	if (s->hb_dev)
+		s->initial_slots = 0;
+
+	if (!s->hb_dev && !s->initial_slots) {
 		if (s->mount == MOUNT_LOCAL)
 			s->initial_slots = 1;
 		else
diff --git a/mounted.ocfs2/mounted.c b/mounted.ocfs2/mounted.c
index b169163..270a06c 100644
--- a/mounted.ocfs2/mounted.c
+++ b/mounted.ocfs2/mounted.c
@@ -109,6 +109,10 @@ static void ocfs2_print_full_detect(struct list_head *dev_list)
 			fflush(stdout);
 			com_err("Unknown", dev->errcode, " ");
 		} else {
+			if (dev->hb_dev) {
+				printf("Heartbeat device\n");
+				continue;
+			}
 			if (dev->node_nums[0] == O2NM_MAX_NODES) {
 				printf("Not mounted\n");
 				continue;
diff --git a/tunefs.ocfs2/tunefs.c b/tunefs.ocfs2/tunefs.c
index fbdb9e3..85070f7 100644
--- a/tunefs.ocfs2/tunefs.c
+++ b/tunefs.ocfs2/tunefs.c
@@ -1246,7 +1246,7 @@ int main(int argc, char **argv)
 {
 	errcode_t ret = 0;
 	ocfs2_filesys *fs = NULL;
-	int open_flags = OCFS2_FLAG_RW | OCFS2_FLAG_STRICT_COMPAT_CHECK;
+	int open_flags;
 	int upd_label = 0;
 	int upd_uuid = 0;
 	int upd_slots = 0;
@@ -1270,21 +1270,26 @@ int main(int argc, char **argv)
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
 
+	memset (&opts, 0, sizeof(opts));
+
+	get_options(argc, argv);
+
 	if (signal(SIGTERM, handle_signal) == SIG_ERR) {
-		fprintf(stderr, "Could not set SIGTERM\n");
+		com_err(opts.progname, 0, "Could not set SIGTERM");
 		exit(1);
 	}
 
 	if (signal(SIGINT, handle_signal) == SIG_ERR) {
-		fprintf(stderr, "Could not set SIGINT\n");
+		com_err(opts.progname, 0, "Could not set SIGINT");
 		exit(1);
 	}
 
-	memset (&opts, 0, sizeof(opts));
-
-	get_options(argc, argv);
+	open_flags = OCFS2_FLAG_HEARTBEAT_DEV_OK;
+	if (opts.queryfmt)
+		open_flags |= OCFS2_FLAG_RO;
+	else
+		open_flags |= OCFS2_FLAG_RW | OCFS2_FLAG_STRICT_COMPAT_CHECK;
 
-	/* strict compat flag check */
 	ret = ocfs2_open(opts.device, open_flags, 0, 0, &fs); //O_EXCL?
 	if (ret) {
 		com_err(opts.progname, ret, "while opening device %s",
@@ -1299,8 +1304,16 @@ int main(int argc, char **argv)
 	}
 
 	if (OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat &
+	    OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV) {
+		com_err(opts.progname, 0, "Heartbeat devices cannot be tuned, "
+			"only re-formatted using mkfs.ocfs2");
+		goto close;
+	}
+
+	if (OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat &
 	    OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG) {
-		fprintf(stderr, "Aborted resize detected. Run fsck.ocfs2 -f <device>.\n");
+		com_err(opts.progname, 0, "Aborted resize detected. "
+			"Run fsck.ocfs2 -f <device>.\n");
 		goto close;
 	}
 
-- 
1.5.2.5




More information about the Ocfs2-tools-devel mailing list