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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <lprocfs_status.h>
35 #include <obd_class.h>
36 #include <linux/seq_file.h>
37 #include "lod_internal.h"
38 #include <uapi/linux/lustre/lustre_param.h>
41 * Notice, all the functions below (except for lod_procfs_init() and
42 * lod_procfs_fini()) are not supposed to be used directly. They are
43 * called by Linux kernel's procfs.
48 static ssize_t dom_stripesize_show(struct kobject *kobj,
49 struct attribute *attr,
52 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
53 struct lod_device *lod = dt2lod_dev(dt);
55 return scnprintf(buf, PAGE_SIZE, "%u\n",
56 lod->lod_dom_stripesize_max_kb << 10);
59 static inline int dom_stripesize_max_kb_update(struct lod_device *lod,
62 /* 1GB is the limit */
63 if (val > (1ULL << 20))
67 if (val < LOD_DOM_MIN_SIZE_KB) {
68 LCONSOLE_INFO("Increasing provided stripe size to a minimum value %u\n",
70 val = LOD_DOM_MIN_SIZE_KB;
71 } else if (val & (LOD_DOM_MIN_SIZE_KB - 1)) {
72 val &= ~(LOD_DOM_MIN_SIZE_KB - 1);
73 LCONSOLE_WARN("Changing provided stripe size to %llu (a multiple of minimum %u)\n",
74 val, LOD_DOM_MIN_SIZE_KB);
77 spin_lock(&lod->lod_lsfs_lock);
78 lod->lod_dom_stripesize_max_kb = val;
79 lod_dom_stripesize_recalc(lod);
80 spin_unlock(&lod->lod_lsfs_lock);
84 static ssize_t dom_stripesize_store(struct kobject *kobj,
85 struct attribute *attr,
86 const char *buffer, size_t count)
88 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
89 struct lod_device *lod = dt2lod_dev(dt);
93 rc = sysfs_memparse(buffer, count, &val, "B");
97 rc = dom_stripesize_max_kb_update(lod, val >> 10);
103 /* Old attribute name is still supported */
104 LUSTRE_RW_ATTR(dom_stripesize);
107 * Show DoM maximum allowed stripe size.
109 static ssize_t dom_stripesize_max_kb_show(struct kobject *kobj,
110 struct attribute *attr,
113 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
114 struct lod_device *lod = dt2lod_dev(dt);
116 return scnprintf(buf, PAGE_SIZE, "%u\n",
117 lod->lod_dom_stripesize_max_kb);
121 * Set DoM maximum allowed stripe size.
123 static ssize_t dom_stripesize_max_kb_store(struct kobject *kobj,
124 struct attribute *attr,
125 const char *buffer, size_t count)
127 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
128 struct lod_device *lod = dt2lod_dev(dt);
132 rc = sysfs_memparse(buffer, count, &val, "KiB");
136 rc = dom_stripesize_max_kb_update(lod, val >> 10);
141 LUSTRE_RW_ATTR(dom_stripesize_max_kb);
144 * Show DoM default stripe size.
146 static ssize_t dom_stripesize_cur_kb_show(struct kobject *kobj,
147 struct attribute *attr,
150 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
151 struct lod_device *lod = dt2lod_dev(dt);
153 return scnprintf(buf, PAGE_SIZE, "%u\n",
154 lod->lod_dom_stripesize_cur_kb);
157 LUSTRE_RO_ATTR(dom_stripesize_cur_kb);
160 * Show DoM threshold.
162 static ssize_t dom_threshold_free_mb_show(struct kobject *kobj,
163 struct attribute *attr, char *buf)
165 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
166 struct lod_device *lod = dt2lod_dev(dt);
168 return scnprintf(buf, PAGE_SIZE, "%llu\n",
169 lod->lod_dom_threshold_free_mb);
173 * Set DoM default stripe size.
175 static ssize_t dom_threshold_free_mb_store(struct kobject *kobj,
176 struct attribute *attr,
177 const char *buffer, size_t count)
179 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
180 struct lod_device *lod = dt2lod_dev(dt);
185 pct = strnchr(buffer, count, '%');
187 rc = string_to_size(&val, buffer, pct - buffer);
190 val = mult_frac(lod->lod_lsfs_total_mb,
191 min_t(unsigned int, val, 100), 100);
193 rc = sysfs_memparse(buffer, count, &val, "MiB");
199 spin_lock(&lod->lod_lsfs_lock);
200 lod->lod_dom_threshold_free_mb = val;
201 lod_dom_stripesize_recalc(lod);
202 spin_unlock(&lod->lod_lsfs_lock);
207 LUSTRE_RW_ATTR(dom_threshold_free_mb);
209 static ssize_t stripesize_show(struct kobject *kobj, struct attribute *attr,
212 struct dt_device *dt = container_of(kobj, struct dt_device,
214 struct lod_device *lod = dt2lod_dev(dt);
216 return scnprintf(buf, PAGE_SIZE, "%llu\n",
217 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size);
220 static ssize_t stripesize_store(struct kobject *kobj, struct attribute *attr,
221 const char *buffer, size_t count)
223 struct dt_device *dt = container_of(kobj, struct dt_device,
225 struct lod_device *lod = dt2lod_dev(dt);
229 rc = sysfs_memparse(buffer, count, &val, "B");
233 lod_fix_desc_stripe_size(&val);
234 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size = val;
239 LUSTRE_RW_ATTR(stripesize);
242 * Show default stripe offset.
244 static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
247 struct dt_device *dt = container_of(kobj, struct dt_device,
249 struct lod_device *lod = dt2lod_dev(dt);
251 return scnprintf(buf, PAGE_SIZE, "%lld\n",
252 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset);
256 * Set default stripe offset.
258 * Usually contains -1 allowing Lustre to balance objects among OST
259 * otherwise may cause severe OST imbalance.
261 static ssize_t stripeoffset_store(struct kobject *kobj,
262 struct attribute *attr,
263 const char *buffer, size_t count)
265 struct dt_device *dt = container_of(kobj, struct dt_device,
267 struct lod_device *lod = dt2lod_dev(dt);
271 rc = kstrtol(buffer, 0, &val);
275 if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
278 lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset = val;
283 LUSTRE_RW_ATTR(stripeoffset);
286 * Show default striping pattern (LOV_PATTERN_*).
288 static ssize_t __stripetype_show(struct kobject *kobj, struct attribute *attr,
289 char *buf, bool is_mdt)
291 struct dt_device *dt = container_of(kobj, struct dt_device,
293 struct lod_device *lod = dt2lod_dev(dt);
294 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
297 return scnprintf(buf, PAGE_SIZE, "%u\n", ltd->ltd_lov_desc.ld_pattern);
300 static ssize_t mdt_stripetype_show(struct kobject *kobj, struct attribute *attr,
303 return __stripetype_show(kobj, attr, buf, true);
306 static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
309 return __stripetype_show(kobj, attr, buf, false);
313 * Set default striping pattern (a number, not a human-readable string).
315 static ssize_t __stripetype_store(struct kobject *kobj, struct attribute *attr,
316 const char *buffer, size_t count, bool is_mdt)
318 struct dt_device *dt = container_of(kobj, struct dt_device,
320 struct lod_device *lod = dt2lod_dev(dt);
321 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
326 rc = kstrtouint(buffer, 0, &pattern);
331 lod_fix_lmv_desc_pattern(&pattern);
333 lod_fix_desc_pattern(&pattern);
335 ltd->ltd_lov_desc.ld_pattern = pattern;
340 static ssize_t mdt_stripetype_store(struct kobject *kobj,
341 struct attribute *attr, const char *buffer,
344 return __stripetype_store(kobj, attr, buffer, count, true);
347 static ssize_t stripetype_store(struct kobject *kobj,
348 struct attribute *attr, const char *buffer,
351 return __stripetype_store(kobj, attr, buffer, count, false);
354 LUSTRE_RW_ATTR(mdt_stripetype);
355 LUSTRE_RW_ATTR(stripetype);
358 * Show default number of stripes.
360 static ssize_t __stripecount_show(struct kobject *kobj, struct attribute *attr,
361 char *buf, bool is_mdt)
363 struct dt_device *dt = container_of(kobj, struct dt_device,
365 struct lod_device *lod = dt2lod_dev(dt);
366 struct lov_desc *desc = is_mdt ? &lod->lod_mdt_descs.ltd_lov_desc :
367 &lod->lod_ost_descs.ltd_lov_desc;
369 return scnprintf(buf, PAGE_SIZE, "%d\n",
370 (s16)(desc->ld_default_stripe_count + 1) - 1);
373 static ssize_t mdt_stripecount_show(struct kobject *kobj,
374 struct attribute *attr, char *buf)
376 return __stripecount_show(kobj, attr, buf, true);
379 static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
382 return __stripecount_show(kobj, attr, buf, false);
386 * Set default number of stripes.
388 static ssize_t __stripecount_store(struct kobject *kobj, struct attribute *attr,
389 const char *buffer, size_t count,
392 struct dt_device *dt = container_of(kobj, struct dt_device,
394 struct lod_device *lod = dt2lod_dev(dt);
395 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
400 rc = kstrtoint(buffer, 0, &stripe_count);
404 if (stripe_count < -1)
407 lod_fix_desc_stripe_count(&stripe_count);
408 ltd->ltd_lov_desc.ld_default_stripe_count = stripe_count;
413 static ssize_t mdt_stripecount_store(struct kobject *kobj,
414 struct attribute *attr,
415 const char *buffer, size_t count)
417 return __stripecount_store(kobj, attr, buffer, count, true);
420 static ssize_t stripecount_store(struct kobject *kobj,
421 struct attribute *attr,
422 const char *buffer, size_t count)
424 return __stripecount_store(kobj, attr, buffer, count, false);
427 LUSTRE_RW_ATTR(mdt_stripecount);
428 LUSTRE_RW_ATTR(stripecount);
431 * Show number of targets.
433 static ssize_t __numobd_show(struct kobject *kobj, struct attribute *attr,
434 char *buf, bool is_mdt)
436 struct dt_device *dt = container_of(kobj, struct dt_device,
438 struct lod_device *lod = dt2lod_dev(dt);
439 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
442 return scnprintf(buf, PAGE_SIZE, "%u\n",
443 ltd->ltd_lov_desc.ld_tgt_count);
446 static ssize_t mdt_numobd_show(struct kobject *kobj, struct attribute *attr,
449 return __numobd_show(kobj, attr, buf, true);
452 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
455 return __numobd_show(kobj, attr, buf, false);
458 LUSTRE_RO_ATTR(mdt_numobd);
459 LUSTRE_RO_ATTR(numobd);
462 * Show number of active targets.
464 static ssize_t __activeobd_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_active_tgt_count);
477 static ssize_t mdt_activeobd_show(struct kobject *kobj, struct attribute *attr,
480 return __activeobd_show(kobj, attr, buf, true);
483 static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
486 return __activeobd_show(kobj, attr, buf, false);
489 LUSTRE_RO_ATTR(mdt_activeobd);
490 LUSTRE_RO_ATTR(activeobd);
493 * Show UUID of LOD device.
495 static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
498 struct dt_device *dt = container_of(kobj, struct dt_device,
500 struct lod_device *lod = dt2lod_dev(dt);
502 return scnprintf(buf, PAGE_SIZE, "%s\n",
503 lod->lod_ost_descs.ltd_lov_desc.ld_uuid.uuid);
505 LUSTRE_RO_ATTR(desc_uuid);
508 * Show QoS priority parameter.
510 * The printed value is a percentage value (0-100%) indicating the priority
511 * of free space compared to performance. 0% means select OSTs equally
512 * regardless of their free space, 100% means select OSTs only by their free
513 * space even if it results in very imbalanced load on the OSTs.
515 static ssize_t __qos_prio_free_show(struct kobject *kobj,
516 struct attribute *attr, char *buf,
519 struct dt_device *dt = container_of(kobj, struct dt_device,
521 struct lod_device *lod = dt2lod_dev(dt);
522 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
525 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
526 (ltd->ltd_qos.lq_prio_free * 100 + 255) >> 8);
529 static ssize_t mdt_qos_prio_free_show(struct kobject *kobj,
530 struct attribute *attr, char *buf)
532 return __qos_prio_free_show(kobj, attr, buf, true);
535 static ssize_t qos_prio_free_show(struct kobject *kobj,
536 struct attribute *attr, char *buf)
538 return __qos_prio_free_show(kobj, attr, buf, false);
542 * Set QoS free space priority parameter.
544 * Set the relative priority of free OST space compared to OST load when OSTs
545 * are space imbalanced. See qos_priofree_show() for description of
546 * this parameter. See qos_threshold_rr_store() and lq_threshold_rr to
547 * determine what constitutes "space imbalanced" OSTs.
549 static ssize_t __qos_prio_free_store(struct kobject *kobj,
550 struct attribute *attr,
551 const char *buffer, size_t count,
554 struct dt_device *dt = container_of(kobj, struct dt_device,
556 struct lod_device *lod = dt2lod_dev(dt);
557 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
562 rc = kstrtouint(buffer, 0, &val);
568 ltd->ltd_qos.lq_prio_free = (val << 8) / 100;
569 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
570 set_bit(LQ_RESET, <d->ltd_qos.lq_flags);
575 static ssize_t mdt_qos_prio_free_store(struct kobject *kobj,
576 struct attribute *attr,
577 const char *buffer, size_t count)
579 return __qos_prio_free_store(kobj, attr, buffer, count, true);
582 static ssize_t qos_prio_free_store(struct kobject *kobj, struct attribute *attr,
583 const char *buffer, size_t count)
585 return __qos_prio_free_store(kobj, attr, buffer, count, false);
588 LUSTRE_RW_ATTR(mdt_qos_prio_free);
589 LUSTRE_RW_ATTR(qos_prio_free);
592 * Show threshold for "same space on all OSTs" rule.
594 static ssize_t __qos_threshold_rr_show(struct kobject *kobj,
595 struct attribute *attr, char *buf,
598 struct dt_device *dt = container_of(kobj, struct dt_device,
600 struct lod_device *lod = dt2lod_dev(dt);
601 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
604 return scnprintf(buf, PAGE_SIZE, "%d%%\n",
605 (ltd->ltd_qos.lq_threshold_rr * 100 + 255) >> 8);
608 static ssize_t mdt_qos_threshold_rr_show(struct kobject *kobj,
609 struct attribute *attr, char *buf)
611 return __qos_threshold_rr_show(kobj, attr, buf, true);
614 static ssize_t qos_threshold_rr_show(struct kobject *kobj,
615 struct attribute *attr, char *buf)
617 return __qos_threshold_rr_show(kobj, attr, buf, false);
621 * Set threshold for "same space on all OSTs" rule.
623 * This sets the maximum percentage difference of free space between the most
624 * full and most empty OST in the currently available OSTs. If this percentage
625 * is exceeded, use the QoS allocator to select OSTs based on their available
626 * space so that more full OSTs are chosen less often, otherwise use the
627 * round-robin allocator for efficiency and performance.
629 static ssize_t __qos_threshold_rr_store(struct kobject *kobj,
630 struct attribute *attr,
631 const char *buffer, size_t count,
634 struct dt_device *dt = container_of(kobj, struct dt_device,
636 struct lod_device *lod = dt2lod_dev(dt);
637 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
643 /* "100%\n\0" should be largest string */
644 if (count >= sizeof(buf))
647 strncpy(buf, buffer, sizeof(buf));
648 buf[sizeof(buf) - 1] = '\0';
649 tmp = strchr(buf, '%');
653 rc = kstrtouint(buf, 0, &val);
659 ltd->ltd_qos.lq_threshold_rr = (val << 8) / 100;
660 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
665 static ssize_t mdt_qos_threshold_rr_store(struct kobject *kobj,
666 struct attribute *attr,
667 const char *buffer, size_t count)
669 return __qos_threshold_rr_store(kobj, attr, buffer, count, true);
672 static ssize_t qos_threshold_rr_store(struct kobject *kobj,
673 struct attribute *attr,
674 const char *buffer, size_t count)
676 return __qos_threshold_rr_store(kobj, attr, buffer, count, false);
679 LUSTRE_RW_ATTR(mdt_qos_threshold_rr);
680 LUSTRE_RW_ATTR(qos_threshold_rr);
683 * Show expiration period used to refresh cached statfs data, which
684 * is used to implement QoS/RR striping allocation algorithm.
686 static ssize_t __qos_maxage_show(struct kobject *kobj, struct attribute *attr,
687 char *buf, bool is_mdt)
689 struct dt_device *dt = container_of(kobj, struct dt_device,
691 struct lod_device *lod = dt2lod_dev(dt);
692 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
695 return scnprintf(buf, PAGE_SIZE, "%u Sec\n",
696 ltd->ltd_lov_desc.ld_qos_maxage);
699 static ssize_t mdt_qos_maxage_show(struct kobject *kobj, struct attribute *attr,
702 return __qos_maxage_show(kobj, attr, buf, true);
705 static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr,
708 return __qos_maxage_show(kobj, attr, buf, true);
712 * Set expiration period used to refresh cached statfs data.
714 static ssize_t __qos_maxage_store(struct kobject *kobj, struct attribute *attr,
715 const char *buffer, size_t count, bool is_mdt)
717 struct dt_device *dt = container_of(kobj, struct dt_device,
719 struct lod_device *lod = dt2lod_dev(dt);
720 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
722 struct lustre_cfg_bufs bufs;
723 struct lu_device *next;
724 struct lustre_cfg *lcfg;
726 struct lu_tgt_desc *tgt;
730 rc = kstrtouint(buffer, 0, &val);
737 ltd->ltd_lov_desc.ld_qos_maxage = val;
740 * propogate the value down to OSPs
742 lustre_cfg_bufs_reset(&bufs, NULL);
743 snprintf(str, 32, "%smaxage=%u", PARAM_OSP, val);
744 lustre_cfg_bufs_set_string(&bufs, 1, str);
745 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
748 lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
751 ltd_foreach_tgt(ltd, tgt) {
752 next = &tgt->ltd_tgt->dd_lu_dev;
753 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
755 CERROR("can't set maxage on #%d: %d\n",
758 lod_putref(lod, ltd);
759 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
764 static ssize_t mdt_qos_maxage_store(struct kobject *kobj,
765 struct attribute *attr,
766 const char *buffer, size_t count)
768 return __qos_maxage_store(kobj, attr, buffer, count, true);
771 static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr,
772 const char *buffer, size_t count)
774 return __qos_maxage_store(kobj, attr, buffer, count, false);
777 LUSTRE_RW_ATTR(mdt_qos_maxage);
778 LUSTRE_RW_ATTR(qos_maxage);
780 static void *lod_tgts_seq_start(struct seq_file *p, loff_t *pos, bool is_mdt)
782 struct obd_device *obd = p->private;
783 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
784 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
787 LASSERT(obd != NULL);
789 lod_getref(ltd); /* released in lod_tgts_seq_stop */
790 if (*pos >= ltd->ltd_tgts_size)
793 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
794 ltd->ltd_tgts_size, *pos);
795 if (*pos < ltd->ltd_tgts_size)
796 return LTD_TGT(ltd, *pos);
801 static void *lod_mdts_seq_start(struct seq_file *p, loff_t *pos)
803 return lod_tgts_seq_start(p, pos, true);
806 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
808 return lod_tgts_seq_start(p, pos, false);
811 static void lod_tgts_seq_stop(struct seq_file *p, void *v, bool is_mdt)
813 struct obd_device *obd = p->private;
814 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
815 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
818 LASSERT(obd != NULL);
819 lod_putref(lod, ltd);
822 static void lod_mdts_seq_stop(struct seq_file *p, void *v)
824 lod_tgts_seq_stop(p, v, true);
827 static void lod_osts_seq_stop(struct seq_file *p, void *v)
829 lod_tgts_seq_stop(p, v, false);
832 static void *lod_tgts_seq_next(struct seq_file *p, void *v, loff_t *pos,
835 struct obd_device *obd = p->private;
836 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
837 struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
841 if (*pos > ltd->ltd_tgts_size - 1)
844 *pos = find_next_bit(ltd->ltd_tgt_bitmap,
845 ltd->ltd_tgts_size, *pos);
846 if (*pos < ltd->ltd_tgts_size)
847 return LTD_TGT(ltd, *pos);
852 static void *lod_mdts_seq_next(struct seq_file *p, void *v, loff_t *pos)
854 return lod_tgts_seq_next(p, v, pos, true);
857 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
859 return lod_tgts_seq_next(p, v, pos, false);
863 * Show active/inactive status for OST found by lod_osts_seq_next().
865 * \param[in] m seq file
866 * \param[in] v unused for single entry
868 * \retval 0 on success
869 * \retval negative error code if failed
871 static int lod_tgts_seq_show(struct seq_file *p, void *v)
873 struct obd_device *obd = p->private;
874 struct lu_tgt_desc *tgt = v;
875 struct dt_device *next;
878 LASSERT(obd->obd_lu_dev);
884 /* XXX: should be non-NULL env, but it's very expensive */
886 rc = dt_statfs(NULL, next, &tgt->ltd_statfs);
887 if (rc == -ENOTCONN) {
893 seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
894 obd_uuid2str(&tgt->ltd_uuid),
899 static const struct seq_operations lod_mdts_sops = {
900 .start = lod_mdts_seq_start,
901 .stop = lod_mdts_seq_stop,
902 .next = lod_mdts_seq_next,
903 .show = lod_tgts_seq_show,
906 static const struct seq_operations lod_osts_sops = {
907 .start = lod_osts_seq_start,
908 .stop = lod_osts_seq_stop,
909 .next = lod_osts_seq_next,
910 .show = lod_tgts_seq_show,
913 static int lod_mdts_seq_open(struct inode *inode, struct file *file)
915 struct seq_file *seq;
918 rc = seq_open(file, &lod_mdts_sops);
922 seq = file->private_data;
923 seq->private = PDE_DATA(inode);
927 static int lod_osts_seq_open(struct inode *inode, struct file *file)
929 struct seq_file *seq;
932 rc = seq_open(file, &lod_osts_sops);
936 seq = file->private_data;
937 seq->private = PDE_DATA(inode);
942 * Show whether special failout mode for testing is enabled or not.
944 static ssize_t lmv_failout_show(struct kobject *kobj, struct attribute *attr,
947 struct dt_device *dt = container_of(kobj, struct dt_device,
949 struct lod_device *lod = dt2lod_dev(dt);
951 return scnprintf(buf, PAGE_SIZE, "%d\n", lod->lod_lmv_failout ? 1 : 0);
955 * Enable/disable a special failout mode for testing.
957 * This determines whether the LMV will try to continue processing a striped
958 * directory even if it has a (partly) corrupted entry in the master directory,
959 * or if it will abort upon finding a corrupted slave directory entry.
961 static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr,
962 const char *buffer, size_t count)
964 struct dt_device *dt = container_of(kobj, struct dt_device,
966 struct lod_device *lod = dt2lod_dev(dt);
970 rc = kstrtobool(buffer, &val);
974 lod->lod_lmv_failout = val;
978 LUSTRE_RW_ATTR(lmv_failout);
980 char *mdt_hash_name[] = { "none",
981 LMV_HASH_NAME_ALL_CHARS,
982 LMV_HASH_NAME_FNV_1A_64,
986 static ssize_t mdt_hash_show(struct kobject *kobj, struct attribute *attr,
989 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
990 struct lod_device *lod = dt2lod_dev(dt);
992 return scnprintf(buf, PAGE_SIZE, "%s\n",
993 mdt_hash_name[lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern]);
996 static ssize_t mdt_hash_store(struct kobject *kobj, struct attribute *attr,
997 const char *buffer, size_t count)
999 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
1000 struct lod_device *lod = dt2lod_dev(dt);
1005 hash = kstrndup(buffer, count, GFP_KERNEL);
1009 len = strcspn(hash, "\n ");
1011 for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++) {
1012 if (!strcmp(hash, mdt_hash_name[i])) {
1013 lod->lod_mdt_descs.ltd_lmv_desc.ld_pattern = i;
1022 LUSTRE_RW_ATTR(mdt_hash);
1024 static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
1028 static const struct file_operations lod_proc_mdt_fops = {
1029 .owner = THIS_MODULE,
1030 .open = lod_mdts_seq_open,
1032 .llseek = seq_lseek,
1033 .release = lprocfs_seq_release,
1036 static const struct file_operations lod_proc_target_fops = {
1037 .owner = THIS_MODULE,
1038 .open = lod_osts_seq_open,
1040 .llseek = seq_lseek,
1041 .release = lprocfs_seq_release,
1044 static struct attribute *lod_attrs[] = {
1045 &lustre_attr_dom_stripesize.attr,
1046 &lustre_attr_dom_stripesize_max_kb.attr,
1047 &lustre_attr_dom_stripesize_cur_kb.attr,
1048 &lustre_attr_dom_threshold_free_mb.attr,
1049 &lustre_attr_stripesize.attr,
1050 &lustre_attr_stripeoffset.attr,
1051 &lustre_attr_stripecount.attr,
1052 &lustre_attr_stripetype.attr,
1053 &lustre_attr_activeobd.attr,
1054 &lustre_attr_desc_uuid.attr,
1055 &lustre_attr_lmv_failout.attr,
1056 &lustre_attr_numobd.attr,
1057 &lustre_attr_qos_maxage.attr,
1058 &lustre_attr_qos_prio_free.attr,
1059 &lustre_attr_qos_threshold_rr.attr,
1060 &lustre_attr_mdt_stripecount.attr,
1061 &lustre_attr_mdt_stripetype.attr,
1062 &lustre_attr_mdt_activeobd.attr,
1063 &lustre_attr_mdt_numobd.attr,
1064 &lustre_attr_mdt_qos_maxage.attr,
1065 &lustre_attr_mdt_qos_prio_free.attr,
1066 &lustre_attr_mdt_qos_threshold_rr.attr,
1067 &lustre_attr_mdt_hash.attr,
1072 * Initialize procfs entries for LOD.
1074 * \param[in] lod LOD device
1076 * \retval 0 on success
1077 * \retval negative error code if failed
1079 int lod_procfs_init(struct lod_device *lod)
1081 struct ldebugfs_vars ldebugfs_obd_vars[] = { { NULL } };
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_vars = lprocfs_lod_obd_vars;
1097 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1098 obd->obd_type->typ_procroot,
1099 obd->obd_vars, obd);
1100 if (IS_ERR(obd->obd_proc_entry)) {
1101 rc = PTR_ERR(obd->obd_proc_entry);
1102 CERROR("%s: error %d setting up lprocfs\n",
1107 rc = lprocfs_seq_create(obd->obd_proc_entry, "mdt_obd",
1108 0444, &lod_proc_mdt_fops, obd);
1110 CWARN("%s: Error adding the target_obd file %d\n",
1115 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1116 0444, &lod_proc_target_fops, obd);
1118 CWARN("%s: Error adding the target_obd file %d\n",
1123 lod->lod_pool_proc_entry = lprocfs_register("pools",
1124 obd->obd_proc_entry,
1126 if (IS_ERR(lod->lod_pool_proc_entry)) {
1127 rc = PTR_ERR(lod->lod_pool_proc_entry);
1128 lod->lod_pool_proc_entry = NULL;
1129 CWARN("%s: Failed to create pool proc file: %d\n",
1134 lov = kset_find_obj(lustre_kset, "lov");
1136 CERROR("%s: lov subsystem not found\n", obd->obd_name);
1137 GOTO(out, rc = -ENODEV);
1140 rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
1143 CERROR("%s: failed to create LOV sysfs symlink\n",
1147 lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov",
1148 "../lod/%s", obd->obd_name);
1149 if (!lod->lod_debugfs)
1150 CERROR("%s: failed to create LOV debugfs symlink\n",
1153 type = container_of(lov, struct obd_type, typ_kobj);
1154 if (!type->typ_procroot)
1157 /* for compatibility we link old procfs's LOV entries to lod ones */
1158 lod->lod_symlink = lprocfs_add_symlink(obd->obd_name,
1160 "../lod/%s", obd->obd_name);
1161 if (lod->lod_symlink == NULL)
1162 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
1167 dt_tunables_fini(&lod->lod_dt_dev);
1173 * Cleanup procfs entries registred for LOD.
1175 * \param[in] lod LOD device
1177 void lod_procfs_fini(struct lod_device *lod)
1179 struct obd_device *obd = lod2obd(lod);
1180 struct kobject *lov;
1182 if (lod->lod_symlink != NULL) {
1183 lprocfs_remove(&lod->lod_symlink);
1184 lod->lod_symlink = NULL;
1187 lov = kset_find_obj(lustre_kset, "lov");
1189 sysfs_remove_link(lov, obd->obd_name);
1193 debugfs_remove_recursive(lod->lod_debugfs);
1195 if (obd->obd_proc_entry) {
1196 lprocfs_remove(&obd->obd_proc_entry);
1197 obd->obd_proc_entry = NULL;
1200 dt_tunables_fini(&lod->lod_dt_dev);
1203 #endif /* CONFIG_PROC_FS */