Whamcloud - gitweb
LU-12254 lnet: correct discovery LNetEQFree()
[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, 2017, 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 #include <linux/kobject.h>
38 #include <linux/sysfs.h>
39
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <lustre_nodemap.h>
43
44 #define MAX_STRING_SIZE 128
45
46 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
47                                     const char *format, ...)
48 {
49         struct dentry *entry = NULL;
50         struct dentry *parent;
51         struct qstr dname;
52         va_list ap;
53         char *dest;
54
55         if (!target || !format)
56                 return NULL;
57
58         dname.name = target;
59         dname.len = strlen(dname.name);
60         dname.hash = ll_full_name_hash(debugfs_lustre_root,
61                                        dname.name, dname.len);
62         parent = d_lookup(debugfs_lustre_root, &dname);
63         if (!parent)
64                 return NULL;
65
66         OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
67         if (!dest)
68                 goto no_entry;
69
70         va_start(ap, format);
71         vsnprintf(dest, MAX_STRING_SIZE, format, ap);
72         va_end(ap);
73
74         entry = debugfs_create_symlink(name, parent, dest);
75         if (IS_ERR_OR_NULL(entry)) {
76                 CERROR("LdebugFS: Could not create symbolic link from %s to %s\n",
77                        name, dest);
78                 entry = NULL;
79         }
80
81         OBD_FREE(dest, MAX_STRING_SIZE + 1);
82 no_entry:
83         dput(parent);
84         return entry;
85 }
86 EXPORT_SYMBOL(ldebugfs_add_symlink);
87
88 #ifdef CONFIG_PROC_FS
89
90 int lprocfs_evict_client_open(struct inode *inode, struct file *f)
91 {
92         struct obd_device *obd = PDE_DATA(file_inode(f));
93
94         atomic_inc(&obd->obd_evict_inprogress);
95         return 0;
96 }
97
98 int lprocfs_evict_client_release(struct inode *inode, struct file *f)
99 {
100         struct obd_device *obd = PDE_DATA(file_inode(f));
101
102         atomic_dec(&obd->obd_evict_inprogress);
103         wake_up(&obd->obd_evict_inprogress_waitq);
104
105         return 0;
106 }
107
108 #define BUFLEN (UUID_MAX + 5)
109
110 ssize_t
111 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
112                                size_t count, loff_t *off)
113 {
114         struct seq_file *m = file->private_data;
115         struct obd_device *obd = m->private;
116         char *tmpbuf, *kbuf;
117
118         OBD_ALLOC(kbuf, BUFLEN);
119         if (kbuf == NULL)
120                 return -ENOMEM;
121
122         /*
123          * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
124          * bytes into kbuf, to ensure that the string is NUL-terminated.
125          * UUID_MAX should include a trailing NUL already.
126          */
127         if (copy_from_user(kbuf, buffer,
128                            min_t(unsigned long, BUFLEN - 1, count))) {
129                 count = -EFAULT;
130                 goto out;
131         }
132         tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
133         class_incref(obd, __func__, current);
134
135         if (strncmp(tmpbuf, "nid:", 4) == 0)
136                 obd_export_evict_by_nid(obd, tmpbuf + 4);
137         else if (strncmp(tmpbuf, "uuid:", 5) == 0)
138                 obd_export_evict_by_uuid(obd, tmpbuf + 5);
139         else
140                 obd_export_evict_by_uuid(obd, tmpbuf);
141
142         class_decref(obd, __func__, current);
143
144 out:
145         OBD_FREE(kbuf, BUFLEN);
146         return count;
147 }
148 EXPORT_SYMBOL(lprocfs_evict_client_seq_write);
149
150 #undef BUFLEN
151
152 int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
153 {
154         struct obd_device *obd = data;
155
156         LASSERT(obd != NULL);
157         seq_printf(m, "%u\n", obd->obd_num_exports);
158         return 0;
159 }
160 EXPORT_SYMBOL(lprocfs_num_exports_seq_show);
161
162 static int obd_export_flags2str(struct obd_export *exp, struct seq_file *m)
163 {
164         bool first = true;
165
166         flag2str(exp, failed);
167         flag2str(exp, in_recovery);
168         flag2str(exp, disconnected);
169         flag2str(exp, connecting);
170
171         return 0;
172 }
173
174 static int
175 lprocfs_exp_print_export_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
176                              struct hlist_node *hnode, void *cb_data)
177 {
178         struct seq_file         *m = cb_data;
179         struct obd_export       *exp = cfs_hash_object(hs, hnode);
180         struct obd_device       *obd;
181         struct obd_connect_data *ocd;
182
183         LASSERT(exp != NULL);
184         if (exp->exp_nid_stats == NULL)
185                 goto out;
186         obd = exp->exp_obd;
187         ocd = &exp->exp_connect_data;
188
189         seq_printf(m, "%s:\n"
190                    "    name: %s\n"
191                    "    client: %s\n"
192                    "    connect_flags: [ ",
193                    obd_uuid2str(&exp->exp_client_uuid),
194                    obd->obd_name,
195                    obd_export_nid2str(exp));
196         obd_connect_seq_flags2str(m, ocd->ocd_connect_flags,
197                                   ocd->ocd_connect_flags2, ", ");
198         seq_printf(m, " ]\n");
199         obd_connect_data_seqprint(m, ocd);
200         seq_printf(m, "    export_flags: [ ");
201         obd_export_flags2str(exp, m);
202         seq_printf(m, " ]\n");
203
204 out:
205         return 0;
206 }
207
208 /**
209  * RPC connections are composed of an import and an export. Using the
210  * lctl utility we can extract important information about the state.
211  * The lprocfs_exp_export_seq_show routine displays the state information
212  * for the export.
213  *
214  * \param[in] m         seq file
215  * \param[in] data      unused
216  *
217  * \retval              0 on success
218  *
219  * The format of the export state information is like:
220  * a793e354-49c0-aa11-8c4f-a4f2b1a1a92b:
221  *     name: MGS
222  *     client: 10.211.55.10@tcp
223  *     connect_flags: [ version, barrier, adaptive_timeouts, ... ]
224  *     connect_data:
225  *        flags: 0x2000011005002020
226  *        instance: 0
227  *        target_version: 2.10.51.0
228  *        export_flags: [ ... ]
229  *
230  */
231 static int lprocfs_exp_export_seq_show(struct seq_file *m, void *data)
232 {
233         struct nid_stat *stats = m->private;
234         struct obd_device *obd = stats->nid_obd;
235
236         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
237                               lprocfs_exp_print_export_seq, m);
238         return 0;
239 }
240 LPROC_SEQ_FOPS_RO(lprocfs_exp_export);
241
242 static void lprocfs_free_client_stats(struct nid_stat *client_stat)
243 {
244         CDEBUG(D_CONFIG, "stat %p - data %p/%p\n", client_stat,
245                client_stat->nid_proc, client_stat->nid_stats);
246
247         LASSERTF(atomic_read(&client_stat->nid_exp_ref_count) == 0,
248                  "nid %s:count %d\n", libcfs_nid2str(client_stat->nid),
249                  atomic_read(&client_stat->nid_exp_ref_count));
250
251         if (client_stat->nid_proc)
252                 lprocfs_remove(&client_stat->nid_proc);
253
254         if (client_stat->nid_stats)
255                 lprocfs_free_stats(&client_stat->nid_stats);
256
257         if (client_stat->nid_ldlm_stats)
258                 lprocfs_free_stats(&client_stat->nid_ldlm_stats);
259
260         OBD_FREE_PTR(client_stat);
261         return;
262 }
263
264 void lprocfs_free_per_client_stats(struct obd_device *obd)
265 {
266         struct cfs_hash *hash = obd->obd_nid_stats_hash;
267         struct nid_stat *stat;
268         ENTRY;
269
270         /* we need extra list - because hash_exit called to early */
271         /* not need locking because all clients is died */
272         while (!list_empty(&obd->obd_nid_stats)) {
273                 stat = list_entry(obd->obd_nid_stats.next,
274                                   struct nid_stat, nid_list);
275                 list_del_init(&stat->nid_list);
276                 cfs_hash_del(hash, &stat->nid, &stat->nid_hash);
277                 lprocfs_free_client_stats(stat);
278         }
279         EXIT;
280 }
281 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
282
283 static int
284 lprocfs_exp_print_uuid_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
285                            struct hlist_node *hnode, void *cb_data)
286 {
287         struct seq_file *m = cb_data;
288         struct obd_export *exp = cfs_hash_object(hs, hnode);
289
290         if (exp->exp_nid_stats != NULL)
291                 seq_printf(m, "%s\n", obd_uuid2str(&exp->exp_client_uuid));
292         return 0;
293 }
294
295 static int
296 lprocfs_exp_print_nodemap_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
297                               struct hlist_node *hnode, void *cb_data)
298 {
299         struct seq_file *m = cb_data;
300         struct obd_export *exp = cfs_hash_object(hs, hnode);
301         struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap;
302
303         if (nodemap != NULL)
304                 seq_printf(m, "%s\n", nodemap->nm_name);
305         return 0;
306 }
307
308 static int
309 lprocfs_exp_nodemap_seq_show(struct seq_file *m, void *data)
310 {
311         struct nid_stat *stats = m->private;
312         struct obd_device *obd = stats->nid_obd;
313
314         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
315                               lprocfs_exp_print_nodemap_seq, m);
316         return 0;
317 }
318 LPROC_SEQ_FOPS_RO(lprocfs_exp_nodemap);
319
320 static int lprocfs_exp_uuid_seq_show(struct seq_file *m, void *data)
321 {
322         struct nid_stat *stats = m->private;
323         struct obd_device *obd = stats->nid_obd;
324
325         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
326                                 lprocfs_exp_print_uuid_seq, m);
327         return 0;
328 }
329 LPROC_SEQ_FOPS_RO(lprocfs_exp_uuid);
330
331 static int
332 lprocfs_exp_print_hash_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
333                            struct hlist_node *hnode, void *cb_data)
334
335 {
336         struct seq_file *m = cb_data;
337         struct obd_export *exp = cfs_hash_object(hs, hnode);
338
339         if (exp->exp_lock_hash != NULL) {
340                 cfs_hash_debug_header(m);
341                 cfs_hash_debug_str(hs, m);
342         }
343         return 0;
344 }
345
346 static int lprocfs_exp_hash_seq_show(struct seq_file *m, void *data)
347 {
348         struct nid_stat *stats = m->private;
349         struct obd_device *obd = stats->nid_obd;
350
351         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
352                                 lprocfs_exp_print_hash_seq, m);
353         return 0;
354 }
355 LPROC_SEQ_FOPS_RO(lprocfs_exp_hash);
356
357 int lprocfs_exp_print_replydata_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
358                                     struct hlist_node *hnode, void *cb_data)
359
360 {
361         struct obd_export *exp = cfs_hash_object(hs, hnode);
362         struct seq_file *m = cb_data;
363         struct tg_export_data *ted = &exp->exp_target_data;
364
365         seq_printf(m, "reply_cnt: %d\n"
366                    "reply_max: %d\n"
367                    "reply_released_by_xid: %d\n"
368                    "reply_released_by_tag: %d\n\n",
369                    ted->ted_reply_cnt,
370                    ted->ted_reply_max,
371                    ted->ted_release_xid,
372                    ted->ted_release_tag);
373         return 0;
374 }
375
376 int lprocfs_exp_replydata_seq_show(struct seq_file *m, void *data)
377 {
378         struct nid_stat *stats = m->private;
379         struct obd_device *obd = stats->nid_obd;
380
381         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
382                                 lprocfs_exp_print_replydata_seq, m);
383         return 0;
384 }
385 LPROC_SEQ_FOPS_RO(lprocfs_exp_replydata);
386
387 int lprocfs_exp_print_fmd_count_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
388                                     struct hlist_node *hnode, void *cb_data)
389
390 {
391         struct obd_export *exp = cfs_hash_object(hs, hnode);
392         struct seq_file *m = cb_data;
393         struct tg_export_data *ted = &exp->exp_target_data;
394
395         seq_printf(m, "%d\n", ted->ted_fmd_count);
396
397         return 0;
398 }
399
400 int lprocfs_exp_fmd_count_seq_show(struct seq_file *m, void *data)
401 {
402         struct nid_stat *stats = m->private;
403         struct obd_device *obd = stats->nid_obd;
404
405         cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
406                               lprocfs_exp_print_fmd_count_seq, m);
407         return 0;
408 }
409 LPROC_SEQ_FOPS_RO(lprocfs_exp_fmd_count);
410
411 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
412 {
413         seq_puts(m, "Write into this file to clear all nid stats and stale nid entries\n");
414         return 0;
415 }
416 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_show);
417
418 static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
419 {
420         struct nid_stat *stat = obj;
421         ENTRY;
422
423         CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
424         if (atomic_read(&stat->nid_exp_ref_count) == 1) {
425                 /* object has only hash references. */
426                 spin_lock(&stat->nid_obd->obd_nid_lock);
427                 list_move(&stat->nid_list, data);
428                 spin_unlock(&stat->nid_obd->obd_nid_lock);
429                 RETURN(1);
430         }
431         /* we has reference to object - only clear data*/
432         if (stat->nid_stats)
433                 lprocfs_clear_stats(stat->nid_stats);
434
435         RETURN(0);
436 }
437
438 ssize_t
439 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
440                                         size_t count, loff_t *off)
441 {
442         struct seq_file *m = file->private_data;
443         struct obd_device *obd = m->private;
444         struct nid_stat *client_stat;
445         struct list_head free_list;
446
447         INIT_LIST_HEAD(&free_list);
448         cfs_hash_cond_del(obd->obd_nid_stats_hash,
449                           lprocfs_nid_stats_clear_write_cb, &free_list);
450
451         while (!list_empty(&free_list)) {
452                 client_stat = list_entry(free_list.next, struct nid_stat,
453                                          nid_list);
454                 list_del_init(&client_stat->nid_list);
455                 lprocfs_free_client_stats(client_stat);
456         }
457         return count;
458 }
459 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_write);
460
461 int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid)
462 {
463         struct nid_stat *new_stat, *old_stat;
464         struct obd_device *obd = NULL;
465         struct proc_dir_entry *entry;
466         char nidstr[LNET_NIDSTR_SIZE];
467         int rc = 0;
468         ENTRY;
469
470         if (!exp || !exp->exp_obd || !exp->exp_obd->obd_proc_exports_entry ||
471             !exp->exp_obd->obd_nid_stats_hash)
472                 RETURN(-EINVAL);
473
474         /* not test against zero because eric say:
475          * You may only test nid against another nid, or LNET_NID_ANY.
476          * Anything else is nonsense.*/
477         if (nid == NULL || *nid == LNET_NID_ANY)
478                 RETURN(-EALREADY);
479
480         libcfs_nid2str_r(*nid, nidstr, sizeof(nidstr));
481
482         spin_lock(&exp->exp_lock);
483         if (exp->exp_nid_stats != NULL) {
484                 spin_unlock(&exp->exp_lock);
485                 RETURN(-EALREADY);
486         }
487         spin_unlock(&exp->exp_lock);
488
489         obd = exp->exp_obd;
490
491         CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
492
493         OBD_ALLOC_PTR(new_stat);
494         if (new_stat == NULL)
495                 RETURN(-ENOMEM);
496
497         new_stat->nid     = *nid;
498         new_stat->nid_obd = exp->exp_obd;
499         /* we need set default refcount to 1 to balance obd_disconnect */
500         atomic_set(&new_stat->nid_exp_ref_count, 1);
501
502         old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
503                                            nid, &new_stat->nid_hash);
504         CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
505                old_stat, nidstr, atomic_read(&old_stat->nid_exp_ref_count));
506
507         /* Return -EALREADY here so that we know that the /proc
508          * entry already has been created */
509         if (old_stat != new_stat) {
510                 spin_lock(&exp->exp_lock);
511                 if (exp->exp_nid_stats) {
512                         LASSERT(exp->exp_nid_stats == old_stat);
513                         nidstat_putref(exp->exp_nid_stats);
514                 }
515                 exp->exp_nid_stats = old_stat;
516                 spin_unlock(&exp->exp_lock);
517                 GOTO(destroy_new, rc = -EALREADY);
518         }
519         /* not found - create */
520         new_stat->nid_proc = lprocfs_register(nidstr,
521                                               obd->obd_proc_exports_entry,
522                                               NULL, NULL);
523
524         if (IS_ERR(new_stat->nid_proc)) {
525                 rc = PTR_ERR(new_stat->nid_proc);
526                 new_stat->nid_proc = NULL;
527                 CERROR("%s: cannot create proc entry for export %s: rc = %d\n",
528                        obd->obd_name, nidstr, rc);
529                 GOTO(destroy_new_ns, rc);
530         }
531
532         entry = lprocfs_add_simple(new_stat->nid_proc, "nodemap", new_stat,
533                                    &lprocfs_exp_nodemap_fops);
534         if (IS_ERR(entry)) {
535                 rc = PTR_ERR(entry);
536                 CWARN("%s: error adding the nodemap file: rc = %d\n",
537                       obd->obd_name, rc);
538                 GOTO(destroy_new_ns, rc);
539         }
540
541         entry = lprocfs_add_simple(new_stat->nid_proc, "uuid", new_stat,
542                                    &lprocfs_exp_uuid_fops);
543         if (IS_ERR(entry)) {
544                 rc = PTR_ERR(entry);
545                 CWARN("%s: error adding the NID stats file: rc = %d\n",
546                       obd->obd_name, rc);
547                 GOTO(destroy_new_ns, rc);
548         }
549
550         entry = lprocfs_add_simple(new_stat->nid_proc, "hash", new_stat,
551                                    &lprocfs_exp_hash_fops);
552         if (IS_ERR(entry)) {
553                 rc = PTR_ERR(entry);
554                 CWARN("%s: error adding the hash file: rc = %d\n",
555                       obd->obd_name, rc);
556                 GOTO(destroy_new_ns, rc);
557         }
558
559         entry = lprocfs_add_simple(new_stat->nid_proc, "export",
560                                    new_stat, &lprocfs_exp_export_fops);
561         if (IS_ERR(entry)) {
562                 rc = PTR_ERR(entry);
563                 CWARN("%s: error adding the export file: rc = %d\n",
564                       obd->obd_name, rc);
565                 GOTO(destroy_new_ns, rc);
566         }
567
568         entry = lprocfs_add_simple(new_stat->nid_proc, "reply_data", new_stat,
569                                    &lprocfs_exp_replydata_fops);
570         if (IS_ERR(entry)) {
571                 rc = PTR_ERR(entry);
572                 CWARN("%s: error adding the reply_data file: rc = %d\n",
573                       obd->obd_name, rc);
574                 GOTO(destroy_new_ns, rc);
575         }
576
577         entry = lprocfs_add_simple(new_stat->nid_proc, "fmd_count", new_stat,
578                                    &lprocfs_exp_fmd_count_fops);
579         if (IS_ERR(entry)) {
580                 rc = PTR_ERR(entry);
581                 CWARN("%s: error adding the fmd_count file: rc = %d\n",
582                       obd->obd_name, rc);
583                 GOTO(destroy_new_ns, rc);
584         }
585
586         spin_lock(&exp->exp_lock);
587         exp->exp_nid_stats = new_stat;
588         spin_unlock(&exp->exp_lock);
589
590         /* protect competitive add to list, not need locking on destroy */
591         spin_lock(&obd->obd_nid_lock);
592         list_add(&new_stat->nid_list, &obd->obd_nid_stats);
593         spin_unlock(&obd->obd_nid_lock);
594
595         RETURN(0);
596
597 destroy_new_ns:
598         if (new_stat->nid_proc != NULL)
599                 lprocfs_remove(&new_stat->nid_proc);
600         cfs_hash_del(obd->obd_nid_stats_hash, nid, &new_stat->nid_hash);
601
602 destroy_new:
603         nidstat_putref(new_stat);
604         OBD_FREE_PTR(new_stat);
605         RETURN(rc);
606 }
607 EXPORT_SYMBOL(lprocfs_exp_setup);
608
609 int lprocfs_exp_cleanup(struct obd_export *exp)
610 {
611         struct nid_stat *stat = exp->exp_nid_stats;
612
613         if (!stat || !exp->exp_obd)
614                 RETURN(0);
615
616         nidstat_putref(exp->exp_nid_stats);
617         exp->exp_nid_stats = NULL;
618
619         return 0;
620 }
621
622 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned int num_stats)
623 {
624         struct lprocfs_stats *stats;
625         int rc;
626
627         LASSERT(obd->obd_stats == NULL);
628         LASSERT(obd->obd_proc_entry != NULL);
629
630         stats = lprocfs_alloc_stats(num_stats, 0);
631         if (stats == NULL)
632                 return -ENOMEM;
633
634         rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
635         if (rc < 0)
636                 lprocfs_free_stats(&stats);
637         else
638                 obd->obd_stats = stats;
639
640         return rc;
641 }
642 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
643
644 void lprocfs_free_obd_stats(struct obd_device *obd)
645 {
646         if (obd->obd_stats)
647                 lprocfs_free_stats(&obd->obd_stats);
648 }
649 EXPORT_SYMBOL(lprocfs_free_obd_stats);
650
651 int lprocfs_hash_seq_show(struct seq_file *m, void *data)
652 {
653         struct obd_device *obd = m->private;
654
655         if (obd == NULL)
656                 return 0;
657
658         cfs_hash_debug_header(m);
659         cfs_hash_debug_str(obd->obd_uuid_hash, m);
660         cfs_hash_debug_str(obd->obd_nid_hash, m);
661         cfs_hash_debug_str(obd->obd_nid_stats_hash, m);
662         return 0;
663 }
664 EXPORT_SYMBOL(lprocfs_hash_seq_show);
665
666 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
667 {
668         struct obd_device *obd = m->private;
669         struct target_distribute_txn_data *tdtd;
670
671         LASSERT(obd != NULL);
672
673         seq_printf(m, "status: ");
674         if (obd->obd_max_recoverable_clients == 0) {
675                 seq_printf(m, "INACTIVE\n");
676                 goto out;
677         }
678
679         /* sampled unlocked, but really... */
680         if (obd->obd_recovering == 0) {
681                 seq_printf(m, "COMPLETE\n");
682                 seq_printf(m, "recovery_start: %lld\n",
683                            (s64)obd->obd_recovery_start);
684                 seq_printf(m, "recovery_duration: %lld\n",
685                            obd->obd_recovery_end ?
686                            obd->obd_recovery_end - obd->obd_recovery_start :
687                            ktime_get_real_seconds() - obd->obd_recovery_start);
688                 /* Number of clients that have completed recovery */
689                 seq_printf(m, "completed_clients: %d/%d\n",
690                            obd->obd_max_recoverable_clients -
691                            obd->obd_stale_clients,
692                            obd->obd_max_recoverable_clients);
693                 seq_printf(m, "replayed_requests: %d\n",
694                            obd->obd_replayed_requests);
695                 seq_printf(m, "last_transno: %lld\n",
696                            obd->obd_next_recovery_transno - 1);
697                 seq_printf(m, "VBR: %s\n", obd->obd_version_recov ?
698                            "ENABLED" : "DISABLED");
699                 seq_printf(m, "IR: %s\n", obd->obd_no_ir ?
700                            "DISABLED" : "ENABLED");
701                 goto out;
702         }
703
704         tdtd = obd->u.obt.obt_lut->lut_tdtd;
705         if (tdtd && tdtd->tdtd_show_update_logs_retrievers) {
706                 char *buf;
707                 int size = 0;
708                 int count = 0;
709
710                 buf = tdtd->tdtd_show_update_logs_retrievers(
711                         tdtd->tdtd_show_retrievers_cbdata,
712                         &size, &count);
713                 if (count > 0) {
714                         seq_printf(m, "WAITING\n");
715                         seq_printf(m, "non-ready MDTs: %s\n",
716                                    buf ? buf : "unknown (not enough RAM)");
717                         seq_printf(m, "recovery_start: %lld\n",
718                                    (s64)obd->obd_recovery_start);
719                         seq_printf(m, "time_waited: %lld\n",
720                                    (s64)(ktime_get_real_seconds() -
721                                          obd->obd_recovery_start));
722                 }
723
724                 if (buf != NULL)
725                         OBD_FREE(buf, size);
726
727                 if (likely(count > 0))
728                         goto out;
729         }
730
731         /* recovery won't start until the clients connect */
732         if (obd->obd_recovery_start == 0) {
733                 seq_printf(m, "WAITING_FOR_CLIENTS\n");
734                 goto out;
735         }
736
737         seq_printf(m, "RECOVERING\n");
738         seq_printf(m, "recovery_start: %lld\n", (s64)obd->obd_recovery_start);
739         seq_printf(m, "time_remaining: %lld\n",
740                    ktime_get_real_seconds() >=
741                    obd->obd_recovery_start +
742                    obd->obd_recovery_timeout ? 0 :
743                    (s64)(obd->obd_recovery_start +
744                          obd->obd_recovery_timeout -
745                          ktime_get_real_seconds()));
746         seq_printf(m, "connected_clients: %d/%d\n",
747                    atomic_read(&obd->obd_connected_clients),
748                    obd->obd_max_recoverable_clients);
749         /* Number of clients that have completed recovery */
750         seq_printf(m, "req_replay_clients: %d\n",
751                    atomic_read(&obd->obd_req_replay_clients));
752         seq_printf(m, "lock_repay_clients: %d\n",
753                    atomic_read(&obd->obd_lock_replay_clients));
754         seq_printf(m, "completed_clients: %d\n",
755                    atomic_read(&obd->obd_connected_clients) -
756                    atomic_read(&obd->obd_lock_replay_clients));
757         seq_printf(m, "evicted_clients: %d\n", obd->obd_stale_clients);
758         seq_printf(m, "replayed_requests: %d\n", obd->obd_replayed_requests);
759         seq_printf(m, "queued_requests: %d\n",
760                    obd->obd_requests_queued_for_recovery);
761         seq_printf(m, "next_transno: %lld\n",
762                    obd->obd_next_recovery_transno);
763 out:
764         return 0;
765 }
766 EXPORT_SYMBOL(lprocfs_recovery_status_seq_show);
767
768 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data)
769 {
770         struct obd_device *obd = m->private;
771
772         LASSERT(obd != NULL);
773         seq_printf(m, "%d\n", obd->obd_recovery_ir_factor);
774         return 0;
775 }
776 EXPORT_SYMBOL(lprocfs_ir_factor_seq_show);
777
778 ssize_t
779 lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
780                             size_t count, loff_t *off)
781 {
782         struct seq_file *m = file->private_data;
783         struct obd_device *obd = m->private;
784         int val;
785         int rc;
786
787         LASSERT(obd != NULL);
788         rc = kstrtoint_from_user(buffer, count, 10, &val);
789         if (rc)
790                 return rc;
791
792         if (val < OBD_IR_FACTOR_MIN || val > OBD_IR_FACTOR_MAX)
793                 return -EINVAL;
794
795         obd->obd_recovery_ir_factor = val;
796         return count;
797 }
798 EXPORT_SYMBOL(lprocfs_ir_factor_seq_write);
799
800 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data)
801 {
802         struct obd_device *obd = m->private;
803
804         LASSERT(obd != NULL);
805         seq_printf(m, "%d\n", obd->obd_checksum_dump);
806         return 0;
807 }
808 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_show);
809
810 ssize_t
811 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
812                             size_t count, loff_t *off)
813 {
814         struct seq_file *m = file->private_data;
815         struct obd_device *obd = m->private;
816         bool val;
817         int rc;
818
819         LASSERT(obd != NULL);
820         rc = kstrtobool_from_user(buffer, count, &val);
821         if (rc)
822                 return rc;
823
824         obd->obd_checksum_dump = val;
825         return count;
826 }
827 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_write);
828
829 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data)
830 {
831         struct obd_device *obd = m->private;
832
833         LASSERT(obd != NULL);
834         seq_printf(m, "%llu\n", obd->obd_recovery_timeout);
835         return 0;
836 }
837 EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_show);
838
839 ssize_t
840 lprocfs_recovery_time_soft_seq_write(struct file *file,
841                                      const char __user *buffer,
842                                      size_t count, loff_t *off)
843 {
844         struct seq_file *m = file->private_data;
845         struct obd_device *obd = m->private;
846         unsigned int val;
847         int rc;
848
849         LASSERT(obd != NULL);
850         rc = kstrtouint_from_user(buffer, count, 0, &val);
851         if (rc)
852                 return rc;
853
854         obd->obd_recovery_timeout = val;
855         return count;
856 }
857 EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_write);
858
859 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data)
860 {
861         struct obd_device *obd = m->private;
862
863         LASSERT(obd != NULL);
864         seq_printf(m, "%lld\n", obd->obd_recovery_time_hard);
865         return 0;
866 }
867 EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_show);
868
869 ssize_t
870 lprocfs_recovery_time_hard_seq_write(struct file *file,
871                                      const char __user *buffer,
872                                      size_t count, loff_t *off)
873 {
874         struct seq_file *m = file->private_data;
875         struct obd_device *obd = m->private;
876         unsigned int val;
877         int rc;
878
879         LASSERT(obd != NULL);
880         rc = kstrtouint_from_user(buffer, count, 0, &val);
881         if (rc)
882                 return rc;
883
884         obd->obd_recovery_time_hard = val;
885         return count;
886 }
887 EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_write);
888
889 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data)
890 {
891         struct obd_device *obd = m->private;
892         struct obd_device_target *target = &obd->u.obt;
893
894         LASSERT(obd != NULL);
895         LASSERT(target->obt_magic == OBT_MAGIC);
896         seq_printf(m, "%u\n", obd->u.obt.obt_instance);
897         return 0;
898 }
899 EXPORT_SYMBOL(lprocfs_target_instance_seq_show);
900
901 #endif /* CONFIG_PROC_FS*/