Whamcloud - gitweb
LU-6215 lprocfs: handle seq_printf api change
[fs/lustre-release.git] / lustre / mdc / lproc_mdc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <linux/vfs.h>
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42
43 #include "mdc_internal.h"
44
45 #ifdef CONFIG_PROC_FS
46 static int mdc_active_seq_show(struct seq_file *m, void *v)
47 {
48         struct obd_device *dev = m->private;
49
50         LPROCFS_CLIMP_CHECK(dev);
51         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
52         LPROCFS_CLIMP_EXIT(dev);
53         return 0;
54 }
55
56 static ssize_t mdc_active_seq_write(struct file *file,
57                                     const char __user *buffer,
58                                     size_t count, loff_t *off)
59 {
60         struct obd_device *dev;
61         int val, rc;
62
63         dev = ((struct seq_file *)file->private_data)->private;
64         rc = lprocfs_write_helper(buffer, count, &val);
65         if (rc)
66                 return rc;
67         if (val < 0 || val > 1)
68                 return -ERANGE;
69
70         /* opposite senses */
71         if (dev->u.cli.cl_import->imp_deactive == val)
72                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
73         else
74                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
75
76         return count;
77 }
78 LPROC_SEQ_FOPS(mdc_active);
79
80 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
81 {
82         struct obd_device *dev = m->private;
83         __u32 max;
84
85         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
86         seq_printf(m, "%u\n", max);
87
88         return 0;
89 }
90
91 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
92                                                 const char __user *buffer,
93                                                 size_t count,
94                                                 loff_t *off)
95 {
96         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
97         int val;
98         int rc;
99
100         rc = lprocfs_write_helper(buffer, count, &val);
101         if (rc == 0)
102                 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
103
104         if (rc != 0)
105                 count = rc;
106
107         return count;
108 }
109 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
110
111
112 static int mdc_max_mod_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
113 {
114         struct obd_device *dev = m->private;
115         __u16 max;
116
117         max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
118         seq_printf(m, "%hu\n", max);
119
120         return 0;
121 }
122
123 static ssize_t mdc_max_mod_rpcs_in_flight_seq_write(struct file *file,
124                                                     const char __user *buffer,
125                                                     size_t count,
126                                                     loff_t *off)
127 {
128         struct obd_device *dev =
129                         ((struct seq_file *)file->private_data)->private;
130         int val;
131         int rc;
132
133         rc = lprocfs_write_helper(buffer, count, &val);
134         if (rc != 0)
135                 return rc;
136
137         if (val < 0 || val > USHRT_MAX)
138                 return -ERANGE;
139
140         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
141         if (rc != 0)
142                 count = rc;
143
144         return count;
145 }
146 LPROC_SEQ_FOPS(mdc_max_mod_rpcs_in_flight);
147
148
149 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
150 {
151         struct obd_device *dev = seq->private;
152
153         return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
154 }
155
156
157 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
158                                        const char __user *buf,
159                                        size_t len, loff_t *off)
160 {
161         struct seq_file *seq = file->private_data;
162         struct obd_device *dev = seq->private;
163         struct client_obd *cli = &dev->u.cli;
164
165         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
166
167         return len;
168 }
169 LPROC_SEQ_FOPS(mdc_rpc_stats);
170
171
172 LPROC_SEQ_FOPS_WO_TYPE(mdc, ping);
173
174 LPROC_SEQ_FOPS_RO_TYPE(mdc, uuid);
175 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
176 LPROC_SEQ_FOPS_RO_TYPE(mdc, blksize);
177 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytestotal);
178 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesfree);
179 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesavail);
180 LPROC_SEQ_FOPS_RO_TYPE(mdc, filestotal);
181 LPROC_SEQ_FOPS_RO_TYPE(mdc, filesfree);
182 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
183 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
184 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
185 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
186
187 static int mdc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
188 {
189         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
190 }
191 LPROC_SEQ_FOPS_RO(mdc_obd_max_pages_per_rpc);
192
193 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
194 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
195
196 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
197         { .name =       "uuid",
198           .fops =       &mdc_uuid_fops          },
199         { .name =       "ping",
200           .fops =       &mdc_ping_fops,
201           .proc_mode =  0222                    },
202         { .name =       "connect_flags",
203           .fops =       &mdc_connect_flags_fops },
204         { .name =       "blocksize",
205           .fops =       &mdc_blksize_fops       },
206         { .name =       "kbytestotal",
207           .fops =       &mdc_kbytestotal_fops   },
208         { .name =       "kbytesfree",
209           .fops =       &mdc_kbytesfree_fops    },
210         { .name =       "kbytesavail",
211           .fops =       &mdc_kbytesavail_fops   },
212         { .name =       "filestotal",
213           .fops =       &mdc_filestotal_fops    },
214         { .name =       "filesfree",
215           .fops =       &mdc_filesfree_fops     },
216         { .name =       "mds_server_uuid",
217           .fops =       &mdc_server_uuid_fops   },
218         { .name =       "mds_conn_uuid",
219           .fops =       &mdc_conn_uuid_fops     },
220         /*
221          * FIXME: below proc entry is provided, but not in used, instead
222          * sbi->sb_md_brw_size is used, the per obd variable should be used
223          * when CMD is enabled, and dir pages are managed in MDC layer.
224          * Remember to enable proc write function.
225          */
226         { .name =       "max_pages_per_rpc",
227           .fops =       &mdc_obd_max_pages_per_rpc_fops },
228         { .name =       "max_rpcs_in_flight",
229           .fops =       &mdc_max_rpcs_in_flight_fops    },
230         { .name =       "max_mod_rpcs_in_flight",
231           .fops =       &mdc_max_mod_rpcs_in_flight_fops        },
232         { .name =       "timeouts",
233           .fops =       &mdc_timeouts_fops              },
234         { .name =       "import",
235           .fops =       &mdc_import_fops                },
236         { .name =       "state",
237           .fops =       &mdc_state_fops                 },
238         { .name =       "pinger_recov",
239           .fops =       &mdc_pinger_recov_fops          },
240         { .name =       "rpc_stats",
241           .fops =       &mdc_rpc_stats_fops             },
242         { .name =       "active",
243           .fops =       &mdc_active_fops                },
244         { NULL }
245 };
246 #endif /* CONFIG_PROC_FS */