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 (c) 2007, 2010, Oracle and/or its affiliates. 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 * lustre/osp/lproc_osp.c
33 * Lustre OST Proxy Device (OSP), procfs functions
35 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
38 #define DEBUG_SUBSYSTEM S_CLASS
40 #include "osp_internal.h"
43 * Show OSP active status
45 * \param[in] m seq_file handle
46 * \param[in] data unused for single entry
47 * \retval 0 on success
48 * \retval negative number on error
50 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
53 struct dt_device *dt = container_of(kobj, struct dt_device,
55 struct lu_device *lu = dt2lu_dev(dt);
56 struct obd_device *obd = lu->ld_obd;
57 struct obd_import *imp;
60 with_imp_locked(obd, imp, rc)
61 rc = sprintf(buf, "%d\n", !imp->imp_deactive);
66 * Activate/Deactivate OSP
68 * \param[in] file proc file
69 * \param[in] buffer string, which is "1" or "0" to activate/deactivate OSP
70 * \param[in] count \a buffer length
71 * \param[in] off unused for single entry
72 * \retval \a count on success
73 * \retval negative number on error
75 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
76 const char *buffer, size_t count)
78 struct dt_device *dt = container_of(kobj, struct dt_device,
80 struct lu_device *lu = dt2lu_dev(dt);
81 struct obd_device *obd = lu->ld_obd;
82 struct obd_import *imp, *imp0;
86 rc = kstrtobool(buffer, &val);
90 with_imp_locked(obd, imp0, rc)
91 imp = class_import_get(imp0);
95 if (imp->imp_deactive == val)
96 rc = ptlrpc_set_import_active(imp, val);
98 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
101 class_import_put(imp);
105 LUSTRE_RW_ATTR(active);
108 * Show number of RPCs in flight
110 * \param[in] m seq_file handle
111 * \param[in] data unused for single entry
112 * \retval 0 on success
113 * \retval negative number on error
115 static ssize_t sync_in_flight_show(struct kobject *kobj,
116 struct attribute *attr,
119 struct dt_device *dt = container_of(kobj, struct dt_device,
121 struct osp_device *osp = dt2osp_dev(dt);
123 return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_flight));
125 LUSTRE_RO_ATTR(sync_in_flight);
128 * Show number of RPCs in processing (including uncommitted by OST)
130 * \param[in] m seq_file handle
131 * \param[in] data unused for single entry
132 * \retval 0 on success
133 * \retval negative number on error
135 static ssize_t sync_in_progress_show(struct kobject *kobj,
136 struct attribute *attr,
139 struct dt_device *dt = container_of(kobj, struct dt_device,
141 struct osp_device *osp = dt2osp_dev(dt);
143 return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_progress));
145 LUSTRE_RO_ATTR(sync_in_progress);
148 * Show number of changes to sync
150 * \param[in] m seq_file handle
151 * \param[in] data unused for single entry
152 * \retval 0 on success
153 * \retval negative number on error
155 static ssize_t sync_changes_show(struct kobject *kobj,
156 struct attribute *attr,
159 struct dt_device *dt = container_of(kobj, struct dt_device,
161 struct osp_device *osp = dt2osp_dev(dt);
163 return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_changes));
169 * \param[in] file proc file
170 * \param[in] buffer unused because any input will do
171 * \param[in] count \a buffer length
172 * \param[in] off unused for single entry
173 * \retval \a count on success
174 * \retval negative number on error
176 static ssize_t sync_changes_store(struct kobject *kobj, struct attribute *attr,
177 const char *buffer, size_t count)
179 struct dt_device *dt = container_of(kobj, struct dt_device,
181 struct osp_device *osp = dt2osp_dev(dt);
185 rc = lu_env_init(&env, LCT_LOCAL);
189 rc = dt_sync(&env, &osp->opd_dt_dev);
192 return rc == 0 ? count : rc;
194 LUSTRE_RW_ATTR(sync_changes);
196 static ssize_t max_sync_changes_show(struct kobject *kobj,
197 struct attribute *attr,
200 struct dt_device *dt = container_of(kobj, struct dt_device,
202 struct osp_device *osp = dt2osp_dev(dt);
204 return sprintf(buf, "%u\n", osp->opd_sync_max_changes);
208 static ssize_t max_sync_changes_store(struct kobject *kobj,
209 struct attribute *attr,
210 const char *buffer, size_t count)
212 struct dt_device *dt = container_of(kobj, struct dt_device,
214 struct osp_device *osp = dt2osp_dev(dt);
218 rc = kstrtoint(buffer, 0, &val);
223 osp->opd_sync_max_changes = val;
227 LUSTRE_RW_ATTR(max_sync_changes);
230 * Show maximum number of RPCs in flight allowed
232 * \param[in] m seq_file handle
233 * \param[in] data unused for single entry
234 * \retval 0 on success
235 * \retval negative number on error
237 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
238 struct attribute *attr,
241 struct dt_device *dt = container_of(kobj, struct dt_device,
243 struct osp_device *osp = dt2osp_dev(dt);
245 return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_flight);
249 * Change maximum number of RPCs in flight allowed
251 * \param[in] file proc file
252 * \param[in] buffer string which represents maximum number
253 * \param[in] count \a buffer length
254 * \param[in] off unused for single entry
255 * \retval \a count on success
256 * \retval negative number on error
258 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
259 struct attribute *attr,
263 struct dt_device *dt = container_of(kobj, struct dt_device,
265 struct osp_device *osp = dt2osp_dev(dt);
269 rc = kstrtouint(buffer, 0, &val);
276 osp->opd_sync_max_rpcs_in_flight = val;
279 LUSTRE_RW_ATTR(max_rpcs_in_flight);
281 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
282 struct attribute *attr,
285 struct dt_device *dt = container_of(kobj, struct dt_device,
287 struct lu_device *lu = dt2lu_dev(dt);
288 struct obd_device *obd = lu->ld_obd;
291 max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
292 return scnprintf(buf, PAGE_SIZE, "%hu\n", max);
295 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
296 struct attribute *attr,
300 struct dt_device *dt = container_of(kobj, struct dt_device,
302 struct lu_device *lu = dt2lu_dev(dt);
303 struct obd_device *obd = lu->ld_obd;
307 rc = kstrtou16(buffer, 10, &val);
311 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
317 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
320 * Show maximum number of RPCs in processing allowed
322 * \param[in] m seq_file handle
323 * \param[in] data unused
324 * \retval 0 on success
325 * \retval negative number on error
327 static ssize_t max_rpcs_in_progress_show(struct kobject *kobj,
328 struct attribute *attr,
331 struct dt_device *dt = container_of(kobj, struct dt_device,
333 struct osp_device *osp = dt2osp_dev(dt);
335 return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_progress);
339 * Change maximum number of RPCs in processing allowed
341 * \param[in] file proc file
342 * \param[in] buffer string which represents maximum number
343 * \param[in] count \a buffer length
344 * \param[in] off unused for single entry
345 * \retval \a count on success
346 * \retval negative number on error
348 static ssize_t max_rpcs_in_progress_store(struct kobject *kobj,
349 struct attribute *attr,
353 struct dt_device *dt = container_of(kobj, struct dt_device,
355 struct osp_device *osp = dt2osp_dev(dt);
359 rc = kstrtouint(buffer, 0, &val);
366 osp->opd_sync_max_rpcs_in_progress = val;
370 LUSTRE_RW_ATTR(max_rpcs_in_progress);
373 * Show number of objects to precreate next time
375 * \param[in] m seq_file handle
376 * \param[in] data unused for single entry
377 * \retval 0 on success
378 * \retval negative number on error
380 static ssize_t create_count_show(struct kobject *kobj,
381 struct attribute *attr,
384 struct dt_device *dt = container_of(kobj, struct dt_device,
386 struct osp_device *osp = dt2osp_dev(dt);
391 return sprintf(buf, "%d\n", osp->opd_pre_create_count);
395 * Change number of objects to precreate next time
397 * \param[in] file proc file
398 * \param[in] buffer string which represents number of objects to precreate
399 * \param[in] count \a buffer length
400 * \param[in] off unused for single entry
401 * \retval \a count on success
402 * \retval negative number on error
404 static ssize_t create_count_store(struct kobject *kobj, struct attribute *attr,
405 const char *buffer, size_t count)
407 struct dt_device *dt = container_of(kobj, struct dt_device,
409 struct osp_device *osp = dt2osp_dev(dt);
416 rc = kstrtouint(buffer, 0, &val);
420 /* The MDT ALWAYS needs to limit the precreate count to
421 * OST_MAX_PRECREATE, and the constant cannot be changed
422 * because it is a value shared between the OSP and OST
423 * that is the maximum possible number of objects that will
424 * ever be handled by MDT->OST recovery processing.
426 * The OSP enforces the pre_create_count to amaximum of
427 * one half of opd_pre_max_create_count.
429 * If the OST ever gets a request to delete more orphans,
430 * this implies that something has gone badly on the MDT
431 * and the OST will refuse to delete so much data from the
432 * filesystem as a safety measure.
434 if (val < OST_MIN_PRECREATE)
436 if (val > osp->opd_pre_max_create_count / 2)
437 val = osp->opd_pre_max_create_count / 2;
439 /* set to largest value <= 32, 64, 128 or a multiple of 256 */
441 osp->opd_pre_create_count = val & 0xffffff00;
443 osp->opd_pre_create_count = rounddown_pow_of_two(val);
447 LUSTRE_RW_ATTR(create_count);
450 * Show maximum number of objects to precreate
452 * \param[in] m seq_file handle
453 * \param[in] data unused for single entry
454 * \retval 0 on success
455 * \retval negative number on error
457 static ssize_t max_create_count_show(struct kobject *kobj,
458 struct attribute *attr,
461 struct dt_device *dt = container_of(kobj, struct dt_device,
463 struct osp_device *osp = dt2osp_dev(dt);
468 return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
472 * Change maximum number of objects to precreate
474 * \param[in] file proc file
475 * \param[in] buffer string which represents maximum number
476 * \param[in] count \a buffer length
477 * \param[in] off unused for single entry
478 * \retval \a count on success
479 * \retval negative number on error
481 static ssize_t max_create_count_store(struct kobject *kobj,
482 struct attribute *attr,
483 const char *buffer, size_t count)
485 struct dt_device *dt = container_of(kobj, struct dt_device,
487 struct osp_device *osp = dt2osp_dev(dt);
494 rc = kstrtouint(buffer, 0, &val);
498 if (val && (val < OST_MIN_PRECREATE ||
499 val > OST_MAX_PRECREATE))
502 if (osp->opd_pre_create_count > val)
503 osp->opd_pre_create_count = val;
505 /* Can be 0 after setting max_create_count to 0 */
506 if (osp->opd_pre_create_count == 0 && val != 0)
507 osp->opd_pre_create_count = OST_MIN_PRECREATE;
509 osp->opd_pre_max_create_count = val;
513 LUSTRE_RW_ATTR(max_create_count);
516 * Show last id to assign in creation
518 * \param[in] m seq_file handle
519 * \param[in] data unused for single entry
520 * \retval 0 on success
521 * \retval negative number on error
523 static ssize_t prealloc_next_id_show(struct kobject *kobj,
524 struct attribute *attr,
527 struct dt_device *dt = container_of(kobj, struct dt_device,
529 struct osp_device *osp = dt2osp_dev(dt);
537 fid = &osp->opd_pre_used_fid;
538 seq_width = osp->opd_pre_seq_width;
539 if (fid_is_idif(fid)) {
540 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
541 if (unlikely(id >= min(IDIF_MAX_OID, seq_width)))
546 id = unlikely(fid_oid(fid) >= min(OBIF_MAX_OID, seq_width)) ?
547 1 : fid_oid(fid) + 1;
550 return sprintf(buf, "%llu\n", id);
552 LUSTRE_RO_ATTR(prealloc_next_id);
555 * Show last created id OST reported
557 * \param[in] m seq_file handle
558 * \param[in] data unused for single entry
559 * \retval 0 on success
560 * \retval negative number on error
563 static ssize_t prealloc_last_id_show(struct kobject *kobj,
564 struct attribute *attr,
567 struct dt_device *dt = container_of(kobj, struct dt_device,
569 struct osp_device *osp = dt2osp_dev(dt);
576 fid = &osp->opd_pre_last_created_fid;
577 id = fid_is_idif(fid) ?
578 fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
581 return sprintf(buf, "%llu\n", id);
583 LUSTRE_RO_ATTR(prealloc_last_id);
586 * Show next FID sequence to precreate
588 * \param[in] m seq_file handle
589 * \param[in] data unused for single entry
590 * \retval 0 on success
591 * \retval negative number on error
593 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
594 struct attribute *attr,
597 struct dt_device *dt = container_of(kobj, struct dt_device,
599 struct osp_device *osp = dt2osp_dev(dt);
605 fid = &osp->opd_pre_used_fid;
606 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
607 fid_seq(fid) & (~0xffff) : fid_seq(fid));
609 LUSTRE_RO_ATTR(prealloc_next_seq);
612 * Show last created FID sequence OST reported
614 * \param[in] m seq_file handle
615 * \param[in] data unused for single entry
616 * \retval 0 on success
617 * \retval negative number on error
619 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
620 struct attribute *attr,
623 struct dt_device *dt = container_of(kobj, struct dt_device,
625 struct osp_device *osp = dt2osp_dev(dt);
631 fid = &osp->opd_pre_last_created_fid;
632 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
633 fid_seq(fid) & (~0xffff) : fid_seq(fid));
635 LUSTRE_RO_ATTR(prealloc_last_seq);
638 * Show the number of ids reserved by declare
640 * \param[in] m seq_file handle
641 * \param[in] data unused for single entry
642 * \retval 0 on success
643 * \retval negative number on error
645 static ssize_t prealloc_reserved_show(struct kobject *kobj,
646 struct attribute *attr,
649 struct dt_device *dt = container_of(kobj, struct dt_device,
651 struct osp_device *osp = dt2osp_dev(dt);
656 return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
658 LUSTRE_RO_ATTR(prealloc_reserved);
661 * Show interval (in seconds) to update statfs data
663 * \param[in] m seq_file handle
664 * \param[in] data unused for single entry
665 * \retval 0 on success
666 * \retval negative number on error
668 static ssize_t maxage_show(struct kobject *kobj,
669 struct attribute *attr,
672 struct dt_device *dt = container_of(kobj, struct dt_device,
674 struct osp_device *osp = dt2osp_dev(dt);
676 return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
680 * Change interval to update statfs data
682 * \param[in] file proc file
683 * \param[in] buffer string which represents statfs interval (in seconds)
684 * \param[in] count \a buffer length
685 * \param[in] off unused for single entry
686 * \retval \a count on success
687 * \retval negative number on error
689 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
690 const char *buffer, size_t count)
692 struct dt_device *dt = container_of(kobj, struct dt_device,
694 struct osp_device *osp = dt2osp_dev(dt);
698 rc = kstrtouint(buffer, 0, &val);
705 osp->opd_statfs_maxage = val;
709 LUSTRE_RW_ATTR(maxage);
712 * Show current precreation status: output 0 means success, otherwise negative
715 * \param[in] m seq_file handle
716 * \param[in] data unused for single entry
717 * \retval 0 on success
718 * \retval negative number on error
720 static ssize_t prealloc_status_show(struct kobject *kobj,
721 struct attribute *attr,
724 struct dt_device *dt = container_of(kobj, struct dt_device,
726 struct osp_device *osp = dt2osp_dev(dt);
731 return sprintf(buf, "%d\n", osp->opd_pre_status);
733 LUSTRE_RO_ATTR(prealloc_status);
736 * Show the number of RPCs in processing (including uncommitted by OST) plus
737 * changes to sync, i.e. this is the total number of changes OST needs to apply
740 * This counter is used to determine if OST has space returned. A zero value
741 * indicates that OST storage space consumed by destroyed objects has been freed
742 * on disk, the associated llog records have been cleared, and no synchronous
743 * RPC are being processed.
745 * \param[in] m seq_file handle
746 * \param[in] data unused for single entry
747 * \retval 0 on success
748 * \retval negative number on error
750 static ssize_t destroys_in_flight_show(struct kobject *kobj,
751 struct attribute *attr,
754 struct dt_device *dt = container_of(kobj, struct dt_device,
756 struct osp_device *osp = dt2osp_dev(dt);
758 return sprintf(buf, "%u\n",
759 atomic_read(&osp->opd_sync_rpcs_in_progress) +
760 atomic_read(&osp->opd_sync_changes));
762 LUSTRE_RO_ATTR(destroys_in_flight);
765 * Show changes synced from previous mount
767 * \param[in] m seq_file handle
768 * \param[in] data unused for single entry
769 * \retval 0 on success
770 * \retval negative number on error
772 static ssize_t old_sync_processed_show(struct kobject *kobj,
773 struct attribute *attr,
776 struct dt_device *dt = container_of(kobj, struct dt_device,
778 struct osp_device *osp = dt2osp_dev(dt);
780 return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
782 LUSTRE_RO_ATTR(old_sync_processed);
785 * Show maximum number of RPCs in flight
787 * \param[in] m seq_file handle
788 * \param[in] data unused for single entry
789 * \retval 0 on success
790 * \retval negative number on error
792 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
793 struct attribute *attr,
796 struct dt_device *dt = container_of(kobj, struct dt_device,
798 struct lu_device *lu = dt2lu_dev(dt);
799 struct obd_device *obd = lu->ld_obd;
802 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
803 return sprintf(buf, "%u\n", max);
807 * Change maximum number of RPCs in flight
809 * \param[in] file proc file
810 * \param[in] buffer string which represents maximum number of RPCs in flight
811 * \param[in] count \a buffer length
812 * \param[in] off unused for single entry
813 * \retval \a count on success
814 * \retval negative number on error
816 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
817 struct attribute *attr,
821 struct dt_device *dt = container_of(kobj, struct dt_device,
823 struct lu_device *lu = dt2lu_dev(dt);
824 struct obd_device *obd = lu->ld_obd;
828 rc = kstrtouint(buffer, 0, &val);
832 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
833 return rc ? rc : count;
835 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
837 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
840 struct dt_device *dt = container_of(kobj, struct dt_device,
842 struct lu_device *lu = dt2lu_dev(dt);
843 struct obd_device *obd = lu->ld_obd;
846 rc = ptlrpc_obd_ping(obd);
850 LUSTRE_RO_ATTR(ping);
852 static ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
855 struct dt_device *dt = container_of(kobj, struct dt_device,
857 struct lu_device *lu = dt2lu_dev(dt);
858 struct obd_device *obd = lu->ld_obd;
859 struct obd_import *imp;
860 struct ptlrpc_connection *conn;
863 with_imp_locked(obd, imp, count) {
864 conn = imp->imp_connection;
866 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
868 count = sprintf(buf, "%s\n", "<none>");
874 LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
875 LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
877 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
878 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
879 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
881 LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
882 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
884 static int osp_rpc_stats_seq_show(struct seq_file *seq, void *v)
886 struct obd_device *dev = seq->private;
888 return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
891 static ssize_t osp_rpc_stats_seq_write(struct file *file,
892 const char __user *buf,
893 size_t len, loff_t *off)
895 struct seq_file *seq = file->private_data;
896 struct obd_device *dev = seq->private;
897 struct client_obd *cli = &dev->u.cli;
899 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
900 cli->cl_mod_rpcs_init = ktime_get_real();
904 LDEBUGFS_SEQ_FOPS(osp_rpc_stats);
907 * Show high watermark (in megabytes). If available free space at OST is greater
908 * than high watermark and object allocation for OST is disabled, enable it.
910 static ssize_t reserved_mb_high_show(struct kobject *kobj,
911 struct attribute *attr,
914 struct dt_device *dt = container_of(kobj, struct dt_device,
916 struct osp_device *osp = dt2osp_dev(dt);
918 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_high);
922 * Change high watermark
924 static ssize_t reserved_mb_high_store(struct kobject *kobj,
925 struct attribute *attr,
929 struct dt_device *dt = container_of(kobj, struct dt_device,
931 struct osp_device *osp = dt2osp_dev(dt);
935 rc = sysfs_memparse(buffer, count, &val, "MiB");
942 spin_lock(&osp->opd_pre_lock);
943 osp->opd_reserved_mb_high = val;
944 if (val <= osp->opd_reserved_mb_low)
945 osp->opd_reserved_mb_low = val - 1;
946 spin_unlock(&osp->opd_pre_lock);
950 LUSTRE_RW_ATTR(reserved_mb_high);
953 * Show low watermark (in megabytes). If available free space at OST is less
954 * than low watermark, object allocation for OST is disabled.
956 static ssize_t reserved_mb_low_show(struct kobject *kobj,
957 struct attribute *attr,
960 struct dt_device *dt = container_of(kobj, struct dt_device,
962 struct osp_device *osp = dt2osp_dev(dt);
964 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_low);
968 * Change low watermark
970 static ssize_t reserved_mb_low_store(struct kobject *kobj,
971 struct attribute *attr,
975 struct dt_device *dt = container_of(kobj, struct dt_device,
977 struct osp_device *osp = dt2osp_dev(dt);
981 rc = sysfs_memparse(buffer, count, &val, "MiB");
986 spin_lock(&osp->opd_pre_lock);
987 osp->opd_reserved_mb_low = val;
988 if (val >= osp->opd_reserved_mb_high)
989 osp->opd_reserved_mb_high = val + 1;
990 spin_unlock(&osp->opd_pre_lock);
994 LUSTRE_RW_ATTR(reserved_mb_low);
997 * Show high watermark of inode.
999 static ssize_t reserved_ino_high_show(struct kobject *kobj,
1000 struct attribute *attr,
1003 struct dt_device *dt = container_of(kobj, struct dt_device,
1005 struct osp_device *osp = dt2osp_dev(dt);
1007 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_high);
1011 * Change high watermark of inode.
1013 static ssize_t reserved_ino_high_store(struct kobject *kobj,
1014 struct attribute *attr,
1018 struct dt_device *dt = container_of(kobj, struct dt_device,
1020 struct osp_device *osp = dt2osp_dev(dt);
1024 rc = kstrtouint(buffer, 0, &val);
1030 spin_lock(&osp->opd_pre_lock);
1031 osp->opd_reserved_ino_high = val;
1032 if (val <= osp->opd_reserved_ino_low)
1033 osp->opd_reserved_ino_low = val >> 1;
1034 spin_unlock(&osp->opd_pre_lock);
1038 LUSTRE_RW_ATTR(reserved_ino_high);
1041 * Show low watermark.
1043 static ssize_t reserved_ino_low_show(struct kobject *kobj,
1044 struct attribute *attr,
1047 struct dt_device *dt = container_of(kobj, struct dt_device,
1049 struct osp_device *osp = dt2osp_dev(dt);
1051 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_low);
1055 * Change low watermark
1057 static ssize_t reserved_ino_low_store(struct kobject *kobj,
1058 struct attribute *attr,
1062 struct dt_device *dt = container_of(kobj, struct dt_device,
1064 struct osp_device *osp = dt2osp_dev(dt);
1068 rc = kstrtouint(buffer, 0, &val);
1072 if (val & (1UL << 31))
1075 spin_lock(&osp->opd_pre_lock);
1076 osp->opd_reserved_ino_low = val;
1077 if (val >= osp->opd_reserved_ino_high)
1078 osp->opd_reserved_ino_high = val << 1;
1079 spin_unlock(&osp->opd_pre_lock);
1083 LUSTRE_RW_ATTR(reserved_ino_low);
1085 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
1086 const char *buffer, size_t count)
1088 struct dt_device *dt = container_of(kobj, struct dt_device,
1093 rc = lu_env_init(&env, LCT_LOCAL);
1097 rc = dt_sync(&env, dt);
1100 return rc == 0 ? count : rc;
1102 LUSTRE_WO_ATTR(force_sync);
1104 static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
1105 { .name = "connect_flags",
1106 .fops = &osp_connect_flags_fops },
1107 { .name = "ost_server_uuid",
1108 .fops = &osp_server_uuid_fops },
1109 { .name = "timeouts",
1110 .fops = &osp_timeouts_fops },
1112 .fops = &osp_import_fops },
1114 .fops = &osp_state_fops },
1118 static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
1119 { .name = "connect_flags",
1120 .fops = &osp_connect_flags_fops },
1121 { .name = "mdt_server_uuid",
1122 .fops = &osp_server_uuid_fops },
1123 { .name = "timeouts",
1124 .fops = &osp_timeouts_fops },
1126 .fops = &osp_import_fops },
1128 .fops = &osp_state_fops },
1129 { .name = "rpc_stats",
1130 .fops = &osp_rpc_stats_fops },
1134 static struct attribute *osp_obd_attrs[] = {
1135 /* First two for compatiability reasons */
1136 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1137 &lustre_attr_destroys_in_flight.attr,
1138 &lustre_attr_active.attr,
1139 &lustre_attr_max_rpcs_in_flight.attr,
1140 &lustre_attr_max_rpcs_in_progress.attr,
1141 &lustre_attr_maxage.attr,
1142 &lustre_attr_ost_conn_uuid.attr,
1143 &lustre_attr_ping.attr,
1144 &lustre_attr_prealloc_status.attr,
1145 &lustre_attr_prealloc_next_id.attr,
1146 &lustre_attr_prealloc_last_id.attr,
1147 &lustre_attr_prealloc_next_seq.attr,
1148 &lustre_attr_prealloc_last_seq.attr,
1149 &lustre_attr_prealloc_reserved.attr,
1150 &lustre_attr_sync_in_flight.attr,
1151 &lustre_attr_sync_in_progress.attr,
1152 &lustre_attr_sync_changes.attr,
1153 &lustre_attr_max_sync_changes.attr,
1154 &lustre_attr_force_sync.attr,
1155 &lustre_attr_old_sync_processed.attr,
1156 &lustre_attr_create_count.attr,
1157 &lustre_attr_max_create_count.attr,
1158 &lustre_attr_reserved_mb_high.attr,
1159 &lustre_attr_reserved_mb_low.attr,
1160 &lustre_attr_reserved_ino_high.attr,
1161 &lustre_attr_reserved_ino_low.attr,
1165 KOBJ_ATTRIBUTE_GROUPS(osp_obd); /* creates osp_obd_groups from osp_obd_attrs */
1167 static struct attribute *osp_md_attrs[] = {
1168 /* First two for compatiability reasons */
1169 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1170 &lustre_attr_destroys_in_flight.attr,
1171 &lustre_attr_active.attr,
1172 &lustre_attr_max_rpcs_in_flight.attr,
1173 &lustre_attr_max_mod_rpcs_in_flight.attr,
1174 &lustre_attr_max_rpcs_in_progress.attr,
1175 &lustre_attr_maxage.attr,
1176 &lustre_attr_mdt_conn_uuid.attr,
1177 &lustre_attr_ping.attr,
1178 &lustre_attr_prealloc_status.attr,
1179 &lustre_attr_reserved_mb_high.attr,
1180 &lustre_attr_reserved_mb_low.attr,
1181 &lustre_attr_reserved_ino_high.attr,
1182 &lustre_attr_reserved_ino_low.attr,
1186 KOBJ_ATTRIBUTE_GROUPS(osp_md); /* creates osp_md_groups from osp_md_attrs */
1188 void osp_tunables_fini(struct osp_device *osp)
1190 struct obd_device *obd = osp->opd_obd;
1191 struct kobject *osc;
1193 osc = kset_find_obj(lustre_kset, "osc");
1195 sysfs_remove_link(osc, obd->obd_name);
1199 debugfs_remove_recursive(osp->opd_debugfs);
1200 osp->opd_debugfs = NULL;
1202 ptlrpc_lprocfs_unregister_obd(obd);
1204 debugfs_remove_recursive(obd->obd_debugfs_entry);
1205 obd->obd_debugfs_entry = NULL;
1207 dt_tunables_fini(&osp->opd_dt_dev);
1211 * Initialize OSP sysfs / debugfs
1213 * param[in] osp OSP device
1215 void osp_tunables_init(struct osp_device *osp)
1217 struct obd_device *obd = osp->opd_obd;
1218 struct kobject *osc;
1221 if (osp->opd_connect_mdt) {
1222 osp->opd_dt_dev.dd_ktype.default_groups =
1223 KOBJ_ATTR_GROUPS(osp_md);
1224 obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
1226 osp->opd_dt_dev.dd_ktype.default_groups =
1227 KOBJ_ATTR_GROUPS(osp_obd);
1228 obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
1231 rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
1234 CERROR("%s: failed to setup DT tunables: %d\n",
1239 /* Since we register the obd device with ptlrpc / sptlrpc we
1240 * have to register debugfs with obd_device
1242 obd->obd_debugfs_entry = debugfs_create_dir(
1243 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1244 ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
1246 sptlrpc_lprocfs_cliobd_attach(obd);
1247 ptlrpc_lprocfs_register_obd(obd);
1249 if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1252 /* If the real OSC is present which is the case for setups
1253 * with both server and clients on the same node then use
1254 * the OSC's proc root
1256 osc = kset_find_obj(lustre_kset, "osc");
1258 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1263 osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1264 "../osp/%s", obd->obd_name);
1265 if (!osp->opd_debugfs)
1266 CERROR("%s: failed to create OSC debugfs symlink\n",