Linux-libre 4.15.7-gnu
[librecmc/linux-libre.git] / drivers / staging / lustre / lustre / mdc / lproc_mdc.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 only,
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License version 2 for more details (a copy is included
15  * in the LICENSE file that accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License
18  * version 2 along with this program; If not, see
19  * http://www.gnu.org/licenses/gpl-2.0.html
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Use is subject to license terms.
26  *
27  * Copyright (c) 2011, 2015, Intel Corporation.
28  */
29 /*
30  * This file is part of Lustre, http://www.lustre.org/
31  * Lustre is a trademark of Sun Microsystems, Inc.
32  */
33 #define DEBUG_SUBSYSTEM S_CLASS
34
35 #include <linux/vfs.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include "mdc_internal.h"
39
40 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
41                            char *buf)
42 {
43         struct obd_device *dev = container_of(kobj, struct obd_device,
44                                               obd_kobj);
45
46         return sprintf(buf, "%u\n", !dev->u.cli.cl_import->imp_deactive);
47 }
48
49 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
50                             const char *buffer, size_t count)
51 {
52         struct obd_device *dev = container_of(kobj, struct obd_device,
53                                               obd_kobj);
54         unsigned long val;
55         int rc;
56
57         rc = kstrtoul(buffer, 10, &val);
58         if (rc)
59                 return rc;
60
61         if (val > 1)
62                 return -ERANGE;
63
64         /* opposite senses */
65         if (dev->u.cli.cl_import->imp_deactive == val) {
66                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
67                 if (rc)
68                         count = rc;
69         } else {
70                 CDEBUG(D_CONFIG, "activate %lu: ignoring repeat request\n", val);
71         }
72         return count;
73 }
74 LUSTRE_RW_ATTR(active);
75
76 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
77                                        struct attribute *attr,
78                                        char *buf)
79 {
80         int len;
81         struct obd_device *dev = container_of(kobj, struct obd_device,
82                                               obd_kobj);
83         __u32 max;
84
85         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
86         len = sprintf(buf, "%u\n", max);
87
88         return len;
89 }
90
91 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
92                                         struct attribute *attr,
93                                         const char *buffer,
94                                         size_t count)
95 {
96         struct obd_device *dev = container_of(kobj, struct obd_device,
97                                               obd_kobj);
98         int rc;
99         unsigned long val;
100
101         rc = kstrtoul(buffer, 10, &val);
102         if (rc)
103                 return rc;
104
105         rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
106         if (rc)
107                 count = rc;
108
109         return count;
110 }
111 LUSTRE_RW_ATTR(max_rpcs_in_flight);
112
113 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
114                                            struct attribute *attr,
115                                            char *buf)
116 {
117         struct obd_device *dev = container_of(kobj, struct obd_device,
118                                               obd_kobj);
119         u16 max;
120         int len;
121
122         max = dev->u.cli.cl_max_mod_rpcs_in_flight;
123         len = sprintf(buf, "%hu\n", max);
124
125         return len;
126 }
127
128 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
129                                             struct attribute *attr,
130                                             const char *buffer,
131                                             size_t count)
132 {
133         struct obd_device *dev = container_of(kobj, struct obd_device,
134                                               obd_kobj);
135         u16 val;
136         int rc;
137
138         rc = kstrtou16(buffer, 10, &val);
139         if (rc)
140                 return rc;
141
142         rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
143         if (rc)
144                 count = rc;
145
146         return count;
147 }
148 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
149
150 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
151 {
152         struct obd_device *dev = seq->private;
153
154         return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
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 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
172
173 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
174 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
175 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
176 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
177 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
178
179 /*
180  * Note: below sysfs entry is provided, but not currently in use, instead
181  * sbi->sb_md_brw_size is used, the per obd variable should be used
182  * when DNE is enabled, and dir pages are managed in MDC layer.
183  * Don't forget to enable sysfs store function then.
184  */
185 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
186                                       struct attribute *attr,
187                                       char *buf)
188 {
189         struct obd_device *dev = container_of(kobj, struct obd_device,
190                                               obd_kobj);
191         struct client_obd *cli = &dev->u.cli;
192
193         return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
194 }
195 LUSTRE_RO_ATTR(max_pages_per_rpc);
196
197 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
198 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
199
200 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
201         { "ping",               &mdc_ping_fops,                 NULL, 0222 },
202         { "connect_flags",      &mdc_connect_flags_fops,        NULL, 0 },
203         /*{ "filegroups",       lprocfs_rd_filegroups,          NULL, 0 },*/
204         { "mds_server_uuid",    &mdc_server_uuid_fops,          NULL, 0 },
205         { "mds_conn_uuid",      &mdc_conn_uuid_fops,            NULL, 0 },
206         { "timeouts",           &mdc_timeouts_fops,             NULL, 0 },
207         { "import",             &mdc_import_fops,               NULL, 0 },
208         { "state",              &mdc_state_fops,                NULL, 0 },
209         { "pinger_recov",       &mdc_pinger_recov_fops,         NULL, 0 },
210         { .name =       "rpc_stats",
211           .fops =       &mdc_rpc_stats_fops             },
212         { NULL }
213 };
214
215 static struct attribute *mdc_attrs[] = {
216         &lustre_attr_active.attr,
217         &lustre_attr_max_rpcs_in_flight.attr,
218         &lustre_attr_max_mod_rpcs_in_flight.attr,
219         &lustre_attr_max_pages_per_rpc.attr,
220         NULL,
221 };
222
223 static const struct attribute_group mdc_attr_group = {
224         .attrs = mdc_attrs,
225 };
226
227 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
228 {
229         lvars->sysfs_vars   = &mdc_attr_group;
230         lvars->obd_vars     = lprocfs_mdc_obd_vars;
231 }