Whamcloud - gitweb
52f59536b8c833892ecfa8bf24a387b27b8ff0b2
[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         struct lu_tgt_desc *tgt;
187
188         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
189                 tgt = lmv_tgt(lmv, (__u32)*pos);
190                 if (tgt)
191                         return tgt;
192
193                 ++*pos;
194         }
195
196         return NULL;
197 }
198
199 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
200 {
201 }
202
203 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
204 {
205         struct obd_device *dev = p->private;
206         struct lmv_obd *lmv = &dev->u.lmv;
207         struct lu_tgt_desc *tgt;
208
209         ++*pos;
210         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
211                 tgt = lmv_tgt(lmv, (__u32)*pos);
212                 if (tgt)
213                         return tgt;
214
215                 ++*pos;
216         }
217
218         return NULL;
219 }
220
221 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
222 {
223         struct lmv_tgt_desc     *tgt = v;
224
225         if (!tgt)
226                 return 0;
227
228         seq_printf(p, "%u: %s %sACTIVE\n",
229                    tgt->ltd_index, tgt->ltd_uuid.uuid,
230                    tgt->ltd_active ? "" : "IN");
231         return 0;
232 }
233
234 static const struct seq_operations lmv_tgt_sops = {
235         .start                 = lmv_tgt_seq_start,
236         .stop                  = lmv_tgt_seq_stop,
237         .next                  = lmv_tgt_seq_next,
238         .show                  = lmv_tgt_seq_show,
239 };
240
241 static int lmv_target_seq_open(struct inode *inode, struct file *file)
242 {
243         struct seq_file         *seq;
244         int                     rc;
245
246         rc = seq_open(file, &lmv_tgt_sops);
247         if (rc)
248                 return rc;
249
250         seq = file->private_data;
251         seq->private = PDE_DATA(inode);
252         return 0;
253 }
254
255 static const struct file_operations lmv_proc_target_fops = {
256         .owner                = THIS_MODULE,
257         .open                 = lmv_target_seq_open,
258         .read                 = seq_read,
259         .llseek               = seq_lseek,
260         .release              = seq_release,
261 };
262 #endif /* CONFIG_PROC_FS */
263
264 static struct attribute *lmv_attrs[] = {
265         &lustre_attr_activeobd.attr,
266         &lustre_attr_desc_uuid.attr,
267         &lustre_attr_numobd.attr,
268         &lustre_attr_qos_maxage.attr,
269         &lustre_attr_qos_prio_free.attr,
270         &lustre_attr_qos_threshold_rr.attr,
271         NULL,
272 };
273
274 int lmv_tunables_init(struct obd_device *obd)
275 {
276         int rc;
277
278         obd->obd_ktype.default_attrs = lmv_attrs;
279         rc = lprocfs_obd_setup(obd, true);
280         if (rc)
281                 goto out_failed;
282 #ifdef CONFIG_PROC_FS
283         rc = lprocfs_alloc_md_stats(obd, 0);
284         if (rc) {
285                 lprocfs_obd_cleanup(obd);
286                 goto out_failed;
287         }
288
289         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
290                                 0444, &lmv_proc_target_fops, obd);
291         if (rc) {
292                 lprocfs_free_md_stats(obd);
293                 lprocfs_obd_cleanup(obd);
294                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
295                       obd->obd_name, rc);
296                 rc = 0;
297         }
298 #endif /* CONFIG_PROC_FS */
299 out_failed:
300         return rc;
301 }