Commit 074127367a503de0168e2ca5d0b36a6f761f026a

Authored by Alexey Dobriyan
Committed by Linus Torvalds
1 parent 997c136f51

ipmi: convert to seq_file interface

The ->read_proc interface is going away, convert to seq_file.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc:Corey Minyard <minyard@acm.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 142 additions and 86 deletions Side-by-side Diff

drivers/char/ipmi/ipmi_msghandler.c
... ... @@ -36,6 +36,7 @@
36 36 #include <asm/system.h>
37 37 #include <linux/poll.h>
38 38 #include <linux/sched.h>
  39 +#include <linux/seq_file.h>
39 40 #include <linux/spinlock.h>
40 41 #include <linux/mutex.h>
41 42 #include <linux/slab.h>
42 43  
43 44  
44 45  
45 46  
46 47  
47 48  
48 49  
49 50  
50 51  
51 52  
52 53  
53 54  
54 55  
55 56  
56 57  
57 58  
58 59  
59 60  
60 61  
61 62  
62 63  
63 64  
64 65  
65 66  
66 67  
67 68  
68 69  
69 70  
70 71  
71 72  
72 73  
73 74  
74 75  
75 76  
76 77  
77 78  
78 79  
79 80  
80 81  
81 82  
... ... @@ -1896,102 +1897,128 @@
1896 1897 EXPORT_SYMBOL(ipmi_request_supply_msgs);
1897 1898  
1898 1899 #ifdef CONFIG_PROC_FS
1899   -static int ipmb_file_read_proc(char *page, char **start, off_t off,
1900   - int count, int *eof, void *data)
  1900 +static int smi_ipmb_proc_show(struct seq_file *m, void *v)
1901 1901 {
1902   - char *out = (char *) page;
1903   - ipmi_smi_t intf = data;
  1902 + ipmi_smi_t intf = m->private;
1904 1903 int i;
1905   - int rv = 0;
1906 1904  
1907   - for (i = 0; i < IPMI_MAX_CHANNELS; i++)
1908   - rv += sprintf(out+rv, "%x ", intf->channels[i].address);
1909   - out[rv-1] = '\n'; /* Replace the final space with a newline */
1910   - out[rv] = '\0';
1911   - rv++;
1912   - return rv;
  1905 + seq_printf(m, "%x", intf->channels[0].address);
  1906 + for (i = 1; i < IPMI_MAX_CHANNELS; i++)
  1907 + seq_printf(m, " %x", intf->channels[i].address);
  1908 + return seq_putc(m, '\n');
1913 1909 }
1914 1910  
1915   -static int version_file_read_proc(char *page, char **start, off_t off,
1916   - int count, int *eof, void *data)
  1911 +static int smi_ipmb_proc_open(struct inode *inode, struct file *file)
1917 1912 {
1918   - char *out = (char *) page;
1919   - ipmi_smi_t intf = data;
  1913 + return single_open(file, smi_ipmb_proc_show, PDE(inode)->data);
  1914 +}
1920 1915  
1921   - return sprintf(out, "%u.%u\n",
  1916 +static const struct file_operations smi_ipmb_proc_ops = {
  1917 + .open = smi_ipmb_proc_open,
  1918 + .read = seq_read,
  1919 + .llseek = seq_lseek,
  1920 + .release = single_release,
  1921 +};
  1922 +
  1923 +static int smi_version_proc_show(struct seq_file *m, void *v)
  1924 +{
  1925 + ipmi_smi_t intf = m->private;
  1926 +
  1927 + return seq_printf(m, "%u.%u\n",
1922 1928 ipmi_version_major(&intf->bmc->id),
1923 1929 ipmi_version_minor(&intf->bmc->id));
1924 1930 }
1925 1931  
1926   -static int stat_file_read_proc(char *page, char **start, off_t off,
1927   - int count, int *eof, void *data)
  1932 +static int smi_version_proc_open(struct inode *inode, struct file *file)
1928 1933 {
1929   - char *out = (char *) page;
1930   - ipmi_smi_t intf = data;
  1934 + return single_open(file, smi_version_proc_show, PDE(inode)->data);
  1935 +}
1931 1936  
1932   - out += sprintf(out, "sent_invalid_commands: %u\n",
  1937 +static const struct file_operations smi_version_proc_ops = {
  1938 + .open = smi_version_proc_open,
  1939 + .read = seq_read,
  1940 + .llseek = seq_lseek,
  1941 + .release = single_release,
  1942 +};
  1943 +
  1944 +static int smi_stats_proc_show(struct seq_file *m, void *v)
  1945 +{
  1946 + ipmi_smi_t intf = m->private;
  1947 +
  1948 + seq_printf(m, "sent_invalid_commands: %u\n",
1933 1949 ipmi_get_stat(intf, sent_invalid_commands));
1934   - out += sprintf(out, "sent_local_commands: %u\n",
  1950 + seq_printf(m, "sent_local_commands: %u\n",
1935 1951 ipmi_get_stat(intf, sent_local_commands));
1936   - out += sprintf(out, "handled_local_responses: %u\n",
  1952 + seq_printf(m, "handled_local_responses: %u\n",
1937 1953 ipmi_get_stat(intf, handled_local_responses));
1938   - out += sprintf(out, "unhandled_local_responses: %u\n",
  1954 + seq_printf(m, "unhandled_local_responses: %u\n",
1939 1955 ipmi_get_stat(intf, unhandled_local_responses));
1940   - out += sprintf(out, "sent_ipmb_commands: %u\n",
  1956 + seq_printf(m, "sent_ipmb_commands: %u\n",
1941 1957 ipmi_get_stat(intf, sent_ipmb_commands));
1942   - out += sprintf(out, "sent_ipmb_command_errs: %u\n",
  1958 + seq_printf(m, "sent_ipmb_command_errs: %u\n",
1943 1959 ipmi_get_stat(intf, sent_ipmb_command_errs));
1944   - out += sprintf(out, "retransmitted_ipmb_commands: %u\n",
  1960 + seq_printf(m, "retransmitted_ipmb_commands: %u\n",
1945 1961 ipmi_get_stat(intf, retransmitted_ipmb_commands));
1946   - out += sprintf(out, "timed_out_ipmb_commands: %u\n",
  1962 + seq_printf(m, "timed_out_ipmb_commands: %u\n",
1947 1963 ipmi_get_stat(intf, timed_out_ipmb_commands));
1948   - out += sprintf(out, "timed_out_ipmb_broadcasts: %u\n",
  1964 + seq_printf(m, "timed_out_ipmb_broadcasts: %u\n",
1949 1965 ipmi_get_stat(intf, timed_out_ipmb_broadcasts));
1950   - out += sprintf(out, "sent_ipmb_responses: %u\n",
  1966 + seq_printf(m, "sent_ipmb_responses: %u\n",
1951 1967 ipmi_get_stat(intf, sent_ipmb_responses));
1952   - out += sprintf(out, "handled_ipmb_responses: %u\n",
  1968 + seq_printf(m, "handled_ipmb_responses: %u\n",
1953 1969 ipmi_get_stat(intf, handled_ipmb_responses));
1954   - out += sprintf(out, "invalid_ipmb_responses: %u\n",
  1970 + seq_printf(m, "invalid_ipmb_responses: %u\n",
1955 1971 ipmi_get_stat(intf, invalid_ipmb_responses));
1956   - out += sprintf(out, "unhandled_ipmb_responses: %u\n",
  1972 + seq_printf(m, "unhandled_ipmb_responses: %u\n",
1957 1973 ipmi_get_stat(intf, unhandled_ipmb_responses));
1958   - out += sprintf(out, "sent_lan_commands: %u\n",
  1974 + seq_printf(m, "sent_lan_commands: %u\n",
1959 1975 ipmi_get_stat(intf, sent_lan_commands));
1960   - out += sprintf(out, "sent_lan_command_errs: %u\n",
  1976 + seq_printf(m, "sent_lan_command_errs: %u\n",
1961 1977 ipmi_get_stat(intf, sent_lan_command_errs));
1962   - out += sprintf(out, "retransmitted_lan_commands: %u\n",
  1978 + seq_printf(m, "retransmitted_lan_commands: %u\n",
1963 1979 ipmi_get_stat(intf, retransmitted_lan_commands));
1964   - out += sprintf(out, "timed_out_lan_commands: %u\n",
  1980 + seq_printf(m, "timed_out_lan_commands: %u\n",
1965 1981 ipmi_get_stat(intf, timed_out_lan_commands));
1966   - out += sprintf(out, "sent_lan_responses: %u\n",
  1982 + seq_printf(m, "sent_lan_responses: %u\n",
1967 1983 ipmi_get_stat(intf, sent_lan_responses));
1968   - out += sprintf(out, "handled_lan_responses: %u\n",
  1984 + seq_printf(m, "handled_lan_responses: %u\n",
1969 1985 ipmi_get_stat(intf, handled_lan_responses));
1970   - out += sprintf(out, "invalid_lan_responses: %u\n",
  1986 + seq_printf(m, "invalid_lan_responses: %u\n",
1971 1987 ipmi_get_stat(intf, invalid_lan_responses));
1972   - out += sprintf(out, "unhandled_lan_responses: %u\n",
  1988 + seq_printf(m, "unhandled_lan_responses: %u\n",
1973 1989 ipmi_get_stat(intf, unhandled_lan_responses));
1974   - out += sprintf(out, "handled_commands: %u\n",
  1990 + seq_printf(m, "handled_commands: %u\n",
1975 1991 ipmi_get_stat(intf, handled_commands));
1976   - out += sprintf(out, "invalid_commands: %u\n",
  1992 + seq_printf(m, "invalid_commands: %u\n",
1977 1993 ipmi_get_stat(intf, invalid_commands));
1978   - out += sprintf(out, "unhandled_commands: %u\n",
  1994 + seq_printf(m, "unhandled_commands: %u\n",
1979 1995 ipmi_get_stat(intf, unhandled_commands));
1980   - out += sprintf(out, "invalid_events: %u\n",
  1996 + seq_printf(m, "invalid_events: %u\n",
1981 1997 ipmi_get_stat(intf, invalid_events));
1982   - out += sprintf(out, "events: %u\n",
  1998 + seq_printf(m, "events: %u\n",
1983 1999 ipmi_get_stat(intf, events));
1984   - out += sprintf(out, "failed rexmit LAN msgs: %u\n",
  2000 + seq_printf(m, "failed rexmit LAN msgs: %u\n",
1985 2001 ipmi_get_stat(intf, dropped_rexmit_lan_commands));
1986   - out += sprintf(out, "failed rexmit IPMB msgs: %u\n",
  2002 + seq_printf(m, "failed rexmit IPMB msgs: %u\n",
1987 2003 ipmi_get_stat(intf, dropped_rexmit_ipmb_commands));
  2004 + return 0;
  2005 +}
1988 2006  
1989   - return (out - ((char *) page));
  2007 +static int smi_stats_proc_open(struct inode *inode, struct file *file)
  2008 +{
  2009 + return single_open(file, smi_stats_proc_show, PDE(inode)->data);
1990 2010 }
  2011 +
  2012 +static const struct file_operations smi_stats_proc_ops = {
  2013 + .open = smi_stats_proc_open,
  2014 + .read = seq_read,
  2015 + .llseek = seq_lseek,
  2016 + .release = single_release,
  2017 +};
1991 2018 #endif /* CONFIG_PROC_FS */
1992 2019  
1993 2020 int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
1994   - read_proc_t *read_proc,
  2021 + const struct file_operations *proc_ops,
1995 2022 void *data)
1996 2023 {
1997 2024 int rv = 0;
1998 2025  
... ... @@ -2010,15 +2037,12 @@
2010 2037 }
2011 2038 strcpy(entry->name, name);
2012 2039  
2013   - file = create_proc_entry(name, 0, smi->proc_dir);
  2040 + file = proc_create_data(name, 0, smi->proc_dir, proc_ops, data);
2014 2041 if (!file) {
2015 2042 kfree(entry->name);
2016 2043 kfree(entry);
2017 2044 rv = -ENOMEM;
2018 2045 } else {
2019   - file->data = data;
2020   - file->read_proc = read_proc;
2021   -
2022 2046 mutex_lock(&smi->proc_entry_lock);
2023 2047 /* Stick it on the list. */
2024 2048 entry->next = smi->proc_entries;
2025 2049  
2026 2050  
... ... @@ -2043,17 +2067,17 @@
2043 2067  
2044 2068 if (rv == 0)
2045 2069 rv = ipmi_smi_add_proc_entry(smi, "stats",
2046   - stat_file_read_proc,
  2070 + &smi_stats_proc_ops,
2047 2071 smi);
2048 2072  
2049 2073 if (rv == 0)
2050 2074 rv = ipmi_smi_add_proc_entry(smi, "ipmb",
2051   - ipmb_file_read_proc,
  2075 + &smi_ipmb_proc_ops,
2052 2076 smi);
2053 2077  
2054 2078 if (rv == 0)
2055 2079 rv = ipmi_smi_add_proc_entry(smi, "version",
2056   - version_file_read_proc,
  2080 + &smi_version_proc_ops,
2057 2081 smi);
2058 2082 #endif /* CONFIG_PROC_FS */
2059 2083  
drivers/char/ipmi/ipmi_si_intf.c
... ... @@ -43,6 +43,7 @@
43 43 #include <linux/moduleparam.h>
44 44 #include <asm/system.h>
45 45 #include <linux/sched.h>
  46 +#include <linux/seq_file.h>
46 47 #include <linux/timer.h>
47 48 #include <linux/errno.h>
48 49 #include <linux/spinlock.h>
49 50  
50 51  
51 52  
52 53  
53 54  
54 55  
55 56  
56 57  
57 58  
58 59  
59 60  
60 61  
61 62  
62 63  
63 64  
64 65  
65 66  
66 67  
67 68  
68 69  
69 70  
... ... @@ -2805,54 +2806,73 @@
2805 2806 return rv;
2806 2807 }
2807 2808  
2808   -static int type_file_read_proc(char *page, char **start, off_t off,
2809   - int count, int *eof, void *data)
  2809 +static int smi_type_proc_show(struct seq_file *m, void *v)
2810 2810 {
2811   - struct smi_info *smi = data;
  2811 + struct smi_info *smi = m->private;
2812 2812  
2813   - return sprintf(page, "%s\n", si_to_str[smi->si_type]);
  2813 + return seq_printf(m, "%s\n", si_to_str[smi->si_type]);
2814 2814 }
2815 2815  
2816   -static int stat_file_read_proc(char *page, char **start, off_t off,
2817   - int count, int *eof, void *data)
  2816 +static int smi_type_proc_open(struct inode *inode, struct file *file)
2818 2817 {
2819   - char *out = (char *) page;
2820   - struct smi_info *smi = data;
  2818 + return single_open(file, smi_type_proc_show, PDE(inode)->data);
  2819 +}
2821 2820  
2822   - out += sprintf(out, "interrupts_enabled: %d\n",
  2821 +static const struct file_operations smi_type_proc_ops = {
  2822 + .open = smi_type_proc_open,
  2823 + .read = seq_read,
  2824 + .llseek = seq_lseek,
  2825 + .release = single_release,
  2826 +};
  2827 +
  2828 +static int smi_si_stats_proc_show(struct seq_file *m, void *v)
  2829 +{
  2830 + struct smi_info *smi = m->private;
  2831 +
  2832 + seq_printf(m, "interrupts_enabled: %d\n",
2823 2833 smi->irq && !smi->interrupt_disabled);
2824   - out += sprintf(out, "short_timeouts: %u\n",
  2834 + seq_printf(m, "short_timeouts: %u\n",
2825 2835 smi_get_stat(smi, short_timeouts));
2826   - out += sprintf(out, "long_timeouts: %u\n",
  2836 + seq_printf(m, "long_timeouts: %u\n",
2827 2837 smi_get_stat(smi, long_timeouts));
2828   - out += sprintf(out, "idles: %u\n",
  2838 + seq_printf(m, "idles: %u\n",
2829 2839 smi_get_stat(smi, idles));
2830   - out += sprintf(out, "interrupts: %u\n",
  2840 + seq_printf(m, "interrupts: %u\n",
2831 2841 smi_get_stat(smi, interrupts));
2832   - out += sprintf(out, "attentions: %u\n",
  2842 + seq_printf(m, "attentions: %u\n",
2833 2843 smi_get_stat(smi, attentions));
2834   - out += sprintf(out, "flag_fetches: %u\n",
  2844 + seq_printf(m, "flag_fetches: %u\n",
2835 2845 smi_get_stat(smi, flag_fetches));
2836   - out += sprintf(out, "hosed_count: %u\n",
  2846 + seq_printf(m, "hosed_count: %u\n",
2837 2847 smi_get_stat(smi, hosed_count));
2838   - out += sprintf(out, "complete_transactions: %u\n",
  2848 + seq_printf(m, "complete_transactions: %u\n",
2839 2849 smi_get_stat(smi, complete_transactions));
2840   - out += sprintf(out, "events: %u\n",
  2850 + seq_printf(m, "events: %u\n",
2841 2851 smi_get_stat(smi, events));
2842   - out += sprintf(out, "watchdog_pretimeouts: %u\n",
  2852 + seq_printf(m, "watchdog_pretimeouts: %u\n",
2843 2853 smi_get_stat(smi, watchdog_pretimeouts));
2844   - out += sprintf(out, "incoming_messages: %u\n",
  2854 + seq_printf(m, "incoming_messages: %u\n",
2845 2855 smi_get_stat(smi, incoming_messages));
  2856 + return 0;
  2857 +}
2846 2858  
2847   - return out - page;
  2859 +static int smi_si_stats_proc_open(struct inode *inode, struct file *file)
  2860 +{
  2861 + return single_open(file, smi_si_stats_proc_show, PDE(inode)->data);
2848 2862 }
2849 2863  
2850   -static int param_read_proc(char *page, char **start, off_t off,
2851   - int count, int *eof, void *data)
  2864 +static const struct file_operations smi_si_stats_proc_ops = {
  2865 + .open = smi_si_stats_proc_open,
  2866 + .read = seq_read,
  2867 + .llseek = seq_lseek,
  2868 + .release = single_release,
  2869 +};
  2870 +
  2871 +static int smi_params_proc_show(struct seq_file *m, void *v)
2852 2872 {
2853   - struct smi_info *smi = data;
  2873 + struct smi_info *smi = m->private;
2854 2874  
2855   - return sprintf(page,
  2875 + return seq_printf(m,
2856 2876 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
2857 2877 si_to_str[smi->si_type],
2858 2878 addr_space_to_str[smi->io.addr_type],
... ... @@ -2864,6 +2884,18 @@
2864 2884 smi->slave_addr);
2865 2885 }
2866 2886  
  2887 +static int smi_params_proc_open(struct inode *inode, struct file *file)
  2888 +{
  2889 + return single_open(file, smi_params_proc_show, PDE(inode)->data);
  2890 +}
  2891 +
  2892 +static const struct file_operations smi_params_proc_ops = {
  2893 + .open = smi_params_proc_open,
  2894 + .read = seq_read,
  2895 + .llseek = seq_lseek,
  2896 + .release = single_release,
  2897 +};
  2898 +
2867 2899 /*
2868 2900 * oem_data_avail_to_receive_msg_avail
2869 2901 * @info - smi_info structure with msg_flags set
... ... @@ -3257,7 +3289,7 @@
3257 3289 }
3258 3290  
3259 3291 rv = ipmi_smi_add_proc_entry(new_smi->intf, "type",
3260   - type_file_read_proc,
  3292 + &smi_type_proc_ops,
3261 3293 new_smi);
3262 3294 if (rv) {
3263 3295 dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
... ... @@ -3265,7 +3297,7 @@
3265 3297 }
3266 3298  
3267 3299 rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats",
3268   - stat_file_read_proc,
  3300 + &smi_si_stats_proc_ops,
3269 3301 new_smi);
3270 3302 if (rv) {
3271 3303 dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
... ... @@ -3273,7 +3305,7 @@
3273 3305 }
3274 3306  
3275 3307 rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
3276   - param_read_proc,
  3308 + &smi_params_proc_ops,
3277 3309 new_smi);
3278 3310 if (rv) {
3279 3311 dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
include/linux/ipmi_smi.h
... ... @@ -236,7 +236,7 @@
236 236 directory for this interface. Note that the entry will
237 237 automatically be dstroyed when the interface is destroyed. */
238 238 int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
239   - read_proc_t *read_proc,
  239 + const struct file_operations *proc_ops,
240 240 void *data);
241 241  
242 242 #endif /* __LINUX_IPMI_SMI_H */