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 *dev = container_of(kobj, struct obd_device,
47 struct lmv_desc *desc;
49 desc = &dev->u.lmv.desc;
50 return sprintf(buf, "%u\n", desc->ld_tgt_count);
52 LUSTRE_RO_ATTR(numobd);
54 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
57 struct obd_device *dev = container_of(kobj, struct obd_device,
59 struct lmv_desc *desc;
61 desc = &dev->u.lmv.desc;
62 return sprintf(buf, "%u\n", desc->ld_active_tgt_count);
64 LUSTRE_RO_ATTR(activeobd);
66 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
69 struct obd_device *dev = container_of(kobj, struct obd_device,
71 struct lmv_desc *desc;
73 desc = &dev->u.lmv.desc;
74 return sprintf(buf, "%s\n", desc->ld_uuid.uuid);
76 LUSTRE_RO_ATTR(desc_uuid);
78 static ssize_t qos_maxage_show(struct kobject *kobj,
79 struct attribute *attr,
82 struct obd_device *dev = container_of(kobj, struct obd_device,
85 return sprintf(buf, "%u\n", dev->u.lmv.desc.ld_qos_maxage);
88 static ssize_t qos_maxage_store(struct kobject *kobj,
89 struct attribute *attr,
93 struct obd_device *dev = container_of(kobj, struct obd_device,
98 rc = kstrtouint(buffer, 0, &val);
102 dev->u.lmv.desc.ld_qos_maxage = val;
106 LUSTRE_RW_ATTR(qos_maxage);
108 static ssize_t qos_prio_free_show(struct kobject *kobj,
109 struct attribute *attr,
112 struct obd_device *dev = container_of(kobj, struct obd_device,
115 return sprintf(buf, "%u%%\n",
116 (dev->u.lmv.lmv_qos.lq_prio_free * 100 + 255) >> 8);
119 static ssize_t qos_prio_free_store(struct kobject *kobj,
120 struct attribute *attr,
124 struct obd_device *dev = container_of(kobj, struct obd_device,
126 struct lmv_obd *lmv = &dev->u.lmv;
130 rc = kstrtouint(buffer, 0, &val);
137 lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
138 lmv->lmv_qos.lq_dirty = 1;
139 lmv->lmv_qos.lq_reset = 1;
143 LUSTRE_RW_ATTR(qos_prio_free);
145 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
146 struct attribute *attr,
149 struct obd_device *dev = container_of(kobj, struct obd_device,
152 return sprintf(buf, "%u%%\n",
153 (dev->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
156 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
157 struct attribute *attr,
161 struct obd_device *dev = container_of(kobj, struct obd_device,
163 struct lmv_obd *lmv = &dev->u.lmv;
167 rc = kstrtouint(buffer, 0, &val);
174 lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
175 lmv->lmv_qos.lq_dirty = 1;
179 LUSTRE_RW_ATTR(qos_threshold_rr);
181 #ifdef CONFIG_PROC_FS
182 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
184 struct obd_device *dev = p->private;
185 struct lmv_obd *lmv = &dev->u.lmv;
187 while (*pos < lmv->tgts_size) {
189 return lmv->tgts[*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 *dev = p->private;
203 struct lmv_obd *lmv = &dev->u.lmv;
206 while (*pos < lmv->tgts_size) {
208 return lmv->tgts[*pos];
215 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
217 struct lmv_tgt_desc *tgt = v;
222 seq_printf(p, "%u: %s %sACTIVE\n",
223 tgt->ltd_index, tgt->ltd_uuid.uuid,
224 tgt->ltd_active ? "" : "IN");
228 static const struct seq_operations lmv_tgt_sops = {
229 .start = lmv_tgt_seq_start,
230 .stop = lmv_tgt_seq_stop,
231 .next = lmv_tgt_seq_next,
232 .show = lmv_tgt_seq_show,
235 static int lmv_target_seq_open(struct inode *inode, struct file *file)
237 struct seq_file *seq;
240 rc = seq_open(file, &lmv_tgt_sops);
244 seq = file->private_data;
245 seq->private = PDE_DATA(inode);
249 static const struct file_operations lmv_proc_target_fops = {
250 .owner = THIS_MODULE,
251 .open = lmv_target_seq_open,
254 .release = seq_release,
256 #endif /* CONFIG_PROC_FS */
258 static struct attribute *lmv_attrs[] = {
259 &lustre_attr_activeobd.attr,
260 &lustre_attr_desc_uuid.attr,
261 &lustre_attr_numobd.attr,
262 &lustre_attr_qos_maxage.attr,
263 &lustre_attr_qos_prio_free.attr,
264 &lustre_attr_qos_threshold_rr.attr,
268 int lmv_tunables_init(struct obd_device *obd)
272 obd->obd_ktype.default_attrs = lmv_attrs;
273 rc = lprocfs_obd_setup(obd, true);
276 #ifdef CONFIG_PROC_FS
277 rc = lprocfs_alloc_md_stats(obd, 0);
279 lprocfs_obd_cleanup(obd);
283 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
284 0444, &lmv_proc_target_fops, obd);
286 lprocfs_free_md_stats(obd);
287 lprocfs_obd_cleanup(obd);
288 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
292 #endif /* CONFIG_PROC_FS */