[Ocfs2-commits] mfasheh commits r1497 - branches/dlm-changes/src

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Sep 27 17:55:11 CDT 2004


Author: mfasheh
Date: 2004-09-27 17:55:09 -0500 (Mon, 27 Sep 2004)
New Revision: 1497

Modified:
   branches/dlm-changes/src/suballoc.c
   branches/dlm-changes/src/suballoc.h
Log:
* update the inode private bitmap info struct on our suballoc inodes.

* complete and enable the code to free bits from suballocators. We
  only do this for inodes right now.

* complete and enable the suballoc chain optimizing code.



Modified: branches/dlm-changes/src/suballoc.c
===================================================================
--- branches/dlm-changes/src/suballoc.c	2004-09-27 22:48:53 UTC (rev 1496)
+++ branches/dlm-changes/src/suballoc.c	2004-09-27 22:55:09 UTC (rev 1497)
@@ -80,6 +80,13 @@
 					    struct buffer_head *group_bh,
 					    unsigned int bit_off, 
 					    unsigned int num_bits);
+static int ocfs_relink_block_group(ocfs_journal_handle *handle,
+				   struct buffer_head *fe_bh,
+				   struct buffer_head *bg_bh,
+				   struct buffer_head *prev_bg_bh,
+				   u16 chain);
+static inline int ocfs_block_group_reasonably_empty(ocfs2_group_desc *bg);
+static inline u64 ocfs_which_suballoc_group(u64 block, unsigned int bit);
 
 static int ocfs2_block_group_fill(ocfs_journal_handle *handle, 
 				  struct inode *alloc_inode,
@@ -331,6 +338,8 @@
 	OCFS_I(alloc_inode)->ip_alloc_size = 
 		(u64)fe->i_clusters << osb->s_clustersize_bits;
 	fe->i_size = OCFS_I(alloc_inode)->ip_alloc_size;
+	OCFS_I(alloc_inode)->u.ip_bitinfo.used_bits = fe->id1.bitmap1.i_used;
+	OCFS_I(alloc_inode)->u.ip_bitinfo.total_bits = fe->id1.bitmap1.i_total;
 	up (&(OCFS_I(alloc_inode)->ip_sem));
 	alloc_inode->i_size = fe->i_size;
 	alloc_inode->i_blocks = (alloc_inode->i_size + osb->sb->s_blocksize - 1) >> osb->sb->s_blocksize_bits;
@@ -627,7 +636,6 @@
 	return best;
 }
 
-#ifdef OCFS2_OPTIMIZE_SUBALLOCATORS
 static int ocfs_relink_block_group(ocfs_journal_handle *handle,
 				   struct buffer_head *fe_bh,
 				   struct buffer_head *bg_bh,
@@ -646,6 +654,10 @@
 	OCFS_ASSERT(IS_VALID_GROUP_DESC(bg));
 	OCFS_ASSERT(IS_VALID_GROUP_DESC(prev_bg));
 
+	printk("In suballoc %llu, chain %u, move group %llu to top, "
+	       "prev = %llu\n", fe->i_blkno, chain, bg->bg_blkno, 
+	       prev_bg->bg_blkno);
+
 	fe_ptr = fe->id2.i_chain.cl_recs[chain].c_blkno;
 	bg_ptr = bg->bg_next_group;
 	prev_bg_ptr = prev_bg->bg_next_group;
@@ -709,7 +721,7 @@
 {
 	return bg->bg_free_bits_count >= (bg->bg_bits / 2);
 }
-#endif
+
 /* will give out up to bits_wanted contiguous bits. */
 static int ocfs_claim_suballoc_bits(ocfs_super *osb,
 				    ocfs_journal_handle *handle,
@@ -785,7 +797,6 @@
 			prev_group_bh = NULL;
 		}
 		next_group = bg->bg_next_group;
-//		brelse(group_bh);
 		prev_group_bh = group_bh;
 		group_bh = NULL;
 		status = ocfs_read_bh(osb, 
@@ -802,17 +813,17 @@
 		OCFS_ASSERT(IS_VALID_GROUP_DESC(bg));
 	}
 
-#ifdef OCFS2_OPTIMIZE_SUBALLOCATORS
-#define OCFS2_BG_RELINK_TRIGGER 3
-	if ((groups_read > OCFS2_BG_RELINK_TRIGGER) && ()) {
-		status = ocfs_relink_block_group(handle, ac->ac_bh, bg_bh, 
-						 prev_bg_bh, chain);
+#define OCFS2_BG_RELINK_TRIGGER 1
+	if ((prev_group_bh) 
+	    && (groups_read > OCFS2_BG_RELINK_TRIGGER) 
+	    && (ocfs_block_group_reasonably_empty(bg))) {
+		status = ocfs_relink_block_group(handle, ac->ac_bh, group_bh, 
+						 prev_group_bh, chain);
 		if (status < 0) {
 			LOG_ERROR_STATUS(status);
 			goto bail;
 		}
 	}
-#endif
 
 	status = ocfs_block_group_find_clear_bits(osb, 
 						  bg, 
@@ -861,6 +872,9 @@
 	       fe->i_blkno);
 	debug_suballoc_inode(fe);
 
+	down (&(OCFS_I(alloc_inode)->ip_sem));
+	OCFS_I(alloc_inode)->u.ip_bitinfo.used_bits = fe->id1.bitmap1.i_used;
+	up (&(OCFS_I(alloc_inode)->ip_sem));
 	*bg_blkno = bg->bg_blkno;
 bail:
 	if (group_bh)
@@ -940,7 +954,6 @@
 
 	OCFS_ASSERT(num_bits == 1);
 
-#warning "is this cast right?"
 	*fe_blkno = bg_blkno + (u64) (*suballoc_bit);
 	ac->ac_bits_given++;
 	status = 0;
@@ -949,24 +962,100 @@
 	return status;
 }
 
-#if 0
+static inline u64 ocfs_which_suballoc_group(u64 block, unsigned int bit)
+{
+	return(block - (u64) bit);
+}
+
+/*
+ * expects the suballoc inode to already be locked.
+ */
 int ocfs_free_suballoc_bits(ocfs_super *osb, 
 			    ocfs_journal_handle *handle, 
 			    struct inode *alloc_inode,
-			    struct buffer_head *alloc_bh) 
+			    struct buffer_head *alloc_bh,
+			    unsigned int start_bit,
+			    u64 start_block,
+			    unsigned int count) 
 {
 	int status = 0;
 	ocfs2_dinode *fe = (ocfs2_dinode *) alloc_bh->b_data;
+	ocfs2_chain_list *cl = &fe->id2.i_chain;
+	u64 bg_blkno;
+	struct buffer_head *group_bh = NULL;
+	ocfs2_group_desc *group;
+	unsigned int tmp;
 
+	LOG_ENTRY();
+
 	OCFS_ASSERT(IS_VALID_FILE_ENTRY(fe));
+	OCFS_ASSERT((count + start_bit) 
+		    <= ((u32) cl->cl_cpg * (u32) cl->cl_bpc));
 
-	//need to figure out the rest of the api here.
-	//don't forget to update bit counts on fe, chain record and
-	//block group.
+	bg_blkno = ocfs_which_suballoc_group(start_block, start_bit);
+	printk("freeing %u bits from group %llu, starting at %u "
+	       "(1st block = %llu, suballocator %llu)\n",
+	       count, bg_blkno, start_bit, start_block, 
+	       OCFS_I(alloc_inode)->ip_blkno);
 
+	status = ocfs_read_bh(osb, 
+			      bg_blkno << osb->sb->s_blocksize_bits, 
+			      &group_bh, 
+			      OCFS_BH_CACHED, 
+			      alloc_inode);
+	if (status < 0) {
+		LOG_ERROR_STATUS(status);
+		goto bail;
+	}
+
+	group = (ocfs2_group_desc *) group_bh->b_data;
+	OCFS_ASSERT(IS_VALID_GROUP_DESC(group));
+
+	status = ocfs_journal_access(handle, group_bh, 
+				     OCFS_JOURNAL_ACCESS_WRITE);
+	if (status < 0) {
+		LOG_ERROR_STATUS(status);
+		goto bail;
+	}
+
+	tmp = count;
+	while(tmp--)
+		clear_bit((start_bit + tmp), group->bg_bitmap);
+	group->bg_free_bits_count += count;
+
+	status = ocfs_journal_dirty(handle, group_bh);
+	if (status < 0) {
+		LOG_ERROR_STATUS(status);
+		goto bail;
+	}
+
+	status = ocfs_journal_access(handle, alloc_bh, 
+				     OCFS_JOURNAL_ACCESS_WRITE);
+	if (status < 0) {
+		LOG_ERROR_STATUS(status);
+		goto bail;
+	}
+
+	cl->cl_recs[group->bg_chain].c_free += count;
+	fe->id1.bitmap1.i_used -= count;
+
+	status = ocfs_journal_dirty(handle, alloc_bh);
+	if (status < 0) {
+		LOG_ERROR_STATUS(status);
+		goto bail;
+	}
+
+	down (&(OCFS_I(alloc_inode)->ip_sem));
+	OCFS_I(alloc_inode)->u.ip_bitinfo.used_bits = fe->id1.bitmap1.i_used;
+	up (&(OCFS_I(alloc_inode)->ip_sem));
+bail:
+	if (group_bh)
+		brelse(group_bh);
+
+	LOG_EXIT_STATUS(status);
 	return status;
 }
-#endif
+
 static inline void debug_bg(ocfs2_group_desc *bg) 
 {
 	printk("Block Group:\n");

Modified: branches/dlm-changes/src/suballoc.h
===================================================================
--- branches/dlm-changes/src/suballoc.h	2004-09-27 22:48:53 UTC (rev 1496)
+++ branches/dlm-changes/src/suballoc.h	2004-09-27 22:55:09 UTC (rev 1497)
@@ -49,5 +49,11 @@
 			u16 *suballoc_bit_start,
 			u32 *num_bits,
 			u64 *blkno_start);
-
+int ocfs_free_suballoc_bits(ocfs_super *osb, 
+			    ocfs_journal_handle *handle, 
+			    struct inode *alloc_inode,
+			    struct buffer_head *alloc_bh,
+			    unsigned int start_bit,
+			    u64 start_block,
+			    unsigned int count);
 #endif /* _CHAINALLOC_H_ */



More information about the Ocfs2-commits mailing list