[Ocfs2-commits] khackel commits r1754 - trunk/cluster

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jan 11 16:36:20 CST 2005


Author: khackel
Date: 2005-01-11 16:36:18 -0600 (Tue, 11 Jan 2005)
New Revision: 1754

Modified:
   trunk/cluster/dlm_compat.h
   trunk/cluster/heartbeat.c
Log:
* added zab's changes for getblk stuff to get 2.6 working
  will just try to get a buffer_head for the current device
  blocksize, to avoid trouble when fs comes along and calls
  set_blocksize during the superblock probe
* put on-disk time in explicitly little-endian format


Modified: trunk/cluster/dlm_compat.h
===================================================================
--- trunk/cluster/dlm_compat.h	2005-01-10 23:57:56 UTC (rev 1753)
+++ trunk/cluster/dlm_compat.h	2005-01-11 22:36:18 UTC (rev 1754)
@@ -40,6 +40,7 @@
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 # include <linux/locks.h>
+# include <linux/blkdev.h>
 #else
 # include <linux/buffer_head.h>
 #endif
@@ -117,9 +118,28 @@
 	return &__sk->tp_info.af_tcp;
 }
 #endif
+static inline int ocfs_dev_bits(kdev_t dev)
+{
+	return blksize_bits(block_size(dev));
+}
 
 #else  /* LINUX_VERSION_CODE < 2.6 */
 
+static inline int ocfs_dev_bits(dev_t dev)
+{
+	struct block_device *bd = bdget(dev);
+	int ret = -EINVAL;
+
+	if (bd == NULL)
+		goto out;
+
+	ret = bd->bd_inode->i_blkbits;
+	bdput(bd);
+out:
+	return ret;
+
+}
+
 static inline struct buffer_head *getblk(dev_t dev, sector_t block, int size)
 {
 	struct block_device *bd = bdget(dev);

Modified: trunk/cluster/heartbeat.c
===================================================================
--- trunk/cluster/heartbeat.c	2005-01-10 23:57:56 UTC (rev 1753)
+++ trunk/cluster/heartbeat.c	2005-01-11 22:36:18 UTC (rev 1754)
@@ -168,6 +168,67 @@
 	submit_bh(rw, bh);
 }
 
+/* 
+ * hb_init_disk_hb_group() sets disk->blocksize_bits which defines the block
+ * size that we'll use to calculate block offsets.  The blocksize of the
+ * device might change under us, though.  this detects when that happens
+ * and tries to lookup the bh again with the newer blocksize.  The exciting
+ * wrinkle here is that its fatal to call __getblk() with the wrong block
+ * size in some 2.6 kernels.
+ *
+ * We only ever use a few bytes of the block so it is ok that we return
+ * a smaller bh than what is implied by blocksize_bits.  We're just fixing
+ * up addressing here.
+ */
+static struct buffer_head *hb_getblk(int orig_blkno, cluster_disk *disk)
+{
+	/* XXX getblk() takes an int block in 2.4 :/ */
+	int blkno;
+	int bits, dev_bits;
+	struct buffer_head *bh = NULL;
+
+	bits = disk->blocksize_bits;
+	blkno = orig_blkno;
+
+	dev_bits = ocfs_dev_bits(disk->dev);
+	if (dev_bits < 0)
+		goto out;
+
+	if (dev_bits < bits)
+		blkno <<= bits - dev_bits;
+	else if (dev_bits > bits)
+		blkno >>= dev_bits - bits;
+
+	bh = getblk(disk->dev, blkno, 1 << dev_bits);
+out:
+	return bh;
+}
+
+static struct buffer_head *hb_get_locked_mapped(hb_disk_slot *slot,
+						int ino,
+						cluster_disk *disk)
+{
+	struct buffer_head *bh = NULL;
+
+	bh = slot->bh;
+	if (bh) {
+		lock_buffer(bh);
+		if (buffer_mapped(bh))
+			goto out;
+		slot->bh = NULL;
+		unlock_buffer(bh);
+		brelse(bh);
+	}
+
+	slot->bh = hb_getblk(ino + disk->start_block, disk);
+	if (slot->bh) {
+		bh = slot->bh;
+		lock_buffer(bh);
+	}
+out:
+	return bh;
+}
+
 static int hb_do_disk_heartbeat(void *page)
 {
 	nm_group_inode_private *priv;
@@ -176,11 +237,11 @@
 	struct buffer_head *bh;
 	hb_disk_slot *slot;
 	hb_disk_heartbeat_block *hb_block;
-	int ino, idx, ret, i;
+	int rw, ino, idx, ret, i;
 	struct inode **dead_nodes, **live_nodes;
 	LIST_HEAD(tmplist);
-	u64 blkno;
 	cluster_disk *disk;
+	u64 cputime;
 
 	// NM_MAX_NODES is 255
 	dead_nodes = page;
@@ -200,10 +261,8 @@
 
 		idx = 0;
 		while ((slot = nm_iterate_group_disk_slots(group, &idx))) {
-retry_submit:
-			bh = slot->bh;
+
 			node = slot->inode;
-
 			if (!node) {
 				hbprintk("no inode in slot %d!\n", idx);
 				idx++;
@@ -211,47 +270,47 @@
 			}
 			ino = nm_get_node_global_index(node);
 
+			bh = hb_get_locked_mapped(slot, ino, disk);
+			if (bh == NULL) {
+				hbprintk("getblk failed in slot %d!\n",
+					 idx);
+				idx++;
+				continue;
+			}
+			
 			if (ino == nm_this_node(group)) {
-				lock_buffer(bh);
-				if (!buffer_mapped(bh)) {
-					blkno = (unsigned long long) bh->b_blocknr;
-					unlock_buffer(bh);
-					brelse(bh);
-					slot->bh = getblk(disk->dev,
-							  blkno,
-							  (1 << disk->blocksize_bits));
-					goto retry_submit;
-				}
 				memset(bh->b_data, 0, bh->b_size);
 				hb_block = (hb_disk_heartbeat_block *)bh->b_data;
-				hb_block->time = OCFS_CURRENT_SECONDS;
-				if (!hb_block->time)
-					hb_block->time = 1;
+				BUG_ON(bh->b_size < sizeof(*hb_block));
+
+				/* TODO: time stuff */
+				cputime = OCFS_CURRENT_SECONDS;
+				if (!cputime)
+					cputime = 1;
+				hb_block->time = cpu_to_le64(cputime);
+
 				set_buffer_uptodate(bh);
 				clear_buffer_dirty(bh);
-				bh->b_end_io = hb_end_buffer_io_sync;
-				hb_submit_bh(WRITE, bh);
+				rw = WRITE;
 			} else {
-				lock_buffer(bh);
-				if (!buffer_mapped(bh)) {
-					blkno = (unsigned long long) bh->b_blocknr;
-					unlock_buffer(bh);
-					brelse(bh);
-					slot->bh = getblk(disk->dev,
-							  blkno,
-							  (1 << disk->blocksize_bits));
-					goto retry_submit;
-				}
 				clear_buffer_uptodate(bh);
-				bh->b_end_io = hb_end_buffer_io_sync;
-				hb_submit_bh(READ, bh);
+				rw = READ;
 			}
+
+			bh->b_end_io = hb_end_buffer_io_sync;
+			hb_submit_bh(rw, bh);
 			idx++;
 		}
 	
 		idx = 0;
 		while ((slot = nm_iterate_group_disk_slots(group, &idx))) {
 			bh = slot->bh;
+			if (!bh) {
+				hbprintk("no bh in slot %d!\n", idx);
+				idx++;
+				continue;
+			}
+
 			node = slot->inode;
 			if (!node) {
 				hbprintk("no inode in slot %d!\n", idx);
@@ -263,15 +322,17 @@
 
 			wait_on_buffer(bh);
 			hb_block = (hb_disk_heartbeat_block *)bh->b_data;
-			if (hb_block->time != slot->last_time) {
+
+			/* TODO: time stuff */
+			cputime = le64_to_cpu(hb_block->time);
+			if (slot->last_time != cputime) {
 				if (slot->state == HB_NODE_STATE_INIT) {
 					hbprintk("first time for this node!\n");
 					live_nodes[ino] = node;
 					slot->state = HB_NODE_STATE_UP;
 				}
-				node->i_atime = mk_inode_time(hb_block->time,
-							      0);
-				slot->last_time = hb_block->time;
+				node->i_atime = mk_inode_time(cputime, 0);
+				slot->last_time = cputime;
 				slot->margin = HB_DISK_MARGIN;
 				hb_do_callbacks(HB_NODE_RESPONDED_CB, group, node, idx);
 			} else {
@@ -604,7 +665,7 @@
 		slot->last_time = 0;
 		slot->margin = HB_INITIAL_DISK_MARGIN;
 #warning needs to change for 2.6
-		slot->bh = getblk(disk->dev, (int)block, (1 << disk->blocksize_bits));
+		slot->bh = hb_getblk(block, disk);
 		slot->state = HB_NODE_STATE_INIT;
 	} else {
 		hbprintk("doing nothing for group add for non-disk heartbeat group\n");



More information about the Ocfs2-commits mailing list