Skip to contentSkip to conversation

ext2: make ext2_count_free a static inline

RFC PATCH In review Adrian Bunk 2 participants 4 messages May 13, 2005 – Nov 18, 2005 ext2 file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ext2: make ext2_count_free a static inline

ext2_count_free is a small function that is only used #ifdef EXT2FS_DEBUG.

We could offer the function itself only #ifdef EXT2FS_DEBUG, but what about this patch to change ot to a static inline?

---

This patch was already sent on:
- 30 Apr 2005
- 23 Apr 2005

 fs/ext2/Makefile |    2 +-
 fs/ext2/bitmap.c |   25 -------------------------
 fs/ext2/ext2.h   |   18 +++++++++++++++++-
 3 files changed, 18 insertions(+), 27 deletions(-)
fs/ext2/ext2.h renamed from fs/ext2/ext2.h.old +17 -1
@@ -1,5 +1,6 @@
 #include <linux/fs.h>
 #include <linux/ext2_fs.h>
+#include <linux/buffer_head.h>
 
 /*
  * second extended file system inode data in memory
@@ -79,6 +80,22 @@
 	return container_of(inode, struct ext2_inode_info, vfs_inode);
 }
 
+static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
+
+static inline unsigned long ext2_count_free (struct buffer_head * map,
+					     unsigned int numchars)
+{
+	unsigned int i;
+	unsigned long sum = 0;
+	
+	if (!map) 
+		return (0);
+	for (i = 0; i < numchars; i++)
+		sum += nibblemap[map->b_data[i] & 0xf] +
+			nibblemap[(map->b_data[i] >> 4) & 0xf];
+	return (sum);
+}
+
 /* balloc.c */
 extern int ext2_bg_has_super(struct super_block *sb, int group);
 extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
@@ -111,7 +128,6 @@
 extern void ext2_free_inode (struct inode *);
 extern unsigned long ext2_count_free_inodes (struct super_block *);
 extern void ext2_check_inodes_bitmap (struct super_block *);
-extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
 
 /* inode.c */
 extern void ext2_read_inode (struct inode *);
fs/ext2/Makefile renamed from fs/ext2/Makefile.old +1 -1
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_EXT2_FS) += ext2.o
 
-ext2-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
+ext2-y := balloc.o dir.o file.o fsync.o ialloc.o inode.o \
 	  ioctl.o namei.o super.o symlink.o
 
 ext2-$(CONFIG_EXT2_FS_XATTR)	 += xattr.o xattr_user.o xattr_trusted.o
fs/ext2/bitmap.c deleted +0 -25
@@ -1,25 +0,0 @@
-/*
- *  linux/fs/ext2/bitmap.c
- *
- * Copyright (C) 1992, 1993, 1994, 1995
- * Remy Card ([email protected])
- * Laboratoire MASI - Institut Blaise Pascal
- * Universite Pierre et Marie Curie (Paris VI)
- */
-
-#include <linux/buffer_head.h>
-
-static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
-
-unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
-{
-	unsigned int i;
-	unsigned long sum = 0;
-	
-	if (!map) 
-		return (0);
-	for (i = 0; i < numchars; i++)
-		sum += nibblemap[map->b_data[i] & 0xf] +
-			nibblemap[(map->b_data[i] >> 4) & 0xf];
-	return (sum);
-}
#1 lore raw
Quoted 8 lines · Adrian Bunk

--- linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h.old 2005-04-20 23:08:52.000000000 +0200
+++ linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h 2005-04-20 23:14:21.000000000 +0200
@@ -1,5 +1,6 @@
#include <linux/fs.h>
#include <linux/ext2_fs.h>
+#include <linux/buffer_head.h>

Quoted 8 lines

/*
* second extended file system inode data in memory
@@ -79,6 +80,22 @@
return container_of(inode, struct ext2_inode_info, vfs_inode);
}

+static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; +

This will cause a copy of `nibblemap' to be included in each compilation unit which uses ext2.h. Unless the compiler is sufficiently smart to elide it, which it might be. But then it might be sufficiently smart to generate a "you're not usig this" warning too.

If it's only needed for EXT2_DEBUG then I'd be inclined to move it into one of the other .c files, inside EXT2_DEBUG. Or just leave it as-is.

#2 lore raw
Quoted 15 lines · Andrew Morton
Quoted 14 lines · Adrian Bunk

--- linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h.old 2005-04-20 23:08:52.000000000 +0200
+++ linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h 2005-04-20 23:14:21.000000000 +0200
@@ -1,5 +1,6 @@
#include <linux/fs.h>
#include <linux/ext2_fs.h>
+#include <linux/buffer_head.h>

/*
* second extended file system inode data in memory
@@ -79,6 +80,22 @@
return container_of(inode, struct ext2_inode_info, vfs_inode);
}

Quoted 7 lines
Quoted 2 lines

+static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; +

This will cause a copy of `nibblemap' to be included in each compilation unit which uses ext2.h. Unless the compiler is sufficiently smart to elide it, which it might be. But then it might be sufficiently smart to generate a "you're not usig this" warning too.

gcc never generates a warning because it's used in the "static inline" function ext2_count_free (whether this function is used or not doesn't matter).

But I get your point.

Quoted 2 lines

If it's only needed for EXT2_DEBUG then I'd be inclined to move it into one of the other .c files, inside EXT2_DEBUG. Or just leave it as-is.

Sounds good.

Any suggestion into which file it should be moved?

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw

PATCH 1/1 fs/ext2/bitmap.c: ext2_count_free() is only required #ifdef EXT2FS_DEBUG

In reply to Andrew Morton
Quoted 18 lines · Andrew Morton
Quoted 8 lines · Adrian Bunk

--- linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h.old 2005-04-20 23:08:52.000000000 +0200
+++ linux-2.6.12-rc2-mm3-full/fs/ext2/ext2.h 2005-04-20 23:14:21.000000000 +0200
@@ -1,5 +1,6 @@
#include <linux/fs.h>
#include <linux/ext2_fs.h>
+#include <linux/buffer_head.h>

Quoted 8 lines

/*
* second extended file system inode data in memory
@@ -79,6 +80,22 @@
return container_of(inode, struct ext2_inode_info, vfs_inode);
}

+static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; +

Quoted 7 lines

This will cause a copy of `nibblemap' to be included in each compilation unit which uses ext2.h. Unless the compiler is sufficiently smart to elide it, which it might be. But then it might be sufficiently smart to generate a "you're not usig this" warning too.

If it's only needed for EXT2_DEBUG then I'd be inclined to move it into one of the other .c files, inside EXT2_DEBUG. Or just leave it as-is.

Patch below.

cu
Adrian

<-- snip -->

There's no need for ext2_count_free() #ifndef EXT2FS_DEBUG.

---

 fs/ext2/bitmap.c |    7 +++++++
 1 file changed, 7 insertions(+)
fs/ext2/bitmap.c renamed from fs/ext2/bitmap.c.old +7 -0
@@ -7,8 +7,12 @@
  * Universite Pierre et Marie Curie (Paris VI)
  */
 
+#ifdef EXT2FS_DEBUG
+
 #include <linux/buffer_head.h>
 
+#include "ext2.h"
+
 static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
 
 unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
@@ -23,3 +27,6 @@
 			nibblemap[(map->b_data[i] >> 4) & 0xf];
 	return (sum);
 }
+
+#endif  /*  EXT2FS_DEBUG  */
+