GNU Linux-libre 4.14.332-gnu1
[releases.git] / drivers / staging / lustre / 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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/vfs.h>
35 #include <obd_class.h>
36 #include <lprocfs_status.h>
37 #include "mdc_internal.h"
38
39 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
40                            char *buf)
41 {
42         struct obd_device *dev = container_of(kobj, struct obd_device,
43                                               obd_kobj);
44
45         return sprintf(buf, "%u\n", !dev->u.cli.cl_import->imp_deactive);
46 }
47
48 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
49                             const char *buffer, size_t count)
50 {
51         struct obd_device *dev = container_of(kobj, struct obd_device,
52                                               obd_kobj);
53         unsigned long val;
54         int rc;
55
56         rc = kstrtoul(buffer, 10, &val);
57         if (rc)
58                 return rc;
59
60         if (val > 1)
61                 return -ERANGE;
62
63         /* opposite senses */
64         if (dev->u.cli.cl_import->imp_deactive == val) {
65                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
66                 if (rc)
67                         count = rc;
68         } else {
69                 CDEBUG(D_CONFIG, "activate %lu: ignoring repeat request\n", val);
70         }
71         return count;
72 }
73 LUSTRE_RW_ATTR(active);
74
75 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
76                                        struct attribute *attr,
77                                        char *buf)
78 {
79         int len;
80         struct obd_device *dev = container_of(kobj, struct obd_device,
81                                               obd_kobj);
82         __u32 max;
83
84         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
85         len = sprintf(buf, "%u\n", max);
86
87         return len;
88 }
89
90 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
91                                         struct attribute *attr,
92                                         const char *buffer,
93                                         size_t count)
94 {
95         struct obd_device *dev = container_of(kobj, struct obd_device,
96                                               obd_kobj);
97         int rc;
98         unsigned long val;
99
100         rc = kstrtoul(buffer, 10, &val);
101         if (rc)
102                 return rc;
103
104         rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
105         if (rc)
106                 count = rc;
107
108         return count;
109 }
110 LUSTRE_RW_ATTR(max_rpcs_in_flight);
111
112 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
113                                            struct attribute *attr,
114                                            char *buf)
115 {
116         struct obd_device *dev = container_of(kobj, struct obd_device,
117                                               obd_kobj);
118         u16 max;
119         int len;
120
121         max = dev->u.cli.cl_max_mod_rpcs_in_flight;
122         len = sprintf(buf, "%hu\n", max);
123
124         return len;
125 }
126
127 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
128                                             struct attribute *attr,
129                                             const char *buffer,
130                                             size_t count)
131 {
132         struct obd_device *dev = container_of(kobj, struct obd_device,
133                                               obd_kobj);
134         u16 val;
135         int rc;
136
137         rc = kstrtou16(buffer, 10, &val);
138         if (rc)
139                 return rc;
140
141         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
142         if (rc)
143                 count = rc;
144
145         return count;
146 }
147 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
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 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
157                                        const char __user *buf,
158                                        size_t len, loff_t *off)
159 {
160         struct seq_file *seq = file->private_data;
161         struct obd_device *dev = seq->private;
162         struct client_obd *cli = &dev->u.cli;
163
164         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
165
166         return len;
167 }
168 LPROC_SEQ_FOPS(mdc_rpc_stats);
169
170 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
171
172 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
173 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
174 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
175 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
176 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
177
178 /*
179  * Note: below sysfs entry is provided, but not currently in use, instead
180  * sbi->sb_md_brw_size is used, the per obd variable should be used
181  * when DNE is enabled, and dir pages are managed in MDC layer.
182  * Don't forget to enable sysfs store function then.
183  */
184 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
185                                       struct attribute *attr,
186                                       char *buf)
187 {
188         struct obd_device *dev = container_of(kobj, struct obd_device,
189                                               obd_kobj);
190         struct client_obd *cli = &dev->u.cli;
191
192         return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
193 }
194 LUSTRE_RO_ATTR(max_pages_per_rpc);
195
196 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
197 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
198
199 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
200         { "ping",               &mdc_ping_fops,                 NULL, 0222 },
201         { "connect_flags",      &mdc_connect_flags_fops,        NULL, 0 },
202         /*{ "filegroups",       lprocfs_rd_filegroups,          NULL, 0 },*/
203         { "mds_server_uuid",    &mdc_server_uuid_fops,          NULL, 0 },
204         { "mds_conn_uuid",      &mdc_conn_uuid_fops,            NULL, 0 },
205         { "timeouts",           &mdc_timeouts_fops,             NULL, 0 },
206         { "import",             &mdc_import_fops,               NULL, 0 },
207         { "state",              &mdc_state_fops,                NULL, 0 },
208         { "pinger_recov",       &mdc_pinger_recov_fops,         NULL, 0 },
209         { .name =       "rpc_stats",
210           .fops =       &mdc_rpc_stats_fops             },
211         { NULL }
212 };
213
214 static struct attribute *mdc_attrs[] = {
215         &lustre_attr_active.attr,
216         &lustre_attr_max_rpcs_in_flight.attr,
217         &lustre_attr_max_mod_rpcs_in_flight.attr,
218         &lustre_attr_max_pages_per_rpc.attr,
219         NULL,
220 };
221
222 static const struct attribute_group mdc_attr_group = {
223         .attrs = mdc_attrs,
224 };
225
226 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
227 {
228         lvars->sysfs_vars   = &mdc_attr_group;
229         lvars->obd_vars     = lprocfs_mdc_obd_vars;
230 }