Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / ptlrpc / lproc_ptlrpc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/obd_support.h>
25 #include <linux/obd.h>
26 #include <linux/lprocfs_status.h>
27 #include <linux/lustre_idl.h>
28 #include <linux/lustre_net.h>
29 #include "ptlrpc_internal.h"
30
31
32 struct ll_rpc_opcode {
33      __u32       opcode;
34      const char *opname;
35 } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = {
36         { OST_REPLY,             "ost_reply" },
37         { OST_GETATTR,           "ost_getattr" },
38         { OST_SETATTR,           "ost_setattr" },
39         { OST_READ,              "ost_read" },
40         { OST_WRITE,             "ost_write" },
41         { OST_CREATE ,           "ost_create" },
42         { OST_DESTROY,           "ost_destroy" },
43         { OST_GET_INFO,          "ost_get_info" },
44         { OST_CONNECT,           "ost_connect" },
45         { OST_DISCONNECT,        "ost_disconnect" },
46         { OST_PUNCH,             "ost_punch" },
47         { OST_OPEN,              "ost_open" },
48         { OST_CLOSE,             "ost_close" },
49         { OST_STATFS,            "ost_statfs" },
50         { OST_SAN_READ,          "ost_san_read" },
51         { OST_SAN_WRITE,         "ost_san_write" },
52         { OST_SYNC,              "ost_sync" },
53         { OST_SET_INFO,          "ost_set_info" },
54         { MDS_GETATTR,           "mds_getattr" },
55         { MDS_GETATTR_LOCK ,     "mds_getattr_lock" },
56         { MDS_CLOSE,             "mds_close" },
57         { MDS_REINT,             "mds_reint" },
58         { MDS_READPAGE,          "mds_readpage" },
59         { MDS_CONNECT,           "mds_connect" },
60         { MDS_DISCONNECT,        "mds_disconnect" },
61         { MDS_GETSTATUS,         "mds_getstatus" },
62         { MDS_STATFS,            "mds_statfs" },
63         { MDS_PIN,               "mds_pin" },
64         { MDS_UNPIN,             "mds_unpin" },
65         { MDS_SYNC,              "mds_sync" },
66         { MDS_DONE_WRITING,      "mds_done_writing" },
67         { MDS_ACCESS_CHECK,      "mds_access_check"},
68         { MDS_PARSE_ID,          "mds_parse_id" },
69         { LDLM_ENQUEUE,          "ldlm_enqueue" },
70         { LDLM_CONVERT,          "ldlm_convert" },
71         { LDLM_CANCEL,           "ldlm_cancel" },
72         { LDLM_BL_CALLBACK,      "ldlm_bl_callback" },
73         { LDLM_CP_CALLBACK,      "ldlm_cp_callback" },
74         { LDLM_GL_CALLBACK,      "ldlm_gl_callback" },
75         { LDLM_FLK_DEADLOCK_CHK, "ldlm_flock_deadlock_check" },
76         { PTLBD_QUERY,           "ptlbd_query" },
77         { PTLBD_READ,            "ptlbd_read" },
78         { PTLBD_WRITE,           "ptlbd_write" },
79         { PTLBD_FLUSH,           "ptlbd_flush" },
80         { PTLBD_CONNECT,         "ptlbd_connect" },
81         { PTLBD_DISCONNECT,      "ptlbd_disconnect" },
82         { OBD_PING,              "obd_ping" },
83         { OBD_LOG_CANCEL,        "llog_origin_handle_cancel"},
84         { SEC_INIT,              "sec_init"},
85         { SEC_INIT_CONTINUE,     "sec_init_continue"},
86         { SEC_FINI,              "sec_fini"},
87 };
88
89 const char* ll_opcode2str(__u32 opcode)
90 {
91         /* When one of the assertions below fail, chances are that:
92          *     1) A new opcode was added in lustre_idl.h, but was
93          *        is missing from the table above.
94          * or  2) The opcode space was renumbered or rearranged,
95          *        and the opcode_offset() function in
96          *        ptlrpc_internals.h needs to be modified.
97          */
98         __u32 offset = opcode_offset(opcode);
99         LASSERT(offset < LUSTRE_MAX_OPCODES);
100         LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
101         return ll_rpc_opcode_table[offset].opname;
102 }
103
104 #ifndef LPROCFS
105 void ptlrpc_lprocfs_register_service(struct obd_device *obddev,
106                                      struct ptlrpc_service *svc) { return ; }
107 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc) { return; }
108 #else
109
110 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
111                              char *name, struct proc_dir_entry **procroot_ret,
112                              struct lprocfs_stats **stats_ret)
113 {
114         struct proc_dir_entry *svc_procroot;
115         struct lprocfs_stats *svc_stats;
116         int i, rc;
117         unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX | 
118                                           LPROCFS_CNTR_STDDEV;
119
120         LASSERT(*procroot_ret == NULL);
121         LASSERT(*stats_ret == NULL);
122
123         svc_stats = lprocfs_alloc_stats(PTLRPC_LAST_CNTR + LUSTRE_MAX_OPCODES);
124         if (svc_stats == NULL)
125                 return;
126
127         if (dir) {
128                 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
129                 if (IS_ERR(svc_procroot)) {
130                         lprocfs_free_stats(svc_stats);
131                         return;
132                 }
133         } else {
134                 svc_procroot = root;
135         }
136
137         lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
138                              svc_counter_config, "req_waittime", "usec");
139         lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
140                              svc_counter_config, "req_qdepth", "reqs");
141         lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
142                              svc_counter_config, "req_active", "reqs");
143         lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
144                              svc_counter_config, "reqbuf_avail", "bufs");
145
146         for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
147                 __u32 opcode = ll_rpc_opcode_table[i].opcode;
148                 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
149                                      svc_counter_config, ll_opcode2str(opcode),
150                                      "usec");
151         }
152
153         rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
154         if (rc < 0) {
155                 if (dir)
156                         lprocfs_remove(svc_procroot);
157                 lprocfs_free_stats(svc_stats);
158         } else {
159                 if (dir)
160                         *procroot_ret = svc_procroot;
161                 *stats_ret = svc_stats;
162         }
163 }
164
165 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
166                                      struct ptlrpc_service *svc)
167 {
168         ptlrpc_lprocfs_register(entry, svc->srv_name,
169                                 "stats", &svc->srv_procroot,
170                                 &svc->srv_stats);
171 }
172
173 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
174 {
175         ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
176                                 &obddev->obd_svc_procroot,
177                                 &obddev->obd_svc_stats);
178 }
179
180 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req)
181 {
182         struct lprocfs_stats *svc_stats;
183         int opc =  opcode_offset(req->rq_reqmsg->opc);
184
185         svc_stats = req->rq_import->imp_obd->obd_svc_stats;
186         if (svc_stats == NULL || opc <= 0)
187                 return;
188         LASSERT(opc < LUSTRE_MAX_OPCODES);
189         lprocfs_counter_add(svc_stats, opc + PTLRPC_LAST_CNTR, 0);
190 }
191
192 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
193 {
194         if (svc->srv_procroot != NULL) {
195                 lprocfs_remove(svc->srv_procroot);
196                 svc->srv_procroot = NULL;
197         }
198         if (svc->srv_stats) {
199                 lprocfs_free_stats(svc->srv_stats);
200                 svc->srv_stats = NULL;
201         }
202 }
203 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
204 {
205         if (obd->obd_svc_procroot) {
206                 lprocfs_remove(obd->obd_svc_procroot);
207                 obd->obd_svc_procroot = NULL;
208         }
209         if (obd->obd_svc_stats) {
210                 lprocfs_free_stats(obd->obd_svc_stats);
211                 obd->obd_svc_stats = NULL;
212         }
213 }
214 #endif /* LPROCFS */