[Ocfs2-commits] khackel commits r1103 - branches/format-changes/src

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jun 15 16:22:07 CDT 2004


Author: khackel
Date: 2004-06-15 15:22:06 -0500 (Tue, 15 Jun 2004)
New Revision: 1103

Modified:
   branches/format-changes/src/alloc.c
   branches/format-changes/src/file.c
   branches/format-changes/src/inode.c
   branches/format-changes/src/journal.c
   branches/format-changes/src/namei.c
   branches/format-changes/src/ocfs_journal.h
   branches/format-changes/src/sysfile.c
Log:
changes to make system files extend properly using ocfs_extend_file
bugfix for extend credits ;-)
this tree is still broken with respect to the local alloc!
may need to comment out ocfs_load_local_alloc in super.c to run



Modified: branches/format-changes/src/alloc.c
===================================================================
--- branches/format-changes/src/alloc.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/alloc.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -2969,7 +2969,8 @@
 	if ( (sysfile && ClusterCount > free_bits) || 
 	     (!sysfile && ClusterCount > 
 	         (free_bits - ((8 * ONE_MEGA_BYTE) >> osb->s_clustersize_bits))) ){
-		LOG_ERROR_STR ("Disk Full");
+		LOG_ERROR_ARGS("Disk Full: ClusterCount=%u, free_bits=%u, sysfile=%s\n",
+			       ClusterCount, free_bits, sysfile?"yes":"no");
 		status = -ENOSPC;
 		goto leave;
 	}
@@ -3036,7 +3037,7 @@
 		goto leave;
 	}
 
-	LOG_TRACE_ARGS ("setting at bit offset=%u\n", bitoffset);
+	LOG_TRACE_ARGS ("setting %u bits at bit offset=%u\n", ClusterCount, bitoffset);
 
 	ocfs_set_bits(osb->sb, handle, &osb->cluster_bitmap, bitoffset,
 		      ClusterCount);
@@ -3084,7 +3085,7 @@
  *
  * You need to be holding node_alloc_sem!
  */
-int ocfs_alloc_node_block (ocfs_super * osb, __u64 FileSize, __u64 * DiskOffset, __u64 * file_off, __u32 NodeNum, __u32 Type, ocfs_journal_handle *handle)
+int ocfs_alloc_node_block (ocfs_super * osb, __u64 bytes_wanted, __u64 * DiskOffset, __u64 * file_off, __u32 NodeNum, __u32 Type, ocfs_journal_handle *handle)
 {
 	int status = 0;
 	int startbh, numblocks;
@@ -3102,13 +3103,15 @@
 	int bm_file = 0;
 	int alloc_file = 0;
 	struct buffer_head *bh = NULL;
+	struct buffer_head *alloc_bh = NULL;
 	ocfs2_dinode *fe = NULL;
+	ocfs2_dinode *alloc_fe = NULL;
 	int needs_uninit = 0;
 	int delay_lockrel = 0;
 	struct inode *inode = NULL; /* alloc bitmap file inode */
 	struct inode *alloc_inode = NULL; /* alloc file inode */
 
-	LOG_ENTRY_ARGS("(FileSize = (%llu), Type=%d)\n", FileSize,Type);
+	LOG_ENTRY_ARGS("(bytes_wanted = (%llu), Type=%d)\n", bytes_wanted,Type);
 
 	switch (Type) {
 		case DISK_ALLOC_EXTENT_NODE:
@@ -3166,20 +3169,19 @@
 		goto leave;
 	}
 
-	numBits = ((FileSize + (blockSize-1)) >> blockSizeBits);
+	numBits = ((bytes_wanted + (blockSize-1)) >> blockSizeBits);
 	numBytes = (u64)numBits << blockSizeBits;
 
-	/* Read in the bitmap file for the dir alloc and look for the
+	/* Read in the bitmap file for the alloc and look for the
 	 * required space, if found */
 	fe = OCFS_BH_GET_DATA_READ(bh);
-	fileSize = fe->i_size;
+	prevFileSize = fileSize = fe->i_size;
 	allocSize = (u64)fe->i_clusters << osb->s_clustersize_bits;
 	OCFS_BH_PUT_DATA(bh);
-	
-	prevFileSize = fileSize;
 
+
+
 	if ((fileSize != 0) && (allocSize != 0)) {
-		/* Round this off to dirnodesize */
 		ocfs_initialize_bitmap(osb->sb, &bitmap,
 				       (__u32)fileSize * 8,
 				       (__u32)allocSize * 8);
@@ -3192,12 +3194,7 @@
 			goto leave;
 		}
 
-		/* Find the requisite number of bits... */
-
-		/* This function will check for clear bits in the Bitmap for */
-		/* consective clear bits equal to ClusterCount */
-		foundBit = ocfs_find_clear_bits(osb, &bitmap, numBits,
-						0, 0);
+		foundBit = ocfs_find_clear_bits(osb, &bitmap, numBits, 0, 0);
 	}
 
 	/* It returns -1 on failure , otherwise ByteOffset points at the */
@@ -3206,19 +3203,44 @@
 
 	if (foundBit == -1) {
 		/* if not found add more allocation to the file and try again. */
+		//extent = ONE_MEGA_BYTE;
 		extent = ( ((numBits * blockSize) + (ONE_MEGA_BYTE-1)) >> 20 ) << 20;
-		
-		newFileSize = alloc_inode->i_size;
-		allocSize = OCFS_I(alloc_inode)->alloc_size;
 
+#warning maybe take this out and put a verifyupdateinode in here
+		status = ocfs_read_bh(osb, GET_INODE_FEOFF(alloc_inode), 
+			&alloc_bh, OCFS_BH_CACHED, alloc_inode);
+		if (status < 0) {
+			LOG_ERROR_STATUS (status);
+			goto leave;
+		}
+
+		alloc_fe = OCFS_BH_GET_DATA_READ(alloc_bh);
+		newFileSize = alloc_fe->i_size;
+		allocSize = (u64)alloc_fe->i_clusters << osb->s_clustersize_bits;
+		if (newFileSize != alloc_inode->i_size ||
+		    allocSize != OCFS_I(alloc_inode)->alloc_size) {
+			LOG_ERROR_ARGS("aha! alloc inode was out of date! "
+			       		"newFileSize=%llu, i_size=%llu, "
+			       		"allocSize=%llu, alloc_size=%llu\n",
+			       		newFileSize, alloc_inode->i_size,
+			       		allocSize, OCFS_I(alloc_inode)->alloc_size);
+		}
+		OCFS_BH_PUT_DATA(alloc_bh);
+
+		//newFileSize = alloc_inode->i_size;
+		//allocSize = OCFS_I(alloc_inode)->alloc_size;
+
 		/* This is for OUI optimzation to allocate more disk
 		 * space for directory allocations */
 		
 		if (allocSize > 0)
 			extent *= 2;
 		
-		status = ocfs_extend_file (osb, newFileSize + extent, GET_INODE_FEOFF(alloc_inode),
-					   handle, alloc_inode, NULL, 1, NULL);
+		LOG_TRACE_ARGS("extending the alloc file to %llu\n",
+		       newFileSize + extent);
+		status = ocfs_extend_file (osb, newFileSize + extent, 
+						GET_INODE_FEOFF(alloc_inode),
+					   	handle, alloc_inode, NULL, 1, NULL);
 		if (status < 0) {
 			LOG_ERROR_STATUS (status);
 			goto leave;
@@ -3231,6 +3253,7 @@
 		 * do a put_data first! */
 		/* Calculate the new bitmap size */
 		
+		LOG_TRACE_ARGS("extending the bitmap file to %llu\n", bitMapSize);
 		status = ocfs_extend_file (osb, bitMapSize, GET_INODE_FEOFF(inode), 
 					   handle, inode, NULL, 1, bh);
 		if (status < 0) {
@@ -3242,6 +3265,8 @@
 		 * we can trust the sizes here */
 		fileSize = fe->i_size;
 		allocSize = (u64)fe->i_clusters << osb->s_clustersize_bits;
+		LOG_TRACE_ARGS("fileSize=%llu, allocSize=%llu\n",
+		       fileSize, allocSize);
 		OCFS_BH_PUT_DATA(bh);
 
 		if (needs_uninit)
@@ -3261,14 +3286,14 @@
 			goto leave;
 		}
 		
-		foundBit = prevFileSize * 8;
+		foundBit = ocfs_find_clear_bits(osb, &bitmap, numBits, 0, 0);
 
 		delay_lockrel = 1;
 		if (Type == DISK_ALLOC_EXTENT_NODE)
 			atomic_inc(&osb->alloc_stats.ext_extends);
 	}
 
-	LOG_TRACE_ARGS ("byte offset=%d\n", foundBit);
+	LOG_TRACE_ARGS ("bit offset=%d, num=%d\n", foundBit, numBits);
 
 	ocfs_set_bits(osb->sb, handle, &bitmap, foundBit, numBits);
 
@@ -3307,6 +3332,8 @@
 
 	if (bh != NULL)
 		brelse(bh);
+	if (alloc_bh != NULL)
+		brelse(alloc_bh);
 
 	LOG_EXIT_STATUS (status);
 	return status;

Modified: branches/format-changes/src/file.c
===================================================================
--- branches/format-changes/src/file.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/file.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -841,7 +841,7 @@
 		LOG_TRACE_STR
 		    ("Generic_file_write ok, asking for OIN update now");
 		inode->i_size = newsize;
-		inode->i_blocks = (newsize + sb->s_blocksize) >> sb->s_blocksize_bits;
+		inode->i_blocks = (newsize + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 		up(&osb->extend_sem);
 	}
 
@@ -1101,7 +1101,8 @@
 	int credits;
 	struct inode *ext_alloc_inode = NULL;
 
-	LOG_ENTRY ();
+	LOG_ENTRY_ARGS("(off=%llu, file_size=%llu, system=%s)\n",
+		       file_off, file_size, system_file?"yes":"no");
 
 	if (!inode)
 		BUG();
@@ -1134,12 +1135,14 @@
 	OCFS_BH_PUT_DATA(bh);
 	fe = NULL;
 
+	LOG_TRACE_ARGS("current_alloc=%llu, alloc_size=%llu\n",
+		       current_alloc, alloc_size);
 	if (passed_handle == NULL) {
 		credits = ocfs_calc_extend_credits(osb->sb,
 						   (__u32) alloc_size); 
 
 		/* cannot call start_trans with a locked buffer head. */
-		handle = ocfs_start_trans(osb, OCFS_FILE_EXTEND_CREDITS);
+		handle = ocfs_start_trans(osb, credits);
 		if (handle == NULL) {
 			LOG_ERROR_STATUS(status = -ENOMEM);
 			goto leave;
@@ -1209,6 +1212,8 @@
 
 		status = ocfs_find_space(osb, alloc_size, &bitmapOffset,
 					 &numClustersAlloc, system_file, handle);
+		LOG_TRACE_ARGS("find_space: alloc_size=%llu, returned off=%llu, num=%llu\n",
+			       alloc_size, bitmapOffset, numClustersAlloc);
 		if (status < 0) {
 			OCFS_BH_PUT_DATA(bh);
 			if (status != -ENOSPC && status != -EINTR)
@@ -1222,7 +1227,43 @@
 		OCFS_BH_PUT_DATA(bh);
 		fe = NULL;
 
-		{
+		if (system_file) {
+			struct buffer_head **bhs = NULL;
+			int numbhs = actualLength >> osb->sb->s_blocksize_bits;
+			int i;
+			char *data;
+			
+			bhs = kmalloc(numbhs*sizeof(struct buffer_head *), GFP_KERNEL);
+			if (!bhs) {
+				status = -ENOMEM;
+				LOG_ERROR_STATUS(status);
+				goto leave;
+			}
+			memset(bhs, 0, numbhs * sizeof(struct buffer_head *));
+			
+			status = ocfs_read_bhs(osb, actualDiskOffset,
+						actualLength, bhs, 0, NULL);
+			if (status < 0) {
+				kfree(bhs);
+				LOG_ERROR_STATUS(status);
+				goto leave;
+			}
+			
+			for(i = 0; i < numbhs; i++) {
+				data = OCFS_BH_GET_DATA_WRITE(bhs[i]);
+				memset(data, 0, osb->sb->s_blocksize);
+				OCFS_BH_PUT_DATA(bhs[i]);
+			}
+			
+			status = ocfs_write_bhs(osb, bhs, numbhs, 0, NULL);
+			for(i = 0; i < numbhs; i++)
+				brelse(bhs[i]);
+			kfree(bhs);
+			if (status < 0) {
+				LOG_ERROR_STATUS(status);
+				goto leave;
+			}
+		} else {
 			struct buffer_head *alloc_bh;
 			unsigned long block;
 			struct super_block *sb = osb->sb;
@@ -1230,9 +1271,12 @@
 			for (block = (unsigned long)(actualDiskOffset >> sb->s_blocksize_bits); 
 			     block < (unsigned long)((actualDiskOffset+actualLength) >> sb->s_blocksize_bits);
 			     block++) {
+				alloc_bh = sb_getblk(sb, block);
+				if (!alloc_bh) {
+					LOG_ERROR_STATUS(status=-EIO);
+					goto leave;
+				}
 				LOG_TRACE_ARGS("setting block %lu as new!\n", block);
-				alloc_bh = sb_getblk(sb, block);
-#warning unchecked allocation here
 				alloc_bh->b_state |= (1UL << BH_New);
 				brelse(alloc_bh);
 			}
@@ -1270,8 +1314,20 @@
 
 	/* Update tha file size and add the new one to old one. */
 	fe->i_size = file_size;
-	LOG_TRACE_ARGS("fe->i_clusters = %u\n", fe->i_clusters);
+	LOG_TRACE_ARGS("fe: i_clusters = %u, i_size=%llu\n", 
+		       fe->i_clusters, fe->i_size);
 
+	/* NOTE: this is a bit of a hack; unlike regular files, 
+	 * system files do not have another opportunity to update
+	 * the inode/i_private fields */
+	if (system_file) {
+		OCFS_I(inode)->alloc_size = (u64)fe->i_clusters << osb->s_clustersize_bits;
+		inode->i_size = fe->i_size;
+		inode->i_blocks = (inode->i_size + osb->sb->s_blocksize - 1) >> osb->sb->s_blocksize_bits;
+	}
+	LOG_TRACE_ARGS("inode: alloc_size=%llu, i_size=%llu\n",
+		       OCFS_I(inode)->alloc_size, inode->i_size);
+
 	if (attr)
 		ocfs_fe_set_attributes(fe, attr);
 	/* Set the Valid bit and reset the change bit here... TODO */
@@ -1432,7 +1488,7 @@
 			ocfs_delete_all_extent_maps(osb, inode);
 		}
 		inode->i_size = newsize;
-		inode->i_blocks = (newsize + sb->s_blocksize) >> sb->s_blocksize_bits;
+		inode->i_blocks = (newsize + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 		up (&(OCFS_I(inode)->priv_sem));
 	}
 

Modified: branches/format-changes/src/inode.c
===================================================================
--- branches/format-changes/src/inode.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/inode.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -352,6 +352,8 @@
 	sb = inode->i_sb;
 	osb = OCFS_SB(sb);
 
+	// this means that read_inode cannot create a superblock 
+	// inode today.  change if needed.
 	if (!IS_VALID_FILE_ENTRY(fe)) {
 		printk("ocfs2: invalid file entry!\n");
 		BUG();
@@ -371,7 +373,7 @@
 	inode->i_uid = fe->i_uid;
 	inode->i_gid = fe->i_gid;
 	inode->i_blksize = (u32)osb->s_clustersize;	// sb->s_blocksize;
-	inode->i_blocks = (fe->i_size + sb->s_blocksize) >> sb->s_blocksize_bits;
+	inode->i_blocks = (fe->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 	inode->i_mapping->a_ops = &ocfs_aops;
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 	inode->i_attr_flags |= ATTR_FLAG_NOATIME;
@@ -386,8 +388,6 @@
 
 	OCFS_I(inode)->alloc_size =
 		(u64)fe->i_clusters << osb->s_clustersize_bits;
-	printk("oin alloc_size=%llu, fe->i_clusters=%u\n",
-	       OCFS_I(inode)->alloc_size, fe->i_clusters);
 	OCFS_I(inode)->inode = inode;
 	OCFS_I(inode)->chng_seq_num = DISK_LOCK(fe)->dl_seq_num;
 	OCFS_I(inode)->u.fe_private = fe->id1.i_pad1;
@@ -418,6 +418,9 @@
 			       OCFS_I(inode)->u.ip_bitinfo.total_bits);
 	} else if (le32_to_cpu(fe->i_flags) & OCFS2_SUPER_BLOCK_FL) {
 		LOG_TRACE_ARGS("superblock inode: i_ino=%lu\n", inode->i_ino);
+		// we can't actually hit this as read_inode can't handle
+		// superblocks today ;-)
+		BUG();
 	}
 	
 	switch (inode->i_mode & S_IFMT) {
@@ -2014,10 +2017,11 @@
 		OCFS_I(inode)->alloc_size = 
 			(u64)fe->i_clusters << osb->s_clustersize_bits;
 		inode->i_size = fe->i_size;
-printk("verifyupdate: setting nlink from %d to %d for %llu\n", inode->i_nlink, fe->i_links_count, GET_INODE_FEOFF(inode));
+		LOG_TRACE_ARGS("verifyupdate: setting nlink from %d to %d for %llu\n", 
+			       inode->i_nlink, fe->i_links_count, GET_INODE_FEOFF(inode));
 		inode->i_nlink = fe->i_links_count;
 		OCFS_I(inode)->chng_seq_num = DISK_LOCK(fe)->dl_seq_num;
-		inode->i_blocks = (inode->i_size + osb->sb->s_blocksize) >> osb->sb->s_blocksize_bits;
+		inode->i_blocks = (inode->i_size + osb->sb->s_blocksize - 1) >> osb->sb->s_blocksize_bits;
 		inode->i_uid = fe->i_uid;
 		inode->i_gid = fe->i_gid;
 		inode->i_mode = fe->i_mode;

Modified: branches/format-changes/src/journal.c
===================================================================
--- branches/format-changes/src/journal.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/journal.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -770,7 +770,10 @@
 			(unsigned long long)bh->b_blocknr);
 
 	if (handle->num_buffs >= handle->max_buffs) {
-		LOG_ERROR_STR("Cannot add buffer to full transaction!");
+		LOG_ERROR_ARGS("Cannot add buffer to full transaction! "
+			       "num_buffs=%d, max_buffs=%d, block=%llu\n",
+			       handle->num_buffs, handle->max_buffs,
+			       (unsigned long long)bh->b_blocknr);
 		goto done;
 	}
 

Modified: branches/format-changes/src/namei.c
===================================================================
--- branches/format-changes/src/namei.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/namei.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -1376,7 +1376,7 @@
 	fe = NULL;
 
 	inode->i_size = newsize;
-	inode->i_blocks = (newsize + sb->s_blocksize) >> sb->s_blocksize_bits;
+	inode->i_blocks = (newsize + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 
 	ocfs_init_lockres (osb, inode);
 	status = ocfs_inode_notify_open(osb, new_fe_bh, handle, inode);

Modified: branches/format-changes/src/ocfs_journal.h
===================================================================
--- branches/format-changes/src/ocfs_journal.h	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/ocfs_journal.h	2004-06-15 20:22:06 UTC (rev 1103)
@@ -334,6 +334,7 @@
 #define OCFS_FILE_EXTEND_CREDITS (OCFS_SINGLE_FILE_EXTEND_CREDITS * 3         \
 				  + 1 + 2 + OCFS_JOURNAL_FUZZ_CREDITS)
 
+
 /* Now that we journal bitmap writes, this might get a bit more
  * complicated, use this function to determine how many credits are
  * needed for an extend. Unfortunately, we're in bytes because the
@@ -342,14 +343,27 @@
 static inline int ocfs_calc_extend_credits(struct super_block *sb,
 					   __u32 bytes_wanted)
 {
-	int bitmap_blocks;
+	int bitmap_blocks, sysfile_bitmap_blocks;
 	unsigned int bits_wanted;
 	bits_wanted = ocfs_clusters_for_bytes(sb, bytes_wanted);
 	/* take advantage of the fact that we always allocate in one 
 	 * large chunk. */
 	bitmap_blocks = ocfs_blocks_for_bits(sb, bits_wanted) + 1;
 
-	return (bitmap_blocks + OCFS_FILE_EXTEND_CREDITS);
+	/* need to account for any bitmap system file extension.
+	 * system files extend by up to 2mb, so the corresponding bitmap
+	 * file (which are all blocksize allocators today) will require
+	 * enough credits to zero the new bitmap data for that 2mb.
+	 * even on a 512byte sect size, this is only 512 bytes of bitmap
+	 * data, so it's really never more than two extra blocks.  add
+	 * some extra in case the request spans the new blocks + old ones. */
+	
+	/* NOTE: if we ever add an allocator that allocates something
+	 * other than blocksize chunks, or expect requests to be lots of 
+	 * bits at a time, this assumption doesn't hold */
+	sysfile_bitmap_blocks = 4;
+	
+	return (bitmap_blocks + sysfile_bitmap_blocks + OCFS_FILE_EXTEND_CREDITS);
 }
 
 /* fe, anything along new 'edge' of tree + fuzz*/

Modified: branches/format-changes/src/sysfile.c
===================================================================
--- branches/format-changes/src/sysfile.c	2004-06-14 23:45:24 UTC (rev 1102)
+++ branches/format-changes/src/sysfile.c	2004-06-15 20:22:06 UTC (rev 1103)
@@ -161,10 +161,6 @@
 		}
 		if (status == 0) {
 			// found all remaining
-			if (blocks < (__u32)contig_blocks) {
-				LOG_ERROR_ARGS("blocks (%u) < contig_blocks (%llu)\n",
-					       blocks, contig_blocks);
-			}
 		} else if (status == -EFAIL && contig_blocks > 0) {
 			// found some
 		} else {



More information about the Ocfs2-commits mailing list