[Ocfs2-tools-commits] jlbec commits r1331 - branches/iocache/libocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Mar 27 08:58:26 PDT 2007


Author: jlbec
Date: 2007-03-27 08:58:25 -0700 (Tue, 27 Mar 2007)
New Revision: 1331

Modified:
   branches/iocache/libocfs2/unix_io.c
Log:

Fix two bugs:

1) Multiblock reads and writes weren't moving the data pointer.  Bad Joel!
2) Cached writes that had errors syncing to disk would leave the new data
   in the cache.  This data might not be reflected on disk.  Now, when
   the real write fails, we drop the block from the cache.

This patch also consolidates the code for dropping a block from the cache
and the code for stealing the LRU block.



Modified: branches/iocache/libocfs2/unix_io.c
===================================================================
--- branches/iocache/libocfs2/unix_io.c	2007-03-27 07:29:06 UTC (rev 1330)
+++ branches/iocache/libocfs2/unix_io.c	2007-03-27 15:58:25 UTC (rev 1331)
@@ -212,6 +212,29 @@
 	list_add_tail(&icb->icb_list, &ic->ic_lru);
 }
 
+static void io_cache_disconnect(struct io_cache *ic,
+				struct io_cache_block *icb)
+{
+	/*
+	 * This icb should longer be looked up.
+	 * If rb_parent is NULL, it's already disconnected.
+	 */
+	if (icb->icb_node.rb_parent) {
+		rb_erase(&icb->icb_node, &ic->ic_lookup);
+		memset(&icb->icb_node, 0, sizeof(struct rb_node));
+	}
+}
+
+static struct io_cache_block *io_cache_pop_lru(struct io_cache *ic)
+{
+	struct io_cache_block *icb;
+
+	icb = list_entry(ic->ic_lru.next, struct io_cache_block, icb_list);
+	io_cache_disconnect(ic, icb);
+
+	return icb;
+}
+
 static errcode_t io_cache_read_one_block(io_channel *channel, int64_t blkno,
 					 char *data)
 {
@@ -223,14 +246,8 @@
 	if (icb)
 		goto found;
 
-	/*
-	 * Ok, this blkno isn't in the cache.  Steal something.
-	 */
-	icb = list_entry(ic->ic_lru.next, struct io_cache_block, icb_list);
-	if (icb->icb_node.rb_parent) {
-		rb_erase(&icb->icb_node, &ic->ic_lookup);
-		memset(&icb->icb_node, 0, sizeof(struct rb_node));
-	}
+	/* Ok, this blkno isn't in the cache.  Steal something. */
+	icb = io_cache_pop_lru(ic);
 
 	/*
 	 * If the read fails, we leave the block at the end of the LRU
@@ -258,7 +275,7 @@
 	int i;
 	errcode_t ret = 0;
 
-	for (i = 0; i < count; i++, blkno++) {
+	for (i = 0; i < count; i++, blkno++, data += channel->io_blksize) {
 		ret = io_cache_read_one_block(channel, blkno, data);
 		if (ret)
 			break;
@@ -278,14 +295,8 @@
 	if (icb)
 		goto found;
 
-	/*
-	 * Ok, this blkno isn't in the cache.  Steal something.
-	 */
-	icb = list_entry(ic->ic_lru.next, struct io_cache_block, icb_list);
-	if (icb->icb_node.rb_parent) {
-		rb_erase(&icb->icb_node, &ic->ic_lookup);
-		memset(&icb->icb_node, 0, sizeof(struct rb_node));
-	}
+	/* Ok, this blkno isn't in the cache.  Steal something. */
+	icb = io_cache_pop_lru(ic);
 
 	icb->icb_blkno = blkno;
 	io_cache_insert(ic, icb);
@@ -295,6 +306,9 @@
 	io_cache_seen(ic, icb);
 
 	ret = unix_io_write_block(channel, blkno, 1, icb->icb_buf);
+	if (ret)
+		io_cache_disconnect(ic, icb);
+
 	return ret;
 }
 
@@ -305,7 +319,7 @@
 	int i;
 	errcode_t ret = 0;
 
-	for (i = 0; i < count; i++, blkno++) {
+	for (i = 0; i < count; i++, blkno++, data += channel->io_blksize) {
 		ret = io_cache_write_one_block(channel, blkno, data);
 		if (ret)
 			break;




More information about the Ocfs2-tools-commits mailing list