Whamcloud - gitweb
LU-8066 obdclass : Add infrastructure for procfs to sysfs migration
[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.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, 2016, 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/version.h>
35 #include <linux/vfs.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38
39 #include "mdc_internal.h"
40
41 #ifdef CONFIG_PROC_FS
42 static int mdc_active_seq_show(struct seq_file *m, void *v)
43 {
44         struct obd_device *dev = m->private;
45
46         LPROCFS_CLIMP_CHECK(dev);
47         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
48         LPROCFS_CLIMP_EXIT(dev);
49         return 0;
50 }
51
52 static ssize_t mdc_active_seq_write(struct file *file,
53                                     const char __user *buffer,
54                                     size_t count, loff_t *off)
55 {
56         struct obd_device *dev;
57         int rc;
58         __s64 val;
59
60         dev = ((struct seq_file *)file->private_data)->private;
61         rc = lprocfs_str_to_s64(buffer, count, &val);
62         if (rc)
63                 return rc;
64         if (val < 0 || val > 1)
65                 return -ERANGE;
66
67         /* opposite senses */
68         if (dev->u.cli.cl_import->imp_deactive == val)
69                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
70         else
71                 CDEBUG(D_CONFIG, "activate %llu: ignoring repeat request\n",
72                        val);
73
74         return count;
75 }
76 LPROC_SEQ_FOPS(mdc_active);
77
78 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device *dev = m->private;
81         __u32 max;
82
83         max = obd_get_max_rpcs_in_flight(&dev->u.cli);
84         seq_printf(m, "%u\n", max);
85
86         return 0;
87 }
88
89 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
90                                                 const char __user *buffer,
91                                                 size_t count, loff_t *off)
92 {
93         struct obd_device *dev;
94         __s64 val;
95         int rc;
96
97         dev = ((struct seq_file *)file->private_data)->private;
98         rc = lprocfs_str_to_s64(buffer, count, &val);
99         if (rc)
100                 return rc;
101
102         if (val < 0 || val > UINT_MAX)
103                 return -ERANGE;
104
105         rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
106         if (rc)
107                 return rc;
108
109         return count;
110 }
111 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
112
113 static int mdc_max_mod_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
114 {
115         struct obd_device *dev = m->private;
116         __u16 max;
117
118         max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
119         seq_printf(m, "%hu\n", max);
120
121         return 0;
122 }
123
124 static ssize_t mdc_max_mod_rpcs_in_flight_seq_write(struct file *file,
125                                                     const char __user *buffer,
126                                                     size_t count, loff_t *off)
127 {
128         struct obd_device *dev =
129                         ((struct seq_file *)file->private_data)->private;
130         __s64 val;
131         int rc;
132
133         rc = lprocfs_str_to_s64(buffer, count, &val);
134         if (rc)
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)
142                 count = rc;
143
144         return count;
145 }
146 LPROC_SEQ_FOPS(mdc_max_mod_rpcs_in_flight);
147
148 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
149 {
150         struct obd_device *dev = seq->private;
151
152         return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
153 }
154
155 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
156                                        const char __user *buf,
157                                        size_t len, loff_t *off)
158 {
159         struct seq_file *seq = file->private_data;
160         struct obd_device *dev = seq->private;
161         struct client_obd *cli = &dev->u.cli;
162
163         lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
164
165         return len;
166 }
167 LPROC_SEQ_FOPS(mdc_rpc_stats);
168
169 LPROC_SEQ_FOPS_WO_TYPE(mdc, ping);
170
171 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
172 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
173 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
174 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
175 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
176 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
177 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
178 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
179
180 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
181         { .name =       "ping",
182           .fops =       &mdc_ping_fops,
183           .proc_mode =  0222                    },
184         { .name =       "connect_flags",
185           .fops =       &mdc_connect_flags_fops },
186         { .name =       "mds_server_uuid",
187           .fops =       &mdc_server_uuid_fops   },
188         { .name =       "mds_conn_uuid",
189           .fops =       &mdc_conn_uuid_fops     },
190         { .name =       "max_pages_per_rpc",
191           .fops =       &mdc_obd_max_pages_per_rpc_fops },
192         { .name =       "max_rpcs_in_flight",
193           .fops =       &mdc_max_rpcs_in_flight_fops    },
194         { .name =       "max_mod_rpcs_in_flight",
195           .fops =       &mdc_max_mod_rpcs_in_flight_fops        },
196         { .name =       "timeouts",
197           .fops =       &mdc_timeouts_fops              },
198         { .name =       "import",
199           .fops =       &mdc_import_fops                },
200         { .name =       "state",
201           .fops =       &mdc_state_fops                 },
202         { .name =       "pinger_recov",
203           .fops =       &mdc_pinger_recov_fops          },
204         { .name =       "rpc_stats",
205           .fops =       &mdc_rpc_stats_fops             },
206         { .name =       "active",
207           .fops =       &mdc_active_fops                },
208         { NULL }
209 };
210 #endif /* CONFIG_PROC_FS */