mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 28/42] ext4: Combine proc file handling into a single set of functions
Date: Thu,  9 Oct 2008 00:05:46 -0400	[thread overview]
Message-ID: <1223525160-9887-29-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1223525160-9887-28-git-send-email-tytso@mit.edu>

Previously mballoc created a separate set of functions for each proc
file.  This combines the tunables into a single set of functions which
gets used for all of the per-superblock proc files, saving
approximately 2k of compiled object code.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 fs/ext4/ext4.h    |   16 ++++++++++++
 fs/ext4/ext4_sb.h |   12 ++++----
 fs/ext4/mballoc.c |   69 ++++------------------------------------------------
 fs/ext4/super.c   |   42 ++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 69 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index b9c9371..163c445 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -957,6 +957,22 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
 
 extern struct proc_dir_entry *ext4_proc_root;
 
+#ifdef CONFIG_PROC_FS
+extern const struct file_operations ext4_ui_proc_fops;
+
+#define	EXT4_PROC_HANDLER(name, var)					\
+do {									\
+	proc = proc_create_data(name, mode, sbi->s_proc,		\
+				&ext4_ui_proc_fops, &sbi->s_##var);	\
+	if (proc == NULL) {						\
+		printk(KERN_ERR "EXT4-fs: can't create %s\n", name);	\
+		goto err_out;						\
+	}								\
+} while (0)
+#else
+#define EXT4_PROC_HANDLER(name, var)
+#endif
+
 /*
  * Function prototypes
  */
diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h
index 95e046e..f92af01 100644
--- a/fs/ext4/ext4_sb.h
+++ b/fs/ext4/ext4_sb.h
@@ -108,12 +108,12 @@ struct ext4_sb_info {
 
 	/* tunables */
 	unsigned long s_stripe;
-	unsigned long s_mb_stream_request;
-	unsigned long s_mb_max_to_scan;
-	unsigned long s_mb_min_to_scan;
-	unsigned long s_mb_stats;
-	unsigned long s_mb_order2_reqs;
-	unsigned long s_mb_group_prealloc;
+	unsigned int s_mb_stream_request;
+	unsigned int s_mb_max_to_scan;
+	unsigned int s_mb_min_to_scan;
+	unsigned int s_mb_stats;
+	unsigned int s_mb_order2_reqs;
+	unsigned int s_mb_group_prealloc;
 	/* where last allocation was done - for stream allocation */
 	unsigned long s_mb_last_group;
 	unsigned long s_mb_last_start;
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 705870c..3373f89 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2721,63 +2721,6 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
 #define EXT4_MB_STREAM_REQ		"stream_req"
 #define EXT4_MB_GROUP_PREALLOC		"group_prealloc"
 
-#define MB_PROC_FOPS(name)					\
-static int ext4_mb_##name##_proc_show(struct seq_file *m, void *v)	\
-{								\
-	struct ext4_sb_info *sbi = m->private;			\
-								\
-	seq_printf(m, "%ld\n", sbi->s_mb_##name);		\
-	return 0;						\
-}								\
-								\
-static int ext4_mb_##name##_proc_open(struct inode *inode, struct file *file)\
-{								\
-	return single_open(file, ext4_mb_##name##_proc_show, PDE(inode)->data);\
-}								\
-								\
-static ssize_t ext4_mb_##name##_proc_write(struct file *file,	\
-		const char __user *buf, size_t cnt, loff_t *ppos)	\
-{								\
-	struct ext4_sb_info *sbi = PDE(file->f_path.dentry->d_inode)->data;\
-	char str[32];						\
-	long value;						\
-	if (cnt >= sizeof(str))					\
-		return -EINVAL;					\
-	if (copy_from_user(str, buf, cnt))			\
-		return -EFAULT;					\
-	value = simple_strtol(str, NULL, 0);			\
-	if (value <= 0)						\
-		return -ERANGE;					\
-	sbi->s_mb_##name = value;				\
-	return cnt;						\
-}								\
-								\
-static const struct file_operations ext4_mb_##name##_proc_fops = {	\
-	.owner		= THIS_MODULE,				\
-	.open		= ext4_mb_##name##_proc_open,		\
-	.read		= seq_read,				\
-	.llseek		= seq_lseek,				\
-	.release	= single_release,			\
-	.write		= ext4_mb_##name##_proc_write,		\
-};
-
-MB_PROC_FOPS(stats);
-MB_PROC_FOPS(max_to_scan);
-MB_PROC_FOPS(min_to_scan);
-MB_PROC_FOPS(order2_reqs);
-MB_PROC_FOPS(stream_request);
-MB_PROC_FOPS(group_prealloc);
-
-#define	MB_PROC_HANDLER(name, var)					\
-do {									\
-	proc = proc_create_data(name, mode, sbi->s_proc,		\
-				&ext4_mb_##var##_proc_fops, sbi);	\
-	if (proc == NULL) {						\
-		printk(KERN_ERR "EXT4-fs: can't to create %s\n", name);	\
-		goto err_out;						\
-	}								\
-} while (0)
-
 static int ext4_mb_init_per_dev_proc(struct super_block *sb)
 {
 	mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
@@ -2787,12 +2730,12 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
 	if (sbi->s_proc == NULL)
 		return -EINVAL;
 
-	MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
-	MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
-	MB_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, min_to_scan);
-	MB_PROC_HANDLER(EXT4_MB_ORDER2_REQ, order2_reqs);
-	MB_PROC_HANDLER(EXT4_MB_STREAM_REQ, stream_request);
-	MB_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, group_prealloc);
+	EXT4_PROC_HANDLER(EXT4_MB_STATS_NAME, mb_stats);
+	EXT4_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, mb_max_to_scan);
+	EXT4_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, mb_min_to_scan);
+	EXT4_PROC_HANDLER(EXT4_MB_ORDER2_REQ, mb_order2_reqs);
+	EXT4_PROC_HANDLER(EXT4_MB_STREAM_REQ, mb_stream_request);
+	EXT4_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, mb_group_prealloc);
 	return 0;
 
 err_out:
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 7feeec6..9f5468f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3541,6 +3541,48 @@ static int ext4_get_sb(struct file_system_type *fs_type,
 	return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
 }
 
+#ifdef CONFIG_PROC_FS
+static int ext4_ui_proc_show(struct seq_file *m, void *v)
+{
+	unsigned int *p = m->private;
+
+	seq_printf(m, "%u\n", *p);
+	return 0;
+}
+
+static int ext4_ui_proc_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, ext4_ui_proc_show, PDE(inode)->data);
+}
+
+static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
+			       size_t cnt, loff_t *ppos)
+{
+	unsigned int *p = PDE(file->f_path.dentry->d_inode)->data;
+	char str[32];
+	unsigned long value;
+
+	if (cnt >= sizeof(str))
+		return -EINVAL;
+	if (copy_from_user(str, buf, cnt))
+		return -EFAULT;
+	value = simple_strtol(str, NULL, 0);
+	if (value < 0)
+		return -ERANGE;
+	*p = value;
+	return cnt;
+}
+
+const struct file_operations ext4_ui_proc_fops = {
+	.owner		= THIS_MODULE,
+	.open		= ext4_ui_proc_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+	.write		= ext4_ui_proc_write,
+};
+#endif
+
 static struct file_system_type ext4dev_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "ext4dev",
-- 
1.5.6.1.205.ge2c7.dirty


  reply	other threads:[~2008-10-09  4:14 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-09  4:05 [PATCH 0/42] Ext4 patches queued up for the 2.6.28 merge window Theodore Ts'o
2008-10-09  4:05 ` [PATCH 01/42] percpu counter: clean up percpu_counter_sum_and_set() Theodore Ts'o
2008-10-09  4:05   ` [PATCH 02/42] ext4: Add printk priority levels to clean up checkpatch warnings Theodore Ts'o
2008-10-09  4:05     ` [PATCH 03/42] ext4: Fix long long " Theodore Ts'o
2008-10-09  4:05       ` [PATCH 04/42] ext4: Fix whitespace checkpatch warnings/errors Theodore Ts'o
2008-10-09  4:05         ` [PATCH 05/42] ext4: invalidate pages if delalloc block allocation fails Theodore Ts'o
2008-10-09  4:05           ` [PATCH 06/42] ext4: Make sure all the block allocation paths reserve blocks Theodore Ts'o
2008-10-09  4:05             ` [PATCH 07/42] ext4: Retry block reservation Theodore Ts'o
2008-10-09  4:05               ` [PATCH 08/42] ext4: Add percpu dirty block accounting Theodore Ts'o
2008-10-09  4:05                 ` [PATCH 09/42] ext4: Switch to non delalloc mode when we are low on free blocks count Theodore Ts'o
2008-10-09  4:05                   ` [PATCH 10/42] ext4: Signed arithmetic fix Theodore Ts'o
2008-10-09  4:05                     ` [PATCH 11/42] ext4: Fix ext4 nomballoc allocator for ENOSPC Theodore Ts'o
2008-10-09  4:05                       ` [PATCH 12/42] ext4: Don't add the inode to journal handle until after the block is allocated Theodore Ts'o
2008-10-09  4:05                         ` [PATCH 13/42] ext4: Retry block allocation if we have free blocks left Theodore Ts'o
2008-10-09  4:05                           ` [PATCH 14/42] ext4: truncate block allocated on a failed ext4_write_begin Theodore Ts'o
2008-10-09  4:05                             ` [PATCH 15/42] ext4: Properly update i_disksize Theodore Ts'o
2008-10-09  4:05                               ` [PATCH 16/42] ext4: Avoid printk floods in the face of directory corruption Theodore Ts'o
2008-10-09  4:05                                 ` [PATCH 17/42] Update flex_bg free blocks and free inodes counters when resizing Theodore Ts'o
2008-10-09  4:05                                   ` [PATCH 18/42] ext4: fix #11321: create /proc/ext4/*/stats more carefully Theodore Ts'o
2008-10-09  4:05                                     ` [PATCH 19/42] jbd2: clean up how the journal device name is printed Theodore Ts'o
2008-10-09  4:05                                       ` [PATCH 20/42] ext4: add missing unlock in ext4_check_descriptors() on error path Theodore Ts'o
2008-10-09  4:05                                         ` [PATCH 21/42] ext4: elevate write count for migrate ioctl Theodore Ts'o
2008-10-09  4:05                                           ` [PATCH 22/42] ext4: hook the ext3 migration interface to the EXT4_IOC_SETFLAGS ioctl Theodore Ts'o
2008-10-09  4:05                                             ` [PATCH 23/42] ext4: Renumber EXT4_IOC_MIGRATE Theodore Ts'o
2008-10-09  4:05                                               ` [PATCH 24/42] ext4: use percpu data structures for lg_prealloc_list Theodore Ts'o
2008-10-09  4:05                                                 ` [PATCH 25/42] ext4/jbd2: Avoid WARN() messages when failing to write to the superblock Theodore Ts'o
2008-10-09  4:05                                                   ` [PATCH 26/42] ext4: Don't use 'struct dentry' for internal lookups Theodore Ts'o
2008-10-09  4:05                                                     ` [PATCH 27/42] ext4: move /proc setup and teardown out of mballoc.c Theodore Ts'o
2008-10-09  4:05                                                       ` Theodore Ts'o [this message]
2008-10-09  4:05                                                         ` [PATCH 29/42] ext4: Use readahead when reading an inode from the inode table Theodore Ts'o
2008-10-09  4:05                                                           ` [PATCH 30/42] ext4: Remove old legacy block allocator Theodore Ts'o
2008-10-09  4:05                                                             ` [PATCH 31/42] ext4: fix initialization of UNINIT bitmap blocks Theodore Ts'o
2008-10-09  4:05                                                               ` [PATCH 32/42] jbd2: abort instead of waiting for nonexistent transaction Theodore Ts'o
2008-10-09  4:05                                                                 ` [PATCH 33/42] ext4: Add debugging markers that can be used by systemtap Theodore Ts'o
2008-10-09  4:05                                                                   ` [PATCH 34/42] jbd2: Fix buffer head leak when writing the commit block Theodore Ts'o
2008-10-09  4:05                                                                     ` [PATCH 35/42] ext4: fix xattr deadlock Theodore Ts'o
2008-10-09  4:05                                                                       ` [PATCH 36/42] vfs: vfs-level fiemap interface Theodore Ts'o
2008-10-09  4:05                                                                         ` [PATCH 37/42] ocfs2: fiemap support Theodore Ts'o
2008-10-09  4:05                                                                           ` [PATCH 38/42] generic block based fiemap implementation Theodore Ts'o
2008-10-09  4:05                                                                             ` [PATCH 39/42] Hook ext4 to the vfs fiemap interface Theodore Ts'o
2008-10-09  4:05                                                                               ` [PATCH 40/42] Update ext4 MAINTAINERS file Theodore Ts'o
2008-10-09  4:05                                                                                 ` [PATCH 41/42] ext4: Avoid double dirtying of super block in ext4_put_super() Theodore Ts'o
2008-10-09  4:06                                                                                   ` [PATCH 42/42] ext4: Rename ext4dev to ext4 Theodore Ts'o
2008-10-11 22:04                                                                                     ` Jeremy Fitzhardinge
2008-10-11 22:09                                                                                       ` Eric Sandeen
2008-10-11 22:54                                                                                         ` Jeremy Fitzhardinge
2008-10-11 22:58                                                                                         ` Theodore Tso
2008-10-11 23:08                                                                                           ` Grant Coady
2008-10-12  1:06                                                                                           ` Eric Sandeen
2008-10-09  8:18                                                           ` [PATCH 29/42] ext4: Use readahead when reading an inode from the inode table Aneesh Kumar K.V
2008-10-09  8:52   ` [PATCH 01/42] percpu counter: clean up percpu_counter_sum_and_set() Peter Zijlstra
2008-10-09 16:52     ` Theodore Tso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223525160-9887-29-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®