Skip to contentSkip to conversation

struct superblock cleanup - minixfs

PATCH In review Brian Gerst 2 participants 2 messages Mar 11, 2002 – Mar 12, 2002 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 struct superblock cleanup - minixfs

These two patches are the start of cleaning up the union of filesystem-specific structures in struct super_block. The goal is to remove dependence on filesystem headers in fs.h. The first patch abstracts the access to the minix_sb_info structure through the function minix_sb(). The second patch switches to using kmalloc to allocate the structure.

Patches are against 2.5.6.

Signature · 1 line
						Brian Gerst
fs/minix/bitmap.c +26 -23
diff -urN -X scripts/dontdiff linux-2.5.6/fs/minix/bitmap.c linux/fs/minix/bitmap.c
@@ -52,6 +52,7 @@
 void minix_free_block(struct inode * inode, int block)
 {
 	struct super_block * sb = inode->i_sb;
+	struct minix_sb_info * sbi = minix_sb(sb);
 	struct buffer_head * bh;
 	unsigned int bit,zone;
 
@@ -59,19 +60,19 @@
 		printk("trying to free block on nonexistent device\n");
 		return;
 	}
-	if (block < sb->u.minix_sb.s_firstdatazone ||
-	    block >= sb->u.minix_sb.s_nzones) {
+	if (block < sbi->s_firstdatazone ||
+	    block >= sbi->s_nzones) {
 		printk("trying to free block not in datazone\n");
 		return;
 	}
-	zone = block - sb->u.minix_sb.s_firstdatazone + 1;
+	zone = block - sbi->s_firstdatazone + 1;
 	bit = zone & 8191;
 	zone >>= 13;
-	if (zone >= sb->u.minix_sb.s_zmap_blocks) {
+	if (zone >= sbi->s_zmap_blocks) {
 		printk("minix_free_block: nonexistent bitmap buffer\n");
 		return;
 	}
-	bh = sb->u.minix_sb.s_zmap[zone];
+	bh = sbi->s_zmap[zone];
 	if (!minix_test_and_clear_bit(bit,bh->b_data))
 		printk("free_block (%s:%d): bit already cleared\n",
 		       sb->s_id, block);
@@ -82,6 +83,7 @@
 int minix_new_block(struct inode * inode)
 {
 	struct super_block * sb = inode->i_sb;
+	struct minix_sb_info * sbi = minix_sb(sb);
 	struct buffer_head * bh;
 	int i,j;
 
@@ -92,8 +94,8 @@
 repeat:
 	j = 8192;
 	bh = NULL;
-	for (i = 0; i < sb->u.minix_sb.s_zmap_blocks; i++) {
-		bh = sb->u.minix_sb.s_zmap[i];
+	for (i = 0; i < sbi->s_zmap_blocks; i++) {
+		bh = sbi->s_zmap[i];
 		if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
 			break;
 	}
@@ -104,25 +106,26 @@
 		goto repeat;
 	}
 	mark_buffer_dirty(bh);
-	j += i*8192 + sb->u.minix_sb.s_firstdatazone-1;
-	if (j < sb->u.minix_sb.s_firstdatazone ||
-	    j >= sb->u.minix_sb.s_nzones)
+	j += i*8192 + sbi->s_firstdatazone-1;
+	if (j < sbi->s_firstdatazone ||
+	    j >= sbi->s_nzones)
 		return 0;
 	return j;
 }
 
 unsigned long minix_count_free_blocks(struct super_block *sb)
 {
-	return (count_free(sb->u.minix_sb.s_zmap, sb->u.minix_sb.s_zmap_blocks,
-		sb->u.minix_sb.s_nzones - sb->u.minix_sb.s_firstdatazone + 1)
-		<< sb->u.minix_sb.s_log_zone_size);
+	struct minix_sb_info *sbi = minix_sb(sb);
+	return (count_free(sbi->s_zmap, sbi->s_zmap_blocks,
+		sbi->s_nzones - sbi->s_firstdatazone + 1)
+		<< sbi->s_log_zone_size);
 }
 
 struct minix_inode *
 minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
 {
 	int block;
-	struct minix_sb_info *sbi = &sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(sb);
 	struct minix_inode *p;
 
 	if (!ino || ino > sbi->s_ninodes) {
@@ -146,7 +149,7 @@
 minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
 {
 	int block;
-	struct minix_sb_info *sbi = &sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(sb);
 	struct minix2_inode *p;
 
 	*bh = NULL;
@@ -198,17 +201,17 @@
 	struct buffer_head * bh;
 	unsigned long ino;
 
-	if (inode->i_ino < 1 || inode->i_ino > inode->i_sb->u.minix_sb.s_ninodes) {
+	if (inode->i_ino < 1 || inode->i_ino > minix_sb(inode->i_sb)->s_ninodes) {
 		printk("free_inode: inode 0 or nonexistent inode\n");
 		return;
 	}
 	ino = inode->i_ino;
-	if ((ino >> 13) >= inode->i_sb->u.minix_sb.s_imap_blocks) {
+	if ((ino >> 13) >= minix_sb(inode->i_sb)->s_imap_blocks) {
 		printk("free_inode: nonexistent imap in superblock\n");
 		return;
 	}
 
-	bh = inode->i_sb->u.minix_sb.s_imap[ino >> 13];
+	bh = minix_sb(inode->i_sb)->s_imap[ino >> 13];
 	minix_clear_inode(inode);
 	clear_inode(inode);
 	if (!minix_test_and_clear_bit(ino & 8191, bh->b_data))
@@ -233,8 +236,8 @@
 	bh = NULL;
 	*error = -ENOSPC;
 	lock_super(sb);
-	for (i = 0; i < sb->u.minix_sb.s_imap_blocks; i++) {
-		bh = inode->i_sb->u.minix_sb.s_imap[i];
+	for (i = 0; i < minix_sb(sb)->s_imap_blocks; i++) {
+		bh = minix_sb(inode->i_sb)->s_imap[i];
 		if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
 			break;
 	}
@@ -251,7 +254,7 @@
 	}
 	mark_buffer_dirty(bh);
 	j += i*8192;
-	if (!j || j > inode->i_sb->u.minix_sb.s_ninodes) {
+	if (!j || j > minix_sb(inode->i_sb)->s_ninodes) {
 		iput(inode);
 		unlock_super(sb);
 		return NULL;
@@ -272,6 +275,6 @@
 
 unsigned long minix_count_free_inodes(struct super_block *sb)
 {
-	return count_free(sb->u.minix_sb.s_imap, sb->u.minix_sb.s_imap_blocks,
-		sb->u.minix_sb.s_ninodes + 1);
+	return count_free(minix_sb(sb)->s_imap, minix_sb(sb)->s_imap_blocks,
+		minix_sb(sb)->s_ninodes + 1);
 }
fs/minix/dir.c +8 -8
diff -urN -X scripts/dontdiff linux-2.5.6/fs/minix/dir.c linux/fs/minix/dir.c
@@ -77,7 +77,7 @@
 	unsigned offset = pos & ~PAGE_CACHE_MASK;
 	unsigned long n = pos >> PAGE_CACHE_SHIFT;
 	unsigned long npages = dir_pages(inode);
-	struct minix_sb_info *sbi = &sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(sb);
 	unsigned chunk_size = sbi->s_dirsize;
 
 	pos = (pos + chunk_size-1) & ~(chunk_size-1);
@@ -140,7 +140,7 @@
 	int namelen = dentry->d_name.len;
 	struct inode * dir = dentry->d_parent->d_inode;
 	struct super_block * sb = dir->i_sb;
-	struct minix_sb_info * sbi = &sb->u.minix_sb;
+	struct minix_sb_info * sbi = minix_sb(sb);
 	unsigned long n;
 	unsigned long npages = dir_pages(dir);
 	struct page *page = NULL;
@@ -178,7 +178,7 @@
 	const char * name = dentry->d_name.name;
 	int namelen = dentry->d_name.len;
 	struct super_block * sb = dir->i_sb;
-	struct minix_sb_info * sbi = &sb->u.minix_sb;
+	struct minix_sb_info * sbi = minix_sb(sb);
 	struct page *page = NULL;
 	struct minix_dir_entry * de;
 	unsigned long npages = dir_pages(dir);
@@ -236,7 +236,7 @@
 	struct inode *inode = (struct inode*)mapping->host;
 	char *kaddr = (char*)page_address(page);
 	unsigned from = (char*)de - kaddr;
-	unsigned to = from + inode->i_sb->u.minix_sb.s_dirsize;
+	unsigned to = from + minix_sb(inode->i_sb)->s_dirsize;
 	int err;
 
 	lock_page(page);
@@ -256,7 +256,7 @@
 {
 	struct address_space *mapping = inode->i_mapping;
 	struct page *page = grab_cache_page(mapping, 0);
-	struct minix_sb_info * sbi = &inode->i_sb->u.minix_sb;
+	struct minix_sb_info * sbi = minix_sb(inode->i_sb);
 	struct minix_dir_entry * de;
 	char *base;
 	int err;
@@ -291,7 +291,7 @@
 {
 	struct page *page = NULL;
 	unsigned long i, npages = dir_pages(inode);
-	struct minix_sb_info *sbi = &inode->i_sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(inode->i_sb);
 
 	for (i = 0; i < npages; i++) {
 		char *kaddr;
@@ -334,7 +334,7 @@
 	struct inode *inode)
 {
 	struct inode *dir = (struct inode*)page->mapping->host;
-	struct minix_sb_info *sbi = &dir->i_sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(dir->i_sb);
 	unsigned from = (char *)de-(char*)page_address(page);
 	unsigned to = from + sbi->s_dirsize;
 	int err;
@@ -354,7 +354,7 @@
 struct minix_dir_entry * minix_dotdot (struct inode *dir, struct page **p)
 {
 	struct page *page = dir_get_page(dir, 0);
-	struct minix_sb_info *sbi = &dir->i_sb->u.minix_sb;
+	struct minix_sb_info *sbi = minix_sb(dir->i_sb);
 	struct minix_dir_entry *de = NULL;
 
 	if (!IS_ERR(page)) {
fs/minix/inode.c +25 -22

109 lines not on this page · raw message

fs/minix/itree_v1.c +1 -1
diff -urN -X scripts/dontdiff linux-2.5.6/fs/minix/itree_v1.c linux/fs/minix/itree_v1.c
@@ -28,7 +28,7 @@
 
 	if (block < 0) {
 		printk("minix_bmap: block<0");
-	} else if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
+	} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
 		printk("minix_bmap: block>big");
 	} else if (block < 7) {
 		offsets[n++] = block;
fs/minix/itree_v2.c +1 -1
diff -urN -X scripts/dontdiff linux-2.5.6/fs/minix/itree_v2.c linux/fs/minix/itree_v2.c
@@ -28,7 +28,7 @@
 
 	if (block < 0) {
 		printk("minix_bmap: block<0");
-	} else if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
+	} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
 		printk("minix_bmap: block>big");
 	} else if (block < 7) {
 		offsets[n++] = block;
fs/minix/namei.c +5 -5
diff -urN -X scripts/dontdiff linux-2.5.6/fs/minix/namei.c linux/fs/minix/namei.c
@@ -38,7 +38,7 @@
 	int i;
 	const unsigned char *name;
 
-	i = dentry->d_inode->i_sb->u.minix_sb.s_namelen;
+	i = minix_sb(dentry->d_inode->i_sb)->s_namelen;
 	if (i >= qstr->len)
 		return 0;
 	/* Truncate the name in place, avoids having to define a compare
@@ -63,7 +63,7 @@
 
 	dentry->d_op = dir->i_sb->s_root->d_op;
 
-	if (dentry->d_name.len > dir->i_sb->u.minix_sb.s_namelen)
+	if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen)
 		return ERR_PTR(-ENAMETOOLONG);
 
 	ino = minix_inode_by_name(dentry);
@@ -131,7 +131,7 @@
 {
 	struct inode *inode = old_dentry->d_inode;
 
-	if (inode->i_nlink >= inode->i_sb->u.minix_sb.s_link_max)
+	if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
 		return -EMLINK;
 
 	inode->i_ctime = CURRENT_TIME;
@@ -145,7 +145,7 @@
 	struct inode * inode;
 	int err = -EMLINK;
 
-	if (dir->i_nlink >= dir->i_sb->u.minix_sb.s_link_max)
+	if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
 		goto out;
 
 	inc_count(dir);
@@ -221,7 +221,7 @@
 static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
 			   struct inode * new_dir, struct dentry *new_dentry)
 {
-	struct minix_sb_info * info = &old_dir->i_sb->u.minix_sb;
+	struct minix_sb_info * info = minix_sb(old_dir->i_sb);
 	struct inode * old_inode = old_dentry->d_inode;
 	struct inode * new_inode = new_dentry->d_inode;
 	struct page * dir_page = NULL;
include/linux/minix_fs.h +7 -1
diff -urN -X scripts/dontdiff linux-2.5.6/include/linux/minix_fs.h linux/include/linux/minix_fs.h
@@ -32,7 +32,7 @@
 #define MINIX_V1		0x0001		/* original minix fs */
 #define MINIX_V2		0x0002		/* minix V2 fs */
 
-#define INODE_VERSION(inode)	inode->i_sb->u.minix_sb.s_version
+#define INODE_VERSION(inode)	minix_sb(inode->i_sb)->s_version
 
 /*
  * This is the original minix inode layout on disk.
@@ -90,6 +90,7 @@
 #ifdef __KERNEL__
 
 #include <linux/minix_fs_i.h>
+#include <linux/minix_fs_sb.h>
 
 /*
  * change the define below to 0 if you want names > info->s_namelen chars to be
@@ -131,6 +132,11 @@
 extern struct file_operations minix_dir_operations;
 extern struct dentry_operations minix_dentry_operations;
 
+static inline struct minix_sb_info *minix_sb(struct super_block *sb)
+{
+	return &sb->u.minix_sb;
+}
+
 static inline struct minix_inode_info *minix_i(struct inode *inode)
 {
 	return list_entry(inode, struct minix_inode_info, vfs_inode);
fs/minix/inode.c +10 -1
diff -urN linux/fs/minix/inode.c linux2/fs/minix/inode.c
@@ -70,6 +70,8 @@
 		brelse(sbi->s_zmap[i]);
 	brelse (sbi->s_sbh);
 	kfree(sbi->s_imap);
+	sb->u.generic_sbp = NULL;
+	kfree(sbi);
 
 	return;
 }
@@ -170,7 +172,12 @@
 	struct minix_super_block *ms;
 	int i, block;
 	struct inode *root_inode;
-	struct minix_sb_info *sbi = minix_sb(s);
+	struct minix_sb_info *sbi;
+
+	sbi = kmalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
+	if (!sbi)
+		return -ENOMEM;
+	s->u.generic_sbp = sbi;
 
 	/* N.B. These should be compile-time tests.
 	   Unfortunately that is impossible. */
@@ -313,6 +320,8 @@
 out_bad_sb:
 	printk("MINIX-fs: unable to read superblock\n");
  out:
+	s->u.generic_sbp = NULL;
+	kfree(sbi);
 	return -EINVAL;
 }
 
include/linux/fs.h +0 -2
diff -urN linux/include/linux/fs.h linux2/include/linux/fs.h
@@ -650,7 +650,6 @@
 #define MNT_FORCE	0x00000001	/* Attempt to forcibily umount */
 #define MNT_DETACH	0x00000002	/* Just detach from the tree */
 
-#include <linux/minix_fs_sb.h>
 #include <linux/ext2_fs_sb.h>
 #include <linux/ext3_fs_sb.h>
 #include <linux/hpfs_fs_sb.h>
@@ -708,7 +707,6 @@
 	char s_id[32];				/* Informational name */
 
 	union {
-		struct minix_sb_info	minix_sb;
 		struct ext2_sb_info	ext2_sb;
 		struct ext3_sb_info	ext3_sb;
 		struct hpfs_sb_info	hpfs_sb;
include/linux/minix_fs.h +1 -1
diff -urN linux/include/linux/minix_fs.h linux2/include/linux/minix_fs.h
@@ -134,7 +134,7 @@
 
 static inline struct minix_sb_info *minix_sb(struct super_block *sb)
 {
-	return &sb->u.minix_sb;
+	return sb->u.generic_sbp;
 }
 
 static inline struct minix_inode_info *minix_i(struct inode *inode)
#1 lore raw
Quoted 6 lines · Brian Gerst

These two patches are the start of cleaning up the union of filesystem-specific structures in struct super_block. The goal is to remove dependence on filesystem headers in fs.h. The first patch abstracts the access to the minix_sb_info structure through the function minix_sb(). The second patch switches to using kmalloc to allocate the structure.

Nice to see it happening, even if it got there by a twisty path ;-)

Signature · 1 line
Daniel