1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_CLASS
28 # include <liblustre.h>
31 #include <obd_support.h>
33 #include <lprocfs_status.h>
34 #include <lustre/lustre_idl.h>
35 #include <lustre_net.h>
36 #include <obd_class.h>
37 #include "ptlrpc_internal.h"
40 struct ll_rpc_opcode {
43 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
44 { OST_REPLY, "ost_reply" },
45 { OST_GETATTR, "ost_getattr" },
46 { OST_SETATTR, "ost_setattr" },
47 { OST_READ, "ost_read" },
48 { OST_WRITE, "ost_write" },
49 { OST_CREATE , "ost_create" },
50 { OST_DESTROY, "ost_destroy" },
51 { OST_GET_INFO, "ost_get_info" },
52 { OST_CONNECT, "ost_connect" },
53 { OST_DISCONNECT, "ost_disconnect" },
54 { OST_PUNCH, "ost_punch" },
55 { OST_OPEN, "ost_open" },
56 { OST_CLOSE, "ost_close" },
57 { OST_STATFS, "ost_statfs" },
58 { 14, NULL }, /* formerly OST_SAN_READ */
59 { 15, NULL }, /* formerly OST_SAN_WRITE */
60 { OST_SYNC, "ost_sync" },
61 { OST_SET_INFO, "ost_set_info" },
62 { OST_QUOTACHECK, "ost_quotacheck" },
63 { OST_QUOTACTL, "ost_quotactl" },
64 { OST_QUOTA_ADJUST_QUNIT, "ost_quota_adjust_qunit" },
65 { MDS_GETATTR, "mds_getattr" },
66 { MDS_GETATTR_NAME, "mds_getattr_lock" },
67 { MDS_CLOSE, "mds_close" },
68 { MDS_REINT, "mds_reint" },
69 { MDS_READPAGE, "mds_readpage" },
70 { MDS_CONNECT, "mds_connect" },
71 { MDS_DISCONNECT, "mds_disconnect" },
72 { MDS_GETSTATUS, "mds_getstatus" },
73 { MDS_STATFS, "mds_statfs" },
74 { MDS_PIN, "mds_pin" },
75 { MDS_UNPIN, "mds_unpin" },
76 { MDS_SYNC, "mds_sync" },
77 { MDS_DONE_WRITING, "mds_done_writing" },
78 { MDS_SET_INFO, "mds_set_info" },
79 { MDS_QUOTACHECK, "mds_quotacheck" },
80 { MDS_QUOTACTL, "mds_quotactl" },
81 { MDS_GETXATTR, "mds_getxattr" },
82 { MDS_SETXATTR, "mds_setxattr" },
83 { LDLM_ENQUEUE, "ldlm_enqueue" },
84 { LDLM_CONVERT, "ldlm_convert" },
85 { LDLM_CANCEL, "ldlm_cancel" },
86 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
87 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
88 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
89 { MGS_CONNECT, "mgs_connect" },
90 { MGS_DISCONNECT, "mgs_disconnect" },
91 { MGS_EXCEPTION, "mgs_exception" },
92 { MGS_TARGET_REG, "mgs_target_reg" },
93 { MGS_TARGET_DEL, "mgs_target_del" },
94 { MGS_SET_INFO, "mgs_set_info" },
95 { OBD_PING, "obd_ping" },
96 { OBD_LOG_CANCEL, "llog_origin_handle_cancel" },
97 { OBD_QC_CALLBACK, "obd_quota_callback" },
98 { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_create" },
99 { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block"},
100 { LLOG_ORIGIN_HANDLE_READ_HEADER,"llog_origin_handle_read_header" },
101 { LLOG_ORIGIN_HANDLE_WRITE_REC, "llog_origin_handle_write_rec" },
102 { LLOG_ORIGIN_HANDLE_CLOSE, "llog_origin_handle_close" },
103 { LLOG_ORIGIN_CONNECT, "llog_origin_connect" },
104 { LLOG_CATINFO, "llog_catinfo" },
105 { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" },
106 { LLOG_ORIGIN_HANDLE_DESTROY, "llog_origin_handle_destroy" },
112 } ll_eopcode_table[EXTRA_LAST_OPC] = {
113 { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" },
114 { LDLM_PLAIN_ENQUEUE, "ldlm_plain_enqueue" },
115 { LDLM_EXTENT_ENQUEUE, "ldlm_extent_enqueue" },
116 { LDLM_FLOCK_ENQUEUE, "ldlm_flock_enqueue" },
117 { LDLM_IBITS_ENQUEUE, "ldlm_ibits_enqueue" },
118 { MDS_REINT_CREATE, "mds_reint_create" },
119 { MDS_REINT_LINK, "mds_reint_link" },
120 { MDS_REINT_OPEN, "mds_reint_open" },
121 { MDS_REINT_SETATTR, "mds_reint_setattr" },
122 { MDS_REINT_RENAME, "mds_reint_rename" },
123 { MDS_REINT_UNLINK, "mds_reint_unlink" }
126 const char *ll_opcode2str(__u32 opcode)
128 /* When one of the assertions below fail, chances are that:
129 * 1) A new opcode was added in lustre_idl.h, but was
130 * is missing from the table above.
131 * or 2) The opcode space was renumbered or rearranged,
132 * and the opcode_offset() function in
133 * ptlrpc_internal.h needs to be modified.
135 __u32 offset = opcode_offset(opcode);
136 LASSERT(offset < LUSTRE_MAX_OPCODES);
137 LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
138 return ll_rpc_opcode_table[offset].opname;
141 const char* ll_eopcode2str(__u32 opcode)
143 LASSERT(ll_eopcode_table[opcode].opcode == opcode);
144 return ll_eopcode_table[opcode].opname;
147 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
148 char *name, struct proc_dir_entry **procroot_ret,
149 struct lprocfs_stats **stats_ret)
151 struct proc_dir_entry *svc_procroot;
152 struct lprocfs_stats *svc_stats;
154 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
157 LASSERT(*procroot_ret == NULL);
158 LASSERT(*stats_ret == NULL);
160 svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES, 0);
161 if (svc_stats == NULL)
165 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
166 if (IS_ERR(svc_procroot)) {
167 lprocfs_free_stats(&svc_stats);
174 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
175 svc_counter_config, "req_waittime", "usec");
176 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
177 svc_counter_config, "req_qdepth", "reqs");
178 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
179 svc_counter_config, "req_active", "reqs");
180 lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
181 svc_counter_config, "req_timeout", "sec");
182 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
183 svc_counter_config, "reqbuf_avail", "bufs");
184 for (i = 0; i < EXTRA_LAST_OPC; i++) {
185 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
187 ll_eopcode2str(i), "reqs");
189 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
190 __u32 opcode = ll_rpc_opcode_table[i].opcode;
191 lprocfs_counter_init(svc_stats,
192 EXTRA_MAX_OPCODES + i, svc_counter_config,
193 ll_opcode2str(opcode), "usec");
196 rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
199 lprocfs_remove(&svc_procroot);
200 lprocfs_free_stats(&svc_stats);
203 *procroot_ret = svc_procroot;
204 *stats_ret = svc_stats;
209 ptlrpc_lprocfs_read_req_history_len(char *page, char **start, off_t off,
210 int count, int *eof, void *data)
212 struct ptlrpc_service *svc = data;
215 return snprintf(page, count, "%d\n", svc->srv_n_history_rqbds);
219 ptlrpc_lprocfs_read_req_history_max(char *page, char **start, off_t off,
220 int count, int *eof, void *data)
222 struct ptlrpc_service *svc = data;
225 return snprintf(page, count, "%d\n", svc->srv_max_history_rqbds);
229 ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer,
230 unsigned long count, void *data)
232 struct ptlrpc_service *svc = data;
235 int rc = lprocfs_write_helper(buffer, count, &val);
243 /* This sanity check is more of an insanity check; we can still
244 * hose a kernel by allowing the request history to grow too
246 bufpages = (svc->srv_buf_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
247 if (val > num_physpages/(2*bufpages))
250 spin_lock(&svc->srv_lock);
251 svc->srv_max_history_rqbds = val;
252 spin_unlock(&svc->srv_lock);
257 struct ptlrpc_srh_iterator {
259 struct ptlrpc_request *srhi_req;
263 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service *svc,
264 struct ptlrpc_srh_iterator *srhi,
268 struct ptlrpc_request *req;
270 if (srhi->srhi_req != NULL &&
271 srhi->srhi_seq > svc->srv_request_max_cull_seq &&
272 srhi->srhi_seq <= seq) {
273 /* If srhi_req was set previously, hasn't been culled and
274 * we're searching for a seq on or after it (i.e. more
275 * recent), search from it onwards.
276 * Since the service history is LRU (i.e. culled reqs will
277 * be near the head), we shouldn't have to do long
279 LASSERT (srhi->srhi_seq == srhi->srhi_req->rq_history_seq);
280 LASSERT (!list_empty(&svc->srv_request_history));
281 e = &srhi->srhi_req->rq_history_list;
283 /* search from start */
284 e = svc->srv_request_history.next;
287 while (e != &svc->srv_request_history) {
288 req = list_entry(e, struct ptlrpc_request, rq_history_list);
290 if (req->rq_history_seq >= seq) {
291 srhi->srhi_seq = req->rq_history_seq;
292 srhi->srhi_req = req;
302 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
304 struct ptlrpc_service *svc = s->private;
305 struct ptlrpc_srh_iterator *srhi;
308 OBD_ALLOC(srhi, sizeof(*srhi));
313 srhi->srhi_req = NULL;
315 spin_lock(&svc->srv_lock);
316 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos);
317 spin_unlock(&svc->srv_lock);
320 *pos = srhi->srhi_seq;
324 OBD_FREE(srhi, sizeof(*srhi));
329 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
331 struct ptlrpc_srh_iterator *srhi = iter;
334 OBD_FREE(srhi, sizeof(*srhi));
338 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
339 void *iter, loff_t *pos)
341 struct ptlrpc_service *svc = s->private;
342 struct ptlrpc_srh_iterator *srhi = iter;
345 spin_lock(&svc->srv_lock);
346 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos + 1);
347 spin_unlock(&svc->srv_lock);
350 OBD_FREE(srhi, sizeof(*srhi));
354 *pos = srhi->srhi_seq;
358 /* common ost/mdt srv_request_history_print_fn */
359 void target_print_req(void *seq_file, struct ptlrpc_request *req)
361 /* Called holding srv_lock with irqs disabled.
362 * Print specific req contents and a newline.
363 * CAVEAT EMPTOR: check request message length before printing!!!
364 * You might have received any old crap so you must be just as
365 * careful here as the service's request parser!!! */
366 struct seq_file *sf = seq_file;
368 switch (req->rq_phase) {
370 /* still awaiting a service thread's attention, or rejected
371 * because the generic request message didn't unpack */
372 seq_printf(sf, "<not swabbed>\n");
374 case RQ_PHASE_INTERPRET:
375 /* being handled, so basic msg swabbed, and opc is valid
376 * but racing with mds_handle() */
377 case RQ_PHASE_COMPLETE:
378 /* been handled by mds_handle() reply state possibly still
380 seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg));
383 DEBUG_REQ(D_ERROR, req, "bad phase %d", req->rq_phase);
386 EXPORT_SYMBOL(target_print_req);
388 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
390 struct ptlrpc_service *svc = s->private;
391 struct ptlrpc_srh_iterator *srhi = iter;
392 struct ptlrpc_request *req;
395 spin_lock(&svc->srv_lock);
397 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, srhi->srhi_seq);
400 req = srhi->srhi_req;
402 /* Print common req fields.
403 * CAVEAT EMPTOR: we're racing with the service handler
404 * here. The request could contain any old crap, so you
405 * must be just as careful as the service's request
406 * parser. Currently I only print stuff here I know is OK
407 * to look at coz it was set up in request_in_callback()!!! */
408 seq_printf(s, LPD64":%s:%s:x"LPD64":%d:%s:%ld:%lds(%+lds) ",
409 req->rq_history_seq, libcfs_nid2str(req->rq_self),
410 libcfs_id2str(req->rq_peer), req->rq_xid,
411 req->rq_reqlen, ptlrpc_rqphase2str(req),
412 req->rq_arrival_time.tv_sec,
413 req->rq_sent - req->rq_arrival_time.tv_sec,
414 req->rq_sent - req->rq_deadline);
415 if (svc->srv_request_history_print_fn == NULL)
418 svc->srv_request_history_print_fn(s, srhi->srhi_req);
421 spin_unlock(&svc->srv_lock);
427 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
429 static struct seq_operations sops = {
430 .start = ptlrpc_lprocfs_svc_req_history_start,
431 .stop = ptlrpc_lprocfs_svc_req_history_stop,
432 .next = ptlrpc_lprocfs_svc_req_history_next,
433 .show = ptlrpc_lprocfs_svc_req_history_show,
435 struct proc_dir_entry *dp = PDE(inode);
436 struct seq_file *seqf;
439 LPROCFS_ENTRY_AND_CHECK(dp);
440 rc = seq_open(file, &sops);
446 seqf = file->private_data;
447 seqf->private = dp->data;
451 /* See also lprocfs_rd_timeouts */
452 static int ptlrpc_lprocfs_rd_timeouts(char *page, char **start, off_t off,
453 int count, int *eof, void *data)
455 struct ptlrpc_service *svc = data;
456 unsigned int cur, worst;
462 cur = at_get(&svc->srv_at_estimate);
463 worst = svc->srv_at_estimate.at_worst_ever;
464 worstt = svc->srv_at_estimate.at_worst_time;
465 s2dhms(&ts, cfs_time_current_sec() - worstt);
467 rc += snprintf(page + rc, count - rc,
468 "adaptive timeouts off, using obd_timeout %u\n",
470 rc += snprintf(page + rc, count - rc,
471 "%10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
472 "service", cur, worst, worstt,
474 rc = lprocfs_at_hist_helper(page, count, rc,
475 &svc->srv_at_estimate);
479 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
480 struct ptlrpc_service *svc)
482 struct lprocfs_vars lproc_vars[] = {
483 {.name = "req_buffer_history_len",
485 .read_fptr = ptlrpc_lprocfs_read_req_history_len,
487 {.name = "req_buffer_history_max",
488 .write_fptr = ptlrpc_lprocfs_write_req_history_max,
489 .read_fptr = ptlrpc_lprocfs_read_req_history_max,
492 .read_fptr = ptlrpc_lprocfs_rd_timeouts,
496 static struct file_operations req_history_fops = {
497 .owner = THIS_MODULE,
498 .open = ptlrpc_lprocfs_svc_req_history_open,
501 .release = lprocfs_seq_release,
503 struct proc_dir_entry *req_history;
505 ptlrpc_lprocfs_register(entry, svc->srv_name,
506 "stats", &svc->srv_procroot,
509 if (svc->srv_procroot == NULL)
512 lprocfs_add_vars(svc->srv_procroot, lproc_vars, NULL);
514 req_history = create_proc_entry("req_history", 0400,
516 if (req_history != NULL) {
517 req_history->data = svc;
518 req_history->proc_fops = &req_history_fops;
522 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
524 ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
525 &obddev->obd_svc_procroot,
526 &obddev->obd_svc_stats);
528 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
530 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req)
532 struct lprocfs_stats *svc_stats;
533 __u32 op = lustre_msg_get_opc(req->rq_reqmsg);
534 int opc = opcode_offset(op);
536 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
537 if (svc_stats == NULL || opc <= 0)
539 LASSERT(opc < LUSTRE_MAX_OPCODES);
540 /* These two use the ptlrpc_lprocfs_brw below */
541 if (!(opc == OST_WRITE || opc == OST_READ || op == LDLM_ENQUEUE
543 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, 0);
546 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes)
548 struct lprocfs_stats *svc_stats;
549 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
552 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, bytes);
554 EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
556 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
558 if (svc->srv_procroot != NULL)
559 lprocfs_remove(&svc->srv_procroot);
561 lprocfs_free_stats(&svc->srv_stats);
564 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
566 if (obd->obd_svc_procroot)
567 lprocfs_remove(&obd->obd_svc_procroot);
568 if (obd->obd_svc_stats)
569 lprocfs_free_stats(&obd->obd_svc_stats);
571 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
574 int lprocfs_wr_evict_client(struct file *file, const char *buffer,
575 unsigned long count, void *data)
577 struct obd_device *obd = data;
578 char tmpbuf[sizeof(struct obd_uuid)];
580 /* Kludge code(deadlock situation): the lprocfs lock has been held
581 * since the client is evicted by writting client's
582 * uuid/nid to procfs "evict_client" entry. However,
583 * obd_export_evict_by_uuid() will call lprocfs_remove() to destroy
584 * the proc entries under the being destroyed export{}, so I have
585 * to drop the lock at first here.
586 * - jay, jxiong@clusterfs.com */
590 sscanf(buffer, "%40s", tmpbuf);
591 if (strncmp(tmpbuf, "nid:", 4) == 0)
592 obd_export_evict_by_nid(obd, tmpbuf + 4);
593 else if (strncmp(tmpbuf, "uuid:", 5) == 0)
594 obd_export_evict_by_uuid(obd, tmpbuf + 5);
596 obd_export_evict_by_uuid(obd, tmpbuf);
603 EXPORT_SYMBOL(lprocfs_wr_evict_client);
605 int lprocfs_wr_ping(struct file *file, const char *buffer,
606 unsigned long count, void *data)
608 struct obd_device *obd = data;
609 struct ptlrpc_request *req;
613 LPROCFS_CLIMP_CHECK(obd);
614 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OBD_VERSION,
615 OBD_PING, 1, NULL, NULL);
616 LPROCFS_CLIMP_EXIT(obd);
620 ptlrpc_req_set_repsize(req, 1, NULL);
621 req->rq_send_state = LUSTRE_IMP_FULL;
622 req->rq_no_resend = 1;
624 rc = ptlrpc_queue_wait(req);
626 ptlrpc_req_finished(req);
631 EXPORT_SYMBOL(lprocfs_wr_ping);