Whamcloud - gitweb
LU-7623 Add __user to seq_write buffer arguments
[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         int rc;
50
51         LPROCFS_CLIMP_CHECK(dev);
52         rc = seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
53         LPROCFS_CLIMP_EXIT(dev);
54         return rc;
55 }
56
57 static ssize_t mdc_active_seq_write(struct file *file,
58                                     const char __user *buffer,
59                                     size_t count, loff_t *off)
60 {
61         struct obd_device *dev;
62         int val, rc;
63
64         dev = ((struct seq_file *)file->private_data)->private;
65         rc = lprocfs_write_helper(buffer, count, &val);
66         if (rc)
67                 return rc;
68         if (val < 0 || val > 1)
69                 return -ERANGE;
70
71         /* opposite senses */
72         if (dev->u.cli.cl_import->imp_deactive == val)
73                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
74         else
75                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
76
77         return count;
78 }
79 LPROC_SEQ_FOPS(mdc_active);
80
81 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
82 {
83         struct obd_device *dev = m->private;
84         __u32 max;
85         int rc;
86
87         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
88         rc = seq_printf(m, "%u\n", max);
89
90         return rc;
91 }
92
93 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
94                                                 const char __user *buffer,
95                                                 size_t count,
96                                                 loff_t *off)
97 {
98         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
99         int val;
100         int rc;
101
102         rc = lprocfs_write_helper(buffer, count, &val);
103         if (rc == 0)
104                 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
105
106         if (rc != 0)
107                 count = rc;
108
109         return count;
110 }
111 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
112
113
114 static int mdc_max_mod_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
115 {
116         struct obd_device *dev = m->private;
117         __u16 max;
118         int rc;
119
120         max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
121         rc = seq_printf(m, "%hu\n", max);
122
123         return rc;
124 }
125
126 static ssize_t mdc_max_mod_rpcs_in_flight_seq_write(struct file *file,
127                                                     const char __user *buffer,
128                                                     size_t count,
129                                                     loff_t *off)
130 {
131         struct obd_device *dev =
132                         ((struct seq_file *)file->private_data)->private;
133         int val;
134         int rc;
135
136         rc = lprocfs_write_helper(buffer, count, &val);
137         if (rc != 0)
138                 return rc;
139
140         if (val < 0 || val > USHRT_MAX)
141                 return -ERANGE;
142
143         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
144         if (rc != 0)
145                 count = rc;
146
147         return count;
148 }
149 LPROC_SEQ_FOPS(mdc_max_mod_rpcs_in_flight);
150
151
152 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
153 {
154         struct obd_device *dev = seq->private;
155
156         return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
157 }
158
159
160 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
161                                        const char __user *buf,
162                                        size_t len, loff_t *off)
163 {
164         struct seq_file *seq = file->private_data;
165         struct obd_device *dev = seq->private;
166         struct client_obd *cli = &dev->u.cli;
167
168         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
169
170         return len;
171 }
172 LPROC_SEQ_FOPS(mdc_rpc_stats);
173
174
175 LPROC_SEQ_FOPS_WO_TYPE(mdc, ping);
176
177 LPROC_SEQ_FOPS_RO_TYPE(mdc, uuid);
178 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
179 LPROC_SEQ_FOPS_RO_TYPE(mdc, blksize);
180 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytestotal);
181 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesfree);
182 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesavail);
183 LPROC_SEQ_FOPS_RO_TYPE(mdc, filestotal);
184 LPROC_SEQ_FOPS_RO_TYPE(mdc, filesfree);
185 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
186 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
187 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
188 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
189
190 static int mdc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
191 {
192         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
193 }
194 LPROC_SEQ_FOPS_RO(mdc_obd_max_pages_per_rpc);
195
196 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
197 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
198
199 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
200         { .name =       "uuid",
201           .fops =       &mdc_uuid_fops          },
202         { .name =       "ping",
203           .fops =       &mdc_ping_fops,
204           .proc_mode =  0222                    },
205         { .name =       "connect_flags",
206           .fops =       &mdc_connect_flags_fops },
207         { .name =       "blocksize",
208           .fops =       &mdc_blksize_fops       },
209         { .name =       "kbytestotal",
210           .fops =       &mdc_kbytestotal_fops   },
211         { .name =       "kbytesfree",
212           .fops =       &mdc_kbytesfree_fops    },
213         { .name =       "kbytesavail",
214           .fops =       &mdc_kbytesavail_fops   },
215         { .name =       "filestotal",
216           .fops =       &mdc_filestotal_fops    },
217         { .name =       "filesfree",
218           .fops =       &mdc_filesfree_fops     },
219         { .name =       "mds_server_uuid",
220           .fops =       &mdc_server_uuid_fops   },
221         { .name =       "mds_conn_uuid",
222           .fops =       &mdc_conn_uuid_fops     },
223         /*
224          * FIXME: below proc entry is provided, but not in used, instead
225          * sbi->sb_md_brw_size is used, the per obd variable should be used
226          * when CMD is enabled, and dir pages are managed in MDC layer.
227          * Remember to enable proc write function.
228          */
229         { .name =       "max_pages_per_rpc",
230           .fops =       &mdc_obd_max_pages_per_rpc_fops },
231         { .name =       "max_rpcs_in_flight",
232           .fops =       &mdc_max_rpcs_in_flight_fops    },
233         { .name =       "max_mod_rpcs_in_flight",
234           .fops =       &mdc_max_mod_rpcs_in_flight_fops        },
235         { .name =       "timeouts",
236           .fops =       &mdc_timeouts_fops              },
237         { .name =       "import",
238           .fops =       &mdc_import_fops                },
239         { .name =       "state",
240           .fops =       &mdc_state_fops                 },
241         { .name =       "pinger_recov",
242           .fops =       &mdc_pinger_recov_fops          },
243         { .name =       "rpc_stats",
244           .fops =       &mdc_rpc_stats_fops             },
245         { .name =       "active",
246           .fops =       &mdc_active_fops                },
247         { NULL }
248 };
249 #endif /* CONFIG_PROC_FS */