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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_CLASS
35 #include <linux/seq_file.h>
36 #include <linux/statfs.h>
37 #include <lprocfs_status.h>
38 #include <obd_class.h>
40 #include "lmv_internal.h"
42 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
45 struct obd_device *obd = container_of(kobj, struct obd_device,
48 return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.lmv.lmv_mdt_count);
50 LUSTRE_RO_ATTR(numobd);
52 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
55 struct obd_device *obd = container_of(kobj, struct obd_device,
58 return scnprintf(buf, PAGE_SIZE, "%u\n",
59 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_active_tgt_count);
61 LUSTRE_RO_ATTR(activeobd);
63 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
66 struct obd_device *obd = container_of(kobj, struct obd_device,
69 return scnprintf(buf, PAGE_SIZE, "%s\n",
70 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_uuid.uuid);
72 LUSTRE_RO_ATTR(desc_uuid);
74 static ssize_t qos_maxage_show(struct kobject *kobj,
75 struct attribute *attr,
78 struct obd_device *obd = container_of(kobj, struct obd_device,
81 return scnprintf(buf, PAGE_SIZE, "%u\n",
82 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage);
85 static ssize_t qos_maxage_store(struct kobject *kobj,
86 struct attribute *attr,
90 struct obd_device *obd = container_of(kobj, struct obd_device,
95 rc = kstrtouint(buffer, 0, &val);
99 obd->u.lmv.lmv_mdt_descs.ltd_lmv_desc.ld_qos_maxage = val;
103 LUSTRE_RW_ATTR(qos_maxage);
105 static ssize_t qos_prio_free_show(struct kobject *kobj,
106 struct attribute *attr,
109 struct obd_device *obd = container_of(kobj, struct obd_device,
112 return scnprintf(buf, PAGE_SIZE, "%u%%\n",
113 (obd->u.lmv.lmv_qos.lq_prio_free * 100 + 255) >> 8);
116 static ssize_t qos_prio_free_store(struct kobject *kobj,
117 struct attribute *attr,
121 struct obd_device *obd = container_of(kobj, struct obd_device,
123 struct lmv_obd *lmv = &obd->u.lmv;
127 rc = kstrtouint(buffer, 0, &val);
134 lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
135 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
136 set_bit(LQ_RESET, &lmv->lmv_qos.lq_flags);
140 LUSTRE_RW_ATTR(qos_prio_free);
142 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
143 struct attribute *attr,
146 struct obd_device *obd = container_of(kobj, struct obd_device,
149 return scnprintf(buf, PAGE_SIZE, "%u%%\n",
150 (obd->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
153 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
154 struct attribute *attr,
158 struct obd_device *obd = container_of(kobj, struct obd_device,
160 struct lmv_obd *lmv = &obd->u.lmv;
164 rc = kstrtouint(buffer, 0, &val);
171 lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
172 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
176 LUSTRE_RW_ATTR(qos_threshold_rr);
178 #ifdef CONFIG_PROC_FS
179 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
181 struct obd_device *obd = p->private;
182 struct lmv_obd *lmv = &obd->u.lmv;
183 struct lu_tgt_desc *tgt;
185 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
186 tgt = lmv_tgt(lmv, (__u32)*pos);
196 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
200 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
202 struct obd_device *obd = p->private;
203 struct lmv_obd *lmv = &obd->u.lmv;
204 struct lu_tgt_desc *tgt;
207 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
208 tgt = lmv_tgt(lmv, (__u32)*pos);
218 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
220 struct lmv_tgt_desc *tgt = v;
225 seq_printf(p, "%u: %s %sACTIVE\n",
226 tgt->ltd_index, tgt->ltd_uuid.uuid,
227 tgt->ltd_active ? "" : "IN");
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,
238 static int lmv_target_seq_open(struct inode *inode, struct file *file)
240 struct seq_file *seq;
243 rc = seq_open(file, &lmv_tgt_sops);
247 seq = file->private_data;
248 seq->private = PDE_DATA(inode);
252 static const struct file_operations lmv_proc_target_fops = {
253 .owner = THIS_MODULE,
254 .open = lmv_target_seq_open,
257 .release = seq_release,
259 #endif /* CONFIG_PROC_FS */
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,
271 int lmv_tunables_init(struct obd_device *obd)
275 obd->obd_ktype.default_attrs = lmv_attrs;
276 rc = lprocfs_obd_setup(obd, true);
279 #ifdef CONFIG_PROC_FS
280 rc = lprocfs_alloc_md_stats(obd, 0);
282 lprocfs_obd_cleanup(obd);
286 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
287 0444, &lmv_proc_target_fops, obd);
289 lprocfs_free_md_stats(obd);
290 lprocfs_obd_cleanup(obd);
291 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
295 #endif /* CONFIG_PROC_FS */