Merge remote-tracking branch 'staging/staging-next'
[deliverable/linux.git] / drivers / staging / lustre / lustre / ptlrpc / lproc_ptlrpc.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
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).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 19 *
d7e09d03
PT
20 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
1dc563a6 26 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
27 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32#define DEBUG_SUBSYSTEM S_CLASS
33
e27db149
GKH
34#include "../include/obd_support.h"
35#include "../include/obd.h"
36#include "../include/lprocfs_status.h"
37#include "../include/lustre/lustre_idl.h"
38#include "../include/lustre_net.h"
39#include "../include/obd_class.h"
d7e09d03
PT
40#include "ptlrpc_internal.h"
41
b3c986d3 42static struct ll_rpc_opcode {
2a763282
KM
43 __u32 opcode;
44 const char *opname;
d7e09d03
PT
45} ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
46 { OST_REPLY, "ost_reply" },
47 { OST_GETATTR, "ost_getattr" },
48 { OST_SETATTR, "ost_setattr" },
49 { OST_READ, "ost_read" },
50 { OST_WRITE, "ost_write" },
b2952d62 51 { OST_CREATE, "ost_create" },
d7e09d03
PT
52 { OST_DESTROY, "ost_destroy" },
53 { OST_GET_INFO, "ost_get_info" },
54 { OST_CONNECT, "ost_connect" },
55 { OST_DISCONNECT, "ost_disconnect" },
56 { OST_PUNCH, "ost_punch" },
57 { OST_OPEN, "ost_open" },
58 { OST_CLOSE, "ost_close" },
59 { OST_STATFS, "ost_statfs" },
60 { 14, NULL }, /* formerly OST_SAN_READ */
61 { 15, NULL }, /* formerly OST_SAN_WRITE */
62 { OST_SYNC, "ost_sync" },
63 { OST_SET_INFO, "ost_set_info" },
64 { OST_QUOTACHECK, "ost_quotacheck" },
65 { OST_QUOTACTL, "ost_quotactl" },
66 { OST_QUOTA_ADJUST_QUNIT, "ost_quota_adjust_qunit" },
67 { MDS_GETATTR, "mds_getattr" },
68 { MDS_GETATTR_NAME, "mds_getattr_lock" },
69 { MDS_CLOSE, "mds_close" },
70 { MDS_REINT, "mds_reint" },
71 { MDS_READPAGE, "mds_readpage" },
72 { MDS_CONNECT, "mds_connect" },
73 { MDS_DISCONNECT, "mds_disconnect" },
74 { MDS_GETSTATUS, "mds_getstatus" },
75 { MDS_STATFS, "mds_statfs" },
76 { MDS_PIN, "mds_pin" },
77 { MDS_UNPIN, "mds_unpin" },
78 { MDS_SYNC, "mds_sync" },
79 { MDS_DONE_WRITING, "mds_done_writing" },
80 { MDS_SET_INFO, "mds_set_info" },
81 { MDS_QUOTACHECK, "mds_quotacheck" },
82 { MDS_QUOTACTL, "mds_quotactl" },
83 { MDS_GETXATTR, "mds_getxattr" },
84 { MDS_SETXATTR, "mds_setxattr" },
85 { MDS_WRITEPAGE, "mds_writepage" },
86 { MDS_IS_SUBDIR, "mds_is_subdir" },
87 { MDS_GET_INFO, "mds_get_info" },
88 { MDS_HSM_STATE_GET, "mds_hsm_state_get" },
89 { MDS_HSM_STATE_SET, "mds_hsm_state_set" },
90 { MDS_HSM_ACTION, "mds_hsm_action" },
91 { MDS_HSM_PROGRESS, "mds_hsm_progress" },
92 { MDS_HSM_REQUEST, "mds_hsm_request" },
93 { MDS_HSM_CT_REGISTER, "mds_hsm_ct_register" },
94 { MDS_HSM_CT_UNREGISTER, "mds_hsm_ct_unregister" },
95 { MDS_SWAP_LAYOUTS, "mds_swap_layouts" },
96 { LDLM_ENQUEUE, "ldlm_enqueue" },
97 { LDLM_CONVERT, "ldlm_convert" },
98 { LDLM_CANCEL, "ldlm_cancel" },
99 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
100 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
101 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
102 { LDLM_SET_INFO, "ldlm_set_info" },
103 { MGS_CONNECT, "mgs_connect" },
104 { MGS_DISCONNECT, "mgs_disconnect" },
105 { MGS_EXCEPTION, "mgs_exception" },
106 { MGS_TARGET_REG, "mgs_target_reg" },
107 { MGS_TARGET_DEL, "mgs_target_del" },
108 { MGS_SET_INFO, "mgs_set_info" },
109 { MGS_CONFIG_READ, "mgs_config_read" },
110 { OBD_PING, "obd_ping" },
65f1c781 111 { OBD_LOG_CANCEL, "llog_cancel" },
d7e09d03
PT
112 { OBD_QC_CALLBACK, "obd_quota_callback" },
113 { OBD_IDX_READ, "dt_index_read" },
65f1c781 114 { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_open" },
d7e09d03 115 { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block" },
1d8cb70c 116 { LLOG_ORIGIN_HANDLE_READ_HEADER, "llog_origin_handle_read_header" },
d7e09d03
PT
117 { LLOG_ORIGIN_HANDLE_WRITE_REC, "llog_origin_handle_write_rec" },
118 { LLOG_ORIGIN_HANDLE_CLOSE, "llog_origin_handle_close" },
119 { LLOG_ORIGIN_CONNECT, "llog_origin_connect" },
120 { LLOG_CATINFO, "llog_catinfo" },
121 { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" },
122 { LLOG_ORIGIN_HANDLE_DESTROY, "llog_origin_handle_destroy" },
123 { QUOTA_DQACQ, "quota_acquire" },
124 { QUOTA_DQREL, "quota_release" },
125 { SEQ_QUERY, "seq_query" },
126 { SEC_CTX_INIT, "sec_ctx_init" },
1d8cb70c 127 { SEC_CTX_INIT_CONT, "sec_ctx_init_cont" },
d7e09d03
PT
128 { SEC_CTX_FINI, "sec_ctx_fini" },
129 { FLD_QUERY, "fld_query" },
b78c2b9b 130 { FLD_READ, "fld_read" },
d7e09d03
PT
131};
132
b3c986d3 133static struct ll_eopcode {
2a763282
KM
134 __u32 opcode;
135 const char *opname;
d7e09d03
PT
136} ll_eopcode_table[EXTRA_LAST_OPC] = {
137 { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" },
138 { LDLM_PLAIN_ENQUEUE, "ldlm_plain_enqueue" },
139 { LDLM_EXTENT_ENQUEUE, "ldlm_extent_enqueue" },
140 { LDLM_FLOCK_ENQUEUE, "ldlm_flock_enqueue" },
141 { LDLM_IBITS_ENQUEUE, "ldlm_ibits_enqueue" },
142 { MDS_REINT_SETATTR, "mds_reint_setattr" },
143 { MDS_REINT_CREATE, "mds_reint_create" },
144 { MDS_REINT_LINK, "mds_reint_link" },
145 { MDS_REINT_UNLINK, "mds_reint_unlink" },
146 { MDS_REINT_RENAME, "mds_reint_rename" },
147 { MDS_REINT_OPEN, "mds_reint_open" },
148 { MDS_REINT_SETXATTR, "mds_reint_setxattr" },
149 { BRW_READ_BYTES, "read_bytes" },
150 { BRW_WRITE_BYTES, "write_bytes" },
151};
152
153const char *ll_opcode2str(__u32 opcode)
154{
155 /* When one of the assertions below fail, chances are that:
156 * 1) A new opcode was added in include/lustre/lustre_idl.h,
157 * but is missing from the table above.
158 * or 2) The opcode space was renumbered or rearranged,
159 * and the opcode_offset() function in
160 * ptlrpc_internal.h needs to be modified.
161 */
162 __u32 offset = opcode_offset(opcode);
50ffcb7e 163
d7e09d03
PT
164 LASSERTF(offset < LUSTRE_MAX_OPCODES,
165 "offset %u >= LUSTRE_MAX_OPCODES %u\n",
166 offset, LUSTRE_MAX_OPCODES);
167 LASSERTF(ll_rpc_opcode_table[offset].opcode == opcode,
168 "ll_rpc_opcode_table[%u].opcode %u != opcode %u\n",
169 offset, ll_rpc_opcode_table[offset].opcode, opcode);
170 return ll_rpc_opcode_table[offset].opname;
171}
172
b3c986d3 173static const char *ll_eopcode2str(__u32 opcode)
d7e09d03
PT
174{
175 LASSERT(ll_eopcode_table[opcode].opcode == opcode);
176 return ll_eopcode_table[opcode].opname;
177}
b3c986d3 178
700815d4
DE
179static void
180ptlrpc_ldebugfs_register(struct dentry *root, char *dir,
181 char *name,
182 struct dentry **debugfs_root_ret,
183 struct lprocfs_stats **stats_ret)
d7e09d03 184{
700815d4 185 struct dentry *svc_debugfs_entry;
d7e09d03
PT
186 struct lprocfs_stats *svc_stats;
187 int i, rc;
188 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
189 LPROCFS_CNTR_STDDEV;
190
8b382089
OD
191 LASSERT(!*debugfs_root_ret);
192 LASSERT(!*stats_ret);
d7e09d03 193
cd94f231 194 svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES,
1d8cb70c 195 0);
8b382089 196 if (!svc_stats)
d7e09d03
PT
197 return;
198
8b382089 199 if (dir) {
700815d4
DE
200 svc_debugfs_entry = ldebugfs_register(dir, root, NULL, NULL);
201 if (IS_ERR(svc_debugfs_entry)) {
d7e09d03
PT
202 lprocfs_free_stats(&svc_stats);
203 return;
204 }
205 } else {
700815d4 206 svc_debugfs_entry = root;
d7e09d03
PT
207 }
208
209 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
210 svc_counter_config, "req_waittime", "usec");
211 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
212 svc_counter_config, "req_qdepth", "reqs");
213 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
214 svc_counter_config, "req_active", "reqs");
215 lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
216 svc_counter_config, "req_timeout", "sec");
217 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
218 svc_counter_config, "reqbuf_avail", "bufs");
219 for (i = 0; i < EXTRA_LAST_OPC; i++) {
220 char *units;
221
3949015e 222 switch (i) {
d7e09d03
PT
223 case BRW_WRITE_BYTES:
224 case BRW_READ_BYTES:
225 units = "bytes";
226 break;
227 default:
228 units = "reqs";
229 break;
230 }
231 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
232 svc_counter_config,
233 ll_eopcode2str(i), units);
234 }
235 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
236 __u32 opcode = ll_rpc_opcode_table[i].opcode;
50ffcb7e 237
d7e09d03
PT
238 lprocfs_counter_init(svc_stats,
239 EXTRA_MAX_OPCODES + i, svc_counter_config,
240 ll_opcode2str(opcode), "usec");
241 }
242
700815d4 243 rc = ldebugfs_register_stats(svc_debugfs_entry, name, svc_stats);
d7e09d03 244 if (rc < 0) {
8b382089 245 if (dir)
700815d4 246 ldebugfs_remove(&svc_debugfs_entry);
d7e09d03
PT
247 lprocfs_free_stats(&svc_stats);
248 } else {
8b382089 249 if (dir)
700815d4 250 *debugfs_root_ret = svc_debugfs_entry;
d7e09d03
PT
251 *stats_ret = svc_stats;
252 }
253}
254
255static int
73bb1da6 256ptlrpc_lprocfs_req_history_len_seq_show(struct seq_file *m, void *v)
d7e09d03 257{
73bb1da6 258 struct ptlrpc_service *svc = m->private;
d7e09d03 259 struct ptlrpc_service_part *svcpt;
d0bfef31
CH
260 int total = 0;
261 int i;
d7e09d03 262
d7e09d03
PT
263 ptlrpc_service_for_each_part(svcpt, i, svc)
264 total += svcpt->scp_hist_nrqbds;
265
8faeebdf
JP
266 seq_printf(m, "%d\n", total);
267 return 0;
d7e09d03 268}
c9f6bb96 269
73bb1da6 270LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_req_history_len);
d7e09d03
PT
271
272static int
73bb1da6 273ptlrpc_lprocfs_req_history_max_seq_show(struct seq_file *m, void *n)
d7e09d03 274{
73bb1da6 275 struct ptlrpc_service *svc = m->private;
d7e09d03 276 struct ptlrpc_service_part *svcpt;
d0bfef31
CH
277 int total = 0;
278 int i;
d7e09d03 279
d7e09d03
PT
280 ptlrpc_service_for_each_part(svcpt, i, svc)
281 total += svc->srv_hist_nrqbds_cpt_max;
282
8faeebdf
JP
283 seq_printf(m, "%d\n", total);
284 return 0;
d7e09d03
PT
285}
286
73bb1da6 287static ssize_t
e84962e3 288ptlrpc_lprocfs_req_history_max_seq_write(struct file *file,
d0bfef31
CH
289 const char __user *buffer,
290 size_t count, loff_t *off)
d7e09d03 291{
73bb1da6 292 struct ptlrpc_service *svc = ((struct seq_file *)file->private_data)->private;
d0bfef31
CH
293 int bufpages;
294 int val;
295 int rc;
d7e09d03
PT
296
297 rc = lprocfs_write_helper(buffer, count, &val);
298 if (rc < 0)
299 return rc;
300
301 if (val < 0)
302 return -ERANGE;
303
304 /* This sanity check is more of an insanity check; we can still
305 * hose a kernel by allowing the request history to grow too
dadfcdab
OD
306 * far.
307 */
09cbfeaf 308 bufpages = (svc->srv_buf_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
4f6cc9ab 309 if (val > totalram_pages / (2 * bufpages))
d7e09d03
PT
310 return -ERANGE;
311
312 spin_lock(&svc->srv_lock);
313
314 if (val == 0)
315 svc->srv_hist_nrqbds_cpt_max = 0;
316 else
317 svc->srv_hist_nrqbds_cpt_max = max(1, (val / svc->srv_ncpts));
318
319 spin_unlock(&svc->srv_lock);
320
321 return count;
322}
c9f6bb96 323
73bb1da6 324LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
d7e09d03 325
673a6796
OD
326static ssize_t threads_min_show(struct kobject *kobj, struct attribute *attr,
327 char *buf)
d7e09d03 328{
673a6796
OD
329 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
330 srv_kobj);
d7e09d03 331
673a6796 332 return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_init * svc->srv_ncpts);
d7e09d03
PT
333}
334
673a6796
OD
335static ssize_t threads_min_store(struct kobject *kobj, struct attribute *attr,
336 const char *buffer, size_t count)
d7e09d03 337{
673a6796
OD
338 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
339 srv_kobj);
340 unsigned long val;
341 int rc = kstrtoul(buffer, 10, &val);
d7e09d03
PT
342
343 if (rc < 0)
344 return rc;
345
346 if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT)
347 return -ERANGE;
348
349 spin_lock(&svc->srv_lock);
350 if (val > svc->srv_nthrs_cpt_limit * svc->srv_ncpts) {
351 spin_unlock(&svc->srv_lock);
352 return -ERANGE;
353 }
354
355 svc->srv_nthrs_cpt_init = val / svc->srv_ncpts;
356
357 spin_unlock(&svc->srv_lock);
358
359 return count;
360}
673a6796 361LUSTRE_RW_ATTR(threads_min);
d7e09d03 362
673a6796
OD
363static ssize_t threads_started_show(struct kobject *kobj,
364 struct attribute *attr,
365 char *buf)
d7e09d03 366{
673a6796
OD
367 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
368 srv_kobj);
d7e09d03 369 struct ptlrpc_service_part *svcpt;
673a6796
OD
370 int total = 0;
371 int i;
d7e09d03
PT
372
373 ptlrpc_service_for_each_part(svcpt, i, svc)
374 total += svcpt->scp_nthrs_running;
375
673a6796 376 return sprintf(buf, "%d\n", total);
d7e09d03 377}
673a6796 378LUSTRE_RO_ATTR(threads_started);
d7e09d03 379
673a6796
OD
380static ssize_t threads_max_show(struct kobject *kobj, struct attribute *attr,
381 char *buf)
d7e09d03 382{
673a6796
OD
383 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
384 srv_kobj);
d7e09d03 385
673a6796 386 return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_limit * svc->srv_ncpts);
d7e09d03
PT
387}
388
673a6796
OD
389static ssize_t threads_max_store(struct kobject *kobj, struct attribute *attr,
390 const char *buffer, size_t count)
d7e09d03 391{
673a6796
OD
392 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
393 srv_kobj);
394 unsigned long val;
395 int rc = kstrtoul(buffer, 10, &val);
d7e09d03
PT
396
397 if (rc < 0)
398 return rc;
399
400 if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT)
401 return -ERANGE;
402
403 spin_lock(&svc->srv_lock);
404 if (val < svc->srv_nthrs_cpt_init * svc->srv_ncpts) {
405 spin_unlock(&svc->srv_lock);
406 return -ERANGE;
407 }
408
409 svc->srv_nthrs_cpt_limit = val / svc->srv_ncpts;
410
411 spin_unlock(&svc->srv_lock);
412
413 return count;
414}
673a6796 415LUSTRE_RW_ATTR(threads_max);
d7e09d03
PT
416
417/**
418 * \addtogoup nrs
419 * @{
420 */
d7e09d03
PT
421
422/**
423 * Translates \e ptlrpc_nrs_pol_state values to human-readable strings.
424 *
425 * \param[in] state The policy state
426 */
427static const char *nrs_state2str(enum ptlrpc_nrs_pol_state state)
428{
429 switch (state) {
430 default:
431 LBUG();
432 case NRS_POL_STATE_INVALID:
433 return "invalid";
434 case NRS_POL_STATE_STOPPED:
435 return "stopped";
436 case NRS_POL_STATE_STOPPING:
437 return "stopping";
438 case NRS_POL_STATE_STARTING:
439 return "starting";
440 case NRS_POL_STATE_STARTED:
441 return "started";
442 }
443}
444
445/**
446 * Obtains status information for \a policy.
447 *
448 * Information is copied in \a info.
449 *
450 * \param[in] policy The policy
451 * \param[out] info Holds returned status information
452 */
96135461 453static void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
30c0aa39 454 struct ptlrpc_nrs_pol_info *info)
d7e09d03 455{
5e42bc9d 456 assert_spin_locked(&policy->pol_nrs->nrs_lock);
d7e09d03
PT
457
458 memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX);
459
460 info->pi_fallback = !!(policy->pol_flags & PTLRPC_NRS_FL_FALLBACK);
461 info->pi_state = policy->pol_state;
462 /**
463 * XXX: These are accessed without holding
464 * ptlrpc_service_part::scp_req_lock.
465 */
466 info->pi_req_queued = policy->pol_req_queued;
467 info->pi_req_started = policy->pol_req_started;
468}
469
470/**
471 * Reads and prints policy status information for all policies of a PTLRPC
472 * service.
473 */
73bb1da6 474static int ptlrpc_lprocfs_nrs_seq_show(struct seq_file *m, void *n)
d7e09d03 475{
d0bfef31
CH
476 struct ptlrpc_service *svc = m->private;
477 struct ptlrpc_service_part *svcpt;
478 struct ptlrpc_nrs *nrs;
479 struct ptlrpc_nrs_policy *policy;
480 struct ptlrpc_nrs_pol_info *infos;
481 struct ptlrpc_nrs_pol_info tmp;
482 unsigned num_pols;
483 unsigned pol_idx = 0;
484 bool hp = false;
485 int i;
486 int rc = 0;
d7e09d03
PT
487
488 /**
489 * Serialize NRS core lprocfs operations with policy registration/
490 * unregistration.
491 */
492 mutex_lock(&nrs_core.nrs_mutex);
493
494 /**
495 * Use the first service partition's regular NRS head in order to obtain
496 * the number of policies registered with NRS heads of this service. All
497 * service partitions will have the same number of policies.
498 */
499 nrs = nrs_svcpt2nrs(svc->srv_parts[0], false);
500
501 spin_lock(&nrs->nrs_lock);
502 num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols;
503 spin_unlock(&nrs->nrs_lock);
504
9ae10597 505 infos = kcalloc(num_pols, sizeof(*infos), GFP_NOFS);
8b382089 506 if (!infos) {
a9b3e8f3 507 rc = -ENOMEM;
848e90c3 508 goto unlock;
a9b3e8f3 509 }
d7e09d03
PT
510again:
511
512 ptlrpc_service_for_each_part(svcpt, i, svc) {
513 nrs = nrs_svcpt2nrs(svcpt, hp);
514 spin_lock(&nrs->nrs_lock);
515
516 pol_idx = 0;
517
30c0aa39 518 list_for_each_entry(policy, &nrs->nrs_policy_list, pol_list) {
d7e09d03
PT
519 LASSERT(pol_idx < num_pols);
520
521 nrs_policy_get_info_locked(policy, &tmp);
522 /**
523 * Copy values when handling the first service
524 * partition.
525 */
526 if (i == 0) {
527 memcpy(infos[pol_idx].pi_name, tmp.pi_name,
528 NRS_POL_NAME_MAX);
529 memcpy(&infos[pol_idx].pi_state, &tmp.pi_state,
530 sizeof(tmp.pi_state));
531 infos[pol_idx].pi_fallback = tmp.pi_fallback;
532 /**
533 * For the rest of the service partitions
534 * sanity-check the values we get.
535 */
536 } else {
537 LASSERT(strncmp(infos[pol_idx].pi_name,
538 tmp.pi_name,
539 NRS_POL_NAME_MAX) == 0);
540 /**
541 * Not asserting ptlrpc_nrs_pol_info::pi_state,
542 * because it may be different between
543 * instances of the same policy in different
544 * service partitions.
545 */
546 LASSERT(infos[pol_idx].pi_fallback ==
547 tmp.pi_fallback);
548 }
549
550 infos[pol_idx].pi_req_queued += tmp.pi_req_queued;
551 infos[pol_idx].pi_req_started += tmp.pi_req_started;
552
553 pol_idx++;
554 }
555 spin_unlock(&nrs->nrs_lock);
556 }
557
558 /**
559 * Policy status information output is in YAML format.
560 * For example:
561 *
562 * regular_requests:
563 * - name: fifo
564 * state: started
565 * fallback: yes
566 * queued: 0
567 * active: 0
568 *
569 * - name: crrn
570 * state: started
571 * fallback: no
572 * queued: 2015
573 * active: 384
574 *
575 * high_priority_requests:
576 * - name: fifo
577 * state: started
578 * fallback: yes
579 * queued: 0
580 * active: 2
581 *
582 * - name: crrn
583 * state: stopped
584 * fallback: no
585 * queued: 0
586 * active: 0
587 */
73bb1da6 588 seq_printf(m, "%s\n",
30c0aa39 589 !hp ? "\nregular_requests:" : "high_priority_requests:");
d7e09d03
PT
590
591 for (pol_idx = 0; pol_idx < num_pols; pol_idx++) {
73bb1da6 592 seq_printf(m, " - name: %s\n"
d7e09d03
PT
593 " state: %s\n"
594 " fallback: %s\n"
595 " queued: %-20d\n"
596 " active: %-20d\n\n",
597 infos[pol_idx].pi_name,
598 nrs_state2str(infos[pol_idx].pi_state),
599 infos[pol_idx].pi_fallback ? "yes" : "no",
600 (int)infos[pol_idx].pi_req_queued,
601 (int)infos[pol_idx].pi_req_started);
d7e09d03
PT
602 }
603
604 if (!hp && nrs_svc_has_hp(svc)) {
605 memset(infos, 0, num_pols * sizeof(*infos));
606
607 /**
608 * Redo the processing for the service's HP NRS heads' policies.
609 */
610 hp = true;
611 goto again;
612 }
613
848e90c3
JL
614 kfree(infos);
615unlock:
d7e09d03
PT
616 mutex_unlock(&nrs_core.nrs_mutex);
617
0a3bdb00 618 return rc;
d7e09d03
PT
619}
620
621/**
b6da17f3 622 * The longest valid command string is the maximum policy name size, plus the
d7e09d03
PT
623 * length of the " reg" substring
624 */
625#define LPROCFS_NRS_WR_MAX_CMD (NRS_POL_NAME_MAX + sizeof(" reg") - 1)
626
627/**
628 * Starts and stops a given policy on a PTLRPC service.
629 *
630 * Commands consist of the policy name, followed by an optional [reg|hp] token;
631 * if the optional token is omitted, the operation is performed on both the
632 * regular and high-priority (if the service has one) NRS head.
633 */
29dd4f9b 634static ssize_t ptlrpc_lprocfs_nrs_seq_write(struct file *file,
d0bfef31
CH
635 const char __user *buffer,
636 size_t count, loff_t *off)
d7e09d03 637{
73bb1da6 638 struct ptlrpc_service *svc = ((struct seq_file *)file->private_data)->private;
d0bfef31
CH
639 enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH;
640 char *cmd;
641 char *cmd_copy = NULL;
642 char *token;
643 int rc = 0;
d7e09d03 644
848e90c3
JL
645 if (count >= LPROCFS_NRS_WR_MAX_CMD)
646 return -EINVAL;
d7e09d03 647
9ae10597 648 cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS);
597851ac 649 if (!cmd)
848e90c3 650 return -ENOMEM;
d7e09d03
PT
651 /**
652 * strsep() modifies its argument, so keep a copy
653 */
654 cmd_copy = cmd;
655
a9b3e8f3
JL
656 if (copy_from_user(cmd, buffer, count)) {
657 rc = -EFAULT;
658 goto out;
659 }
d7e09d03
PT
660
661 cmd[count] = '\0';
662
663 token = strsep(&cmd, " ");
664
a9b3e8f3
JL
665 if (strlen(token) > NRS_POL_NAME_MAX - 1) {
666 rc = -EINVAL;
667 goto out;
668 }
d7e09d03
PT
669
670 /**
671 * No [reg|hp] token has been specified
672 */
8b382089 673 if (!cmd)
d7e09d03
PT
674 goto default_queue;
675
676 /**
677 * The second token is either NULL, or an optional [reg|hp] string
678 */
da5ecb4d 679 if (strcmp(cmd, "reg") == 0) {
d7e09d03 680 queue = PTLRPC_NRS_QUEUE_REG;
da5ecb4d 681 } else if (strcmp(cmd, "hp") == 0) {
d7e09d03 682 queue = PTLRPC_NRS_QUEUE_HP;
da5ecb4d 683 } else {
a9b3e8f3
JL
684 rc = -EINVAL;
685 goto out;
686 }
d7e09d03
PT
687
688default_queue:
689
a9b3e8f3
JL
690 if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc)) {
691 rc = -ENODEV;
692 goto out;
da5ecb4d 693 } else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc)) {
d7e09d03 694 queue = PTLRPC_NRS_QUEUE_REG;
da5ecb4d 695 }
d7e09d03
PT
696
697 /**
698 * Serialize NRS core lprocfs operations with policy registration/
699 * unregistration.
700 */
701 mutex_lock(&nrs_core.nrs_mutex);
702
703 rc = ptlrpc_nrs_policy_control(svc, queue, token, PTLRPC_NRS_CTL_START,
704 false, NULL);
705
706 mutex_unlock(&nrs_core.nrs_mutex);
707out:
848e90c3 708 kfree(cmd_copy);
d7e09d03 709
0a3bdb00 710 return rc < 0 ? rc : count;
d7e09d03 711}
c9f6bb96 712
73bb1da6 713LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs);
d7e09d03
PT
714
715/** @} nrs */
716
717struct ptlrpc_srh_iterator {
718 int srhi_idx;
719 __u64 srhi_seq;
720 struct ptlrpc_request *srhi_req;
721};
722
b3c986d3 723static int
d7e09d03
PT
724ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service_part *svcpt,
725 struct ptlrpc_srh_iterator *srhi,
726 __u64 seq)
727{
d0bfef31
CH
728 struct list_head *e;
729 struct ptlrpc_request *req;
d7e09d03 730
8b382089 731 if (srhi->srhi_req && srhi->srhi_seq > svcpt->scp_hist_seq_culled &&
d7e09d03
PT
732 srhi->srhi_seq <= seq) {
733 /* If srhi_req was set previously, hasn't been culled and
734 * we're searching for a seq on or after it (i.e. more
735 * recent), search from it onwards.
736 * Since the service history is LRU (i.e. culled reqs will
737 * be near the head), we shouldn't have to do long
dadfcdab
OD
738 * re-scans
739 */
d7e09d03 740 LASSERTF(srhi->srhi_seq == srhi->srhi_req->rq_history_seq,
b0f5aad5 741 "%s:%d: seek seq %llu, request seq %llu\n",
d7e09d03
PT
742 svcpt->scp_service->srv_name, svcpt->scp_cpt,
743 srhi->srhi_seq, srhi->srhi_req->rq_history_seq);
744 LASSERTF(!list_empty(&svcpt->scp_hist_reqs),
2d00bd17 745 "%s:%d: seek offset %llu, request seq %llu, last culled %llu\n",
d7e09d03
PT
746 svcpt->scp_service->srv_name, svcpt->scp_cpt,
747 seq, srhi->srhi_seq, svcpt->scp_hist_seq_culled);
748 e = &srhi->srhi_req->rq_history_list;
749 } else {
750 /* search from start */
751 e = svcpt->scp_hist_reqs.next;
752 }
753
754 while (e != &svcpt->scp_hist_reqs) {
755 req = list_entry(e, struct ptlrpc_request, rq_history_list);
756
757 if (req->rq_history_seq >= seq) {
758 srhi->srhi_seq = req->rq_history_seq;
759 srhi->srhi_req = req;
760 return 0;
761 }
762 e = e->next;
763 }
764
765 return -ENOENT;
766}
767
768/*
769 * ptlrpc history sequence is used as "position" of seq_file, in some case,
770 * seq_read() will increase "position" to indicate reading the next
771 * element, however, low bits of history sequence are reserved for CPT id
772 * (check the details from comments before ptlrpc_req_add_history), which
773 * means seq_read() might change CPT id of history sequence and never
774 * finish reading of requests on a CPT. To make it work, we have to shift
775 * CPT id to high bits and timestamp to low bits, so seq_read() will only
776 * increase timestamp which can correctly indicate the next position.
777 */
778
779/* convert seq_file pos to cpt */
780#define PTLRPC_REQ_POS2CPT(svc, pos) \
781 ((svc)->srv_cpt_bits == 0 ? 0 : \
782 (__u64)(pos) >> (64 - (svc)->srv_cpt_bits))
783
784/* make up seq_file pos from cpt */
785#define PTLRPC_REQ_CPT2POS(svc, cpt) \
786 ((svc)->srv_cpt_bits == 0 ? 0 : \
787 (cpt) << (64 - (svc)->srv_cpt_bits))
788
789/* convert sequence to position */
790#define PTLRPC_REQ_SEQ2POS(svc, seq) \
791 ((svc)->srv_cpt_bits == 0 ? (seq) : \
792 ((seq) >> (svc)->srv_cpt_bits) | \
793 ((seq) << (64 - (svc)->srv_cpt_bits)))
794
795/* convert position to sequence */
796#define PTLRPC_REQ_POS2SEQ(svc, pos) \
797 ((svc)->srv_cpt_bits == 0 ? (pos) : \
798 ((__u64)(pos) << (svc)->srv_cpt_bits) | \
799 ((__u64)(pos) >> (64 - (svc)->srv_cpt_bits)))
800
801static void *
802ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
803{
804 struct ptlrpc_service *svc = s->private;
805 struct ptlrpc_service_part *svcpt;
806 struct ptlrpc_srh_iterator *srhi;
807 unsigned int cpt;
808 int rc;
809 int i;
810
811 if (sizeof(loff_t) != sizeof(__u64)) { /* can't support */
2d00bd17
JP
812 CWARN("Failed to read request history because size of loff_t %d can't match size of u64\n",
813 (int)sizeof(loff_t));
d7e09d03
PT
814 return NULL;
815 }
816
9ae10597 817 srhi = kzalloc(sizeof(*srhi), GFP_NOFS);
597851ac 818 if (!srhi)
d7e09d03
PT
819 return NULL;
820
821 srhi->srhi_seq = 0;
822 srhi->srhi_req = NULL;
823
824 cpt = PTLRPC_REQ_POS2CPT(svc, *pos);
825
826 ptlrpc_service_for_each_part(svcpt, i, svc) {
827 if (i < cpt) /* skip */
828 continue;
829 if (i > cpt) /* make up the lowest position for this CPT */
830 *pos = PTLRPC_REQ_CPT2POS(svc, i);
831
832 spin_lock(&svcpt->scp_lock);
833 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi,
834 PTLRPC_REQ_POS2SEQ(svc, *pos));
835 spin_unlock(&svcpt->scp_lock);
836 if (rc == 0) {
837 *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq);
838 srhi->srhi_idx = i;
839 return srhi;
840 }
841 }
842
9ae10597 843 kfree(srhi);
d7e09d03
PT
844 return NULL;
845}
846
847static void
848ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
849{
850 struct ptlrpc_srh_iterator *srhi = iter;
851
848e90c3 852 kfree(srhi);
d7e09d03
PT
853}
854
855static void *
856ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
857 void *iter, loff_t *pos)
858{
d0bfef31
CH
859 struct ptlrpc_service *svc = s->private;
860 struct ptlrpc_srh_iterator *srhi = iter;
861 struct ptlrpc_service_part *svcpt;
862 __u64 seq;
863 int rc;
864 int i;
d7e09d03
PT
865
866 for (i = srhi->srhi_idx; i < svc->srv_ncpts; i++) {
867 svcpt = svc->srv_parts[i];
868
869 if (i > srhi->srhi_idx) { /* reset iterator for a new CPT */
870 srhi->srhi_req = NULL;
3d2b8f57
NC
871 seq = 0;
872 srhi->srhi_seq = 0;
d7e09d03
PT
873 } else { /* the next sequence */
874 seq = srhi->srhi_seq + (1 << svc->srv_cpt_bits);
875 }
876
877 spin_lock(&svcpt->scp_lock);
878 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, seq);
879 spin_unlock(&svcpt->scp_lock);
880 if (rc == 0) {
881 *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq);
882 srhi->srhi_idx = i;
883 return srhi;
884 }
885 }
886
9ae10597 887 kfree(srhi);
d7e09d03
PT
888 return NULL;
889}
890
d7e09d03
PT
891static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
892{
d0bfef31
CH
893 struct ptlrpc_service *svc = s->private;
894 struct ptlrpc_srh_iterator *srhi = iter;
895 struct ptlrpc_service_part *svcpt;
896 struct ptlrpc_request *req;
897 int rc;
d7e09d03
PT
898
899 LASSERT(srhi->srhi_idx < svc->srv_ncpts);
900
901 svcpt = svc->srv_parts[srhi->srhi_idx];
902
903 spin_lock(&svcpt->scp_lock);
904
905 rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, srhi->srhi_seq);
906
907 if (rc == 0) {
80feb1ef
DE
908 char nidstr[LNET_NIDSTR_SIZE];
909
d7e09d03
PT
910 req = srhi->srhi_req;
911
80feb1ef 912 libcfs_nid2str_r(req->rq_self, nidstr, sizeof(nidstr));
d7e09d03
PT
913 /* Print common req fields.
914 * CAVEAT EMPTOR: we're racing with the service handler
915 * here. The request could contain any old crap, so you
916 * must be just as careful as the service's request
917 * parser. Currently I only print stuff here I know is OK
dadfcdab
OD
918 * to look at coz it was set up in request_in_callback()!!!
919 */
219e6de6 920 seq_printf(s, "%lld:%s:%s:x%llu:%d:%s:%lld:%lds(%+lds) ",
80feb1ef 921 req->rq_history_seq, nidstr,
d7e09d03
PT
922 libcfs_id2str(req->rq_peer), req->rq_xid,
923 req->rq_reqlen, ptlrpc_rqphase2str(req),
219e6de6
AB
924 (s64)req->rq_arrival_time.tv_sec,
925 (long)(req->rq_sent - req->rq_arrival_time.tv_sec),
926 (long)(req->rq_sent - req->rq_deadline));
8b382089 927 if (!svc->srv_ops.so_req_printer)
8d816fb6 928 seq_putc(s, '\n');
d7e09d03
PT
929 else
930 svc->srv_ops.so_req_printer(s, srhi->srhi_req);
931 }
932
933 spin_unlock(&svcpt->scp_lock);
934 return rc;
935}
936
937static int
938ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
939{
faac7a8d 940 static const struct seq_operations sops = {
d7e09d03
PT
941 .start = ptlrpc_lprocfs_svc_req_history_start,
942 .stop = ptlrpc_lprocfs_svc_req_history_stop,
943 .next = ptlrpc_lprocfs_svc_req_history_next,
944 .show = ptlrpc_lprocfs_svc_req_history_show,
945 };
d0bfef31
CH
946 struct seq_file *seqf;
947 int rc;
d7e09d03 948
d7e09d03 949 rc = seq_open(file, &sops);
73bb1da6 950 if (rc)
d7e09d03 951 return rc;
d7e09d03
PT
952
953 seqf = file->private_data;
700815d4 954 seqf->private = inode->i_private;
d7e09d03
PT
955 return 0;
956}
957
958/* See also lprocfs_rd_timeouts */
73bb1da6 959static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n)
d7e09d03 960{
d0bfef31
CH
961 struct ptlrpc_service *svc = m->private;
962 struct ptlrpc_service_part *svcpt;
963 struct dhms ts;
0ac0478b 964 time64_t worstt;
d0bfef31
CH
965 unsigned int cur;
966 unsigned int worst;
967 int i;
d7e09d03
PT
968
969 if (AT_OFF) {
73bb1da6 970 seq_printf(m, "adaptive timeouts off, using obd_timeout %u\n",
30c0aa39 971 obd_timeout);
73bb1da6 972 return 0;
d7e09d03
PT
973 }
974
975 ptlrpc_service_for_each_part(svcpt, i, svc) {
976 cur = at_get(&svcpt->scp_at_estimate);
977 worst = svcpt->scp_at_estimate.at_worst_ever;
978 worstt = svcpt->scp_at_estimate.at_worst_time;
0ac0478b 979 s2dhms(&ts, ktime_get_real_seconds() - worstt);
d7e09d03 980
0ac0478b 981 seq_printf(m, "%10s : cur %3u worst %3u (at %lld, "
30c0aa39
OD
982 DHMS_FMT " ago) ", "service",
983 cur, worst, (s64)worstt, DHMS_VARS(&ts));
73bb1da6
PT
984
985 lprocfs_at_hist_helper(m, &svcpt->scp_at_estimate);
d7e09d03
PT
986 }
987
73bb1da6 988 return 0;
d7e09d03 989}
c9f6bb96 990
73bb1da6 991LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts);
d7e09d03 992
b40881e5
OD
993static ssize_t high_priority_ratio_show(struct kobject *kobj,
994 struct attribute *attr,
995 char *buf)
d7e09d03 996{
b40881e5
OD
997 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
998 srv_kobj);
999 return sprintf(buf, "%d\n", svc->srv_hpreq_ratio);
d7e09d03
PT
1000}
1001
b40881e5
OD
1002static ssize_t high_priority_ratio_store(struct kobject *kobj,
1003 struct attribute *attr,
1004 const char *buffer,
1005 size_t count)
d7e09d03 1006{
b40881e5
OD
1007 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
1008 srv_kobj);
1009 int rc;
b815555d 1010 int val;
d7e09d03 1011
b815555d 1012 rc = kstrtoint(buffer, 10, &val);
d7e09d03
PT
1013 if (rc < 0)
1014 return rc;
1015
1016 if (val < 0)
1017 return -ERANGE;
1018
1019 spin_lock(&svc->srv_lock);
1020 svc->srv_hpreq_ratio = val;
1021 spin_unlock(&svc->srv_lock);
1022
1023 return count;
1024}
b40881e5 1025LUSTRE_RW_ATTR(high_priority_ratio);
d7e09d03 1026
328676f8 1027static struct attribute *ptlrpc_svc_attrs[] = {
673a6796
OD
1028 &lustre_attr_threads_min.attr,
1029 &lustre_attr_threads_started.attr,
1030 &lustre_attr_threads_max.attr,
b40881e5 1031 &lustre_attr_high_priority_ratio.attr,
328676f8
OD
1032 NULL,
1033};
1034
1035static void ptlrpc_sysfs_svc_release(struct kobject *kobj)
1036{
1037 struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
1038 srv_kobj);
1039
1040 complete(&svc->srv_kobj_unregister);
1041}
1042
1043static struct kobj_type ptlrpc_svc_ktype = {
1044 .default_attrs = ptlrpc_svc_attrs,
1045 .sysfs_ops = &lustre_sysfs_ops,
1046 .release = ptlrpc_sysfs_svc_release,
1047};
1048
1049void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc)
1050{
1051 /* Let's see if we had a chance at initialization first */
1052 if (svc->srv_kobj.kset) {
1053 kobject_put(&svc->srv_kobj);
1054 wait_for_completion(&svc->srv_kobj_unregister);
1055 }
1056}
1057
1058int ptlrpc_sysfs_register_service(struct kset *parent,
1059 struct ptlrpc_service *svc)
1060{
1061 int rc;
1062
1063 svc->srv_kobj.kset = parent;
1064 init_completion(&svc->srv_kobj_unregister);
1065 rc = kobject_init_and_add(&svc->srv_kobj, &ptlrpc_svc_ktype, NULL,
1066 "%s", svc->srv_name);
1067
1068 return rc;
1069}
1070
700815d4
DE
1071void ptlrpc_ldebugfs_register_service(struct dentry *entry,
1072 struct ptlrpc_service *svc)
d7e09d03
PT
1073{
1074 struct lprocfs_vars lproc_vars[] = {
d7e09d03 1075 {.name = "req_buffer_history_len",
73bb1da6 1076 .fops = &ptlrpc_lprocfs_req_history_len_fops,
d7e09d03
PT
1077 .data = svc},
1078 {.name = "req_buffer_history_max",
73bb1da6 1079 .fops = &ptlrpc_lprocfs_req_history_max_fops,
d7e09d03 1080 .data = svc},
d7e09d03 1081 {.name = "timeouts",
73bb1da6 1082 .fops = &ptlrpc_lprocfs_timeouts_fops,
d7e09d03
PT
1083 .data = svc},
1084 {.name = "nrs_policies",
73bb1da6 1085 .fops = &ptlrpc_lprocfs_nrs_fops,
d7e09d03
PT
1086 .data = svc},
1087 {NULL}
1088 };
dddf4c23 1089 static const struct file_operations req_history_fops = {
d7e09d03
PT
1090 .owner = THIS_MODULE,
1091 .open = ptlrpc_lprocfs_svc_req_history_open,
1092 .read = seq_read,
1093 .llseek = seq_lseek,
1094 .release = lprocfs_seq_release,
1095 };
1096
1097 int rc;
1098
700815d4
DE
1099 ptlrpc_ldebugfs_register(entry, svc->srv_name,
1100 "stats", &svc->srv_debugfs_entry,
1101 &svc->srv_stats);
d7e09d03 1102
8b382089 1103 if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
d7e09d03
PT
1104 return;
1105
700815d4 1106 ldebugfs_add_vars(svc->srv_debugfs_entry, lproc_vars, NULL);
d7e09d03 1107
700815d4
DE
1108 rc = ldebugfs_seq_create(svc->srv_debugfs_entry, "req_history",
1109 0400, &req_history_fops, svc);
d7e09d03
PT
1110 if (rc)
1111 CWARN("Error adding the req_history file\n");
1112}
1113
1114void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
1115{
61e87ab0
DE
1116 ptlrpc_ldebugfs_register(obddev->obd_debugfs_entry, NULL, "stats",
1117 &obddev->obd_svc_debugfs_entry,
1118 &obddev->obd_svc_stats);
d7e09d03
PT
1119}
1120EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
1121
1122void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req, long amount)
1123{
1124 struct lprocfs_stats *svc_stats;
1125 __u32 op = lustre_msg_get_opc(req->rq_reqmsg);
1126 int opc = opcode_offset(op);
1127
1128 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
8b382089 1129 if (!svc_stats || opc <= 0)
d7e09d03
PT
1130 return;
1131 LASSERT(opc < LUSTRE_MAX_OPCODES);
1132 if (!(op == LDLM_ENQUEUE || op == MDS_REINT))
1133 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, amount);
1134}
1135
1136void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes)
1137{
1138 struct lprocfs_stats *svc_stats;
1139 int idx;
1140
1141 if (!req->rq_import)
1142 return;
1143 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
1144 if (!svc_stats)
1145 return;
1146 idx = lustre_msg_get_opc(req->rq_reqmsg);
1147 switch (idx) {
1148 case OST_READ:
1149 idx = BRW_READ_BYTES + PTLRPC_LAST_CNTR;
1150 break;
1151 case OST_WRITE:
1152 idx = BRW_WRITE_BYTES + PTLRPC_LAST_CNTR;
1153 break;
1154 default:
1155 LASSERTF(0, "unsupported opcode %u\n", idx);
1156 break;
1157 }
1158
1159 lprocfs_counter_add(svc_stats, idx, bytes);
1160}
d7e09d03
PT
1161EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
1162
1163void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
1164{
8b382089 1165 if (!IS_ERR_OR_NULL(svc->srv_debugfs_entry))
700815d4 1166 ldebugfs_remove(&svc->srv_debugfs_entry);
d7e09d03
PT
1167
1168 if (svc->srv_stats)
1169 lprocfs_free_stats(&svc->srv_stats);
1170}
1171
1172void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
1173{
61e87ab0
DE
1174 if (!IS_ERR_OR_NULL(obd->obd_svc_debugfs_entry))
1175 ldebugfs_remove(&obd->obd_svc_debugfs_entry);
d7e09d03
PT
1176
1177 if (obd->obd_svc_stats)
1178 lprocfs_free_stats(&obd->obd_svc_stats);
1179}
1180EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
1181
d7e09d03
PT
1182#undef BUFLEN
1183
e84962e3 1184int lprocfs_wr_ping(struct file *file, const char __user *buffer,
73bb1da6 1185 size_t count, loff_t *off)
d7e09d03 1186{
73bb1da6 1187 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
d7e09d03 1188 struct ptlrpc_request *req;
d0bfef31 1189 int rc;
d7e09d03 1190
a15b2225
KS
1191 rc = lprocfs_climp_check(obd);
1192 if (rc)
1193 return rc;
1194
d7e09d03 1195 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
e5b6b5d4 1196 up_read(&obd->u.cli.cl_sem);
8b382089 1197 if (!req)
0a3bdb00 1198 return -ENOMEM;
d7e09d03
PT
1199
1200 req->rq_send_state = LUSTRE_IMP_FULL;
1201
1202 rc = ptlrpc_queue_wait(req);
1203
1204 ptlrpc_req_finished(req);
1205 if (rc >= 0)
0a3bdb00
GKH
1206 return count;
1207 return rc;
d7e09d03
PT
1208}
1209EXPORT_SYMBOL(lprocfs_wr_ping);
1210
1211/* Write the connection UUID to this file to attempt to connect to that node.
1212 * The connection UUID is a node's primary NID. For example,
1213 * "echo connection=192.168.0.1@tcp0::instance > .../import".
1214 */
e84962e3 1215int lprocfs_wr_import(struct file *file, const char __user *buffer,
73bb1da6 1216 size_t count, loff_t *off)
d7e09d03 1217{
73bb1da6 1218 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
1219 struct obd_import *imp = obd->u.cli.cl_import;
1220 char *kbuf = NULL;
1221 char *uuid;
1222 char *ptr;
1223 int do_reconn = 1;
1224 const char prefix[] = "connection=";
1225 const int prefix_len = sizeof(prefix) - 1;
1226
09cbfeaf 1227 if (count > PAGE_SIZE - 1 || count <= prefix_len)
d7e09d03
PT
1228 return -EINVAL;
1229
9ae10597 1230 kbuf = kzalloc(count + 1, GFP_NOFS);
597851ac 1231 if (!kbuf)
d7e09d03
PT
1232 return -ENOMEM;
1233
a9b3e8f3
JL
1234 if (copy_from_user(kbuf, buffer, count)) {
1235 count = -EFAULT;
1236 goto out;
1237 }
d7e09d03
PT
1238
1239 kbuf[count] = 0;
1240
1241 /* only support connection=uuid::instance now */
a9b3e8f3
JL
1242 if (strncmp(prefix, kbuf, prefix_len) != 0) {
1243 count = -EINVAL;
1244 goto out;
1245 }
d7e09d03
PT
1246
1247 uuid = kbuf + prefix_len;
1248 ptr = strstr(uuid, "::");
1249 if (ptr) {
1250 __u32 inst;
1251 char *endptr;
1252
1253 *ptr = 0;
1254 do_reconn = 0;
1255 ptr += strlen("::");
e3ce40cb 1256 inst = simple_strtoul(ptr, &endptr, 10);
d7e09d03
PT
1257 if (*endptr) {
1258 CERROR("config: wrong instance # %s\n", ptr);
1259 } else if (inst != imp->imp_connect_data.ocd_instance) {
2d00bd17 1260 CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted target(%u/%u), reconnecting...\n",
d7e09d03
PT
1261 imp->imp_obd->obd_name,
1262 imp->imp_connect_data.ocd_instance, inst);
1263 do_reconn = 1;
1264 } else {
2d00bd17 1265 CDEBUG(D_INFO, "IR: %s has already been connecting to new target(%u)\n",
d7e09d03
PT
1266 imp->imp_obd->obd_name, inst);
1267 }
1268 }
1269
1270 if (do_reconn)
1271 ptlrpc_recover_import(imp, uuid, 1);
1272
1273out:
9ae10597 1274 kfree(kbuf);
d7e09d03
PT
1275 return count;
1276}
1277EXPORT_SYMBOL(lprocfs_wr_import);
1278
73bb1da6 1279int lprocfs_rd_pinger_recov(struct seq_file *m, void *n)
d7e09d03 1280{
73bb1da6 1281 struct obd_device *obd = m->private;
d7e09d03 1282 struct obd_import *imp = obd->u.cli.cl_import;
a15b2225
KS
1283 int rc;
1284
1285 rc = lprocfs_climp_check(obd);
1286 if (rc)
1287 return rc;
d7e09d03 1288
91b3a685 1289 seq_printf(m, "%d\n", !imp->imp_no_pinger_recover);
e5b6b5d4 1290 up_read(&obd->u.cli.cl_sem);
d7e09d03 1291
91b3a685 1292 return 0;
d7e09d03
PT
1293}
1294EXPORT_SYMBOL(lprocfs_rd_pinger_recov);
1295
e84962e3 1296int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
30c0aa39 1297 size_t count, loff_t *off)
d7e09d03 1298{
73bb1da6 1299 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
1300 struct client_obd *cli = &obd->u.cli;
1301 struct obd_import *imp = cli->cl_import;
1302 int rc, val;
1303
1304 rc = lprocfs_write_helper(buffer, count, &val);
1305 if (rc < 0)
1306 return rc;
1307
1308 if (val != 0 && val != 1)
1309 return -ERANGE;
1310
a15b2225
KS
1311 rc = lprocfs_climp_check(obd);
1312 if (rc)
1313 return rc;
1314
d7e09d03
PT
1315 spin_lock(&imp->imp_lock);
1316 imp->imp_no_pinger_recover = !val;
1317 spin_unlock(&imp->imp_lock);
e5b6b5d4 1318 up_read(&obd->u.cli.cl_sem);
d7e09d03
PT
1319
1320 return count;
d7e09d03
PT
1321}
1322EXPORT_SYMBOL(lprocfs_wr_pinger_recov);
This page took 0.775682 seconds and 5 git commands to generate.