Whamcloud - gitweb
feded160ee133b29525822a28c42dbd333bd9e11
[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         unsigned int val;
124         int rc;
125
126         rc = kstrtouint(buffer, 0, &val);
127         if (rc)
128                 return rc;
129
130         if (val > 100)
131                 return -EINVAL;
132
133         lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
134         set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
135         set_bit(LQ_RESET, &lmv->lmv_qos.lq_flags);
136
137         return count;
138 }
139 LUSTRE_RW_ATTR(qos_prio_free);
140
141 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
142                                      struct attribute *attr,
143                                      char *buf)
144 {
145         struct obd_device *obd = container_of(kobj, struct obd_device,
146                                               obd_kset.kobj);
147
148         return scnprintf(buf, PAGE_SIZE, "%u%%\n",
149                         (obd->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
150 }
151
152 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
153                                       struct attribute *attr,
154                                       const char *buffer,
155                                       size_t count)
156 {
157         struct obd_device *obd = container_of(kobj, struct obd_device,
158                                               obd_kset.kobj);
159         struct lmv_obd *lmv = &obd->u.lmv;
160         unsigned int val;
161         int rc;
162
163         rc = kstrtouint(buffer, 0, &val);
164         if (rc)
165                 return rc;
166
167         if (val > 100)
168                 return -EINVAL;
169
170         lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
171         set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
172
173         return count;
174 }
175 LUSTRE_RW_ATTR(qos_threshold_rr);
176
177 #ifdef CONFIG_PROC_FS
178 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
179 {
180         struct obd_device *obd = p->private;
181         struct lmv_obd *lmv = &obd->u.lmv;
182         struct lu_tgt_desc *tgt;
183
184         while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
185                 tgt = lmv_tgt(lmv, (__u32)*pos);
186                 if (tgt)
187                         return tgt;
188
189                 ++*pos;
190         }
191
192         return NULL;
193 }
194
195 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
196 {
197 }
198
199 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
200 {
201         struct obd_device *obd = p->private;
202         struct lmv_obd *lmv = &obd->u.lmv;
203         struct lu_tgt_desc *tgt;
204
205         ++*pos;
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 int lmv_tgt_seq_show(struct seq_file *p, void *v)
218 {
219         struct lmv_tgt_desc     *tgt = v;
220
221         if (!tgt)
222                 return 0;
223
224         seq_printf(p, "%u: %s %sACTIVE\n",
225                    tgt->ltd_index, tgt->ltd_uuid.uuid,
226                    tgt->ltd_active ? "" : "IN");
227         return 0;
228 }
229
230 static const struct seq_operations lmv_tgt_sops = {
231         .start                 = lmv_tgt_seq_start,
232         .stop                  = lmv_tgt_seq_stop,
233         .next                  = lmv_tgt_seq_next,
234         .show                  = lmv_tgt_seq_show,
235 };
236
237 static int lmv_target_seq_open(struct inode *inode, struct file *file)
238 {
239         struct seq_file         *seq;
240         int                     rc;
241
242         rc = seq_open(file, &lmv_tgt_sops);
243         if (rc)
244                 return rc;
245
246         seq = file->private_data;
247         seq->private = PDE_DATA(inode);
248         return 0;
249 }
250
251 static const struct proc_ops lmv_proc_target_fops = {
252         PROC_OWNER(THIS_MODULE)
253         .proc_open      = lmv_target_seq_open,
254         .proc_read      = seq_read,
255         .proc_lseek     = seq_lseek,
256         .proc_release   = seq_release,
257 };
258 #endif /* CONFIG_PROC_FS */
259
260 static struct attribute *lmv_attrs[] = {
261         &lustre_attr_activeobd.attr,
262         &lustre_attr_desc_uuid.attr,
263         &lustre_attr_numobd.attr,
264         &lustre_attr_qos_maxage.attr,
265         &lustre_attr_qos_prio_free.attr,
266         &lustre_attr_qos_threshold_rr.attr,
267         NULL,
268 };
269
270 int lmv_tunables_init(struct obd_device *obd)
271 {
272         int rc;
273
274         obd->obd_ktype.default_attrs = lmv_attrs;
275         rc = lprocfs_obd_setup(obd, true);
276         if (rc)
277                 goto out_failed;
278 #ifdef CONFIG_PROC_FS
279         rc = lprocfs_alloc_md_stats(obd, 0);
280         if (rc) {
281                 lprocfs_obd_cleanup(obd);
282                 goto out_failed;
283         }
284
285         rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
286                                 0444, &lmv_proc_target_fops, obd);
287         if (rc) {
288                 lprocfs_free_md_stats(obd);
289                 lprocfs_obd_cleanup(obd);
290                 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
291                       obd->obd_name, rc);
292                 rc = 0;
293         }
294 #endif /* CONFIG_PROC_FS */
295 out_failed:
296         return rc;
297 }