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
27 #include <obd_support.h>
29 #include <lprocfs_status.h>
30 #include <lustre/lustre_idl.h>
31 #include <lustre_net.h>
32 #include <obd_class.h>
33 #include "ptlrpc_internal.h"
36 struct ll_rpc_opcode {
39 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
40 { OST_REPLY, "ost_reply" },
41 { OST_GETATTR, "ost_getattr" },
42 { OST_SETATTR, "ost_setattr" },
43 { OST_READ, "ost_read" },
44 { OST_WRITE, "ost_write" },
45 { OST_CREATE , "ost_create" },
46 { OST_DESTROY, "ost_destroy" },
47 { OST_GET_INFO, "ost_get_info" },
48 { OST_CONNECT, "ost_connect" },
49 { OST_DISCONNECT, "ost_disconnect" },
50 { OST_PUNCH, "ost_punch" },
51 { OST_OPEN, "ost_open" },
52 { OST_CLOSE, "ost_close" },
53 { OST_STATFS, "ost_statfs" },
54 { OST_SAN_READ, "ost_san_read" },
55 { OST_SAN_WRITE, "ost_san_write" },
56 { OST_SYNC, "ost_sync" },
57 { OST_SET_INFO, "ost_set_info" },
58 { OST_QUOTACHECK, "ost_quotacheck" },
59 { OST_QUOTACTL, "ost_quotactl" },
60 { MDS_GETATTR, "mds_getattr" },
61 { MDS_GETATTR_NAME, "mds_getattr_name" },
62 { MDS_CLOSE, "mds_close" },
63 { MDS_REINT, "mds_reint" },
64 { MDS_READPAGE, "mds_readpage" },
65 { MDS_CONNECT, "mds_connect" },
66 { MDS_DISCONNECT, "mds_disconnect" },
67 { MDS_GETSTATUS, "mds_getstatus" },
68 { MDS_STATFS, "mds_statfs" },
69 { MDS_PIN, "mds_pin" },
70 { MDS_UNPIN, "mds_unpin" },
71 { MDS_SYNC, "mds_sync" },
72 { MDS_DONE_WRITING, "mds_done_writing" },
73 { MDS_SET_INFO, "mds_set_info" },
74 { MDS_QUOTACHECK, "mds_quotacheck" },
75 { MDS_QUOTACTL, "mds_quotactl" },
76 { MDS_GETXATTR, "mds_getxattr" },
77 { MDS_SETXATTR, "mds_setxattr" },
78 { LDLM_ENQUEUE, "ldlm_enqueue" },
79 { LDLM_CONVERT, "ldlm_convert" },
80 { LDLM_CANCEL, "ldlm_cancel" },
81 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
82 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
83 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
84 { OBD_PING, "obd_ping" },
85 { OBD_LOG_CANCEL, "llog_origin_handle_cancel" },
86 { OBD_QC_CALLBACK, "obd_qc_callback" },
87 { FLD_QUERY, "fld_query" },
88 { SEQ_QUERY, "seq_query" }
91 const char* ll_opcode2str(__u32 opcode)
93 /* When one of the assertions below fail, chances are that:
94 * 1) A new opcode was added in lustre_idl.h, but was
95 * is missing from the table above.
96 * or 2) The opcode space was renumbered or rearranged,
97 * and the opcode_offset() function in
98 * ptlrpc_internals.h needs to be modified.
100 __u32 offset = opcode_offset(opcode);
101 LASSERT(offset < LUSTRE_MAX_OPCODES);
102 LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
103 return ll_rpc_opcode_table[offset].opname;
107 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
108 char *name, struct proc_dir_entry **procroot_ret,
109 struct lprocfs_stats **stats_ret)
111 struct proc_dir_entry *svc_procroot;
112 struct lprocfs_stats *svc_stats;
114 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
117 LASSERT(*procroot_ret == NULL);
118 LASSERT(*stats_ret == NULL);
120 svc_stats = lprocfs_alloc_stats(PTLRPC_LAST_CNTR + LUSTRE_MAX_OPCODES);
121 if (svc_stats == NULL)
125 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
126 if (IS_ERR(svc_procroot)) {
127 lprocfs_free_stats(svc_stats);
134 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
135 svc_counter_config, "req_waittime", "usec");
136 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
137 svc_counter_config, "req_qdepth", "reqs");
138 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
139 svc_counter_config, "req_active", "reqs");
140 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
141 svc_counter_config, "reqbuf_avail", "bufs");
142 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
143 __u32 opcode = ll_rpc_opcode_table[i].opcode;
144 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
145 svc_counter_config, ll_opcode2str(opcode),
149 rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
152 lprocfs_remove(svc_procroot);
153 lprocfs_free_stats(svc_stats);
156 *procroot_ret = svc_procroot;
157 *stats_ret = svc_stats;
162 ptlrpc_lprocfs_read_req_history_len(char *page, char **start, off_t off,
163 int count, int *eof, void *data)
165 struct ptlrpc_service *svc = data;
168 return snprintf(page, count, "%d\n", svc->srv_n_history_rqbds);
172 ptlrpc_lprocfs_read_req_history_max(char *page, char **start, off_t off,
173 int count, int *eof, void *data)
175 struct ptlrpc_service *svc = data;
178 return snprintf(page, count, "%d\n", svc->srv_max_history_rqbds);
182 ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer,
183 unsigned long count, void *data)
185 struct ptlrpc_service *svc = data;
189 int rc = lprocfs_write_helper(buffer, count, &val);
197 /* This sanity check is more of an insanity check; we can still
198 * hose a kernel by allowing the request history to grow too
200 bufpages = (svc->srv_buf_size + PAGE_SIZE - 1)/PAGE_SIZE;
201 if (val > num_physpages/(2*bufpages))
204 spin_lock_irqsave(&svc->srv_lock, flags);
205 svc->srv_max_history_rqbds = val;
206 spin_unlock_irqrestore(&svc->srv_lock, flags);
211 struct ptlrpc_srh_iterator {
213 struct ptlrpc_request *srhi_req;
217 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service *svc,
218 struct ptlrpc_srh_iterator *srhi,
222 struct ptlrpc_request *req;
224 if (srhi->srhi_req != NULL &&
225 srhi->srhi_seq > svc->srv_request_max_cull_seq &&
226 srhi->srhi_seq <= seq) {
227 /* If srhi_req was set previously, hasn't been culled and
228 * we're searching for a seq on or after it (i.e. more
229 * recent), search from it onwards.
230 * Since the service history is LRU (i.e. culled reqs will
231 * be near the head), we shouldn't have to do long
233 LASSERT (srhi->srhi_seq == srhi->srhi_req->rq_history_seq);
234 LASSERT (!list_empty(&svc->srv_request_history));
235 e = &srhi->srhi_req->rq_history_list;
237 /* search from start */
238 e = svc->srv_request_history.next;
241 while (e != &svc->srv_request_history) {
242 req = list_entry(e, struct ptlrpc_request, rq_history_list);
244 if (req->rq_history_seq >= seq) {
245 srhi->srhi_seq = req->rq_history_seq;
246 srhi->srhi_req = req;
256 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
258 struct ptlrpc_service *svc = s->private;
259 struct ptlrpc_srh_iterator *srhi;
263 OBD_ALLOC(srhi, sizeof(*srhi));
268 srhi->srhi_req = NULL;
270 spin_lock_irqsave(&svc->srv_lock, flags);
271 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos);
272 spin_unlock_irqrestore(&svc->srv_lock, flags);
275 *pos = srhi->srhi_seq;
279 OBD_FREE(srhi, sizeof(*srhi));
284 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
286 struct ptlrpc_srh_iterator *srhi = iter;
289 OBD_FREE(srhi, sizeof(*srhi));
293 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
294 void *iter, loff_t *pos)
296 struct ptlrpc_service *svc = s->private;
297 struct ptlrpc_srh_iterator *srhi = iter;
301 spin_lock_irqsave(&svc->srv_lock, flags);
302 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos + 1);
303 spin_unlock_irqrestore(&svc->srv_lock, flags);
306 OBD_FREE(srhi, sizeof(*srhi));
310 *pos = srhi->srhi_seq;
314 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
316 struct ptlrpc_service *svc = s->private;
317 struct ptlrpc_srh_iterator *srhi = iter;
318 struct ptlrpc_request *req;
322 spin_lock_irqsave(&svc->srv_lock, flags);
324 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, srhi->srhi_seq);
327 req = srhi->srhi_req;
329 /* Print common req fields.
330 * CAVEAT EMPTOR: we're racing with the service handler
331 * here. The request could contain any old crap, so you
332 * must be just as careful as the service's request
333 * parser. Currently I only print stuff here I know is OK
334 * to look at coz it was set up in request_in_callback()!!! */
335 seq_printf(s, LPD64":%s:%s:"LPD64":%d:%s ",
336 req->rq_history_seq, libcfs_nid2str(req->rq_self),
337 libcfs_id2str(req->rq_peer), req->rq_xid,
338 req->rq_reqlen,ptlrpc_rqphase2str(req));
340 if (svc->srv_request_history_print_fn == NULL)
343 svc->srv_request_history_print_fn(s, srhi->srhi_req);
346 spin_unlock_irqrestore(&svc->srv_lock, flags);
352 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
354 static struct seq_operations sops = {
355 .start = ptlrpc_lprocfs_svc_req_history_start,
356 .stop = ptlrpc_lprocfs_svc_req_history_stop,
357 .next = ptlrpc_lprocfs_svc_req_history_next,
358 .show = ptlrpc_lprocfs_svc_req_history_show,
360 struct proc_dir_entry *dp = PDE(inode);
361 struct seq_file *seqf;
364 rc = seq_open(file, &sops);
367 seqf = file->private_data;
368 seqf->private = dp->data;
374 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
375 struct ptlrpc_service *svc)
377 struct lprocfs_vars lproc_vars[] = {
378 {.name = "req_buffer_history_len",
380 .read_fptr = ptlrpc_lprocfs_read_req_history_len,
382 {.name = "req_buffer_history_max",
383 .write_fptr = ptlrpc_lprocfs_write_req_history_max,
384 .read_fptr = ptlrpc_lprocfs_read_req_history_max,
388 static struct file_operations req_history_fops = {
389 .owner = THIS_MODULE,
390 .open = ptlrpc_lprocfs_svc_req_history_open,
393 .release = seq_release,
395 struct proc_dir_entry *req_history;
397 ptlrpc_lprocfs_register(entry, svc->srv_name,
398 "stats", &svc->srv_procroot,
401 if (svc->srv_procroot == NULL)
404 lprocfs_add_vars(svc->srv_procroot, lproc_vars, NULL);
406 req_history = create_proc_entry("req_history", 0400,
408 if (req_history != NULL) {
409 req_history->data = svc;
410 req_history->proc_fops = &req_history_fops;
414 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
416 ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
417 &obddev->obd_svc_procroot,
418 &obddev->obd_svc_stats);
420 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
422 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req)
424 struct lprocfs_stats *svc_stats;
425 int opc = opcode_offset(req->rq_reqmsg->opc);
427 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
428 if (svc_stats == NULL || opc <= 0)
430 LASSERT(opc < LUSTRE_MAX_OPCODES);
431 lprocfs_counter_add(svc_stats, opc + PTLRPC_LAST_CNTR, 0);
434 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
436 if (svc->srv_procroot != NULL) {
437 lprocfs_remove(svc->srv_procroot);
438 svc->srv_procroot = NULL;
440 if (svc->srv_stats) {
441 lprocfs_free_stats(svc->srv_stats);
442 svc->srv_stats = NULL;
446 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
448 if (obd->obd_svc_procroot) {
449 lprocfs_remove(obd->obd_svc_procroot);
450 obd->obd_svc_procroot = NULL;
452 if (obd->obd_svc_stats) {
453 lprocfs_free_stats(obd->obd_svc_stats);
454 obd->obd_svc_stats = NULL;
457 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
460 int lprocfs_wr_evict_client(struct file *file, const char *buffer,
461 unsigned long count, void *data)
463 struct obd_device *obd = data;
464 char tmpbuf[sizeof(struct obd_uuid)];
466 sscanf(buffer, "%40s", tmpbuf);
468 obd_export_evict_by_uuid(obd, tmpbuf);
472 EXPORT_SYMBOL(lprocfs_wr_evict_client);
474 int lprocfs_wr_ping(struct file *file, const char *buffer,
475 unsigned long count, void *data)
477 struct obd_device *obd = data;
478 struct ptlrpc_request *req;
482 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OBD_VERSION,
483 OBD_PING, 0, NULL, NULL);
487 req->rq_replen = lustre_msg_size(0, NULL);
488 req->rq_send_state = LUSTRE_IMP_FULL;
489 req->rq_no_resend = 1;
491 rc = ptlrpc_queue_wait(req);
493 ptlrpc_req_finished(req);
498 EXPORT_SYMBOL(lprocfs_wr_ping);