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