Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[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 +
161                         (QOS_THRESHOLD_MAX - 1)) / QOS_THRESHOLD_MAX);
162 }
163
164 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
165                                       struct attribute *attr,
166                                       const char *buffer,
167                                       size_t count)
168 {
169         struct obd_device *obd = container_of(kobj, struct obd_device,
170                                               obd_kset.kobj);
171         struct lmv_obd *lmv = &obd->u.lmv;
172         char buf[6], *tmp;
173         unsigned int val;
174         int rc;
175
176         /* "100%\n\0" should be largest string */
177         if (count >= sizeof(buf))
178                 return -ERANGE;
179
180         strncpy(buf, buffer, sizeof(buf));
181         buf[sizeof(buf) - 1] = '\0';
182         tmp = strchr(buf, '%');
183         if (tmp)
184                 *tmp = '\0';
185
186         rc = kstrtouint(buf, 0, &val);
187         if (rc)
188                 return rc;
189
190         if (val > 100)
191                 return -EINVAL;
192
193         lmv->lmv_qos.lq_threshold_rr = (val * QOS_THRESHOLD_MAX) / 100;
194         set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
195
196         return count;
197 }
198 LUSTRE_RW_ATTR(qos_threshold_rr);
199
200 #ifdef CONFIG_PROC_FS
201 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
202 {
203         struct obd_device *obd = p->private;
204         struct lmv_obd *lmv = &obd->u.lmv;
205         struct lu_tgt_desc *tgt;
206
207         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
208                 tgt = lmv_tgt(lmv, (__u32)*pos);
209                 if (tgt)
210                         return tgt;
211
212                 ++*pos;
213         }
214
215         return NULL;
216 }
217
218 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
219 {
220 }
221
222 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
223 {
224         struct obd_device *obd = p->private;
225         struct lmv_obd *lmv = &obd->u.lmv;
226         struct lu_tgt_desc *tgt;
227
228         ++*pos;
229         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
230                 tgt = lmv_tgt(lmv, (__u32)*pos);
231                 if (tgt)
232                         return tgt;
233
234                 ++*pos;
235         }
236
237         return NULL;
238 }
239
240 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
241 {
242         struct lmv_tgt_desc     *tgt = v;
243
244         if (!tgt)
245                 return 0;
246
247         seq_printf(p, "%u: %s %sACTIVE\n",
248                    tgt->ltd_index, tgt->ltd_uuid.uuid,
249                    tgt->ltd_active ? "" : "IN");
250         return 0;
251 }
252
253 static const struct seq_operations lmv_tgt_sops = {
254         .start                 = lmv_tgt_seq_start,
255         .stop                  = lmv_tgt_seq_stop,
256         .next                  = lmv_tgt_seq_next,
257         .show                  = lmv_tgt_seq_show,
258 };
259
260 static int lmv_target_seq_open(struct inode *inode, struct file *file)
261 {
262         struct seq_file         *seq;
263         int                     rc;
264
265         rc = seq_open(file, &lmv_tgt_sops);
266         if (rc)
267                 return rc;
268
269         seq = file->private_data;
270         seq->private = PDE_DATA(inode);
271         return 0;
272 }
273
274 static const struct proc_ops lmv_proc_target_fops = {
275         PROC_OWNER(THIS_MODULE)
276         .proc_open      = lmv_target_seq_open,
277         .proc_read      = seq_read,
278         .proc_lseek     = seq_lseek,
279         .proc_release   = seq_release,
280 };
281 #endif /* CONFIG_PROC_FS */
282
283 static struct attribute *lmv_attrs[] = {
284         &lustre_attr_activeobd.attr,
285         &lustre_attr_desc_uuid.attr,
286         &lustre_attr_numobd.attr,
287         &lustre_attr_qos_maxage.attr,
288         &lustre_attr_qos_prio_free.attr,
289         &lustre_attr_qos_threshold_rr.attr,
290         NULL,
291 };
292
293 int lmv_tunables_init(struct obd_device *obd)
294 {
295         int rc;
296
297         obd->obd_ktype.default_attrs = lmv_attrs;
298         rc = lprocfs_obd_setup(obd, true);
299         if (rc)
300                 goto out_failed;
301 #ifdef CONFIG_PROC_FS
302         rc = lprocfs_alloc_md_stats(obd, 0);
303         if (rc) {
304                 lprocfs_obd_cleanup(obd);
305                 goto out_failed;
306         }
307
308         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
309                                 0444, &lmv_proc_target_fops, obd);
310         if (rc) {
311                 lprocfs_free_md_stats(obd);
312                 lprocfs_obd_cleanup(obd);
313                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
314                       obd->obd_name, rc);
315                 rc = 0;
316         }
317 #endif /* CONFIG_PROC_FS */
318 out_failed:
319         return rc;
320 }