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