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 { MDS_GETATTR, "mds_getattr" },
65 { MDS_GETATTR_NAME, "mds_getattr_lock" },
66 { MDS_CLOSE, "mds_close" },
67 { MDS_REINT, "mds_reint" },
68 { MDS_READPAGE, "mds_readpage" },
69 { MDS_CONNECT, "mds_connect" },
70 { MDS_DISCONNECT, "mds_disconnect" },
71 { MDS_GETSTATUS, "mds_getstatus" },
72 { MDS_STATFS, "mds_statfs" },
73 { MDS_PIN, "mds_pin" },
74 { MDS_UNPIN, "mds_unpin" },
75 { MDS_SYNC, "mds_sync" },
76 { MDS_DONE_WRITING, "mds_done_writing" },
77 { MDS_SET_INFO, "mds_set_info" },
78 { MDS_QUOTACHECK, "mds_quotacheck" },
79 { MDS_QUOTACTL, "mds_quotactl" },
80 { MDS_GETXATTR, "mds_getxattr" },
81 { MDS_SETXATTR, "mds_setxattr" },
82 { LDLM_ENQUEUE, "ldlm_enqueue" },
83 { LDLM_CONVERT, "ldlm_convert" },
84 { LDLM_CANCEL, "ldlm_cancel" },
85 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
86 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
87 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
88 { MGS_CONNECT, "mgs_connect" },
89 { MGS_DISCONNECT, "mgs_disconnect" },
90 { MGS_EXCEPTION, "mgs_exception" },
91 { MGS_TARGET_REG, "mgs_target_reg" },
92 { MGS_TARGET_DEL, "mgs_target_del" },
93 { OBD_PING, "obd_ping" },
94 { OBD_LOG_CANCEL, "llog_origin_handle_cancel" },
95 { OBD_QC_CALLBACK, "obd_quota_callback" },
96 { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_create" },
97 { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block"},
98 { LLOG_ORIGIN_HANDLE_READ_HEADER,"llog_origin_handle_read_header" },
99 { LLOG_ORIGIN_HANDLE_WRITE_REC, "llog_origin_handle_write_rec" },
100 { LLOG_ORIGIN_HANDLE_CLOSE, "llog_origin_handle_close" },
101 { LLOG_ORIGIN_CONNECT, "llog_origin_connect" },
102 { LLOG_CATINFO, "llog_catinfo" },
103 { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" },
104 { LLOG_ORIGIN_HANDLE_DESTROY, "llog_origin_handle_destroy" },
107 const char* ll_opcode2str(__u32 opcode)
109 /* When one of the assertions below fail, chances are that:
110 * 1) A new opcode was added in lustre_idl.h, but was
111 * is missing from the table above.
112 * or 2) The opcode space was renumbered or rearranged,
113 * and the opcode_offset() function in
114 * ptlrpc_internal.h needs to be modified.
116 __u32 offset = opcode_offset(opcode);
117 LASSERT(offset < LUSTRE_MAX_OPCODES);
118 LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
119 return ll_rpc_opcode_table[offset].opname;
123 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
124 char *name, struct proc_dir_entry **procroot_ret,
125 struct lprocfs_stats **stats_ret)
127 struct proc_dir_entry *svc_procroot;
128 struct lprocfs_stats *svc_stats;
130 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
133 LASSERT(*procroot_ret == NULL);
134 LASSERT(*stats_ret == NULL);
136 svc_stats = lprocfs_alloc_stats(PTLRPC_LAST_CNTR + LUSTRE_MAX_OPCODES);
137 if (svc_stats == NULL)
141 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
142 if (IS_ERR(svc_procroot)) {
143 lprocfs_free_stats(&svc_stats);
150 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
151 svc_counter_config, "req_waittime", "usec");
152 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
153 svc_counter_config, "req_qdepth", "reqs");
154 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
155 svc_counter_config, "req_active", "reqs");
156 lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
157 svc_counter_config, "adaptive_timeout", "sec");
158 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
159 svc_counter_config, "reqbuf_avail", "bufs");
160 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
161 __u32 opcode = ll_rpc_opcode_table[i].opcode;
162 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
163 svc_counter_config, ll_opcode2str(opcode),
167 rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
170 lprocfs_remove(&svc_procroot);
171 lprocfs_free_stats(&svc_stats);
174 *procroot_ret = svc_procroot;
175 *stats_ret = svc_stats;
180 ptlrpc_lprocfs_read_req_history_len(char *page, char **start, off_t off,
181 int count, int *eof, void *data)
183 struct ptlrpc_service *svc = data;
186 return snprintf(page, count, "%d\n", svc->srv_n_history_rqbds);
190 ptlrpc_lprocfs_read_req_history_max(char *page, char **start, off_t off,
191 int count, int *eof, void *data)
193 struct ptlrpc_service *svc = data;
196 return snprintf(page, count, "%d\n", svc->srv_max_history_rqbds);
200 ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer,
201 unsigned long count, void *data)
203 struct ptlrpc_service *svc = data;
206 int rc = lprocfs_write_helper(buffer, count, &val);
214 /* This sanity check is more of an insanity check; we can still
215 * hose a kernel by allowing the request history to grow too
217 bufpages = (svc->srv_buf_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
218 if (val > num_physpages/(2*bufpages))
221 spin_lock(&svc->srv_lock);
222 svc->srv_max_history_rqbds = val;
223 spin_unlock(&svc->srv_lock);
228 struct ptlrpc_srh_iterator {
230 struct ptlrpc_request *srhi_req;
234 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service *svc,
235 struct ptlrpc_srh_iterator *srhi,
239 struct ptlrpc_request *req;
241 if (srhi->srhi_req != NULL &&
242 srhi->srhi_seq > svc->srv_request_max_cull_seq &&
243 srhi->srhi_seq <= seq) {
244 /* If srhi_req was set previously, hasn't been culled and
245 * we're searching for a seq on or after it (i.e. more
246 * recent), search from it onwards.
247 * Since the service history is LRU (i.e. culled reqs will
248 * be near the head), we shouldn't have to do long
250 LASSERT (srhi->srhi_seq == srhi->srhi_req->rq_history_seq);
251 LASSERT (!list_empty(&svc->srv_request_history));
252 e = &srhi->srhi_req->rq_history_list;
254 /* search from start */
255 e = svc->srv_request_history.next;
258 while (e != &svc->srv_request_history) {
259 req = list_entry(e, struct ptlrpc_request, rq_history_list);
261 if (req->rq_history_seq >= seq) {
262 srhi->srhi_seq = req->rq_history_seq;
263 srhi->srhi_req = req;
273 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
275 struct ptlrpc_service *svc = s->private;
276 struct ptlrpc_srh_iterator *srhi;
279 OBD_ALLOC(srhi, sizeof(*srhi));
284 srhi->srhi_req = NULL;
286 spin_lock(&svc->srv_lock);
287 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos);
288 spin_unlock(&svc->srv_lock);
291 *pos = srhi->srhi_seq;
295 OBD_FREE(srhi, sizeof(*srhi));
300 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
302 struct ptlrpc_srh_iterator *srhi = iter;
305 OBD_FREE(srhi, sizeof(*srhi));
309 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
310 void *iter, loff_t *pos)
312 struct ptlrpc_service *svc = s->private;
313 struct ptlrpc_srh_iterator *srhi = iter;
316 spin_lock(&svc->srv_lock);
317 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos + 1);
318 spin_unlock(&svc->srv_lock);
321 OBD_FREE(srhi, sizeof(*srhi));
325 *pos = srhi->srhi_seq;
329 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
331 struct ptlrpc_service *svc = s->private;
332 struct ptlrpc_srh_iterator *srhi = iter;
333 struct ptlrpc_request *req;
336 spin_lock(&svc->srv_lock);
338 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, srhi->srhi_seq);
341 req = srhi->srhi_req;
343 /* Print common req fields.
344 * CAVEAT EMPTOR: we're racing with the service handler
345 * here. The request could contain any old crap, so you
346 * must be just as careful as the service's request
347 * parser. Currently I only print stuff here I know is OK
348 * to look at coz it was set up in request_in_callback()!!! */
349 seq_printf(s, LPD64":%s:%s:"LPD64":%d:%s ",
350 req->rq_history_seq, libcfs_nid2str(req->rq_self),
351 libcfs_id2str(req->rq_peer), req->rq_xid,
352 req->rq_reqlen,ptlrpc_rqphase2str(req));
354 if (svc->srv_request_history_print_fn == NULL)
357 svc->srv_request_history_print_fn(s, srhi->srhi_req);
360 spin_unlock(&svc->srv_lock);
366 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
368 static struct seq_operations sops = {
369 .start = ptlrpc_lprocfs_svc_req_history_start,
370 .stop = ptlrpc_lprocfs_svc_req_history_stop,
371 .next = ptlrpc_lprocfs_svc_req_history_next,
372 .show = ptlrpc_lprocfs_svc_req_history_show,
374 struct proc_dir_entry *dp = PDE(inode);
375 struct seq_file *seqf;
378 LPROCFS_ENTRY_AND_CHECK(dp);
379 rc = seq_open(file, &sops);
385 seqf = file->private_data;
386 seqf->private = dp->data;
390 /* See also lprocfs_rd_timeouts */
391 static int ptlrpc_lprocfs_rd_timeouts(char *page, char **start, off_t off,
392 int count, int *eof, void *data)
394 struct ptlrpc_service *svc = data;
395 unsigned int cur, worst;
401 cur = at_get(&svc->srv_at_estimate);
402 worst = svc->srv_at_estimate.at_worst_ever;
403 worstt = svc->srv_at_estimate.at_worst_time;
404 s2dhms(&ts, cfs_time_current_sec() - worstt);
406 rc += snprintf(page + rc, count - rc,
407 "adaptive timeouts off, using obd_timeout %u\n",
409 rc += snprintf(page + rc, count - rc,
410 "%10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
411 "service", cur, worst, worstt,
413 rc = lprocfs_at_hist_helper(page, count, rc,
414 &svc->srv_at_estimate);
418 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
419 struct ptlrpc_service *svc)
421 struct lprocfs_vars lproc_vars[] = {
422 {.name = "req_buffer_history_len",
424 .read_fptr = ptlrpc_lprocfs_read_req_history_len,
426 {.name = "req_buffer_history_max",
427 .write_fptr = ptlrpc_lprocfs_write_req_history_max,
428 .read_fptr = ptlrpc_lprocfs_read_req_history_max,
431 .read_fptr = ptlrpc_lprocfs_rd_timeouts,
435 static struct file_operations req_history_fops = {
436 .owner = THIS_MODULE,
437 .open = ptlrpc_lprocfs_svc_req_history_open,
440 .release = lprocfs_seq_release,
442 struct proc_dir_entry *req_history;
444 ptlrpc_lprocfs_register(entry, svc->srv_name,
445 "stats", &svc->srv_procroot,
448 if (svc->srv_procroot == NULL)
451 lprocfs_add_vars(svc->srv_procroot, lproc_vars, NULL);
453 req_history = create_proc_entry("req_history", 0400,
455 if (req_history != NULL) {
456 req_history->data = svc;
457 req_history->proc_fops = &req_history_fops;
461 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
463 ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
464 &obddev->obd_svc_procroot,
465 &obddev->obd_svc_stats);
467 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
469 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req)
471 struct lprocfs_stats *svc_stats;
472 int opc = opcode_offset(lustre_msg_get_opc(req->rq_reqmsg));
474 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
475 if (svc_stats == NULL || opc <= 0)
477 LASSERT(opc < LUSTRE_MAX_OPCODES);
478 /* These two use the ptlrpc_lprocfs_brw below */
479 if (!(opc == OST_WRITE || opc == OST_READ))
480 lprocfs_counter_add(svc_stats, opc + PTLRPC_LAST_CNTR, 0);
483 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes)
485 struct lprocfs_stats *svc_stats;
486 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
489 lprocfs_counter_add(svc_stats, opc + PTLRPC_LAST_CNTR, bytes);
491 EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
493 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
495 if (svc->srv_procroot != NULL)
496 lprocfs_remove(&svc->srv_procroot);
498 lprocfs_free_stats(&svc->srv_stats);
501 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
503 if (obd->obd_svc_procroot)
504 lprocfs_remove(&obd->obd_svc_procroot);
505 if (obd->obd_svc_stats)
506 lprocfs_free_stats(&obd->obd_svc_stats);
508 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
511 int lprocfs_wr_evict_client(struct file *file, const char *buffer,
512 unsigned long count, void *data)
514 struct obd_device *obd = data;
515 char tmpbuf[sizeof(struct obd_uuid)];
517 /* Kludge code(deadlock situation): the lprocfs lock has been held
518 * since the client is evicted by writting client's
519 * uuid/nid to procfs "evict_client" entry. However,
520 * obd_export_evict_by_uuid() will call lprocfs_remove() to destroy
521 * the proc entries under the being destroyed export{}, so I have
522 * to drop the lock at first here.
523 * - jay, jxiong@clusterfs.com */
527 sscanf(buffer, "%40s", tmpbuf);
528 if (strncmp(tmpbuf, "nid:", 4) == 0)
529 obd_export_evict_by_nid(obd, tmpbuf + 4);
530 else if (strncmp(tmpbuf, "uuid:", 5) == 0)
531 obd_export_evict_by_uuid(obd, tmpbuf + 5);
533 obd_export_evict_by_uuid(obd, tmpbuf);
540 EXPORT_SYMBOL(lprocfs_wr_evict_client);
542 int lprocfs_wr_ping(struct file *file, const char *buffer,
543 unsigned long count, void *data)
545 struct obd_device *obd = data;
546 struct ptlrpc_request *req;
550 LPROCFS_CLIMP_CHECK(obd);
551 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OBD_VERSION,
552 OBD_PING, 1, NULL, NULL);
553 LPROCFS_CLIMP_EXIT(obd);
557 ptlrpc_req_set_repsize(req, 1, NULL);
558 req->rq_send_state = LUSTRE_IMP_FULL;
559 req->rq_no_resend = 1;
561 rc = ptlrpc_queue_wait(req);
563 ptlrpc_req_finished(req);
568 EXPORT_SYMBOL(lprocfs_wr_ping);