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_str_with_units_to_s64(buffer, count, &val, '1');
104 lod_fix_desc_stripe_size(&val);
105 lod->lod_desc.ld_default_stripe_size = val;
109 LPROC_SEQ_FOPS(lod_stripesize);
112 * Show default stripe offset.
114 * \param[in] m seq file
115 * \param[in] v unused for single entry
117 * \retval 0 on success
118 * \retval negative error code if failed
120 static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
122 struct obd_device *dev = m->private;
123 struct lod_device *lod;
125 LASSERT(dev != NULL);
126 lod = lu2lod_dev(dev->obd_lu_dev);
127 seq_printf(m, LPU64"\n",
128 lod->lod_desc.ld_default_stripe_offset);
133 * Set default stripe offset.
135 * Usually contains -1 allowing Lustre to balance objects among OST
136 * otherwise may cause severe OST imbalance.
138 * \param[in] file proc file
139 * \param[in] buffer string describing starting OST index for new files
140 * \param[in] count @buffer length
141 * \param[in] off unused for single entry
143 * \retval @count on success
144 * \retval negative error code if failed
147 lod_stripeoffset_seq_write(struct file *file, const char __user *buffer,
148 size_t count, loff_t *off)
150 struct seq_file *m = file->private_data;
151 struct obd_device *dev = m->private;
152 struct lod_device *lod;
156 LASSERT(dev != NULL);
157 lod = lu2lod_dev(dev->obd_lu_dev);
158 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
164 lod->lod_desc.ld_default_stripe_offset = val;
168 LPROC_SEQ_FOPS(lod_stripeoffset);
171 * Show default striping pattern (LOV_PATTERN_*).
173 * \param[in] m seq file
174 * \param[in] v unused for single entry
176 * \retval 0 on success
177 * \retval negative error code if failed
179 static int lod_stripetype_seq_show(struct seq_file *m, void *v)
181 struct obd_device *dev = m->private;
182 struct lod_device *lod;
184 LASSERT(dev != NULL);
185 lod = lu2lod_dev(dev->obd_lu_dev);
186 seq_printf(m, "%u\n", lod->lod_desc.ld_pattern);
191 * Set default striping pattern (a number, not a human-readable string).
193 * \param[in] file proc file
194 * \param[in] buffer string containing the default striping pattern for new
195 * files. This is an integer LOV_PATTERN_* value
196 * \param[in] count @buffer length
197 * \param[in] off unused for single entry
199 * \retval @count on success
200 * \retval negative error code if failed
203 lod_stripetype_seq_write(struct file *file, const char __user *buffer,
204 size_t count, loff_t *off)
206 struct seq_file *m = file->private_data;
207 struct obd_device *dev = m->private;
208 struct lod_device *lod;
213 LASSERT(dev != NULL);
214 lod = lu2lod_dev(dev->obd_lu_dev);
215 rc = lprocfs_str_to_s64(buffer, count, &val);
222 lod_fix_desc_pattern(&pattern);
223 lod->lod_desc.ld_pattern = pattern;
227 LPROC_SEQ_FOPS(lod_stripetype);
230 * Show default number of stripes.
232 * \param[in] m seq file
233 * \param[in] v unused for single entry
235 * \retval 0 on success,
236 * \retval negative error code if failed
238 static int lod_stripecount_seq_show(struct seq_file *m, void *v)
240 struct obd_device *dev = m->private;
241 struct lod_device *lod;
243 LASSERT(dev != NULL);
244 lod = lu2lod_dev(dev->obd_lu_dev);
245 seq_printf(m, "%d\n",
246 (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
251 * Set default number of stripes.
253 * \param[in] file proc file
254 * \param[in] buffer string containing the default number of stripes
256 * \param[in] count @buffer length
257 * \param[in] off unused for single entry
259 * \retval @count on success
260 * \retval negative error code otherwise
263 lod_stripecount_seq_write(struct file *file, const char __user *buffer,
264 size_t count, loff_t *off)
266 struct seq_file *m = file->private_data;
267 struct obd_device *dev = m->private;
268 struct lod_device *lod;
273 LASSERT(dev != NULL);
274 lod = lu2lod_dev(dev->obd_lu_dev);
275 rc = lprocfs_str_to_s64(buffer, count, &val);
282 lod_fix_desc_stripe_count(&stripe_count);
283 lod->lod_desc.ld_default_stripe_count = stripe_count;
287 LPROC_SEQ_FOPS(lod_stripecount);
290 * Show number of targets.
292 * \param[in] m seq file
293 * \param[in] v unused for single entry
295 * \retval 0 on success
296 * \retval negative error code if failed
298 static int lod_numobd_seq_show(struct seq_file *m, void *v)
300 struct obd_device *dev = m->private;
301 struct lod_device *lod;
303 LASSERT(dev != NULL);
304 lod = lu2lod_dev(dev->obd_lu_dev);
305 seq_printf(m, "%u\n", lod->lod_desc.ld_tgt_count);
308 LPROC_SEQ_FOPS_RO(lod_numobd);
311 * Show number of active targets.
313 * \param[in] m seq file
314 * \param[in] v unused for single entry
316 * \retval 0 on success
317 * \retval negative error code if failed
319 static int lod_activeobd_seq_show(struct seq_file *m, void *v)
321 struct obd_device *dev = m->private;
322 struct lod_device *lod;
324 LASSERT(dev != NULL);
325 lod = lu2lod_dev(dev->obd_lu_dev);
326 seq_printf(m, "%u\n", lod->lod_desc.ld_active_tgt_count);
329 LPROC_SEQ_FOPS_RO(lod_activeobd);
332 * Show UUID of LOD device.
334 * \param[in] m seq file
335 * \param[in] v unused for single entry
337 * \retval 0 on success
338 * \retval negative error code if failed
340 static int lod_desc_uuid_seq_show(struct seq_file *m, void *v)
342 struct obd_device *dev = m->private;
343 struct lod_device *lod;
345 LASSERT(dev != NULL);
346 lod = lu2lod_dev(dev->obd_lu_dev);
347 seq_printf(m, "%s\n", lod->lod_desc.ld_uuid.uuid);
350 LPROC_SEQ_FOPS_RO(lod_desc_uuid);
353 * Show QoS priority parameter.
355 * The printed value is a percentage value (0-100%) indicating the priority
356 * of free space compared to performance. 0% means select OSTs equally
357 * regardless of their free space, 100% means select OSTs only by their free
358 * space even if it results in very imbalanced load on the OSTs.
360 * \param[in] m seq file
361 * \param[in] v unused for single entry
363 * \retval 0 on success
364 * \retval negative error code if failed
366 static int lod_qos_priofree_seq_show(struct seq_file *m, void *v)
368 struct obd_device *dev = m->private;
369 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
371 LASSERT(lod != NULL);
372 seq_printf(m, "%d%%\n",
373 (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
378 * Set QoS free space priority parameter.
380 * Set the relative priority of free OST space compared to OST load when OSTs
381 * are space imbalanced. See lod_qos_priofree_seq_show() for description of
382 * this parameter. See lod_qos_thresholdrr_seq_write() and lq_threshold_rr to
383 * determine what constitutes "space imbalanced" OSTs.
385 * \param[in] file proc file
386 * \param[in] buffer string which contains the free space priority (0-100)
387 * \param[in] count @buffer length
388 * \param[in] off unused for single entry
390 * \retval @count on success
391 * \retval negative error code if failed
394 lod_qos_priofree_seq_write(struct file *file, const char __user *buffer,
395 size_t count, loff_t *off)
397 struct seq_file *m = file->private_data;
398 struct obd_device *dev = m->private;
399 struct lod_device *lod;
403 LASSERT(dev != NULL);
404 lod = lu2lod_dev(dev->obd_lu_dev);
406 rc = lprocfs_str_to_s64(buffer, count, &val);
410 if (val < 0 || val > 100)
412 lod->lod_qos.lq_prio_free = (val << 8) / 100;
413 lod->lod_qos.lq_dirty = 1;
414 lod->lod_qos.lq_reset = 1;
418 LPROC_SEQ_FOPS(lod_qos_priofree);
421 * Show threshold for "same space on all OSTs" rule.
423 * \param[in] m seq file
424 * \param[in] v unused for single entry
426 * \retval 0 on success
427 * \retval negative error code if failed
429 static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
431 struct obd_device *dev = m->private;
432 struct lod_device *lod;
434 LASSERT(dev != NULL);
435 lod = lu2lod_dev(dev->obd_lu_dev);
436 seq_printf(m, "%d%%\n",
437 (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
442 * Set threshold for "same space on all OSTs" rule.
444 * This sets the maximum percentage difference of free space between the most
445 * full and most empty OST in the currently available OSTs. If this percentage
446 * is exceeded, use the QoS allocator to select OSTs based on their available
447 * space so that more full OSTs are chosen less often, otherwise use the
448 * round-robin allocator for efficiency and performance.
450 * \param[in] file proc file
451 * \param[in] buffer string containing percentage difference of free space
452 * \param[in] count @buffer length
453 * \param[in] off unused for single entry
455 * \retval @count on success
456 * \retval negative error code if failed
459 lod_qos_thresholdrr_seq_write(struct file *file, const char __user *buffer,
460 size_t count, loff_t *off)
462 struct seq_file *m = file->private_data;
463 struct obd_device *dev = m->private;
464 struct lod_device *lod;
468 LASSERT(dev != NULL);
469 lod = lu2lod_dev(dev->obd_lu_dev);
471 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '%');
475 if (val > 100 || val < 0)
478 lod->lod_qos.lq_threshold_rr = (val << 8) / 100;
479 lod->lod_qos.lq_dirty = 1;
483 LPROC_SEQ_FOPS(lod_qos_thresholdrr);
486 * Show expiration period used to refresh cached statfs data, which
487 * is used to implement QoS/RR striping allocation algorithm.
489 * \param[in] m seq file
490 * \param[in] v unused for single entry
492 * \retval 0 on success
493 * \retval negative error code if failed
495 static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
497 struct obd_device *dev = m->private;
498 struct lod_device *lod;
500 LASSERT(dev != NULL);
501 lod = lu2lod_dev(dev->obd_lu_dev);
502 seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
507 * Set expiration period used to refresh cached statfs data.
509 * \param[in] file proc file
510 * \param[in] buffer string contains maximum age of statfs data in seconds
511 * \param[in] count @buffer length
512 * \param[in] off unused for single entry
514 * \retval @count on success
515 * \retval negative error code if failed
518 lod_qos_maxage_seq_write(struct file *file, const char __user *buffer,
519 size_t count, loff_t *off)
521 struct seq_file *m = file->private_data;
522 struct obd_device *dev = m->private;
523 struct lustre_cfg_bufs bufs;
524 struct lod_device *lod;
525 struct lu_device *next;
526 struct lustre_cfg *lcfg;
532 LASSERT(dev != NULL);
533 lod = lu2lod_dev(dev->obd_lu_dev);
535 rc = lprocfs_str_to_s64(buffer, count, &val);
541 lod->lod_desc.ld_qos_maxage = val;
544 * propogate the value down to OSPs
546 lustre_cfg_bufs_reset(&bufs, NULL);
547 snprintf(str, 32, "%smaxage=%u", PARAM_OSP, (__u32)val);
548 lustre_cfg_bufs_set_string(&bufs, 1, str);
549 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
553 lod_getref(&lod->lod_ost_descs);
554 lod_foreach_ost(lod, i) {
555 next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
556 rc = next->ld_ops->ldo_process_config(NULL, next, lcfg);
558 CERROR("can't set maxage on #%d: %d\n", i, rc);
560 lod_putref(lod, &lod->lod_ost_descs);
561 lustre_cfg_free(lcfg);
565 LPROC_SEQ_FOPS(lod_qos_maxage);
567 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
569 struct obd_device *dev = p->private;
570 struct lod_device *lod;
572 LASSERT(dev != NULL);
573 lod = lu2lod_dev(dev->obd_lu_dev);
575 lod_getref(&lod->lod_ost_descs); /* released in lod_osts_seq_stop */
576 if (*pos >= lod->lod_ost_bitmap->size)
579 *pos = find_next_bit(lod->lod_ost_bitmap->data,
580 lod->lod_ost_bitmap->size, *pos);
581 if (*pos < lod->lod_ost_bitmap->size)
582 return OST_TGT(lod,*pos);
587 static void lod_osts_seq_stop(struct seq_file *p, void *v)
589 struct obd_device *dev = p->private;
590 struct lod_device *lod;
592 LASSERT(dev != NULL);
593 lod = lu2lod_dev(dev->obd_lu_dev);
594 lod_putref(lod, &lod->lod_ost_descs);
597 static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
599 struct obd_device *dev = p->private;
600 struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
602 if (*pos >= lod->lod_ost_bitmap->size - 1)
605 *pos = find_next_bit(lod->lod_ost_bitmap->data,
606 lod->lod_ost_bitmap->size, *pos + 1);
607 if (*pos < lod->lod_ost_bitmap->size)
608 return OST_TGT(lod,*pos);
614 * Show active/inactive status for OST found by lod_osts_seq_next().
616 * \param[in] m seq file
617 * \param[in] v unused for single entry
619 * \retval 0 on success
620 * \retval negative error code if failed
622 static int lod_osts_seq_show(struct seq_file *p, void *v)
624 struct obd_device *obd = p->private;
625 struct lod_ost_desc *ost_desc = v;
626 struct lod_device *lod;
628 struct dt_device *next;
629 struct obd_statfs sfs;
631 LASSERT(obd->obd_lu_dev);
632 lod = lu2lod_dev(obd->obd_lu_dev);
634 idx = ost_desc->ltd_index;
635 next = OST_TGT(lod,idx)->ltd_ost;
639 /* XXX: should be non-NULL env, but it's very expensive */
641 rc = dt_statfs(NULL, next, &sfs);
642 if (rc == -ENOTCONN) {
648 seq_printf(p, "%d: %s %sACTIVE\n", idx,
649 obd_uuid2str(&ost_desc->ltd_uuid),
654 static const struct seq_operations lod_osts_sops = {
655 .start = lod_osts_seq_start,
656 .stop = lod_osts_seq_stop,
657 .next = lod_osts_seq_next,
658 .show = lod_osts_seq_show,
661 static int lod_osts_seq_open(struct inode *inode, struct file *file)
663 struct seq_file *seq;
666 rc = seq_open(file, &lod_osts_sops);
670 seq = file->private_data;
671 seq->private = PDE_DATA(inode);
675 LPROC_SEQ_FOPS_RO_TYPE(lod, uuid);
677 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_blksize);
678 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytestotal);
679 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesfree);
680 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesavail);
681 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filestotal);
682 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filesfree);
685 * Show whether special failout mode for testing is enabled or not.
687 * \param[in] m seq file
688 * \param[in] v unused for single entry
690 * \retval 0 on success
691 * \retval negative error code if failed
693 static int lod_lmv_failout_seq_show(struct seq_file *m, void *v)
695 struct obd_device *dev = m->private;
696 struct lod_device *lod;
698 LASSERT(dev != NULL);
699 lod = lu2lod_dev(dev->obd_lu_dev);
701 seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0);
706 * Enable/disable a special failout mode for testing.
708 * This determines whether the LMV will try to continue processing a striped
709 * directory even if it has a (partly) corrupted entry in the master directory,
710 * or if it will abort upon finding a corrupted slave directory entry.
712 * \param[in] file proc file
713 * \param[in] buffer string: 0 or non-zero to disable or enable LMV failout
714 * \param[in] count @buffer length
715 * \param[in] off unused for single entry
717 * \retval @count on success
718 * \retval negative error code if failed
721 lod_lmv_failout_seq_write(struct file *file, const char __user *buffer,
722 size_t count, loff_t *off)
724 struct seq_file *m = file->private_data;
725 struct obd_device *dev = m->private;
726 struct lod_device *lod;
730 LASSERT(dev != NULL);
731 lod = lu2lod_dev(dev->obd_lu_dev);
733 rc = lprocfs_str_to_s64(buffer, count, &val);
737 lod->lod_lmv_failout = !!val;
741 LPROC_SEQ_FOPS(lod_lmv_failout);
743 static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
745 .fops = &lod_uuid_fops },
746 { .name = "stripesize",
747 .fops = &lod_stripesize_fops },
748 { .name = "stripeoffset",
749 .fops = &lod_stripeoffset_fops },
750 { .name = "stripecount",
751 .fops = &lod_stripecount_fops },
752 { .name = "stripetype",
753 .fops = &lod_stripetype_fops },
755 .fops = &lod_numobd_fops },
756 { .name = "activeobd",
757 .fops = &lod_activeobd_fops },
758 { .name = "desc_uuid",
759 .fops = &lod_desc_uuid_fops },
760 { .name = "qos_prio_free",
761 .fops = &lod_qos_priofree_fops },
762 { .name = "qos_threshold_rr",
763 .fops = &lod_qos_thresholdrr_fops },
764 { .name = "qos_maxage",
765 .fops = &lod_qos_maxage_fops },
766 { .name = "lmv_failout",
767 .fops = &lod_lmv_failout_fops },
771 static struct lprocfs_vars lprocfs_lod_osd_vars[] = {
772 { "blocksize", &lod_dt_blksize_fops },
773 { "kbytestotal", &lod_dt_kbytestotal_fops },
774 { "kbytesfree", &lod_dt_kbytesfree_fops },
775 { "kbytesavail", &lod_dt_kbytesavail_fops },
776 { "filestotal", &lod_dt_filestotal_fops },
777 { "filesfree", &lod_dt_filesfree_fops },
781 static const struct file_operations lod_proc_target_fops = {
782 .owner = THIS_MODULE,
783 .open = lod_osts_seq_open,
786 .release = lprocfs_seq_release,
790 * Initialize procfs entries for LOD.
792 * \param[in] lod LOD device
794 * \retval 0 on success
795 * \retval negative error code if failed
797 int lod_procfs_init(struct lod_device *lod)
799 struct obd_device *obd = lod2obd(lod);
800 struct proc_dir_entry *lov_proc_dir = NULL;
801 struct obd_type *type;
804 obd->obd_vars = lprocfs_lod_obd_vars;
805 rc = lprocfs_obd_setup(obd);
807 CERROR("%s: cannot setup procfs entry: %d\n",
812 rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars,
815 CERROR("%s: cannot setup procfs entry: %d\n",
820 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
821 0444, &lod_proc_target_fops, obd);
823 CWARN("%s: Error adding the target_obd file %d\n",
828 lod->lod_pool_proc_entry = lprocfs_register("pools",
831 if (IS_ERR(lod->lod_pool_proc_entry)) {
832 rc = PTR_ERR(lod->lod_pool_proc_entry);
833 lod->lod_pool_proc_entry = NULL;
834 CWARN("%s: Failed to create pool proc file: %d\n",
839 /* If the real LOV is present which is the case for setups
840 * with both server and clients on the same node then use
841 * the LOV's proc root */
842 type = class_search_type(LUSTRE_LOV_NAME);
843 if (type != NULL && type->typ_procroot != NULL)
844 lov_proc_dir = type->typ_procroot;
846 lov_proc_dir = obd->obd_type->typ_procsym;
848 if (lov_proc_dir == NULL)
851 /* for compatibility we link old procfs's LOV entries to lod ones */
852 lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
853 "../lod/%s", obd->obd_name);
854 if (lod->lod_symlink == NULL)
855 CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
860 lprocfs_obd_cleanup(obd);
866 * Cleanup procfs entries registred for LOD.
868 * \param[in] lod LOD device
870 void lod_procfs_fini(struct lod_device *lod)
872 struct obd_device *obd = lod2obd(lod);
874 if (lod->lod_symlink != NULL) {
875 lprocfs_remove(&lod->lod_symlink);
876 lod->lod_symlink = NULL;
879 if (lod->lod_pool_proc_entry != NULL) {
880 lprocfs_remove(&lod->lod_pool_proc_entry);
881 lod->lod_pool_proc_entry = NULL;
884 lprocfs_obd_cleanup(obd);
887 #endif /* CONFIG_PROC_FS */