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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <lprocfs_status.h>
39 #include <obd_class.h>
40 #include <linux/seq_file.h>
41 #include "lod_internal.h"
42 #include <lustre_param.h>
45 * Notice, all the functions below (except for lod_procfs_init() and
46 * lod_procfs_fini()) are not supposed to be used directly. They are
47 * called by Linux kernel's procfs.
53 * Show default stripe size.
55 * \param[in] m seq file
56 * \param[in] v unused for single entry
58 * \retval 0 on success
59 * \retval negative error code if failed
61 static int lod_stripesize_seq_show(struct seq_file *m, void *v)
63 struct obd_device *dev = m->private;
64 struct lod_device *lod;
67 lod = lu2lod_dev(dev->obd_lu_dev);
68 seq_printf(m, LPU64"\n",
69 lod->lod_desc.ld_default_stripe_size);
74 * Set default stripe size.
76 * \param[in] file proc file
77 * \param[in] buffer string containing the maximum number of bytes stored in
78 * each object before moving to the next object in the
80 * \param[in] count @buffer length
81 * \param[in] off unused for single entry
83 * \retval @count on success
84 * \retval negative error code if failed
87 lod_stripesize_seq_write(struct file *file, const char __user *buffer,
88 size_t count, loff_t *off)
90 struct seq_file *m = file->private_data;
91 struct obd_device *dev = m->private;
92 struct lod_device *lod;
97 lod = lu2lod_dev(dev->obd_lu_dev);
98 rc = lprocfs_write_u64_helper(buffer, count, &val);
102 lod_fix_desc_stripe_size(&val);
103 lod->lod_desc.ld_default_stripe_size = val;
106 LPROC_SEQ_FOPS(lod_stripesize);
109 * Show default stripe offset.
111 * \param[in] m seq file
112 * \param[in] v unused for single entry
114 * \retval 0 on success
115 * \retval negative error code if failed
117 static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
119 struct obd_device *dev = m->private;
120 struct lod_device *lod;
122 LASSERT(dev != NULL);
123 lod = lu2lod_dev(dev->obd_lu_dev);
124 seq_printf(m, LPU64"\n",
125 lod->lod_desc.ld_default_stripe_offset);
130 * Set default stripe offset.
132 * Usually contains -1 allowing Lustre to balance objects among OST
133 * otherwise may cause severe OST imbalance.
135 * \param[in] file proc file
136 * \param[in] buffer string describing starting OST index for new files
137 * \param[in] count @buffer length
138 * \param[in] off unused for single entry
140 * \retval @count on success
141 * \retval negative error code if failed
144 lod_stripeoffset_seq_write(struct file *file, const char __user *buffer,
145 size_t count, loff_t *off)
147 struct seq_file *m = file->private_data;
148 struct obd_device *dev = m->private;
149 struct lod_device *lod;
153 LASSERT(dev != NULL);
154 lod = lu2lod_dev(dev->obd_lu_dev);
155 rc = lprocfs_write_u64_helper(buffer, count, &val);
159 lod->lod_desc.ld_default_stripe_offset = val;
162 LPROC_SEQ_FOPS(lod_stripeoffset);
165 * Show default striping pattern (LOV_PATTERN_*).
167 * \param[in] m seq file
168 * \param[in] v unused for single entry
170 * \retval 0 on success
171 * \retval negative error code if failed
173 static int lod_stripetype_seq_show(struct seq_file *m, void *v)
175 struct obd_device *dev = m->private;
176 struct lod_device *lod;
178 LASSERT(dev != NULL);
179 lod = lu2lod_dev(dev->obd_lu_dev);
180 seq_printf(m, "%u\n", lod->lod_desc.ld_pattern);
185 * Set default striping pattern (a number, not a human-readable string).
187 * \param[in] file proc file
188 * \param[in] buffer string containing the default striping pattern for new
189 * files. This is an integer LOV_PATTERN_* value
190 * \param[in] count @buffer length
191 * \param[in] off unused for single entry
193 * \retval @count on success
194 * \retval negative error code if failed
197 lod_stripetype_seq_write(struct file *file, const char __user *buffer,
198 size_t count, loff_t *off)
200 struct seq_file *m = file->private_data;
201 struct obd_device *dev = m->private;
202 struct lod_device *lod;
205 LASSERT(dev != NULL);
206 lod = lu2lod_dev(dev->obd_lu_dev);
207 rc = lprocfs_write_helper(buffer, count, &val);
211 lod_fix_desc_pattern(&val);
212 lod->lod_desc.ld_pattern = val;
215 LPROC_SEQ_FOPS(lod_stripetype);
218 * Show default number of stripes.
220 * \param[in] m seq file
221 * \param[in] v unused for single entry
223 * \retval 0 on success,
224 * \retval negative error code if failed
226 static int lod_stripecount_seq_show(struct seq_file *m, void *v)
228 struct obd_device *dev = m->private;
229 struct lod_device *lod;
231 LASSERT(dev != NULL);
232 lod = lu2lod_dev(dev->obd_lu_dev);
233 seq_printf(m, "%d\n",
234 (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
239 * Set default number of stripes.
241 * \param[in] file proc file
242 * \param[in] buffer string containing the default number of stripes
244 * \param[in] count @buffer length
245 * \param[in] off unused for single entry
247 * \retval @count on success
248 * \retval negative error code otherwise
251 lod_stripecount_seq_write(struct file *file, const char __user *buffer,
252 size_t count, loff_t *off)
254 struct seq_file *m = file->private_data;
255 struct obd_device *dev = m->private;
256 struct lod_device *lod;
259 LASSERT(dev != NULL);
260 lod = lu2lod_dev(dev->obd_lu_dev);
261 rc = lprocfs_write_helper(buffer, count, &val);
265 lod_fix_desc_stripe_count(&val);
266 lod->lod_desc.ld_default_stripe_count = val;
269 LPROC_SEQ_FOPS(lod_stripecount);
272 * Show number of targets.
274 * \param[in] m seq file
275 * \param[in] v unused for single entry
277 * \retval 0 on success
278 * \retval negative error code if failed
280 static int lod_numobd_seq_show(struct seq_file *m, void *v)
282 struct obd_device *dev = m->private;
283 struct lod_device *lod;
285 LASSERT(dev != NULL);
286 lod = lu2lod_dev(dev->obd_lu_dev);
287 seq_printf(m, "%u\n", lod->lod_desc.ld_tgt_count);
290 LPROC_SEQ_FOPS_RO(lod_numobd);
293 * Show number of active targets.
295 * \param[in] m seq file
296 * \param[in] v unused for single entry
298 * \retval 0 on success
299 * \retval negative error code if failed
301 static int lod_activeobd_seq_show(struct seq_file *m, void *v)
303 struct obd_device *dev = m->private;
304 struct lod_device *lod;
306 LASSERT(dev != NULL);
307 lod = lu2lod_dev(dev->obd_lu_dev);
308 seq_printf(m, "%u\n", lod->lod_desc.ld_active_tgt_count);
311 LPROC_SEQ_FOPS_RO(lod_activeobd);
314 * Show UUID of LOD device.
316 * \param[in] m seq file
317 * \param[in] v unused for single entry
319 * \retval 0 on success
320 * \retval negative error code if failed
322 static int lod_desc_uuid_seq_show(struct seq_file *m, void *v)
324 struct obd_device *dev = m->private;
325 struct lod_device *lod;
327 LASSERT(dev != NULL);
328 lod = lu2lod_dev(dev->obd_lu_dev);
329 seq_printf(m, "%s\n", lod->lod_desc.ld_uuid.uuid);
332 LPROC_SEQ_FOPS_RO(lod_desc_uuid);
335 * Show QoS priority parameter.
337 * The printed value is a percentage value (0-100%) indicating the priority
338 * of free space compared to performance. 0% means select OSTs equally
339 * regardless of their free space, 100% means select OSTs only by their free
340 * space even if it results in very imbalanced load on the OSTs.
342 * \param[in] m seq file
343 * \param[in] v unused for single entry
345 * \retval 0 on success
346 * \retval negative error code if failed
348 static int lod_qos_priofree_seq_show(struct seq_file *m, void *v)
350 struct obd_device *dev = m->private;
351 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
353 LASSERT(lod != NULL);
354 seq_printf(m, "%d%%\n",
355 (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
360 * Set QoS free space priority parameter.
362 * Set the relative priority of free OST space compared to OST load when OSTs
363 * are space imbalanced. See lod_qos_priofree_seq_show() for description of
364 * this parameter. See lod_qos_thresholdrr_seq_write() and lq_threshold_rr to
365 * determine what constitutes "space imbalanced" OSTs.
367 * \param[in] file proc file
368 * \param[in] buffer string which contains the free space priority (0-100)
369 * \param[in] count @buffer length
370 * \param[in] off unused for single entry
372 * \retval @count on success
373 * \retval negative error code if failed
376 lod_qos_priofree_seq_write(struct file *file, const char __user *buffer,
377 size_t count, loff_t *off)
379 struct seq_file *m = file->private_data;
380 struct obd_device *dev = m->private;
381 struct lod_device *lod;
384 LASSERT(dev != NULL);
385 lod = lu2lod_dev(dev->obd_lu_dev);
387 rc = lprocfs_write_helper(buffer, count, &val);
393 lod->lod_qos.lq_prio_free = (val << 8) / 100;
394 lod->lod_qos.lq_dirty = 1;
395 lod->lod_qos.lq_reset = 1;
398 LPROC_SEQ_FOPS(lod_qos_priofree);
401 * Show threshold for "same space on all OSTs" rule.
403 * \param[in] m seq file
404 * \param[in] v unused for single entry
406 * \retval 0 on success
407 * \retval negative error code if failed
409 static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
411 struct obd_device *dev = m->private;
412 struct lod_device *lod;
414 LASSERT(dev != NULL);
415 lod = lu2lod_dev(dev->obd_lu_dev);
416 seq_printf(m, "%d%%\n",
417 (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
422 * Set threshold for "same space on all OSTs" rule.
424 * This sets the maximum percentage difference of free space between the most
425 * full and most empty OST in the currently available OSTs. If this percentage
426 * is exceeded, use the QoS allocator to select OSTs based on their available
427 * space so that more full OSTs are chosen less often, otherwise use the
428 * round-robin allocator for efficiency and performance.
430 * \param[in] file proc file
431 * \param[in] buffer string containing percentage difference of free space
432 * \param[in] count @buffer length
433 * \param[in] off unused for single entry
435 * \retval @count on success
436 * \retval negative error code if failed
439 lod_qos_thresholdrr_seq_write(struct file *file, const char __user *buffer,
440 size_t count, loff_t *off)
442 struct seq_file *m = file->private_data;
443 struct obd_device *dev = m->private;
444 struct lod_device *lod;
447 LASSERT(dev != NULL);
448 lod = lu2lod_dev(dev->obd_lu_dev);
450 rc = lprocfs_write_helper(buffer, count, &val);
454 if (val > 100 || val < 0)
457 lod->lod_qos.lq_threshold_rr = (val << 8) / 100;
458 lod->lod_qos.lq_dirty = 1;
461 LPROC_SEQ_FOPS(lod_qos_thresholdrr);
464 * Show expiration period used to refresh cached statfs data, which
465 * is used to implement QoS/RR striping allocation algorithm.
467 * \param[in] m seq file
468 * \param[in] v unused for single entry
470 * \retval 0 on success
471 * \retval negative error code if failed
473 static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
475 struct obd_device *dev = m->private;
476 struct lod_device *lod;
478 LASSERT(dev != NULL);
479 lod = lu2lod_dev(dev->obd_lu_dev);
480 seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
485 * Set expiration period used to refresh cached statfs data.
487 * \param[in] file proc file
488 * \param[in] buffer string contains maximum age of statfs data in seconds
489 * \param[in] count @buffer length
490 * \param[in] off unused for single entry
492 * \retval @count on success
493 * \retval negative error code if failed
496 lod_qos_maxage_seq_write(struct file *file, const char __user *buffer,
497 size_t count, loff_t *off)
499 struct seq_file *m = file->private_data;
500 struct obd_device *dev = m->private;
501 struct lustre_cfg_bufs bufs;
502 struct lod_device *lod;
503 struct lu_device *next;
504 struct lustre_cfg *lcfg;
509 LASSERT(dev != NULL);
510 lod = lu2lod_dev(dev->obd_lu_dev);
512 rc = lprocfs_write_helper(buffer, count, &val);
518 lod->lod_desc.ld_qos_maxage = val;
521 * propogate the value down to OSPs
523 lustre_cfg_bufs_reset(&bufs, NULL);
524 sprintf(str, "%smaxage=%d", PARAM_OSP, val);
525 lustre_cfg_bufs_set_string(&bufs, 1, str);
526 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
530 lod_getref(&lod->lod_ost_descs);
531 lod_foreach_ost(lod, i) {
532 next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
533 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
535 CERROR("can't set maxage on #%d: %d\n", i, rc);
537 lod_putref(lod, &lod->lod_ost_descs);
538 lustre_cfg_free(lcfg);
542 LPROC_SEQ_FOPS(lod_qos_maxage);
544 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
546 struct obd_device *dev = p->private;
547 struct lod_device *lod;
549 LASSERT(dev != NULL);
550 lod = lu2lod_dev(dev->obd_lu_dev);
552 lod_getref(&lod->lod_ost_descs); /* released in lod_osts_seq_stop */
553 if (*pos >= lod->lod_ost_bitmap->size)
556 *pos = find_next_bit(lod->lod_ost_bitmap->data,
557 lod->lod_ost_bitmap->size, *pos);
558 if (*pos < lod->lod_ost_bitmap->size)
559 return OST_TGT(lod,*pos);
564 static void lod_osts_seq_stop(struct seq_file *p, void *v)
566 struct obd_device *dev = p->private;
567 struct lod_device *lod;
569 LASSERT(dev != NULL);
570 lod = lu2lod_dev(dev->obd_lu_dev);
571 lod_putref(lod, &lod->lod_ost_descs);
574 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
576 struct obd_device *dev = p->private;
577 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
579 if (*pos >= lod->lod_ost_bitmap->size - 1)
582 *pos = find_next_bit(lod->lod_ost_bitmap->data,
583 lod->lod_ost_bitmap->size, *pos + 1);
584 if (*pos < lod->lod_ost_bitmap->size)
585 return OST_TGT(lod,*pos);
591 * Show active/inactive status for OST found by lod_osts_seq_next().
593 * \param[in] m seq file
594 * \param[in] v unused for single entry
596 * \retval 0 on success
597 * \retval negative error code if failed
599 static int lod_osts_seq_show(struct seq_file *p, void *v)
601 struct obd_device *obd = p->private;
602 struct lod_ost_desc *ost_desc = v;
603 struct lod_device *lod;
605 struct dt_device *next;
606 struct obd_statfs sfs;
608 LASSERT(obd->obd_lu_dev);
609 lod = lu2lod_dev(obd->obd_lu_dev);
611 idx = ost_desc->ltd_index;
612 next = OST_TGT(lod,idx)->ltd_ost;
616 /* XXX: should be non-NULL env, but it's very expensive */
618 rc = dt_statfs(NULL, next, &sfs);
619 if (rc == -ENOTCONN) {
625 seq_printf(p, "%d: %s %sACTIVE\n", idx,
626 obd_uuid2str(&ost_desc->ltd_uuid),
631 static const struct seq_operations lod_osts_sops = {
632 .start = lod_osts_seq_start,
633 .stop = lod_osts_seq_stop,
634 .next = lod_osts_seq_next,
635 .show = lod_osts_seq_show,
638 static int lod_osts_seq_open(struct inode *inode, struct file *file)
640 struct seq_file *seq;
643 rc = seq_open(file, &lod_osts_sops);
647 seq = file->private_data;
648 seq->private = PDE_DATA(inode);
652 LPROC_SEQ_FOPS_RO_TYPE(lod, uuid);
654 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_blksize);
655 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytestotal);
656 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesfree);
657 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesavail);
658 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filestotal);
659 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filesfree);
662 * Show whether special failout mode for testing is enabled or not.
664 * \param[in] m seq file
665 * \param[in] v unused for single entry
667 * \retval 0 on success
668 * \retval negative error code if failed
670 static int lod_lmv_failout_seq_show(struct seq_file *m, void *v)
672 struct obd_device *dev = m->private;
673 struct lod_device *lod;
675 LASSERT(dev != NULL);
676 lod = lu2lod_dev(dev->obd_lu_dev);
678 seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0);
683 * Enable/disable a special failout mode for testing.
685 * This determines whether the LMV will try to continue processing a striped
686 * directory even if it has a (partly) corrupted entry in the master directory,
687 * or if it will abort upon finding a corrupted slave directory entry.
689 * \param[in] file proc file
690 * \param[in] buffer string: 0 or non-zero to disable or enable LMV failout
691 * \param[in] count @buffer length
692 * \param[in] off unused for single entry
694 * \retval @count on success
695 * \retval negative error code if failed
698 lod_lmv_failout_seq_write(struct file *file, const char __user *buffer,
699 size_t count, loff_t *off)
701 struct seq_file *m = file->private_data;
702 struct obd_device *dev = m->private;
703 struct lod_device *lod;
707 LASSERT(dev != NULL);
708 lod = lu2lod_dev(dev->obd_lu_dev);
710 rc = lprocfs_write_helper(buffer, count, &val);
715 lod->lod_lmv_failout = 1;
717 lod->lod_lmv_failout = 0;
721 LPROC_SEQ_FOPS(lod_lmv_failout);
723 static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
725 .fops = &lod_uuid_fops },
726 { .name = "stripesize",
727 .fops = &lod_stripesize_fops },
728 { .name = "stripeoffset",
729 .fops = &lod_stripeoffset_fops },
730 { .name = "stripecount",
731 .fops = &lod_stripecount_fops },
732 { .name = "stripetype",
733 .fops = &lod_stripetype_fops },
735 .fops = &lod_numobd_fops },
736 { .name = "activeobd",
737 .fops = &lod_activeobd_fops },
738 { .name = "desc_uuid",
739 .fops = &lod_desc_uuid_fops },
740 { .name = "qos_prio_free",
741 .fops = &lod_qos_priofree_fops },
742 { .name = "qos_threshold_rr",
743 .fops = &lod_qos_thresholdrr_fops },
744 { .name = "qos_maxage",
745 .fops = &lod_qos_maxage_fops },
746 { .name = "lmv_failout",
747 .fops = &lod_lmv_failout_fops },
751 static struct lprocfs_vars lprocfs_lod_osd_vars[] = {
752 { "blocksize", &lod_dt_blksize_fops },
753 { "kbytestotal", &lod_dt_kbytestotal_fops },
754 { "kbytesfree", &lod_dt_kbytesfree_fops },
755 { "kbytesavail", &lod_dt_kbytesavail_fops },
756 { "filestotal", &lod_dt_filestotal_fops },
757 { "filesfree", &lod_dt_filesfree_fops },
761 static const struct file_operations lod_proc_target_fops = {
762 .owner = THIS_MODULE,
763 .open = lod_osts_seq_open,
766 .release = lprocfs_seq_release,
770 * Initialize procfs entries for LOD.
772 * \param[in] lod LOD device
774 * \retval 0 on success
775 * \retval negative error code if failed
777 int lod_procfs_init(struct lod_device *lod)
779 struct obd_device *obd = lod2obd(lod);
780 struct proc_dir_entry *lov_proc_dir = NULL;
781 struct obd_type *type;
784 obd->obd_vars = lprocfs_lod_obd_vars;
785 rc = lprocfs_obd_setup(obd);
787 CERROR("%s: cannot setup procfs entry: %d\n",
792 rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars,
795 CERROR("%s: cannot setup procfs entry: %d\n",
800 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
801 0444, &lod_proc_target_fops, obd);
803 CWARN("%s: Error adding the target_obd file %d\n",
808 lod->lod_pool_proc_entry = lprocfs_register("pools",
811 if (IS_ERR(lod->lod_pool_proc_entry)) {
812 rc = PTR_ERR(lod->lod_pool_proc_entry);
813 lod->lod_pool_proc_entry = NULL;
814 CWARN("%s: Failed to create pool proc file: %d\n",
819 /* If the real LOV is present which is the case for setups
820 * with both server and clients on the same node then use
821 * the LOV's proc root */
822 type = class_search_type(LUSTRE_LOV_NAME);
823 if (type != NULL && type->typ_procroot != NULL)
824 lov_proc_dir = type->typ_procroot;
826 lov_proc_dir = obd->obd_type->typ_procsym;
828 if (lov_proc_dir == NULL)
831 /* for compatibility we link old procfs's LOV entries to lod ones */
832 lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
833 "../lod/%s", obd->obd_name);
834 if (lod->lod_symlink == NULL)
835 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
840 lprocfs_obd_cleanup(obd);
846 * Cleanup procfs entries registred for LOD.
848 * \param[in] lod LOD device
850 void lod_procfs_fini(struct lod_device *lod)
852 struct obd_device *obd = lod2obd(lod);
854 if (lod->lod_symlink != NULL) {
855 lprocfs_remove(&lod->lod_symlink);
856 lod->lod_symlink = NULL;
859 if (lod->lod_pool_proc_entry != NULL) {
860 lprocfs_remove(&lod->lod_pool_proc_entry);
861 lod->lod_pool_proc_entry = NULL;
864 lprocfs_obd_cleanup(obd);
867 #endif /* CONFIG_PROC_FS */