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