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;
127 /* "100%\n\0" should be largest string */
128 if (count >= sizeof(buf))
131 strncpy(buf, buffer, sizeof(buf));
132 buf[sizeof(buf) - 1] = '\0';
133 tmp = strchr(buf, '%');
137 rc = kstrtouint(buf, 0, &val);
144 lmv->lmv_qos.lq_prio_free = (val << 8) / 100;
145 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
146 set_bit(LQ_RESET, &lmv->lmv_qos.lq_flags);
150 LUSTRE_RW_ATTR(qos_prio_free);
152 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
153 struct attribute *attr,
156 struct obd_device *obd = container_of(kobj, struct obd_device,
159 return scnprintf(buf, PAGE_SIZE, "%u%%\n",
160 (obd->u.lmv.lmv_qos.lq_threshold_rr * 100 + 255) >> 8);
163 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
164 struct attribute *attr,
168 struct obd_device *obd = container_of(kobj, struct obd_device,
170 struct lmv_obd *lmv = &obd->u.lmv;
175 /* "100%\n\0" should be largest string */
176 if (count >= sizeof(buf))
179 strncpy(buf, buffer, sizeof(buf));
180 buf[sizeof(buf) - 1] = '\0';
181 tmp = strchr(buf, '%');
185 rc = kstrtouint(buf, 0, &val);
192 lmv->lmv_qos.lq_threshold_rr = (val << 8) / 100;
193 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
197 LUSTRE_RW_ATTR(qos_threshold_rr);
199 #ifdef CONFIG_PROC_FS
200 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
202 struct obd_device *obd = p->private;
203 struct lmv_obd *lmv = &obd->u.lmv;
204 struct lu_tgt_desc *tgt;
206 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
207 tgt = lmv_tgt(lmv, (__u32)*pos);
217 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
221 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
223 struct obd_device *obd = p->private;
224 struct lmv_obd *lmv = &obd->u.lmv;
225 struct lu_tgt_desc *tgt;
228 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
229 tgt = lmv_tgt(lmv, (__u32)*pos);
239 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
241 struct lmv_tgt_desc *tgt = v;
246 seq_printf(p, "%u: %s %sACTIVE\n",
247 tgt->ltd_index, tgt->ltd_uuid.uuid,
248 tgt->ltd_active ? "" : "IN");
252 static const struct seq_operations lmv_tgt_sops = {
253 .start = lmv_tgt_seq_start,
254 .stop = lmv_tgt_seq_stop,
255 .next = lmv_tgt_seq_next,
256 .show = lmv_tgt_seq_show,
259 static int lmv_target_seq_open(struct inode *inode, struct file *file)
261 struct seq_file *seq;
264 rc = seq_open(file, &lmv_tgt_sops);
268 seq = file->private_data;
269 seq->private = PDE_DATA(inode);
273 static const struct proc_ops lmv_proc_target_fops = {
274 PROC_OWNER(THIS_MODULE)
275 .proc_open = lmv_target_seq_open,
276 .proc_read = seq_read,
277 .proc_lseek = seq_lseek,
278 .proc_release = seq_release,
280 #endif /* CONFIG_PROC_FS */
282 static struct attribute *lmv_attrs[] = {
283 &lustre_attr_activeobd.attr,
284 &lustre_attr_desc_uuid.attr,
285 &lustre_attr_numobd.attr,
286 &lustre_attr_qos_maxage.attr,
287 &lustre_attr_qos_prio_free.attr,
288 &lustre_attr_qos_threshold_rr.attr,
292 int lmv_tunables_init(struct obd_device *obd)
296 obd->obd_ktype.default_attrs = lmv_attrs;
297 rc = lprocfs_obd_setup(obd, true);
300 #ifdef CONFIG_PROC_FS
301 rc = lprocfs_alloc_md_stats(obd, 0);
303 lprocfs_obd_cleanup(obd);
307 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
308 0444, &lmv_proc_target_fops, obd);
310 lprocfs_free_md_stats(obd);
311 lprocfs_obd_cleanup(obd);
312 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
316 #endif /* CONFIG_PROC_FS */