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 2008 Sun Microsystems, Inc. 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/
31 #define DEBUG_SUBSYSTEM S_CLASS
33 #include <lprocfs_status.h>
34 #include <obd_class.h>
35 #include <linux/seq_file.h>
36 #include "lod_internal.h"
37 #include <uapi/linux/lustre/lustre_param.h>
40 * Notice, all the functions below (except for lod_procfs_init() and
41 * lod_procfs_fini()) are not supposed to be used directly. They are
42 * called by Linux kernel's procfs.
47 static ssize_t dom_stripesize_show(struct kobject *kobj,
48 struct attribute *attr,
51 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
52 struct lod_device *lod = dt2lod_dev(dt);
54 return scnprintf(buf, PAGE_SIZE, "%u\n",
55 lod->lod_dom_stripesize_max_kb << 10);
58 static inline int dom_stripesize_max_kb_update(struct lod_device *lod,
61 /* 1GB is the limit */
62 if (val > (1ULL << 20))
66 if (val < LOD_DOM_MIN_SIZE_KB) {
67 LCONSOLE_INFO("Increasing provided stripe size to a minimum value %u\n",
69 val = LOD_DOM_MIN_SIZE_KB;
70 } else if (val & (LOD_DOM_MIN_SIZE_KB - 1)) {
71 val &= ~(LOD_DOM_MIN_SIZE_KB - 1);
72 LCONSOLE_WARN("Changing provided stripe size to %llu (a multiple of minimum %u)\n",
73 val, LOD_DOM_MIN_SIZE_KB);
76 spin_lock(&lod->lod_lsfs_lock);
77 lod->lod_dom_stripesize_max_kb = val;
78 lod_dom_stripesize_recalc(lod);
79 spin_unlock(&lod->lod_lsfs_lock);
83 static ssize_t dom_stripesize_store(struct kobject *kobj,
84 struct attribute *attr,
85 const char *buffer, size_t count)
87 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
88 struct lod_device *lod = dt2lod_dev(dt);
92 rc = sysfs_memparse(buffer, count, &val, "B");
96 rc = dom_stripesize_max_kb_update(lod, val >> 10);
102 /* Old attribute name is still supported */
103 LUSTRE_RW_ATTR(dom_stripesize);
106 * Show DoM maximum allowed stripe size.
108 static ssize_t dom_stripesize_max_kb_show(struct kobject *kobj,
109 struct attribute *attr,
112 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
113 struct lod_device *lod = dt2lod_dev(dt);
115 return scnprintf(buf, PAGE_SIZE, "%u\n",
116 lod->lod_dom_stripesize_max_kb);
120 * Set DoM maximum allowed stripe size.
122 static ssize_t dom_stripesize_max_kb_store(struct kobject *kobj,
123 struct attribute *attr,
124 const char *buffer, size_t count)
126 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
127 struct lod_device *lod = dt2lod_dev(dt);
131 rc = sysfs_memparse(buffer, count, &val, "KiB");
135 rc = dom_stripesize_max_kb_update(lod, val >> 10);
140 LUSTRE_RW_ATTR(dom_stripesize_max_kb);
143 * Show DoM default stripe size.
145 static ssize_t dom_stripesize_cur_kb_show(struct kobject *kobj,
146 struct attribute *attr,
149 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
150 struct lod_device *lod = dt2lod_dev(dt);
152 return scnprintf(buf, PAGE_SIZE, "%u\n",
153 lod->lod_dom_stripesize_cur_kb);
156 LUSTRE_RO_ATTR(dom_stripesize_cur_kb);
159 * Show DoM threshold.
161 static ssize_t dom_threshold_free_mb_show(struct kobject *kobj,
162 struct attribute *attr, char *buf)
164 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
165 struct lod_device *lod = dt2lod_dev(dt);
167 return scnprintf(buf, PAGE_SIZE, "%llu\n",
168 lod->lod_dom_threshold_free_mb);
172 * Set DoM default stripe size.
174 static ssize_t dom_threshold_free_mb_store(struct kobject *kobj,
175 struct attribute *attr,
176 const char *buffer, size_t count)
178 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
179 struct lod_device *lod = dt2lod_dev(dt);
184 pct = strnchr(buffer, count, '%');
186 rc = string_to_size(&val, buffer, pct - buffer);
189 val = mult_frac(lod->lod_lsfs_total_mb,
190 min_t(unsigned int, val, 100), 100);
192 rc = sysfs_memparse(buffer, count, &val, "MiB");
198 spin_lock(&lod->lod_lsfs_lock);
199 lod->lod_dom_threshold_free_mb = val;
200 lod_dom_stripesize_recalc(lod);
201 spin_unlock(&lod->lod_lsfs_lock);
206 LUSTRE_RW_ATTR(dom_threshold_free_mb);
208 static ssize_t stripesize_show(struct kobject *kobj, struct attribute *attr,
211 struct dt_device *dt = container_of(kobj, struct dt_device,
213 struct lod_device *lod = dt2lod_dev(dt);
215 return scnprintf(buf, PAGE_SIZE, "%llu\n",
216 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size);
219 static ssize_t stripesize_store(struct kobject *kobj, struct attribute *attr,
220 const char *buffer, size_t count)
222 struct dt_device *dt = container_of(kobj, struct dt_device,
224 struct lod_device *lod = dt2lod_dev(dt);
228 rc = sysfs_memparse(buffer, count, &val, "B");
232 lod_fix_desc_stripe_size(&val);
233 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size = val;
238 LUSTRE_RW_ATTR(stripesize);
241 * Show default stripe offset.
243 static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
246 struct dt_device *dt = container_of(kobj, struct dt_device,
248 struct lod_device *lod = dt2lod_dev(dt);
250 return scnprintf(buf, PAGE_SIZE, "%lld\n",
251 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset);
255 * Set default stripe offset.
257 * Usually contains -1 allowing Lustre to balance objects among OST
258 * otherwise may cause severe OST imbalance.
260 static ssize_t stripeoffset_store(struct kobject *kobj,
261 struct attribute *attr,
262 const char *buffer, size_t count)
264 struct dt_device *dt = container_of(kobj, struct dt_device,
266 struct lod_device *lod = dt2lod_dev(dt);
270 rc = kstrtol(buffer, 0, &val);
274 if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
277 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset = val;
282 LUSTRE_RW_ATTR(stripeoffset);
285 * Show default striping pattern (LOV_PATTERN_*).
287 static ssize_t __stripetype_show(struct kobject *kobj, struct attribute *attr,
288 char *buf, bool is_mdt)
290 struct dt_device *dt = container_of(kobj, struct dt_device,
292 struct lod_device *lod = dt2lod_dev(dt);
293 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
296 return scnprintf(buf, PAGE_SIZE, "%u\n", ltd->ltd_lov_desc.ld_pattern);
299 static ssize_t mdt_stripetype_show(struct kobject *kobj, struct attribute *attr,
302 return __stripetype_show(kobj, attr, buf, true);
305 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
308 return __stripetype_show(kobj, attr, buf, false);
312 * Set default striping pattern (a number, not a human-readable string).
314 static ssize_t __stripetype_store(struct kobject *kobj, struct attribute *attr,
315 const char *buffer, size_t count, bool is_mdt)
317 struct dt_device *dt = container_of(kobj, struct dt_device,
319 struct lod_device *lod = dt2lod_dev(dt);
320 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
325 rc = kstrtouint(buffer, 0, &pattern);
330 lod_fix_lmv_desc_pattern(&pattern);
332 lod_fix_desc_pattern(&pattern);
334 ltd->ltd_lov_desc.ld_pattern = pattern;
339 static ssize_t mdt_stripetype_store(struct kobject *kobj,
340 struct attribute *attr, const char *buffer,
343 return __stripetype_store(kobj, attr, buffer, count, true);
346 static ssize_t stripetype_store(struct kobject *kobj,
347 struct attribute *attr, const char *buffer,
350 return __stripetype_store(kobj, attr, buffer, count, false);
353 LUSTRE_RW_ATTR(mdt_stripetype);
354 LUSTRE_RW_ATTR(stripetype);
357 * Show default number of stripes.
359 static ssize_t __stripecount_show(struct kobject *kobj, struct attribute *attr,
360 char *buf, bool is_mdt)
362 struct dt_device *dt = container_of(kobj, struct dt_device,
364 struct lod_device *lod = dt2lod_dev(dt);
365 struct lov_desc *desc = is_mdt ? &lod->lod_mdt_descs.ltd_lov_desc :
366 &lod->lod_ost_descs.ltd_lov_desc;
368 return scnprintf(buf, PAGE_SIZE, "%d\n",
369 (s16)(desc->ld_default_stripe_count + 1) - 1);
372 static ssize_t mdt_stripecount_show(struct kobject *kobj,
373 struct attribute *attr, char *buf)
375 return __stripecount_show(kobj, attr, buf, true);
378 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
381 return __stripecount_show(kobj, attr, buf, false);
385 * Set default number of stripes.
387 static ssize_t __stripecount_store(struct kobject *kobj, struct attribute *attr,
388 const char *buffer, size_t count,
391 struct dt_device *dt = container_of(kobj, struct dt_device,
393 struct lod_device *lod = dt2lod_dev(dt);
394 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
399 rc = kstrtoint(buffer, 0, &stripe_count);
403 if (stripe_count < -1)
406 lod_fix_desc_stripe_count(&stripe_count);
407 ltd->ltd_lov_desc.ld_default_stripe_count = stripe_count;
412 static ssize_t mdt_stripecount_store(struct kobject *kobj,
413 struct attribute *attr,
414 const char *buffer, size_t count)
416 return __stripecount_store(kobj, attr, buffer, count, true);
419 static ssize_t stripecount_store(struct kobject *kobj,
420 struct attribute *attr,
421 const char *buffer, size_t count)
423 return __stripecount_store(kobj, attr, buffer, count, false);
426 LUSTRE_RW_ATTR(mdt_stripecount);
427 LUSTRE_RW_ATTR(stripecount);
430 * Show number of targets.
432 static ssize_t __numobd_show(struct kobject *kobj, struct attribute *attr,
433 char *buf, bool is_mdt)
435 struct dt_device *dt = container_of(kobj, struct dt_device,
437 struct lod_device *lod = dt2lod_dev(dt);
438 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
441 return scnprintf(buf, PAGE_SIZE, "%u\n",
442 ltd->ltd_lov_desc.ld_tgt_count);
445 static ssize_t mdt_numobd_show(struct kobject *kobj, struct attribute *attr,
448 return __numobd_show(kobj, attr, buf, true);
451 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
454 return __numobd_show(kobj, attr, buf, false);
457 LUSTRE_RO_ATTR(mdt_numobd);
458 LUSTRE_RO_ATTR(numobd);
461 * Show number of active targets.
463 static ssize_t __activeobd_show(struct kobject *kobj, struct attribute *attr,
464 char *buf, bool is_mdt)
466 struct dt_device *dt = container_of(kobj, struct dt_device,
468 struct lod_device *lod = dt2lod_dev(dt);
469 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
472 return scnprintf(buf, PAGE_SIZE, "%u\n",
473 ltd->ltd_lov_desc.ld_active_tgt_count);
476 static ssize_t mdt_activeobd_show(struct kobject *kobj, struct attribute *attr,
479 return __activeobd_show(kobj, attr, buf, true);
482 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
485 return __activeobd_show(kobj, attr, buf, false);
488 LUSTRE_RO_ATTR(mdt_activeobd);
489 LUSTRE_RO_ATTR(activeobd);
492 * Show UUID of LOD device.
494 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
497 struct dt_device *dt = container_of(kobj, struct dt_device,
499 struct lod_device *lod = dt2lod_dev(dt);
501 return scnprintf(buf, PAGE_SIZE, "%s\n",
502 lod->lod_ost_descs.ltd_lov_desc.ld_uuid.uuid);
504 LUSTRE_RO_ATTR(desc_uuid);
507 * Show QoS priority parameter.
509 * The printed value is a percentage value (0-100%) indicating the priority
510 * of free space compared to performance. 0% means select OSTs equally
511 * regardless of their free space, 100% means select OSTs only by their free
512 * space even if it results in very imbalanced load on the OSTs.
514 static ssize_t __qos_prio_free_show(struct kobject *kobj,
515 struct attribute *attr, char *buf,
518 struct dt_device *dt = container_of(kobj, struct dt_device,
520 struct lod_device *lod = dt2lod_dev(dt);
521 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
524 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
525 (ltd->ltd_qos.lq_prio_free * 100 + 255) >> 8);
528 static ssize_t mdt_qos_prio_free_show(struct kobject *kobj,
529 struct attribute *attr, char *buf)
531 return __qos_prio_free_show(kobj, attr, buf, true);
534 static ssize_t qos_prio_free_show(struct kobject *kobj,
535 struct attribute *attr, char *buf)
537 return __qos_prio_free_show(kobj, attr, buf, false);
541 * Set QoS free space priority parameter.
543 * Set the relative priority of free OST space compared to OST load when OSTs
544 * are space imbalanced. See qos_priofree_show() for description of
545 * this parameter. See qos_threshold_rr_store() and lq_threshold_rr to
546 * determine what constitutes "space imbalanced" OSTs.
548 static ssize_t __qos_prio_free_store(struct kobject *kobj,
549 struct attribute *attr,
550 const char *buffer, size_t count,
553 struct dt_device *dt = container_of(kobj, struct dt_device,
555 struct lod_device *lod = dt2lod_dev(dt);
556 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
562 /* "100%\n\0" should be largest string */
563 if (count >= sizeof(buf))
566 strncpy(buf, buffer, sizeof(buf));
567 buf[sizeof(buf) - 1] = '\0';
568 tmp = strchr(buf, '%');
572 rc = kstrtouint(buf, 0, &val);
579 ltd->ltd_qos.lq_prio_free = (val << 8) / 100;
580 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
581 set_bit(LQ_RESET, <d->ltd_qos.lq_flags);
586 static ssize_t mdt_qos_prio_free_store(struct kobject *kobj,
587 struct attribute *attr,
588 const char *buffer, size_t count)
590 return __qos_prio_free_store(kobj, attr, buffer, count, true);
593 static ssize_t qos_prio_free_store(struct kobject *kobj, struct attribute *attr,
594 const char *buffer, size_t count)
596 return __qos_prio_free_store(kobj, attr, buffer, count, false);
599 LUSTRE_RW_ATTR(mdt_qos_prio_free);
600 LUSTRE_RW_ATTR(qos_prio_free);
603 * Show threshold for "same space on all OSTs" rule.
605 static ssize_t __qos_threshold_rr_show(struct kobject *kobj,
606 struct attribute *attr, char *buf,
609 struct dt_device *dt = container_of(kobj, struct dt_device,
611 struct lod_device *lod = dt2lod_dev(dt);
612 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
615 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
616 (ltd->ltd_qos.lq_threshold_rr * 100 + 255) >> 8);
619 static ssize_t mdt_qos_threshold_rr_show(struct kobject *kobj,
620 struct attribute *attr, char *buf)
622 return __qos_threshold_rr_show(kobj, attr, buf, true);
625 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
626 struct attribute *attr, char *buf)
628 return __qos_threshold_rr_show(kobj, attr, buf, false);
632 * Set threshold for "same space on all OSTs" rule.
634 * This sets the maximum percentage difference of free space between the most
635 * full and most empty OST in the currently available OSTs. If this percentage
636 * is exceeded, use the QoS allocator to select OSTs based on their available
637 * space so that more full OSTs are chosen less often, otherwise use the
638 * round-robin allocator for efficiency and performance.
640 static ssize_t __qos_threshold_rr_store(struct kobject *kobj,
641 struct attribute *attr,
642 const char *buffer, size_t count,
645 struct dt_device *dt = container_of(kobj, struct dt_device,
647 struct lod_device *lod = dt2lod_dev(dt);
648 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
654 /* "100%\n\0" should be largest string */
655 if (count >= sizeof(buf))
658 strncpy(buf, buffer, sizeof(buf));
659 buf[sizeof(buf) - 1] = '\0';
660 tmp = strchr(buf, '%');
664 rc = kstrtouint(buf, 0, &val);
670 ltd->ltd_qos.lq_threshold_rr = (val << 8) / 100;
671 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
676 static ssize_t mdt_qos_threshold_rr_store(struct kobject *kobj,
677 struct attribute *attr,
678 const char *buffer, size_t count)
680 return __qos_threshold_rr_store(kobj, attr, buffer, count, true);
683 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
684 struct attribute *attr,
685 const char *buffer, size_t count)
687 return __qos_threshold_rr_store(kobj, attr, buffer, count, false);
690 LUSTRE_RW_ATTR(mdt_qos_threshold_rr);
691 LUSTRE_RW_ATTR(qos_threshold_rr);
694 * Show expiration period used to refresh cached statfs data, which
695 * is used to implement QoS/RR striping allocation algorithm.
697 static ssize_t __qos_maxage_show(struct kobject *kobj, struct attribute *attr,
698 char *buf, bool is_mdt)
700 struct dt_device *dt = container_of(kobj, struct dt_device,
702 struct lod_device *lod = dt2lod_dev(dt);
703 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
706 return scnprintf(buf, PAGE_SIZE, "%u Sec\n",
707 ltd->ltd_lov_desc.ld_qos_maxage);
710 static ssize_t mdt_qos_maxage_show(struct kobject *kobj, struct attribute *attr,
713 return __qos_maxage_show(kobj, attr, buf, true);
716 static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr,
719 return __qos_maxage_show(kobj, attr, buf, true);
723 * Set expiration period used to refresh cached statfs data.
725 static ssize_t __qos_maxage_store(struct kobject *kobj, struct attribute *attr,
726 const char *buffer, size_t count, bool is_mdt)
728 struct dt_device *dt = container_of(kobj, struct dt_device,
730 struct lod_device *lod = dt2lod_dev(dt);
731 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
733 struct lustre_cfg_bufs bufs;
734 struct lu_device *next;
735 struct lustre_cfg *lcfg;
737 struct lu_tgt_desc *tgt;
741 rc = kstrtouint(buffer, 0, &val);
748 ltd->ltd_lov_desc.ld_qos_maxage = val;
751 * propogate the value down to OSPs
753 lustre_cfg_bufs_reset(&bufs, NULL);
754 snprintf(str, 32, "%smaxage=%u", PARAM_OSP, val);
755 lustre_cfg_bufs_set_string(&bufs, 1, str);
756 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
759 lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
762 ltd_foreach_tgt(ltd, tgt) {
763 next = &tgt->ltd_tgt->dd_lu_dev;
764 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
766 CERROR("can't set maxage on #%d: %d\n",
769 lod_putref(lod, ltd);
770 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
775 static ssize_t mdt_qos_maxage_store(struct kobject *kobj,
776 struct attribute *attr,
777 const char *buffer, size_t count)
779 return __qos_maxage_store(kobj, attr, buffer, count, true);
782 static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr,
783 const char *buffer, size_t count)
785 return __qos_maxage_store(kobj, attr, buffer, count, false);
788 LUSTRE_RW_ATTR(mdt_qos_maxage);
789 LUSTRE_RW_ATTR(qos_maxage);
791 static void *lod_tgts_seq_start(struct seq_file *p, loff_t *pos, bool is_mdt)
793 struct obd_device *obd = p->private;
794 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
795 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
798 LASSERT(obd != NULL);
800 lod_getref(ltd); /* released in lod_tgts_seq_stop */
801 if (*pos >= ltd->ltd_tgts_size)
804 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
805 ltd->ltd_tgts_size, *pos);
806 if (*pos < ltd->ltd_tgts_size)
807 return LTD_TGT(ltd, *pos);
812 static void *lod_mdts_seq_start(struct seq_file *p, loff_t *pos)
814 return lod_tgts_seq_start(p, pos, true);
817 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
819 return lod_tgts_seq_start(p, pos, false);
822 static void lod_tgts_seq_stop(struct seq_file *p, void *v, bool is_mdt)
824 struct obd_device *obd = p->private;
825 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
826 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
829 LASSERT(obd != NULL);
830 lod_putref(lod, ltd);
833 static void lod_mdts_seq_stop(struct seq_file *p, void *v)
835 lod_tgts_seq_stop(p, v, true);
838 static void lod_osts_seq_stop(struct seq_file *p, void *v)
840 lod_tgts_seq_stop(p, v, false);
843 static void *lod_tgts_seq_next(struct seq_file *p, void *v, loff_t *pos,
846 struct obd_device *obd = p->private;
847 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
848 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
852 if (*pos > ltd->ltd_tgts_size - 1)
855 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
856 ltd->ltd_tgts_size, *pos);
857 if (*pos < ltd->ltd_tgts_size)
858 return LTD_TGT(ltd, *pos);
863 static void *lod_mdts_seq_next(struct seq_file *p, void *v, loff_t *pos)
865 return lod_tgts_seq_next(p, v, pos, true);
868 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
870 return lod_tgts_seq_next(p, v, pos, false);
874 * Show active/inactive status for OST found by lod_osts_seq_next().
876 * \param[in] m seq file
877 * \param[in] v unused for single entry
879 * \retval 0 on success
880 * \retval negative error code if failed
882 static int lod_tgts_seq_show(struct seq_file *p, void *v)
884 struct obd_device *obd = p->private;
885 struct lu_tgt_desc *tgt = v;
886 struct dt_device *next;
889 LASSERT(obd->obd_lu_dev);
895 /* XXX: should be non-NULL env, but it's very expensive */
897 rc = dt_statfs(NULL, next, &tgt->ltd_statfs);
898 if (rc == -ENOTCONN) {
904 seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
905 obd_uuid2str(&tgt->ltd_uuid),
910 static const struct seq_operations lod_mdts_sops = {
911 .start = lod_mdts_seq_start,
912 .stop = lod_mdts_seq_stop,
913 .next = lod_mdts_seq_next,
914 .show = lod_tgts_seq_show,
917 static const struct seq_operations lod_osts_sops = {
918 .start = lod_osts_seq_start,
919 .stop = lod_osts_seq_stop,
920 .next = lod_osts_seq_next,
921 .show = lod_tgts_seq_show,
924 static int lod_mdts_seq_open(struct inode *inode, struct file *file)
926 struct seq_file *seq;
929 rc = seq_open(file, &lod_mdts_sops);
933 seq = file->private_data;
934 seq->private = PDE_DATA(inode);
938 static int lod_osts_seq_open(struct inode *inode, struct file *file)
940 struct seq_file *seq;
943 rc = seq_open(file, &lod_osts_sops);
947 seq = file->private_data;
948 seq->private = PDE_DATA(inode);
953 * Show whether special failout mode for testing is enabled or not.
955 static ssize_t lmv_failout_show(struct kobject *kobj, struct attribute *attr,
958 struct dt_device *dt = container_of(kobj, struct dt_device,
960 struct lod_device *lod = dt2lod_dev(dt);
962 return scnprintf(buf, PAGE_SIZE, "%d\n", lod->lod_lmv_failout ? 1 : 0);
966 * Enable/disable a special failout mode for testing.
968 * This determines whether the LMV will try to continue processing a striped
969 * directory even if it has a (partly) corrupted entry in the master directory,
970 * or if it will abort upon finding a corrupted slave directory entry.
972 static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr,
973 const char *buffer, size_t count)
975 struct dt_device *dt = container_of(kobj, struct dt_device,
977 struct lod_device *lod = dt2lod_dev(dt);
981 rc = kstrtobool(buffer, &val);
985 lod->lod_lmv_failout = val;
989 LUSTRE_RW_ATTR(lmv_failout);
991 static ssize_t mdt_hash_show(struct kobject *kobj, struct attribute *attr,
994 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
995 struct lod_device *lod = dt2lod_dev(dt);
997 return scnprintf(buf, PAGE_SIZE, "%s\n",
998 mdt_hash_name[lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern]);
1001 static ssize_t mdt_hash_store(struct kobject *kobj, struct attribute *attr,
1002 const char *buffer, size_t count)
1004 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
1005 struct lod_device *lod = dt2lod_dev(dt);
1010 hash = kstrndup(buffer, count, GFP_KERNEL);
1014 len = strcspn(hash, "\n ");
1016 for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++) {
1017 if (!strcmp(hash, mdt_hash_name[i])) {
1018 lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern = i;
1027 LUSTRE_RW_ATTR(mdt_hash);
1029 static const struct proc_ops lod_proc_mdt_fops = {
1030 PROC_OWNER(THIS_MODULE)
1031 .proc_open = lod_mdts_seq_open,
1032 .proc_read = seq_read,
1033 .proc_lseek = seq_lseek,
1034 .proc_release = lprocfs_seq_release,
1037 static struct proc_ops lod_proc_target_fops = {
1038 PROC_OWNER(THIS_MODULE)
1039 .proc_open = lod_osts_seq_open,
1040 .proc_read = seq_read,
1041 .proc_lseek = seq_lseek,
1042 .proc_release = lprocfs_seq_release,
1045 static struct attribute *lod_attrs[] = {
1046 &lustre_attr_dom_stripesize.attr,
1047 &lustre_attr_dom_stripesize_max_kb.attr,
1048 &lustre_attr_dom_stripesize_cur_kb.attr,
1049 &lustre_attr_dom_threshold_free_mb.attr,
1050 &lustre_attr_stripesize.attr,
1051 &lustre_attr_stripeoffset.attr,
1052 &lustre_attr_stripecount.attr,
1053 &lustre_attr_stripetype.attr,
1054 &lustre_attr_activeobd.attr,
1055 &lustre_attr_desc_uuid.attr,
1056 &lustre_attr_lmv_failout.attr,
1057 &lustre_attr_numobd.attr,
1058 &lustre_attr_qos_maxage.attr,
1059 &lustre_attr_qos_prio_free.attr,
1060 &lustre_attr_qos_threshold_rr.attr,
1061 &lustre_attr_mdt_stripecount.attr,
1062 &lustre_attr_mdt_stripetype.attr,
1063 &lustre_attr_mdt_activeobd.attr,
1064 &lustre_attr_mdt_numobd.attr,
1065 &lustre_attr_mdt_qos_maxage.attr,
1066 &lustre_attr_mdt_qos_prio_free.attr,
1067 &lustre_attr_mdt_qos_threshold_rr.attr,
1068 &lustre_attr_mdt_hash.attr,
1073 * Initialize procfs entries for LOD.
1075 * \param[in] lod LOD device
1077 * \retval 0 on success
1078 * \retval negative error code if failed
1080 int lod_procfs_init(struct lod_device *lod)
1082 struct obd_device *obd = lod2obd(lod);
1083 struct obd_type *type;
1084 struct kobject *lov;
1087 lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
1088 rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
1091 CERROR("%s: failed to setup DT tunables: %d\n",
1096 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1097 obd->obd_type->typ_procroot,
1099 if (IS_ERR(obd->obd_proc_entry)) {
1100 rc = PTR_ERR(obd->obd_proc_entry);
1101 CERROR("%s: error %d setting up lprocfs\n",
1106 rc = lprocfs_seq_create(obd->obd_proc_entry, "mdt_obd",
1107 0444, &lod_proc_mdt_fops, obd);
1109 CWARN("%s: Error adding the target_obd file %d\n",
1114 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1115 0444, &lod_proc_target_fops, obd);
1117 CWARN("%s: Error adding the target_obd file %d\n",
1122 lod->lod_pool_proc_entry = lprocfs_register("pools",
1123 obd->obd_proc_entry,
1125 if (IS_ERR(lod->lod_pool_proc_entry)) {
1126 rc = PTR_ERR(lod->lod_pool_proc_entry);
1127 lod->lod_pool_proc_entry = NULL;
1128 CWARN("%s: Failed to create pool proc file: %d\n",
1133 lov = kset_find_obj(lustre_kset, "lov");
1135 CERROR("%s: lov subsystem not found\n", obd->obd_name);
1136 GOTO(out, rc = -ENODEV);
1139 rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
1142 CERROR("%s: failed to create LOV sysfs symlink\n",
1146 obd->obd_debugfs_entry = debugfs_create_dir(obd->obd_name,
1147 obd->obd_type->typ_debugfs_entry);
1149 lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov",
1150 "../lod/%s", obd->obd_name);
1151 if (!lod->lod_debugfs)
1152 CERROR("%s: failed to create LOV debugfs symlink\n",
1155 type = container_of(lov, struct obd_type, typ_kobj);
1156 if (!type->typ_procroot)
1159 /* for compatibility we link old procfs's LOV entries to lod ones */
1160 lod->lod_symlink = lprocfs_add_symlink(obd->obd_name,
1162 "../lod/%s", obd->obd_name);
1163 if (lod->lod_symlink == NULL)
1164 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
1169 dt_tunables_fini(&lod->lod_dt_dev);
1175 * Cleanup procfs entries registred for LOD.
1177 * \param[in] lod LOD device
1179 void lod_procfs_fini(struct lod_device *lod)
1181 struct obd_device *obd = lod2obd(lod);
1182 struct kobject *lov;
1184 if (lod->lod_symlink != NULL) {
1185 lprocfs_remove(&lod->lod_symlink);
1186 lod->lod_symlink = NULL;
1189 lov = kset_find_obj(lustre_kset, "lov");
1191 sysfs_remove_link(lov, obd->obd_name);
1195 debugfs_remove_recursive(lod->lod_debugfs);
1197 if (obd->obd_proc_entry) {
1198 lprocfs_remove(&obd->obd_proc_entry);
1199 obd->obd_proc_entry = NULL;
1202 dt_tunables_fini(&lod->lod_dt_dev);
1205 #endif /* CONFIG_PROC_FS */