4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <linux/seq_file.h>
35 #include <linux/statfs.h>
36 #include <lprocfs_status.h>
37 #include <obd_class.h>
39 #include "lmv_internal.h"
41 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
44 struct obd_device *obd = container_of(kobj, struct obd_device,
47 return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.lmv.lmv_mdt_count);
49 LUSTRE_RO_ATTR(numobd);
51 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
54 struct obd_device *obd = container_of(kobj, struct obd_device,
57 return scnprintf(buf, PAGE_SIZE, "%u\n",
58 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_active_tgt_count);
60 LUSTRE_RO_ATTR(activeobd);
62 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
65 struct obd_device *obd = container_of(kobj, struct obd_device,
68 return scnprintf(buf, PAGE_SIZE, "%s\n",
69 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_uuid.uuid);
71 LUSTRE_RO_ATTR(desc_uuid);
73 static ssize_t qos_maxage_show(struct kobject *kobj,
74 struct attribute *attr,
77 struct obd_device *obd = container_of(kobj, struct obd_device,
80 return scnprintf(buf, PAGE_SIZE, "%u\n",
81 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage);
84 static ssize_t qos_maxage_store(struct kobject *kobj,
85 struct attribute *attr,
89 struct obd_device *obd = container_of(kobj, struct obd_device,
94 rc = kstrtouint(buffer, 0, &val);
98 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage = val;
102 LUSTRE_RW_ATTR(qos_maxage);
104 static ssize_t qos_prio_free_show(struct kobject *kobj,
105 struct attribute *attr,
108 struct obd_device *obd = container_of(kobj, struct obd_device,
111 return scnprintf(buf, PAGE_SIZE, "%u%%\n",
112 (obd->u.lmv.lmv_qos.lq_prio_free * 100 + 255) >> 8);
115 static ssize_t qos_prio_free_store(struct kobject *kobj,
116 struct attribute *attr,
120 struct obd_device *obd = container_of(kobj, struct obd_device,
122 struct lmv_obd *lmv = &obd->u.lmv;
126 rc = kstrtouint(buffer, 0, &val);
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);
139 LUSTRE_RW_ATTR(qos_prio_free);
141 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
142 struct attribute *attr,
145 struct obd_device *obd = container_of(kobj, struct obd_device,
148 return scnprintf(buf, PAGE_SIZE, "%u%%\n",
149 (obd->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
152 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
153 struct attribute *attr,
157 struct obd_device *obd = container_of(kobj, struct obd_device,
159 struct lmv_obd *lmv = &obd->u.lmv;
163 rc = kstrtouint(buffer, 0, &val);
170 lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
171 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
175 LUSTRE_RW_ATTR(qos_threshold_rr);
177 #ifdef CONFIG_PROC_FS
178 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
180 struct obd_device *obd = p->private;
181 struct lmv_obd *lmv = &obd->u.lmv;
182 struct lu_tgt_desc *tgt;
184 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
185 tgt = lmv_tgt(lmv, (__u32)*pos);
195 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
199 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
201 struct obd_device *obd = p->private;
202 struct lmv_obd *lmv = &obd->u.lmv;
203 struct lu_tgt_desc *tgt;
206 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
207 tgt = lmv_tgt(lmv, (__u32)*pos);
217 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
219 struct lmv_tgt_desc *tgt = v;
224 seq_printf(p, "%u: %s %sACTIVE\n",
225 tgt->ltd_index, tgt->ltd_uuid.uuid,
226 tgt->ltd_active ? "" : "IN");
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,
237 static int lmv_target_seq_open(struct inode *inode, struct file *file)
239 struct seq_file *seq;
242 rc = seq_open(file, &lmv_tgt_sops);
246 seq = file->private_data;
247 seq->private = PDE_DATA(inode);
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,
258 #endif /* CONFIG_PROC_FS */
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,
270 int lmv_tunables_init(struct obd_device *obd)
274 obd->obd_ktype.default_attrs = lmv_attrs;
275 rc = lprocfs_obd_setup(obd, true);
278 #ifdef CONFIG_PROC_FS
279 rc = lprocfs_alloc_md_stats(obd, 0);
281 lprocfs_obd_cleanup(obd);
285 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
286 0444, &lmv_proc_target_fops, obd);
288 lprocfs_free_md_stats(obd);
289 lprocfs_obd_cleanup(obd);
290 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
294 #endif /* CONFIG_PROC_FS */