[Ocfs2-tools-commits] jlbec commits r308 - in branches/dlm-changes: libocfs2 libocfs2/include mkfs.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Oct 1 17:28:01 CDT 2004


Author: jlbec
Date: 2004-10-01 17:28:00 -0500 (Fri, 01 Oct 2004)
New Revision: 308

Modified:
   branches/dlm-changes/libocfs2/extent_map.c
   branches/dlm-changes/libocfs2/include/ocfs2_fs.h
   branches/dlm-changes/libocfs2/inode_scan.c
   branches/dlm-changes/libocfs2/ocfs2_err.et.in
   branches/dlm-changes/mkfs.ocfs2/mkfs.c
Log:

WARNING, this breaks the disk something fierce.

o Move ocfs2_dinode fields around a lot.  Because ocfs2_disk_lock has
  a lot of unused space now, move it all into reserved space on the
  ocfs2_dinode, and move fields about to make it coalesce.
o Teach libocfs2/inode_scan.c how to scan the new chain-allocator based
  inode allocators.
o Teach mkfs to set i_clusters on the superblock to the size of the
  filesystem.



Modified: branches/dlm-changes/libocfs2/extent_map.c
===================================================================
--- branches/dlm-changes/libocfs2/extent_map.c	2004-10-01 17:06:10 UTC (rev 307)
+++ branches/dlm-changes/libocfs2/extent_map.c	2004-10-01 22:28:00 UTC (rev 308)
@@ -34,6 +34,8 @@
 
 #include "extent_map.h"
 
+/* FIXME: Use rbtrees.  Add lookup */
+
 struct extent_map_context {
 	ocfs2_cached_inode *cinode;
 	errcode_t errcode;

Modified: branches/dlm-changes/libocfs2/include/ocfs2_fs.h
===================================================================
--- branches/dlm-changes/libocfs2/include/ocfs2_fs.h	2004-10-01 17:06:10 UTC (rev 307)
+++ branches/dlm-changes/libocfs2/include/ocfs2_fs.h	2004-10-01 22:28:00 UTC (rev 308)
@@ -132,7 +132,7 @@
 
 static char *ocfs2_system_inode_names[NUM_SYSTEM_INODES] = {
 	/* Global system inodes (single copy) */
-	/* The first three are only used from userspace mfks/tunefs */
+	/* The first two are only used from userspace mfks/tunefs */
 	[BAD_BLOCK_SYSTEM_INODE]		"bad_blocks",
 	[GLOBAL_INODE_ALLOC_SYSTEM_INODE] 	"global_inode_alloc",
 
@@ -288,12 +288,9 @@
 typedef struct _ocfs2_disk_lock
 {
 /*00*/	__s16 dl_master;	/* Node number of current master */
-	__u16 dl_reserved1;
 	__u8 dl_level;		/* Lock level */
-	__u8 dl_reserved2[3];	/* Pad to u64 */
-	__u64 dl_reserved3;	/* was dl_seq_num */
-/*10*/	__u32 dl_reserved4[8];  /* was dl_node_map */
-/*30*/
+	__u8 dl_reserved1;
+/*04*/
 } ocfs2_disk_lock;
 
 /*
@@ -357,36 +354,33 @@
 					   belongs to */
 	__u16 i_suballoc_bit;		/* Bit offset in suballocater
 					   block group */
-/*10*/	__u64 i_reserved1;
-/*18*/	ocfs2_disk_lock i_disk_lock;	/* Lock structure */
-/*48*/	__u32 i_uid;			/* Owner UID */
+/*10*/	ocfs2_disk_lock i_disk_lock;	/* Lock structure */
+/*14*/	__u32 i_clusters;		/* Cluster count */
+/*18*/	__u32 i_uid;			/* Owner UID */
 	__u32 i_gid;			/* Owning GID */
-/*50*/	__u64 i_size;			/* Size in bytes */
+/*20*/	__u64 i_size;			/* Size in bytes */
 	__u16 i_mode;			/* File mode */
 	__u16 i_links_count;		/* Links count */
 	__u32 i_flags;			/* File flags */
-/*60*/	__u64 i_atime;			/* Access time */
+/*30*/	__u64 i_atime;			/* Access time */
 	__u64 i_ctime;			/* Creation time */
-/*70*/	__u64 i_mtime;			/* Modification time */
+/*40*/	__u64 i_mtime;			/* Modification time */
 	__u64 i_dtime;			/* Deletion time */
-/*80*/	__u64 i_blkno;			/* Offset on disk, in blocks */
-	__u32 i_clusters;		/* Cluster count */
-	__u32 i_reserved2;
-/*90*/	__u64 i_last_eb_blk;		/* Pointer to last extent
+/*50*/	__u64 i_blkno;			/* Offset on disk, in blocks */
+	__u64 i_last_eb_blk;		/* Pointer to last extent
 					   block */
-	__u64 i_reserved3;
-/*A0*/	__u64 i_reserved4;
-	__u64 i_reserved5;
-/*B0*/	__u64 i_reserved6;
-	union {
-		__u64 i_pad1;		/* Generic way to refer to this 64bit
-					   union */
+/*60*/	__u64 i_reserved1[11];
+/*B8*/	union {
+		__u64 i_pad1;		/* Generic way to refer to this
+					   64bit union */
 		struct {
 			__u64 i_rdev;	/* Device number */
 		} dev1;
-		struct {		/* Info for bitmap system inodes */
+		struct {		/* Info for bitmap system
+					   inodes */
 			__u32 i_used;	/* Bits (ie, clusters) used  */
-			__u32 i_total;	/* Total bits (clusters) available */
+			__u32 i_total;	/* Total bits (clusters)
+					   available */
 		} bitmap1;
 	} id1;				/* Inode type dependant 1 */
 /*C0*/	union {

Modified: branches/dlm-changes/libocfs2/inode_scan.c
===================================================================
--- branches/dlm-changes/libocfs2/inode_scan.c	2004-10-01 17:06:10 UTC (rev 307)
+++ branches/dlm-changes/libocfs2/inode_scan.c	2004-10-01 22:28:00 UTC (rev 308)
@@ -45,104 +45,150 @@
 	int next_inode_file;
 	ocfs2_cached_inode *cur_inode_alloc;
 	ocfs2_cached_inode **inode_alloc;
-	ocfs2_extent_map_entry *cur_entry;
+	ocfs2_chain_rec *cur_rec;
+	int next_rec;
+	ocfs2_group_desc *cur_desc;
+	unsigned int count;
 	uint64_t cur_blkno;
-	char *extent_buffer;
+	char *group_buffer;
 	char *cur_block;
-	uint32_t buffer_clusters;
-	uint64_t blocks_in_buffer;
-	uint64_t blocks_left;
-	uint32_t cpos;
+	int buffer_blocks;
+	int blocks_in_buffer;
+	unsigned int blocks_left;
+	uint64_t bpos;
 	int c_to_b_bits;
 };
 
 
 /*
- * This function is called by fill_extent_buffer when an extent has
- * been completely read.  It must not be called from the last extent.
+ * This function is called by fill_group_buffer when an alloc group has
+ * been completely read.  It must not be called from the last group.
  * ocfs2_get_next_inode() should have detected that condition.
  */
-static errcode_t get_next_extent(ocfs2_inode_scan *scan)
+static errcode_t get_next_group(ocfs2_inode_scan *scan)
 {
-	struct list_head *pos;
-	ocfs2_extent_map *em;
+	errcode_t ret;
 
-	em = scan->cur_inode_alloc->ci_map;
-	pos = scan->cur_entry->e_list.next;
-	if (pos == &em->em_extents)
+	if (!scan->cur_desc) {
+		if (scan->bpos)
+			abort();
+
+		ret = ocfs2_malloc_block(scan->fs->fs_io,
+					 &scan->cur_desc);
+		if (ret)
+			return ret;
+	}
+
+	if (scan->bpos)
+		scan->cur_blkno = scan->cur_desc->bg_next_group;
+
+	/*
+	 * scan->cur_blkno better be nonzero, either set by
+	 * get_next_chain() or valid from bg_next_group
+	 */ 
+	if (!scan->cur_blkno)
 		abort();
-	scan->cur_entry = list_entry(pos, ocfs2_extent_map_entry,
-				     e_list);
-	if (scan->cur_entry->e_rec.e_cpos != scan->cpos)
-		return OCFS2_ET_CORRUPT_EXTENT_BLOCK;
 
-	scan->cur_blkno = scan->cur_entry->e_rec.e_blkno;
+	ret = io_read_block(scan->fs->fs_io, scan->cur_blkno, 1,
+			    (char *)scan->cur_desc);
+	if (ret)
+		return (ret);
 
+	if (scan->cur_desc->bg_blkno != scan->cur_blkno)
+		return OCFS2_ET_CORRUPT_GROUP_DESC;
+
+	/* Skip past group descriptor block */
+	scan->cur_blkno++;
+	scan->count++;
+	scan->blocks_left--;
+	scan->bpos = scan->cur_blkno;
+
 	return 0;
 }
 
 /*
+ * This function is called by fill_group_buffer when an alloc chain
+ * has been completely read.  It must not be called  when the current
+ * inode alloc file has been read in its entirety.  This condition
+ * should have been detected by ocfs2_get_next_inode().
+ */
+static errcode_t get_next_chain(ocfs2_inode_scan *scan)
+{
+	ocfs2_dinode *di = scan->cur_inode_alloc->ci_inode;
+
+	if (scan->next_rec == di->id2.i_chain.cl_next_free_rec) {
+		if (!scan->next_rec) {
+			/*
+			 * The only way we can get here with next_rec
+			 * == cl_next_free_rec == 0 is if
+			 * bitmap1.i_total was non-zero.  But if i_total
+			 * was non-zero and we have no chains, we're
+			 * corrupt.
+			 */
+			return OCFS2_ET_CORRUPT_CHAIN;
+		} else
+			abort();
+	}
+
+	scan->cur_rec = &di->id2.i_chain.cl_recs[scan->next_rec];
+	scan->next_rec++;
+	scan->count = 0;
+	scan->bpos = 0;
+	scan->cur_blkno = scan->cur_rec->c_blkno;
+
+	return 0;
+}
+
+/*
  * This function is called by ocfs2_get_next_inode when it needs
  * to read in more clusters from the current inode alloc file.  It
  * must not be called when the current inode alloc file has been read
  * in its entirety.  This condition is detected by
  * ocfs2_get_next_inode().
  */
-static errcode_t fill_extent_buffer(ocfs2_inode_scan *scan)
+static errcode_t fill_group_buffer(ocfs2_inode_scan *scan)
 {
 	errcode_t ret;
-	uint64_t num_blocks;
-	uint32_t num_clusters;
+	int num_blocks;
 
-	if (scan->cpos > (scan->cur_entry->e_rec.e_cpos +
-			  scan->cur_entry->e_rec.e_clusters))
+	if (scan->cur_rec && (scan->count > scan->cur_rec->c_total))
+	    abort();
+
+	if (scan->cur_rec && (scan->bpos > (scan->cur_desc->bg_blkno +
+			  scan->cur_desc->bg_bits)))
 		abort();
 
-	if (scan->cpos == (scan->cur_entry->e_rec.e_cpos +
-			   scan->cur_entry->e_rec.e_clusters)) {
-		ret = get_next_extent(scan);
+	if (!scan->cur_rec || (scan->count == scan->cur_rec->c_total)) {
+		ret = get_next_chain(scan);
 		if (ret)
 			return ret;
 	}
+	
+	if (!scan->bpos || (scan->bpos == (scan->cur_desc->bg_blkno +
+					   scan->cur_desc->bg_bits))) {
+		ret = get_next_group(scan);
+		if (ret)
+			return ret;
+	}
 
-	num_clusters = scan->cur_entry->e_rec.e_clusters -
-		(scan->cpos - scan->cur_entry->e_rec.e_cpos);
 
-	if (num_clusters > scan->buffer_clusters)
-		num_clusters = scan->buffer_clusters;
+	num_blocks = (scan->cur_desc->bg_blkno +
+		      scan->cur_desc->bg_bits) - scan->bpos;
 
-	num_blocks = (uint64_t)num_clusters << scan->c_to_b_bits;
+	if (num_blocks > scan->buffer_blocks)
+		num_blocks = scan->buffer_blocks;
+
 	ret = io_read_block(scan->fs->fs_io,
 			    scan->cur_blkno,
 			    num_blocks,
-			    scan->extent_buffer);
+			    scan->group_buffer);
 	if (ret)
 		return ret;
 
-	scan->cpos += num_clusters;
+	scan->bpos += num_blocks;
 	scan->blocks_in_buffer = num_blocks;
-	scan->cur_block = scan->extent_buffer;
+	scan->cur_block = scan->group_buffer;
 
-	if (!scan->cur_blkno) {
-		/*
-		 * inode_alloc[0] is the global inode allocator.  It
-		 * contains the first extent of the filesystem,
-		 * including block zero.  If this is that allocator
-		 * skip it past the superblock inode.
-		 *
-		 * (next_inode_file is one because we just incremented
-		 *  it.)
-		 */
-		if (scan->next_inode_file == 1) {
-			scan->cur_blkno = OCFS2_SUPER_BLOCK_BLKNO + 1;
-			scan->cur_block += (scan->cur_blkno *
-					    scan->fs->fs_blocksize);
-			scan->blocks_left -= scan->cur_blkno;
-			scan->blocks_in_buffer -= scan->cur_blkno;
-		}
-		/* FIXME: error otherwise */
-	}
-
 	return 0;
 }
 
@@ -151,7 +197,7 @@
 {
 	ocfs2_cached_inode *cinode = scan->cur_inode_alloc;
 
-	if (cinode && (scan->cpos != cinode->ci_inode->i_clusters))
+	if (cinode && scan->blocks_left)
 		abort();
 
 	do {
@@ -163,15 +209,14 @@
 		cinode = scan->cur_inode_alloc;
 
 		scan->next_inode_file++;
-	} while (list_empty(&cinode->ci_map->em_extents));
+	} while (!cinode->ci_inode->id1.bitmap1.i_total);
 
-	scan->cur_entry = list_entry(cinode->ci_map->em_extents.next,
-				     ocfs2_extent_map_entry, e_list);
-	scan->cpos = scan->cur_entry->e_rec.e_cpos;
-	/* could check cpos == 0 */
-	scan->cur_blkno = scan->cur_entry->e_rec.e_blkno;
+	scan->next_rec = 0;
+	scan->count = 0;
+	scan->cur_blkno = 0;
+	scan->cur_rec = 0;
 	scan->blocks_left =
-		cinode->ci_inode->i_clusters << scan->c_to_b_bits;
+		cinode->ci_inode->id1.bitmap1.i_total;
 
 	return 0;
 }
@@ -192,12 +237,12 @@
 	}
 
 	if (!scan->blocks_in_buffer) {
-		ret = fill_extent_buffer(scan);
+		ret = fill_group_buffer(scan);
 		if (ret)
 			return ret;
 	}
 	
-	/* Should swap the inode */
+	/* FIXME: Should swap the inode */
 	memcpy(inode, scan->cur_block, scan->fs->fs_blocksize);
 
 	scan->cur_block += scan->fs->fs_blocksize;
@@ -205,6 +250,7 @@
 	scan->blocks_left--;
 	*blkno = scan->cur_blkno;
 	scan->cur_blkno++;
+	scan->count++;
 
 	return 0;
 }
@@ -236,16 +282,17 @@
 		goto out_scan;
 
 	/* Minimum 8 inodes in the buffer */
-	if ((fs->fs_clustersize / fs->fs_blocksize) < 8) {
-		scan->buffer_clusters =
+	scan->buffer_blocks = fs->fs_clustersize / fs->fs_blocksize;
+	if (scan->buffer_blocks < 8) {
+		scan->buffer_blocks =
 			((8 * fs->fs_blocksize) +
 			 (fs->fs_clustersize - 1)) /
 			fs->fs_clustersize;
-	} else {
-		scan->buffer_clusters = 1;
+		scan->buffer_blocks <<= scan->c_to_b_bits;
 	}
-	ret = ocfs2_malloc(sizeof(char) * scan->buffer_clusters *
-			   fs->fs_clustersize, &scan->extent_buffer);
+
+	ret = ocfs2_malloc(sizeof(char) * scan->buffer_blocks *
+			   fs->fs_blocksize, &scan->group_buffer);
 	if (ret)
 		goto out_inode_files;
 
@@ -274,11 +321,10 @@
 			goto out_cleanup;
 	}
 
-	for (i = 0; i < scan->num_inode_alloc; i++) {
-		ret = ocfs2_load_extent_map(fs, scan->inode_alloc[i]);
-		if (ret)
-			goto out_cleanup;
-	}
+	/*
+	 * FIXME: Should this pre-read all the group descriptors like
+	 * the old code read all the extent maps?
+	 */
 
 	*ret_scan = scan;
 
@@ -311,7 +357,8 @@
 		}
 	}
 
-	ocfs2_free(&scan->extent_buffer);
+	ocfs2_free(&scan->group_buffer);
+	ocfs2_free(&scan->cur_desc);
 	ocfs2_free(&scan->inode_alloc);
 	ocfs2_free(&scan);
 
@@ -352,7 +399,7 @@
 	}
 	filename = argv[1];
 
-	ret = ocfs2_open(filename, OCFS2_FLAG_RO, 0, 0, &fs);
+	ret = ocfs2_open(filename, OCFS2_FLAG_RO|OCFS2_FLAG_BUFFERED, 0, 0, &fs);
 	if (ret) {
 		com_err(argv[0], ret,
 			"while opening file \"%s\"", filename);

Modified: branches/dlm-changes/libocfs2/ocfs2_err.et.in
===================================================================
--- branches/dlm-changes/libocfs2/ocfs2_err.et.in	2004-10-01 17:06:10 UTC (rev 307)
+++ branches/dlm-changes/libocfs2/ocfs2_err.et.in	2004-10-01 22:28:00 UTC (rev 308)
@@ -89,4 +89,7 @@
 ec	OCFS2_ET_CORRUPT_GROUP_DESC,
 	"Group descriptor is corrupt"
 
+ec	OCFS2_ET_CORRUPT_CHAIN,
+	"Chain allocator is corrupt"
+
 	end

Modified: branches/dlm-changes/mkfs.ocfs2/mkfs.c
===================================================================
--- branches/dlm-changes/mkfs.ocfs2/mkfs.c	2004-10-01 17:06:10 UTC (rev 307)
+++ branches/dlm-changes/mkfs.ocfs2/mkfs.c	2004-10-01 22:28:00 UTC (rev 308)
@@ -424,8 +424,8 @@
 	alloc_from_bitmap (s, need, s->global_bm, &system_dir_rec.extent_off, &system_dir_rec.extent_len);
 	system_dir_rec.fe_off = alloc_inode(s, &system_dir_rec.suballoc_bit);
 	system_dir->record = &system_dir_rec;
-	add_entry_to_directory(s, system_dir, ".", system_dir_rec.extent_off, OCFS2_FT_DIR);
-	add_entry_to_directory(s, system_dir, "..", system_dir_rec.extent_off, OCFS2_FT_DIR);
+	add_entry_to_directory(s, system_dir, ".", system_dir_rec.fe_off, OCFS2_FT_DIR);
+	add_entry_to_directory(s, system_dir, "..", system_dir_rec.fe_off, OCFS2_FT_DIR);
 
 	for (i = 0; i < NUM_SYSTEM_INODES; i++) {
 		num = (system_files[i].global) ? 1 : s->initial_nodes;
@@ -1240,6 +1240,7 @@
 
 	strcpy(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE);
 	di->i_suballoc_node = cpu_to_le16((__u16)-1);
+	di->i_suballoc_bit = cpu_to_le16((__u16)-1);
 
 	di->i_atime = 0;
 	di->i_ctime = cpu_to_le64(s->format_time);
@@ -1247,6 +1248,7 @@
 	di->i_blkno = cpu_to_le64(super_off >> s->blocksize_bits);
 	di->i_flags = cpu_to_le32(OCFS2_VALID_FL | OCFS2_SYSTEM_FL |
 				  OCFS2_SUPER_BLOCK_FL);
+	di->i_clusters = s->volume_size_in_clusters;
 	di->id2.i_super.s_major_rev_level = cpu_to_le16(OCFS2_MAJOR_REV_LEVEL);
 	di->id2.i_super.s_minor_rev_level = cpu_to_le16(OCFS2_MINOR_REV_LEVEL);
 	di->id2.i_super.s_root_blkno = cpu_to_le64(root_rec->fe_off >> s->blocksize_bits);



More information about the Ocfs2-tools-commits mailing list