[Ocfs2-tools-commits] smushran commits r247 - in trunk: libocfs2 libocfs2/include mkfs.ocfs2 mounted.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Sep 21 18:06:19 CDT 2004


Author: smushran
Date: 2004-09-21 18:06:17 -0500 (Tue, 21 Sep 2004)
New Revision: 247

Modified:
   trunk/libocfs2/checkhb.c
   trunk/libocfs2/include/kernel-list.h
   trunk/libocfs2/include/ocfs1_fs_compat.h
   trunk/libocfs2/include/ocfs2.h
   trunk/mkfs.ocfs2/Cscope.make
   trunk/mounted.ocfs2/mounted.c
Log:
checkheartbeat does parallel mount detect

Modified: trunk/libocfs2/checkhb.c
===================================================================
--- trunk/libocfs2/checkhb.c	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/libocfs2/checkhb.c	2004-09-21 23:06:17 UTC (rev 247)
@@ -40,9 +40,37 @@
 #include "ocfs2_disk_dlm.h"
 #include "ocfs1_fs_compat.h"
 
+
+typedef struct _ocfs2_fs {
+	ocfs2_filesys *fs;
+	char *dev_name;
+	uint64_t dlm_blkno;
+	uint64_t *pub_times;
+	int *live_node;
+	struct list_head list;
+} ocfs2_fs;
+
+
+void ocfs2_detect_live_nodes (ocfs2_fs *fs_blk, char *pub_buf, int first_time);
+
+errcode_t ocfs2_gather_times_v2(ocfs2_fs *fs_blk, struct list_head *node_list,
+				int first_time);
+
+errcode_t ocfs2_gather_times_v1(ocfs2_fs *fs_blk, struct list_head *node_list,
+			       	int first_time);
+
 /*
  * ocfs2_check_heartbeat() check if the device is mounted on the
  * cluster or not
+ * 
+ *  notify ==>
+ *      Called for every step of progress (because this takes a few
+ *      seconds).  Can be NULL.  States are:
+ *              OCFS2_CHB_START
+ *              OCFS2_CHB_WAITING  (N times)
+ *              OCFS2_CHB_COMPLETE
+ *  user_data ==>
+ *      User data pointer for the notify function.
  *
  * Return:
  *  mounted_flags set to ==>
@@ -51,127 +79,220 @@
  * 	OCFS2_MF_READONLY
  * 	OCFS2_MF_SWAP
  * 	OCFS2_MF_MOUNTED_CLUSTER	if mounted on cluster
- *  node_names set to ==>
- *  	Slots of live nodes set to name
- *  notify ==>
- *      Called for every step of progress (because this takes a few
- *      seconds).  Can be NULL.  States are:
- *              OCFS2_CHB_START
- *              OCFS2_CHB_WAITING  (N times)
- *              OCFS2_CHB_COMPLETE
- *  user_data ==>
- *      User data pointer for the notify function.
+ *  nodes_list set to ==>
+ *  	List of live nodes
+ *
  */
-errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
-                                char **node_names,
-                                ocfs2_chb_notify notify,
-                                void *user_data)
+errcode_t ocfs2_check_heartbeat(char *device, int quick_detect,
+				int *mount_flags, struct list_head *nodes_list,
+                                ocfs2_chb_notify notify, void *user_data)
 {
-	ocfs2_filesys *fs = NULL;
-	char *buf = NULL;
-	int buflen = 0;
-	__u64 pub_times[OCFS2_NODE_MAP_MAX_NODES];
-	int node_stats[OCFS2_NODE_MAP_MAX_NODES];
-	char *p;
-	errcode_t ret;
-	int64_t blkno, blksize;
-	uint16_t num_nodes;
-	uint32_t blksz_bits;
-	uint64_t dlm_blkno;
-	int i;
-	int wait_time;
-	char *dlm = ocfs2_system_inode_names[DLM_SYSTEM_INODE];
+	errcode_t ret = 0;
+	struct list_head dev_list;
+	struct list_head *pos1, *pos2, *pos3, *pos4;
+	ocfs2_devices *dev;
+	ocfs2_nodes *node;
 
-	memset(&fs, 0, sizeof(ocfs2_filesys));
-	memset(pub_times, 0, (sizeof(__u64) * OCFS2_NODE_MAP_MAX_NODES));
-	memset(node_stats, 0, (sizeof(int) * OCFS2_NODE_MAP_MAX_NODES));
+	INIT_LIST_HEAD(&dev_list);
 
-	/* is it locally mounted */
-	*mount_flags = 0;
-	ret = ocfs2_check_mount_point(device, mount_flags, NULL, 0);
-	if (ret)
+	if (!device)
 		goto bail;
 
-	/* open	fs */
-	blksize = 0;
-	blkno = 0;
-	ret = ocfs2_open(device, OCFS2_FLAG_RO, blkno, blksize, &fs);
+	ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
 	if (ret)
 		goto bail;
+	strncpy(dev->dev_name, device, sizeof(dev->dev_name));
+	dev->mount_flags = 0;
+	INIT_LIST_HEAD(&(dev->node_list));
+	list_add(&(dev->list), &dev_list);
 
-	blksize = fs->fs_blocksize;
-	num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
-	blksz_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
-
-	/* get the dlm blkno */
-	ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, dlm, strlen(dlm),
-			   NULL, &dlm_blkno);
+	ret = ocfs2_check_heartbeats(&dev_list, quick_detect, notify, user_data);
 	if (ret)
 		goto bail;
 
-	/* read dlm file */
-	ret = ocfs2_read_whole_file(fs, dlm_blkno, &buf, &buflen);
-	if (ret)
-		goto bail;
+	list_for_each_safe(pos1, pos2, &(dev_list)) {
+		dev = list_entry(pos1, ocfs2_devices, list);
+		*mount_flags = dev->mount_flags;
+		list_for_each_safe(pos3, pos4, &(dev->node_list)) {
+			node = list_entry(pos3, ocfs2_nodes, list);
+			if (nodes_list) {
+				list_add_tail(&node->list, nodes_list);
+			} else {
+				list_del(&(node->list));
+				ocfs2_free(&node);
+			}
+		}
+		list_del(&(dev->list));
+		ocfs2_free(&dev);
+		break;
+	}
 
-	/* init publish times */
-	p = buf + ((2 + 4 + num_nodes) << blksz_bits); /* start of publish */
-	ocfs2_detect_live_nodes (fs, p, pub_times, node_stats, 1);
+bail:
+	if (ret) {
+		list_for_each_safe(pos1, pos2, &(dev_list)) {
+			dev = list_entry(pos1, ocfs2_devices, list);
+			list_for_each_safe(pos3, pos4, &(dev->node_list)) {
+				node = list_entry(pos3, ocfs2_nodes, list);
+				list_del(&(node->list));
+				ocfs2_free(&node);
+			}
+			list_del(&(dev->list));
+			ocfs2_free(&dev);
+		}
+	}
+	return ret;
+}
 
-	if (buflen && buf) {
-		ocfs2_free (&buf);
-		buflen = 0;
+/*
+ * ocfs2_check_heartbeats()
+ *
+ */
+errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int quick_detect,
+				 ocfs2_chb_notify notify, void *user_data)
+{
+	ocfs2_filesys *fs = NULL;
+	errcode_t ret = 0;
+	uint16_t num_nodes;
+	int i;
+	struct list_head *pos;
+	ocfs2_devices *dev = NULL;
+	char *device= NULL;
+	ocfs2_fs *fs_blk = NULL;
+	int any_ocfs = 0;
+
+	if (notify && !quick_detect)
+		notify(OCFS2_CHB_START, "Checking heart beat on volume ", user_data);
+
+	list_for_each(pos, dev_list) {
+		dev = list_entry(pos, ocfs2_devices, list);
+		device = dev->dev_name;
+
+		INIT_LIST_HEAD(&(dev->node_list));
+
+		/* is it locally mounted */
+		ret = ocfs2_check_mount_point(device, &dev->mount_flags, NULL, 0);
+		if (ret)
+			goto bail;
+
+		/* open	fs */
+		fs = NULL;
+		ret = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
+		if (ret) {
+			if (ret == OCFS2_ET_OCFS_REV)
+				dev->fs_type = 1;
+			else
+				continue;
+		} else
+			dev->fs_type = 2;
+
+		ret = 0;
+
+		/* get label/uuid for ocfs and ocfs2 */
+		if (dev->fs_type == 2) {
+			num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
+			memcpy(dev->label, OCFS2_RAW_SB(fs->fs_super)->s_label,
+			       sizeof(dev->label));
+			memcpy(dev->uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
+			       sizeof(dev->uuid));
+		} else {
+			num_nodes = 32;
+			if (ocfs2_get_ocfs1_label(dev->dev_name,
+					dev->label, sizeof(dev->label),
+					dev->uuid, sizeof(dev->uuid))) {
+				dev->label[0] = '\0';
+				memset(dev->uuid, 0, sizeof(dev->uuid));
+			}
+		}
+
+		if (!quick_detect) {
+			ret = ocfs2_malloc0(sizeof(ocfs2_fs), &fs_blk);
+			if (ret)
+				goto bail;
+
+			ret = ocfs2_malloc0((num_nodes * sizeof(uint64_t)), &fs_blk->pub_times);
+			if (ret)
+				goto bail;
+
+			ret = ocfs2_malloc0((num_nodes * sizeof(int)), &fs_blk->live_node);
+			if (ret)
+				goto bail;
+
+			fs_blk->fs = fs;
+			fs_blk->dev_name = dev->dev_name;
+
+			dev->private = (void *)fs_blk;
+
+			if (dev->fs_type == 2)
+				ret = ocfs2_gather_times_v2(fs_blk, NULL, 1);
+			else
+				ret = ocfs2_gather_times_v1(fs_blk, NULL, 1);
+			if (ret)
+				goto bail;
+		}
+
+		any_ocfs = 1;
 	}
 
-	if (notify)
-		notify(OCFS2_CHB_START,
-		       "Checking heart beat on volume ",
-		       user_data);
+	if (quick_detect)
+		goto bail;
 
+	if (!any_ocfs)
+		goto bail;
+
 	/* wait */
-	wait_time = 1;
-	wait_time = (wait_time ? wait_time : 1);
 	for (i = 0; i < OCFS2_HBT_WAIT; ++i) {
 		if (notify)
 			notify(OCFS2_CHB_WAITING, ".", user_data);
-		sleep(wait_time);
+		sleep(1);
 	}
 
+	list_for_each(pos, dev_list) {
+		dev = list_entry(pos, ocfs2_devices, list);
+
+		if (dev->fs_type < 1)
+			continue;
+
+		fs_blk = (ocfs2_fs *) dev->private;
+		fs = fs_blk->fs;
+
+		if (dev->fs_type == 2) {
+			num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
+			ret = ocfs2_gather_times_v2(fs_blk, &dev->node_list, 0);
+		} else {
+			num_nodes = 32;
+			ret = ocfs2_gather_times_v1(fs_blk, &dev->node_list, 0);
+		}
+		if (ret)
+			goto bail;
+
+		/* fill mount_flags */
+		for (i = 0; i < num_nodes; ++i) {
+			if (fs_blk->live_node[i]) {
+				dev->mount_flags |= OCFS2_MF_MOUNTED_CLUSTER;
+				break;
+			}
+		}
+	}
+
 	if (notify)
 		notify(OCFS2_CHB_COMPLETE,
 		       "\r                                                \r",
 		       user_data);
-  
-	/* read dlm file again */
-	ret = ocfs2_read_whole_file(fs, dlm_blkno, &buf, &buflen);
-	if (ret)
-		goto bail;
 
-	/* detect live nodes */
-	p = buf + ((2 + 4 + num_nodes) << blksz_bits); /* start of publish */
-	ocfs2_detect_live_nodes (fs, p, pub_times, node_stats, 0);
-
-	/* fill mount_flags */
-	for (i = 0; i < num_nodes; ++i) {
-		if (node_stats[i]) {
-			*mount_flags |= OCFS2_MF_MOUNTED_CLUSTER;
-			break;
+bail:
+	list_for_each(pos, dev_list) {
+		dev = list_entry(pos, ocfs2_devices, list);
+		if (dev->private) {
+			fs_blk = (ocfs2_fs *) dev->private;
+			if (fs_blk->fs)
+				ocfs2_close(fs_blk->fs);
+			ocfs2_free(&fs_blk->pub_times);
+			ocfs2_free(&fs_blk->live_node);
+			ocfs2_free(&fs_blk);
+			dev->private = NULL;
 		}
 	}
 
-	/* fill node_names */
-	if (node_names) {
-		p = buf + (2 << blksz_bits);	/* start of node cfg */
-		ocfs2_live_node_names(fs, p, node_stats, node_names);
-	}
-
-bail:
-	if (fs)
-		ocfs2_close(fs);
-
-	if (buflen && buf)
-		ocfs2_free (&buf);
-
 	return ret;
 }
 
@@ -179,15 +300,23 @@
  * ocfs2_detect_live_nodes()
  *
  */
-void ocfs2_detect_live_nodes (ocfs2_filesys *fs, char *pub_buf, uint64_t *pub_times,
-			      int *node_stats, int first_time)
+void ocfs2_detect_live_nodes (ocfs2_fs *fs_blk, char *pub_buf, int first_time)
 {
 	char *p;
 	ocfs_publish *publish;
 	int i;
-	uint16_t num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
-	uint32_t blksz_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+	uint16_t num_nodes;
+	uint32_t blksz_bits;
+	uint64_t *pub_times = fs_blk->pub_times;
+	int *live_node = fs_blk->live_node;
 
+	if (fs_blk->fs) {
+		num_nodes = OCFS2_RAW_SB(fs_blk->fs->fs_super)->s_max_nodes;
+		blksz_bits = OCFS2_RAW_SB(fs_blk->fs->fs_super)->s_blocksize_bits;
+	} else {
+		num_nodes = 32;
+		blksz_bits = 9;
+	}
 
 	if (first_time) {
 		p = (char *)pub_buf;
@@ -204,7 +333,7 @@
 		publish = (ocfs_publish *) p;
 		if (pub_times[i] != publish->time) {
 			pub_times[i] = publish->time;
-			node_stats[i] = 1;
+			live_node[i] = 1;
 		}
 		p += (1 << blksz_bits);
 	}
@@ -214,26 +343,162 @@
 }
 
 /*
- * ocfs2_live_node_names()
+ * ocfs2_gather_times_v2()
  *
  */
-void ocfs2_live_node_names(ocfs2_filesys *fs, char *node_buf, int *node_stats,
-			   char **node_names)
+errcode_t ocfs2_gather_times_v2(ocfs2_fs *fs_blk, struct list_head *node_list,
+			       	int first_time)
 {
+	ocfs2_filesys *fs = fs_blk->fs;
+	char *dlm = ocfs2_system_inode_names[DLM_SYSTEM_INODE];
+	char *buf = NULL;
+	int buflen = 0;
+	errcode_t ret = 0;
 	char *p;
-	int i;
-	ocfs_node_config_info *node;
 	uint16_t num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
 	uint32_t blksz_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+	ocfs_node_config_info *node;
+	ocfs2_nodes *node_blk;
+	int i;
 
-	p = node_buf;
-	for (i = 0; i < num_nodes; ++i) {
-		if (node_stats[i]) {
-			node = (ocfs_node_config_info *)p;
-			node_names[i] = strdup(node->node_name);
+	/* get the dlm blkno */
+	if (!fs_blk->dlm_blkno) {
+		ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, dlm, strlen(dlm),
+				   NULL, &(fs_blk->dlm_blkno));
+		if (ret)
+			goto bail;
+	}
+
+	/* read dlm file */
+	ret = ocfs2_read_whole_file(fs, fs_blk->dlm_blkno, &buf, &buflen);
+	if (ret)
+		goto bail;
+
+	/* process publish times */
+	p = buf + ((2 + 4 + num_nodes) << blksz_bits); /* start of publish */
+	ocfs2_detect_live_nodes (fs_blk, p, first_time);
+
+	/* fill node_names */
+	if (!first_time && node_list) {
+		p = buf + (2 << blksz_bits);	/* start of node cfg */
+		for (i = 0; i < num_nodes; ++i) {
+			if (fs_blk->live_node[i]) {
+				node = (ocfs_node_config_info *)p;
+				ret = ocfs2_malloc0(sizeof(ocfs2_nodes), &node_blk);
+				if (ret)
+					goto bail;
+				strncpy(node_blk->node_name, node->node_name,
+					sizeof(node_blk->node_name));
+				node_blk->node_num = i;
+				list_add_tail(&(node_blk->list), node_list);
+			}
+			p += (1 << blksz_bits);
 		}
-		p += (1 << blksz_bits);
 	}
 
-	return ;
+bail:
+	if (buflen && buf)
+		ocfs2_free (&buf);
+
+	return ret;
 }
+
+/*
+ * ocfs2_gather_times_v1()
+ *
+ */
+errcode_t ocfs2_gather_times_v1(ocfs2_fs *fs_blk, struct list_head *node_list,
+			       	int first_time)
+{
+	int fd = -1;
+	char *buf = NULL;
+	int buflen = 0;
+	errcode_t ret = 0;
+	char *p;
+	uint16_t num_nodes = 32;	/* v1 numnodes */
+	uint32_t blksz_bits = 9;	/* v1 blksz is fixed at 512 bytes */
+	ocfs1_disk_node_config_info *node;
+	ocfs2_nodes *node_blk;
+	int i;
+
+	/* open device */
+	fd = open(fs_blk->dev_name, O_RDONLY);
+	if (fd == -1)
+		goto bail;
+
+	buflen = 2;		/* node cfg hdr */
+        buflen += num_nodes;	/* node cfgs */
+	buflen += 4;		/* node cfg trailer */
+	buflen += num_nodes;	/* publish */
+	buflen <<= blksz_bits;	/* convert to bytes */
+
+	/* alloc mem to read cfg+publish */
+	ret = ocfs2_malloc0(buflen, &buf);
+	if (ret)
+		goto bail;
+
+	/* read cfg+publish */
+	if (pread(fd, buf, buflen, 4096) == -1)
+		goto bail;
+
+	/* process publish times */
+	p = buf + ((2 + num_nodes + 4) << blksz_bits); /* start of publish */
+	ocfs2_detect_live_nodes (fs_blk, p, first_time);
+
+	/* fill node_names */
+	if (!first_time && node_list) {
+		p = buf + (2 << blksz_bits);	/* start of node cfg */
+		for (i = 0; i < num_nodes; ++i) {
+			if (fs_blk->live_node[i]) {
+				node = (ocfs1_disk_node_config_info *)p;
+				ret = ocfs2_malloc0(sizeof(ocfs2_nodes), &node_blk);
+				if (ret)
+					goto bail;
+				strncpy(node_blk->node_name, node->node_name,
+					sizeof(node_blk->node_name));
+				node_blk->node_num = i;
+				list_add_tail(&(node_blk->list), node_list);
+			}
+			p += (1 << blksz_bits);
+		}
+	}
+
+bail:
+	if (buf)
+		ocfs2_free (&buf);
+
+	if (fd != -1)
+		close(fd);
+
+	return ret;
+}
+
+/*
+ * ocfs2_get_ocfs1_label()
+ *
+ */
+errcode_t ocfs2_get_ocfs1_label(char *device, uint8_t *label, uint16_t label_len,
+				uint8_t *uuid, uint16_t uuid_len)
+{
+	int fd = -1;
+	int ret = OCFS2_ET_IO;
+	char buf[512];
+	ocfs1_vol_label *v1_lbl;
+
+	fd = open(device, O_RDONLY);
+	if (fd == -1)
+		goto bail;
+
+	if (pread(fd, buf, sizeof(buf), 512) == -1)
+		goto bail;
+
+	v1_lbl = (ocfs1_vol_label *)buf;
+	memcpy(label, v1_lbl->label, label_len);
+	memcpy(uuid, v1_lbl->vol_id, uuid_len);
+
+	ret = 0;
+bail:
+	if (fd >= 0)
+		close(fd);
+	return ret;
+}

Modified: trunk/libocfs2/include/kernel-list.h
===================================================================
--- trunk/libocfs2/include/kernel-list.h	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/libocfs2/include/kernel-list.h	2004-09-21 23:06:17 UTC (rev 247)
@@ -109,4 +109,8 @@
 #define list_for_each(pos, head) \
         for (pos = (head)->next; pos != (head); pos = pos->next)
 
+#define list_for_each_safe(pos, n, head) \
+	        for (pos = (head)->next, n = pos->next; pos != (head); \
+		                     pos = n, n = pos->next)
+
 #endif

Modified: trunk/libocfs2/include/ocfs1_fs_compat.h
===================================================================
--- trunk/libocfs2/include/ocfs1_fs_compat.h	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/libocfs2/include/ocfs1_fs_compat.h	2004-09-21 23:06:17 UTC (rev 247)
@@ -36,7 +36,13 @@
 #define MAX_VOL_ID_LENGTH_V1               16
 #define MAX_VOL_LABEL_LEN_V1               64
 #define MAX_CLUSTER_NAME_LEN_V1            64
+#define MAX_IP_ADDR_LEN                    32
+#define MAX_NODE_NAME_LENGTH               32
 
+#define GUID_LEN                           32
+#define HOSTID_LEN                         20
+#define MACID_LEN                          12
+
 #define OCFS1_MAJOR_VERSION              (2)
 #define OCFS1_MINOR_VERSION              (0)
 #define OCFS1_VOLUME_SIGNATURE		 "OracleCFS"
@@ -108,5 +114,31 @@
 } ocfs1_vol_label;
 
 
+typedef struct _ocfs1_ipc_config_info
+{
+	__u8 type;
+	__u8 ip_addr[MAX_IP_ADDR_LEN+1];
+	__u32 ip_port;
+	__u8 ip_mask[MAX_IP_ADDR_LEN+1];
+} ocfs1_ipc_config_info;
+
+typedef union _ocfs1_guid
+{
+	struct
+	{
+		char host_id[HOSTID_LEN];
+		char mac_id[MACID_LEN];
+	} id;
+	__u8 guid[GUID_LEN];
+} ocfs1_guid;
+
+typedef struct _ocfs1_disk_node_config_info
+{
+	ocfs1_disk_lock disk_lock;
+	__u8 node_name[MAX_NODE_NAME_LENGTH+1];
+	ocfs1_guid guid;
+	ocfs1_ipc_config_info ipc_config;
+} ocfs1_disk_node_config_info;
+
 #endif /* _OCFS1_FS_COMPAT_H */
 

Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/libocfs2/include/ocfs2.h	2004-09-21 23:06:17 UTC (rev 247)
@@ -44,6 +44,8 @@
 
 #include "byteorder.h"
 
+#include <kernel-list.h>
+
 #if OCFS2_FLAT_INCLUDES
 #include "ocfs2_err.h"
 
@@ -151,6 +153,8 @@
 typedef struct _ocfs2_extent_map ocfs2_extent_map;
 typedef struct _ocfs2_inode_scan ocfs2_inode_scan;
 typedef struct _ocfs2_bitmap ocfs2_bitmap;
+typedef struct _ocfs2_nodes ocfs2_nodes;
+typedef struct _ocfs2_devices ocfs2_devices;
 
 struct _ocfs2_filesys {
 	char *fs_devname;
@@ -178,7 +182,23 @@
 	ocfs2_extent_map *ci_map;
 };
 
+struct _ocfs2_nodes {
+	struct list_head list;
+	char node_name[MAX_NODE_NAME_LENGTH+1];
+	uint16_t node_num;
+};
 
+struct _ocfs2_devices {
+	struct list_head list;
+	char dev_name[100];
+	uint8_t label[64];
+	uint8_t uuid[16];
+	int mount_flags;
+	int fs_type;		/* 0=unknown, 1=ocfs, 2=ocfs2 */
+	void *private;
+	struct list_head node_list;
+};
+
 errcode_t ocfs2_malloc(unsigned long size, void *ptr);
 errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
 errcode_t ocfs2_free(void *ptr);
@@ -328,18 +348,14 @@
 errcode_t ocfs2_read_whole_file(ocfs2_filesys *fs, uint64_t blkno,
 				char **buf, int *len);
 
-errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
-				char **node_names,
-				ocfs2_chb_notify notify,
-				void *user_data);
+errcode_t ocfs2_check_heartbeat(char *device, int quick_detect,
+			       	int *mount_flags, struct list_head *nodes_list,
+                                ocfs2_chb_notify notify, void *user_data);
 
-void ocfs2_detect_live_nodes(ocfs2_filesys *fs, char *pub_buf,
-			     uint64_t *pub_times, int *node_stats,
-			     int first_time);
+errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int quick_detect,
+				 ocfs2_chb_notify notify, void *user_data);
 
-void ocfs2_live_node_names(ocfs2_filesys *fs, char *node_buf,
-			   int *node_stats,
-			   char **node_names);
+errcode_t ocfs2_get_ocfs1_label(char *device, uint8_t *label, uint16_t label_len,
+				uint8_t *uuid, uint16_t uuid_len);
 
 #endif  /* _FILESYS_H */
-

Modified: trunk/mkfs.ocfs2/Cscope.make
===================================================================
--- trunk/mkfs.ocfs2/Cscope.make	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/mkfs.ocfs2/Cscope.make	2004-09-21 23:06:17 UTC (rev 247)
@@ -3,7 +3,8 @@
 	rm -f cscope.*
 	echo "-k" >> cscope.files
 	echo "-I inc" >> cscope.files
-	find . -maxdepth 2 -name '*.c' -print >>cscope.files
+	find . -maxdepth 2 -name '*.c' -print | grep -v mkfs2.c >>cscope.files
 	find . -maxdepth 2 -name '*.h' -print >>cscope.files
 	find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+	find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
 	cscope -b

Modified: trunk/mounted.ocfs2/mounted.c
===================================================================
--- trunk/mounted.ocfs2/mounted.c	2004-09-21 21:51:06 UTC (rev 246)
+++ trunk/mounted.ocfs2/mounted.c	2004-09-21 23:06:17 UTC (rev 247)
@@ -2,6 +2,7 @@
  * mounted.c
  *
  * ocfs2 mount detect utility
+ * Detects both ocfs and ocfs2 volumes
  *
  * Copyright (C) 2004 Oracle.  All rights reserved.
  *
@@ -42,27 +43,20 @@
 #include <ocfs1_fs_compat.h>
 #include <kernel-list.h>
 
-int detect_only = 0;
+int quick_detect = 0;
 char *device = NULL;
 char *progname = NULL;
 
-#define MAX_DEVNAME_LEN		100
-
-struct _ocfs2_devices {
-	struct list_head list;
-	char name[MAX_DEVNAME_LEN];
-};
-typedef struct _ocfs2_devices ocfs2_devices;
-
 char *usage_string =
-"usage: %s [-d] [device]\n"
-"	-d detect only\n";
+"usage: %s [-d] [-f] [device]\n"
+"	-d quick detect\n"
+"	-f full detect\n";
 
-errcode_t ocfs2_full_detect(char *device);
-errcode_t ocfs2_quick_detect(char *device);
-void ocfs2_print_live_nodes(char **node_names, uint16_t num_nodes);
+errcode_t ocfs2_detect(char *device, int quick_detect);
+void ocfs2_print_quick_detect(struct list_head *dev_list);
+void ocfs2_print_full_detect(struct list_head *dev_list);
+void ocfs2_print_nodes(struct list_head *node_list);
 errcode_t ocfs2_partition_list (struct list_head *dev_list);
-int ocfs2_get_ocfs1_label(char *device, char *buf, int buflen);
 int read_options(int argc, char **argv);
 void usage(char *progname);
 
@@ -80,17 +74,8 @@
 	if (ret)
 		goto bail;
 
-	if (!detect_only && !device) {
-		usage(progname);
-		ret = 1;
-		goto bail;
-	}
+	ret = ocfs2_detect(device, quick_detect);
 
-	if (detect_only)
-		ret = ocfs2_quick_detect(device);
-	else
-		ret = ocfs2_full_detect(device);
-
 bail:
 	return ret;
 }
@@ -102,166 +87,134 @@
 }
 
 /*
- * ocfs2_full_detect()
+ * ocfs2_detect()
  *
  */
-errcode_t ocfs2_full_detect(char *device)
+errcode_t ocfs2_detect(char *device, int quick_detect)
 {
 	errcode_t ret = 0;
-	int mount_flags = 0;
-	char *node_names[OCFS2_NODE_MAP_MAX_NODES];
-	ocfs2_filesys *fs = NULL;
-	uint8_t *vol_label = NULL;
-	uint8_t *vol_uuid = NULL;
-	uint16_t num_nodes = OCFS2_NODE_MAP_MAX_NODES;
-	int i;
+	struct list_head dev_list;
+	struct list_head *pos1, *pos2, *pos3, *pos4;
+	ocfs2_nodes *node;
+	ocfs2_devices *dev;
 
-	memset(node_names, 0, sizeof(node_names));
+	INIT_LIST_HEAD(&(dev_list));
 
-	/* open	fs */
-	ret = ocfs2_open(device, O_DIRECT | OCFS2_FLAG_RO, 0, 0, &fs);
-	if (ret) {
-		if (ret == OCFS2_ET_OCFS_REV)
-			fprintf(stderr, "Error: %s is an ocfs volume. "
-				"Use mounted.ocfs to detect heartbeat on it.\n",
-				device);
-		else
-			com_err(progname, ret, "while opening \"%s\"", device);
-		goto bail;
+	if (device) {
+		ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
+		if (ret)
+			goto bail;
+		strncpy(dev->dev_name, device, sizeof(dev->dev_name));
+		list_add(&(dev->list), &dev_list);
+	} else {
+		ret = ocfs2_partition_list(&dev_list);
+		if (ret) {
+			com_err(progname, ret, "while reading /proc/partitions");
+			goto bail;
+		}
 	}
 
-	num_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
-	vol_label = OCFS2_RAW_SB(fs->fs_super)->s_label;
-	vol_uuid = OCFS2_RAW_SB(fs->fs_super)->s_uuid;
-
-	printf("Device: %s\n", device);
-	printf("Label : %s\n", vol_label);
-	printf("Id    : ");
-	for (i = 0; i < 16; i++)
-		printf("%02X", vol_uuid[i]);
-	printf("\n");
-
-	if (detect_only)
-		goto bail;
-		
-	ret = ocfs2_check_heartbeat(device, &mount_flags, node_names,
-                                    chb_notify, NULL);
+	ret = ocfs2_check_heartbeats(&dev_list, quick_detect, chb_notify, NULL);
 	if (ret) {
 		com_err(progname, ret, "while detecting heartbeat");
 		goto bail;
 	}
 
-	if (mount_flags & (OCFS2_MF_MOUNTED | OCFS2_MF_MOUNTED_CLUSTER)) {
-		printf("Nodes :");
-		ocfs2_print_live_nodes(node_names, num_nodes);
-	} else {
-		printf("Nodes : Not mounted\n");
-		goto bail;
-	}
+	if (quick_detect)
+		ocfs2_print_quick_detect(&dev_list);
+	else
+		ocfs2_print_full_detect(&dev_list);
 
 bail:
-	if (fs)
-		ocfs2_close(fs);
+	list_for_each_safe(pos1, pos2, &(dev_list)) {
+		dev = list_entry(pos1, ocfs2_devices, list);
+		list_for_each_safe(pos3, pos4, &(dev->node_list)) {
+			node = list_entry(pos3, ocfs2_nodes, list);
+			list_del(&(node->list));
+			ocfs2_free(&node);
+		}
+		list_del(&(dev->list));
+		ocfs2_free(&dev);
+	}
 
-	for (i = 0; i < num_nodes; ++i)
-		if (node_names[i])
-			ocfs2_free (&node_names[i]);
-
 	return ret;
 }
 
 /*
- * ocfs2_quick_detect()
+ * ocfs2_print_full_detect()
  *
  */
-errcode_t ocfs2_quick_detect(char *device)
+void ocfs2_print_full_detect(struct list_head *dev_list)
 {
-	errcode_t ret = 0;
-	ocfs2_filesys *fs = NULL;
-	uint8_t *vol_label = NULL;
-	uint8_t *vol_uuid = NULL;
-	ocfs1_vol_label *v1_lbl = NULL;
-	struct list_head dev_list;
-	struct list_head *pos;
 	ocfs2_devices *dev;
-	char buf[512];
-	char uuid[40];
-	char *p;
-	int i;
+	struct list_head *pos;
 
-	INIT_LIST_HEAD(&dev_list);
-
-	if (device) {
-		ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
-		if (ret)
-			goto bail;
-		strncpy(dev->name, device, MAX_DEVNAME_LEN);
-		list_add(&(dev->list), &dev_list);
-	} else {
-		ret = ocfs2_partition_list(&dev_list);
-		if (ret) {
-			com_err(progname, ret, "while reading /proc/partitions");
-			goto bail;
+	printf("%-20s  %-5s  %s\n", "Device", "FS", "Nodes");
+	list_for_each(pos, dev_list) {
+		dev = list_entry(pos, ocfs2_devices, list);
+		if (dev->fs_type == 0)
+			continue;
+		printf("%-20s  %-5s  ", dev->dev_name,
+		       (dev->fs_type == 2 ? "ocfs2" : "ocfs"));
+		if (list_empty(&(dev->node_list))) {
+			printf("Not mounted\n");
+			continue;
 		}
+		ocfs2_print_nodes(&(dev->node_list));
+		printf("\n");
 	}
+	return ;
+}
 
-	printf("%-20s  %-6s  %-32s  %-s\n", "Device", "Type", "GUID", "Label");
 
-	list_for_each(pos, &(dev_list)) {
+/*
+ * ocfs2_print_quick_detect()
+ *
+ */
+void ocfs2_print_quick_detect(struct list_head *dev_list)
+{
+	ocfs2_devices *dev;
+	struct list_head *pos;
+	char uuid[40];
+	char *p;
+	int i;
+
+	printf("%-20s  %-5s  %-32s  %-s\n", "Device", "FS", "GUID", "Label");
+	list_for_each(pos, dev_list) {
 		dev = list_entry(pos, ocfs2_devices, list);
-		ret = ocfs2_open(dev->name, OCFS2_FLAG_RO, 0, 0, &fs);
-		if (ret == 0 || ret == OCFS2_ET_OCFS_REV) {
-			if (!ret) {
-				vol_label = OCFS2_RAW_SB(fs->fs_super)->s_label;
-				vol_uuid = OCFS2_RAW_SB(fs->fs_super)->s_uuid;
-			} else {
-				if (!ocfs2_get_ocfs1_label(dev->name, buf, sizeof(buf))) {
-					v1_lbl = (ocfs1_vol_label *)buf;
-					vol_label = v1_lbl->label;
-					vol_uuid = v1_lbl->vol_id;
-				} else {
-					vol_label = NULL;
-					vol_uuid = NULL;
-				}
-			}
-	
-			memset(uuid, 0, sizeof(uuid));		
-			for (i = 0, p = uuid; i < 16 && vol_uuid; i++, p += 2)
-				sprintf(p, "%02X", vol_uuid[i]);
+		if (dev->fs_type == 0)
+			continue;
 
-			printf("%-20s  %-6s  %-32s  %-s\n", dev->name,
-			       (!ret ? "ocfs2" : "ocfs"), uuid,
-			       (vol_label ? (char *)vol_label : " "));
-		}
-		if (!ret)
-			ocfs2_close(fs);
-	}
+		memset(uuid, 0, sizeof(uuid));		
+		for (i = 0, p = uuid; i < 16; i++, p += 2)
+			sprintf(p, "%02X", dev->uuid[i]);
 
-bail:
-	list_for_each(pos, &(dev_list)) {
-		dev = list_entry(pos, ocfs2_devices, list);
-		list_del(&(dev->list));
+		printf("%-20s  %-5s  %-32s  %-s\n", dev->dev_name,
+		       (dev->fs_type == 2 ? "ocfs2" : "ocfs"), uuid,
+		       dev->label);
 	}
 
-	return 0;
+	return ;
 }
 
 /*
- * ocfs2_print_live_nodes()
+ * ocfs2_print_nodes()
  *
  */
-void ocfs2_print_live_nodes(char **node_names, uint16_t num_nodes)
+void ocfs2_print_nodes(struct list_head *node_list)
 {
-	int i;
-	char comma = '\0';
+	ocfs2_nodes *node;
+	struct list_head *pos;
+	int begin = 1;
 
-	for (i = 0; i < num_nodes; ++i) {
-		if (node_names[i]) {
-			printf("%c %s", comma, node_names[i]);
-			comma = ',';
-		}
+	list_for_each(pos, node_list) {
+		node = list_entry(pos, ocfs2_nodes, list);
+		if (begin) {
+			printf("%s", node->node_name);
+			begin = 0;
+		}  else
+			printf(", %s", node->node_name);
 	}
-	printf("\n");
 
 	return ;
 }
@@ -292,7 +245,7 @@
 		if (ret)
 			goto bail;
 
-		snprintf(dev->name, MAX_DEVNAME_LEN, "/dev/%s", name);
+		snprintf(dev->dev_name, sizeof(dev->dev_name), "/dev/%s", name);
 		list_add_tail(&(dev->list), dev_list);
 	}
 
@@ -304,29 +257,6 @@
 }
 
 /*
- * ocfs2_get_ocfs1_label()
- *
- */
-int ocfs2_get_ocfs1_label(char *device, char *buf, int buflen)
-{
-	int fd = -1;
-	int ret = -1;
-	
-	fd = open(device, O_RDONLY);
-	if (fd == -1)
-		goto bail;
-
-	if (pread(fd, buf, buflen, 512) == -1)
-		goto bail;
-
-	ret = 0;
-bail:
-	if (fd > 0)
-		close(fd);
-	return ret;
-}
-
-/*
  * usage()
  *
  */
@@ -354,15 +284,19 @@
 	}
 
 	while(1) {
-		c = getopt(argc, argv, "d");
+		c = getopt(argc, argv, "df");
 		if (c == -1)
 			break;
 
 		switch (c) {
-		case 'd':	/* detect only */
-			detect_only = 1;
+		case 'd':	/* quick detect*/
+			quick_detect = 1;
 			break;
 
+		case 'f':	/* full detect*/
+			quick_detect = 0;
+			break;
+
 		default:
 			break;
 		}



More information about the Ocfs2-tools-commits mailing list