[Ocfs2-commits] mfasheh commits r2576 - branches/readonly-operation/fs/ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Sep 15 21:00:30 CDT 2005


Author: mfasheh
Date: 2005-09-15 21:00:29 -0500 (Thu, 15 Sep 2005)
New Revision: 2576

Modified:
   branches/readonly-operation/fs/ocfs2/alloc.c
   branches/readonly-operation/fs/ocfs2/extent_map.c
   branches/readonly-operation/fs/ocfs2/localalloc.c
   branches/readonly-operation/fs/ocfs2/ocfs2.h
   branches/readonly-operation/fs/ocfs2/suballoc.c
Log:
* Convert the rest of our read-only marking BUG_ON* macros to actually go
  read-only now.                



Modified: branches/readonly-operation/fs/ocfs2/alloc.c
===================================================================
--- branches/readonly-operation/fs/ocfs2/alloc.c	2005-09-15 22:59:36 UTC (rev 2575)
+++ branches/readonly-operation/fs/ocfs2/alloc.c	2005-09-16 02:00:29 UTC (rev 2576)
@@ -311,7 +311,11 @@
 	for(i = 0; i < new_blocks; i++) {
 		bh = new_eb_bhs[i];
 		eb = (ocfs2_extent_block *) bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			status = -EIO;
+			goto bail;
+		}
 		eb_el = &eb->h_list;
 
 		status = ocfs2_journal_access(handle, inode, bh,
@@ -435,7 +439,12 @@
 	}
 
 	eb = (ocfs2_extent_block *) new_eb_bh->b_data;
-	OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+	if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+		OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+		status = -EIO;
+		goto bail;
+	}
+
 	eb_el = &eb->h_list;
 	fe = (ocfs2_dinode *) fe_bh->b_data;
 	fe_el = &fe->id2.i_list;
@@ -553,7 +562,14 @@
 		i = 0;
 		while(el->l_tree_depth) {
 			next_free = le16_to_cpu(el->l_next_free_rec);
-			OCFS2_BUG_ON_RO(next_free == 0);
+			if (next_free == 0) {
+				ocfs2_error(inode->i_sb,
+					    "Dinode %"MLFu64" has a bad "
+					    "extent list\n",
+					    OCFS2_I(inode)->ip_blkno);
+				status = -EIO;
+				goto bail;
+			}
 			next_blkno = le64_to_cpu(el->l_recs[next_free - 1].e_blkno);
 
 			BUG_ON(i >= num_bhs);
@@ -564,7 +580,12 @@
 				goto bail;
 			}
 			eb = (ocfs2_extent_block *) eb_bhs[i]->b_data;
-			OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+			if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+				OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb,
+								 eb);
+				status = -EIO;
+				goto bail;
+			}
 
 			status = ocfs2_journal_access(handle, inode, eb_bhs[i],
 						      OCFS2_JOURNAL_ACCESS_WRITE);
@@ -586,7 +607,14 @@
 		 * bottom-most leaf in order to update it with the
 		 * actual extent data below. */
 		next_free = le16_to_cpu(el->l_next_free_rec);
-		OCFS2_BUG_ON_RO(next_free == 0);
+		if (next_free == 0) {
+			ocfs2_error(inode->i_sb,
+				    "Dinode %"MLFu64" has a bad "
+				    "extent list\n",
+				    OCFS2_I(inode)->ip_blkno);
+			status = -EIO;
+			goto bail;
+		}
 		le32_add_cpu(&el->l_recs[next_free - 1].e_clusters,
 			     new_clusters);
 		/* (num_bhs - 1) to avoid the leaf */
@@ -620,7 +648,15 @@
 	} else if (le16_to_cpu(el->l_next_free_rec) &&
 		   (le32_to_cpu(el->l_recs[i].e_clusters) == 0)) {
 		/* having an empty extent at eof is legal. */
-		OCFS2_BUG_ON_RO(el->l_recs[i].e_cpos != fe->i_clusters);
+		if (el->l_recs[i].e_cpos != fe->i_clusters) {
+			ocfs2_error(inode->i_sb,
+				    "Dinode %"MLFu64" trailing extent is bad: "
+				    "cpos (%u) != number of clusters (%u)\n",
+				    le32_to_cpu(el->l_recs[i].e_cpos),
+				    le32_to_cpu(fe->i_clusters));
+			status = -EIO;
+			goto bail;
+		}
 		el->l_recs[i].e_blkno = cpu_to_le64(start_blk);
 		el->l_recs[i].e_clusters = cpu_to_le32(new_clusters);
 	} else {
@@ -708,10 +744,23 @@
 	el = &fe->id2.i_list;
 
 	while(le16_to_cpu(el->l_tree_depth) > 1) {
-		OCFS2_BUG_ON_RO(le16_to_cpu(el->l_next_free_rec) == 0);
+		if (le16_to_cpu(el->l_next_free_rec) == 0) {
+			ocfs2_error(inode->i_sb, "Dinode %"MLFu64" has empty "
+				    "extent list (next_free_rec == 0)\n",
+				    OCFS2_I(inode)->ip_blkno);
+			status = -EIO;
+			goto bail;
+		}
 		i = le16_to_cpu(el->l_next_free_rec) - 1;
 		blkno = le64_to_cpu(el->l_recs[i].e_blkno);
-		OCFS2_BUG_ON_RO(!blkno);
+		if (!blkno) {
+			ocfs2_error(inode->i_sb, "Dinode %"MLFu64" has extent "
+				    "list where extent # %d has no physical "
+				    "block start\n",
+				    OCFS2_I(inode)->ip_blkno, i);
+			status = -EIO;
+			goto bail;
+		}
 
 		if (bh) {
 			brelse(bh);
@@ -726,7 +775,11 @@
 		}
 
 		eb = (ocfs2_extent_block *) bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			status = -EIO;
+			goto bail;
+		}
 		el = &eb->h_list;
 
 		if (le16_to_cpu(el->l_next_free_rec) <
@@ -1465,7 +1518,11 @@
 		}
 		eb = (ocfs2_extent_block *) bh->b_data;
 		el = &eb->h_list;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			status = -EIO;
+			goto bail;
+		}
 	} while (el->l_tree_depth);
 
 	*new_last_eb = bh;
@@ -1596,7 +1653,11 @@
 			goto bail;
 		}
 		eb = (ocfs2_extent_block *)eb_bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			status = -EIO;
+			goto bail;
+		}
 		el = &(eb->h_list);
 
 		status = ocfs2_journal_access(handle, inode, eb_bh,
@@ -1760,7 +1821,11 @@
 			goto bail;
 		}
 		eb = (ocfs2_extent_block *) last_eb_bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			status = -EIO;
+			goto bail;
+		}
 		el = &(eb->h_list);
 	}
 
@@ -1901,7 +1966,13 @@
 			goto bail;
 		}
 		eb = (ocfs2_extent_block *) last_eb_bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+
+			brelse(last_eb_bh);
+			status = -EIO;
+			goto bail;
+		}
 		el = &(eb->h_list);
 		if (le32_to_cpu(el->l_recs[0].e_cpos) >= new_i_clusters)
 			metadata_delete = 1;

Modified: branches/readonly-operation/fs/ocfs2/extent_map.c
===================================================================
--- branches/readonly-operation/fs/ocfs2/extent_map.c	2005-09-15 22:59:36 UTC (rev 2575)
+++ branches/readonly-operation/fs/ocfs2/extent_map.c	2005-09-16 02:00:29 UTC (rev 2576)
@@ -237,7 +237,11 @@
 		if (ret)
 			goto out_free;
 		eb = (ocfs2_extent_block *)eb_bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			ret = -EIO;
+			goto out_free;
+		}
 		el = &eb->h_list;
 	}
 
@@ -299,7 +303,11 @@
 			return ret;
 		}
 		eb = (ocfs2_extent_block *)bh->b_data;
-		OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(eb);
+		if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+			OCFS2_RO_ON_INVALID_EXTENT_BLOCK(inode->i_sb, eb);
+			brelse(bh);
+			return -EIO;
+		}
 		el = &eb->h_list;
 	} else {
 		spin_unlock(&OCFS2_I(inode)->ip_lock);

Modified: branches/readonly-operation/fs/ocfs2/localalloc.c
===================================================================
--- branches/readonly-operation/fs/ocfs2/localalloc.c	2005-09-15 22:59:36 UTC (rev 2575)
+++ branches/readonly-operation/fs/ocfs2/localalloc.c	2005-09-16 02:00:29 UTC (rev 2576)
@@ -40,6 +40,7 @@
 #include "journal.h"
 #include "localalloc.h"
 #include "suballoc.h"
+#include "super.h"
 #include "sysfile.h"
 
 #include "buffer_head_io.h"
@@ -490,8 +491,16 @@
 
 	alloc = (ocfs2_dinode *) osb->local_alloc_bh->b_data;
 
-	OCFS2_BUG_ON_RO(le32_to_cpu(alloc->id1.bitmap1.i_used) !=
-			ocfs2_local_alloc_count_bits(alloc));
+	if (le32_to_cpu(alloc->id1.bitmap1.i_used) !=
+	    ocfs2_local_alloc_count_bits(alloc)) {
+		ocfs2_error(osb->sb, "local alloc inode %"MLFu64" says it has "
+			    "%u free bits, but a count shows %u\n",
+			    le64_to_cpu(alloc->i_blkno),
+			    le32_to_cpu(alloc->id1.bitmap1.i_used),
+			    ocfs2_local_alloc_count_bits(alloc));
+		status = -EIO;
+		goto bail;
+	}
 
 	free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
 		le32_to_cpu(alloc->id1.bitmap1.i_used);

Modified: branches/readonly-operation/fs/ocfs2/ocfs2.h
===================================================================
--- branches/readonly-operation/fs/ocfs2/ocfs2.h	2005-09-15 22:59:36 UTC (rev 2575)
+++ branches/readonly-operation/fs/ocfs2/ocfs2.h	2005-09-16 02:00:29 UTC (rev 2576)
@@ -345,10 +345,6 @@
 	return ret;
 }
 
-/* Helps document which BUG's should really just force the file system
- * to go readonly */
-#define OCFS2_BUG_ON_RO(x) BUG_ON((x))
-
 #define OCFS2_IS_VALID_DINODE(ptr)					\
 	(!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE))
 
@@ -363,21 +359,23 @@
 #define OCFS2_IS_VALID_EXTENT_BLOCK(ptr)				\
 	(!strcmp((ptr)->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE))
 
-#define OCFS2_BUG_ON_INVALID_EXTENT_BLOCK(__eb)	do {			\
-	mlog_bug_on_msg(!OCFS2_IS_VALID_EXTENT_BLOCK((__eb)),		\
+#define OCFS2_RO_ON_INVALID_EXTENT_BLOCK(__sb, __eb)	do {		\
+	typeof(__eb) ____eb = (__eb);					\
+	ocfs2_error((__sb), 						\
 		"Extent Block # %"MLFu64" has bad signature %.*s\n",	\
-		(__eb)->h_blkno, 7,					\
-		(__eb)->h_signature);					\
+		(____eb)->h_blkno, 7,					\
+		(____eb)->h_signature);					\
 } while (0);
 
 #define OCFS2_IS_VALID_GROUP_DESC(ptr)					\
 	(!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE))
 
-#define OCFS2_BUG_ON_INVALID_GROUP_DESC(__gd)	do {			\
-	mlog_bug_on_msg(!OCFS2_IS_VALID_GROUP_DESC((__gd)),		\
+#define OCFS2_RO_ON_INVALID_GROUP_DESC(__sb, __gd)	do {		\
+	typeof(__gd) ____gd = (__gd);					\
+		ocfs2_error((__sb),					\
 		"Group Descriptor # %"MLFu64" has bad signature %.*s\n",\
-		(__gd)->bg_blkno, 7,					\
-		(__gd)->bg_signature);					\
+		(____gd)->bg_blkno, 7,					\
+		(____gd)->bg_signature);				\
 } while (0);
 
 static inline unsigned long ino_from_blkno(struct super_block *sb,

Modified: branches/readonly-operation/fs/ocfs2/suballoc.c
===================================================================
--- branches/readonly-operation/fs/ocfs2/suballoc.c	2005-09-15 22:59:36 UTC (rev 2575)
+++ branches/readonly-operation/fs/ocfs2/suballoc.c	2005-09-16 02:00:29 UTC (rev 2576)
@@ -156,7 +156,13 @@
 
 	mlog_entry_void();
 
-	OCFS2_BUG_ON_RO(((unsigned long long) bg_bh->b_blocknr) != group_blkno);
+	if (((unsigned long long) bg_bh->b_blocknr) != group_blkno) {
+		ocfs2_error(alloc_inode->i_sb, "group block (%"MLFu64") "
+			    "!= b_blocknr (%llu)\n", group_blkno,
+			    (unsigned long long) bg_bh->b_blocknr);
+		status = -EIO;
+		goto bail;
+	}
 
 	status = ocfs2_journal_access(handle,
 				      alloc_inode,
@@ -664,7 +670,10 @@
 	int offset, start, found, status = 0;
 	ocfs2_group_desc *bg = (ocfs2_group_desc *) bg_bh->b_data;
 
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
+	if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(osb->sb, bg);
+		return -EIO;
+	}
 
 	found = start = best_offset = best_size = 0;
 	bitmap = bg->bg_bitmap;
@@ -731,7 +740,11 @@
 
 	mlog_entry_void();
 
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
+	if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
+		status = -EIO;
+		goto bail;
+	}
 	BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits);
 
 	mlog(0, "block_group_set_bits: off = %u, num = %u\n", bit_off,
@@ -805,8 +818,16 @@
 		status = -EIO;
 		goto out;
 	}
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(prev_bg);
+	if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
+		status = -EIO;
+		goto out;
+	}
+	if (!OCFS2_IS_VALID_GROUP_DESC(prev_bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, prev_bg);
+		status = -EIO;
+		goto out;
+	}
 
 	mlog(0, "In suballoc %"MLFu64", chain %u, move group %"MLFu64" to "
 	     "top, prev = %"MLFu64"\n",
@@ -897,12 +918,17 @@
 		ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb),
 							group_bh, bits_wanted,
 							&tmp_off, &tmp_found);
-		if (!ret) {
-			if (min_bits <= tmp_found) {
-				*bit_off = tmp_off;
-				*bits_found = tmp_found;
-				search = 0; /* success */
-			}
+		if (ret)
+			return ret;
+
+		/* ocfs2_block_group_find_clear_bits() might
+		 * return success, but we still want to return
+		 * -ENOSPC unless it found the minimum number
+		 * of bits. */
+		if (min_bits <= tmp_found) {
+			*bit_off = tmp_off;
+			*bits_found = tmp_found;
+			search = 0; /* success */
 		}
 	}
 
@@ -959,7 +985,11 @@
 		goto bail;
 	}
 	bg = (ocfs2_group_desc *) group_bh->b_data;
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
+	if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
+		status = -EIO;
+		goto bail;
+	}
 
 	status = -ENOSPC;
 	/* for now, the chain search is a bit simplistic. We just use
@@ -985,7 +1015,11 @@
 			goto bail;
 		}
 		bg = (ocfs2_group_desc *) group_bh->b_data;
-		OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
+		if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+			OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
+			status = -EIO;
+			goto bail;
+		}
 	}
 	if (status < 0) {
 		if (status != -ENOSPC)
@@ -1380,7 +1414,11 @@
 
 	mlog_entry_void();
 
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(bg);
+	if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
+		status = -EIO;
+		goto bail;
+	}
 
 	mlog(0, "off = %u, num = %u\n", bit_off, num_bits);
 
@@ -1454,7 +1492,11 @@
 	}
 
 	group = (ocfs2_group_desc *) group_bh->b_data;
-	OCFS2_BUG_ON_INVALID_GROUP_DESC(group);
+	if (!OCFS2_IS_VALID_GROUP_DESC(group)) {
+		OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, group);
+		status = -EIO;
+		goto bail;
+	}
 	BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits));
 
 	status = ocfs2_block_group_clear_bits(handle, alloc_inode,



More information about the Ocfs2-commits mailing list