Whamcloud - gitweb
LU-12635 build: Support for gcc -Wimplicit-fallthrough
[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  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #define DEBUG_SUBSYSTEM S_CLASS
34
35 #include <linux/seq_file.h>
36 #include <linux/statfs.h>
37 #include <lprocfs_status.h>
38 #include <obd_class.h>
39
40 #include "lmv_internal.h"
41
42 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
43                            char *buf)
44 {
45         struct obd_device *dev = container_of(kobj, struct obd_device,
46                                               obd_kset.kobj);
47         struct lmv_desc *desc;
48
49         desc = &dev->u.lmv.desc;
50         return sprintf(buf, "%u\n", desc->ld_tgt_count);
51 }
52 LUSTRE_RO_ATTR(numobd);
53
54 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
55                               char *buf)
56 {
57         struct obd_device *dev = container_of(kobj, struct obd_device,
58                                               obd_kset.kobj);
59         struct lmv_desc *desc;
60
61         desc = &dev->u.lmv.desc;
62         return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
63 }
64 LUSTRE_RO_ATTR(activeobd);
65
66 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
67                               char *buf)
68 {
69         struct obd_device *dev = container_of(kobj, struct obd_device,
70                                               obd_kset.kobj);
71         struct lmv_desc *desc;
72
73         desc = &dev->u.lmv.desc;
74         return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
75 }
76 LUSTRE_RO_ATTR(desc_uuid);
77
78 static ssize_t qos_maxage_show(struct kobject *kobj,
79                                struct attribute *attr,
80                                char *buf)
81 {
82         struct obd_device *dev = container_of(kobj, struct obd_device,
83                                               obd_kset.kobj);
84
85         return sprintf(buf, "%u\n", dev->u.lmv.desc.ld_qos_maxage);
86 }
87
88 static ssize_t qos_maxage_store(struct kobject *kobj,
89                                 struct attribute *attr,
90                                 const char *buffer,
91                                 size_t count)
92 {
93         struct obd_device *dev = container_of(kobj, struct obd_device,
94                                               obd_kset.kobj);
95         unsigned int val;
96         int rc;
97
98         rc = kstrtouint(buffer, 0, &val);
99         if (rc)
100                 return rc;
101
102         dev->u.lmv.desc.ld_qos_maxage = val;
103
104         return count;
105 }
106 LUSTRE_RW_ATTR(qos_maxage);
107
108 static ssize_t qos_prio_free_show(struct kobject *kobj,
109                                   struct attribute *attr,
110                                   char *buf)
111 {
112         struct obd_device *dev = container_of(kobj, struct obd_device,
113                                               obd_kset.kobj);
114
115         return sprintf(buf, "%u%%\n",
116                        (dev->u.lmv.lmv_qos.lq_prio_free * 100 + 255) >> 8);
117 }
118
119 static ssize_t qos_prio_free_store(struct kobject *kobj,
120                                    struct attribute *attr,
121                                    const char *buffer,
122                                    size_t count)
123 {
124         struct obd_device *dev = container_of(kobj, struct obd_device,
125                                               obd_kset.kobj);
126         struct lmv_obd *lmv = &dev->u.lmv;
127         unsigned int val;
128         int rc;
129
130         rc = kstrtouint(buffer, 0, &val);
131         if (rc)
132                 return rc;
133
134         if (val > 100)
135                 return -EINVAL;
136
137         lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
138         lmv->lmv_qos.lq_dirty = 1;
139         lmv->lmv_qos.lq_reset = 1;
140
141         return count;
142 }
143 LUSTRE_RW_ATTR(qos_prio_free);
144
145 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
146                                      struct attribute *attr,
147                                      char *buf)
148 {
149         struct obd_device *dev = container_of(kobj, struct obd_device,
150                                               obd_kset.kobj);
151
152         return sprintf(buf, "%u%%\n",
153                        (dev->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
154 }
155
156 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
157                                       struct attribute *attr,
158                                       const char *buffer,
159                                       size_t count)
160 {
161         struct obd_device *dev = container_of(kobj, struct obd_device,
162                                               obd_kset.kobj);
163         struct lmv_obd *lmv = &dev->u.lmv;
164         unsigned int val;
165         int rc;
166
167         rc = kstrtouint(buffer, 0, &val);
168         if (rc)
169                 return rc;
170
171         if (val > 100)
172                 return -EINVAL;
173
174         lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
175         lmv->lmv_qos.lq_dirty = 1;
176
177         return count;
178 }
179 LUSTRE_RW_ATTR(qos_threshold_rr);
180
181 #ifdef CONFIG_PROC_FS
182 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
183 {
184         struct obd_device       *dev = p->private;
185         struct lmv_obd          *lmv = &dev->u.lmv;
186
187         while (*pos < lmv->tgts_size) {
188                 if (lmv->tgts[*pos])
189                         return lmv->tgts[*pos];
190                 ++*pos;
191         }
192
193         return  NULL;
194 }
195
196 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
197 {
198 }
199
200 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
201 {
202         struct obd_device       *dev = p->private;
203         struct lmv_obd          *lmv = &dev->u.lmv;
204
205         ++*pos;
206         while (*pos < lmv->tgts_size) {
207                 if (lmv->tgts[*pos])
208                         return lmv->tgts[*pos];
209                 ++*pos;
210         }
211
212         return  NULL;
213 }
214
215 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
216 {
217         struct lmv_tgt_desc     *tgt = v;
218
219         if (!tgt)
220                 return 0;
221
222         seq_printf(p, "%u: %s %sACTIVE\n",
223                    tgt->ltd_index, tgt->ltd_uuid.uuid,
224                    tgt->ltd_active ? "" : "IN");
225         return 0;
226 }
227
228 static const struct seq_operations lmv_tgt_sops = {
229         .start                 = lmv_tgt_seq_start,
230         .stop                  = lmv_tgt_seq_stop,
231         .next                  = lmv_tgt_seq_next,
232         .show                  = lmv_tgt_seq_show,
233 };
234
235 static int lmv_target_seq_open(struct inode *inode, struct file *file)
236 {
237         struct seq_file         *seq;
238         int                     rc;
239
240         rc = seq_open(file, &lmv_tgt_sops);
241         if (rc)
242                 return rc;
243
244         seq = file->private_data;
245         seq->private = PDE_DATA(inode);
246         return 0;
247 }
248
249 static const struct file_operations lmv_proc_target_fops = {
250         .owner                = THIS_MODULE,
251         .open                 = lmv_target_seq_open,
252         .read                 = seq_read,
253         .llseek               = seq_lseek,
254         .release              = seq_release,
255 };
256 #endif /* CONFIG_PROC_FS */
257
258 static struct attribute *lmv_attrs[] = {
259         &lustre_attr_activeobd.attr,
260         &lustre_attr_desc_uuid.attr,
261         &lustre_attr_numobd.attr,
262         &lustre_attr_qos_maxage.attr,
263         &lustre_attr_qos_prio_free.attr,
264         &lustre_attr_qos_threshold_rr.attr,
265         NULL,
266 };
267
268 int lmv_tunables_init(struct obd_device *obd)
269 {
270         int rc;
271
272         obd->obd_ktype.default_attrs = lmv_attrs;
273         rc = lprocfs_obd_setup(obd, true);
274         if (rc)
275                 goto out_failed;
276 #ifdef CONFIG_PROC_FS
277         rc = lprocfs_alloc_md_stats(obd, 0);
278         if (rc) {
279                 lprocfs_obd_cleanup(obd);
280                 goto out_failed;
281         }
282
283         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
284                                 0444, &lmv_proc_target_fops, obd);
285         if (rc) {
286                 lprocfs_free_md_stats(obd);
287                 lprocfs_obd_cleanup(obd);
288                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
289                       obd->obd_name, rc);
290                 rc = 0;
291         }
292 #endif /* CONFIG_PROC_FS */
293 out_failed:
294         return rc;
295 }