Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[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_SYNCFS,       "ost_syncfs" },
53         { OST_SET_INFO,     "ost_set_info" },
54         { MDS_GETATTR,      "mds_getattr" },
55         { MDS_GETATTR_NAME, "mds_getattr_name" },
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_GETLOVINFO,   "mds_getlovinfo" },
64         { MDS_PIN,          "mds_pin" },
65         { MDS_UNPIN,        "mds_unpin" },
66         { LDLM_ENQUEUE,     "ldlm_enqueue" },
67         { LDLM_CONVERT,     "ldlm_convert" },
68         { LDLM_CANCEL,      "ldlm_cancel" },
69         { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
70         { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
71         { PTLBD_QUERY,      "ptlbd_query" },
72         { PTLBD_READ,       "ptlbd_read" },
73         { PTLBD_WRITE,      "ptlbd_write" },
74         { PTLBD_FLUSH,      "ptlbd_flush" },
75         { PTLBD_CONNECT,    "ptlbd_connect" },
76         { PTLBD_DISCONNECT, "ptlbd_disconnect" },
77         { OBD_PING,         "obd_ping" },
78         { OBD_LOG_CANCEL,   "obd_log_cancel" },
79 };
80
81 const char* ll_opcode2str(__u32 opcode)
82 {
83         /* When one of the assertions below fail, chances are that:
84          *     1) A new opcode was added in lustre_idl.h, but was
85          *        is missing from the table above.
86          * or  2) The opcode space was renumbered or rearranged,
87          *        and the opcode_offset() function in
88          *        ptlrpc_internals.h needs to be modified.
89          */
90         __u32 offset = opcode_offset(opcode);
91         LASSERT(offset < LUSTRE_MAX_OPCODES);
92         LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
93         return ll_rpc_opcode_table[offset].opname;
94 }
95
96 #ifndef LPROCFS
97 void ptlrpc_lprocfs_register_service(struct obd_device *obddev,
98                                      struct ptlrpc_service *svc) { return ; }
99 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc) { return; }
100 #else
101
102 void ptlrpc_lprocfs_register_service(struct obd_device *obddev,
103                                      struct ptlrpc_service *svc)
104 {
105         struct proc_dir_entry *svc_procroot;
106         struct lprocfs_stats *svc_stats;
107         int i, rc;
108         unsigned int svc_counter_config = LPROCFS_CNTR_EXTERNALLOCK |
109                 LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV;
110
111         LASSERT(svc->svc_procroot == NULL);
112         LASSERT(svc->svc_stats == NULL);
113
114         svc_procroot = lprocfs_register(svc->srv_name, obddev->obd_proc_entry,
115                                         NULL, NULL);
116         if (svc_procroot == NULL)
117                 return;
118
119         svc_stats = lprocfs_alloc_stats(PTLRPC_LAST_CNTR + LUSTRE_MAX_OPCODES);
120         if (svc_stats == NULL) {
121                 lprocfs_remove(svc_procroot);
122                 return;
123         }
124
125         lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
126                              svc_counter_config, "req_waittime", "usec");
127         /* Wait for b_eq branch
128         lprocfs_counter_init(svc_stats, PTLRPC_SVCEQDEPTH_CNTR,
129                              svc_counter_config, "svc_eqdepth", "reqs");
130          */
131         /* no stddev on idletime */
132         lprocfs_counter_init(svc_stats, PTLRPC_SVCIDLETIME_CNTR,
133                              (LPROCFS_CNTR_EXTERNALLOCK|LPROCFS_CNTR_AVGMINMAX),
134                              "svc_idletime", "usec");
135         for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
136                 __u32 opcode = ll_rpc_opcode_table[i].opcode;
137                 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
138                                      svc_counter_config, ll_opcode2str(opcode),
139                                      "usec");
140         }
141
142         rc = lprocfs_register_stats(svc_procroot, "stats", svc_stats);
143         if (rc < 0) {
144                 lprocfs_remove(svc_procroot);
145                 lprocfs_free_stats(svc_stats);
146         } else {
147                 svc->svc_procroot = svc_procroot;
148                 svc->svc_stats = svc_stats;
149         }
150 }
151
152 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
153 {
154         if (svc->svc_procroot) {
155                 lprocfs_remove(svc->svc_procroot);
156                 svc->svc_procroot = NULL;
157         }
158         if (svc->svc_stats) {
159                 lprocfs_free_stats(svc->svc_stats);
160                 svc->svc_stats = NULL;
161         }
162 }
163 #endif /* LPROCFS */