[Ocfs2-tools-devel] Patch for mounted.ocfs2 heartbeat detection

tao.ma tao.ma at oracle.com
Thu Apr 5 02:46:12 PDT 2007


> Index: mounted.ocfs2/mounted.c
> ===================================================================
> --- mounted.ocfs2/mounted.c	(revision 1336)
> +++ mounted.ocfs2/mounted.c	(working copy)
> @@ -67,6 +67,63 @@
>  	}
>  }
>  
> +/* Return 0 if //heartbeat not change in 10 seconds */
> +static int ocfs2_detect_heartbeat(ocfs2_devices *dev)
> +{
> +	ocfs2_filesys *fs = NULL;
> +	char *device= NULL;
> +	errcode_t ret = 0;
> +	uint64_t hb_blkno;
> +	char sysfile[40];
> +	char *hbbuf = NULL;
> +	char *hbbuf2 = NULL;
> +	int len;
> +	int val = 0;
> +
> +	device = dev->dev_name;
> +	/* open fs */
> +	fs = NULL;
> +	ret = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
> +	if (ret) {
> +		ret = 0;
> +		return -1; /* something is wrong */
> +	} else
> +		dev->fs_type = 2;
> +
> +	snprintf (sysfile, sizeof(sysfile),
> +		ocfs2_system_inodes[HEARTBEAT_SYSTEM_INODE].si_name);
> +
> +	ret = ocfs2_lookup(fs, OCFS2_RAW_SB(fs->fs_super)->s_system_dir_blkno,
> +		sysfile, strlen(sysfile), NULL, &hb_blkno);
> +	if (ret)
> +		hb_blkno = 0;
>   
Why you set hb_blkno to "0" here? Although the "0" may cause the 
function ocfs2_read_whole_file error, the "ret" is different. So you may 
give the user a wrong message of "reading heartbeat system file" for the 
error in ocfs2_lookup.
> +
> +	ret = ocfs2_read_whole_file(fs, hb_blkno, &hbbuf, &len);
> +	if (ret) {
> +		com_err("", ret, "while reading heartbeat system file");
> +		goto bail;
> +	}
> +
> +	sleep(10);
>   
Why use 10? Could you please add some comment for why choose this magic 
number?

Is it the value of idle timeout second? If it is, I remember that in the 
new ocfs2 kernel we have configurable timeout.
You may get the value by 
$(configfs_path)/cluster/${CLUSTER}/idle_timeout_ms(See 
vendor/common/o2cb.init). For an old ocfs2 version, you may use 10. I am 
not quite sure of it. So you may ask others about it. :)

> +
> +	ret = ocfs2_read_whole_file(fs, hb_blkno, &hbbuf2, &len);
> +	if (ret) {
> +		com_err("", ret, "while reading heartbeat system file");
> +		goto bail;
> +	}
> +
> +	val = memcmp(hbbuf, hbbuf2, len);
> +
> +bail:
> +	if (hbbuf2)
> +		ocfs2_free(&hbbuf2);
> +	if (hbbuf)
> +		ocfs2_free(&hbbuf);
> +	ocfs2_close(fs);
> +
> +	return val;
> +}
> +
>  
>  static void ocfs2_print_full_detect(struct list_head *dev_list)
>  {
> @@ -105,6 +162,11 @@
>  
>  		printf("%-20s  %-5s  ", dev->dev_name, "ocfs2");
>  
> +		if (0 == ocfs2_detect_heartbeat(dev)) {
> +			printf("Not mounted\n");
> +			continue;
> +		}
> +
>  		if (dev->errcode) {
>  			fflush(stdout);
>  			com_err("Unknown", dev->errcode, " ");
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ocfs2-tools-devel mailing list
> Ocfs2-tools-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-tools-devel

<http://www.oracle.com/cdc/>



More information about the Ocfs2-tools-devel mailing list