Whamcloud - gitweb
4917fe6eb626c8285c0c8aedda733722b69f2993
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status_server.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2014, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/obdclass/lprocfs_status_server.c
33  */
34
35 #define DEBUG_SUBSYSTEM S_CLASS
36
37
38 #include <obd_class.h>
39 #include <lprocfs_status.h>
40 #include <lustre/lustre_idl.h>
41 #include <lustre_nodemap.h>
42
43 #ifdef CONFIG_PROC_FS
44
45 int lprocfs_evict_client_open(struct inode *inode, struct file *f)
46 {
47         struct obd_device *obd = PDE_DATA(f->f_path.dentry->d_inode);
48
49         atomic_inc(&obd->obd_evict_inprogress);
50         return 0;
51 }
52
53 int lprocfs_evict_client_release(struct inode *inode, struct file *f)
54 {
55         struct obd_device *obd = PDE_DATA(f->f_path.dentry->d_inode);
56
57         atomic_dec(&obd->obd_evict_inprogress);
58         wake_up(&obd->obd_evict_inprogress_waitq);
59
60         return 0;
61 }
62
63 #define BUFLEN (UUID_MAX + 5)
64
65 ssize_t
66 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
67                                size_t count, loff_t *off)
68 {
69         struct seq_file *m = file->private_data;
70         struct obd_device *obd = m->private;
71         char *tmpbuf, *kbuf;
72
73         OBD_ALLOC(kbuf, BUFLEN);
74         if (kbuf == NULL)
75                 return -ENOMEM;
76
77         /*
78          * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
79          * bytes into kbuf, to ensure that the string is NUL-terminated.
80          * UUID_MAX should include a trailing NUL already.
81          */
82         if (copy_from_user(kbuf, buffer,
83                            min_t(unsigned long, BUFLEN - 1, count))) {
84                 count = -EFAULT;
85                 goto out;
86         }
87         tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
88         class_incref(obd, __func__, current);
89
90         if (strncmp(tmpbuf, "nid:", 4) == 0)
91                 obd_export_evict_by_nid(obd, tmpbuf + 4);
92         else if (strncmp(tmpbuf, "uuid:", 5) == 0)
93                 obd_export_evict_by_uuid(obd, tmpbuf + 5);
94         else
95                 obd_export_evict_by_uuid(obd, tmpbuf);
96
97         class_decref(obd, __func__, current);
98
99 out:
100         OBD_FREE(kbuf, BUFLEN);
101         return count;
102 }
103 EXPORT_SYMBOL(lprocfs_evict_client_seq_write);
104
105 #undef BUFLEN
106
107 int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
108 {
109         struct obd_device *obd = data;
110
111         LASSERT(obd != NULL);
112         return seq_printf(m, "%u\n", obd->obd_num_exports);
113 }
114 EXPORT_SYMBOL(lprocfs_num_exports_seq_show);
115
116 static void lprocfs_free_client_stats(struct nid_stat *client_stat)
117 {
118         CDEBUG(D_CONFIG, "stat %p - data %p/%p\n", client_stat,
119                client_stat->nid_proc, client_stat->nid_stats);
120
121         LASSERTF(atomic_read(&client_stat->nid_exp_ref_count) == 0,
122                  "nid %s:count %d\n", libcfs_nid2str(client_stat->nid),
123                  atomic_read(&client_stat->nid_exp_ref_count));
124
125         if (client_stat->nid_proc)
126                 lprocfs_remove(&client_stat->nid_proc);
127
128         if (client_stat->nid_stats)
129                 lprocfs_free_stats(&client_stat->nid_stats);
130
131         if (client_stat->nid_ldlm_stats)
132                 lprocfs_free_stats(&client_stat->nid_ldlm_stats);
133
134         OBD_FREE_PTR(client_stat);
135         return;
136 }
137
138 void lprocfs_free_per_client_stats(struct obd_device *obd)
139 {
140         cfs_hash_t *hash = obd->obd_nid_stats_hash;
141         struct nid_stat *stat;
142         ENTRY;
143
144         /* we need extra list - because hash_exit called to early */
145         /* not need locking because all clients is died */
146         while (!list_empty(&obd->obd_nid_stats)) {
147                 stat = list_entry(obd->obd_nid_stats.next,
148                                   struct nid_stat, nid_list);
149                 list_del_init(&stat->nid_list);
150                 cfs_hash_del(hash, &stat->nid, &stat->nid_hash);
151                 lprocfs_free_client_stats(stat);
152         }
153         EXIT;
154 }
155 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
156
157 static int lprocfs_exp_print_uuid_seq(cfs_hash_t *hs, cfs_hash_bd_t *bd,
158                                       struct hlist_node *hnode, void *cb_data)
159 {
160         struct seq_file *m = cb_data;
161         struct obd_export *exp = cfs_hash_object(hs, hnode);
162
163         if (exp->exp_nid_stats != NULL)
164                 seq_printf(m, "%s\n", obd_uuid2str(&exp->exp_client_uuid));
165         return 0;
166 }
167
168 static int lprocfs_exp_print_nodemap_seq(cfs_hash_t *hs, cfs_hash_bd_t *bd,
169                                         struct hlist_node *hnode, void *cb_data)
170 {
171         struct seq_file *m = cb_data;
172         struct obd_export *exp = cfs_hash_object(hs, hnode);
173         struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap;
174
175         if (nodemap != NULL)
176                 seq_printf(m, "%s\n", nodemap->nm_name);
177         return 0;
178 }
179
180 static int lprocfs_exp_nodemap_seq_show(struct seq_file *m, void *data)
181 {
182         struct nid_stat *stats = m->private;
183         struct obd_device *obd = stats->nid_obd;
184
185         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
186                               lprocfs_exp_print_nodemap_seq, m);
187         return 0;
188 }
189 LPROC_SEQ_FOPS_RO(lprocfs_exp_nodemap);
190
191 static int lprocfs_exp_uuid_seq_show(struct seq_file *m, void *data)
192 {
193         struct nid_stat *stats = m->private;
194         struct obd_device *obd = stats->nid_obd;
195
196         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
197                                 lprocfs_exp_print_uuid_seq, m);
198         return 0;
199 }
200 LPROC_SEQ_FOPS_RO(lprocfs_exp_uuid);
201
202 static int lprocfs_exp_print_hash_seq(cfs_hash_t *hs, cfs_hash_bd_t *bd,
203                                       struct hlist_node *hnode, void *cb_data)
204
205 {
206         struct seq_file *m = cb_data;
207         struct obd_export *exp = cfs_hash_object(hs, hnode);
208
209         if (exp->exp_lock_hash != NULL) {
210                 cfs_hash_debug_header(m);
211                 cfs_hash_debug_str(hs, m);
212         }
213         return 0;
214 }
215
216 static int lprocfs_exp_hash_seq_show(struct seq_file *m, void *data)
217 {
218         struct nid_stat *stats = m->private;
219         struct obd_device *obd = stats->nid_obd;
220
221         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
222                                 lprocfs_exp_print_hash_seq, m);
223         return 0;
224 }
225 LPROC_SEQ_FOPS_RO(lprocfs_exp_hash);
226
227 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
228 {
229         return seq_printf(m, "%s\n", "Write into this file to clear all nid "
230                           "stats and stale nid entries");
231 }
232 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_show);
233
234 static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
235 {
236         struct nid_stat *stat = obj;
237         ENTRY;
238
239         CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
240         if (atomic_read(&stat->nid_exp_ref_count) == 1) {
241                 /* object has only hash references. */
242                 spin_lock(&stat->nid_obd->obd_nid_lock);
243                 list_move(&stat->nid_list, data);
244                 spin_unlock(&stat->nid_obd->obd_nid_lock);
245                 RETURN(1);
246         }
247         /* we has reference to object - only clear data*/
248         if (stat->nid_stats)
249                 lprocfs_clear_stats(stat->nid_stats);
250
251         RETURN(0);
252 }
253
254 ssize_t
255 lprocfs_nid_stats_clear_seq_write(struct file *file, const char *buffer,
256                                         size_t count, loff_t *off)
257 {
258         struct seq_file *m = file->private_data;
259         struct obd_device *obd = m->private;
260         struct nid_stat *client_stat;
261         struct list_head free_list;
262
263         INIT_LIST_HEAD(&free_list);
264         cfs_hash_cond_del(obd->obd_nid_stats_hash,
265                           lprocfs_nid_stats_clear_write_cb, &free_list);
266
267         while (!list_empty(&free_list)) {
268                 client_stat = list_entry(free_list.next, struct nid_stat,
269                                          nid_list);
270                 list_del_init(&client_stat->nid_list);
271                 lprocfs_free_client_stats(client_stat);
272         }
273         return count;
274 }
275 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_write);
276
277 int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid)
278 {
279         struct nid_stat *new_stat, *old_stat;
280         struct obd_device *obd = NULL;
281         struct proc_dir_entry *entry;
282         char nidstr[LNET_NIDSTR_SIZE];
283         int rc = 0;
284         ENTRY;
285
286         if (!exp || !exp->exp_obd || !exp->exp_obd->obd_proc_exports_entry ||
287             !exp->exp_obd->obd_nid_stats_hash)
288                 RETURN(-EINVAL);
289
290         /* not test against zero because eric say:
291          * You may only test nid against another nid, or LNET_NID_ANY.
292          * Anything else is nonsense.*/
293         if (nid == NULL || *nid == LNET_NID_ANY)
294                 RETURN(-EALREADY);
295
296         libcfs_nid2str_r(*nid, nidstr, sizeof(nidstr));
297
298         spin_lock(&exp->exp_lock);
299         if (exp->exp_nid_stats != NULL) {
300                 spin_unlock(&exp->exp_lock);
301                 RETURN(-EALREADY);
302         }
303         spin_unlock(&exp->exp_lock);
304
305         obd = exp->exp_obd;
306
307         CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
308
309         OBD_ALLOC_PTR(new_stat);
310         if (new_stat == NULL)
311                 RETURN(-ENOMEM);
312
313         new_stat->nid     = *nid;
314         new_stat->nid_obd = exp->exp_obd;
315         /* we need set default refcount to 1 to balance obd_disconnect */
316         atomic_set(&new_stat->nid_exp_ref_count, 1);
317
318         old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
319                                            nid, &new_stat->nid_hash);
320         CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
321                old_stat, nidstr, atomic_read(&old_stat->nid_exp_ref_count));
322
323         /* Return -EALREADY here so that we know that the /proc
324          * entry already has been created */
325         if (old_stat != new_stat) {
326                 spin_lock(&exp->exp_lock);
327                 if (exp->exp_nid_stats) {
328                         LASSERT(exp->exp_nid_stats == old_stat);
329                         nidstat_putref(exp->exp_nid_stats);
330                 }
331                 exp->exp_nid_stats = old_stat;
332                 spin_unlock(&exp->exp_lock);
333                 GOTO(destroy_new, rc = -EALREADY);
334         }
335         /* not found - create */
336         new_stat->nid_proc = lprocfs_register(nidstr,
337                                               obd->obd_proc_exports_entry,
338                                               NULL, NULL);
339
340         if (IS_ERR(new_stat->nid_proc)) {
341                 rc = PTR_ERR(new_stat->nid_proc);
342                 new_stat->nid_proc = NULL;
343                 CERROR("%s: cannot create proc entry for export %s: rc = %d\n",
344                        obd->obd_name, nidstr, rc);
345                 GOTO(destroy_new_ns, rc);
346         }
347
348         entry = lprocfs_add_simple(new_stat->nid_proc, "nodemap", new_stat,
349                                    &lprocfs_exp_nodemap_fops);
350         if (IS_ERR(entry)) {
351                 rc = PTR_ERR(entry);
352                 CWARN("Error adding the nodemap file: rc = %d\n", rc);
353                 GOTO(destroy_new_ns, rc);
354         }
355
356         entry = lprocfs_add_simple(new_stat->nid_proc, "uuid", new_stat,
357                                    &lprocfs_exp_uuid_fops);
358         if (IS_ERR(entry)) {
359                 rc = PTR_ERR(entry);
360                 CWARN("Error adding the NID stats file: rc = %d\n", rc);
361                 GOTO(destroy_new_ns, rc);
362         }
363
364         entry = lprocfs_add_simple(new_stat->nid_proc, "hash", new_stat,
365                                    &lprocfs_exp_hash_fops);
366         if (IS_ERR(entry)) {
367                 rc = PTR_ERR(entry);
368                 CWARN("Error adding the hash file: rc = %d\n", rc);
369                 GOTO(destroy_new_ns, rc);
370         }
371
372         spin_lock(&exp->exp_lock);
373         exp->exp_nid_stats = new_stat;
374         spin_unlock(&exp->exp_lock);
375
376         /* protect competitive add to list, not need locking on destroy */
377         spin_lock(&obd->obd_nid_lock);
378         list_add(&new_stat->nid_list, &obd->obd_nid_stats);
379         spin_unlock(&obd->obd_nid_lock);
380
381         RETURN(0);
382
383 destroy_new_ns:
384         if (new_stat->nid_proc != NULL)
385                 lprocfs_remove(&new_stat->nid_proc);
386         cfs_hash_del(obd->obd_nid_stats_hash, nid, &new_stat->nid_hash);
387
388 destroy_new:
389         nidstat_putref(new_stat);
390         OBD_FREE_PTR(new_stat);
391         RETURN(rc);
392 }
393 EXPORT_SYMBOL(lprocfs_exp_setup);
394
395 int lprocfs_exp_cleanup(struct obd_export *exp)
396 {
397         struct nid_stat *stat = exp->exp_nid_stats;
398
399         if (!stat || !exp->exp_obd)
400                 RETURN(0);
401
402         nidstat_putref(exp->exp_nid_stats);
403         exp->exp_nid_stats = NULL;
404
405         return 0;
406 }
407
408 #define LPROCFS_OBD_OP_INIT(base, stats, op)                    \
409 do {                                                            \
410         unsigned int coffset = base + OBD_COUNTER_OFFSET(op);   \
411         LASSERT(coffset < stats->ls_num);                       \
412         lprocfs_counter_init(stats, coffset, 0, #op, "reqs");   \
413 } while (0)
414
415 void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
416 {
417         LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
418         LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
419         LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info_async);
420         LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
421         LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
422         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
423         LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
424         LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
425         LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
426         LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
427         LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
428         LPROCFS_OBD_OP_INIT(num_private_stats, stats, reconnect);
429         LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
430         LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_init);
431         LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_fini);
432         LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
433         LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
434         LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
435         LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
436         LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
437         LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
438         LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
439         LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
440         LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
441         LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
442         LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
443         LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
444         LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
445         LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
446         LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);
447         LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_uuid);
448         LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);
449         LPROCFS_OBD_OP_INIT(num_private_stats, stats, ping);
450         LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_new);
451         LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_rem);
452         LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_add);
453         LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_del);
454         LPROCFS_OBD_OP_INIT(num_private_stats, stats, getref);
455         LPROCFS_OBD_OP_INIT(num_private_stats, stats, putref);
456
457         CLASSERT(NUM_OBD_STATS == OBD_COUNTER_OFFSET(putref) + 1);
458 }
459 EXPORT_SYMBOL(lprocfs_init_ops_stats);
460
461 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
462 {
463         struct lprocfs_stats *stats;
464         unsigned int num_stats;
465         int rc, i;
466
467         LASSERT(obd->obd_stats == NULL);
468         LASSERT(obd->obd_proc_entry != NULL);
469         LASSERT(obd->obd_cntr_base == 0);
470
471         num_stats = NUM_OBD_STATS + num_private_stats;
472         stats = lprocfs_alloc_stats(num_stats, 0);
473         if (stats == NULL)
474                 return -ENOMEM;
475
476         lprocfs_init_ops_stats(num_private_stats, stats);
477
478         for (i = num_private_stats; i < num_stats; i++) {
479                 /* If this LBUGs, it is likely that an obd
480                  * operation was added to struct obd_ops in
481                  * <obd.h>, and that the corresponding line item
482                  * LPROCFS_OBD_OP_INIT(.., .., opname)
483                  * is missing from the list above. */
484                 LASSERTF(stats->ls_cnt_header[i].lc_name != NULL,
485                          "Missing obd_stat initializer obd_op "
486                          "operation at offset %d.\n", i - num_private_stats);
487         }
488         rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
489         if (rc < 0) {
490                 lprocfs_free_stats(&stats);
491         } else {
492                 obd->obd_stats  = stats;
493                 obd->obd_cntr_base = num_private_stats;
494         }
495         return rc;
496 }
497 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
498
499 void lprocfs_free_obd_stats(struct obd_device *obd)
500 {
501         if (obd->obd_stats)
502                 lprocfs_free_stats(&obd->obd_stats);
503 }
504 EXPORT_SYMBOL(lprocfs_free_obd_stats);
505
506 int lprocfs_hash_seq_show(struct seq_file *m, void *data)
507 {
508         struct obd_device *obd = m->private;
509         int c = 0;
510
511         if (obd == NULL)
512                 return 0;
513
514         c += cfs_hash_debug_header(m);
515         c += cfs_hash_debug_str(obd->obd_uuid_hash, m);
516         c += cfs_hash_debug_str(obd->obd_nid_hash, m);
517         c += cfs_hash_debug_str(obd->obd_nid_stats_hash, m);
518         return c;
519 }
520 EXPORT_SYMBOL(lprocfs_hash_seq_show);
521
522 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
523 {
524         struct obd_device *obd = m->private;
525
526         LASSERT(obd != NULL);
527
528         seq_printf(m, "status: ");
529         if (obd->obd_max_recoverable_clients == 0) {
530                 seq_printf(m, "INACTIVE\n");
531                 goto out;
532         }
533
534         /* sampled unlocked, but really... */
535         if (obd->obd_recovering == 0) {
536                 seq_printf(m, "COMPLETE\n");
537                 seq_printf(m, "recovery_start: %lu\n", obd->obd_recovery_start);
538                 seq_printf(m, "recovery_duration: %lu\n",
539                            obd->obd_recovery_end - obd->obd_recovery_start);
540                 /* Number of clients that have completed recovery */
541                 seq_printf(m, "completed_clients: %d/%d\n",
542                            obd->obd_max_recoverable_clients -
543                            obd->obd_stale_clients,
544                            obd->obd_max_recoverable_clients);
545                 seq_printf(m, "replayed_requests: %d\n",
546                            obd->obd_replayed_requests);
547                 seq_printf(m, "last_transno: "LPD64"\n",
548                            obd->obd_next_recovery_transno - 1);
549                 seq_printf(m, "VBR: %s\n", obd->obd_version_recov ?
550                            "ENABLED" : "DISABLED");
551                 seq_printf(m, "IR: %s\n", obd->obd_no_ir ?
552                            "DISABLED" : "ENABLED");
553                 goto out;
554         }
555
556         seq_printf(m, "RECOVERING\n");
557         seq_printf(m, "recovery_start: %lu\n", obd->obd_recovery_start);
558         seq_printf(m, "time_remaining: %lu\n",
559                    cfs_time_current_sec() >=
560                    obd->obd_recovery_start +
561                    obd->obd_recovery_timeout ? 0 :
562                    obd->obd_recovery_start +
563                    obd->obd_recovery_timeout -
564                    cfs_time_current_sec());
565         seq_printf(m, "connected_clients: %d/%d\n",
566                    atomic_read(&obd->obd_connected_clients),
567                    obd->obd_max_recoverable_clients);
568         /* Number of clients that have completed recovery */
569         seq_printf(m, "req_replay_clients: %d\n",
570                    atomic_read(&obd->obd_req_replay_clients));
571         seq_printf(m, "lock_repay_clients: %d\n",
572                    atomic_read(&obd->obd_lock_replay_clients));
573         seq_printf(m, "completed_clients: %d\n",
574                    atomic_read(&obd->obd_connected_clients) -
575                    atomic_read(&obd->obd_lock_replay_clients));
576         seq_printf(m, "evicted_clients: %d\n", obd->obd_stale_clients);
577         seq_printf(m, "replayed_requests: %d\n", obd->obd_replayed_requests);
578         seq_printf(m, "queued_requests: %d\n",
579                    obd->obd_requests_queued_for_recovery);
580         seq_printf(m, "next_transno: "LPD64"\n",
581                    obd->obd_next_recovery_transno);
582 out:
583         return 0;
584 }
585 EXPORT_SYMBOL(lprocfs_recovery_status_seq_show);
586
587 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data)
588 {
589         struct obd_device *obd = m->private;
590
591         LASSERT(obd != NULL);
592         return seq_printf(m, "%d\n", obd->obd_recovery_ir_factor);
593 }
594 EXPORT_SYMBOL(lprocfs_ir_factor_seq_show);
595
596 ssize_t
597 lprocfs_ir_factor_seq_write(struct file *file, const char *buffer,
598                             size_t count, loff_t *off)
599 {
600         struct seq_file *m = file->private_data;
601         struct obd_device *obd = m->private;
602         int val, rc;
603
604         LASSERT(obd != NULL);
605         rc = lprocfs_write_helper(buffer, count, &val);
606         if (rc)
607                 return rc;
608
609         if (val < OBD_IR_FACTOR_MIN || val > OBD_IR_FACTOR_MAX)
610                 return -EINVAL;
611
612         obd->obd_recovery_ir_factor = val;
613         return count;
614 }
615 EXPORT_SYMBOL(lprocfs_ir_factor_seq_write);
616
617 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data)
618 {
619         struct obd_device *obd = m->private;
620
621         LASSERT(obd != NULL);
622         return seq_printf(m, "%d\n", obd->obd_recovery_timeout);
623 }
624 EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_show);
625
626 ssize_t
627 lprocfs_recovery_time_soft_seq_write(struct file *file, const char *buffer,
628                                         size_t count, loff_t *off)
629 {
630         struct seq_file *m = file->private_data;
631         struct obd_device *obd = m->private;
632         int val, rc;
633
634         LASSERT(obd != NULL);
635         rc = lprocfs_write_helper(buffer, count, &val);
636         if (rc)
637                 return rc;
638
639         obd->obd_recovery_timeout = val;
640         return count;
641 }
642 EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_write);
643
644 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data)
645 {
646         struct obd_device *obd = m->private;
647
648         LASSERT(obd != NULL);
649         return seq_printf(m, "%u\n", obd->obd_recovery_time_hard);
650 }
651 EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_show);
652
653 ssize_t
654 lprocfs_recovery_time_hard_seq_write(struct file *file, const char *buffer,
655                                      size_t count, loff_t *off)
656 {
657         struct seq_file *m = file->private_data;
658         struct obd_device *obd = m->private;
659         int val, rc;
660
661         LASSERT(obd != NULL);
662         rc = lprocfs_write_helper(buffer, count, &val);
663         if (rc)
664                 return rc;
665
666         obd->obd_recovery_time_hard = val;
667         return count;
668 }
669 EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_write);
670
671 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data)
672 {
673         struct obd_device *obd = m->private;
674         struct obd_device_target *target = &obd->u.obt;
675
676         LASSERT(obd != NULL);
677         LASSERT(target->obt_magic == OBT_MAGIC);
678         return seq_printf(m, "%u\n", obd->u.obt.obt_instance);
679 }
680 EXPORT_SYMBOL(lprocfs_target_instance_seq_show);
681
682 #endif /* CONFIG_PROC_FS*/