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