Whamcloud - gitweb
LU-14976 ptlrpc: align function names with param names
[fs/lustre-release.git] / lustre / lmv / lproc_lmv.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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/seq_file.h>
35 #include <linux/statfs.h>
36 #include <lprocfs_status.h>
37 #include <obd_class.h>
38
39 #include "lmv_internal.h"
40
41 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
42                            char *buf)
43 {
44         struct obd_device *obd = container_of(kobj, struct obd_device,
45                                               obd_kset.kobj);
46
47         return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.lmv.lmv_mdt_count);
48 }
49 LUSTRE_RO_ATTR(numobd);
50
51 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
52                               char *buf)
53 {
54         struct obd_device *obd = container_of(kobj, struct obd_device,
55                                               obd_kset.kobj);
56
57         return scnprintf(buf, PAGE_SIZE, "%u\n",
58                 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_active_tgt_count);
59 }
60 LUSTRE_RO_ATTR(activeobd);
61
62 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
63                               char *buf)
64 {
65         struct obd_device *obd = container_of(kobj, struct obd_device,
66                                               obd_kset.kobj);
67
68         return scnprintf(buf, PAGE_SIZE, "%s\n",
69                         obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_uuid.uuid);
70 }
71 LUSTRE_RO_ATTR(desc_uuid);
72
73 static ssize_t qos_maxage_show(struct kobject *kobj,
74                                struct attribute *attr,
75                                char *buf)
76 {
77         struct obd_device *obd = container_of(kobj, struct obd_device,
78                                               obd_kset.kobj);
79
80         return scnprintf(buf, PAGE_SIZE, "%u\n",
81                         obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage);
82 }
83
84 static ssize_t qos_maxage_store(struct kobject *kobj,
85                                 struct attribute *attr,
86                                 const char *buffer,
87                                 size_t count)
88 {
89         struct obd_device *obd = container_of(kobj, struct obd_device,
90                                               obd_kset.kobj);
91         unsigned int val;
92         int rc;
93
94         rc = kstrtouint(buffer, 0, &val);
95         if (rc)
96                 return rc;
97
98         obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage = val;
99
100         return count;
101 }
102 LUSTRE_RW_ATTR(qos_maxage);
103
104 static ssize_t qos_prio_free_show(struct kobject *kobj,
105                                   struct attribute *attr,
106                                   char *buf)
107 {
108         struct obd_device *obd = container_of(kobj, struct obd_device,
109                                               obd_kset.kobj);
110
111         return scnprintf(buf, PAGE_SIZE, "%u%%\n",
112                         (obd->u.lmv.lmv_qos.lq_prio_free * 100 + 255) >> 8);
113 }
114
115 static ssize_t qos_prio_free_store(struct kobject *kobj,
116                                    struct attribute *attr,
117                                    const char *buffer,
118                                    size_t count)
119 {
120         struct obd_device *obd = container_of(kobj, struct obd_device,
121                                               obd_kset.kobj);
122         struct lmv_obd *lmv = &obd->u.lmv;
123         char buf[6], *tmp;
124         unsigned int val;
125         int rc;
126
127         /* "100%\n\0" should be largest string */
128         if (count >= sizeof(buf))
129                 return -ERANGE;
130
131         strncpy(buf, buffer, sizeof(buf));
132         buf[sizeof(buf) - 1] = '\0';
133         tmp = strchr(buf, '%');
134         if (tmp)
135                 *tmp = '\0';
136
137         rc = kstrtouint(buf, 0, &val);
138         if (rc)
139                 return rc;
140
141         if (val > 100)
142                 return -EINVAL;
143
144         lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
145         set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
146         set_bit(LQ_RESET, &lmv->lmv_qos.lq_flags);
147
148         return count;
149 }
150 LUSTRE_RW_ATTR(qos_prio_free);
151
152 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
153                                      struct attribute *attr,
154                                      char *buf)
155 {
156         struct obd_device *obd = container_of(kobj, struct obd_device,
157                                               obd_kset.kobj);
158
159         return scnprintf(buf, PAGE_SIZE, "%u%%\n",
160                         (obd->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
161 }
162
163 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
164                                       struct attribute *attr,
165                                       const char *buffer,
166                                       size_t count)
167 {
168         struct obd_device *obd = container_of(kobj, struct obd_device,
169                                               obd_kset.kobj);
170         struct lmv_obd *lmv = &obd->u.lmv;
171         char buf[6], *tmp;
172         unsigned int val;
173         int rc;
174
175         /* "100%\n\0" should be largest string */
176         if (count >= sizeof(buf))
177                 return -ERANGE;
178
179         strncpy(buf, buffer, sizeof(buf));
180         buf[sizeof(buf) - 1] = '\0';
181         tmp = strchr(buf, '%');
182         if (tmp)
183                 *tmp = '\0';
184
185         rc = kstrtouint(buf, 0, &val);
186         if (rc)
187                 return rc;
188
189         if (val > 100)
190                 return -EINVAL;
191
192         lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
193         set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
194
195         return count;
196 }
197 LUSTRE_RW_ATTR(qos_threshold_rr);
198
199 #ifdef CONFIG_PROC_FS
200 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
201 {
202         struct obd_device *obd = p->private;
203         struct lmv_obd *lmv = &obd->u.lmv;
204         struct lu_tgt_desc *tgt;
205
206         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
207                 tgt = lmv_tgt(lmv, (__u32)*pos);
208                 if (tgt)
209                         return tgt;
210
211                 ++*pos;
212         }
213
214         return NULL;
215 }
216
217 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
218 {
219 }
220
221 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
222 {
223         struct obd_device *obd = p->private;
224         struct lmv_obd *lmv = &obd->u.lmv;
225         struct lu_tgt_desc *tgt;
226
227         ++*pos;
228         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
229                 tgt = lmv_tgt(lmv, (__u32)*pos);
230                 if (tgt)
231                         return tgt;
232
233                 ++*pos;
234         }
235
236         return NULL;
237 }
238
239 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
240 {
241         struct lmv_tgt_desc     *tgt = v;
242
243         if (!tgt)
244                 return 0;
245
246         seq_printf(p, "%u: %s %sACTIVE\n",
247                    tgt->ltd_index, tgt->ltd_uuid.uuid,
248                    tgt->ltd_active ? "" : "IN");
249         return 0;
250 }
251
252 static const struct seq_operations lmv_tgt_sops = {
253         .start                 = lmv_tgt_seq_start,
254         .stop                  = lmv_tgt_seq_stop,
255         .next                  = lmv_tgt_seq_next,
256         .show                  = lmv_tgt_seq_show,
257 };
258
259 static int lmv_target_seq_open(struct inode *inode, struct file *file)
260 {
261         struct seq_file         *seq;
262         int                     rc;
263
264         rc = seq_open(file, &lmv_tgt_sops);
265         if (rc)
266                 return rc;
267
268         seq = file->private_data;
269         seq->private = PDE_DATA(inode);
270         return 0;
271 }
272
273 static const struct proc_ops lmv_proc_target_fops = {
274         PROC_OWNER(THIS_MODULE)
275         .proc_open      = lmv_target_seq_open,
276         .proc_read      = seq_read,
277         .proc_lseek     = seq_lseek,
278         .proc_release   = seq_release,
279 };
280 #endif /* CONFIG_PROC_FS */
281
282 static struct attribute *lmv_attrs[] = {
283         &lustre_attr_activeobd.attr,
284         &lustre_attr_desc_uuid.attr,
285         &lustre_attr_numobd.attr,
286         &lustre_attr_qos_maxage.attr,
287         &lustre_attr_qos_prio_free.attr,
288         &lustre_attr_qos_threshold_rr.attr,
289         NULL,
290 };
291
292 int lmv_tunables_init(struct obd_device *obd)
293 {
294         int rc;
295
296         obd->obd_ktype.default_attrs = lmv_attrs;
297         rc = lprocfs_obd_setup(obd, true);
298         if (rc)
299                 goto out_failed;
300 #ifdef CONFIG_PROC_FS
301         rc = lprocfs_alloc_md_stats(obd, 0);
302         if (rc) {
303                 lprocfs_obd_cleanup(obd);
304                 goto out_failed;
305         }
306
307         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
308                                 0444, &lmv_proc_target_fops, obd);
309         if (rc) {
310                 lprocfs_free_md_stats(obd);
311                 lprocfs_obd_cleanup(obd);
312                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
313                       obd->obd_name, rc);
314                 rc = 0;
315         }
316 #endif /* CONFIG_PROC_FS */
317 out_failed:
318         return rc;
319 }