diff options
author | Theodore Ts'o <tytso@mit.edu> | 2008-09-23 18:07:35 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-09-23 18:07:35 -0400 |
commit | 5e8814f2f74f53d58aa5679bf32b38a7940033fe (patch) | |
tree | 05f70d1d57d20111a57cd35fb971e36f836d24e8 /fs/ext4 | |
parent | 9f6200bbfc962d8f926278cf5d5ddb90a228c322 (diff) |
ext4: Combine proc file handling into a single set of functions
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>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/ext4.h | 16 | ||||
-rw-r--r-- | fs/ext4/ext4_sb.h | 12 | ||||
-rw-r--r-- | fs/ext4/mballoc.c | 69 | ||||
-rw-r--r-- | 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 b9c9371d8164..163c44527dde 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, | |||
957 | 957 | ||
958 | extern struct proc_dir_entry *ext4_proc_root; | 958 | extern struct proc_dir_entry *ext4_proc_root; |
959 | 959 | ||
960 | #ifdef CONFIG_PROC_FS | ||
961 | extern const struct file_operations ext4_ui_proc_fops; | ||
962 | |||
963 | #define EXT4_PROC_HANDLER(name, var) \ | ||
964 | do { \ | ||
965 | proc = proc_create_data(name, mode, sbi->s_proc, \ | ||
966 | &ext4_ui_proc_fops, &sbi->s_##var); \ | ||
967 | if (proc == NULL) { \ | ||
968 | printk(KERN_ERR "EXT4-fs: can't create %s\n", name); \ | ||
969 | goto err_out; \ | ||
970 | } \ | ||
971 | } while (0) | ||
972 | #else | ||
973 | #define EXT4_PROC_HANDLER(name, var) | ||
974 | #endif | ||
975 | |||
960 | /* | 976 | /* |
961 | * Function prototypes | 977 | * Function prototypes |
962 | */ | 978 | */ |
diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h index 95e046e77cb1..f92af01138d4 100644 --- a/fs/ext4/ext4_sb.h +++ b/fs/ext4/ext4_sb.h | |||
@@ -108,12 +108,12 @@ struct ext4_sb_info { | |||
108 | 108 | ||
109 | /* tunables */ | 109 | /* tunables */ |
110 | unsigned long s_stripe; | 110 | unsigned long s_stripe; |
111 | unsigned long s_mb_stream_request; | 111 | unsigned int s_mb_stream_request; |
112 | unsigned long s_mb_max_to_scan; | 112 | unsigned int s_mb_max_to_scan; |
113 | unsigned long s_mb_min_to_scan; | 113 | unsigned int s_mb_min_to_scan; |
114 | unsigned long s_mb_stats; | 114 | unsigned int s_mb_stats; |
115 | unsigned long s_mb_order2_reqs; | 115 | unsigned int s_mb_order2_reqs; |
116 | unsigned long s_mb_group_prealloc; | 116 | unsigned int s_mb_group_prealloc; |
117 | /* where last allocation was done - for stream allocation */ | 117 | /* where last allocation was done - for stream allocation */ |
118 | unsigned long s_mb_last_group; | 118 | unsigned long s_mb_last_group; |
119 | unsigned long s_mb_last_start; | 119 | unsigned long s_mb_last_start; |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 842d4017006e..b9118bb29939 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -2721,63 +2721,6 @@ ext4_mb_free_committed_blocks(struct super_block *sb) | |||
2721 | #define EXT4_MB_STREAM_REQ "stream_req" | 2721 | #define EXT4_MB_STREAM_REQ "stream_req" |
2722 | #define EXT4_MB_GROUP_PREALLOC "group_prealloc" | 2722 | #define EXT4_MB_GROUP_PREALLOC "group_prealloc" |
2723 | 2723 | ||
2724 | #define MB_PROC_FOPS(name) \ | ||
2725 | static int ext4_mb_##name##_proc_show(struct seq_file *m, void *v) \ | ||
2726 | { \ | ||
2727 | struct ext4_sb_info *sbi = m->private; \ | ||
2728 | \ | ||
2729 | seq_printf(m, "%ld\n", sbi->s_mb_##name); \ | ||
2730 | return 0; \ | ||
2731 | } \ | ||
2732 | \ | ||
2733 | static int ext4_mb_##name##_proc_open(struct inode *inode, struct file *file)\ | ||
2734 | { \ | ||
2735 | return single_open(file, ext4_mb_##name##_proc_show, PDE(inode)->data);\ | ||
2736 | } \ | ||
2737 | \ | ||
2738 | static ssize_t ext4_mb_##name##_proc_write(struct file *file, \ | ||
2739 | const char __user *buf, size_t cnt, loff_t *ppos) \ | ||
2740 | { \ | ||
2741 | struct ext4_sb_info *sbi = PDE(file->f_path.dentry->d_inode)->data;\ | ||
2742 | char str[32]; \ | ||
2743 | long value; \ | ||
2744 | if (cnt >= sizeof(str)) \ | ||
2745 | return -EINVAL; \ | ||
2746 | if (copy_from_user(str, buf, cnt)) \ | ||
2747 | return -EFAULT; \ | ||
2748 | value = simple_strtol(str, NULL, 0); \ | ||
2749 | if (value <= 0) \ | ||
2750 | return -ERANGE; \ | ||
2751 | sbi->s_mb_##name = value; \ | ||
2752 | return cnt; \ | ||
2753 | } \ | ||
2754 | \ | ||
2755 | static const struct file_operations ext4_mb_##name##_proc_fops = { \ | ||
2756 | .owner = THIS_MODULE, \ | ||
2757 | .open = ext4_mb_##name##_proc_open, \ | ||
2758 | .read = seq_read, \ | ||
2759 | .llseek = seq_lseek, \ | ||
2760 | .release = single_release, \ | ||
2761 | .write = ext4_mb_##name##_proc_write, \ | ||
2762 | }; | ||
2763 | |||
2764 | MB_PROC_FOPS(stats); | ||
2765 | MB_PROC_FOPS(max_to_scan); | ||
2766 | MB_PROC_FOPS(min_to_scan); | ||
2767 | MB_PROC_FOPS(order2_reqs); | ||
2768 | MB_PROC_FOPS(stream_request); | ||
2769 | MB_PROC_FOPS(group_prealloc); | ||
2770 | |||
2771 | #define MB_PROC_HANDLER(name, var) \ | ||
2772 | do { \ | ||
2773 | proc = proc_create_data(name, mode, sbi->s_proc, \ | ||
2774 | &ext4_mb_##var##_proc_fops, sbi); \ | ||
2775 | if (proc == NULL) { \ | ||
2776 | printk(KERN_ERR "EXT4-fs: can't to create %s\n", name); \ | ||
2777 | goto err_out; \ | ||
2778 | } \ | ||
2779 | } while (0) | ||
2780 | |||
2781 | static int ext4_mb_init_per_dev_proc(struct super_block *sb) | 2724 | static int ext4_mb_init_per_dev_proc(struct super_block *sb) |
2782 | { | 2725 | { |
2783 | mode_t mode = S_IFREG | S_IRUGO | S_IWUSR; | 2726 | 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) | |||
2787 | if (sbi->s_proc == NULL) | 2730 | if (sbi->s_proc == NULL) |
2788 | return -EINVAL; | 2731 | return -EINVAL; |
2789 | 2732 | ||
2790 | MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats); | 2733 | EXT4_PROC_HANDLER(EXT4_MB_STATS_NAME, mb_stats); |
2791 | MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan); | 2734 | EXT4_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, mb_max_to_scan); |
2792 | MB_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, min_to_scan); | 2735 | EXT4_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, mb_min_to_scan); |
2793 | MB_PROC_HANDLER(EXT4_MB_ORDER2_REQ, order2_reqs); | 2736 | EXT4_PROC_HANDLER(EXT4_MB_ORDER2_REQ, mb_order2_reqs); |
2794 | MB_PROC_HANDLER(EXT4_MB_STREAM_REQ, stream_request); | 2737 | EXT4_PROC_HANDLER(EXT4_MB_STREAM_REQ, mb_stream_request); |
2795 | MB_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, group_prealloc); | 2738 | EXT4_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, mb_group_prealloc); |
2796 | return 0; | 2739 | return 0; |
2797 | 2740 | ||
2798 | err_out: | 2741 | err_out: |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 7feeec6f7c39..9f5468fb06da 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, | |||
3541 | return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); | 3541 | return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); |
3542 | } | 3542 | } |
3543 | 3543 | ||
3544 | #ifdef CONFIG_PROC_FS | ||
3545 | static int ext4_ui_proc_show(struct seq_file *m, void *v) | ||
3546 | { | ||
3547 | unsigned int *p = m->private; | ||
3548 | |||
3549 | seq_printf(m, "%u\n", *p); | ||
3550 | return 0; | ||
3551 | } | ||
3552 | |||
3553 | static int ext4_ui_proc_open(struct inode *inode, struct file *file) | ||
3554 | { | ||
3555 | return single_open(file, ext4_ui_proc_show, PDE(inode)->data); | ||
3556 | } | ||
3557 | |||
3558 | static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf, | ||
3559 | size_t cnt, loff_t *ppos) | ||
3560 | { | ||
3561 | unsigned int *p = PDE(file->f_path.dentry->d_inode)->data; | ||
3562 | char str[32]; | ||
3563 | unsigned long value; | ||
3564 | |||
3565 | if (cnt >= sizeof(str)) | ||
3566 | return -EINVAL; | ||
3567 | if (copy_from_user(str, buf, cnt)) | ||
3568 | return -EFAULT; | ||
3569 | value = simple_strtol(str, NULL, 0); | ||
3570 | if (value < 0) | ||
3571 | return -ERANGE; | ||
3572 | *p = value; | ||
3573 | return cnt; | ||
3574 | } | ||
3575 | |||
3576 | const struct file_operations ext4_ui_proc_fops = { | ||
3577 | .owner = THIS_MODULE, | ||
3578 | .open = ext4_ui_proc_open, | ||
3579 | .read = seq_read, | ||
3580 | .llseek = seq_lseek, | ||
3581 | .release = single_release, | ||
3582 | .write = ext4_ui_proc_write, | ||
3583 | }; | ||
3584 | #endif | ||
3585 | |||
3544 | static struct file_system_type ext4dev_fs_type = { | 3586 | static struct file_system_type ext4dev_fs_type = { |
3545 | .owner = THIS_MODULE, | 3587 | .owner = THIS_MODULE, |
3546 | .name = "ext4dev", | 3588 | .name = "ext4dev", |