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);
445 if (osp->opd_pre_create_count + osp->opd_pre_reserved >
446 osp_objs_precreated(osp))
447 wake_up(&osp->opd_pre_waitq);
451 LUSTRE_RW_ATTR(create_count);
454 * Show maximum number of objects to precreate
456 * \param[in] m seq_file handle
457 * \param[in] data unused for single entry
458 * \retval 0 on success
459 * \retval negative number on error
461 static ssize_t max_create_count_show(struct kobject *kobj,
462 struct attribute *attr,
465 struct dt_device *dt = container_of(kobj, struct dt_device,
467 struct osp_device *osp = dt2osp_dev(dt);
472 return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
476 * Change maximum number of objects to precreate
478 * \param[in] file proc file
479 * \param[in] buffer string which represents maximum number
480 * \param[in] count \a buffer length
481 * \param[in] off unused for single entry
482 * \retval \a count on success
483 * \retval negative number on error
485 static ssize_t max_create_count_store(struct kobject *kobj,
486 struct attribute *attr,
487 const char *buffer, size_t count)
489 struct dt_device *dt = container_of(kobj, struct dt_device,
491 struct osp_device *osp = dt2osp_dev(dt);
498 rc = kstrtouint(buffer, 0, &val);
502 if (val && (val < OST_MIN_PRECREATE ||
503 val > OST_MAX_PRECREATE))
506 if (osp->opd_pre_create_count > val)
507 osp->opd_pre_create_count = val;
509 /* Can be 0 after setting max_create_count to 0 */
510 if (osp->opd_pre_create_count == 0 && val != 0)
511 osp->opd_pre_create_count = OST_MIN_PRECREATE;
513 osp->opd_pre_max_create_count = val;
517 LUSTRE_RW_ATTR(max_create_count);
520 * Show last id to assign in creation
522 * \param[in] m seq_file handle
523 * \param[in] data unused for single entry
524 * \retval 0 on success
525 * \retval negative number on error
527 static ssize_t prealloc_next_id_show(struct kobject *kobj,
528 struct attribute *attr,
531 struct dt_device *dt = container_of(kobj, struct dt_device,
533 struct osp_device *osp = dt2osp_dev(dt);
541 fid = &osp->opd_pre_used_fid;
542 seq_width = osp->opd_pre_seq_width;
543 if (fid_is_idif(fid)) {
544 id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
545 if (unlikely(id >= min(IDIF_MAX_OID, seq_width)))
550 id = unlikely(fid_oid(fid) >= min(OBIF_MAX_OID, seq_width)) ?
551 1 : fid_oid(fid) + 1;
554 return sprintf(buf, "%llu\n", id);
556 LUSTRE_RO_ATTR(prealloc_next_id);
559 * Show last created id OST reported
561 * \param[in] m seq_file handle
562 * \param[in] data unused for single entry
563 * \retval 0 on success
564 * \retval negative number on error
567 static ssize_t prealloc_last_id_show(struct kobject *kobj,
568 struct attribute *attr,
571 struct dt_device *dt = container_of(kobj, struct dt_device,
573 struct osp_device *osp = dt2osp_dev(dt);
580 fid = &osp->opd_pre_last_created_fid;
581 id = fid_is_idif(fid) ?
582 fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
585 return sprintf(buf, "%llu\n", id);
587 LUSTRE_RO_ATTR(prealloc_last_id);
590 * Show next FID sequence to precreate
592 * \param[in] m seq_file handle
593 * \param[in] data unused for single entry
594 * \retval 0 on success
595 * \retval negative number on error
597 static ssize_t prealloc_next_seq_show(struct kobject *kobj,
598 struct attribute *attr,
601 struct dt_device *dt = container_of(kobj, struct dt_device,
603 struct osp_device *osp = dt2osp_dev(dt);
609 fid = &osp->opd_pre_used_fid;
610 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
611 fid_seq(fid) & (~0xffff) : fid_seq(fid));
613 LUSTRE_RO_ATTR(prealloc_next_seq);
616 * Show last created FID sequence OST reported
618 * \param[in] m seq_file handle
619 * \param[in] data unused for single entry
620 * \retval 0 on success
621 * \retval negative number on error
623 static ssize_t prealloc_last_seq_show(struct kobject *kobj,
624 struct attribute *attr,
627 struct dt_device *dt = container_of(kobj, struct dt_device,
629 struct osp_device *osp = dt2osp_dev(dt);
635 fid = &osp->opd_pre_last_created_fid;
636 return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
637 fid_seq(fid) & (~0xffff) : fid_seq(fid));
639 LUSTRE_RO_ATTR(prealloc_last_seq);
642 * Show the number of ids reserved by declare
644 * \param[in] m seq_file handle
645 * \param[in] data unused for single entry
646 * \retval 0 on success
647 * \retval negative number on error
649 static ssize_t prealloc_reserved_show(struct kobject *kobj,
650 struct attribute *attr,
653 struct dt_device *dt = container_of(kobj, struct dt_device,
655 struct osp_device *osp = dt2osp_dev(dt);
660 return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
662 LUSTRE_RO_ATTR(prealloc_reserved);
665 * Show interval (in seconds) to update statfs data
667 * \param[in] m seq_file handle
668 * \param[in] data unused for single entry
669 * \retval 0 on success
670 * \retval negative number on error
672 static ssize_t maxage_show(struct kobject *kobj,
673 struct attribute *attr,
676 struct dt_device *dt = container_of(kobj, struct dt_device,
678 struct osp_device *osp = dt2osp_dev(dt);
680 return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
684 * Change interval to update statfs data
686 * \param[in] file proc file
687 * \param[in] buffer string which represents statfs interval (in seconds)
688 * \param[in] count \a buffer length
689 * \param[in] off unused for single entry
690 * \retval \a count on success
691 * \retval negative number on error
693 static ssize_t maxage_store(struct kobject *kobj, struct attribute *attr,
694 const char *buffer, size_t count)
696 struct dt_device *dt = container_of(kobj, struct dt_device,
698 struct osp_device *osp = dt2osp_dev(dt);
702 rc = kstrtouint(buffer, 0, &val);
709 osp->opd_statfs_maxage = val;
713 LUSTRE_RW_ATTR(maxage);
716 * Show current precreation status: output 0 means success, otherwise negative
719 * \param[in] m seq_file handle
720 * \param[in] data unused for single entry
721 * \retval 0 on success
722 * \retval negative number on error
724 static ssize_t prealloc_status_show(struct kobject *kobj,
725 struct attribute *attr,
728 struct dt_device *dt = container_of(kobj, struct dt_device,
730 struct osp_device *osp = dt2osp_dev(dt);
735 return sprintf(buf, "%d\n", osp->opd_pre_status);
737 LUSTRE_RO_ATTR(prealloc_status);
739 static ssize_t prealloc_force_new_seq_show(struct kobject *kobj,
740 struct attribute *attr,
743 struct dt_device *dt = container_of(kobj, struct dt_device,
745 struct osp_device *osp = dt2osp_dev(dt);
750 return scnprintf(buf, PAGE_SIZE, "%d\n", osp->opd_pre_force_new_seq);
753 static ssize_t prealloc_force_new_seq_store(struct kobject *kobj,
754 struct attribute *attr,
758 struct dt_device *dt = container_of(kobj, struct dt_device,
760 struct osp_device *osp = dt2osp_dev(dt);
767 rc = kstrtobool(buffer, &val);
771 osp->opd_pre_force_new_seq = val;
775 LUSTRE_RW_ATTR(prealloc_force_new_seq);
778 * Show the number of RPCs in processing (including uncommitted by OST) plus
779 * changes to sync, i.e. this is the total number of changes OST needs to apply
782 * This counter is used to determine if OST has space returned. A zero value
783 * indicates that OST storage space consumed by destroyed objects has been freed
784 * on disk, the associated llog records have been cleared, and no synchronous
785 * RPC are being processed.
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 destroys_in_flight_show(struct kobject *kobj,
793 struct attribute *attr,
796 struct dt_device *dt = container_of(kobj, struct dt_device,
798 struct osp_device *osp = dt2osp_dev(dt);
800 return sprintf(buf, "%u\n",
801 atomic_read(&osp->opd_sync_rpcs_in_progress) +
802 atomic_read(&osp->opd_sync_changes));
804 LUSTRE_RO_ATTR(destroys_in_flight);
807 * Show changes synced from previous mount
809 * \param[in] m seq_file handle
810 * \param[in] data unused for single entry
811 * \retval 0 on success
812 * \retval negative number on error
814 static ssize_t old_sync_processed_show(struct kobject *kobj,
815 struct attribute *attr,
818 struct dt_device *dt = container_of(kobj, struct dt_device,
820 struct osp_device *osp = dt2osp_dev(dt);
822 return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
824 LUSTRE_RO_ATTR(old_sync_processed);
827 * Show maximum number of RPCs in flight
829 * \param[in] m seq_file handle
830 * \param[in] data unused for single entry
831 * \retval 0 on success
832 * \retval negative number on error
834 static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
835 struct attribute *attr,
838 struct dt_device *dt = container_of(kobj, struct dt_device,
840 struct lu_device *lu = dt2lu_dev(dt);
841 struct obd_device *obd = lu->ld_obd;
844 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
845 return sprintf(buf, "%u\n", max);
849 * Change maximum number of RPCs in flight
851 * \param[in] file proc file
852 * \param[in] buffer string which represents maximum number of RPCs in flight
853 * \param[in] count \a buffer length
854 * \param[in] off unused for single entry
855 * \retval \a count on success
856 * \retval negative number on error
858 static ssize_t lfsck_max_rpcs_in_flight_store(struct kobject *kobj,
859 struct attribute *attr,
863 struct dt_device *dt = container_of(kobj, struct dt_device,
865 struct lu_device *lu = dt2lu_dev(dt);
866 struct obd_device *obd = lu->ld_obd;
870 rc = kstrtouint(buffer, 0, &val);
874 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
875 return rc ? rc : count;
877 LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
879 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
882 struct dt_device *dt = container_of(kobj, struct dt_device,
884 struct lu_device *lu = dt2lu_dev(dt);
885 struct obd_device *obd = lu->ld_obd;
888 rc = ptlrpc_obd_ping(obd);
892 LUSTRE_RO_ATTR(ping);
894 static ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
897 struct dt_device *dt = container_of(kobj, struct dt_device,
899 struct lu_device *lu = dt2lu_dev(dt);
900 struct obd_device *obd = lu->ld_obd;
901 struct obd_import *imp;
902 struct ptlrpc_connection *conn;
905 with_imp_locked(obd, imp, count) {
906 conn = imp->imp_connection;
908 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
910 count = sprintf(buf, "%s\n", "<none>");
916 LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
917 LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
919 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
920 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
921 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
923 LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
924 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
926 static int osp_rpc_stats_seq_show(struct seq_file *seq, void *v)
928 struct obd_device *dev = seq->private;
930 return obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
933 static ssize_t osp_rpc_stats_seq_write(struct file *file,
934 const char __user *buf,
935 size_t len, loff_t *off)
937 struct seq_file *seq = file->private_data;
938 struct obd_device *dev = seq->private;
939 struct client_obd *cli = &dev->u.cli;
941 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
942 cli->cl_mod_rpcs_init = ktime_get_real();
946 LDEBUGFS_SEQ_FOPS(osp_rpc_stats);
949 * Show high watermark (in megabytes). If available free space at OST is greater
950 * than high watermark and object allocation for OST is disabled, enable it.
952 static ssize_t reserved_mb_high_show(struct kobject *kobj,
953 struct attribute *attr,
956 struct dt_device *dt = container_of(kobj, struct dt_device,
958 struct osp_device *osp = dt2osp_dev(dt);
960 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_high);
964 * Change high watermark
966 static ssize_t reserved_mb_high_store(struct kobject *kobj,
967 struct attribute *attr,
971 struct dt_device *dt = container_of(kobj, struct dt_device,
973 struct osp_device *osp = dt2osp_dev(dt);
977 rc = sysfs_memparse(buffer, count, &val, "MiB");
984 spin_lock(&osp->opd_pre_lock);
985 osp->opd_reserved_mb_high = val;
986 if (val <= osp->opd_reserved_mb_low)
987 osp->opd_reserved_mb_low = val - 1;
988 spin_unlock(&osp->opd_pre_lock);
992 LUSTRE_RW_ATTR(reserved_mb_high);
995 * Show low watermark (in megabytes). If available free space at OST is less
996 * than low watermark, object allocation for OST is disabled.
998 static ssize_t reserved_mb_low_show(struct kobject *kobj,
999 struct attribute *attr,
1002 struct dt_device *dt = container_of(kobj, struct dt_device,
1004 struct osp_device *osp = dt2osp_dev(dt);
1006 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_mb_low);
1010 * Change low watermark
1012 static ssize_t reserved_mb_low_store(struct kobject *kobj,
1013 struct attribute *attr,
1017 struct dt_device *dt = container_of(kobj, struct dt_device,
1019 struct osp_device *osp = dt2osp_dev(dt);
1023 rc = sysfs_memparse(buffer, count, &val, "MiB");
1028 spin_lock(&osp->opd_pre_lock);
1029 osp->opd_reserved_mb_low = val;
1030 if (val >= osp->opd_reserved_mb_high)
1031 osp->opd_reserved_mb_high = val + 1;
1032 spin_unlock(&osp->opd_pre_lock);
1036 LUSTRE_RW_ATTR(reserved_mb_low);
1039 * Show high watermark of inode.
1041 static ssize_t reserved_ino_high_show(struct kobject *kobj,
1042 struct attribute *attr,
1045 struct dt_device *dt = container_of(kobj, struct dt_device,
1047 struct osp_device *osp = dt2osp_dev(dt);
1049 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_high);
1053 * Change high watermark of inode.
1055 static ssize_t reserved_ino_high_store(struct kobject *kobj,
1056 struct attribute *attr,
1060 struct dt_device *dt = container_of(kobj, struct dt_device,
1062 struct osp_device *osp = dt2osp_dev(dt);
1066 rc = kstrtouint(buffer, 0, &val);
1072 spin_lock(&osp->opd_pre_lock);
1073 osp->opd_reserved_ino_high = val;
1074 if (val <= osp->opd_reserved_ino_low)
1075 osp->opd_reserved_ino_low = val >> 1;
1076 spin_unlock(&osp->opd_pre_lock);
1080 LUSTRE_RW_ATTR(reserved_ino_high);
1083 * Show low watermark.
1085 static ssize_t reserved_ino_low_show(struct kobject *kobj,
1086 struct attribute *attr,
1089 struct dt_device *dt = container_of(kobj, struct dt_device,
1091 struct osp_device *osp = dt2osp_dev(dt);
1093 return snprintf(buf, PAGE_SIZE, "%u\n", osp->opd_reserved_ino_low);
1097 * Change low watermark
1099 static ssize_t reserved_ino_low_store(struct kobject *kobj,
1100 struct attribute *attr,
1104 struct dt_device *dt = container_of(kobj, struct dt_device,
1106 struct osp_device *osp = dt2osp_dev(dt);
1110 rc = kstrtouint(buffer, 0, &val);
1114 if (val & (1UL << 31))
1117 spin_lock(&osp->opd_pre_lock);
1118 osp->opd_reserved_ino_low = val;
1119 if (val >= osp->opd_reserved_ino_high)
1120 osp->opd_reserved_ino_high = val << 1;
1121 spin_unlock(&osp->opd_pre_lock);
1125 LUSTRE_RW_ATTR(reserved_ino_low);
1127 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
1128 const char *buffer, size_t count)
1130 struct dt_device *dt = container_of(kobj, struct dt_device,
1135 rc = lu_env_init(&env, LCT_LOCAL);
1139 rc = dt_sync(&env, dt);
1142 return rc == 0 ? count : rc;
1144 LUSTRE_WO_ATTR(force_sync);
1146 static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
1147 { .name = "connect_flags",
1148 .fops = &osp_connect_flags_fops },
1149 { .name = "ost_server_uuid",
1150 .fops = &osp_server_uuid_fops },
1151 { .name = "timeouts",
1152 .fops = &osp_timeouts_fops },
1154 .fops = &osp_import_fops },
1156 .fops = &osp_state_fops },
1160 static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
1161 { .name = "connect_flags",
1162 .fops = &osp_connect_flags_fops },
1163 { .name = "mdt_server_uuid",
1164 .fops = &osp_server_uuid_fops },
1165 { .name = "timeouts",
1166 .fops = &osp_timeouts_fops },
1168 .fops = &osp_import_fops },
1170 .fops = &osp_state_fops },
1171 { .name = "rpc_stats",
1172 .fops = &osp_rpc_stats_fops },
1176 static struct attribute *osp_obd_attrs[] = {
1177 /* First two for compatiability reasons */
1178 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1179 &lustre_attr_destroys_in_flight.attr,
1180 &lustre_attr_active.attr,
1181 &lustre_attr_max_rpcs_in_flight.attr,
1182 &lustre_attr_max_rpcs_in_progress.attr,
1183 &lustre_attr_maxage.attr,
1184 &lustre_attr_ost_conn_uuid.attr,
1185 &lustre_attr_ping.attr,
1186 &lustre_attr_prealloc_status.attr,
1187 &lustre_attr_prealloc_next_id.attr,
1188 &lustre_attr_prealloc_last_id.attr,
1189 &lustre_attr_prealloc_next_seq.attr,
1190 &lustre_attr_prealloc_last_seq.attr,
1191 &lustre_attr_prealloc_reserved.attr,
1192 &lustre_attr_prealloc_force_new_seq.attr,
1193 &lustre_attr_sync_in_flight.attr,
1194 &lustre_attr_sync_in_progress.attr,
1195 &lustre_attr_sync_changes.attr,
1196 &lustre_attr_max_sync_changes.attr,
1197 &lustre_attr_force_sync.attr,
1198 &lustre_attr_old_sync_processed.attr,
1199 &lustre_attr_create_count.attr,
1200 &lustre_attr_max_create_count.attr,
1201 &lustre_attr_reserved_mb_high.attr,
1202 &lustre_attr_reserved_mb_low.attr,
1203 &lustre_attr_reserved_ino_high.attr,
1204 &lustre_attr_reserved_ino_low.attr,
1208 KOBJ_ATTRIBUTE_GROUPS(osp_obd); /* creates osp_obd_groups from osp_obd_attrs */
1210 static struct attribute *osp_md_attrs[] = {
1211 /* First two for compatiability reasons */
1212 &lustre_attr_lfsck_max_rpcs_in_flight.attr,
1213 &lustre_attr_destroys_in_flight.attr,
1214 &lustre_attr_active.attr,
1215 &lustre_attr_max_rpcs_in_flight.attr,
1216 &lustre_attr_max_mod_rpcs_in_flight.attr,
1217 &lustre_attr_max_rpcs_in_progress.attr,
1218 &lustre_attr_maxage.attr,
1219 &lustre_attr_mdt_conn_uuid.attr,
1220 &lustre_attr_ping.attr,
1221 &lustre_attr_prealloc_status.attr,
1222 &lustre_attr_reserved_mb_high.attr,
1223 &lustre_attr_reserved_mb_low.attr,
1224 &lustre_attr_reserved_ino_high.attr,
1225 &lustre_attr_reserved_ino_low.attr,
1229 KOBJ_ATTRIBUTE_GROUPS(osp_md); /* creates osp_md_groups from osp_md_attrs */
1231 void osp_tunables_fini(struct osp_device *osp)
1233 struct obd_device *obd = osp->opd_obd;
1234 struct kobject *osc;
1236 osc = kset_find_obj(lustre_kset, "osc");
1238 sysfs_remove_link(osc, obd->obd_name);
1242 debugfs_remove_recursive(osp->opd_debugfs);
1243 osp->opd_debugfs = NULL;
1245 ptlrpc_lprocfs_unregister_obd(obd);
1247 debugfs_remove_recursive(obd->obd_debugfs_entry);
1248 obd->obd_debugfs_entry = NULL;
1250 dt_tunables_fini(&osp->opd_dt_dev);
1254 * Initialize OSP sysfs / debugfs
1256 * param[in] osp OSP device
1258 void osp_tunables_init(struct osp_device *osp)
1260 struct obd_device *obd = osp->opd_obd;
1261 struct kobject *osc;
1264 if (osp->opd_connect_mdt) {
1265 osp->opd_dt_dev.dd_ktype.default_groups =
1266 KOBJ_ATTR_GROUPS(osp_md);
1267 obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
1269 osp->opd_dt_dev.dd_ktype.default_groups =
1270 KOBJ_ATTR_GROUPS(osp_obd);
1271 obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
1274 rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
1277 CERROR("%s: failed to setup DT tunables: %d\n",
1282 /* Since we register the obd device with ptlrpc / sptlrpc we
1283 * have to register debugfs with obd_device
1285 obd->obd_debugfs_entry = debugfs_create_dir(
1286 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1287 ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
1289 sptlrpc_lprocfs_cliobd_attach(obd);
1290 ptlrpc_lprocfs_register_obd(obd);
1292 if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
1295 /* If the real OSC is present which is the case for setups
1296 * with both server and clients on the same node then use
1297 * the OSC's proc root
1299 osc = kset_find_obj(lustre_kset, "osc");
1301 rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
1306 osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
1307 "../osp/%s", obd->obd_name);
1308 if (!osp->opd_debugfs)
1309 CERROR("%s: failed to create OSC debugfs symlink\n",