1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 #define DEBUG_SUBSYSTEM S_CLASS
41 # include <liblustre.h>
44 #include <obd_support.h>
46 #include <lprocfs_status.h>
47 #include <lustre/lustre_idl.h>
48 #include <lustre_net.h>
49 #include <obd_class.h>
50 #include "ptlrpc_internal.h"
53 struct ll_rpc_opcode {
56 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
57 { OST_REPLY, "ost_reply" },
58 { OST_GETATTR, "ost_getattr" },
59 { OST_SETATTR, "ost_setattr" },
60 { OST_READ, "ost_read" },
61 { OST_WRITE, "ost_write" },
62 { OST_CREATE , "ost_create" },
63 { OST_DESTROY, "ost_destroy" },
64 { OST_GET_INFO, "ost_get_info" },
65 { OST_CONNECT, "ost_connect" },
66 { OST_DISCONNECT, "ost_disconnect" },
67 { OST_PUNCH, "ost_punch" },
68 { OST_OPEN, "ost_open" },
69 { OST_CLOSE, "ost_close" },
70 { OST_STATFS, "ost_statfs" },
71 { 14, NULL }, /* formerly OST_SAN_READ */
72 { 15, NULL }, /* formerly OST_SAN_WRITE */
73 { OST_SYNC, "ost_sync" },
74 { OST_SET_INFO, "ost_set_info" },
75 { OST_QUOTACHECK, "ost_quotacheck" },
76 { OST_QUOTACTL, "ost_quotactl" },
77 { OST_QUOTA_ADJUST_QUNIT, "ost_quota_adjust_qunit" },
78 { MDS_GETATTR, "mds_getattr" },
79 { MDS_GETATTR_NAME, "mds_getattr_lock" },
80 { MDS_CLOSE, "mds_close" },
81 { MDS_REINT, "mds_reint" },
82 { MDS_READPAGE, "mds_readpage" },
83 { MDS_CONNECT, "mds_connect" },
84 { MDS_DISCONNECT, "mds_disconnect" },
85 { MDS_GETSTATUS, "mds_getstatus" },
86 { MDS_STATFS, "mds_statfs" },
87 { MDS_PIN, "mds_pin" },
88 { MDS_UNPIN, "mds_unpin" },
89 { MDS_SYNC, "mds_sync" },
90 { MDS_DONE_WRITING, "mds_done_writing" },
91 { MDS_SET_INFO, "mds_set_info" },
92 { MDS_QUOTACHECK, "mds_quotacheck" },
93 { MDS_QUOTACTL, "mds_quotactl" },
94 { MDS_GETXATTR, "mds_getxattr" },
95 { MDS_SETXATTR, "mds_setxattr" },
96 { MDS_WRITEPAGE, "mds_writepage" },
97 { MDS_IS_SUBDIR, "mds_is_subdir" },
98 { MDS_GET_INFO, "mds_get_info" },
99 { LDLM_ENQUEUE, "ldlm_enqueue" },
100 { LDLM_CONVERT, "ldlm_convert" },
101 { LDLM_CANCEL, "ldlm_cancel" },
102 { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
103 { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
104 { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
105 { LDLM_SET_INFO, "ldlm_set_info" },
106 { MGS_CONNECT, "mgs_connect" },
107 { MGS_DISCONNECT, "mgs_disconnect" },
108 { MGS_EXCEPTION, "mgs_exception" },
109 { MGS_TARGET_REG, "mgs_target_reg" },
110 { MGS_TARGET_DEL, "mgs_target_del" },
111 { MGS_SET_INFO, "mgs_set_info" },
112 { MGS_CONFIG_READ, "mgs_config_read" },
113 { OBD_PING, "obd_ping" },
114 { OBD_LOG_CANCEL, "llog_origin_handle_cancel" },
115 { OBD_QC_CALLBACK, "obd_quota_callback" },
116 { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_create" },
117 { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block" },
118 { LLOG_ORIGIN_HANDLE_READ_HEADER,"llog_origin_handle_read_header" },
119 { LLOG_ORIGIN_HANDLE_WRITE_REC, "llog_origin_handle_write_rec" },
120 { LLOG_ORIGIN_HANDLE_CLOSE, "llog_origin_handle_close" },
121 { LLOG_ORIGIN_CONNECT, "llog_origin_connect" },
122 { 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" }
137 } ll_eopcode_table[EXTRA_LAST_OPC] = {
138 { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" },
139 { LDLM_PLAIN_ENQUEUE, "ldlm_plain_enqueue" },
140 { LDLM_EXTENT_ENQUEUE, "ldlm_extent_enqueue" },
141 { LDLM_FLOCK_ENQUEUE, "ldlm_flock_enqueue" },
142 { LDLM_IBITS_ENQUEUE, "ldlm_ibits_enqueue" },
143 { MDS_REINT_SETATTR, "mds_reint_setattr" },
144 { MDS_REINT_CREATE, "mds_reint_create" },
145 { MDS_REINT_LINK, "mds_reint_link" },
146 { MDS_REINT_UNLINK, "mds_reint_unlink" },
147 { MDS_REINT_RENAME, "mds_reint_rename" },
148 { MDS_REINT_OPEN, "mds_reint_open" },
149 { MDS_REINT_SETXATTR, "mds_reint_setxattr" },
150 { BRW_READ_BYTES, "read_bytes" },
151 { BRW_WRITE_BYTES, "write_bytes" },
154 const char *ll_opcode2str(__u32 opcode)
156 /* When one of the assertions below fail, chances are that:
157 * 1) A new opcode was added in include/lustre/lustre_idl.h,
158 * but is missing from the table above.
159 * or 2) The opcode space was renumbered or rearranged,
160 * and the opcode_offset() function in
161 * ptlrpc_internal.h needs to be modified.
163 __u32 offset = opcode_offset(opcode);
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;
173 const char* ll_eopcode2str(__u32 opcode)
175 LASSERT(ll_eopcode_table[opcode].opcode == opcode);
176 return ll_eopcode_table[opcode].opname;
179 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
180 char *name, struct proc_dir_entry **procroot_ret,
181 struct lprocfs_stats **stats_ret)
183 struct proc_dir_entry *svc_procroot;
184 struct lprocfs_stats *svc_stats;
186 unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
189 LASSERT(*procroot_ret == NULL);
190 LASSERT(*stats_ret == NULL);
192 svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES+LUSTRE_MAX_OPCODES,0);
193 if (svc_stats == NULL)
197 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
198 if (IS_ERR(svc_procroot)) {
199 lprocfs_free_stats(&svc_stats);
206 lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
207 svc_counter_config, "req_waittime", "usec");
208 lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
209 svc_counter_config, "req_qdepth", "reqs");
210 lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
211 svc_counter_config, "req_active", "reqs");
212 lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
213 svc_counter_config, "req_timeout", "sec");
214 lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
215 svc_counter_config, "reqbuf_avail", "bufs");
216 for (i = 0; i < EXTRA_LAST_OPC; i++) {
220 case BRW_WRITE_BYTES:
228 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
230 ll_eopcode2str(i), units);
232 for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
233 __u32 opcode = ll_rpc_opcode_table[i].opcode;
234 lprocfs_counter_init(svc_stats,
235 EXTRA_MAX_OPCODES + i, svc_counter_config,
236 ll_opcode2str(opcode), "usec");
239 rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
242 lprocfs_remove(&svc_procroot);
243 lprocfs_free_stats(&svc_stats);
246 *procroot_ret = svc_procroot;
247 *stats_ret = svc_stats;
252 ptlrpc_lprocfs_read_req_history_len(char *page, char **start, off_t off,
253 int count, int *eof, void *data)
255 struct ptlrpc_service *svc = data;
258 return snprintf(page, count, "%d\n", svc->srv_n_history_rqbds);
262 ptlrpc_lprocfs_read_req_history_max(char *page, char **start, off_t off,
263 int count, int *eof, void *data)
265 struct ptlrpc_service *svc = data;
268 return snprintf(page, count, "%d\n", svc->srv_max_history_rqbds);
272 ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer,
273 unsigned long count, void *data)
275 struct ptlrpc_service *svc = data;
278 int rc = lprocfs_write_helper(buffer, count, &val);
286 /* This sanity check is more of an insanity check; we can still
287 * hose a kernel by allowing the request history to grow too
289 bufpages = (svc->srv_buf_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
290 if (val > cfs_num_physpages/(2 * bufpages))
293 cfs_spin_lock(&svc->srv_lock);
294 svc->srv_max_history_rqbds = val;
295 cfs_spin_unlock(&svc->srv_lock);
301 ptlrpc_lprocfs_rd_threads_min(char *page, char **start, off_t off,
302 int count, int *eof, void *data)
304 struct ptlrpc_service *svc = data;
306 return snprintf(page, count, "%d\n", svc->srv_threads_min);
310 ptlrpc_lprocfs_wr_threads_min(struct file *file, const char *buffer,
311 unsigned long count, void *data)
313 struct ptlrpc_service *svc = data;
315 int rc = lprocfs_write_helper(buffer, count, &val);
323 if (val > svc->srv_threads_max)
326 cfs_spin_lock(&svc->srv_lock);
327 svc->srv_threads_min = val;
328 cfs_spin_unlock(&svc->srv_lock);
334 ptlrpc_lprocfs_rd_threads_started(char *page, char **start, off_t off,
335 int count, int *eof, void *data)
337 struct ptlrpc_service *svc = data;
339 return snprintf(page, count, "%d\n", svc->srv_threads_running);
343 ptlrpc_lprocfs_rd_threads_max(char *page, char **start, off_t off,
344 int count, int *eof, void *data)
346 struct ptlrpc_service *svc = data;
348 return snprintf(page, count, "%d\n", svc->srv_threads_max);
352 ptlrpc_lprocfs_wr_threads_max(struct file *file, const char *buffer,
353 unsigned long count, void *data)
355 struct ptlrpc_service *svc = data;
357 int rc = lprocfs_write_helper(buffer, count, &val);
365 if (val < svc->srv_threads_min)
368 cfs_spin_lock(&svc->srv_lock);
369 svc->srv_threads_max = val;
370 cfs_spin_unlock(&svc->srv_lock);
375 struct ptlrpc_srh_iterator {
377 struct ptlrpc_request *srhi_req;
381 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service *svc,
382 struct ptlrpc_srh_iterator *srhi,
386 struct ptlrpc_request *req;
388 if (srhi->srhi_req != NULL &&
389 srhi->srhi_seq > svc->srv_request_max_cull_seq &&
390 srhi->srhi_seq <= seq) {
391 /* If srhi_req was set previously, hasn't been culled and
392 * we're searching for a seq on or after it (i.e. more
393 * recent), search from it onwards.
394 * Since the service history is LRU (i.e. culled reqs will
395 * be near the head), we shouldn't have to do long
397 LASSERT (srhi->srhi_seq == srhi->srhi_req->rq_history_seq);
398 LASSERT (!cfs_list_empty(&svc->srv_request_history));
399 e = &srhi->srhi_req->rq_history_list;
401 /* search from start */
402 e = svc->srv_request_history.next;
405 while (e != &svc->srv_request_history) {
406 req = cfs_list_entry(e, struct ptlrpc_request, rq_history_list);
408 if (req->rq_history_seq >= seq) {
409 srhi->srhi_seq = req->rq_history_seq;
410 srhi->srhi_req = req;
420 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
422 struct ptlrpc_service *svc = s->private;
423 struct ptlrpc_srh_iterator *srhi;
426 OBD_ALLOC(srhi, sizeof(*srhi));
431 srhi->srhi_req = NULL;
433 cfs_spin_lock(&svc->srv_lock);
434 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos);
435 cfs_spin_unlock(&svc->srv_lock);
438 *pos = srhi->srhi_seq;
442 OBD_FREE(srhi, sizeof(*srhi));
447 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
449 struct ptlrpc_srh_iterator *srhi = iter;
452 OBD_FREE(srhi, sizeof(*srhi));
456 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
457 void *iter, loff_t *pos)
459 struct ptlrpc_service *svc = s->private;
460 struct ptlrpc_srh_iterator *srhi = iter;
463 cfs_spin_lock(&svc->srv_lock);
464 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos + 1);
465 cfs_spin_unlock(&svc->srv_lock);
468 OBD_FREE(srhi, sizeof(*srhi));
472 *pos = srhi->srhi_seq;
476 /* common ost/mdt srv_req_printfn */
477 void target_print_req(void *seq_file, struct ptlrpc_request *req)
479 /* Called holding srv_lock with irqs disabled.
480 * Print specific req contents and a newline.
481 * CAVEAT EMPTOR: check request message length before printing!!!
482 * You might have received any old crap so you must be just as
483 * careful here as the service's request parser!!! */
484 struct seq_file *sf = seq_file;
486 switch (req->rq_phase) {
488 /* still awaiting a service thread's attention, or rejected
489 * because the generic request message didn't unpack */
490 seq_printf(sf, "<not swabbed>\n");
492 case RQ_PHASE_INTERPRET:
493 /* being handled, so basic msg swabbed, and opc is valid
494 * but racing with mds_handle() */
495 case RQ_PHASE_COMPLETE:
496 /* been handled by mds_handle() reply state possibly still
498 seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg));
501 DEBUG_REQ(D_ERROR, req, "bad phase %d", req->rq_phase);
504 EXPORT_SYMBOL(target_print_req);
506 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
508 struct ptlrpc_service *svc = s->private;
509 struct ptlrpc_srh_iterator *srhi = iter;
510 struct ptlrpc_request *req;
513 cfs_spin_lock(&svc->srv_lock);
515 rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, srhi->srhi_seq);
518 req = srhi->srhi_req;
520 /* Print common req fields.
521 * CAVEAT EMPTOR: we're racing with the service handler
522 * here. The request could contain any old crap, so you
523 * must be just as careful as the service's request
524 * parser. Currently I only print stuff here I know is OK
525 * to look at coz it was set up in request_in_callback()!!! */
526 seq_printf(s, LPD64":%s:%s:x"LPU64":%d:%s:%ld:%lds(%+lds) ",
527 req->rq_history_seq, libcfs_nid2str(req->rq_self),
528 libcfs_id2str(req->rq_peer), req->rq_xid,
529 req->rq_reqlen, ptlrpc_rqphase2str(req),
530 req->rq_arrival_time.tv_sec,
531 req->rq_sent - req->rq_arrival_time.tv_sec,
532 req->rq_sent - req->rq_deadline);
533 if (svc->srv_req_printfn == NULL)
536 svc->srv_req_printfn(s, srhi->srhi_req);
539 cfs_spin_unlock(&svc->srv_lock);
545 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
547 static struct seq_operations sops = {
548 .start = ptlrpc_lprocfs_svc_req_history_start,
549 .stop = ptlrpc_lprocfs_svc_req_history_stop,
550 .next = ptlrpc_lprocfs_svc_req_history_next,
551 .show = ptlrpc_lprocfs_svc_req_history_show,
553 struct proc_dir_entry *dp = PDE(inode);
554 struct seq_file *seqf;
557 LPROCFS_ENTRY_AND_CHECK(dp);
558 rc = seq_open(file, &sops);
564 seqf = file->private_data;
565 seqf->private = dp->data;
569 /* See also lprocfs_rd_timeouts */
570 static int ptlrpc_lprocfs_rd_timeouts(char *page, char **start, off_t off,
571 int count, int *eof, void *data)
573 struct ptlrpc_service *svc = data;
574 unsigned int cur, worst;
580 cur = at_get(&svc->srv_at_estimate);
581 worst = svc->srv_at_estimate.at_worst_ever;
582 worstt = svc->srv_at_estimate.at_worst_time;
583 s2dhms(&ts, cfs_time_current_sec() - worstt);
585 rc += snprintf(page + rc, count - rc,
586 "adaptive timeouts off, using obd_timeout %u\n",
588 rc += snprintf(page + rc, count - rc,
589 "%10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
590 "service", cur, worst, worstt,
592 rc = lprocfs_at_hist_helper(page, count, rc,
593 &svc->srv_at_estimate);
597 static int ptlrpc_lprocfs_rd_hp_ratio(char *page, char **start, off_t off,
598 int count, int *eof, void *data)
600 struct ptlrpc_service *svc = data;
601 int rc = snprintf(page, count, "%d", svc->srv_hpreq_ratio);
605 static int ptlrpc_lprocfs_wr_hp_ratio(struct file *file, const char *buffer,
606 unsigned long count, void *data)
608 struct ptlrpc_service *svc = data;
611 rc = lprocfs_write_helper(buffer, count, &val);
617 cfs_spin_lock(&svc->srv_lock);
618 svc->srv_hpreq_ratio = val;
619 cfs_spin_unlock(&svc->srv_lock);
623 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
624 struct ptlrpc_service *svc)
626 struct lprocfs_vars lproc_vars[] = {
627 {.name = "high_priority_ratio",
628 .read_fptr = ptlrpc_lprocfs_rd_hp_ratio,
629 .write_fptr = ptlrpc_lprocfs_wr_hp_ratio,
631 {.name = "req_buffer_history_len",
632 .read_fptr = ptlrpc_lprocfs_read_req_history_len,
634 {.name = "req_buffer_history_max",
635 .write_fptr = ptlrpc_lprocfs_write_req_history_max,
636 .read_fptr = ptlrpc_lprocfs_read_req_history_max,
638 {.name = "threads_min",
639 .read_fptr = ptlrpc_lprocfs_rd_threads_min,
640 .write_fptr = ptlrpc_lprocfs_wr_threads_min,
642 {.name = "threads_max",
643 .read_fptr = ptlrpc_lprocfs_rd_threads_max,
644 .write_fptr = ptlrpc_lprocfs_wr_threads_max,
646 {.name = "threads_started",
647 .read_fptr = ptlrpc_lprocfs_rd_threads_started,
650 .read_fptr = ptlrpc_lprocfs_rd_timeouts,
654 static struct file_operations req_history_fops = {
655 .owner = THIS_MODULE,
656 .open = ptlrpc_lprocfs_svc_req_history_open,
659 .release = lprocfs_seq_release,
664 ptlrpc_lprocfs_register(entry, svc->srv_name,
665 "stats", &svc->srv_procroot,
668 if (svc->srv_procroot == NULL)
671 lprocfs_add_vars(svc->srv_procroot, lproc_vars, NULL);
673 rc = lprocfs_seq_create(svc->srv_procroot, "req_history",
674 0400, &req_history_fops, svc);
676 CWARN("Error adding the req_history file\n");
679 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
681 ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
682 &obddev->obd_svc_procroot,
683 &obddev->obd_svc_stats);
685 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
687 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req, long amount)
689 struct lprocfs_stats *svc_stats;
690 __u32 op = lustre_msg_get_opc(req->rq_reqmsg);
691 int opc = opcode_offset(op);
693 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
694 if (svc_stats == NULL || opc <= 0)
696 LASSERT(opc < LUSTRE_MAX_OPCODES);
697 if (!(op == LDLM_ENQUEUE || op == MDS_REINT))
698 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, amount);
701 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes)
703 struct lprocfs_stats *svc_stats;
708 svc_stats = req->rq_import->imp_obd->obd_svc_stats;
711 idx = lustre_msg_get_opc(req->rq_reqmsg);
714 idx = BRW_READ_BYTES + PTLRPC_LAST_CNTR;
717 idx = BRW_WRITE_BYTES + PTLRPC_LAST_CNTR;
720 LASSERTF(0, "unsupported opcode %u\n", idx);
724 lprocfs_counter_add(svc_stats, idx, bytes);
727 EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
729 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
731 if (svc->srv_procroot != NULL)
732 lprocfs_remove(&svc->srv_procroot);
735 lprocfs_free_stats(&svc->srv_stats);
738 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
740 if (obd->obd_svc_procroot)
741 lprocfs_remove(&obd->obd_svc_procroot);
743 if (obd->obd_svc_stats)
744 lprocfs_free_stats(&obd->obd_svc_stats);
746 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
749 #define BUFLEN (UUID_MAX + 5)
751 int lprocfs_wr_evict_client(struct file *file, const char *buffer,
752 unsigned long count, void *data)
754 struct obd_device *obd = data;
758 OBD_ALLOC(kbuf, BUFLEN);
763 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
764 * bytes into kbuf, to ensure that the string is NUL-terminated.
765 * UUID_MAX should include a trailing NUL already.
767 if (cfs_copy_from_user(kbuf, buffer,
768 min_t(unsigned long, BUFLEN - 1, count))) {
772 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
773 /* Kludge code(deadlock situation): the lprocfs lock has been held
774 * since the client is evicted by writting client's
775 * uuid/nid to procfs "evict_client" entry. However,
776 * obd_export_evict_by_uuid() will call lprocfs_remove() to destroy
777 * the proc entries under the being destroyed export{}, so I have
778 * to drop the lock at first here.
779 * - jay, jxiong@clusterfs.com */
780 class_incref(obd, __FUNCTION__, cfs_current());
783 if (strncmp(tmpbuf, "nid:", 4) == 0)
784 obd_export_evict_by_nid(obd, tmpbuf + 4);
785 else if (strncmp(tmpbuf, "uuid:", 5) == 0)
786 obd_export_evict_by_uuid(obd, tmpbuf + 5);
788 obd_export_evict_by_uuid(obd, tmpbuf);
791 class_decref(obd, __FUNCTION__, cfs_current());
794 OBD_FREE(kbuf, BUFLEN);
797 EXPORT_SYMBOL(lprocfs_wr_evict_client);
801 int lprocfs_wr_ping(struct file *file, const char *buffer,
802 unsigned long count, void *data)
804 struct obd_device *obd = data;
805 struct ptlrpc_request *req;
809 LPROCFS_CLIMP_CHECK(obd);
810 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
811 LPROCFS_CLIMP_EXIT(obd);
815 req->rq_send_state = LUSTRE_IMP_FULL;
817 rc = ptlrpc_queue_wait(req);
819 ptlrpc_req_finished(req);
824 EXPORT_SYMBOL(lprocfs_wr_ping);
826 /* Write the connection UUID to this file to attempt to connect to that node.
827 * The connection UUID is a node's primary NID. For example,
828 * "echo connection=192.168.0.1@tcp0::instance > .../import".
830 int lprocfs_wr_import(struct file *file, const char *buffer,
831 unsigned long count, void *data)
833 struct obd_device *obd = data;
834 struct obd_import *imp = obd->u.cli.cl_import;
839 const char prefix[] = "connection=";
840 const int prefix_len = sizeof(prefix) - 1;
842 if (count > CFS_PAGE_SIZE - 1 || count <= prefix_len)
845 OBD_ALLOC(kbuf, count + 1);
849 if (cfs_copy_from_user(kbuf, buffer, count))
850 GOTO(out, count = -EFAULT);
854 /* only support connection=uuid::instance now */
855 if (strncmp(prefix, kbuf, prefix_len) != 0)
856 GOTO(out, count = -EINVAL);
858 uuid = kbuf + prefix_len;
859 ptr = strstr(uuid, "::");
867 inst = simple_strtol(ptr, &endptr, 10);
869 CERROR("config: wrong instance # %s\n", ptr);
870 } else if (inst != imp->imp_connect_data.ocd_instance) {
871 CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted "
872 "target(%u/%u), reconnecting...\n",
873 imp->imp_obd->obd_name,
874 imp->imp_connect_data.ocd_instance, inst);
877 CDEBUG(D_INFO, "IR: %s has already been connecting to "
879 imp->imp_obd->obd_name, inst);
884 ptlrpc_recover_import(imp, uuid, 1);
887 OBD_FREE(kbuf, count + 1);
890 EXPORT_SYMBOL(lprocfs_wr_import);
892 int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
893 int count, int *eof, void *data)
895 struct obd_device *obd = data;
896 struct obd_import *imp = obd->u.cli.cl_import;
899 LPROCFS_CLIMP_CHECK(obd);
900 rc = snprintf(page, count, "%d\n", !imp->imp_no_pinger_recover);
901 LPROCFS_CLIMP_EXIT(obd);
905 EXPORT_SYMBOL(lprocfs_rd_pinger_recov);
907 int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
908 unsigned long count, void *data)
910 struct obd_device *obd = data;
911 struct client_obd *cli = &obd->u.cli;
912 struct obd_import *imp = cli->cl_import;
915 rc = lprocfs_write_helper(buffer, count, &val);
919 if (val != 0 && val != 1)
922 LPROCFS_CLIMP_CHECK(obd);
923 cfs_spin_lock(&imp->imp_lock);
924 imp->imp_no_pinger_recover = !val;
925 cfs_spin_unlock(&imp->imp_lock);
926 LPROCFS_CLIMP_EXIT(obd);
931 EXPORT_SYMBOL(lprocfs_wr_pinger_recov);