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, char *buf)
199 struct dt_device *dt = container_of(kobj, struct dt_device,
201 struct osp_device *osp = dt2osp_dev(dt);
203 return sprintf(buf, "%u\n", osp->opd_sync_max_changes);
207 static ssize_t max_sync_changes_store(struct kobject *kobj,
208 struct attribute *attr, const char *buffer, size_t count)
210 struct dt_device *dt = container_of(kobj, struct dt_device,
212 struct osp_device *osp = dt2osp_dev(dt);
216 rc = kstrtoint(buffer, 0, &val);
221 osp->opd_sync_max_changes = val;
225 LUSTRE_RW_ATTR(max_sync_changes);
228 * Show maximum number of RPCs in flight allowed
230 * \param[in] m seq_file handle
231 * \param[in] data unused for single entry
232 * \retval 0 on success
233 * \retval negative number on error
235 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
236 struct attribute *attr,
239 struct dt_device *dt = container_of(kobj, struct dt_device,
241 struct osp_device *osp = dt2osp_dev(dt);
243 return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_flight);
247 * Change maximum number of RPCs in flight allowed
249 * \param[in] file proc file
250 * \param[in] buffer string which represents maximum number
251 * \param[in] count \a buffer length
252 * \param[in] off unused for single entry
253 * \retval \a count on success
254 * \retval negative number on error
256 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
257 struct attribute *attr,
261 struct dt_device *dt = container_of(kobj, struct dt_device,
263 struct osp_device *osp = dt2osp_dev(dt);
267 rc = kstrtouint(buffer, 0, &val);
274 osp->opd_sync_max_rpcs_in_flight = val;
277 LUSTRE_RW_ATTR(max_rpcs_in_flight);
279 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
280 struct attribute *attr,
283 struct dt_device *dt = container_of(kobj, struct dt_device,
285 struct lu_device *lu = dt2lu_dev(dt);
286 struct obd_device *obd = lu->ld_obd;
289 max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
290 return scnprintf(buf, PAGE_SIZE, "%hu\n", max);
293 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
294 struct attribute *attr,
298 struct dt_device *dt = container_of(kobj, struct dt_device,
300 struct lu_device *lu = dt2lu_dev(dt);
301 struct obd_device *obd = lu->ld_obd;
305 rc = kstrtou16(buffer, 10, &val);
309 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
315 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
318 * Show maximum number of RPCs in processing allowed
320 * \param[in] m seq_file handle
321 * \param[in] data unused
322 * \retval 0 on success
323 * \retval negative number on error
325 static ssize_t max_rpcs_in_progress_show(struct kobject *kobj,
326 struct attribute *attr,
329 struct dt_device *dt = container_of(kobj, struct dt_device,
331 struct osp_device *osp = dt2osp_dev(dt);
333 return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_progress);
337 * Change maximum number of RPCs in processing allowed
339 * \param[in] file proc file
340 * \param[in] buffer string which represents maximum number
341 * \param[in] count \a buffer length
342 * \param[in] off unused for single entry
343 * \retval \a count on success
344 * \retval negative number on error
346 static ssize_t max_rpcs_in_progress_store(struct kobject *kobj,
347 struct attribute *attr,
351 struct dt_device *dt = container_of(kobj, struct dt_device,
353 struct osp_device *osp = dt2osp_dev(dt);
357 rc = kstrtouint(buffer, 0, &val);
364 osp->opd_sync_max_rpcs_in_progress = val;
368 LUSTRE_RW_ATTR(max_rpcs_in_progress);
371 * Show number of objects to precreate next time
373 * \param[in] m seq_file handle
374 * \param[in] data unused for single entry
375 * \retval 0 on success
376 * \retval negative number on error
378 static ssize_t create_count_show(struct kobject *kobj,
379 struct attribute *attr,
382 struct dt_device *dt = container_of(kobj, struct dt_device,
384 struct osp_device *osp = dt2osp_dev(dt);
389 return sprintf(buf, "%d\n", osp->opd_pre_create_count);
393 * Change number of objects to precreate next time
395 * \param[in] file proc file
396 * \param[in] buffer string which represents number of objects to precreate
397 * \param[in] count \a buffer length
398 * \param[in] off unused for single entry
399 * \retval \a count on success
400 * \retval negative number on error
402 static ssize_t create_count_store(struct kobject *kobj, struct attribute *attr,
403 const char *buffer, size_t count)
405 struct dt_device *dt = container_of(kobj, struct dt_device,
407 struct osp_device *osp = dt2osp_dev(dt);
414 rc = kstrtouint(buffer, 0, &val);
418 /* The MDT ALWAYS needs to limit the precreate count to
419 * OST_MAX_PRECREATE, and the constant cannot be changed
420 * because it is a value shared between the OSP and OST
421 * that is the maximum possible number of objects that will
422 * ever be handled by MDT->OST recovery processing.
424 * The OSP enforces the pre_create_count to amaximum of
425 * one half of opd_pre_max_create_count.
427 * If the OST ever gets a request to delete more orphans,
428 * this implies that something has gone badly on the MDT
429 * and the OST will refuse to delete so much data from the
430 * filesystem as a safety measure.
432 if (val < OST_MIN_PRECREATE)
434 if (val > osp->opd_pre_max_create_count / 2)
435 val = osp->opd_pre_max_create_count / 2;
437 /* set to largest value <= 32, 64, 128 or a multiple of 256 */
439 osp->opd_pre_create_count = val & 0xffffff00;
441 osp->opd_pre_create_count = rounddown_pow_of_two(val);
445 LUSTRE_RW_ATTR(create_count);
448 * Show maximum number of objects to precreate
450 * \param[in] m seq_file handle
451 * \param[in] data unused for single entry
452 * \retval 0 on success
453 * \retval negative number on error
455 static ssize_t max_create_count_show(struct kobject *kobj,
456 struct attribute *attr,
459 struct dt_device *dt = container_of(kobj, struct dt_device,
461 struct osp_device *osp = dt2osp_dev(dt);
466 return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
470 * Change maximum number of objects to precreate
472 * \param[in] file proc file
473 * \param[in] buffer string which represents maximum number
474 * \param[in] count \a buffer length
475 * \param[in] off unused for single entry
476 * \retval \a count on success
477 * \retval negative number on error
479 static ssize_t max_create_count_store(struct kobject *kobj,
480 struct attribute *attr,
481 const char *buffer, size_t count)
483 struct dt_device *dt = container_of(kobj, struct dt_device,
485 struct osp_device *osp = dt2osp_dev(dt);
492 rc = kstrtouint(buffer, 0, &val);
496 if (val && (val < OST_MIN_PRECREATE ||
497 val > OST_MAX_PRECREATE))
500 if (osp->opd_pre_create_count > val)
501 osp->opd_pre_create_count = val;
503 /* Can be 0 after setting max_create_count to 0 */
504 if (osp->opd_pre_create_count == 0 && val != 0)
505 osp->opd_pre_create_count = OST_MIN_PRECREATE;
507 osp->opd_pre_max_create_count = val;
511 LUSTRE_RW_ATTR(max_create_count);
514 * Show last id to assign in creation
516 * \param[in] m seq_file handle
517 * \param[in] data unused for single entry
518 * \retval 0 on success
519 * \retval negative number on error
521 static ssize_t prealloc_next_id_show(struct kobject *kobj,
522 struct attribute *attr,
525 struct dt_device *dt = container_of(kobj, struct dt_device,
527 struct osp_device *osp = dt2osp_dev(dt);
534 fid = &osp->opd_pre_used_fid;
535 if (fid_is_idif(fid)) {
536 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
539 id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
540 1 : fid_oid(fid) + 1;
543 return sprintf(buf, "%llu\n", id);
545 LUSTRE_RO_ATTR(prealloc_next_id);
548 * Show last created id OST reported
550 * \param[in] m seq_file handle
551 * \param[in] data unused for single entry
552 * \retval 0 on success
553 * \retval negative number on error
556 static ssize_t prealloc_last_id_show(struct kobject *kobj,
557 struct attribute *attr,
560 struct dt_device *dt = container_of(kobj, struct dt_device,
562 struct osp_device *osp = dt2osp_dev(dt);
569 fid = &osp->opd_pre_last_created_fid;
570 id = fid_is_idif(fid) ?
571 fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
574 return sprintf(buf, "%llu\n", id);
576 LUSTRE_RO_ATTR(prealloc_last_id);
579 * Show next FID sequence to precreate
581 * \param[in] m seq_file handle
582 * \param[in] data unused for single entry
583 * \retval 0 on success
584 * \retval negative number on error
586 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
587 struct attribute *attr,
590 struct dt_device *dt = container_of(kobj, struct dt_device,
592 struct osp_device *osp = dt2osp_dev(dt);
598 fid = &osp->opd_pre_used_fid;
599 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
600 fid_seq(fid) & (~0xffff) : fid_seq(fid));
602 LUSTRE_RO_ATTR(prealloc_next_seq);
605 * Show last created FID sequence OST reported
607 * \param[in] m seq_file handle
608 * \param[in] data unused for single entry
609 * \retval 0 on success
610 * \retval negative number on error
612 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
613 struct attribute *attr,
616 struct dt_device *dt = container_of(kobj, struct dt_device,
618 struct osp_device *osp = dt2osp_dev(dt);
624 fid = &osp->opd_pre_last_created_fid;
625 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
626 fid_seq(fid) & (~0xffff) : fid_seq(fid));
628 LUSTRE_RO_ATTR(prealloc_last_seq);
631 * Show the number of ids reserved by declare
633 * \param[in] m seq_file handle
634 * \param[in] data unused for single entry
635 * \retval 0 on success
636 * \retval negative number on error
638 static ssize_t prealloc_reserved_show(struct kobject *kobj,
639 struct attribute *attr,
642 struct dt_device *dt = container_of(kobj, struct dt_device,
644 struct osp_device *osp = dt2osp_dev(dt);
649 return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
651 LUSTRE_RO_ATTR(prealloc_reserved);
654 * Show interval (in seconds) to update statfs data
656 * \param[in] m seq_file handle
657 * \param[in] data unused for single entry
658 * \retval 0 on success
659 * \retval negative number on error
661 static ssize_t maxage_show(struct kobject *kobj,
662 struct attribute *attr,
665 struct dt_device *dt = container_of(kobj, struct dt_device,
667 struct osp_device *osp = dt2osp_dev(dt);
669 return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
673 * Change interval to update statfs data
675 * \param[in] file proc file
676 * \param[in] buffer string which represents statfs interval (in seconds)
677 * \param[in] count \a buffer length
678 * \param[in] off unused for single entry
679 * \retval \a count on success
680 * \retval negative number on error
682 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
683 const char *buffer, size_t count)
685 struct dt_device *dt = container_of(kobj, struct dt_device,
687 struct osp_device *osp = dt2osp_dev(dt);
691 rc = kstrtouint(buffer, 0, &val);
698 osp->opd_statfs_maxage = val;
702 LUSTRE_RW_ATTR(maxage);
705 * Show current precreation status: output 0 means success, otherwise negative
708 * \param[in] m seq_file handle
709 * \param[in] data unused for single entry
710 * \retval 0 on success
711 * \retval negative number on error
713 static ssize_t prealloc_status_show(struct kobject *kobj,
714 struct attribute *attr,
717 struct dt_device *dt = container_of(kobj, struct dt_device,
719 struct osp_device *osp = dt2osp_dev(dt);
724 return sprintf(buf, "%d\n", osp->opd_pre_status);
726 LUSTRE_RO_ATTR(prealloc_status);
729 * Show the number of RPCs in processing (including uncommitted by OST) plus
730 * changes to sync, i.e. this is the total number of changes OST needs to apply
733 * This counter is used to determine if OST has space returned. A zero value
734 * indicates that OST storage space consumed by destroyed objects has been freed
735 * on disk, the associated llog records have been cleared, and no synchronous
736 * RPC are being processed.
738 * \param[in] m seq_file handle
739 * \param[in] data unused for single entry
740 * \retval 0 on success
741 * \retval negative number on error
743 static ssize_t destroys_in_flight_show(struct kobject *kobj,
744 struct attribute *attr,
747 struct dt_device *dt = container_of(kobj, struct dt_device,
749 struct osp_device *osp = dt2osp_dev(dt);
751 return sprintf(buf, "%u\n",
752 atomic_read(&osp->opd_sync_rpcs_in_progress) +
753 atomic_read(&osp->opd_sync_changes));
755 LUSTRE_RO_ATTR(destroys_in_flight);
758 * Show changes synced from previous mount
760 * \param[in] m seq_file handle
761 * \param[in] data unused for single entry
762 * \retval 0 on success
763 * \retval negative number on error
765 static ssize_t old_sync_processed_show(struct kobject *kobj,
766 struct attribute *attr,
769 struct dt_device *dt = container_of(kobj, struct dt_device,
771 struct osp_device *osp = dt2osp_dev(dt);
773 return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
775 LUSTRE_RO_ATTR(old_sync_processed);
778 * Show maximum number of RPCs in flight
780 * \param[in] m seq_file handle
781 * \param[in] data unused for single entry
782 * \retval 0 on success
783 * \retval negative number on error
785 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
786 struct attribute *attr,
789 struct dt_device *dt = container_of(kobj, struct dt_device,
791 struct lu_device *lu = dt2lu_dev(dt);
792 struct obd_device *obd = lu->ld_obd;
795 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
796 return sprintf(buf, "%u\n", max);
800 * Change maximum number of RPCs in flight
802 * \param[in] file proc file
803 * \param[in] buffer string which represents maximum number of RPCs in flight
804 * \param[in] count \a buffer length
805 * \param[in] off unused for single entry
806 * \retval \a count on success
807 * \retval negative number on error
809 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
810 struct attribute *attr,
814 struct dt_device *dt = container_of(kobj, struct dt_device,
816 struct lu_device *lu = dt2lu_dev(dt);
817 struct obd_device *obd = lu->ld_obd;
821 rc = kstrtouint(buffer, 0, &val);
825 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
826 return rc ? rc : count;
828 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
830 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
833 struct dt_device *dt = container_of(kobj, struct dt_device,
835 struct lu_device *lu = dt2lu_dev(dt);
836 struct obd_device *obd = lu->ld_obd;
839 rc = ptlrpc_obd_ping(obd);
843 LUSTRE_RO_ATTR(ping);
845 ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
848 struct dt_device *dt = container_of(kobj, struct dt_device,
850 struct lu_device *lu = dt2lu_dev(dt);
851 struct obd_device *obd = lu->ld_obd;
852 struct obd_import *imp;
853 struct ptlrpc_connection *conn;
856 with_imp_locked(obd, imp, count) {
857 conn = imp->imp_connection;
859 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
861 count = sprintf(buf, "%s\n", "<none>");
867 LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
868 LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
870 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
871 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
872 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
874 LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
875 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
877 static int osp_rpc_stats_seq_show(struct seq_file *seq, void *v)
879 struct obd_device *dev = seq->private;
881 return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
884 static ssize_t osp_rpc_stats_seq_write(struct file *file,
885 const char __user *buf,
886 size_t len, loff_t *off)
888 struct seq_file *seq = file->private_data;
889 struct obd_device *dev = seq->private;
890 struct client_obd *cli = &dev->u.cli;
892 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
893 cli->cl_mod_rpcs_init = ktime_get_real();
897 LDEBUGFS_SEQ_FOPS(osp_rpc_stats);
900 * Show high watermark (in megabytes). If available free space at OST is greater
901 * than high watermark and object allocation for OST is disabled, enable it.
903 static ssize_t reserved_mb_high_show(struct kobject *kobj,
904 struct attribute *attr,
907 struct dt_device *dt = container_of(kobj, struct dt_device,
909 struct osp_device *osp = dt2osp_dev(dt);
911 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_high);
915 * Change high watermark
917 static ssize_t reserved_mb_high_store(struct kobject *kobj,
918 struct attribute *attr,
922 struct dt_device *dt = container_of(kobj, struct dt_device,
924 struct osp_device *osp = dt2osp_dev(dt);
928 rc = sysfs_memparse(buffer, count, &val, "MiB");
935 spin_lock(&osp->opd_pre_lock);
936 osp->opd_reserved_mb_high = val;
937 if (val <= osp->opd_reserved_mb_low)
938 osp->opd_reserved_mb_low = val - 1;
939 spin_unlock(&osp->opd_pre_lock);
943 LUSTRE_RW_ATTR(reserved_mb_high);
946 * Show low watermark (in megabytes). If available free space at OST is less
947 * than low watermark, object allocation for OST is disabled.
949 static ssize_t reserved_mb_low_show(struct kobject *kobj,
950 struct attribute *attr,
953 struct dt_device *dt = container_of(kobj, struct dt_device,
955 struct osp_device *osp = dt2osp_dev(dt);
957 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_low);
961 * Change low watermark
963 static ssize_t reserved_mb_low_store(struct kobject *kobj,
964 struct attribute *attr,
968 struct dt_device *dt = container_of(kobj, struct dt_device,
970 struct osp_device *osp = dt2osp_dev(dt);
974 rc = sysfs_memparse(buffer, count, &val, "MiB");
979 spin_lock(&osp->opd_pre_lock);
980 osp->opd_reserved_mb_low = val;
981 if (val >= osp->opd_reserved_mb_high)
982 osp->opd_reserved_mb_high = val + 1;
983 spin_unlock(&osp->opd_pre_lock);
987 LUSTRE_RW_ATTR(reserved_mb_low);
990 * Show high watermark of inode.
992 static ssize_t reserved_ino_high_show(struct kobject *kobj,
993 struct attribute *attr,
996 struct dt_device *dt = container_of(kobj, struct dt_device,
998 struct osp_device *osp = dt2osp_dev(dt);
1000 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_high);
1004 * Change high watermark of inode.
1006 static ssize_t reserved_ino_high_store(struct kobject *kobj,
1007 struct attribute *attr,
1011 struct dt_device *dt = container_of(kobj, struct dt_device,
1013 struct osp_device *osp = dt2osp_dev(dt);
1017 rc = kstrtouint(buffer, 0, &val);
1023 spin_lock(&osp->opd_pre_lock);
1024 osp->opd_reserved_ino_high = val;
1025 if (val <= osp->opd_reserved_ino_low)
1026 osp->opd_reserved_ino_low = val >> 1;
1027 spin_unlock(&osp->opd_pre_lock);
1031 LUSTRE_RW_ATTR(reserved_ino_high);
1034 * Show low watermark.
1036 static ssize_t reserved_ino_low_show(struct kobject *kobj,
1037 struct attribute *attr,
1040 struct dt_device *dt = container_of(kobj, struct dt_device,
1042 struct osp_device *osp = dt2osp_dev(dt);
1044 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_low);
1048 * Change low watermark
1050 static ssize_t reserved_ino_low_store(struct kobject *kobj,
1051 struct attribute *attr,
1055 struct dt_device *dt = container_of(kobj, struct dt_device,
1057 struct osp_device *osp = dt2osp_dev(dt);
1061 rc = kstrtouint(buffer, 0, &val);
1065 if (val & (1UL << 31))
1068 spin_lock(&osp->opd_pre_lock);
1069 osp->opd_reserved_ino_low = val;
1070 if (val >= osp->opd_reserved_ino_high)
1071 osp->opd_reserved_ino_high = val << 1;
1072 spin_unlock(&osp->opd_pre_lock);
1076 LUSTRE_RW_ATTR(reserved_ino_low);
1078 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
1079 const char *buffer, size_t count)
1081 struct dt_device *dt = container_of(kobj, struct dt_device,
1086 rc = lu_env_init(&env, LCT_LOCAL);
1090 rc = dt_sync(&env, dt);
1093 return rc == 0 ? count : rc;
1095 LUSTRE_WO_ATTR(force_sync);
1097 static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
1098 { .name = "connect_flags",
1099 .fops = &osp_connect_flags_fops },
1100 { .name = "ost_server_uuid",
1101 .fops = &osp_server_uuid_fops },
1102 { .name = "timeouts",
1103 .fops = &osp_timeouts_fops },
1105 .fops = &osp_import_fops },
1107 .fops = &osp_state_fops },
1111 static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
1112 { .name = "connect_flags",
1113 .fops = &osp_connect_flags_fops },
1114 { .name = "mdt_server_uuid",
1115 .fops = &osp_server_uuid_fops },
1116 { .name = "timeouts",
1117 .fops = &osp_timeouts_fops },
1119 .fops = &osp_import_fops },
1121 .fops = &osp_state_fops },
1122 { .name = "rpc_stats",
1123 .fops = &osp_rpc_stats_fops },
1127 static struct attribute *osp_obd_attrs[] = {
1128 /* First two for compatiability reasons */
1129 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1130 &lustre_attr_destroys_in_flight.attr,
1131 &lustre_attr_active.attr,
1132 &lustre_attr_max_rpcs_in_flight.attr,
1133 &lustre_attr_max_rpcs_in_progress.attr,
1134 &lustre_attr_maxage.attr,
1135 &lustre_attr_ost_conn_uuid.attr,
1136 &lustre_attr_ping.attr,
1137 &lustre_attr_prealloc_status.attr,
1138 &lustre_attr_prealloc_next_id.attr,
1139 &lustre_attr_prealloc_last_id.attr,
1140 &lustre_attr_prealloc_next_seq.attr,
1141 &lustre_attr_prealloc_last_seq.attr,
1142 &lustre_attr_prealloc_reserved.attr,
1143 &lustre_attr_sync_in_flight.attr,
1144 &lustre_attr_sync_in_progress.attr,
1145 &lustre_attr_sync_changes.attr,
1146 &lustre_attr_max_sync_changes.attr,
1147 &lustre_attr_force_sync.attr,
1148 &lustre_attr_old_sync_processed.attr,
1149 &lustre_attr_create_count.attr,
1150 &lustre_attr_max_create_count.attr,
1151 &lustre_attr_reserved_mb_high.attr,
1152 &lustre_attr_reserved_mb_low.attr,
1153 &lustre_attr_reserved_ino_high.attr,
1154 &lustre_attr_reserved_ino_low.attr,
1158 KOBJ_ATTRIBUTE_GROUPS(osp_obd); /* creates osp_obd_groups from osp_obd_attrs */
1160 static struct attribute *osp_md_attrs[] = {
1161 /* First two for compatiability reasons */
1162 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1163 &lustre_attr_destroys_in_flight.attr,
1164 &lustre_attr_active.attr,
1165 &lustre_attr_max_rpcs_in_flight.attr,
1166 &lustre_attr_max_mod_rpcs_in_flight.attr,
1167 &lustre_attr_max_rpcs_in_progress.attr,
1168 &lustre_attr_maxage.attr,
1169 &lustre_attr_mdt_conn_uuid.attr,
1170 &lustre_attr_ping.attr,
1171 &lustre_attr_prealloc_status.attr,
1172 &lustre_attr_reserved_mb_high.attr,
1173 &lustre_attr_reserved_mb_low.attr,
1174 &lustre_attr_reserved_ino_high.attr,
1175 &lustre_attr_reserved_ino_low.attr,
1179 KOBJ_ATTRIBUTE_GROUPS(osp_md); /* creates osp_md_groups from osp_md_attrs */
1181 void osp_tunables_fini(struct osp_device *osp)
1183 struct obd_device *obd = osp->opd_obd;
1184 struct kobject *osc;
1186 osc = kset_find_obj(lustre_kset, "osc");
1188 sysfs_remove_link(osc, obd->obd_name);
1192 debugfs_remove_recursive(osp->opd_debugfs);
1193 osp->opd_debugfs = NULL;
1195 ptlrpc_lprocfs_unregister_obd(obd);
1197 debugfs_remove_recursive(obd->obd_debugfs_entry);
1198 obd->obd_debugfs_entry = NULL;
1200 dt_tunables_fini(&osp->opd_dt_dev);
1204 * Initialize OSP sysfs / debugfs
1206 * param[in] osp OSP device
1208 void osp_tunables_init(struct osp_device *osp)
1210 struct obd_device *obd = osp->opd_obd;
1211 struct kobject *osc;
1214 if (osp->opd_connect_mdt) {
1215 osp->opd_dt_dev.dd_ktype.default_groups =
1216 KOBJ_ATTR_GROUPS(osp_md);
1217 obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
1219 osp->opd_dt_dev.dd_ktype.default_groups =
1220 KOBJ_ATTR_GROUPS(osp_obd);
1221 obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
1224 rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
1227 CERROR("%s: failed to setup DT tunables: %d\n",
1232 /* Since we register the obd device with ptlrpc / sptlrpc we
1233 * have to register debugfs with obd_device
1235 obd->obd_debugfs_entry = debugfs_create_dir(
1236 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1237 ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
1239 sptlrpc_lprocfs_cliobd_attach(obd);
1240 ptlrpc_lprocfs_register_obd(obd);
1242 if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1245 /* If the real OSC is present which is the case for setups
1246 * with both server and clients on the same node then use
1247 * the OSC's proc root
1249 osc = kset_find_obj(lustre_kset, "osc");
1251 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1256 osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1257 "../osp/%s", obd->obd_name);
1258 if (!osp->opd_debugfs)
1259 CERROR("%s: failed to create OSC debugfs symlink\n",