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) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
35 #include <obd_support.h>
37 #include <lprocfs_status.h>
38 #include <lustre_net.h>
39 #include <obd_class.h>
40 #include "ptlrpc_internal.h"
43 static struct ll_rpc_opcode {
46 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
47 { OST_REPLY, "ost_reply" },
48 { OST_GETATTR, "ost_getattr" },
49 { OST_SETATTR, "ost_setattr" },
50 { OST_READ, "ost_read" },
51 { OST_WRITE, "ost_write" },
52 { OST_CREATE , "ost_create" },
53 { OST_DESTROY, "ost_destroy" },
54 { OST_GET_INFO, "ost_get_info" },
55 { OST_CONNECT, "ost_connect" },
56 { OST_DISCONNECT, "ost_disconnect" },
57 { OST_PUNCH, "ost_punch" },
58 { OST_OPEN, "ost_open" },
59 { OST_CLOSE, "ost_close" },
60 { OST_STATFS, "ost_statfs" },
61 { 14, NULL }, /* formerly OST_SAN_READ */
62 { 15, NULL }, /* formerly OST_SAN_WRITE */
63 { OST_SYNC, "ost_sync" },
64 { OST_SET_INFO, "ost_set_info" },
65 { OST_QUOTACHECK, "ost_quotacheck" },
66 { OST_QUOTACTL, "ost_quotactl" },
67 { OST_QUOTA_ADJUST_QUNIT, "ost_quota_adjust_qunit" },
68 { OST_LADVISE, "ost_ladvise" },
69 { MDS_GETATTR, "mds_getattr" },
70 { MDS_GETATTR_NAME, "mds_getattr_lock" },
71 { MDS_CLOSE, "mds_close" },
72 { MDS_REINT, "mds_reint" },
73 { MDS_READPAGE, "mds_readpage" },
74 { MDS_CONNECT, "mds_connect" },
75 { MDS_DISCONNECT, "mds_disconnect" },
76 { MDS_GET_ROOT, "mds_get_root" },
77 { MDS_STATFS, "mds_statfs" },
78 { MDS_PIN, "mds_pin" },
79 { MDS_UNPIN, "mds_unpin" },
80 { MDS_SYNC, "mds_sync" },
81 { MDS_DONE_WRITING, "mds_done_writing" },
82 { MDS_SET_INFO, "mds_set_info" },
83 { MDS_QUOTACHECK, "mds_quotacheck" },
84 { MDS_QUOTACTL, "mds_quotactl" },
85 { MDS_GETXATTR, "mds_getxattr" },
86 { MDS_SETXATTR, "mds_setxattr" },
87 { MDS_WRITEPAGE, "mds_writepage" },
88 { MDS_IS_SUBDIR, "mds_is_subdir" },
89 { MDS_GET_INFO, "mds_get_info" },
90 { MDS_HSM_STATE_GET, "mds_hsm_state_get" },
91 { MDS_HSM_STATE_SET, "mds_hsm_state_set" },
92 { MDS_HSM_ACTION, "mds_hsm_action" },
93 { MDS_HSM_PROGRESS, "mds_hsm_progress" },
94 { MDS_HSM_REQUEST, "mds_hsm_request" },
95 { MDS_HSM_CT_REGISTER, "mds_hsm_ct_register" },
96 { MDS_HSM_CT_UNREGISTER, "mds_hsm_ct_unregister" },
97 { MDS_SWAP_LAYOUTS, "mds_swap_layouts" },
98 { LDLM_ENQUEUE, "ldlm_enqueue" },
99 { LDLM_CONVERT, "ldlm_convert" },
100 { LDLM_CANCEL, "ldlm_cancel" },
101 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
102 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
103 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
104 { LDLM_SET_INFO, "ldlm_set_info" },
105 { MGS_CONNECT, "mgs_connect" },
106 { MGS_DISCONNECT, "mgs_disconnect" },
107 { MGS_EXCEPTION, "mgs_exception" },
108 { MGS_TARGET_REG, "mgs_target_reg" },
109 { MGS_TARGET_DEL, "mgs_target_del" },
110 { MGS_SET_INFO, "mgs_set_info" },
111 { MGS_CONFIG_READ, "mgs_config_read" },
112 { OBD_PING, "obd_ping" },
113 { 401, /* was OBD_LOG_CANCEL */ "llog_cancel" },
114 { 402, /* was OBD_QC_CALLBACK */ "obd_quota_callback" },
115 { OBD_IDX_READ, "dt_index_read" },
116 { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_open" },
117 { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block" },
118 { LLOG_ORIGIN_HANDLE_READ_HEADER,"llog_origin_handle_read_header" },
119 { 504, /*LLOG_ORIGIN_HANDLE_WRITE_REC*/"llog_origin_handle_write_rec" },
120 { 505, /* was LLOG_ORIGIN_HANDLE_CLOSE */ "llog_origin_handle_close" },
121 { 506, /* was LLOG_ORIGIN_CONNECT */ "llog_origin_connect" },
122 { 507, /* was LLOG_CATINFO */ "llog_catinfo" },
123 { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" },
124 { LLOG_ORIGIN_HANDLE_DESTROY, "llog_origin_handle_destroy" },
125 { QUOTA_DQACQ, "quota_acquire" },
126 { QUOTA_DQREL, "quota_release" },
127 { SEQ_QUERY, "seq_query" },
128 { SEC_CTX_INIT, "sec_ctx_init" },
129 { SEC_CTX_INIT_CONT,"sec_ctx_init_cont" },
130 { SEC_CTX_FINI, "sec_ctx_fini" },
131 { FLD_QUERY, "fld_query" },
132 { FLD_READ, "fld_read" },
133 { OUT_UPDATE, "out_update" },
134 { LFSCK_NOTIFY, "lfsck_notify" },
135 { LFSCK_QUERY, "lfsck_query" },
138 static struct ll_eopcode {
141 } ll_eopcode_table[EXTRA_LAST_OPC] = {
142 { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" },
143 { LDLM_PLAIN_ENQUEUE, "ldlm_plain_enqueue" },
144 { LDLM_EXTENT_ENQUEUE, "ldlm_extent_enqueue" },
145 { LDLM_FLOCK_ENQUEUE, "ldlm_flock_enqueue" },
146 { LDLM_IBITS_ENQUEUE, "ldlm_ibits_enqueue" },
147 { MDS_REINT_SETATTR, "mds_reint_setattr" },
148 { MDS_REINT_CREATE, "mds_reint_create" },
149 { MDS_REINT_LINK, "mds_reint_link" },
150 { MDS_REINT_UNLINK, "mds_reint_unlink" },
151 { MDS_REINT_RENAME, "mds_reint_rename" },
152 { MDS_REINT_OPEN, "mds_reint_open" },
153 { MDS_REINT_SETXATTR, "mds_reint_setxattr" },
154 { MDS_REINT_RESYNC, "mds_reint_resync" },
155 { BRW_READ_BYTES, "read_bytes" },
156 { BRW_WRITE_BYTES, "write_bytes" },
159 const char *ll_opcode2str(__u32 opcode)
161 /* When one of the assertions below fail, chances are that:
162 * 1) A new opcode was added in include/lustre/lustre_idl.h,
163 * but is missing from the table above.
164 * or 2) The opcode space was renumbered or rearranged,
165 * and the opcode_offset() function in
166 * ptlrpc_internal.h needs to be modified.
168 __u32 offset = opcode_offset(opcode);
169 LASSERTF(offset < LUSTRE_MAX_OPCODES,
170 "offset %u >= LUSTRE_MAX_OPCODES %u\n",
171 offset, LUSTRE_MAX_OPCODES);
172 LASSERTF(ll_rpc_opcode_table[offset].opcode == opcode,
173 "ll_rpc_opcode_table[%u].opcode %u != opcode %u\n",
174 offset, ll_rpc_opcode_table[offset].opcode, opcode);
175 return ll_rpc_opcode_table[offset].opname;
178 const int ll_str2opcode(const char *ops)
182 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
183 if (ll_rpc_opcode_table[i].opname != NULL &&
184 strcmp(ll_rpc_opcode_table[i].opname, ops) == 0)
185 return ll_rpc_opcode_table[i].opcode;
191 static const char *ll_eopcode2str(__u32 opcode)
193 LASSERT(ll_eopcode_table[opcode].opcode == opcode);
194 return ll_eopcode_table[opcode].opname;
198 ptlrpc_ldebugfs_register(struct dentry *root, char *dir, char *name,
199 struct dentry **debugfs_root_ret,
200 struct lprocfs_stats **stats_ret)
202 struct dentry *svc_debugfs_entry;
203 struct lprocfs_stats *svc_stats;
205 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
208 LASSERT(!*debugfs_root_ret);
209 LASSERT(!*stats_ret);
211 svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES,
217 svc_debugfs_entry = ldebugfs_register(dir, root, NULL, NULL);
218 if (IS_ERR(svc_debugfs_entry)) {
219 lprocfs_free_stats(&svc_stats);
223 svc_debugfs_entry = root;
226 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
227 svc_counter_config, "req_waittime", "usec");
228 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
229 svc_counter_config, "req_qdepth", "reqs");
230 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
231 svc_counter_config, "req_active", "reqs");
232 lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
233 svc_counter_config, "req_timeout", "sec");
234 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
235 svc_counter_config, "reqbuf_avail", "bufs");
236 for (i = 0; i < EXTRA_LAST_OPC; i++) {
240 case BRW_WRITE_BYTES:
248 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
250 ll_eopcode2str(i), units);
252 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
253 __u32 opcode = ll_rpc_opcode_table[i].opcode;
254 lprocfs_counter_init(svc_stats,
255 EXTRA_MAX_OPCODES + i, svc_counter_config,
256 ll_opcode2str(opcode), "usec");
259 rc = ldebugfs_register_stats(svc_debugfs_entry, name, svc_stats);
262 ldebugfs_remove(&svc_debugfs_entry);
263 lprocfs_free_stats(&svc_stats);
266 *debugfs_root_ret = svc_debugfs_entry;
267 *stats_ret = svc_stats;
272 ptlrpc_lprocfs_req_history_len_seq_show(struct seq_file *m, void *v)
274 struct ptlrpc_service *svc = m->private;
275 struct ptlrpc_service_part *svcpt;
279 ptlrpc_service_for_each_part(svcpt, i, svc)
280 total += svcpt->scp_hist_nrqbds;
282 seq_printf(m, "%d\n", total);
287 LDEBUGFS_SEQ_FOPS_RO(ptlrpc_lprocfs_req_history_len);
290 ptlrpc_lprocfs_req_history_max_seq_show(struct seq_file *m, void *n)
292 struct ptlrpc_service *svc = m->private;
293 struct ptlrpc_service_part *svcpt;
297 ptlrpc_service_for_each_part(svcpt, i, svc)
298 total += svc->srv_hist_nrqbds_cpt_max;
300 seq_printf(m, "%d\n", total);
305 ptlrpc_lprocfs_req_history_max_seq_write(struct file *file,
306 const char __user *buffer,
307 size_t count, loff_t *off)
309 struct seq_file *m = file->private_data;
310 struct ptlrpc_service *svc = m->private;
311 unsigned long long val;
312 unsigned long long limit;
316 rc = kstrtoull_from_user(buffer, count, 0, &val);
320 if (val < 0 || val > INT_MAX)
323 /* This sanity check is more of an insanity check; we can still
324 * hose a kernel by allowing the request history to grow too
325 * far. The roundup to the next power of two is an empirical way
326 * to take care that request buffer is allocated in Slab and thus
327 * will be upgraded */
328 bufpages = (roundup_pow_of_two(svc->srv_buf_size) + PAGE_SIZE - 1) >>
330 limit = cfs_totalram_pages() / (2 * bufpages);
331 /* do not allow history to consume more than half max number of rqbds */
332 if ((svc->srv_nrqbds_max == 0 && val > limit) ||
333 (svc->srv_nrqbds_max != 0 && val > svc->srv_nrqbds_max / 2))
336 spin_lock(&svc->srv_lock);
339 svc->srv_hist_nrqbds_cpt_max = 0;
341 svc->srv_hist_nrqbds_cpt_max =
342 max(1, ((int)val / svc->srv_ncpts));
344 spin_unlock(&svc->srv_lock);
349 LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
352 ptlrpc_lprocfs_req_buffers_max_seq_show(struct seq_file *m, void *n)
354 struct ptlrpc_service *svc = m->private;
356 seq_printf(m, "%d\n", svc->srv_nrqbds_max);
361 ptlrpc_lprocfs_req_buffers_max_seq_write(struct file *file,
362 const char __user *buffer,
363 size_t count, loff_t *off)
365 struct seq_file *m = file->private_data;
366 struct ptlrpc_service *svc = m->private;
370 rc = kstrtoint_from_user(buffer, count, 0, &val);
374 if (val < svc->srv_nbuf_per_group && val != 0)
377 spin_lock(&svc->srv_lock);
379 svc->srv_nrqbds_max = (uint)val;
381 spin_unlock(&svc->srv_lock);
386 LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_req_buffers_max);
388 static ssize_t threads_min_show(struct kobject *kobj, struct attribute *attr,
391 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
394 return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_init * svc->srv_ncpts);
397 static ssize_t threads_min_store(struct kobject *kobj, struct attribute *attr,
398 const char *buffer, size_t count)
400 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
405 rc = kstrtoul(buffer, 10, &val);
409 if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT)
412 spin_lock(&svc->srv_lock);
413 if (val > svc->srv_nthrs_cpt_limit * svc->srv_ncpts) {
414 spin_unlock(&svc->srv_lock);
418 svc->srv_nthrs_cpt_init = (int)val / svc->srv_ncpts;
420 spin_unlock(&svc->srv_lock);
424 LUSTRE_RW_ATTR(threads_min);
426 static ssize_t threads_started_show(struct kobject *kobj,
427 struct attribute *attr,
430 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
432 struct ptlrpc_service_part *svcpt;
436 ptlrpc_service_for_each_part(svcpt, i, svc)
437 total += svcpt->scp_nthrs_running;
439 return sprintf(buf, "%d\n", total);
441 LUSTRE_RO_ATTR(threads_started);
443 static ssize_t threads_max_show(struct kobject *kobj, struct attribute *attr,
446 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
449 return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_limit * svc->srv_ncpts);
452 static ssize_t threads_max_store(struct kobject *kobj, struct attribute *attr,
453 const char *buffer, size_t count)
455 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
460 rc = kstrtoul(buffer, 10, &val);
464 if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT)
467 spin_lock(&svc->srv_lock);
468 if (val < svc->srv_nthrs_cpt_init * svc->srv_ncpts) {
469 spin_unlock(&svc->srv_lock);
473 svc->srv_nthrs_cpt_limit = (int)val / svc->srv_ncpts;
475 spin_unlock(&svc->srv_lock);
479 LUSTRE_RW_ATTR(threads_max);
482 * Translates \e ptlrpc_nrs_pol_state values to human-readable strings.
484 * \param[in] state The policy state
486 static const char *nrs_state2str(enum ptlrpc_nrs_pol_state state)
491 case NRS_POL_STATE_INVALID:
493 case NRS_POL_STATE_STOPPED:
495 case NRS_POL_STATE_STOPPING:
497 case NRS_POL_STATE_STARTING:
499 case NRS_POL_STATE_STARTED:
505 * Obtains status information for \a policy.
507 * Information is copied in \a info.
509 * \param[in] policy The policy
510 * \param[out] info Holds returned status information
512 void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
513 struct ptlrpc_nrs_pol_info *info)
515 LASSERT(policy != NULL);
516 LASSERT(info != NULL);
517 assert_spin_locked(&policy->pol_nrs->nrs_lock);
519 CLASSERT(sizeof(info->pi_arg) == sizeof(policy->pol_arg));
520 memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX);
521 memcpy(info->pi_arg, policy->pol_arg, sizeof(policy->pol_arg));
523 info->pi_fallback = !!(policy->pol_flags & PTLRPC_NRS_FL_FALLBACK);
524 info->pi_state = policy->pol_state;
526 * XXX: These are accessed without holding
527 * ptlrpc_service_part::scp_req_lock.
529 info->pi_req_queued = policy->pol_req_queued;
530 info->pi_req_started = policy->pol_req_started;
534 * Reads and prints policy status information for all policies of a PTLRPC
537 static int ptlrpc_lprocfs_nrs_seq_show(struct seq_file *m, void *n)
539 struct ptlrpc_service *svc = m->private;
540 struct ptlrpc_service_part *svcpt;
541 struct ptlrpc_nrs *nrs;
542 struct ptlrpc_nrs_policy *policy;
543 struct ptlrpc_nrs_pol_info *infos;
544 struct ptlrpc_nrs_pol_info tmp;
546 unsigned pol_idx = 0;
553 * Serialize NRS core lprocfs operations with policy registration/
556 mutex_lock(&nrs_core.nrs_mutex);
559 * Use the first service partition's regular NRS head in order to obtain
560 * the number of policies registered with NRS heads of this service. All
561 * service partitions will have the same number of policies.
563 nrs = nrs_svcpt2nrs(svc->srv_parts[0], false);
565 spin_lock(&nrs->nrs_lock);
566 num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols;
567 spin_unlock(&nrs->nrs_lock);
569 OBD_ALLOC(infos, num_pols * sizeof(*infos));
571 GOTO(out, rc = -ENOMEM);
574 ptlrpc_service_for_each_part(svcpt, i, svc) {
575 nrs = nrs_svcpt2nrs(svcpt, hp);
576 spin_lock(&nrs->nrs_lock);
580 list_for_each_entry(policy, &nrs->nrs_policy_list,
582 LASSERT(pol_idx < num_pols);
584 nrs_policy_get_info_locked(policy, &tmp);
586 * Copy values when handling the first service
590 memcpy(infos[pol_idx].pi_name, tmp.pi_name,
592 memcpy(infos[pol_idx].pi_arg, tmp.pi_arg,
594 memcpy(&infos[pol_idx].pi_state, &tmp.pi_state,
595 sizeof(tmp.pi_state));
596 infos[pol_idx].pi_fallback = tmp.pi_fallback;
598 * For the rest of the service partitions
599 * sanity-check the values we get.
602 LASSERT(strncmp(infos[pol_idx].pi_name,
604 NRS_POL_NAME_MAX) == 0);
605 LASSERT(strncmp(infos[pol_idx].pi_arg,
607 sizeof(tmp.pi_arg)) == 0);
609 * Not asserting ptlrpc_nrs_pol_info::pi_state,
610 * because it may be different between
611 * instances of the same policy in different
612 * service partitions.
614 LASSERT(infos[pol_idx].pi_fallback ==
618 infos[pol_idx].pi_req_queued += tmp.pi_req_queued;
619 infos[pol_idx].pi_req_started += tmp.pi_req_started;
623 spin_unlock(&nrs->nrs_lock);
627 * Policy status information output is in YAML format.
643 * high_priority_requests:
656 seq_printf(m, "%s\n", !hp ? "\nregular_requests:" :
657 "high_priority_requests:");
659 for (pol_idx = 0; pol_idx < num_pols; pol_idx++) {
660 if (strlen(infos[pol_idx].pi_arg) > 0)
661 seq_printf(m, " - name: %s %s\n",
662 infos[pol_idx].pi_name,
663 infos[pol_idx].pi_arg);
665 seq_printf(m, " - name: %s\n",
666 infos[pol_idx].pi_name);
669 seq_printf(m, " state: %s\n"
672 " active: %-20d\n\n",
673 nrs_state2str(infos[pol_idx].pi_state),
674 infos[pol_idx].pi_fallback ? "yes" : "no",
675 (int)infos[pol_idx].pi_req_queued,
676 (int)infos[pol_idx].pi_req_started);
679 if (!hp && nrs_svc_has_hp(svc)) {
680 memset(infos, 0, num_pols * sizeof(*infos));
683 * Redo the processing for the service's HP NRS heads' policies.
691 OBD_FREE(infos, num_pols * sizeof(*infos));
693 mutex_unlock(&nrs_core.nrs_mutex);
699 #define LPROCFS_NRS_WR_MAX_ARG (1024)
701 * The longest valid command string is the maxium policy name size, plus the
702 * length of the " reg" substring, plus the lenght of argument
704 #define LPROCFS_NRS_WR_MAX_CMD (NRS_POL_NAME_MAX + sizeof(" reg") - 1 \
705 + LPROCFS_NRS_WR_MAX_ARG)
708 * Starts and stops a given policy on a PTLRPC service.
710 * Commands consist of the policy name, followed by an optional [reg|hp] token;
711 * if the optional token is omitted, the operation is performed on both the
712 * regular and high-priority (if the service has one) NRS head.
715 ptlrpc_lprocfs_nrs_seq_write(struct file *file, const char __user *buffer,
716 size_t count, loff_t *off)
718 struct seq_file *m = file->private_data;
719 struct ptlrpc_service *svc = m->private;
720 enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH;
722 char *cmd_copy = NULL;
728 if (count >= LPROCFS_NRS_WR_MAX_CMD)
729 GOTO(out, rc = -EINVAL);
731 OBD_ALLOC(cmd, LPROCFS_NRS_WR_MAX_CMD);
733 GOTO(out, rc = -ENOMEM);
735 * strsep() modifies its argument, so keep a copy
739 if (copy_from_user(cmd, buffer, count))
740 GOTO(out, rc = -EFAULT);
744 policy_name = strsep(&cmd, " ");
746 if (strlen(policy_name) > NRS_POL_NAME_MAX - 1)
747 GOTO(out, rc = -EINVAL);
750 * No [reg|hp] token has been specified
755 queue_name = strsep(&cmd, " ");
757 * The second token is either an optional [reg|hp] string,
760 if (strcmp(queue_name, "reg") == 0)
761 queue = PTLRPC_NRS_QUEUE_REG;
762 else if (strcmp(queue_name, "hp") == 0)
763 queue = PTLRPC_NRS_QUEUE_HP;
772 if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc))
773 GOTO(out, rc = -ENODEV);
774 else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc))
775 queue = PTLRPC_NRS_QUEUE_REG;
778 * Serialize NRS core lprocfs operations with policy registration/
781 mutex_lock(&nrs_core.nrs_mutex);
783 rc = ptlrpc_nrs_policy_control(svc, queue, policy_name,
784 PTLRPC_NRS_CTL_START,
787 mutex_unlock(&nrs_core.nrs_mutex);
790 OBD_FREE(cmd_copy, LPROCFS_NRS_WR_MAX_CMD);
792 RETURN(rc < 0 ? rc : count);
795 LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs);
799 struct ptlrpc_srh_iterator {
802 struct ptlrpc_request *srhi_req;
806 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service_part *svcpt,
807 struct ptlrpc_srh_iterator *srhi,
811 struct ptlrpc_request *req;
813 if (srhi->srhi_req != NULL &&
814 srhi->srhi_seq > svcpt->scp_hist_seq_culled &&
815 srhi->srhi_seq <= seq) {
816 /* If srhi_req was set previously, hasn't been culled and
817 * we're searching for a seq on or after it (i.e. more
818 * recent), search from it onwards.
819 * Since the service history is LRU (i.e. culled reqs will
820 * be near the head), we shouldn't have to do long
822 LASSERTF(srhi->srhi_seq == srhi->srhi_req->rq_history_seq,
823 "%s:%d: seek seq %llu, request seq %llu\n",
824 svcpt->scp_service->srv_name, svcpt->scp_cpt,
825 srhi->srhi_seq, srhi->srhi_req->rq_history_seq);
826 LASSERTF(!list_empty(&svcpt->scp_hist_reqs),
827 "%s:%d: seek offset %llu, request seq %llu, "
828 "last culled %llu\n",
829 svcpt->scp_service->srv_name, svcpt->scp_cpt,
830 seq, srhi->srhi_seq, svcpt->scp_hist_seq_culled);
831 e = &srhi->srhi_req->rq_history_list;
833 /* search from start */
834 e = svcpt->scp_hist_reqs.next;
837 while (e != &svcpt->scp_hist_reqs) {
838 req = list_entry(e, struct ptlrpc_request, rq_history_list);
840 if (req->rq_history_seq >= seq) {
841 srhi->srhi_seq = req->rq_history_seq;
842 srhi->srhi_req = req;
852 * ptlrpc history sequence is used as "position" of seq_file, in some case,
853 * seq_read() will increase "position" to indicate reading the next
854 * element, however, low bits of history sequence are reserved for CPT id
855 * (check the details from comments before ptlrpc_req_add_history), which
856 * means seq_read() might change CPT id of history sequence and never
857 * finish reading of requests on a CPT. To make it work, we have to shift
858 * CPT id to high bits and timestamp to low bits, so seq_read() will only
859 * increase timestamp which can correctly indicate the next position.
862 /* convert seq_file pos to cpt */
863 #define PTLRPC_REQ_POS2CPT(svc, pos) \
864 ((svc)->srv_cpt_bits == 0 ? 0 : \
865 (__u64)(pos) >> (64 - (svc)->srv_cpt_bits))
867 /* make up seq_file pos from cpt */
868 #define PTLRPC_REQ_CPT2POS(svc, cpt) \
869 ((svc)->srv_cpt_bits == 0 ? 0 : \
870 (cpt) << (64 - (svc)->srv_cpt_bits))
872 /* convert sequence to position */
873 #define PTLRPC_REQ_SEQ2POS(svc, seq) \
874 ((svc)->srv_cpt_bits == 0 ? (seq) : \
875 ((seq) >> (svc)->srv_cpt_bits) | \
876 ((seq) << (64 - (svc)->srv_cpt_bits)))
878 /* convert position to sequence */
879 #define PTLRPC_REQ_POS2SEQ(svc, pos) \
880 ((svc)->srv_cpt_bits == 0 ? (pos) : \
881 ((__u64)(pos) << (svc)->srv_cpt_bits) | \
882 ((__u64)(pos) >> (64 - (svc)->srv_cpt_bits)))
885 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
887 struct ptlrpc_service *svc = s->private;
888 struct ptlrpc_service_part *svcpt;
889 struct ptlrpc_srh_iterator *srhi;
894 if (sizeof(loff_t) != sizeof(__u64)) { /* can't support */
895 CWARN("Failed to read request history because size of loff_t "
896 "%d can't match size of u64\n", (int)sizeof(loff_t));
900 OBD_ALLOC(srhi, sizeof(*srhi));
905 srhi->srhi_req = NULL;
907 cpt = PTLRPC_REQ_POS2CPT(svc, *pos);
909 ptlrpc_service_for_each_part(svcpt, i, svc) {
910 if (i < cpt) /* skip */
912 if (i > cpt) /* make up the lowest position for this CPT */
913 *pos = PTLRPC_REQ_CPT2POS(svc, i);
915 mutex_lock(&svcpt->scp_mutex);
916 spin_lock(&svcpt->scp_lock);
917 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi,
918 PTLRPC_REQ_POS2SEQ(svc, *pos));
919 spin_unlock(&svcpt->scp_lock);
920 mutex_unlock(&svcpt->scp_mutex);
922 *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq);
928 OBD_FREE(srhi, sizeof(*srhi));
933 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
935 struct ptlrpc_srh_iterator *srhi = iter;
938 OBD_FREE(srhi, sizeof(*srhi));
942 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
943 void *iter, loff_t *pos)
945 struct ptlrpc_service *svc = s->private;
946 struct ptlrpc_srh_iterator *srhi = iter;
947 struct ptlrpc_service_part *svcpt;
952 for (i = srhi->srhi_idx; i < svc->srv_ncpts; i++) {
953 svcpt = svc->srv_parts[i];
955 if (i > srhi->srhi_idx) { /* reset iterator for a new CPT */
956 srhi->srhi_req = NULL;
957 seq = srhi->srhi_seq = 0;
958 } else { /* the next sequence */
959 seq = srhi->srhi_seq + (1 << svc->srv_cpt_bits);
962 mutex_lock(&svcpt->scp_mutex);
963 spin_lock(&svcpt->scp_lock);
964 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, seq);
965 spin_unlock(&svcpt->scp_lock);
966 mutex_unlock(&svcpt->scp_mutex);
968 *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq);
974 OBD_FREE(srhi, sizeof(*srhi));
978 /* common ost/mdt so_req_printer */
979 void target_print_req(void *seq_file, struct ptlrpc_request *req)
981 /* Called holding srv_lock with irqs disabled.
982 * Print specific req contents and a newline.
983 * CAVEAT EMPTOR: check request message length before printing!!!
984 * You might have received any old crap so you must be just as
985 * careful here as the service's request parser!!! */
986 struct seq_file *sf = seq_file;
988 switch (req->rq_phase) {
990 /* still awaiting a service thread's attention, or rejected
991 * because the generic request message didn't unpack */
992 seq_printf(sf, "<not swabbed>\n");
994 case RQ_PHASE_INTERPRET:
995 /* being handled, so basic msg swabbed, and opc is valid
996 * but racing with mds_handle() */
997 case RQ_PHASE_COMPLETE:
998 /* been handled by mds_handle() reply state possibly still
1000 seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg));
1003 DEBUG_REQ(D_ERROR, req, "bad phase %d", req->rq_phase);
1006 EXPORT_SYMBOL(target_print_req);
1008 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
1010 struct ptlrpc_service *svc = s->private;
1011 struct ptlrpc_srh_iterator *srhi = iter;
1012 struct ptlrpc_service_part *svcpt;
1013 struct ptlrpc_request *req;
1016 LASSERT(srhi->srhi_idx < svc->srv_ncpts);
1018 svcpt = svc->srv_parts[srhi->srhi_idx];
1020 mutex_lock(&svcpt->scp_mutex);
1021 spin_lock(&svcpt->scp_lock);
1023 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, srhi->srhi_seq);
1026 struct timespec64 arrival, sent, arrivaldiff;
1027 char nidstr[LNET_NIDSTR_SIZE];
1029 req = srhi->srhi_req;
1031 libcfs_nid2str_r(req->rq_self, nidstr, sizeof(nidstr));
1032 arrival.tv_sec = req->rq_arrival_time.tv_sec;
1033 arrival.tv_nsec = req->rq_arrival_time.tv_nsec;
1034 sent.tv_sec = req->rq_sent;
1036 arrivaldiff = timespec64_sub(sent, arrival);
1038 /* Print common req fields.
1039 * CAVEAT EMPTOR: we're racing with the service handler
1040 * here. The request could contain any old crap, so you
1041 * must be just as careful as the service's request
1042 * parser. Currently I only print stuff here I know is OK
1043 * to look at coz it was set up in request_in_callback()!!!
1045 seq_printf(s, "%lld:%s:%s:x%llu:%d:%s:%lld.%06lld:%lld.%06llds(%+lld.0s) ",
1046 req->rq_history_seq, nidstr,
1047 libcfs_id2str(req->rq_peer), req->rq_xid,
1048 req->rq_reqlen, ptlrpc_rqphase2str(req),
1049 (s64)req->rq_arrival_time.tv_sec,
1050 (s64)(req->rq_arrival_time.tv_nsec / NSEC_PER_USEC),
1051 (s64)arrivaldiff.tv_sec,
1052 (s64)(arrivaldiff.tv_nsec / NSEC_PER_USEC),
1053 (s64)(req->rq_sent - req->rq_deadline));
1054 if (svc->srv_ops.so_req_printer == NULL)
1055 seq_printf(s, "\n");
1057 svc->srv_ops.so_req_printer(s, srhi->srhi_req);
1060 spin_unlock(&svcpt->scp_lock);
1061 mutex_unlock(&svcpt->scp_mutex);
1067 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
1069 static struct seq_operations sops = {
1070 .start = ptlrpc_lprocfs_svc_req_history_start,
1071 .stop = ptlrpc_lprocfs_svc_req_history_stop,
1072 .next = ptlrpc_lprocfs_svc_req_history_next,
1073 .show = ptlrpc_lprocfs_svc_req_history_show,
1075 struct seq_file *seqf;
1078 rc = LPROCFS_ENTRY_CHECK(inode);
1082 rc = seq_open(file, &sops);
1086 seqf = file->private_data;
1087 seqf->private = inode->i_private;
1091 /* See also lprocfs_rd_timeouts */
1092 static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n)
1094 struct ptlrpc_service *svc = m->private;
1095 struct ptlrpc_service_part *svcpt;
1102 seq_printf(m, "adaptive timeouts off, using obd_timeout %u\n",
1107 ptlrpc_service_for_each_part(svcpt, i, svc) {
1108 cur = at_get(&svcpt->scp_at_estimate);
1109 worst = svcpt->scp_at_estimate.at_worst_ever;
1110 worstt = svcpt->scp_at_estimate.at_worst_time;
1112 seq_printf(m, "%10s : cur %3u worst %3u (at %lld, %llds ago) ",
1113 "service", cur, worst, (s64)worstt,
1114 (s64)(ktime_get_real_seconds() - worstt));
1116 lprocfs_at_hist_helper(m, &svcpt->scp_at_estimate);
1122 LDEBUGFS_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts);
1124 static ssize_t high_priority_ratio_show(struct kobject *kobj,
1125 struct attribute *attr,
1128 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
1131 return sprintf(buf, "%d\n", svc->srv_hpreq_ratio);
1134 static ssize_t high_priority_ratio_store(struct kobject *kobj,
1135 struct attribute *attr,
1139 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
1144 rc = kstrtoul(buffer, 10, &val);
1148 spin_lock(&svc->srv_lock);
1149 svc->srv_hpreq_ratio = val;
1150 spin_unlock(&svc->srv_lock);
1154 LUSTRE_RW_ATTR(high_priority_ratio);
1156 static struct attribute *ptlrpc_svc_attrs[] = {
1157 &lustre_attr_threads_min.attr,
1158 &lustre_attr_threads_started.attr,
1159 &lustre_attr_threads_max.attr,
1160 &lustre_attr_high_priority_ratio.attr,
1164 static void ptlrpc_sysfs_svc_release(struct kobject *kobj)
1166 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
1169 complete(&svc->srv_kobj_unregister);
1172 static struct kobj_type ptlrpc_svc_ktype = {
1173 .default_attrs = ptlrpc_svc_attrs,
1174 .sysfs_ops = &lustre_sysfs_ops,
1175 .release = ptlrpc_sysfs_svc_release,
1178 void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc)
1180 /* Let's see if we had a chance at initialization first */
1181 if (svc->srv_kobj.kset) {
1182 kobject_put(&svc->srv_kobj);
1183 wait_for_completion(&svc->srv_kobj_unregister);
1187 int ptlrpc_sysfs_register_service(struct kset *parent,
1188 struct ptlrpc_service *svc)
1190 svc->srv_kobj.kset = parent;
1191 init_completion(&svc->srv_kobj_unregister);
1192 return kobject_init_and_add(&svc->srv_kobj, &ptlrpc_svc_ktype,
1193 &parent->kobj, "%s", svc->srv_name);
1196 void ptlrpc_ldebugfs_register_service(struct dentry *entry,
1197 struct ptlrpc_service *svc)
1199 struct lprocfs_vars lproc_vars[] = {
1200 { .name = "req_buffer_history_len",
1201 .fops = &ptlrpc_lprocfs_req_history_len_fops,
1203 { .name = "req_buffer_history_max",
1204 .fops = &ptlrpc_lprocfs_req_history_max_fops,
1206 { .name = "timeouts",
1207 .fops = &ptlrpc_lprocfs_timeouts_fops,
1209 { .name = "nrs_policies",
1210 .fops = &ptlrpc_lprocfs_nrs_fops,
1212 { .name = "req_buffers_max",
1213 .fops = &ptlrpc_lprocfs_req_buffers_max_fops,
1217 static struct file_operations req_history_fops = {
1218 .owner = THIS_MODULE,
1219 .open = ptlrpc_lprocfs_svc_req_history_open,
1221 .llseek = seq_lseek,
1222 .release = lprocfs_seq_release,
1227 ptlrpc_ldebugfs_register(entry, svc->srv_name, "stats",
1228 &svc->srv_debugfs_entry, &svc->srv_stats);
1229 if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
1232 ldebugfs_add_vars(svc->srv_debugfs_entry, lproc_vars, NULL);
1234 rc = ldebugfs_seq_create(svc->srv_debugfs_entry, "req_history",
1235 0400, &req_history_fops, svc);
1237 CWARN("Error adding the req_history file\n");
1240 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
1242 ptlrpc_ldebugfs_register(obddev->obd_debugfs_entry, NULL, "stats",
1243 &obddev->obd_svc_debugfs_entry,
1244 &obddev->obd_svc_stats);
1246 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
1248 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req, long amount)
1250 struct lprocfs_stats *svc_stats;
1251 __u32 op = lustre_msg_get_opc(req->rq_reqmsg);
1252 int opc = opcode_offset(op);
1254 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
1255 if (svc_stats == NULL || opc <= 0)
1257 LASSERT(opc < LUSTRE_MAX_OPCODES);
1258 if (!(op == LDLM_ENQUEUE || op == MDS_REINT))
1259 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, amount);
1262 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes)
1264 struct lprocfs_stats *svc_stats;
1267 if (!req->rq_import)
1269 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
1272 idx = lustre_msg_get_opc(req->rq_reqmsg);
1275 idx = BRW_READ_BYTES + PTLRPC_LAST_CNTR;
1278 idx = BRW_WRITE_BYTES + PTLRPC_LAST_CNTR;
1281 LASSERTF(0, "unsupported opcode %u\n", idx);
1285 lprocfs_counter_add(svc_stats, idx, bytes);
1288 EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
1290 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
1292 if (!IS_ERR_OR_NULL(svc->srv_debugfs_entry))
1293 ldebugfs_remove(&svc->srv_debugfs_entry);
1296 lprocfs_free_stats(&svc->srv_stats);
1299 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
1301 /* cleanup first to allow concurrent access to device's
1302 * stats via debugfs to complete safely
1304 lprocfs_obd_cleanup(obd);
1306 if (!IS_ERR_OR_NULL(obd->obd_svc_debugfs_entry))
1307 ldebugfs_remove(&obd->obd_svc_debugfs_entry);
1309 if (obd->obd_svc_stats)
1310 lprocfs_free_stats(&obd->obd_svc_stats);
1312 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
1314 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
1317 struct obd_device *obd = container_of(kobj, struct obd_device,
1319 struct ptlrpc_request *req;
1323 LPROCFS_CLIMP_CHECK(obd);
1324 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
1325 LPROCFS_CLIMP_EXIT(obd);
1329 req->rq_send_state = LUSTRE_IMP_FULL;
1331 rc = ptlrpc_queue_wait(req);
1332 ptlrpc_req_finished(req);
1336 EXPORT_SYMBOL(ping_show);
1338 /* kept for older verison of tools. */
1339 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
1340 const char *buffer, size_t count)
1342 return ping_show(kobj, attr, (char *)buffer);
1344 EXPORT_SYMBOL(ping_store);
1346 /* Write the connection UUID to this file to attempt to connect to that node.
1347 * The connection UUID is a node's primary NID. For example,
1348 * "echo connection=192.168.0.1@tcp0::instance > .../import".
1351 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1352 size_t count, loff_t *off)
1354 struct seq_file *m = file->private_data;
1355 struct obd_device *obd = m->private;
1356 struct obd_import *imp = obd->u.cli.cl_import;
1361 const char prefix[] = "connection=";
1362 const int prefix_len = sizeof(prefix) - 1;
1364 if (count > PAGE_SIZE - 1 || count <= prefix_len)
1367 OBD_ALLOC(kbuf, count + 1);
1371 if (copy_from_user(kbuf, buffer, count))
1372 GOTO(out, count = -EFAULT);
1376 /* only support connection=uuid::instance now */
1377 if (strncmp(prefix, kbuf, prefix_len) != 0)
1378 GOTO(out, count = -EINVAL);
1380 uuid = kbuf + prefix_len;
1381 ptr = strstr(uuid, "::");
1388 ptr += 2; /* Skip :: */
1389 rc = kstrtouint(ptr, 10, &inst);
1391 CERROR("config: wrong instance # %s\n", ptr);
1392 } else if (inst != imp->imp_connect_data.ocd_instance) {
1393 CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted "
1394 "target(%u/%u), reconnecting...\n",
1395 imp->imp_obd->obd_name,
1396 imp->imp_connect_data.ocd_instance, inst);
1399 CDEBUG(D_INFO, "IR: %s has already been connecting to "
1401 imp->imp_obd->obd_name, inst);
1406 ptlrpc_recover_import(imp, uuid, 1);
1409 OBD_FREE(kbuf, count + 1);
1412 EXPORT_SYMBOL(lprocfs_import_seq_write);
1414 int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *n)
1416 struct obd_device *obd = m->private;
1417 struct obd_import *imp = obd->u.cli.cl_import;
1419 LPROCFS_CLIMP_CHECK(obd);
1420 seq_printf(m, "%d\n", !imp->imp_no_pinger_recover);
1421 LPROCFS_CLIMP_EXIT(obd);
1424 EXPORT_SYMBOL(lprocfs_pinger_recov_seq_show);
1427 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1428 size_t count, loff_t *off)
1430 struct seq_file *m = file->private_data;
1431 struct obd_device *obd = m->private;
1432 struct client_obd *cli = &obd->u.cli;
1433 struct obd_import *imp = cli->cl_import;
1437 rc = kstrtobool_from_user(buffer, count, &val);
1441 LPROCFS_CLIMP_CHECK(obd);
1442 spin_lock(&imp->imp_lock);
1443 imp->imp_no_pinger_recover = !val;
1444 spin_unlock(&imp->imp_lock);
1445 LPROCFS_CLIMP_EXIT(obd);
1448 EXPORT_SYMBOL(lprocfs_pinger_recov_seq_write);