[Ocfs2-tools-commits] jlbec commits r242 - in trunk: libocfs2 libocfs2/include mounted.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Sep 16 18:45:24 CDT 2004


Author: jlbec
Date: 2004-09-16 18:45:22 -0500 (Thu, 16 Sep 2004)
New Revision: 242

Modified:
   trunk/libocfs2/checkhb.c
   trunk/libocfs2/include/ocfs2.h
   trunk/mounted.ocfs2/mounted.c
Log:

o Added notify function to check_heartbeat.
o Changed mounted.ocfs2 to use the notify function.



Modified: trunk/libocfs2/checkhb.c
===================================================================
--- trunk/libocfs2/checkhb.c	2004-09-16 23:43:00 UTC (rev 241)
+++ trunk/libocfs2/checkhb.c	2004-09-16 23:45:22 UTC (rev 242)
@@ -53,9 +53,19 @@
  * 	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.
  */
-errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags, char **node_names)
+errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
+                                char **node_names,
+                                ocfs2_chb_notify notify,
+                                void *user_data)
 {
 	ocfs2_filesys *fs = NULL;
 	char *buf = NULL;
@@ -85,7 +95,7 @@
 	/* open	fs */
 	blksize = 0;
 	blkno = 0;
-	ret = ocfs2_open(device, O_DIRECT | OCFS2_FLAG_RO, blkno, blksize, &fs);
+	ret = ocfs2_open(device, OCFS2_FLAG_RO, blkno, blksize, &fs);
 	if (ret)
 		goto bail;
 
@@ -113,17 +123,24 @@
 		buflen = 0;
 	}
 
+	if (notify)
+		notify(OCFS2_CHB_START,
+		       "Checking heart beat on volume ",
+		       user_data);
+
 	/* wait */
-	printf("Checking heart beat on volume ");
 	wait_time = 1;
 	wait_time = (wait_time ? wait_time : 1);
 	for (i = 0; i < OCFS2_HBT_WAIT; ++i) {
-		printf(".");
-		fflush(stdout);
+		if (notify)
+			notify(OCFS2_CHB_WAITING, ".", user_data);
 		sleep(wait_time);
 	}
-	printf("\r                                                \r");
-	fflush(stdout);
+
+	if (notify)
+		notify(OCFS2_CHB_COMPLETE,
+		       "\r                                                \r",
+		       user_data);
   
 	/* read dlm file again */
 	ret = ocfs2_read_whole_file(fs, dlm_blkno, &buf, &buflen);

Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h	2004-09-16 23:43:00 UTC (rev 241)
+++ trunk/libocfs2/include/ocfs2.h	2004-09-16 23:45:22 UTC (rev 242)
@@ -137,6 +137,13 @@
 #define OCFS2_NODE_MAP_MAX_NODES	256
 #define OCFS2_HBT_WAIT			10
 
+/* check_heartbeats progress states */
+#define OCFS2_CHB_START		1
+#define OCFS2_CHB_WAITING	2
+#define OCFS2_CHB_COMPLETE	3
+
+typedef void (*ocfs2_chb_notify)(int state, char *progress, void *data);
+
 typedef struct _ocfs2_filesys ocfs2_filesys;
 typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
 typedef struct _io_channel io_channel;
@@ -321,13 +328,16 @@
 				char **buf, int *len);
 
 errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
-				char **node_names);
+				char **node_names,
+				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);
 
-void ocfs2_live_node_names(ocfs2_filesys *fs, char *node_buf, int *node_stats,
+void ocfs2_live_node_names(ocfs2_filesys *fs, char *node_buf,
+			   int *node_stats,
 			   char **node_names);
 
 #endif  /* _FILESYS_H */

Modified: trunk/mounted.ocfs2/mounted.c
===================================================================
--- trunk/mounted.ocfs2/mounted.c	2004-09-16 23:43:00 UTC (rev 241)
+++ trunk/mounted.ocfs2/mounted.c	2004-09-16 23:45:22 UTC (rev 242)
@@ -95,6 +95,12 @@
 	return ret;
 }
 
+static void chb_notify(int state, char *progress, void *user_data)
+{
+    fprintf(stdout, "%s", progress);
+    fflush(stdout);
+}
+
 /*
  * ocfs2_full_detect()
  *
@@ -138,7 +144,8 @@
 	if (detect_only)
 		goto bail;
 		
-	ret = ocfs2_check_heartbeat(device, &mount_flags, node_names);
+	ret = ocfs2_check_heartbeat(device, &mount_flags, node_names,
+                                    chb_notify, NULL);
 	if (ret) {
 		com_err(progname, ret, "while detecting heartbeat");
 		goto bail;



More information about the Ocfs2-tools-commits mailing list