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 the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
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.
13  *
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.
18  *
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.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #ifndef __KERNEL__
28 # include <liblustre.h>
29 #endif
30
31 #include <obd_support.h>
32 #include <obd.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"
38
39
40 struct ll_rpc_opcode {
41      __u32       opcode;
42      const char *opname;
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         { MDS_WRITEPAGE,    "mds_writepage" },
83         { MDS_IS_SUBDIR,    "mds_is_subdir" },
84         { LDLM_ENQUEUE,     "ldlm_enqueue" },
85         { LDLM_CONVERT,     "ldlm_convert" },
86         { LDLM_CANCEL,      "ldlm_cancel" },
87         { LDLM_BL_CALLBACK, "ldlm_bl_callback" },
88         { LDLM_CP_CALLBACK, "ldlm_cp_callback" },
89         { LDLM_GL_CALLBACK, "ldlm_gl_callback" },
90         { MGS_CONNECT,      "mgs_connect" },
91         { MGS_DISCONNECT,   "mgs_disconnect" },
92         { MGS_EXCEPTION,    "mgs_exception" },
93         { MGS_TARGET_REG,   "mgs_target_reg" },
94         { MGS_TARGET_DEL,   "mgs_target_del" },
95         { MGS_SET_INFO,     "mgs_set_info" },
96         { OBD_PING,         "obd_ping" },
97         { OBD_LOG_CANCEL,   "llog_origin_handle_cancel" },
98         { OBD_QC_CALLBACK,  "obd_qc_callback" },
99         { LLOG_ORIGIN_HANDLE_CREATE,     "llog_origin_handle_create" },
100         { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block" },
101         { LLOG_ORIGIN_HANDLE_READ_HEADER,"llog_origin_handle_read_header" },
102         { LLOG_ORIGIN_HANDLE_WRITE_REC,  "llog_origin_handle_write_rec" },
103         { LLOG_ORIGIN_HANDLE_CLOSE,      "llog_origin_handle_close" },
104         { LLOG_ORIGIN_CONNECT,           "llog_origin_connect" },
105         { LLOG_CATINFO,                  "llog_catinfo" },
106         { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" },
107         { LLOG_ORIGIN_HANDLE_DESTROY,    "llog_origin_handle_destroy" },
108         { FLD_QUERY,        "fld_query" },
109         { SEQ_QUERY,        "seq_query" },
110         { SEC_CTX_INIT,     "sec_ctx_init" },
111         { SEC_CTX_INIT_CONT,"sec_ctx_init_cont" },
112         { SEC_CTX_FINI,     "sec_ctx_fini" }
113 };
114
115 struct ll_eopcode {
116      __u32       opcode;
117      const char *opname;
118 } ll_eopcode_table[EXTRA_LAST_OPC] = {
119         { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" },
120         { LDLM_PLAIN_ENQUEUE,   "ldlm_plain_enqueue" },
121         { LDLM_EXTENT_ENQUEUE,  "ldlm_extent_enqueue" },
122         { LDLM_FLOCK_ENQUEUE,   "ldlm_flock_enqueue" },
123         { LDLM_IBITS_ENQUEUE,   "ldlm_ibits_enqueue" },
124         { MDS_REINT_CREATE,     "mds_reint_create" },
125         { MDS_REINT_LINK,       "mds_reint_link" },
126         { MDS_REINT_OPEN,       "mds_reint_open" },
127         { MDS_REINT_SETATTR,    "mds_reint_setattr" },
128         { MDS_REINT_RENAME,     "mds_reint_rename" },
129         { MDS_REINT_UNLINK,     "mds_reint_unlink" }
130 };
131
132 const char *ll_opcode2str(__u32 opcode)
133 {
134         /* When one of the assertions below fail, chances are that:
135          *     1) A new opcode was added in lustre_idl.h, but was
136          *        is missing from the table above.
137          * or  2) The opcode space was renumbered or rearranged,
138          *        and the opcode_offset() function in
139          *        ptlrpc_internal.h needs to be modified.
140          */
141         __u32 offset = opcode_offset(opcode);
142         LASSERT(offset < LUSTRE_MAX_OPCODES);
143         LASSERT(ll_rpc_opcode_table[offset].opcode == opcode);
144         return ll_rpc_opcode_table[offset].opname;
145 }
146
147 const char* ll_eopcode2str(__u32 opcode)
148 {
149         LASSERT(ll_eopcode_table[opcode].opcode == opcode);
150         return ll_eopcode_table[opcode].opname;
151 }
152 #ifdef LPROCFS
153 void ptlrpc_lprocfs_register(struct proc_dir_entry *root, char *dir,
154                              char *name, struct proc_dir_entry **procroot_ret,
155                              struct lprocfs_stats **stats_ret)
156 {
157         struct proc_dir_entry *svc_procroot;
158         struct lprocfs_stats *svc_stats;
159         int i, rc;
160         unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX |
161                                           LPROCFS_CNTR_STDDEV;
162
163         LASSERT(*procroot_ret == NULL);
164         LASSERT(*stats_ret == NULL);
165
166         svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES, 0);
167         if (svc_stats == NULL)
168                 return;
169
170         if (dir) {
171                 svc_procroot = lprocfs_register(dir, root, NULL, NULL);
172                 if (IS_ERR(svc_procroot)) {
173                         lprocfs_free_stats(&svc_stats);
174                         return;
175                 }
176         } else {
177                 svc_procroot = root;
178         }
179
180         lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR,
181                              svc_counter_config, "req_waittime", "usec");
182         lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR,
183                              svc_counter_config, "req_qdepth", "reqs");
184         lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR,
185                              svc_counter_config, "req_active", "reqs");
186         lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT,
187                              svc_counter_config, "req_timeout", "sec");
188         lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR,
189                              svc_counter_config, "reqbuf_avail", "bufs");
190         for (i = 0; i < EXTRA_LAST_OPC; i++) {
191                 lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i,
192                                      svc_counter_config,
193                                      ll_eopcode2str(i), "reqs");
194         }
195         for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
196                 __u32 opcode = ll_rpc_opcode_table[i].opcode;
197                 lprocfs_counter_init(svc_stats,
198                                      EXTRA_MAX_OPCODES + i, svc_counter_config,
199                                      ll_opcode2str(opcode), "usec");
200         }
201
202         rc = lprocfs_register_stats(svc_procroot, name, svc_stats);
203         if (rc < 0) {
204                 if (dir)
205                         lprocfs_remove(&svc_procroot);
206                 lprocfs_free_stats(&svc_stats);
207         } else {
208                 if (dir)
209                         *procroot_ret = svc_procroot;
210                 *stats_ret = svc_stats;
211         }
212 }
213
214 static int
215 ptlrpc_lprocfs_read_req_history_len(char *page, char **start, off_t off,
216                                     int count, int *eof, void *data)
217 {
218         struct ptlrpc_service *svc = data;
219
220         *eof = 1;
221         return snprintf(page, count, "%d\n", svc->srv_n_history_rqbds);
222 }
223
224 static int
225 ptlrpc_lprocfs_read_req_history_max(char *page, char **start, off_t off,
226                                     int count, int *eof, void *data)
227 {
228         struct ptlrpc_service *svc = data;
229
230         *eof = 1;
231         return snprintf(page, count, "%d\n", svc->srv_max_history_rqbds);
232 }
233
234 static int
235 ptlrpc_lprocfs_write_req_history_max(struct file *file, const char *buffer,
236                                      unsigned long count, void *data)
237 {
238         struct ptlrpc_service *svc = data;
239         int                    bufpages;
240         int                    val;
241         int                    rc = lprocfs_write_helper(buffer, count, &val);
242
243         if (rc < 0)
244                 return rc;
245
246         if (val < 0)
247                 return -ERANGE;
248
249         /* This sanity check is more of an insanity check; we can still
250          * hose a kernel by allowing the request history to grow too
251          * far. */
252         bufpages = (svc->srv_buf_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
253         if (val > num_physpages/(2 * bufpages))
254                 return -ERANGE;
255
256         spin_lock(&svc->srv_lock);
257         svc->srv_max_history_rqbds = val;
258         spin_unlock(&svc->srv_lock);
259
260         return count;
261 }
262
263 struct ptlrpc_srh_iterator {
264         __u64                  srhi_seq;
265         struct ptlrpc_request *srhi_req;
266 };
267
268 int
269 ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service *svc,
270                                     struct ptlrpc_srh_iterator *srhi,
271                                     __u64 seq)
272 {
273         struct list_head      *e;
274         struct ptlrpc_request *req;
275
276         if (srhi->srhi_req != NULL &&
277             srhi->srhi_seq > svc->srv_request_max_cull_seq &&
278             srhi->srhi_seq <= seq) {
279                 /* If srhi_req was set previously, hasn't been culled and
280                  * we're searching for a seq on or after it (i.e. more
281                  * recent), search from it onwards.
282                  * Since the service history is LRU (i.e. culled reqs will
283                  * be near the head), we shouldn't have to do long
284                  * re-scans */
285                 LASSERT (srhi->srhi_seq == srhi->srhi_req->rq_history_seq);
286                 LASSERT (!list_empty(&svc->srv_request_history));
287                 e = &srhi->srhi_req->rq_history_list;
288         } else {
289                 /* search from start */
290                 e = svc->srv_request_history.next;
291         }
292
293         while (e != &svc->srv_request_history) {
294                 req = list_entry(e, struct ptlrpc_request, rq_history_list);
295
296                 if (req->rq_history_seq >= seq) {
297                         srhi->srhi_seq = req->rq_history_seq;
298                         srhi->srhi_req = req;
299                         return 0;
300                 }
301                 e = e->next;
302         }
303
304         return -ENOENT;
305 }
306
307 static void *
308 ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
309 {
310         struct ptlrpc_service       *svc = s->private;
311         struct ptlrpc_srh_iterator  *srhi;
312         int                          rc;
313
314         OBD_ALLOC(srhi, sizeof(*srhi));
315         if (srhi == NULL)
316                 return NULL;
317
318         srhi->srhi_seq = 0;
319         srhi->srhi_req = NULL;
320
321         spin_lock(&svc->srv_lock);
322         rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos);
323         spin_unlock(&svc->srv_lock);
324
325         if (rc == 0) {
326                 *pos = srhi->srhi_seq;
327                 return srhi;
328         }
329
330         OBD_FREE(srhi, sizeof(*srhi));
331         return NULL;
332 }
333
334 static void
335 ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
336 {
337         struct ptlrpc_srh_iterator *srhi = iter;
338
339         if (srhi != NULL)
340                 OBD_FREE(srhi, sizeof(*srhi));
341 }
342
343 static void *
344 ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
345                                     void *iter, loff_t *pos)
346 {
347         struct ptlrpc_service       *svc = s->private;
348         struct ptlrpc_srh_iterator  *srhi = iter;
349         int                          rc;
350
351         spin_lock(&svc->srv_lock);
352         rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, *pos + 1);
353         spin_unlock(&svc->srv_lock);
354
355         if (rc != 0) {
356                 OBD_FREE(srhi, sizeof(*srhi));
357                 return NULL;
358         }
359
360         *pos = srhi->srhi_seq;
361         return srhi;
362 }
363
364 /* common ost/mdt srv_request_history_print_fn */
365 void target_print_req(void *seq_file, struct ptlrpc_request *req)
366 {
367         /* Called holding srv_lock with irqs disabled.
368          * Print specific req contents and a newline.
369          * CAVEAT EMPTOR: check request message length before printing!!!
370          * You might have received any old crap so you must be just as
371          * careful here as the service's request parser!!! */
372         struct seq_file *sf = seq_file;
373
374         switch (req->rq_phase) {
375         case RQ_PHASE_NEW:
376                 /* still awaiting a service thread's attention, or rejected
377                  * because the generic request message didn't unpack */
378                 seq_printf(sf, "<not swabbed>\n");
379                 break;
380         case RQ_PHASE_INTERPRET:
381                 /* being handled, so basic msg swabbed, and opc is valid
382                  * but racing with mds_handle() */
383         case RQ_PHASE_COMPLETE:
384                 /* been handled by mds_handle() reply state possibly still
385                  * volatile */
386                 seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg));
387                 break;
388         default:
389                 DEBUG_REQ(D_ERROR, req, "bad phase %d", req->rq_phase);
390         }
391 }
392 EXPORT_SYMBOL(target_print_req);
393
394 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
395 {
396         struct ptlrpc_service      *svc = s->private;
397         struct ptlrpc_srh_iterator *srhi = iter;
398         struct ptlrpc_request      *req;
399         int                         rc;
400
401         spin_lock(&svc->srv_lock);
402
403         rc = ptlrpc_lprocfs_svc_req_history_seek(svc, srhi, srhi->srhi_seq);
404
405         if (rc == 0) {
406                 req = srhi->srhi_req;
407
408                 /* Print common req fields.
409                  * CAVEAT EMPTOR: we're racing with the service handler
410                  * here.  The request could contain any old crap, so you
411                  * must be just as careful as the service's request
412                  * parser. Currently I only print stuff here I know is OK
413                  * to look at coz it was set up in request_in_callback()!!! */
414                 seq_printf(s, LPD64":%s:%s:x"LPD64":%d:%s:%ld:%lds(%+lds) ",
415                            req->rq_history_seq, libcfs_nid2str(req->rq_self),
416                            libcfs_id2str(req->rq_peer), req->rq_xid,
417                            req->rq_reqlen, ptlrpc_rqphase2str(req),
418                            req->rq_arrival_time.tv_sec,
419                            req->rq_sent - req->rq_arrival_time.tv_sec,
420                            req->rq_sent - req->rq_deadline);
421                 if (svc->srv_request_history_print_fn == NULL)
422                         seq_printf(s, "\n");
423                 else
424                         svc->srv_request_history_print_fn(s, srhi->srhi_req);
425         }
426
427         spin_unlock(&svc->srv_lock);
428
429         return rc;
430 }
431
432 static int
433 ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
434 {
435         static struct seq_operations sops = {
436                 .start = ptlrpc_lprocfs_svc_req_history_start,
437                 .stop  = ptlrpc_lprocfs_svc_req_history_stop,
438                 .next  = ptlrpc_lprocfs_svc_req_history_next,
439                 .show  = ptlrpc_lprocfs_svc_req_history_show,
440         };
441         struct proc_dir_entry *dp = PDE(inode);
442         struct seq_file       *seqf;
443         int                    rc;
444
445         LPROCFS_ENTRY_AND_CHECK(dp);
446         rc = seq_open(file, &sops);
447         if (rc) {
448                 LPROCFS_EXIT();
449                 return rc;
450         }
451
452         seqf = file->private_data;
453         seqf->private = dp->data;
454         return 0;
455 }
456
457 /* See also lprocfs_rd_timeouts */
458 static int ptlrpc_lprocfs_rd_timeouts(char *page, char **start, off_t off,
459                                       int count, int *eof, void *data)
460 {
461         struct ptlrpc_service *svc = data;
462         unsigned int cur, worst;
463         time_t worstt;
464         struct dhms ts;
465         int rc = 0;
466
467         *eof = 1;
468         cur = at_get(&svc->srv_at_estimate);
469         worst = svc->srv_at_estimate.at_worst_ever;
470         worstt = svc->srv_at_estimate.at_worst_time;
471         s2dhms(&ts, cfs_time_current_sec() - worstt);
472         if (AT_OFF)
473                 rc += snprintf(page + rc, count - rc,
474                               "adaptive timeouts off, using obd_timeout %u\n",
475                               obd_timeout);
476         rc += snprintf(page + rc, count - rc,
477                        "%10s : cur %3u  worst %3u (at %ld, "DHMS_FMT" ago) ",
478                        "service", cur, worst, worstt,
479                        DHMS_VARS(&ts));
480         rc = lprocfs_at_hist_helper(page, count, rc,
481                                     &svc->srv_at_estimate);
482         return rc;
483 }
484
485 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
486                                      struct ptlrpc_service *svc)
487 {
488         struct lprocfs_vars lproc_vars[] = {
489                 {.name       = "req_buffer_history_len",
490                  .write_fptr = NULL,
491                  .read_fptr  = ptlrpc_lprocfs_read_req_history_len,
492                  .data       = svc},
493                 {.name       = "req_buffer_history_max",
494                  .write_fptr = ptlrpc_lprocfs_write_req_history_max,
495                  .read_fptr  = ptlrpc_lprocfs_read_req_history_max,
496                  .data       = svc},
497                 {.name       = "timeouts",
498                  .read_fptr  = ptlrpc_lprocfs_rd_timeouts,
499                  .data       = svc},
500                 {NULL}
501         };
502         static struct file_operations req_history_fops = {
503                 .owner       = THIS_MODULE,
504                 .open        = ptlrpc_lprocfs_svc_req_history_open,
505                 .read        = seq_read,
506                 .llseek      = seq_lseek,
507                 .release     = lprocfs_seq_release,
508         };
509
510         int rc;
511
512         ptlrpc_lprocfs_register(entry, svc->srv_name,
513                                 "stats", &svc->srv_procroot,
514                                 &svc->srv_stats);
515
516         if (svc->srv_procroot == NULL)
517                 return;
518
519         lprocfs_add_vars(svc->srv_procroot, lproc_vars, NULL);
520
521         rc = lprocfs_seq_create(svc->srv_procroot, "req_history",
522                                 0400, &req_history_fops, svc);
523         if (rc)
524                 CWARN("Error adding the req_history file\n");
525 }
526
527 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev)
528 {
529         ptlrpc_lprocfs_register(obddev->obd_proc_entry, NULL, "stats",
530                                 &obddev->obd_svc_procroot,
531                                 &obddev->obd_svc_stats);
532 }
533 EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd);
534
535 void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req)
536 {
537         struct lprocfs_stats *svc_stats;
538         __u32 op = lustre_msg_get_opc(req->rq_reqmsg);
539         int opc = opcode_offset(op);
540
541         svc_stats = req->rq_import->imp_obd->obd_svc_stats;
542         if (svc_stats == NULL || opc <= 0)
543                 return;
544         LASSERT(opc < LUSTRE_MAX_OPCODES);
545         /* These two use the ptlrpc_lprocfs_brw below */
546         if (!(opc == OST_WRITE || opc == OST_READ || op == LDLM_ENQUEUE
547               || op == MDS_REINT))
548                 lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, 0);
549 }
550
551 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes)
552 {
553         struct lprocfs_stats *svc_stats;
554         svc_stats = req->rq_import->imp_obd->obd_svc_stats;
555         if (!svc_stats) 
556                 return;
557         lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, bytes);
558 }
559 EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
560
561 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
562 {
563         if (svc->srv_procroot != NULL)
564                 lprocfs_remove(&svc->srv_procroot);
565
566         if (svc->srv_stats)
567                 lprocfs_free_stats(&svc->srv_stats);
568 }
569
570 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
571 {
572         if (obd->obd_svc_procroot)
573                 lprocfs_remove(&obd->obd_svc_procroot);
574
575         if (obd->obd_svc_stats)
576                 lprocfs_free_stats(&obd->obd_svc_stats);
577 }
578 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
579
580
581 int lprocfs_wr_evict_client(struct file *file, const char *buffer,
582                             unsigned long count, void *data)
583 {
584         struct obd_device *obd = data;
585         char tmpbuf[sizeof(struct obd_uuid)];
586
587         /* Kludge code(deadlock situation): the lprocfs lock has been held 
588          * since the client is evicted by writting client's
589          * uuid/nid to procfs "evict_client" entry. However, 
590          * obd_export_evict_by_uuid() will call lprocfs_remove() to destroy
591          * the proc entries under the being destroyed export{}, so I have
592          * to drop the lock at first here. 
593          * - jay, jxiong@clusterfs.com */
594         class_incref(obd);
595         LPROCFS_EXIT();
596  
597         sscanf(buffer, "%40s", tmpbuf);
598         if (strncmp(tmpbuf, "nid:", 4) == 0)
599                 obd_export_evict_by_nid(obd, tmpbuf + 4);
600         else if (strncmp(tmpbuf, "uuid:", 5) == 0)
601                 obd_export_evict_by_uuid(obd, tmpbuf + 5);
602         else
603                 obd_export_evict_by_uuid(obd, tmpbuf);
604
605         LPROCFS_ENTRY();
606         class_decref(obd);
607
608         return count;
609 }
610 EXPORT_SYMBOL(lprocfs_wr_evict_client);
611
612 int lprocfs_wr_ping(struct file *file, const char *buffer,
613                     unsigned long count, void *data)
614 {
615         struct obd_device     *obd = data;
616         struct ptlrpc_request *req;
617         int                    rc;
618         ENTRY;
619
620         LPROCFS_CLIMP_CHECK(obd);
621         req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_OBD_PING,
622                                         LUSTRE_OBD_VERSION, OBD_PING);
623
624         LPROCFS_CLIMP_EXIT(obd);
625         if (req == NULL)
626                 RETURN(-ENOMEM);
627
628         ptlrpc_request_set_replen(req);
629         req->rq_send_state = LUSTRE_IMP_FULL;
630         req->rq_no_resend = 1;
631         req->rq_no_delay = 1;
632
633         rc = ptlrpc_queue_wait(req);
634
635         ptlrpc_req_finished(req);
636         if (rc >= 0)
637                 RETURN(count);
638         RETURN(rc);
639 }
640 EXPORT_SYMBOL(lprocfs_wr_ping);
641
642 #endif /* LPROCFS */