[Ocfs2-commits] manish commits r2224 - trunk/fs/ocfs2/cluster

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue May 10 22:59:39 CDT 2005


Author: manish
Signed-off-by: mfasheh
Date: 2005-05-10 22:59:37 -0500 (Tue, 10 May 2005)
New Revision: 2224

Modified:
   trunk/fs/ocfs2/cluster/heartbeat.c
   trunk/fs/ocfs2/cluster/ocfs2_nodemanager.h
Log:
Calculate hearbeat region parameters in userspace, and enforce the hearbeat
block size to be the same as the hardware sector size.

Signed-off-by: mfasheh


Modified: trunk/fs/ocfs2/cluster/heartbeat.c
===================================================================
--- trunk/fs/ocfs2/cluster/heartbeat.c	2005-05-06 23:19:15 UTC (rev 2223)
+++ trunk/fs/ocfs2/cluster/heartbeat.c	2005-05-11 03:59:37 UTC (rev 2224)
@@ -115,21 +115,19 @@
  * we ask the thread to stop, who cleans up the region */
 struct hb_region {
 	struct config_item	hr_item;
+
 	/* protected by the hr_callback_sem */
 	struct task_struct 	*hr_task;
-	unsigned int		hr_fs_block_bytes;
-	unsigned int		hr_fs_block_bits;
-	unsigned long long	hr_fs_start_block;
-	unsigned int		hr_fs_blocks;
-	/* will probably need: hr_start_block, hr_blocks */
+
 	unsigned int		hr_blocks;
 	unsigned long long	hr_start_block;
 
-	unsigned int		hr_hb_block_bits;
-	unsigned int		hr_hb_block_bytes;
-	unsigned int		hr_hb_slots_per_page;
+	unsigned int		hr_block_bits;
+	unsigned int		hr_block_bytes;
 
+	unsigned int		hr_slots_per_page;
 	unsigned int		hr_num_pages;
+
 	struct page             **hr_slot_data;
 	struct block_device	*hr_bdev;
 	struct hb_disk_slot	*hr_slots;
@@ -203,8 +201,8 @@
 {
 	int i, nr_vecs, len, first_page, last_page;
 	unsigned int vec_len, vec_start;
-	unsigned int bits = reg->hr_hb_block_bits;
-	unsigned int spp = reg->hr_hb_slots_per_page;
+	unsigned int bits = reg->hr_block_bits;
+	unsigned int spp = reg->hr_slots_per_page;
 	struct bio *bio;
 	struct page *page;
 
@@ -295,10 +293,10 @@
 
 	max_sectors = compute_max_sectors(reg->hr_bdev);
 
-	io_sectors = num_slots << (reg->hr_hb_block_bits - 9);
+	io_sectors = num_slots << (reg->hr_block_bits - 9);
 
 	*num_bios = (io_sectors + max_sectors - 1) / max_sectors;
-	*slots_per_bio = max_sectors >> (reg->hr_hb_block_bits - 9);
+	*slots_per_bio = max_sectors >> (reg->hr_block_bits - 9);
 
 	mlog(ML_HB_BIO, "My io size is %u sectors for %u slots. This "
 	     "device can handle %u sectors of I/O\n", io_sectors, num_slots,
@@ -425,7 +423,7 @@
 	slot = &reg->hr_slots[node_num];
 
 	hb_block = (struct hb_disk_heartbeat_block *) slot->ds_raw_block;
-	memset(hb_block, 0, reg->hr_hb_block_bytes);
+	memset(hb_block, 0, reg->hr_block_bytes);
 	/* TODO: time stuff */
 	cputime = CURRENT_TIME.tv_sec;
 	if (!cputime)
@@ -571,7 +569,8 @@
 	 * changes at any time during their dead time */
 	if (list_empty(&slot->ds_live_item) &&
 	    slot->ds_changed_samples >= HB_LIVE_THRESHOLD) {
-		mlog(ML_HEARTBEAT, "Node %d joined my region\n", slot->ds_node_num);
+		mlog(ML_HEARTBEAT, "Node %d joined my region\n",
+		     slot->ds_node_num);
 
 		/* first on the list generates a callback */
 		if (list_empty(&hb_live_slots[slot->ds_node_num])) {
@@ -598,7 +597,8 @@
 	 * samples..  reset the missed counter whenever we see 
 	 * activity */
 	if (slot->ds_equal_samples >= HB_DEAD_THRESHOLD) {
-		mlog(ML_HEARTBEAT, "Node %d left my region\n", slot->ds_node_num);
+		mlog(ML_HEARTBEAT, "Node %d left my region\n",
+		     slot->ds_node_num);
 
 		/* last off the live_slot generates a callback */
 		list_del_init(&slot->ds_live_item);
@@ -803,14 +803,6 @@
 	kfree(reg);
 }
 
-static void hb_init_region_params(struct hb_region *reg,
-				  unsigned int block_bits)
-{
-	reg->hr_hb_block_bits = block_bits;
-	reg->hr_hb_block_bytes = 1 << block_bits;
-	reg->hr_hb_slots_per_page = PAGE_CACHE_SIZE >> block_bits;
-}
-
 static int hb_read_block_input(struct hb_region *reg,
 			       const char *page,
 			       size_t count,
@@ -838,35 +830,9 @@
 	return 0;
 }
 
-static ssize_t hb_region_slot_bytes_read(struct hb_region *reg, char *page)
-{
-	return sprintf(page, "%u\n", reg->hr_hb_block_bytes);
-}
-
-static ssize_t hb_region_slot_bytes_write(struct hb_region *reg,
-					  const char *page,
-					  size_t count)
-{
-	int status;
-	unsigned int slot_bits;
-
-	if (reg->hr_bdev)
-		return -EINVAL;
-
-	status = hb_read_block_input(reg, page, count, NULL, &slot_bits);
-	if (status)
-		return status;
-
-	hb_init_region_params(reg, slot_bits);
-
-	mlog(ML_HEARTBEAT, "Heartbeat region using %u sized slots\n", 1 << slot_bits);
-
-	return count;
-}
-
 static ssize_t hb_region_block_bytes_read(struct hb_region *reg, char *page)
 {
-	return sprintf(page, "%u\n", reg->hr_fs_block_bytes);
+	return sprintf(page, "%u\n", reg->hr_block_bytes);
 }
 
 static ssize_t hb_region_block_bytes_write(struct hb_region *reg,
@@ -874,26 +840,26 @@
 					   size_t count)
 {
 	int status;
-	unsigned long fs_bytes;
-	unsigned int fs_bits;
+	unsigned long block_bytes;
+	unsigned int block_bits;
 
 	if (reg->hr_bdev)
 		return -EINVAL;
 
-	status = hb_read_block_input(reg, page, count, &fs_bytes, &fs_bits);
+	status = hb_read_block_input(reg, page, count,
+				     &block_bytes, &block_bits);
 	if (status)
 		return status;
 
-	/* XXX compare blocks against dev later on commit? */
-	reg->hr_fs_block_bytes = (unsigned int) fs_bytes;
-	reg->hr_fs_block_bits = fs_bits;
+	reg->hr_block_bytes = (unsigned int)block_bytes;
+	reg->hr_block_bits = block_bits;
 
 	return count;
 }
 
 static ssize_t hb_region_start_block_read(struct hb_region *reg, char *page)
 {
-	return sprintf(page, "%llu\n", reg->hr_fs_start_block);
+	return sprintf(page, "%llu\n", reg->hr_start_block);
 }
 
 static ssize_t hb_region_start_block_write(struct hb_region *reg,
@@ -910,14 +876,14 @@
 	if (!p || (*p && (*p != '\n')))
 		return -EINVAL;
 
-	/* XXX compare blocks against dev later on commit? */
-	reg->hr_fs_start_block = tmp;
+	reg->hr_start_block = tmp;
 
 	return count;
 }
+
 static ssize_t hb_region_blocks_read(struct hb_region *reg, char *page)
 {
-	return sprintf(page, "%d\n", reg->hr_fs_blocks);
+	return sprintf(page, "%d\n", reg->hr_blocks);
 }
 
 static ssize_t hb_region_blocks_write(struct hb_region *reg,
@@ -937,7 +903,7 @@
 	if (tmp >= NM_MAX_NODES)
 		return -ERANGE;
 
-	reg->hr_fs_blocks = (unsigned int) tmp;
+	reg->hr_blocks = (unsigned int)tmp;
 
 	return count;
 }
@@ -952,34 +918,21 @@
 	return ret;
 }
 
-/* expects all hr_fs_ members to be filled, as well as hr->hr_bdev */
-static void hb_calculate_region_offsets(struct hb_region *reg)
+static void hb_init_region_params(struct hb_region *reg)
 {
-	unsigned long long tmp_bytes;
+	reg->hr_slots_per_page = PAGE_CACHE_SIZE >> reg->hr_block_bits;
 
-	/* for the # of hearbeat blocks, don't use more than the
-	 * number of fs blocks allocated to the file system. We
-	 * already know that hb block size can't be bigger than fs
-	 * block size... */
-	reg->hr_blocks = reg->hr_fs_blocks;
-
-	tmp_bytes = reg->hr_fs_start_block << reg->hr_fs_block_bits;
-	reg->hr_start_block = tmp_bytes >> reg->hr_hb_block_bits;
-
-	mlog(ML_HEARTBEAT, "fs_block_bytes = %u, fs_block_bits = %u\n",
-	     reg->hr_fs_block_bytes, reg->hr_fs_block_bits);
-	mlog(ML_HEARTBEAT, "fs_start_block = %llu\n", reg->hr_fs_start_block);
 	mlog(ML_HEARTBEAT, "hr_start_block = %llu, hr_blocks = %u\n",
 	     reg->hr_start_block, reg->hr_blocks);
-	mlog(ML_HEARTBEAT, "hb block bytes = %u, hb block bits = %u\n",
-	     reg->hr_hb_block_bytes, reg->hr_hb_block_bits);
+	mlog(ML_HEARTBEAT, "hr_block_bytes = %u, hr_block_bits = %u\n",
+	     reg->hr_block_bytes, reg->hr_block_bits);
 }
 
 static int hb_map_slot_data(struct hb_region *reg)
 {
 	int i, j;
 	unsigned int last_slot;
-	unsigned int spp = reg->hr_hb_slots_per_page;
+	unsigned int spp = reg->hr_slots_per_page;
 	struct page *page;
 	char *raw;
 	struct hb_disk_slot *slot;
@@ -1026,9 +979,10 @@
 			BUG_ON((j + last_slot) >= reg->hr_blocks);
 
 			slot = &reg->hr_slots[j + last_slot];
-			slot->ds_raw_block = (struct hb_disk_heartbeat_block *) raw;
+			slot->ds_raw_block =
+				(struct hb_disk_heartbeat_block *) raw;
 
-			raw += reg->hr_hb_block_bytes;
+			raw += reg->hr_block_bytes;
 		}
 	}
 
@@ -1040,6 +994,7 @@
 				   size_t count)
 {
 	long fd;
+	int sectsize;
 	char *p = (char *)page;
 	struct file *filp = NULL;
 	struct inode *inode = NULL;
@@ -1059,12 +1014,10 @@
 	if (filp == NULL)
 		goto out;
 
-	if (reg->hr_fs_blocks == 0 || reg->hr_fs_start_block == 0)
+	if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
+	    reg->hr_block_bytes == 0)
 		goto out;
 
-	if (reg->hr_hb_block_bits > reg->hr_fs_block_bits)
-		goto out;
-
 	inode = igrab(filp->f_mapping->host);
 	if (inode == NULL)
 		goto out;
@@ -1082,8 +1035,17 @@
 
 	bdevname(reg->hr_bdev, reg->hr_dev_name);
 
-	hb_calculate_region_offsets(reg);
+	sectsize = bdev_hardsect_size(reg->hr_bdev);
+	if (sectsize != reg->hr_block_bytes) {
+		mlog(ML_ERROR,
+		     "blocksize %u incorrect for device, expected %d",
+		     reg->hr_block_bytes, sectsize);
+		ret = -EINVAL;
+		goto out;
+	}
 
+	hb_init_region_params(reg);
+
 	ret = hb_map_slot_data(reg);
 	if (ret) {
 		mlog_errno(ret);
@@ -1095,6 +1057,8 @@
 	reg->hr_task = kthread_run(hb_thread, reg, "hb-%s",
 				   reg->hr_item.ci_name);
 	if (IS_ERR(reg->hr_task)) {
+		ret = PTR_ERR(reg->hr_task);
+		mlog_errno(ret);
 		reg->hr_task = NULL;
 		goto out;
 	}
@@ -1127,11 +1091,6 @@
 	ssize_t (*store)(struct hb_region *, const char *, size_t);
 };
 
-static struct hb_region_attribute hb_region_attr_slot_bytes = {
-	.attr	= { .ca_owner = THIS_MODULE, .ca_name = "slot_bytes", .ca_mode = S_IRUGO | S_IWUSR },
-	.show	= hb_region_slot_bytes_read,
-	.store	= hb_region_slot_bytes_write,
-};
 static struct hb_region_attribute hb_region_attr_block_bytes = {
 	.attr	= { .ca_owner = THIS_MODULE, .ca_name = "block_bytes", .ca_mode = S_IRUGO | S_IWUSR },
 	.show	= hb_region_block_bytes_read,
@@ -1154,7 +1113,6 @@
 };
 
 static struct configfs_attribute *hb_region_attrs[] = {
-	&hb_region_attr_slot_bytes.attr,
 	&hb_region_attr_block_bytes.attr,
 	&hb_region_attr_start_block.attr,
 	&hb_region_attr_blocks.attr,
@@ -1226,8 +1184,6 @@
 	if (reg == NULL)
 		goto out; /* ENOMEM */
 
-	hb_init_region_params(reg, HB_DEFAULT_BLOCK_BITS);
-
 	config_item_init_type_name(&reg->hr_item, name, &hb_region_type);
 
 	ret = &reg->hr_item;
@@ -1374,8 +1330,9 @@
 	hb_fill_node_map(testing_map, sizeof(testing_map));
 
 	if (!test_bit(node_num, testing_map)) {
-		mlog(ML_HEARTBEAT, "this node (%u) does not have heartbeating "
-		     "enabled.\n", node_num);
+		mlog(ML_HEARTBEAT,
+		     "this node (%u) does not have heartbeating enabled.\n",
+		     node_num);
 		return 0;
 	}
 

Modified: trunk/fs/ocfs2/cluster/ocfs2_nodemanager.h
===================================================================
--- trunk/fs/ocfs2/cluster/ocfs2_nodemanager.h	2005-05-06 23:19:15 UTC (rev 2223)
+++ trunk/fs/ocfs2/cluster/ocfs2_nodemanager.h	2005-05-11 03:59:37 UTC (rev 2224)
@@ -30,7 +30,7 @@
 
 #include "ocfs2_heartbeat.h"
 
-#define NM_API_VERSION		1
+#define NM_API_VERSION		2
 
 #define NM_MAX_NODES		255
 #define NM_INVALID_SLOT_NUM	255



More information about the Ocfs2-commits mailing list