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 +
161 (QOS_THRESHOLD_MAX - 1)) / QOS_THRESHOLD_MAX);
164 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
165 struct attribute *attr,
169 struct obd_device *obd = container_of(kobj, struct obd_device,
171 struct lmv_obd *lmv = &obd->u.lmv;
176 /* "100%\n\0" should be largest string */
177 if (count >= sizeof(buf))
180 strncpy(buf, buffer, sizeof(buf));
181 buf[sizeof(buf) - 1] = '\0';
182 tmp = strchr(buf, '%');
186 rc = kstrtouint(buf, 0, &val);
193 lmv->lmv_qos.lq_threshold_rr = (val * QOS_THRESHOLD_MAX) / 100;
194 set_bit(LQ_DIRTY, &lmv->lmv_qos.lq_flags);
198 LUSTRE_RW_ATTR(qos_threshold_rr);
200 #ifdef CONFIG_PROC_FS
201 /* directories with exclude prefixes will be created on the same MDT as its
202 * parent directory, the prefixes are set with the rule as shell environment
203 * PATH: ':' is used as separator for prefixes. And for convenience, '+/-' is
204 * used to add/remove prefixes.
206 static int qos_exclude_prefixes_seq_show(struct seq_file *m, void *v)
208 struct obd_device *obd = m->private;
209 struct lmv_obd *lmv = &obd->u.lmv;
210 struct qos_exclude_prefix *prefix;
213 spin_lock(&lmv->lmv_lock);
214 list_for_each_entry(prefix, &lmv->lmv_qos_exclude_list, qep_list) {
215 seq_printf(m, "%s\n", prefix->qep_name);
216 if (seq_has_overflowed(m)) {
217 spin_unlock(&lmv->lmv_lock);
220 m->buf = kvmalloc(m->size <<= 1, GFP_KERNEL_ACCOUNT);
226 spin_unlock(&lmv->lmv_lock);
231 static ssize_t qos_exclude_prefixes_seq_write(struct file *file,
232 const char __user *buffer,
233 size_t count, loff_t *off)
235 struct obd_device *obd;
241 char namebuf[NAME_MAX + 1];
242 struct qos_exclude_prefix *prefix;
243 struct qos_exclude_prefix *tmp;
248 /* one extra char to ensure buf ends with '\0' */
249 OBD_ALLOC(buf, count + 1);
252 if (copy_from_user(buf, buffer, count)) {
253 OBD_FREE(buf, count + 1);
257 obd = ((struct seq_file *)file->private_data)->private;
265 if (*p == '+' || *p == '-')
269 p = strchr(name, ':');
276 if (len > NAME_MAX) {
277 CERROR("%s: %s length exceeds NAME_MAX\n",
278 obd->obd_name, name);
279 OBD_FREE(buf, count + 1);
286 spin_lock(&lmv->lmv_lock);
287 list_for_each_entry_safe(prefix, tmp,
288 &lmv->lmv_qos_exclude_list,
290 list_del(&prefix->qep_list);
291 rhashtable_remove_fast(
292 &lmv->lmv_qos_exclude_hash,
294 qos_exclude_hash_params);
297 spin_unlock(&lmv->lmv_lock);
302 prefix = kmalloc(sizeof(*prefix), __GFP_ZERO);
304 OBD_FREE(buf, count + 1);
307 strncpy(prefix->qep_name, name, len);
308 rc = rhashtable_lookup_insert_fast(
309 &lmv->lmv_qos_exclude_hash,
311 qos_exclude_hash_params);
313 spin_lock(&lmv->lmv_lock);
314 list_add_tail(&prefix->qep_list,
315 &lmv->lmv_qos_exclude_list);
316 spin_unlock(&lmv->lmv_lock);
322 strncpy(namebuf, name, len);
324 prefix = rhashtable_lookup(&lmv->lmv_qos_exclude_hash,
326 qos_exclude_hash_params);
328 spin_lock(&lmv->lmv_lock);
329 list_del(&prefix->qep_list);
330 spin_unlock(&lmv->lmv_lock);
331 rhashtable_remove_fast(
332 &lmv->lmv_qos_exclude_hash,
334 qos_exclude_hash_params);
341 OBD_FREE(buf, count + 1);
344 LPROC_SEQ_FOPS(qos_exclude_prefixes);
346 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
348 struct obd_device *obd = p->private;
349 struct lmv_obd *lmv = &obd->u.lmv;
350 struct lu_tgt_desc *tgt;
352 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
353 tgt = lmv_tgt(lmv, (__u32)*pos);
363 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
367 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
369 struct obd_device *obd = p->private;
370 struct lmv_obd *lmv = &obd->u.lmv;
371 struct lu_tgt_desc *tgt;
374 while (*pos < lmv->lmv_mdt_descs.ltd_tgts_size) {
375 tgt = lmv_tgt(lmv, (__u32)*pos);
385 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
387 struct lmv_tgt_desc *tgt = v;
392 seq_printf(p, "%u: %s %sACTIVE\n",
393 tgt->ltd_index, tgt->ltd_uuid.uuid,
394 tgt->ltd_active ? "" : "IN");
398 static const struct seq_operations lmv_tgt_sops = {
399 .start = lmv_tgt_seq_start,
400 .stop = lmv_tgt_seq_stop,
401 .next = lmv_tgt_seq_next,
402 .show = lmv_tgt_seq_show,
405 static int lmv_target_seq_open(struct inode *inode, struct file *file)
407 struct seq_file *seq;
410 rc = seq_open(file, &lmv_tgt_sops);
414 seq = file->private_data;
415 seq->private = pde_data(inode);
419 static const struct proc_ops lmv_proc_target_fops = {
420 PROC_OWNER(THIS_MODULE)
421 .proc_open = lmv_target_seq_open,
422 .proc_read = seq_read,
423 .proc_lseek = seq_lseek,
424 .proc_release = seq_release,
427 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
428 { .name = "qos_exclude_prefixes",
429 .fops = &qos_exclude_prefixes_fops },
430 { .name = "target_obd",
431 .fops = &lmv_proc_target_fops },
434 #endif /* CONFIG_PROC_FS */
436 static struct attribute *lmv_attrs[] = {
437 &lustre_attr_activeobd.attr,
438 &lustre_attr_desc_uuid.attr,
439 &lustre_attr_numobd.attr,
440 &lustre_attr_qos_maxage.attr,
441 &lustre_attr_qos_prio_free.attr,
442 &lustre_attr_qos_threshold_rr.attr,
446 KOBJ_ATTRIBUTE_GROUPS(lmv); /* creates lmv_groups */
448 int lmv_tunables_init(struct obd_device *obd)
452 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(lmv);
453 #ifdef CONFIG_PROC_FS
454 obd->obd_vars = lprocfs_lmv_obd_vars;
456 rc = lprocfs_obd_setup(obd, true);
459 #ifdef CONFIG_PROC_FS
460 rc = lprocfs_alloc_md_stats(obd, 0);
462 lprocfs_obd_cleanup(obd);
465 #endif /* CONFIG_PROC_FS */