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);
284 static ssize_t max_stripecount_show(struct kobject *kobj,
285 struct attribute *attr, char *buf)
287 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
288 struct lod_device *lod = dt2lod_dev(dt);
290 return scnprintf(buf, PAGE_SIZE, "%u\n", lod->lod_max_stripecount);
293 static ssize_t max_stripecount_store(struct kobject *kobj,
294 struct attribute *attr,
295 const char *buffer, size_t count)
297 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
298 struct lod_device *lod = dt2lod_dev(dt);
302 rc = kstrtol(buffer, 0, &val);
306 if (val < 0 || val > LOV_MAX_STRIPE_COUNT)
309 lod->lod_max_stripecount = val;
314 LUSTRE_RW_ATTR(max_stripecount);
317 * Show default striping pattern (LOV_PATTERN_*).
319 static ssize_t __stripetype_show(struct kobject *kobj, struct attribute *attr,
320 char *buf, bool is_mdt)
322 struct dt_device *dt = container_of(kobj, struct dt_device,
324 struct lod_device *lod = dt2lod_dev(dt);
325 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
328 return scnprintf(buf, PAGE_SIZE, "%u\n", ltd->ltd_lov_desc.ld_pattern);
331 static ssize_t mdt_stripetype_show(struct kobject *kobj, struct attribute *attr,
334 return __stripetype_show(kobj, attr, buf, true);
337 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
340 return __stripetype_show(kobj, attr, buf, false);
344 * Set default striping pattern (a number, not a human-readable string).
346 static ssize_t __stripetype_store(struct kobject *kobj, struct attribute *attr,
347 const char *buffer, size_t count, bool is_mdt)
349 struct dt_device *dt = container_of(kobj, struct dt_device,
351 struct lod_device *lod = dt2lod_dev(dt);
352 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
357 rc = kstrtouint(buffer, 0, &pattern);
362 lod_fix_lmv_desc_pattern(&pattern);
364 lod_fix_desc_pattern(&pattern);
366 ltd->ltd_lov_desc.ld_pattern = pattern;
371 static ssize_t mdt_stripetype_store(struct kobject *kobj,
372 struct attribute *attr, const char *buffer,
375 return __stripetype_store(kobj, attr, buffer, count, true);
378 static ssize_t stripetype_store(struct kobject *kobj,
379 struct attribute *attr, const char *buffer,
382 return __stripetype_store(kobj, attr, buffer, count, false);
385 LUSTRE_RW_ATTR(mdt_stripetype);
386 LUSTRE_RW_ATTR(stripetype);
389 * Show default number of stripes.
391 static ssize_t __stripecount_show(struct kobject *kobj, struct attribute *attr,
392 char *buf, bool is_mdt)
394 struct dt_device *dt = container_of(kobj, struct dt_device,
396 struct lod_device *lod = dt2lod_dev(dt);
397 struct lov_desc *desc = is_mdt ? &lod->lod_mdt_descs.ltd_lov_desc :
398 &lod->lod_ost_descs.ltd_lov_desc;
400 return scnprintf(buf, PAGE_SIZE, "%d\n",
401 (s16)(desc->ld_default_stripe_count + 1) - 1);
404 static ssize_t mdt_stripecount_show(struct kobject *kobj,
405 struct attribute *attr, char *buf)
407 return __stripecount_show(kobj, attr, buf, true);
410 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
413 return __stripecount_show(kobj, attr, buf, false);
417 * Set default number of stripes.
419 static ssize_t __stripecount_store(struct kobject *kobj, struct attribute *attr,
420 const char *buffer, size_t count,
423 struct dt_device *dt = container_of(kobj, struct dt_device,
425 struct lod_device *lod = dt2lod_dev(dt);
426 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
431 rc = kstrtoint(buffer, 0, &stripe_count);
435 if (stripe_count < -1)
438 lod_fix_desc_stripe_count(&stripe_count);
439 ltd->ltd_lov_desc.ld_default_stripe_count = stripe_count;
444 static ssize_t mdt_stripecount_store(struct kobject *kobj,
445 struct attribute *attr,
446 const char *buffer, size_t count)
448 return __stripecount_store(kobj, attr, buffer, count, true);
451 static ssize_t stripecount_store(struct kobject *kobj,
452 struct attribute *attr,
453 const char *buffer, size_t count)
455 return __stripecount_store(kobj, attr, buffer, count, false);
458 LUSTRE_RW_ATTR(mdt_stripecount);
459 LUSTRE_RW_ATTR(stripecount);
462 * Show number of targets.
464 static ssize_t __numobd_show(struct kobject *kobj, struct attribute *attr,
465 char *buf, bool is_mdt)
467 struct dt_device *dt = container_of(kobj, struct dt_device,
469 struct lod_device *lod = dt2lod_dev(dt);
470 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
473 return scnprintf(buf, PAGE_SIZE, "%u\n",
474 ltd->ltd_lov_desc.ld_tgt_count);
477 static ssize_t mdt_numobd_show(struct kobject *kobj, struct attribute *attr,
480 return __numobd_show(kobj, attr, buf, true);
483 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
486 return __numobd_show(kobj, attr, buf, false);
489 LUSTRE_RO_ATTR(mdt_numobd);
490 LUSTRE_RO_ATTR(numobd);
493 * Show number of active targets.
495 static ssize_t __activeobd_show(struct kobject *kobj, struct attribute *attr,
496 char *buf, bool is_mdt)
498 struct dt_device *dt = container_of(kobj, struct dt_device,
500 struct lod_device *lod = dt2lod_dev(dt);
501 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
504 return scnprintf(buf, PAGE_SIZE, "%u\n",
505 ltd->ltd_lov_desc.ld_active_tgt_count);
508 static ssize_t mdt_activeobd_show(struct kobject *kobj, struct attribute *attr,
511 return __activeobd_show(kobj, attr, buf, true);
514 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
517 return __activeobd_show(kobj, attr, buf, false);
520 LUSTRE_RO_ATTR(mdt_activeobd);
521 LUSTRE_RO_ATTR(activeobd);
524 * Show UUID of LOD device.
526 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
529 struct dt_device *dt = container_of(kobj, struct dt_device,
531 struct lod_device *lod = dt2lod_dev(dt);
533 return scnprintf(buf, PAGE_SIZE, "%s\n",
534 lod->lod_ost_descs.ltd_lov_desc.ld_uuid.uuid);
536 LUSTRE_RO_ATTR(desc_uuid);
539 * Show QoS priority parameter.
541 * The printed value is a percentage value (0-100%) indicating the priority
542 * of free space compared to performance. 0% means select OSTs equally
543 * regardless of their free space, 100% means select OSTs only by their free
544 * space even if it results in very imbalanced load on the OSTs.
546 static ssize_t __qos_prio_free_show(struct kobject *kobj,
547 struct attribute *attr, char *buf,
550 struct dt_device *dt = container_of(kobj, struct dt_device,
552 struct lod_device *lod = dt2lod_dev(dt);
553 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
556 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
557 (ltd->ltd_qos.lq_prio_free * 100 + 255) >> 8);
560 static ssize_t mdt_qos_prio_free_show(struct kobject *kobj,
561 struct attribute *attr, char *buf)
563 return __qos_prio_free_show(kobj, attr, buf, true);
566 static ssize_t qos_prio_free_show(struct kobject *kobj,
567 struct attribute *attr, char *buf)
569 return __qos_prio_free_show(kobj, attr, buf, false);
573 * Set QoS free space priority parameter.
575 * Set the relative priority of free OST space compared to OST load when OSTs
576 * are space imbalanced. See qos_priofree_show() for description of
577 * this parameter. See qos_threshold_rr_store() and lq_threshold_rr to
578 * determine what constitutes "space imbalanced" OSTs.
580 static ssize_t __qos_prio_free_store(struct kobject *kobj,
581 struct attribute *attr,
582 const char *buffer, size_t count,
585 struct dt_device *dt = container_of(kobj, struct dt_device,
587 struct lod_device *lod = dt2lod_dev(dt);
588 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
594 /* "100%\n\0" should be largest string */
595 if (count >= sizeof(buf))
598 strncpy(buf, buffer, sizeof(buf));
599 buf[sizeof(buf) - 1] = '\0';
600 tmp = strchr(buf, '%');
604 rc = kstrtouint(buf, 0, &val);
611 ltd->ltd_qos.lq_prio_free = (val << 8) / 100;
612 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
613 set_bit(LQ_RESET, <d->ltd_qos.lq_flags);
618 static ssize_t mdt_qos_prio_free_store(struct kobject *kobj,
619 struct attribute *attr,
620 const char *buffer, size_t count)
622 return __qos_prio_free_store(kobj, attr, buffer, count, true);
625 static ssize_t qos_prio_free_store(struct kobject *kobj, struct attribute *attr,
626 const char *buffer, size_t count)
628 return __qos_prio_free_store(kobj, attr, buffer, count, false);
631 LUSTRE_RW_ATTR(mdt_qos_prio_free);
632 LUSTRE_RW_ATTR(qos_prio_free);
635 * Show threshold for "same space on all OSTs" rule.
637 static ssize_t __qos_threshold_rr_show(struct kobject *kobj,
638 struct attribute *attr, char *buf,
641 struct dt_device *dt = container_of(kobj, struct dt_device,
643 struct lod_device *lod = dt2lod_dev(dt);
644 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
647 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
648 (ltd->ltd_qos.lq_threshold_rr * 100 + 255) >> 8);
651 static ssize_t mdt_qos_threshold_rr_show(struct kobject *kobj,
652 struct attribute *attr, char *buf)
654 return __qos_threshold_rr_show(kobj, attr, buf, true);
657 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
658 struct attribute *attr, char *buf)
660 return __qos_threshold_rr_show(kobj, attr, buf, false);
664 * Set threshold for "same space on all OSTs" rule.
666 * This sets the maximum percentage difference of free space between the most
667 * full and most empty OST in the currently available OSTs. If this percentage
668 * is exceeded, use the QoS allocator to select OSTs based on their available
669 * space so that more full OSTs are chosen less often, otherwise use the
670 * round-robin allocator for efficiency and performance.
672 static ssize_t __qos_threshold_rr_store(struct kobject *kobj,
673 struct attribute *attr,
674 const char *buffer, size_t count,
677 struct dt_device *dt = container_of(kobj, struct dt_device,
679 struct lod_device *lod = dt2lod_dev(dt);
680 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
686 /* "100%\n\0" should be largest string */
687 if (count >= sizeof(buf))
690 strncpy(buf, buffer, sizeof(buf));
691 buf[sizeof(buf) - 1] = '\0';
692 tmp = strchr(buf, '%');
696 rc = kstrtouint(buf, 0, &val);
702 ltd->ltd_qos.lq_threshold_rr = (val << 8) / 100;
703 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
708 static ssize_t mdt_qos_threshold_rr_store(struct kobject *kobj,
709 struct attribute *attr,
710 const char *buffer, size_t count)
712 return __qos_threshold_rr_store(kobj, attr, buffer, count, true);
715 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
716 struct attribute *attr,
717 const char *buffer, size_t count)
719 return __qos_threshold_rr_store(kobj, attr, buffer, count, false);
722 LUSTRE_RW_ATTR(mdt_qos_threshold_rr);
723 LUSTRE_RW_ATTR(qos_threshold_rr);
726 * Show expiration period used to refresh cached statfs data, which
727 * is used to implement QoS/RR striping allocation algorithm.
729 static ssize_t __qos_maxage_show(struct kobject *kobj, struct attribute *attr,
730 char *buf, bool is_mdt)
732 struct dt_device *dt = container_of(kobj, struct dt_device,
734 struct lod_device *lod = dt2lod_dev(dt);
735 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
738 return scnprintf(buf, PAGE_SIZE, "%u\n",
739 ltd->ltd_lov_desc.ld_qos_maxage);
742 static ssize_t mdt_qos_maxage_show(struct kobject *kobj, struct attribute *attr,
745 return __qos_maxage_show(kobj, attr, buf, true);
748 static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr,
751 return __qos_maxage_show(kobj, attr, buf, true);
755 * Set expiration period used to refresh cached statfs data.
757 static ssize_t __qos_maxage_store(struct kobject *kobj, struct attribute *attr,
758 const char *buffer, size_t count, bool is_mdt)
760 struct dt_device *dt = container_of(kobj, struct dt_device,
762 struct lod_device *lod = dt2lod_dev(dt);
763 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
765 struct lustre_cfg_bufs bufs;
766 struct lu_device *next;
767 struct lustre_cfg *lcfg;
769 struct lu_tgt_desc *tgt;
773 rc = kstrtouint(buffer, 0, &val);
780 ltd->ltd_lov_desc.ld_qos_maxage = val;
783 * propogate the value down to OSPs
785 lustre_cfg_bufs_reset(&bufs, NULL);
786 snprintf(str, 32, "%smaxage=%u", PARAM_OSP, val);
787 lustre_cfg_bufs_set_string(&bufs, 1, str);
788 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
791 lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
794 ltd_foreach_tgt(ltd, tgt) {
795 next = &tgt->ltd_tgt->dd_lu_dev;
796 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
798 CERROR("can't set maxage on #%d: %d\n",
801 lod_putref(lod, ltd);
802 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
807 static ssize_t mdt_qos_maxage_store(struct kobject *kobj,
808 struct attribute *attr,
809 const char *buffer, size_t count)
811 return __qos_maxage_store(kobj, attr, buffer, count, true);
814 static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr,
815 const char *buffer, size_t count)
817 return __qos_maxage_store(kobj, attr, buffer, count, false);
820 LUSTRE_RW_ATTR(mdt_qos_maxage);
821 LUSTRE_RW_ATTR(qos_maxage);
823 static void *lod_tgts_seq_start(struct seq_file *p, loff_t *pos, bool is_mdt)
825 struct obd_device *obd = p->private;
826 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
827 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
830 LASSERT(obd != NULL);
832 lod_getref(ltd); /* released in lod_tgts_seq_stop */
833 if (*pos >= ltd->ltd_tgts_size)
836 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
837 ltd->ltd_tgts_size, *pos);
838 if (*pos < ltd->ltd_tgts_size)
839 return LTD_TGT(ltd, *pos);
844 static void *lod_mdts_seq_start(struct seq_file *p, loff_t *pos)
846 return lod_tgts_seq_start(p, pos, true);
849 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
851 return lod_tgts_seq_start(p, pos, false);
854 static void lod_tgts_seq_stop(struct seq_file *p, void *v, bool is_mdt)
856 struct obd_device *obd = p->private;
857 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
858 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
861 LASSERT(obd != NULL);
862 lod_putref(lod, ltd);
865 static void lod_mdts_seq_stop(struct seq_file *p, void *v)
867 lod_tgts_seq_stop(p, v, true);
870 static void lod_osts_seq_stop(struct seq_file *p, void *v)
872 lod_tgts_seq_stop(p, v, false);
875 static void *lod_tgts_seq_next(struct seq_file *p, void *v, loff_t *pos,
878 struct obd_device *obd = p->private;
879 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
880 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
884 if (*pos > ltd->ltd_tgts_size - 1)
887 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
888 ltd->ltd_tgts_size, *pos);
889 if (*pos < ltd->ltd_tgts_size)
890 return LTD_TGT(ltd, *pos);
895 static void *lod_mdts_seq_next(struct seq_file *p, void *v, loff_t *pos)
897 return lod_tgts_seq_next(p, v, pos, true);
900 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
902 return lod_tgts_seq_next(p, v, pos, false);
906 * Show active/inactive status for OST found by lod_osts_seq_next().
908 * \param[in] m seq file
909 * \param[in] v unused for single entry
911 * \retval 0 on success
912 * \retval negative error code if failed
914 static int lod_tgts_seq_show(struct seq_file *p, void *v)
916 struct obd_device *obd = p->private;
917 struct lu_tgt_desc *tgt = v;
918 struct dt_device *next;
921 LASSERT(obd->obd_lu_dev);
927 /* XXX: should be non-NULL env, but it's very expensive */
929 rc = dt_statfs(NULL, next, &tgt->ltd_statfs);
930 if (rc == -ENOTCONN) {
936 seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
937 obd_uuid2str(&tgt->ltd_uuid),
942 static const struct seq_operations lod_mdts_sops = {
943 .start = lod_mdts_seq_start,
944 .stop = lod_mdts_seq_stop,
945 .next = lod_mdts_seq_next,
946 .show = lod_tgts_seq_show,
949 static const struct seq_operations lod_osts_sops = {
950 .start = lod_osts_seq_start,
951 .stop = lod_osts_seq_stop,
952 .next = lod_osts_seq_next,
953 .show = lod_tgts_seq_show,
956 static int lod_mdts_seq_open(struct inode *inode, struct file *file)
958 struct seq_file *seq;
961 rc = seq_open(file, &lod_mdts_sops);
965 seq = file->private_data;
966 seq->private = PDE_DATA(inode);
970 static int lod_osts_seq_open(struct inode *inode, struct file *file)
972 struct seq_file *seq;
975 rc = seq_open(file, &lod_osts_sops);
979 seq = file->private_data;
980 seq->private = PDE_DATA(inode);
985 * Show whether special failout mode for testing is enabled or not.
987 static ssize_t lmv_failout_show(struct kobject *kobj, struct attribute *attr,
990 struct dt_device *dt = container_of(kobj, struct dt_device,
992 struct lod_device *lod = dt2lod_dev(dt);
994 return scnprintf(buf, PAGE_SIZE, "%d\n", lod->lod_lmv_failout ? 1 : 0);
998 * Enable/disable a special failout mode for testing.
1000 * This determines whether the LMV will try to continue processing a striped
1001 * directory even if it has a (partly) corrupted entry in the master directory,
1002 * or if it will abort upon finding a corrupted slave directory entry.
1004 static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr,
1005 const char *buffer, size_t count)
1007 struct dt_device *dt = container_of(kobj, struct dt_device,
1009 struct lod_device *lod = dt2lod_dev(dt);
1013 rc = kstrtobool(buffer, &val);
1017 lod->lod_lmv_failout = val;
1021 LUSTRE_RW_ATTR(lmv_failout);
1023 static ssize_t mdt_hash_show(struct kobject *kobj, struct attribute *attr,
1026 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
1027 struct lod_device *lod = dt2lod_dev(dt);
1029 return scnprintf(buf, PAGE_SIZE, "%s\n",
1030 mdt_hash_name[lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern]);
1033 static ssize_t mdt_hash_store(struct kobject *kobj, struct attribute *attr,
1034 const char *buffer, size_t count)
1036 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
1037 struct lod_device *lod = dt2lod_dev(dt);
1042 hash = kstrndup(buffer, count, GFP_KERNEL);
1046 len = strcspn(hash, "\n ");
1048 for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++) {
1049 if (!strcmp(hash, mdt_hash_name[i])) {
1050 lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern = i;
1059 LUSTRE_RW_ATTR(mdt_hash);
1061 static const struct proc_ops lod_proc_mdt_fops = {
1062 PROC_OWNER(THIS_MODULE)
1063 .proc_open = lod_mdts_seq_open,
1064 .proc_read = seq_read,
1065 .proc_lseek = seq_lseek,
1066 .proc_release = lprocfs_seq_release,
1069 static int lod_spill_threshold_pct_seq_show(struct seq_file *m, void *v)
1071 struct pool_desc *pool = m->private;
1073 LASSERT(pool != NULL);
1074 seq_printf(m, "%d\n", pool->pool_spill_threshold_pct);
1080 lod_spill_threshold_pct_seq_write(struct file *file, const char __user *buffer,
1081 size_t count, loff_t *off)
1083 struct seq_file *m = file->private_data;
1084 struct pool_desc *pool = m->private;
1088 LASSERT(pool != NULL);
1090 rc = kstrtoint_from_user(buffer, count, 0, &val);
1094 if (val > 100 || val < 0)
1097 pool->pool_spill_threshold_pct = val;
1098 pool->pool_spill_expire = 0;
1099 if (pool->pool_spill_threshold_pct == 0)
1100 pool->pool_spill_is_active = false;
1104 LPROC_SEQ_FOPS(lod_spill_threshold_pct);
1106 static int lod_spill_target_seq_show(struct seq_file *m, void *v)
1108 struct pool_desc *pool = m->private;
1110 LASSERT(pool != NULL);
1111 seq_printf(m, "%s\n", pool->pool_spill_target);
1117 lod_spill_target_seq_write(struct file *file, const char __user *buffer,
1118 size_t count, loff_t *off)
1120 struct seq_file *m = file->private_data;
1121 struct pool_desc *pool = m->private;
1122 struct lod_device *lod;
1124 LASSERT(pool != NULL);
1125 lod = lu2lod_dev(pool->pool_lobd->obd_lu_dev);
1128 pool->pool_spill_target[0] = '\0';
1129 pool->pool_spill_is_active = false;
1133 if (count > LOV_MAXPOOLNAME - 1)
1135 if (copy_from_user(pool->pool_spill_target, buffer, count))
1138 pool->pool_spill_target[count] = '\0';
1139 if (strcmp(pool->pool_name, pool->pool_spill_target) == 0)
1141 if (!lod_pool_exists(lod, pool->pool_spill_target)) {
1142 pool->pool_spill_target[0] = '\0';
1143 pool->pool_spill_expire = 0;
1149 LPROC_SEQ_FOPS(lod_spill_target);
1151 static int lod_spill_is_active_seq_show(struct seq_file *m, void *v)
1153 struct pool_desc *pool = m->private;
1154 struct lod_device *lod;
1161 rc = lu_env_init(&env, LCT_LOCAL);
1165 lod = lu2lod_dev(pool->pool_lobd->obd_lu_dev);
1166 lod_spill_target_refresh(&env, lod, pool);
1169 seq_printf(m, "%d\n", pool->pool_spill_is_active ? 1 : 0);
1173 LPROC_SEQ_FOPS_RO(lod_spill_is_active);
1175 static int lod_spill_hit_seq_show(struct seq_file *m, void *v)
1177 struct pool_desc *pool = m->private;
1179 LASSERT(pool != NULL);
1180 seq_printf(m, "%d\n", atomic_read(&pool->pool_spill_hit));
1183 LPROC_SEQ_FOPS_RO(lod_spill_hit);
1185 struct lprocfs_vars lprocfs_lod_spill_vars[] = {
1186 { .name = "spill_threshold_pct",
1187 .fops = &lod_spill_threshold_pct_fops },
1188 { .name = "spill_target",
1189 .fops = &lod_spill_target_fops },
1190 { .name = "spill_is_active",
1191 .fops = &lod_spill_is_active_fops },
1192 { .name = "spill_hit",
1193 .fops = &lod_spill_hit_fops },
1197 static struct proc_ops lod_proc_target_fops = {
1198 PROC_OWNER(THIS_MODULE)
1199 .proc_open = lod_osts_seq_open,
1200 .proc_read = seq_read,
1201 .proc_lseek = seq_lseek,
1202 .proc_release = lprocfs_seq_release,
1205 static struct attribute *lod_attrs[] = {
1206 &lustre_attr_dom_stripesize.attr,
1207 &lustre_attr_dom_stripesize_max_kb.attr,
1208 &lustre_attr_dom_stripesize_cur_kb.attr,
1209 &lustre_attr_dom_threshold_free_mb.attr,
1210 &lustre_attr_stripesize.attr,
1211 &lustre_attr_stripeoffset.attr,
1212 &lustre_attr_stripecount.attr,
1213 &lustre_attr_max_stripecount.attr,
1214 &lustre_attr_stripetype.attr,
1215 &lustre_attr_activeobd.attr,
1216 &lustre_attr_desc_uuid.attr,
1217 &lustre_attr_lmv_failout.attr,
1218 &lustre_attr_numobd.attr,
1219 &lustre_attr_qos_maxage.attr,
1220 &lustre_attr_qos_prio_free.attr,
1221 &lustre_attr_qos_threshold_rr.attr,
1222 &lustre_attr_mdt_stripecount.attr,
1223 &lustre_attr_mdt_stripetype.attr,
1224 &lustre_attr_mdt_activeobd.attr,
1225 &lustre_attr_mdt_numobd.attr,
1226 &lustre_attr_mdt_qos_maxage.attr,
1227 &lustre_attr_mdt_qos_prio_free.attr,
1228 &lustre_attr_mdt_qos_threshold_rr.attr,
1229 &lustre_attr_mdt_hash.attr,
1234 * Initialize procfs entries for LOD.
1236 * \param[in] lod LOD device
1238 * \retval 0 on success
1239 * \retval negative error code if failed
1241 int lod_procfs_init(struct lod_device *lod)
1243 struct obd_device *obd = lod2obd(lod);
1244 struct obd_type *type;
1245 struct kobject *lov;
1248 lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
1249 rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
1252 CERROR("%s: failed to setup DT tunables: %d\n",
1257 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1258 obd->obd_type->typ_procroot,
1260 if (IS_ERR(obd->obd_proc_entry)) {
1261 rc = PTR_ERR(obd->obd_proc_entry);
1262 CERROR("%s: error %d setting up lprocfs\n",
1267 rc = lprocfs_seq_create(obd->obd_proc_entry, "mdt_obd",
1268 0444, &lod_proc_mdt_fops, obd);
1270 CWARN("%s: Error adding the target_obd file %d\n",
1275 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1276 0444, &lod_proc_target_fops, obd);
1278 CWARN("%s: Error adding the target_obd file %d\n",
1283 lod->lod_pool_proc_entry = lprocfs_register("pools",
1284 obd->obd_proc_entry,
1286 if (IS_ERR(lod->lod_pool_proc_entry)) {
1287 rc = PTR_ERR(lod->lod_pool_proc_entry);
1288 lod->lod_pool_proc_entry = NULL;
1289 CWARN("%s: Failed to create pools proc file: %d\n",
1294 lod->lod_spill_proc_entry = lprocfs_register("pool",
1295 obd->obd_proc_entry,
1297 if (IS_ERR(lod->lod_spill_proc_entry)) {
1298 rc = PTR_ERR(lod->lod_spill_proc_entry);
1299 lod->lod_spill_proc_entry = NULL;
1300 CWARN("%s: Failed to create pool proc file: %d\n",
1305 lov = kset_find_obj(lustre_kset, "lov");
1307 CERROR("%s: lov subsystem not found\n", obd->obd_name);
1308 GOTO(out, rc = -ENODEV);
1311 rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
1314 CERROR("%s: failed to create LOV sysfs symlink\n",
1318 obd->obd_debugfs_entry = debugfs_create_dir(obd->obd_name,
1319 obd->obd_type->typ_debugfs_entry);
1321 lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov",
1322 "../lod/%s", obd->obd_name);
1323 if (!lod->lod_debugfs)
1324 CERROR("%s: failed to create LOV debugfs symlink\n",
1327 type = container_of(lov, struct obd_type, typ_kobj);
1328 if (!type->typ_procroot)
1331 /* for compatibility we link old procfs's LOV entries to lod ones */
1332 lod->lod_symlink = lprocfs_add_symlink(obd->obd_name,
1334 "../lod/%s", obd->obd_name);
1335 if (lod->lod_symlink == NULL)
1336 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
1341 dt_tunables_fini(&lod->lod_dt_dev);
1347 * Cleanup procfs entries registred for LOD.
1349 * \param[in] lod LOD device
1351 void lod_procfs_fini(struct lod_device *lod)
1353 struct obd_device *obd = lod2obd(lod);
1354 struct kobject *lov;
1356 if (lod->lod_symlink != NULL) {
1357 lprocfs_remove(&lod->lod_symlink);
1358 lod->lod_symlink = NULL;
1361 lov = kset_find_obj(lustre_kset, "lov");
1363 sysfs_remove_link(lov, obd->obd_name);
1367 debugfs_remove_recursive(lod->lod_debugfs);
1369 if (obd->obd_proc_entry) {
1370 lprocfs_remove(&obd->obd_proc_entry);
1371 obd->obd_proc_entry = NULL;
1374 dt_tunables_fini(&lod->lod_dt_dev);
1377 #endif /* CONFIG_PROC_FS */