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