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