Whamcloud - gitweb
LU-7988 hsm: run HSM coordinator once per second at most
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.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) 2011, 2016, 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.c
33  *
34  * Author: Hariharan Thantry <thantry@users.sourceforge.net>
35  */
36
37 #define DEBUG_SUBSYSTEM S_CLASS
38
39 #include <obd_class.h>
40 #include <lprocfs_status.h>
41 #include <lustre/lustre_idl.h>
42
43 #ifdef CONFIG_PROC_FS
44
45 static int lprocfs_no_percpu_stats = 0;
46 module_param(lprocfs_no_percpu_stats, int, 0644);
47 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
48
49 #define MAX_STRING_SIZE 128
50
51 int lprocfs_single_release(struct inode *inode, struct file *file)
52 {
53         return single_release(inode, file);
54 }
55 EXPORT_SYMBOL(lprocfs_single_release);
56
57 int lprocfs_seq_release(struct inode *inode, struct file *file)
58 {
59         return seq_release(inode, file);
60 }
61 EXPORT_SYMBOL(lprocfs_seq_release);
62
63 struct proc_dir_entry *
64 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
65                    void *data, const struct file_operations *fops)
66 {
67         struct proc_dir_entry *proc;
68         mode_t mode = 0;
69
70         if (root == NULL || name == NULL || fops == NULL)
71                 return ERR_PTR(-EINVAL);
72
73         if (fops->read)
74                 mode = 0444;
75         if (fops->write)
76                 mode |= 0200;
77         proc = proc_create_data(name, mode, root, fops, data);
78         if (!proc) {
79                 CERROR("LprocFS: No memory to create /proc entry %s\n",
80                        name);
81                 return ERR_PTR(-ENOMEM);
82         }
83         return proc;
84 }
85 EXPORT_SYMBOL(lprocfs_add_simple);
86
87 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
88                         struct proc_dir_entry *parent, const char *format, ...)
89 {
90         struct proc_dir_entry *entry;
91         char *dest;
92         va_list ap;
93
94         if (parent == NULL || format == NULL)
95                 return NULL;
96
97         OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
98         if (dest == NULL)
99                 return NULL;
100
101         va_start(ap, format);
102         vsnprintf(dest, MAX_STRING_SIZE, format, ap);
103         va_end(ap);
104
105         entry = proc_symlink(name, parent, dest);
106         if (entry == NULL)
107                 CERROR("LprocFS: Could not create symbolic link from "
108                        "%s to %s\n", name, dest);
109
110         OBD_FREE(dest, MAX_STRING_SIZE + 1);
111         return entry;
112 }
113 EXPORT_SYMBOL(lprocfs_add_symlink);
114
115 static const struct file_operations lprocfs_generic_fops = { };
116
117 int ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *list,
118                       void *data)
119 {
120         if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
121                 return -EINVAL;
122
123         while (list->name) {
124                 struct dentry *entry;
125                 umode_t mode = 0;
126
127                 if (list->proc_mode != 0000) {
128                         mode = list->proc_mode;
129                 } else if (list->fops) {
130                         if (list->fops->read)
131                                 mode = 0444;
132                         if (list->fops->write)
133                                 mode |= 0200;
134                 }
135                 entry = debugfs_create_file(list->name, mode, parent,
136                                             list->data ? : data,
137                                             list->fops ? : &lprocfs_generic_fops);
138                 if (IS_ERR_OR_NULL(entry))
139                         return entry ? PTR_ERR(entry) : -ENOMEM;
140                 list++;
141         }
142         return 0;
143 }
144 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
145
146 /**
147  * Add /proc entries.
148  *
149  * \param root [in]  The parent proc entry on which new entry will be added.
150  * \param list [in]  Array of proc entries to be added.
151  * \param data [in]  The argument to be passed when entries read/write routines
152  *                   are called through /proc file.
153  *
154  * \retval 0   on success
155  *         < 0 on error
156  */
157 int
158 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
159                  void *data)
160 {
161         if (root == NULL || list == NULL)
162                 return -EINVAL;
163
164         while (list->name != NULL) {
165                 struct proc_dir_entry *proc;
166                 mode_t mode = 0;
167
168                 if (list->proc_mode != 0000) {
169                         mode = list->proc_mode;
170                 } else if (list->fops) {
171                         if (list->fops->read)
172                                 mode = 0444;
173                         if (list->fops->write)
174                                 mode |= 0200;
175                 }
176                 proc = proc_create_data(list->name, mode, root,
177                                         list->fops ?: &lprocfs_generic_fops,
178                                         list->data ?: data);
179                 if (proc == NULL)
180                         return -ENOMEM;
181                 list++;
182         }
183         return 0;
184 }
185 EXPORT_SYMBOL(lprocfs_add_vars);
186
187 void ldebugfs_remove(struct dentry **entryp)
188 {
189         debugfs_remove(*entryp);
190         *entryp = NULL;
191 }
192 EXPORT_SYMBOL_GPL(ldebugfs_remove);
193
194 #ifndef HAVE_REMOVE_PROC_SUBTREE
195 /* for b=10866, global variable */
196 DECLARE_RWSEM(_lprocfs_lock);
197 EXPORT_SYMBOL(_lprocfs_lock);
198
199 static void lprocfs_remove_nolock(struct proc_dir_entry **proot)
200 {
201         struct proc_dir_entry *root = *proot;
202         struct proc_dir_entry *temp = root;
203         struct proc_dir_entry *rm_entry;
204         struct proc_dir_entry *parent;
205
206         *proot = NULL;
207         if (root == NULL || IS_ERR(root))
208                 return;
209
210         parent = root->parent;
211         LASSERT(parent != NULL);
212
213         while (1) {
214                 while (temp->subdir != NULL)
215                         temp = temp->subdir;
216
217                 rm_entry = temp;
218                 temp = temp->parent;
219
220                 /* Memory corruption once caused this to fail, and
221                    without this LASSERT we would loop here forever. */
222                 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
223                          "0x%p  %s/%s len %d\n", rm_entry, temp->name,
224                          rm_entry->name, (int)strlen(rm_entry->name));
225
226                 remove_proc_entry(rm_entry->name, temp);
227                 if (temp == parent)
228                         break;
229         }
230 }
231
232 int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
233 {
234         struct proc_dir_entry    *t = NULL;
235         struct proc_dir_entry   **p;
236         int                       len, busy = 0;
237
238         LASSERT(parent != NULL);
239         len = strlen(name);
240
241         down_write(&_lprocfs_lock);
242         /* lookup target name */
243         for (p = &parent->subdir; *p; p = &(*p)->next) {
244                 if ((*p)->namelen != len)
245                         continue;
246                 if (memcmp(name, (*p)->name, len))
247                         continue;
248                 t = *p;
249                 break;
250         }
251
252         if (t) {
253                 /* verify it's empty: do not count "num_refs" */
254                 for (p = &t->subdir; *p; p = &(*p)->next) {
255                         if ((*p)->namelen != strlen("num_refs")) {
256                                 busy = 1;
257                                 break;
258                         }
259                         if (memcmp("num_refs", (*p)->name,
260                                    strlen("num_refs"))) {
261                                 busy = 1;
262                                 break;
263                         }
264                 }
265         }
266
267         if (busy == 0)
268                 lprocfs_remove_nolock(&t);
269
270         up_write(&_lprocfs_lock);
271         return 0;
272 }
273 #endif /* !HAVE_REMOVE_PROC_SUBTREE */
274
275 #ifndef HAVE_PROC_REMOVE
276 void proc_remove(struct proc_dir_entry *de)
277 {
278 #ifndef HAVE_REMOVE_PROC_SUBTREE
279         down_write(&_lprocfs_lock); /* search vs remove race */
280         lprocfs_remove_nolock(&de);
281         up_write(&_lprocfs_lock);
282 #else
283         if (de)
284                 remove_proc_subtree(de->name, de->parent);
285 #endif
286 }
287 #endif
288
289 void lprocfs_remove(struct proc_dir_entry **rooth)
290 {
291         proc_remove(*rooth);
292         *rooth = NULL;
293 }
294 EXPORT_SYMBOL(lprocfs_remove);
295
296 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
297 {
298         LASSERT(parent != NULL);
299         remove_proc_entry(name, parent);
300 }
301 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
302
303 struct dentry *ldebugfs_register(const char *name, struct dentry *parent,
304                                  struct lprocfs_vars *list, void *data)
305 {
306         struct dentry *entry;
307
308         entry = debugfs_create_dir(name, parent);
309         if (IS_ERR_OR_NULL(entry)) {
310                 entry = entry ?: ERR_PTR(-ENOMEM);
311                 goto out;
312         }
313
314         if (!IS_ERR_OR_NULL(list)) {
315                 int rc;
316
317                 rc = ldebugfs_add_vars(entry, list, data);
318                 if (rc) {
319                         debugfs_remove(entry);
320                         entry = ERR_PTR(rc);
321                 }
322         }
323 out:
324         return entry;
325 }
326 EXPORT_SYMBOL_GPL(ldebugfs_register);
327
328 struct proc_dir_entry *
329 lprocfs_register(const char *name, struct proc_dir_entry *parent,
330                  struct lprocfs_vars *list, void *data)
331 {
332         struct proc_dir_entry *newchild;
333
334         newchild = proc_mkdir(name, parent);
335         if (newchild == NULL)
336                 return ERR_PTR(-ENOMEM);
337
338         if (list != NULL) {
339                 int rc = lprocfs_add_vars(newchild, list, data);
340                 if (rc) {
341                         lprocfs_remove(&newchild);
342                         return ERR_PTR(rc);
343                 }
344         }
345         return newchild;
346 }
347 EXPORT_SYMBOL(lprocfs_register);
348
349 /* Generic callbacks */
350 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
351 {
352         seq_printf(m, "%u\n", *(unsigned int *)data);
353         return 0;
354 }
355 EXPORT_SYMBOL(lprocfs_uint_seq_show);
356
357 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
358                     unsigned long count, void *data)
359 {
360         unsigned        *p = data;
361         char             dummy[MAX_STRING_SIZE + 1];
362         char            *end;
363         unsigned long    tmp;
364
365         if (count >= sizeof(dummy))
366                 return -EINVAL;
367
368         if (count == 0)
369                 return 0;
370
371         if (copy_from_user(dummy, buffer, count))
372                 return -EFAULT;
373
374         dummy[count] = 0;
375
376         tmp = simple_strtoul(dummy, &end, 0);
377         if (dummy == end)
378                 return -EINVAL;
379
380         *p = (unsigned int)tmp;
381         return count;
382 }
383 EXPORT_SYMBOL(lprocfs_wr_uint);
384
385 ssize_t lprocfs_uint_seq_write(struct file *file, const char __user *buffer,
386                                size_t count, loff_t *off)
387 {
388         int *data = ((struct seq_file *)file->private_data)->private;
389         int rc;
390         __s64 val = 0;
391
392         rc = lprocfs_str_to_s64(buffer, count, &val);
393         if (rc < 0)
394                 return rc;
395
396         return lprocfs_wr_uint(file, buffer, count, data);
397 }
398 EXPORT_SYMBOL(lprocfs_uint_seq_write);
399
400 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
401 {
402         LASSERT(data != NULL);
403         seq_printf(m, "%llu\n", *(__u64 *)data);
404         return 0;
405 }
406 EXPORT_SYMBOL(lprocfs_u64_seq_show);
407
408 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
409 {
410         atomic_t *atom = data;
411         LASSERT(atom != NULL);
412         seq_printf(m, "%d\n", atomic_read(atom));
413         return 0;
414 }
415 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
416
417 ssize_t
418 lprocfs_atomic_seq_write(struct file *file, const char __user *buffer,
419                         size_t count, loff_t *off)
420 {
421         atomic_t *atm = ((struct seq_file *)file->private_data)->private;
422         __s64 val = 0;
423         int rc;
424
425         rc = lprocfs_str_to_s64(buffer, count, &val);
426         if (rc < 0)
427                 return rc;
428
429         if (val <= 0 || val > INT_MAX)
430                 return -ERANGE;
431
432         atomic_set(atm, val);
433         return count;
434 }
435 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
436
437 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
438 {
439         struct obd_device *obd = data;
440
441         LASSERT(obd != NULL);
442         seq_printf(m, "%s\n", obd->obd_uuid.uuid);
443         return 0;
444 }
445 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
446
447 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
448                          char *buf)
449 {
450         struct obd_device *obd = container_of(kobj, struct obd_device,
451                                               obd_kobj);
452
453         return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
454 }
455 LUSTRE_RO_ATTR(uuid);
456
457 int lprocfs_name_seq_show(struct seq_file *m, void *data)
458 {
459         struct obd_device *dev = data;
460
461         LASSERT(dev != NULL);
462         seq_printf(m, "%s\n", dev->obd_name);
463         return 0;
464 }
465 EXPORT_SYMBOL(lprocfs_name_seq_show);
466
467 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
468                               char *buf)
469 {
470         struct obd_device *obd = container_of(kobj, struct obd_device,
471                                               obd_kobj);
472         struct obd_statfs osfs;
473         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
474                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
475                             OBD_STATFS_NODELAY);
476         if (!rc)
477                 return sprintf(buf, "%u\n", osfs.os_bsize);
478
479         return rc;
480 }
481 LUSTRE_RO_ATTR(blocksize);
482
483 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
484                                 char *buf)
485 {
486         struct obd_device *obd = container_of(kobj, struct obd_device,
487                                               obd_kobj);
488         struct obd_statfs osfs;
489         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
490                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
491                             OBD_STATFS_NODELAY);
492         if (!rc) {
493                 u32 blk_size = osfs.os_bsize >> 10;
494                 u64 result = osfs.os_blocks;
495
496                 while (blk_size >>= 1)
497                         result <<= 1;
498
499                 return sprintf(buf, "%llu\n", result);
500         }
501
502         return rc;
503 }
504 LUSTRE_RO_ATTR(kbytestotal);
505
506 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
507                                char *buf)
508 {
509         struct obd_device *obd = container_of(kobj, struct obd_device,
510                                               obd_kobj);
511         struct obd_statfs osfs;
512         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
513                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
514                             OBD_STATFS_NODELAY);
515         if (!rc) {
516                 u32 blk_size = osfs.os_bsize >> 10;
517                 u64 result = osfs.os_bfree;
518
519                 while (blk_size >>= 1)
520                         result <<= 1;
521
522                 return sprintf(buf, "%llu\n", result);
523         }
524
525         return rc;
526 }
527 LUSTRE_RO_ATTR(kbytesfree);
528
529 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
530                                 char *buf)
531 {
532         struct obd_device *obd = container_of(kobj, struct obd_device,
533                                               obd_kobj);
534         struct obd_statfs osfs;
535         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
536                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
537                             OBD_STATFS_NODELAY);
538         if (!rc) {
539                 u32 blk_size = osfs.os_bsize >> 10;
540                 u64 result = osfs.os_bavail;
541
542                 while (blk_size >>= 1)
543                         result <<= 1;
544
545                 return sprintf(buf, "%llu\n", result);
546         }
547
548         return rc;
549 }
550 LUSTRE_RO_ATTR(kbytesavail);
551
552 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
553                                char *buf)
554 {
555         struct obd_device *obd = container_of(kobj, struct obd_device,
556                                               obd_kobj);
557         struct obd_statfs osfs;
558         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
559                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
560                             OBD_STATFS_NODELAY);
561         if (!rc)
562                 return sprintf(buf, "%llu\n", osfs.os_files);
563
564         return rc;
565 }
566 LUSTRE_RO_ATTR(filestotal);
567
568 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
569                               char *buf)
570 {
571         struct obd_device *obd = container_of(kobj, struct obd_device,
572                                               obd_kobj);
573         struct obd_statfs osfs;
574         int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
575                             cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
576                             OBD_STATFS_NODELAY);
577         if (!rc)
578                 return sprintf(buf, "%llu\n", osfs.os_ffree);
579
580         return rc;
581 }
582 LUSTRE_RO_ATTR(filesfree);
583
584 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
585 {
586         struct obd_device *obd = data;
587         struct obd_import *imp;
588         char *imp_state_name = NULL;
589         int rc = 0;
590
591         LASSERT(obd != NULL);
592         LPROCFS_CLIMP_CHECK(obd);
593         imp = obd->u.cli.cl_import;
594         imp_state_name = ptlrpc_import_state_name(imp->imp_state);
595         seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
596                    imp->imp_deactive ? "\tDEACTIVATED" : "");
597
598         LPROCFS_CLIMP_EXIT(obd);
599         return rc;
600 }
601 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
602
603 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
604 {
605         struct obd_device *obd = data;
606         struct ptlrpc_connection *conn;
607         int rc = 0;
608
609         LASSERT(obd != NULL);
610
611         LPROCFS_CLIMP_CHECK(obd);
612         conn = obd->u.cli.cl_import->imp_connection;
613         if (conn && obd->u.cli.cl_import)
614                 seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
615         else
616                 seq_printf(m, "%s\n", "<none>");
617
618         LPROCFS_CLIMP_EXIT(obd);
619         return rc;
620 }
621 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
622
623 /** add up per-cpu counters */
624
625 /**
626  * Lock statistics structure for access, possibly only on this CPU.
627  *
628  * The statistics struct may be allocated with per-CPU structures for
629  * efficient concurrent update (usually only on server-wide stats), or
630  * as a single global struct (e.g. for per-client or per-job statistics),
631  * so the required locking depends on the type of structure allocated.
632  *
633  * For per-CPU statistics, pin the thread to the current cpuid so that
634  * will only access the statistics for that CPU.  If the stats structure
635  * for the current CPU has not been allocated (or previously freed),
636  * allocate it now.  The per-CPU statistics do not need locking since
637  * the thread is pinned to the CPU during update.
638  *
639  * For global statistics, lock the stats structure to prevent concurrent update.
640  *
641  * \param[in] stats     statistics structure to lock
642  * \param[in] opc       type of operation:
643  *                      LPROCFS_GET_SMP_ID: "lock" and return current CPU index
644  *                              for incrementing statistics for that CPU
645  *                      LPROCFS_GET_NUM_CPU: "lock" and return number of used
646  *                              CPU indices to iterate over all indices
647  * \param[out] flags    CPU interrupt saved state for IRQ-safe locking
648  *
649  * \retval cpuid of current thread or number of allocated structs
650  * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
651  */
652 int lprocfs_stats_lock(struct lprocfs_stats *stats,
653                        enum lprocfs_stats_lock_ops opc,
654                        unsigned long *flags)
655 {
656         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
657                 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
658                         spin_lock_irqsave(&stats->ls_lock, *flags);
659                 else
660                         spin_lock(&stats->ls_lock);
661                 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
662         }
663
664         switch (opc) {
665         case LPROCFS_GET_SMP_ID: {
666                 unsigned int cpuid = get_cpu();
667
668                 if (unlikely(!stats->ls_percpu[cpuid])) {
669                         int rc = lprocfs_stats_alloc_one(stats, cpuid);
670
671                         if (rc < 0) {
672                                 put_cpu();
673                                 return rc;
674                         }
675                 }
676                 return cpuid;
677         }
678         case LPROCFS_GET_NUM_CPU:
679                 return stats->ls_biggest_alloc_num;
680         default:
681                 LBUG();
682         }
683 }
684
685 /**
686  * Unlock statistics structure after access.
687  *
688  * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
689  * or unpin this thread from the current cpuid for per-CPU statistics.
690  *
691  * This function must be called using the same arguments as used when calling
692  * lprocfs_stats_lock() so that the correct operation can be performed.
693  *
694  * \param[in] stats     statistics structure to unlock
695  * \param[in] opc       type of operation (current cpuid or number of structs)
696  * \param[in] flags     CPU interrupt saved state for IRQ-safe locking
697  */
698 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
699                           enum lprocfs_stats_lock_ops opc,
700                           unsigned long *flags)
701 {
702         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
703                 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
704                         spin_unlock_irqrestore(&stats->ls_lock, *flags);
705                 else
706                         spin_unlock(&stats->ls_lock);
707         } else if (opc == LPROCFS_GET_SMP_ID) {
708                 put_cpu();
709         }
710 }
711
712 /** add up per-cpu counters */
713 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
714                            struct lprocfs_counter *cnt)
715 {
716         unsigned int                    num_entry;
717         struct lprocfs_counter          *percpu_cntr;
718         int                             i;
719         unsigned long                   flags = 0;
720
721         memset(cnt, 0, sizeof(*cnt));
722
723         if (stats == NULL) {
724                 /* set count to 1 to avoid divide-by-zero errs in callers */
725                 cnt->lc_count = 1;
726                 return;
727         }
728
729         cnt->lc_min = LC_MIN_INIT;
730
731         num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
732
733         for (i = 0; i < num_entry; i++) {
734                 if (stats->ls_percpu[i] == NULL)
735                         continue;
736                 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
737
738                 cnt->lc_count += percpu_cntr->lc_count;
739                 cnt->lc_sum += percpu_cntr->lc_sum;
740                 if (percpu_cntr->lc_min < cnt->lc_min)
741                         cnt->lc_min = percpu_cntr->lc_min;
742                 if (percpu_cntr->lc_max > cnt->lc_max)
743                         cnt->lc_max = percpu_cntr->lc_max;
744                 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
745         }
746
747         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
748 }
749
750 /**
751  * Append a space separated list of current set flags to str.
752  */
753 #define flag2str(flag)                                          \
754         do {                                                            \
755                 if (imp->imp_##flag) {                                  \
756                         seq_printf(m, "%s" #flag, first ? "" : ", ");   \
757                         first = false;                                  \
758                 }                                                       \
759         } while (0)
760 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
761 {
762         bool first = true;
763
764         if (imp->imp_obd->obd_no_recov) {
765                 seq_printf(m, "no_recov");
766                 first = false;
767         }
768
769         flag2str(invalid);
770         flag2str(deactive);
771         flag2str(replayable);
772         flag2str(delayed_recovery);
773         flag2str(no_lock_replay);
774         flag2str(vbr_failed);
775         flag2str(pingable);
776         flag2str(resend_replay);
777         flag2str(no_pinger_recover);
778         flag2str(need_mne_swab);
779         flag2str(connect_tried);
780 }
781 #undef flag2str
782
783 static const char *obd_connect_names[] = {
784         /* flags names  */
785         "read_only",
786         "lov_index",
787         "connect_from_mds",
788         "write_grant",
789         "server_lock",
790         "version",
791         "request_portal",
792         "acl",
793         "xattr",
794         "create_on_write",
795         "truncate_lock",
796         "initial_transno",
797         "inode_bit_locks",
798         "barrier",
799         "getattr_by_fid",
800         "no_oh_for_devices",
801         "remote_client",
802         "remote_client_by_force",
803         "max_byte_per_rpc",
804         "64bit_qdata",
805         "mds_capability",
806         "oss_capability",
807         "early_lock_cancel",
808         "som",
809         "adaptive_timeouts",
810         "lru_resize",
811         "mds_mds_connection",
812         "real_conn",
813         "change_qunit_size",
814         "alt_checksum_algorithm",
815         "fid_is_enabled",
816         "version_recovery",
817         "pools",
818         "grant_shrink",
819         "skip_orphan",
820         "large_ea",
821         "full20",
822         "layout_lock",
823         "64bithash",
824         "object_max_bytes",
825         "imp_recov",
826         "jobstats",
827         "umask",
828         "einprogress",
829         "grant_param",
830         "flock_owner",
831         "lvb_type",
832         "nanoseconds_times",
833         "lightweight_conn",
834         "short_io",
835         "pingless",
836         "flock_deadlock",
837         "disp_stripe",
838         "open_by_fid",
839         "lfsck",
840         "unknown",
841         "unlink_close",
842         "multi_mod_rpcs",
843         "dir_stripe",
844         "subtree",
845         "lock_ahead",
846         "bulk_mbits",
847         "compact_obdo",
848         "second_flags",
849         /* flags2 names */
850         "file_secctx",
851         NULL
852 };
853
854 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags,
855                                       __u64 flags2, const char *sep)
856 {
857         bool first = true;
858         __u64 mask;
859         int i;
860
861         for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
862                 if (flags & mask) {
863                         seq_printf(m, "%s%s",
864                                    first ? "" : sep, obd_connect_names[i]);
865                         first = false;
866                 }
867         }
868
869         if (flags & ~(mask - 1)) {
870                 seq_printf(m, "%sunknown_%#llx",
871                            first ? "" : sep, flags & ~(mask - 1));
872                 first = false;
873         }
874
875         if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
876                 return;
877
878         for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
879                 if (flags2 & mask) {
880                         seq_printf(m, "%s%s",
881                                    first ? "" : sep, obd_connect_names[i]);
882                         first = false;
883                 }
884         }
885
886         if (flags2 & ~(mask - 1)) {
887                 seq_printf(m, "%sunknown2_%#llx",
888                            first ? "" : sep, flags2 & ~(mask - 1));
889                 first = false;
890         }
891 }
892
893 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
894                           const char *sep)
895 {
896         __u64 mask;
897         int i, ret = 0;
898
899         for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
900                 if (flags & mask)
901                         ret += snprintf(page + ret, count - ret, "%s%s",
902                                         ret ? sep : "", obd_connect_names[i]);
903         }
904
905         if (flags & ~(mask - 1))
906                 ret += snprintf(page + ret, count - ret,
907                                 "%sunknown_%#llx",
908                                 ret ? sep : "", flags & ~(mask - 1));
909
910         if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
911                 return ret;
912
913         for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
914                 if (flags2 & mask)
915                         ret += snprintf(page + ret, count - ret, "%s%s",
916                                         ret ? sep : "", obd_connect_names[i]);
917         }
918
919         if (flags2 & ~(mask - 1))
920                 ret += snprintf(page + ret, count - ret,
921                                 "%sunknown2_%#llx",
922                                 ret ? sep : "", flags2 & ~(mask - 1));
923
924         return ret;
925 }
926 EXPORT_SYMBOL(obd_connect_flags2str);
927
928 static void obd_connect_data_seqprint(struct seq_file *m,
929                                       struct obd_connect_data *ocd)
930 {
931         __u64 flags;
932
933         LASSERT(ocd != NULL);
934         flags = ocd->ocd_connect_flags;
935
936         seq_printf(m, "    connect_data:\n"
937                    "       flags: %#llx\n"
938                    "       instance: %u\n",
939                    ocd->ocd_connect_flags,
940                    ocd->ocd_instance);
941         if (flags & OBD_CONNECT_VERSION)
942                 seq_printf(m, "       target_version: %u.%u.%u.%u\n",
943                            OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
944                            OBD_OCD_VERSION_MINOR(ocd->ocd_version),
945                            OBD_OCD_VERSION_PATCH(ocd->ocd_version),
946                            OBD_OCD_VERSION_FIX(ocd->ocd_version));
947         if (flags & OBD_CONNECT_MDS)
948                 seq_printf(m, "       mdt_index: %d\n", ocd->ocd_group);
949         if (flags & OBD_CONNECT_GRANT)
950                 seq_printf(m, "       initial_grant: %d\n", ocd->ocd_grant);
951         if (flags & OBD_CONNECT_INDEX)
952                 seq_printf(m, "       target_index: %u\n", ocd->ocd_index);
953         if (flags & OBD_CONNECT_BRW_SIZE)
954                 seq_printf(m, "       max_brw_size: %d\n", ocd->ocd_brw_size);
955         if (flags & OBD_CONNECT_IBITS)
956                 seq_printf(m, "       ibits_known: %#llx\n",
957                            ocd->ocd_ibits_known);
958         if (flags & OBD_CONNECT_GRANT_PARAM)
959                 seq_printf(m, "       grant_block_size: %d\n"
960                            "       grant_inode_size: %d\n"
961                            "       grant_max_extent_size: %d\n"
962                            "       grant_extent_tax: %d\n",
963                            1 << ocd->ocd_grant_blkbits,
964                            1 << ocd->ocd_grant_inobits,
965                            ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
966                            ocd->ocd_grant_tax_kb << 10);
967         if (flags & OBD_CONNECT_TRANSNO)
968                 seq_printf(m, "       first_transno: %#llx\n",
969                            ocd->ocd_transno);
970         if (flags & OBD_CONNECT_CKSUM)
971                 seq_printf(m, "       cksum_types: %#x\n",
972                            ocd->ocd_cksum_types);
973         if (flags & OBD_CONNECT_MAX_EASIZE)
974                 seq_printf(m, "       max_easize: %d\n", ocd->ocd_max_easize);
975         if (flags & OBD_CONNECT_MAXBYTES)
976                 seq_printf(m, "       max_object_bytes: %llu\n",
977                            ocd->ocd_maxbytes);
978         if (flags & OBD_CONNECT_MULTIMODRPCS)
979                 seq_printf(m, "       max_mod_rpcs: %hu\n",
980                            ocd->ocd_maxmodrpcs);
981 }
982
983 int lprocfs_import_seq_show(struct seq_file *m, void *data)
984 {
985         char                            nidstr[LNET_NIDSTR_SIZE];
986         struct lprocfs_counter          ret;
987         struct lprocfs_counter_header   *header;
988         struct obd_device               *obd    = (struct obd_device *)data;
989         struct obd_import               *imp;
990         struct obd_import_conn          *conn;
991         struct obd_connect_data         *ocd;
992         int                             j;
993         int                             k;
994         int                             rw      = 0;
995
996         LASSERT(obd != NULL);
997         LPROCFS_CLIMP_CHECK(obd);
998         imp = obd->u.cli.cl_import;
999         ocd = &imp->imp_connect_data;
1000
1001         seq_printf(m, "import:\n"
1002                    "    name: %s\n"
1003                    "    target: %s\n"
1004                    "    state: %s\n"
1005                    "    connect_flags: [ ",
1006                    obd->obd_name,
1007                    obd2cli_tgt(obd),
1008                    ptlrpc_import_state_name(imp->imp_state));
1009         obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1010                                   imp->imp_connect_data.ocd_connect_flags2,
1011                                   ", ");
1012         seq_printf(m, " ]\n");
1013         obd_connect_data_seqprint(m, ocd);
1014         seq_printf(m, "    import_flags: [ ");
1015         obd_import_flags2str(imp, m);
1016
1017         seq_printf(m, " ]\n"
1018                    "    connection:\n"
1019                    "       failover_nids: [ ");
1020         spin_lock(&imp->imp_lock);
1021         j = 0;
1022         list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1023                 libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
1024                                  nidstr, sizeof(nidstr));
1025                 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
1026                 j++;
1027         }
1028         if (imp->imp_connection != NULL)
1029                 libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
1030                                  nidstr, sizeof(nidstr));
1031         else
1032                 strncpy(nidstr, "<none>", sizeof(nidstr));
1033         seq_printf(m, " ]\n"
1034                    "       current_connection: %s\n"
1035                    "       connection_attempts: %u\n"
1036                    "       generation: %u\n"
1037                    "       in-progress_invalidations: %u\n",
1038                    nidstr,
1039                    imp->imp_conn_cnt,
1040                    imp->imp_generation,
1041                    atomic_read(&imp->imp_inval_count));
1042         spin_unlock(&imp->imp_lock);
1043
1044         if (obd->obd_svc_stats == NULL)
1045                 goto out_climp;
1046
1047         header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1048         lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1049         if (ret.lc_count != 0) {
1050                 /* first argument to do_div MUST be __u64 */
1051                 __u64 sum = ret.lc_sum;
1052                 do_div(sum, ret.lc_count);
1053                 ret.lc_sum = sum;
1054         } else
1055                 ret.lc_sum = 0;
1056         seq_printf(m, "    rpcs:\n"
1057                    "       inflight: %u\n"
1058                    "       unregistering: %u\n"
1059                    "       timeouts: %u\n"
1060                    "       avg_waittime: %llu %s\n",
1061                    atomic_read(&imp->imp_inflight),
1062                    atomic_read(&imp->imp_unregistering),
1063                    atomic_read(&imp->imp_timeouts),
1064                    ret.lc_sum, header->lc_units);
1065
1066         k = 0;
1067         for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1068                 if (imp->imp_at.iat_portal[j] == 0)
1069                         break;
1070                 k = max_t(unsigned int, k,
1071                           at_get(&imp->imp_at.iat_service_estimate[j]));
1072         }
1073         seq_printf(m, "    service_estimates:\n"
1074                    "       services: %u sec\n"
1075                    "       network: %u sec\n",
1076                    k,
1077                    at_get(&imp->imp_at.iat_net_latency));
1078
1079         seq_printf(m, "    transactions:\n"
1080                    "       last_replay: %llu\n"
1081                    "       peer_committed: %llu\n"
1082                    "       last_checked: %llu\n",
1083                    imp->imp_last_replay_transno,
1084                    imp->imp_peer_committed_transno,
1085                    imp->imp_last_transno_checked);
1086
1087         /* avg data rates */
1088         for (rw = 0; rw <= 1; rw++) {
1089                 lprocfs_stats_collect(obd->obd_svc_stats,
1090                                       PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1091                                       &ret);
1092                 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1093                         /* first argument to do_div MUST be __u64 */
1094                         __u64 sum = ret.lc_sum;
1095                         do_div(sum, ret.lc_count);
1096                         ret.lc_sum = sum;
1097                         seq_printf(m, "    %s_data_averages:\n"
1098                                    "       bytes_per_rpc: %llu\n",
1099                                    rw ? "write" : "read",
1100                                    ret.lc_sum);
1101                 }
1102                 k = (int)ret.lc_sum;
1103                 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1104                 header = &obd->obd_svc_stats->ls_cnt_header[j];
1105                 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1106                 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1107                         /* first argument to do_div MUST be __u64 */
1108                         __u64 sum = ret.lc_sum;
1109                         do_div(sum, ret.lc_count);
1110                         ret.lc_sum = sum;
1111                         seq_printf(m, "       %s_per_rpc: %llu\n",
1112                                    header->lc_units, ret.lc_sum);
1113                         j = (int)ret.lc_sum;
1114                         if (j > 0)
1115                                 seq_printf(m, "       MB_per_sec: %u.%.02u\n",
1116                                            k / j, (100 * k / j) % 100);
1117                 }
1118         }
1119
1120 out_climp:
1121         LPROCFS_CLIMP_EXIT(obd);
1122         return 0;
1123 }
1124 EXPORT_SYMBOL(lprocfs_import_seq_show);
1125
1126 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1127 {
1128         struct obd_device *obd = (struct obd_device *)data;
1129         struct obd_import *imp;
1130         int j, k;
1131
1132         LASSERT(obd != NULL);
1133         LPROCFS_CLIMP_CHECK(obd);
1134         imp = obd->u.cli.cl_import;
1135
1136         seq_printf(m, "current_state: %s\n",
1137                    ptlrpc_import_state_name(imp->imp_state));
1138         seq_printf(m, "state_history:\n");
1139         k = imp->imp_state_hist_idx;
1140         for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1141                 struct import_state_hist *ish =
1142                         &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1143                 if (ish->ish_state == 0)
1144                         continue;
1145                 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
1146                            ptlrpc_import_state_name(ish->ish_state));
1147         }
1148
1149         LPROCFS_CLIMP_EXIT(obd);
1150         return 0;
1151 }
1152 EXPORT_SYMBOL(lprocfs_state_seq_show);
1153
1154 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1155 {
1156         int i;
1157         for (i = 0; i < AT_BINS; i++)
1158                 seq_printf(m, "%3u ", at->at_hist[i]);
1159         seq_printf(m, "\n");
1160         return 0;
1161 }
1162 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1163
1164 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1165 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1166 {
1167         struct obd_device *obd = (struct obd_device *)data;
1168         struct obd_import *imp;
1169         unsigned int cur, worst;
1170         time64_t now, worstt;
1171         int i;
1172
1173         LASSERT(obd != NULL);
1174         LPROCFS_CLIMP_CHECK(obd);
1175         imp = obd->u.cli.cl_import;
1176
1177         now = ktime_get_real_seconds();
1178
1179         /* Some network health info for kicks */
1180         seq_printf(m, "%-10s : %lld, %llds ago\n",
1181                    "last reply", (s64)imp->imp_last_reply_time,
1182                    (s64)(now - imp->imp_last_reply_time));
1183
1184         cur = at_get(&imp->imp_at.iat_net_latency);
1185         worst = imp->imp_at.iat_net_latency.at_worst_ever;
1186         worstt = imp->imp_at.iat_net_latency.at_worst_time;
1187         seq_printf(m, "%-10s : cur %3u  worst %3u (at %lld, %llds ago) ",
1188                    "network", cur, worst, (s64)worstt, (s64)(now - worstt));
1189         lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1190
1191         for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1192                 if (imp->imp_at.iat_portal[i] == 0)
1193                         break;
1194                 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1195                 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1196                 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1197                 seq_printf(m, "portal %-2d  : cur %3u  worst %3u (at %lld, %llds ago) ",
1198                            imp->imp_at.iat_portal[i], cur, worst, (s64)worstt,
1199                            (s64)(now - worstt));
1200                 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1201         }
1202
1203         LPROCFS_CLIMP_EXIT(obd);
1204         return 0;
1205 }
1206 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1207
1208 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1209 {
1210         struct obd_device *obd = data;
1211         __u64 flags;
1212         __u64 flags2;
1213
1214         LPROCFS_CLIMP_CHECK(obd);
1215         flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1216         flags2 = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags2;
1217         seq_printf(m, "flags=%#llx\n", flags);
1218         seq_printf(m, "flags2=%#llx\n", flags2);
1219         obd_connect_seq_flags2str(m, flags, flags2, "\n");
1220         seq_printf(m, "\n");
1221         LPROCFS_CLIMP_EXIT(obd);
1222         return 0;
1223 }
1224 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1225
1226 static struct attribute *obd_def_uuid_attrs[] = {
1227         &lustre_attr_uuid.attr,
1228         NULL,
1229 };
1230
1231 static struct attribute *obd_def_attrs[] = {
1232         &lustre_attr_blocksize.attr,
1233         &lustre_attr_kbytestotal.attr,
1234         &lustre_attr_kbytesfree.attr,
1235         &lustre_attr_kbytesavail.attr,
1236         &lustre_attr_filestotal.attr,
1237         &lustre_attr_filesfree.attr,
1238         &lustre_attr_uuid.attr,
1239         NULL,
1240 };
1241
1242 static void obd_sysfs_release(struct kobject *kobj)
1243 {
1244         struct obd_device *obd = container_of(kobj, struct obd_device,
1245                                               obd_kobj);
1246
1247         complete(&obd->obd_kobj_unregister);
1248 }
1249
1250 static struct kobj_type obd_ktype = {
1251         .sysfs_ops      = &lustre_sysfs_ops,
1252         .release        = obd_sysfs_release,
1253 };
1254
1255 int
1256 lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1257 {
1258         int rc = 0;
1259
1260         LASSERT(obd != NULL);
1261         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1262         LASSERT(obd->obd_type->typ_procroot != NULL);
1263
1264         if (uuid_only)
1265                 obd_ktype.default_attrs = obd_def_uuid_attrs;
1266         else
1267                 obd_ktype.default_attrs = obd_def_attrs;
1268
1269         init_completion(&obd->obd_kobj_unregister);
1270         rc = kobject_init_and_add(&obd->obd_kobj, &obd_ktype,
1271                                   obd->obd_type->typ_kobj,
1272                                   "%s", obd->obd_name);
1273         if (rc)
1274                 return rc;
1275
1276         if (obd->obd_attrs) {
1277                 rc = sysfs_create_group(&obd->obd_kobj, obd->obd_attrs);
1278                 if (rc) {
1279                         kobject_put(&obd->obd_kobj);
1280                         return rc;
1281                 }
1282         }
1283
1284         obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1285                                                obd->obd_type->typ_procroot,
1286                                                obd->obd_vars, obd);
1287         if (IS_ERR(obd->obd_proc_entry)) {
1288                 kobject_put(&obd->obd_kobj);
1289                 rc = PTR_ERR(obd->obd_proc_entry);
1290                 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1291                 obd->obd_proc_entry = NULL;
1292         }
1293
1294         return rc;
1295 }
1296 EXPORT_SYMBOL(lprocfs_obd_setup);
1297
1298 int lprocfs_obd_cleanup(struct obd_device *obd)
1299 {
1300         if (!obd)
1301                 return -EINVAL;
1302
1303         if (obd->obd_proc_exports_entry) {
1304                 /* Should be no exports left */
1305                 lprocfs_remove(&obd->obd_proc_exports_entry);
1306                 obd->obd_proc_exports_entry = NULL;
1307         }
1308
1309         if (obd->obd_proc_entry) {
1310                 lprocfs_remove(&obd->obd_proc_entry);
1311                 obd->obd_proc_entry = NULL;
1312         }
1313
1314         kobject_put(&obd->obd_kobj);
1315         wait_for_completion(&obd->obd_kobj_unregister);
1316         return 0;
1317 }
1318 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1319
1320 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1321 {
1322         struct lprocfs_counter  *cntr;
1323         unsigned int            percpusize;
1324         int                     rc = -ENOMEM;
1325         unsigned long           flags = 0;
1326         int                     i;
1327
1328         LASSERT(stats->ls_percpu[cpuid] == NULL);
1329         LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1330
1331         percpusize = lprocfs_stats_counter_size(stats);
1332         LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1333         if (stats->ls_percpu[cpuid] != NULL) {
1334                 rc = 0;
1335                 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1336                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1337                                 spin_lock_irqsave(&stats->ls_lock, flags);
1338                         else
1339                                 spin_lock(&stats->ls_lock);
1340                         if (stats->ls_biggest_alloc_num <= cpuid)
1341                                 stats->ls_biggest_alloc_num = cpuid + 1;
1342                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1343                                 spin_unlock_irqrestore(&stats->ls_lock, flags);
1344                         } else {
1345                                 spin_unlock(&stats->ls_lock);
1346                         }
1347                 }
1348                 /* initialize the ls_percpu[cpuid] non-zero counter */
1349                 for (i = 0; i < stats->ls_num; ++i) {
1350                         cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1351                         cntr->lc_min = LC_MIN_INIT;
1352                 }
1353         }
1354         return rc;
1355 }
1356
1357 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1358                                           enum lprocfs_stats_flags flags)
1359 {
1360         struct lprocfs_stats    *stats;
1361         unsigned int            num_entry;
1362         unsigned int            percpusize = 0;
1363         int                     i;
1364
1365         if (num == 0)
1366                 return NULL;
1367
1368         if (lprocfs_no_percpu_stats != 0)
1369                 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1370
1371         if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1372                 num_entry = 1;
1373         else
1374                 num_entry = num_possible_cpus();
1375
1376         /* alloc percpu pointers for all possible cpu slots */
1377         LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1378         if (stats == NULL)
1379                 return NULL;
1380
1381         stats->ls_num = num;
1382         stats->ls_flags = flags;
1383         spin_lock_init(&stats->ls_lock);
1384
1385         /* alloc num of counter headers */
1386         LIBCFS_ALLOC(stats->ls_cnt_header,
1387                      stats->ls_num * sizeof(struct lprocfs_counter_header));
1388         if (stats->ls_cnt_header == NULL)
1389                 goto fail;
1390
1391         if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1392                 /* contains only one set counters */
1393                 percpusize = lprocfs_stats_counter_size(stats);
1394                 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1395                 if (stats->ls_percpu[0] == NULL)
1396                         goto fail;
1397                 stats->ls_biggest_alloc_num = 1;
1398         } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1399                 /* alloc all percpu data, currently only obd_memory use this */
1400                 for (i = 0; i < num_entry; ++i)
1401                         if (lprocfs_stats_alloc_one(stats, i) < 0)
1402                                 goto fail;
1403         }
1404
1405         return stats;
1406
1407 fail:
1408         lprocfs_free_stats(&stats);
1409         return NULL;
1410 }
1411 EXPORT_SYMBOL(lprocfs_alloc_stats);
1412
1413 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1414 {
1415         struct lprocfs_stats *stats = *statsh;
1416         unsigned int num_entry;
1417         unsigned int percpusize;
1418         unsigned int i;
1419
1420         if (stats == NULL || stats->ls_num == 0)
1421                 return;
1422         *statsh = NULL;
1423
1424         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1425                 num_entry = 1;
1426         else
1427                 num_entry = num_possible_cpus();
1428
1429         percpusize = lprocfs_stats_counter_size(stats);
1430         for (i = 0; i < num_entry; i++)
1431                 if (stats->ls_percpu[i] != NULL)
1432                         LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1433         if (stats->ls_cnt_header != NULL)
1434                 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1435                                         sizeof(struct lprocfs_counter_header));
1436         LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1437 }
1438 EXPORT_SYMBOL(lprocfs_free_stats);
1439
1440 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1441                             enum lprocfs_fields_flags field)
1442 {
1443         unsigned long flags = 0;
1444         unsigned int num_cpu;
1445         unsigned int i;
1446         u64 ret = 0;
1447
1448         LASSERT(stats);
1449
1450         num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1451         for (i = 0; i < num_cpu; i++) {
1452                 struct lprocfs_counter *cntr;
1453
1454                 if (!stats->ls_percpu[i])
1455                         continue;
1456
1457                 cntr = lprocfs_stats_counter_get(stats, i, idx);
1458                 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1459                                            stats->ls_flags, field);
1460         }
1461         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1462         return ret;
1463 }
1464 EXPORT_SYMBOL(lprocfs_stats_collector);
1465
1466 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1467 {
1468         struct lprocfs_counter          *percpu_cntr;
1469         int                             i;
1470         int                             j;
1471         unsigned int                    num_entry;
1472         unsigned long                   flags = 0;
1473
1474         num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1475
1476         for (i = 0; i < num_entry; i++) {
1477                 if (stats->ls_percpu[i] == NULL)
1478                         continue;
1479                 for (j = 0; j < stats->ls_num; j++) {
1480                         percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1481                         percpu_cntr->lc_count           = 0;
1482                         percpu_cntr->lc_min             = LC_MIN_INIT;
1483                         percpu_cntr->lc_max             = 0;
1484                         percpu_cntr->lc_sumsquare       = 0;
1485                         percpu_cntr->lc_sum             = 0;
1486                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1487                                 percpu_cntr->lc_sum_irq = 0;
1488                 }
1489         }
1490
1491         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1492 }
1493 EXPORT_SYMBOL(lprocfs_clear_stats);
1494
1495 static ssize_t lprocfs_stats_seq_write(struct file *file,
1496                                        const char __user *buf,
1497                                        size_t len, loff_t *off)
1498 {
1499         struct seq_file *seq = file->private_data;
1500         struct lprocfs_stats *stats = seq->private;
1501
1502         lprocfs_clear_stats(stats);
1503
1504         return len;
1505 }
1506
1507 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1508 {
1509         struct lprocfs_stats *stats = p->private;
1510
1511         return (*pos < stats->ls_num) ? pos : NULL;
1512 }
1513
1514 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1515 {
1516 }
1517
1518 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1519 {
1520         (*pos)++;
1521
1522         return lprocfs_stats_seq_start(p, pos);
1523 }
1524
1525 /* seq file export of one lprocfs counter */
1526 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1527 {
1528         struct lprocfs_stats            *stats  = p->private;
1529         struct lprocfs_counter_header   *hdr;
1530         struct lprocfs_counter           ctr;
1531         int                              idx    = *(loff_t *)v;
1532
1533         if (idx == 0) {
1534                 struct timespec64 now;
1535
1536                 ktime_get_real_ts64(&now);
1537                 seq_printf(p, "%-25s %llu.%09lu secs.nsecs\n",
1538                            "snapshot_time", (s64)now.tv_sec, now.tv_nsec);
1539         }
1540
1541         hdr = &stats->ls_cnt_header[idx];
1542         lprocfs_stats_collect(stats, idx, &ctr);
1543
1544         if (ctr.lc_count == 0)
1545                 return 0;
1546
1547         seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1548                    ctr.lc_count, hdr->lc_units);
1549
1550         if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1551                 seq_printf(p, " %lld %lld %lld",
1552                            ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1553                 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1554                         seq_printf(p, " %llu", ctr.lc_sumsquare);
1555         }
1556         seq_putc(p, '\n');
1557         return 0;
1558 }
1559
1560 static const struct seq_operations lprocfs_stats_seq_sops = {
1561         .start  = lprocfs_stats_seq_start,
1562         .stop   = lprocfs_stats_seq_stop,
1563         .next   = lprocfs_stats_seq_next,
1564         .show   = lprocfs_stats_seq_show,
1565 };
1566
1567 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1568 {
1569         struct seq_file *seq;
1570         int rc;
1571
1572         rc = LPROCFS_ENTRY_CHECK(inode);
1573         if (rc < 0)
1574                 return rc;
1575
1576         rc = seq_open(file, &lprocfs_stats_seq_sops);
1577         if (rc)
1578                 return rc;
1579         seq = file->private_data;
1580         seq->private = inode->i_private ? : PDE_DATA(inode);
1581         return 0;
1582 }
1583
1584 static const struct file_operations lprocfs_stats_seq_fops = {
1585         .owner   = THIS_MODULE,
1586         .open    = lprocfs_stats_seq_open,
1587         .read    = seq_read,
1588         .write   = lprocfs_stats_seq_write,
1589         .llseek  = seq_lseek,
1590         .release = lprocfs_seq_release,
1591 };
1592
1593 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1594                             struct lprocfs_stats *stats)
1595 {
1596         struct dentry *entry;
1597
1598         LASSERT(!IS_ERR_OR_NULL(parent));
1599
1600         entry = debugfs_create_file(name, 0644, parent, stats,
1601                                     &lprocfs_stats_seq_fops);
1602         if (IS_ERR_OR_NULL(entry))
1603                 return entry ? PTR_ERR(entry) : -ENOMEM;
1604
1605         return 0;
1606 }
1607 EXPORT_SYMBOL_GPL(ldebugfs_register_stats);
1608
1609 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1610                            struct lprocfs_stats *stats)
1611 {
1612         struct proc_dir_entry *entry;
1613         LASSERT(root != NULL);
1614
1615         entry = proc_create_data(name, 0644, root,
1616                                  &lprocfs_stats_seq_fops, stats);
1617         if (entry == NULL)
1618                 return -ENOMEM;
1619         return 0;
1620 }
1621 EXPORT_SYMBOL(lprocfs_register_stats);
1622
1623 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1624                           unsigned conf, const char *name, const char *units)
1625 {
1626         struct lprocfs_counter_header   *header;
1627         struct lprocfs_counter          *percpu_cntr;
1628         unsigned long                   flags = 0;
1629         unsigned int                    i;
1630         unsigned int                    num_cpu;
1631
1632         LASSERT(stats != NULL);
1633
1634         header = &stats->ls_cnt_header[index];
1635         LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1636                  index, name, units);
1637
1638         header->lc_config = conf;
1639         header->lc_name   = name;
1640         header->lc_units  = units;
1641
1642         num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1643         for (i = 0; i < num_cpu; ++i) {
1644                 if (stats->ls_percpu[i] == NULL)
1645                         continue;
1646                 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1647                 percpu_cntr->lc_count           = 0;
1648                 percpu_cntr->lc_min             = LC_MIN_INIT;
1649                 percpu_cntr->lc_max             = 0;
1650                 percpu_cntr->lc_sumsquare       = 0;
1651                 percpu_cntr->lc_sum             = 0;
1652                 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1653                         percpu_cntr->lc_sum_irq = 0;
1654         }
1655         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1656 }
1657 EXPORT_SYMBOL(lprocfs_counter_init);
1658
1659 /* Note that we only init md counters for ops whose offset is less
1660  * than NUM_MD_STATS. This is explained in a comment in the definition
1661  * of struct md_ops. */
1662 #define LPROCFS_MD_OP_INIT(base, stats, op)                                    \
1663         do {                                                                   \
1664                 unsigned int _idx = base + MD_COUNTER_OFFSET(op);              \
1665                                                                                \
1666                 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) {                    \
1667                         LASSERT(_idx < stats->ls_num);                         \
1668                         lprocfs_counter_init(stats, _idx, 0, #op, "reqs");     \
1669                 }                                                              \
1670         } while (0)
1671
1672 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1673 {
1674         LPROCFS_MD_OP_INIT(num_private_stats, stats, get_root);
1675         LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1676         LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1677         LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1678         LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1679         LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1680         LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1681         LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1682         LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1683         LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1684         LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1685         LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
1686         LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
1687         LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1688         LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1689         LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1690         LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1691         LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1692         LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1693         LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
1694         LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1695         LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1696         LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1697         LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1698         LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1699         LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1700         LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1701 }
1702
1703 int lprocfs_alloc_md_stats(struct obd_device *obd,
1704                            unsigned int num_private_stats)
1705 {
1706         struct lprocfs_stats *stats;
1707         unsigned int num_stats;
1708         int rc, i;
1709
1710         CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
1711         CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
1712         CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
1713
1714         /* TODO Ensure that this function is only used where
1715          * appropriate by adding an assertion to the effect that
1716          * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1717          * because mdt_procfs_init() uses this function to allocate
1718          * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1719          * mdt layer does not use the md_ops interface. This is
1720          * confusing and a waste of memory. See LU-2484.
1721          */
1722         LASSERT(obd->obd_proc_entry != NULL);
1723         LASSERT(obd->obd_md_stats == NULL);
1724         LASSERT(obd->obd_md_cntr_base == 0);
1725
1726         num_stats = NUM_MD_STATS + num_private_stats;
1727         stats = lprocfs_alloc_stats(num_stats, 0);
1728         if (stats == NULL)
1729                 return -ENOMEM;
1730
1731         lprocfs_init_mps_stats(num_private_stats, stats);
1732
1733         for (i = num_private_stats; i < num_stats; i++) {
1734                 if (stats->ls_cnt_header[i].lc_name == NULL) {
1735                         CERROR("Missing md_stat initializer md_op "
1736                                "operation at offset %d. Aborting.\n",
1737                                i - num_private_stats);
1738                         LBUG();
1739                 }
1740         }
1741
1742         rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1743         if (rc < 0) {
1744                 lprocfs_free_stats(&stats);
1745         } else {
1746                 obd->obd_md_stats = stats;
1747                 obd->obd_md_cntr_base = num_private_stats;
1748         }
1749
1750         return rc;
1751 }
1752 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1753
1754 void lprocfs_free_md_stats(struct obd_device *obd)
1755 {
1756         struct lprocfs_stats *stats = obd->obd_md_stats;
1757
1758         if (stats != NULL) {
1759                 obd->obd_md_stats = NULL;
1760                 obd->obd_md_cntr_base = 0;
1761                 lprocfs_free_stats(&stats);
1762         }
1763 }
1764 EXPORT_SYMBOL(lprocfs_free_md_stats);
1765
1766 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1767 {
1768         lprocfs_counter_init(ldlm_stats,
1769                              LDLM_ENQUEUE - LDLM_FIRST_OPC,
1770                              0, "ldlm_enqueue", "reqs");
1771         lprocfs_counter_init(ldlm_stats,
1772                              LDLM_CONVERT - LDLM_FIRST_OPC,
1773                              0, "ldlm_convert", "reqs");
1774         lprocfs_counter_init(ldlm_stats,
1775                              LDLM_CANCEL - LDLM_FIRST_OPC,
1776                              0, "ldlm_cancel", "reqs");
1777         lprocfs_counter_init(ldlm_stats,
1778                              LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1779                              0, "ldlm_bl_callback", "reqs");
1780         lprocfs_counter_init(ldlm_stats,
1781                              LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1782                              0, "ldlm_cp_callback", "reqs");
1783         lprocfs_counter_init(ldlm_stats,
1784                              LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1785                              0, "ldlm_gl_callback", "reqs");
1786 }
1787 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1788
1789 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1790                           struct lprocfs_counter_header *header,
1791                           enum lprocfs_stats_flags flags,
1792                           enum lprocfs_fields_flags field)
1793 {
1794         __s64 ret = 0;
1795
1796         if (lc == NULL || header == NULL)
1797                 RETURN(0);
1798
1799         switch (field) {
1800                 case LPROCFS_FIELDS_FLAGS_CONFIG:
1801                         ret = header->lc_config;
1802                         break;
1803                 case LPROCFS_FIELDS_FLAGS_SUM:
1804                         ret = lc->lc_sum;
1805                         if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1806                                 ret += lc->lc_sum_irq;
1807                         break;
1808                 case LPROCFS_FIELDS_FLAGS_MIN:
1809                         ret = lc->lc_min;
1810                         break;
1811                 case LPROCFS_FIELDS_FLAGS_MAX:
1812                         ret = lc->lc_max;
1813                         break;
1814                 case LPROCFS_FIELDS_FLAGS_AVG:
1815                         ret = (lc->lc_max - lc->lc_min) / 2;
1816                         break;
1817                 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1818                         ret = lc->lc_sumsquare;
1819                         break;
1820                 case LPROCFS_FIELDS_FLAGS_COUNT:
1821                         ret = lc->lc_count;
1822                         break;
1823                 default:
1824                         break;
1825         };
1826         RETURN(ret);
1827 }
1828 EXPORT_SYMBOL(lprocfs_read_helper);
1829
1830 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
1831                              int mult)
1832 {
1833         long decimal_val, frac_val;
1834         int prtn;
1835
1836         if (count < 10)
1837                 return -EINVAL;
1838
1839         decimal_val = val / mult;
1840         prtn = snprintf(buffer, count, "%ld", decimal_val);
1841         frac_val = val % mult;
1842
1843         if (prtn < (count - 4) && frac_val > 0) {
1844                 long temp_frac;
1845                 int i, temp_mult = 1, frac_bits = 0;
1846
1847                 temp_frac = frac_val * 10;
1848                 buffer[prtn++] = '.';
1849                 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
1850                         /* only reserved 2 bits fraction */
1851                         buffer[prtn++] ='0';
1852                         temp_frac *= 10;
1853                         frac_bits++;
1854                 }
1855                 /*
1856                  * Need to think these cases :
1857                  *      1. #echo x.00 > /proc/xxx       output result : x
1858                  *      2. #echo x.0x > /proc/xxx       output result : x.0x
1859                  *      3. #echo x.x0 > /proc/xxx       output result : x.x
1860                  *      4. #echo x.xx > /proc/xxx       output result : x.xx
1861                  *      Only reserved 2 bits fraction.
1862                  */
1863                 for (i = 0; i < (5 - prtn); i++)
1864                         temp_mult *= 10;
1865
1866                 frac_bits = min((int)count - prtn, 3 - frac_bits);
1867                 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
1868                                  frac_val * temp_mult / mult);
1869
1870                 prtn--;
1871                 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
1872                         prtn--;
1873                         if (buffer[prtn] == '.') {
1874                                 prtn--;
1875                                 break;
1876                         }
1877                 }
1878                 prtn++;
1879         }
1880         buffer[prtn++] ='\n';
1881         return prtn;
1882 }
1883 EXPORT_SYMBOL(lprocfs_read_frac_helper);
1884
1885 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1886 {
1887         long decimal_val, frac_val;
1888
1889         decimal_val = val / mult;
1890         seq_printf(m, "%ld", decimal_val);
1891         frac_val = val % mult;
1892
1893         if (frac_val > 0) {
1894                 frac_val *= 100;
1895                 frac_val /= mult;
1896         }
1897         if (frac_val > 0) {
1898                 /* Three cases: x0, xx, 0x */
1899                 if ((frac_val % 10) != 0)
1900                         seq_printf(m, ".%ld", frac_val);
1901                 else
1902                         seq_printf(m, ".%ld", frac_val / 10);
1903         }
1904
1905         seq_printf(m, "\n");
1906         return 0;
1907 }
1908 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1909
1910 /* Obtains the conversion factor for the unit specified */
1911 static int get_mult(char unit, __u64 *mult)
1912 {
1913         __u64 units = 1;
1914
1915         switch (unit) {
1916         /* peta, tera, giga, mega, and kilo */
1917         case 'p':
1918         case 'P':
1919                 units <<= 10;
1920         case 't':
1921         case 'T':
1922                 units <<= 10;
1923         case 'g':
1924         case 'G':
1925                 units <<= 10;
1926         case 'm':
1927         case 'M':
1928                 units <<= 10;
1929         case 'k':
1930         case 'K':
1931                 units <<= 10;
1932                 break;
1933         /* some tests expect % to be accepted */
1934         case '%':
1935                 units = 1;
1936                 break;
1937         default:
1938                 return -EINVAL;
1939         }
1940
1941         *mult = units;
1942
1943         return 0;
1944 }
1945
1946 /*
1947  * Ensures the numeric string is valid. The function provides the final
1948  * multiplier in the case a unit exists at the end of the string. It also
1949  * locates the start of the whole and fractional parts (if any). This
1950  * function modifies the string so kstrtoull can be used to parse both
1951  * the whole and fraction portions. This function also figures out
1952  * the base of the number.
1953  */
1954 static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
1955                                   bool allow_units, char **whole, char **frac,
1956                                   unsigned int *base)
1957 {
1958         bool hit_decimal = false;
1959         bool hit_unit = false;
1960         int rc = 0;
1961         char *start;
1962         *mult = def_mult;
1963         *whole = NULL;
1964         *frac = NULL;
1965         *base = 10;
1966
1967         /* a hex string if it starts with "0x" */
1968         if (buffer[0] == '0' && tolower(buffer[1]) == 'x') {
1969                 *base = 16;
1970                 buffer += 2;
1971         }
1972
1973         start = buffer;
1974
1975         while (*buffer) {
1976                 /* allow for a single new line before the null terminator */
1977                 if (*buffer == '\n') {
1978                         *buffer = '\0';
1979                         buffer++;
1980
1981                         if (*buffer)
1982                                 return -EINVAL;
1983
1984                         break;
1985                 }
1986
1987                 /* any chars after our unit indicates a malformed string */
1988                 if (hit_unit)
1989                         return -EINVAL;
1990
1991                 /* ensure we only hit one decimal */
1992                 if (*buffer == '.') {
1993                         if (hit_decimal)
1994                                 return -EINVAL;
1995
1996                         /* if past start, there's a whole part */
1997                         if (start != buffer)
1998                                 *whole = start;
1999
2000                         *buffer = '\0';
2001                         start = buffer + 1;
2002                         hit_decimal = true;
2003                 } else if (!isdigit(*buffer) &&
2004                            !(*base == 16 && isxdigit(*buffer))) {
2005                         if (allow_units) {
2006                                 /* if we allow units, attempt to get mult */
2007                                 hit_unit = true;
2008                                 rc = get_mult(*buffer, mult);
2009                                 if (rc)
2010                                         return rc;
2011
2012                                 /* string stops here, but keep processing */
2013                                 *buffer = '\0';
2014                         } else {
2015                                 /* bad string */
2016                                 return -EINVAL;
2017                         }
2018                 }
2019
2020                 buffer++;
2021         }
2022
2023         if (hit_decimal) {
2024                 /* hit a decimal, make sure there's a fractional part */
2025                 if (!*start)
2026                         return -EINVAL;
2027
2028                 *frac = start;
2029         } else {
2030                 /* didn't hit a decimal, but may have a whole part */
2031                 if (start != buffer && *start)
2032                         *whole = start;
2033         }
2034
2035         /* malformed string if we didn't get anything */
2036         if (!*frac && !*whole)
2037                 return -EINVAL;
2038
2039         return 0;
2040 }
2041
2042 /*
2043  * Parses a numeric string which can contain a whole and fraction portion
2044  * into a __u64. Accepts a multiplier to apply to the value parsed. Also
2045  * allows the string to have a unit at the end. The function handles
2046  * wrapping of the final unsigned value.
2047  */
2048 static int str_to_u64_parse(char *buffer, unsigned long count,
2049                             __u64 *val, __u64 def_mult, bool allow_units)
2050 {
2051         __u64 whole = 0;
2052         __u64 frac = 0;
2053         unsigned int frac_d = 1;
2054         __u64 wrap_indicator = ULLONG_MAX;
2055         int rc = 0;
2056         __u64 mult;
2057         char *strwhole;
2058         char *strfrac;
2059         unsigned int base = 10;
2060
2061         rc = preprocess_numeric_str(buffer, &mult, def_mult, allow_units,
2062                                     &strwhole, &strfrac, &base);
2063
2064         if (rc)
2065                 return rc;
2066
2067         if (mult == 0) {
2068                 *val = 0;
2069                 return 0;
2070         }
2071
2072         /* the multiplier limits how large the value can be */
2073         wrap_indicator /=  mult;
2074
2075         if (strwhole) {
2076                 rc = kstrtoull(strwhole, base, &whole);
2077                 if (rc)
2078                         return rc;
2079
2080                 if (whole > wrap_indicator)
2081                         return -ERANGE;
2082
2083                 whole *= mult;
2084         }
2085
2086         if (strfrac) {
2087                 if (strlen(strfrac) > 10)
2088                         strfrac[10] = '\0';
2089
2090                 rc = kstrtoull(strfrac, base, &frac);
2091                 if (rc)
2092                         return rc;
2093
2094                 /* determine power of fractional portion */
2095                 while (*strfrac) {
2096                         frac_d *= base;
2097                         strfrac++;
2098                 }
2099
2100                 /* fractional portion is too large to perform calculation */
2101                 if (frac > wrap_indicator)
2102                         return -ERANGE;
2103
2104                 frac *= mult;
2105                 do_div(frac, frac_d);
2106         }
2107
2108         /* check that the sum of whole and fraction fits in u64 */
2109         if (whole > (ULLONG_MAX - frac))
2110                 return -ERANGE;
2111
2112         *val = whole + frac;
2113
2114         return 0;
2115 }
2116
2117 /*
2118  * This function parses numeric/hex strings into __s64. It accepts a multiplier
2119  * which will apply to the value parsed. It also can allow the string to
2120  * have a unit as the last character. The function handles overflow/underflow
2121  * of the signed integer.
2122  */
2123 static int str_to_s64_internal(const char __user *buffer, unsigned long count,
2124                                __s64 *val, __u64 def_mult, bool allow_units)
2125 {
2126         char kernbuf[22];
2127         __u64 tmp;
2128         unsigned int offset = 0;
2129         int signed sign = 1;
2130         __u64 max = LLONG_MAX;
2131         int rc = 0;
2132
2133         if (count > (sizeof(kernbuf) - 1))
2134                 return -EINVAL;
2135
2136         if (copy_from_user(kernbuf, buffer, count))
2137                 return -EFAULT;
2138
2139         kernbuf[count] = '\0';
2140
2141         /* keep track of our sign */
2142         if (*kernbuf == '-') {
2143                 sign = -1;
2144                 offset++;
2145                 /* equivalent to max = -LLONG_MIN, avoids overflow */
2146                 max++;
2147         }
2148
2149         rc = str_to_u64_parse(kernbuf + offset, count - offset,
2150                               &tmp, def_mult, allow_units);
2151         if (rc)
2152                 return rc;
2153
2154         /* check for overflow/underflow */
2155         if (max < tmp)
2156                 return -ERANGE;
2157
2158         *val = (__s64)tmp * sign;
2159
2160         return 0;
2161 }
2162
2163 /**
2164  * Convert a user string into a signed 64 bit number. This function produces
2165  * an error when the value parsed from the string underflows or
2166  * overflows. This function accepts strings which contain digits and
2167  * optionally a decimal or hex strings which are prefixed with "0x".
2168  *
2169  * \param[in] buffer    string consisting of numbers and optionally a decimal
2170  * \param[in] count     buffer length
2171  * \param[in] val       if successful, the value represented by the string
2172  *
2173  * \retval              0 on success
2174  * \retval              negative number on error
2175  */
2176 int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
2177                        __s64 *val)
2178 {
2179         return str_to_s64_internal(buffer, count, val, 1, false);
2180 }
2181 EXPORT_SYMBOL(lprocfs_str_to_s64);
2182
2183 /**
2184  * Convert a user string into a signed 64 bit number. This function produces
2185  * an error when the value parsed from the string times multiplier underflows or
2186  * overflows. This function only accepts strings that contains digits, an
2187  * optional decimal, and a char representing a unit at the end. If a unit is
2188  * specified in the string, the multiplier provided by the caller is ignored.
2189  * This function can also accept hexadecimal strings which are prefixed with
2190  * "0x".
2191  *
2192  * \param[in] buffer    string consisting of numbers, a decimal, and a unit
2193  * \param[in] count     buffer length
2194  * \param[in] val       if successful, the value represented by the string
2195  * \param[in] defunit   default unit if string doesn't contain one
2196  *
2197  * \retval              0 on success
2198  * \retval              negative number on error
2199  */
2200 int lprocfs_str_with_units_to_s64(const char __user *buffer,
2201                                   unsigned long count, __s64 *val, char defunit)
2202 {
2203         __u64 mult = 1;
2204         int rc;
2205
2206         if (defunit != '1') {
2207                 rc = get_mult(defunit, &mult);
2208                 if (rc)
2209                         return rc;
2210         }
2211
2212         return str_to_s64_internal(buffer, count, val, mult, true);
2213 }
2214 EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
2215
2216 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2217 {
2218         size_t l2;
2219
2220         l2 = strlen(s2);
2221         if (!l2)
2222                 return (char *)s1;
2223         while (len >= l2) {
2224                 len--;
2225                 if (!memcmp(s1, s2, l2))
2226                         return (char *)s1;
2227                 s1++;
2228         }
2229         return NULL;
2230 }
2231
2232 /**
2233  * Find the string \a name in the input \a buffer, and return a pointer to the
2234  * value immediately following \a name, reducing \a count appropriately.
2235  * If \a name is not found the original \a buffer is returned.
2236  */
2237 char *lprocfs_find_named_value(const char *buffer, const char *name,
2238                                 size_t *count)
2239 {
2240         char *val;
2241         size_t buflen = *count;
2242
2243         /* there is no strnstr() in rhel5 and ubuntu kernels */
2244         val = lprocfs_strnstr(buffer, name, buflen);
2245         if (val == NULL)
2246                 return (char *)buffer;
2247
2248         val += strlen(name);                             /* skip prefix */
2249         while (val < buffer + buflen && isspace(*val)) /* skip separator */
2250                 val++;
2251
2252         *count = 0;
2253         while (val < buffer + buflen && isalnum(*val)) {
2254                 ++*count;
2255                 ++val;
2256         }
2257
2258         return val - *count;
2259 }
2260 EXPORT_SYMBOL(lprocfs_find_named_value);
2261
2262 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
2263                         const struct file_operations *seq_fops, void *data)
2264 {
2265         struct dentry *entry;
2266
2267         /* Disallow secretly (un)writable entries. */
2268         LASSERT((!seq_fops->write) == (!(mode & 0222)));
2269
2270         entry = debugfs_create_file(name, mode, parent, data, seq_fops);
2271         if (IS_ERR_OR_NULL(entry))
2272                 return entry ? PTR_ERR(entry) : -ENOMEM;
2273
2274         return 0;
2275 }
2276 EXPORT_SYMBOL_GPL(ldebugfs_seq_create);
2277
2278 int lprocfs_seq_create(struct proc_dir_entry *parent,
2279                        const char *name,
2280                        mode_t mode,
2281                        const struct file_operations *seq_fops,
2282                        void *data)
2283 {
2284         struct proc_dir_entry *entry;
2285         ENTRY;
2286
2287         /* Disallow secretly (un)writable entries. */
2288         LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2289
2290         entry = proc_create_data(name, mode, parent, seq_fops, data);
2291
2292         if (entry == NULL)
2293                 RETURN(-ENOMEM);
2294
2295         RETURN(0);
2296 }
2297 EXPORT_SYMBOL(lprocfs_seq_create);
2298
2299 int lprocfs_obd_seq_create(struct obd_device *dev,
2300                            const char *name,
2301                            mode_t mode,
2302                            const struct file_operations *seq_fops,
2303                            void *data)
2304 {
2305         return (lprocfs_seq_create(dev->obd_proc_entry, name,
2306                                    mode, seq_fops, data));
2307 }
2308 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2309
2310 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2311 {
2312         if (value >= OBD_HIST_MAX)
2313                 value = OBD_HIST_MAX - 1;
2314
2315         spin_lock(&oh->oh_lock);
2316         oh->oh_buckets[value]++;
2317         spin_unlock(&oh->oh_lock);
2318 }
2319 EXPORT_SYMBOL(lprocfs_oh_tally);
2320
2321 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2322 {
2323         unsigned int val = 0;
2324
2325         if (likely(value != 0))
2326                 val = min(fls(value - 1), OBD_HIST_MAX);
2327
2328         lprocfs_oh_tally(oh, val);
2329 }
2330 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2331
2332 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2333 {
2334         unsigned long ret = 0;
2335         int i;
2336
2337         for (i = 0; i < OBD_HIST_MAX; i++)
2338                 ret +=  oh->oh_buckets[i];
2339         return ret;
2340 }
2341 EXPORT_SYMBOL(lprocfs_oh_sum);
2342
2343 void lprocfs_oh_clear(struct obd_histogram *oh)
2344 {
2345         spin_lock(&oh->oh_lock);
2346         memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2347         spin_unlock(&oh->oh_lock);
2348 }
2349 EXPORT_SYMBOL(lprocfs_oh_clear);
2350
2351 ssize_t lustre_attr_show(struct kobject *kobj,
2352                          struct attribute *attr, char *buf)
2353 {
2354         struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2355
2356         return a->show ? a->show(kobj, attr, buf) : 0;
2357 }
2358 EXPORT_SYMBOL_GPL(lustre_attr_show);
2359
2360 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2361                           const char *buf, size_t len)
2362 {
2363         struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2364
2365         return a->store ? a->store(kobj, attr, buf, len) : len;
2366 }
2367 EXPORT_SYMBOL_GPL(lustre_attr_store);
2368
2369 const struct sysfs_ops lustre_sysfs_ops = {
2370         .show  = lustre_attr_show,
2371         .store = lustre_attr_store,
2372 };
2373 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2374
2375 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2376 {
2377         struct obd_device *dev = data;
2378         struct client_obd *cli = &dev->u.cli;
2379
2380         spin_lock(&cli->cl_loi_list_lock);
2381         seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2382         spin_unlock(&cli->cl_loi_list_lock);
2383         return 0;
2384 }
2385 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2386
2387 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2388                                                 const char __user *buffer,
2389                                                 size_t count, loff_t *off)
2390 {
2391         struct obd_device *dev =
2392                 ((struct seq_file *)file->private_data)->private;
2393         struct client_obd *cli = &dev->u.cli;
2394         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
2395         int chunk_mask, rc;
2396         __s64 val;
2397
2398         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
2399         if (rc)
2400                 return rc;
2401         if (val < 0)
2402                 return -ERANGE;
2403
2404         /* if the max_pages is specified in bytes, convert to pages */
2405         if (val >= ONE_MB_BRW_SIZE)
2406                 val >>= PAGE_SHIFT;
2407
2408         LPROCFS_CLIMP_CHECK(dev);
2409
2410         chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2411         /* max_pages_per_rpc must be chunk aligned */
2412         val = (val + ~chunk_mask) & chunk_mask;
2413         if (val == 0 || (ocd->ocd_brw_size != 0 &&
2414                          val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2415                 LPROCFS_CLIMP_EXIT(dev);
2416                 return -ERANGE;
2417         }
2418         spin_lock(&cli->cl_loi_list_lock);
2419         cli->cl_max_pages_per_rpc = val;
2420         client_adjust_max_dirty(cli);
2421         spin_unlock(&cli->cl_loi_list_lock);
2422
2423         LPROCFS_CLIMP_EXIT(dev);
2424         return count;
2425 }
2426 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2427
2428 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2429                            struct root_squash_info *squash, char *name)
2430 {
2431         int rc;
2432         char kernbuf[64], *tmp, *errmsg;
2433         unsigned long uid, gid;
2434         ENTRY;
2435
2436         if (count >= sizeof(kernbuf)) {
2437                 errmsg = "string too long";
2438                 GOTO(failed_noprint, rc = -EINVAL);
2439         }
2440         if (copy_from_user(kernbuf, buffer, count)) {
2441                 errmsg = "bad address";
2442                 GOTO(failed_noprint, rc = -EFAULT);
2443         }
2444         kernbuf[count] = '\0';
2445
2446         /* look for uid gid separator */
2447         tmp = strchr(kernbuf, ':');
2448         if (tmp == NULL) {
2449                 errmsg = "needs uid:gid format";
2450                 GOTO(failed, rc = -EINVAL);
2451         }
2452         *tmp = '\0';
2453         tmp++;
2454
2455         /* parse uid */
2456         if (kstrtoul(kernbuf, 0, &uid) != 0) {
2457                 errmsg = "bad uid";
2458                 GOTO(failed, rc = -EINVAL);
2459         }
2460
2461         /* parse gid */
2462         if (kstrtoul(tmp, 0, &gid) != 0) {
2463                 errmsg = "bad gid";
2464                 GOTO(failed, rc = -EINVAL);
2465         }
2466
2467         squash->rsi_uid = uid;
2468         squash->rsi_gid = gid;
2469
2470         LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2471                       name, squash->rsi_uid, squash->rsi_gid);
2472         RETURN(count);
2473
2474 failed:
2475         if (tmp != NULL) {
2476                 tmp--;
2477                 *tmp = ':';
2478         }
2479         CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2480               name, kernbuf, errmsg, rc);
2481         RETURN(rc);
2482 failed_noprint:
2483         CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2484               name, errmsg, rc);
2485         RETURN(rc);
2486 }
2487 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2488
2489
2490 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2491                              struct root_squash_info *squash, char *name)
2492 {
2493         int rc;
2494         char *kernbuf = NULL;
2495         char *errmsg;
2496         struct list_head tmp;
2497         int len = count;
2498         ENTRY;
2499
2500         if (count > 4096) {
2501                 errmsg = "string too long";
2502                 GOTO(failed, rc = -EINVAL);
2503         }
2504
2505         OBD_ALLOC(kernbuf, count + 1);
2506         if (kernbuf == NULL) {
2507                 errmsg = "no memory";
2508                 GOTO(failed, rc = -ENOMEM);
2509         }
2510         if (copy_from_user(kernbuf, buffer, count)) {
2511                 errmsg = "bad address";
2512                 GOTO(failed, rc = -EFAULT);
2513         }
2514         kernbuf[count] = '\0';
2515
2516         if (count > 0 && kernbuf[count - 1] == '\n')
2517                 len = count - 1;
2518
2519         if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2520             (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2521                 /* empty string is special case */
2522                 down_write(&squash->rsi_sem);
2523                 if (!list_empty(&squash->rsi_nosquash_nids))
2524                         cfs_free_nidlist(&squash->rsi_nosquash_nids);
2525                 up_write(&squash->rsi_sem);
2526                 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2527                 OBD_FREE(kernbuf, count + 1);
2528                 RETURN(count);
2529         }
2530
2531         INIT_LIST_HEAD(&tmp);
2532         if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2533                 errmsg = "can't parse";
2534                 GOTO(failed, rc = -EINVAL);
2535         }
2536         LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2537                       name, kernbuf);
2538         OBD_FREE(kernbuf, count + 1);
2539         kernbuf = NULL;
2540
2541         down_write(&squash->rsi_sem);
2542         if (!list_empty(&squash->rsi_nosquash_nids))
2543                 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2544         list_splice(&tmp, &squash->rsi_nosquash_nids);
2545         up_write(&squash->rsi_sem);
2546
2547         RETURN(count);
2548
2549 failed:
2550         if (kernbuf) {
2551                 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2552                       name, kernbuf, errmsg, rc);
2553                 OBD_FREE(kernbuf, count + 1);
2554         } else {
2555                 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2556                       name, errmsg, rc);
2557         }
2558         RETURN(rc);
2559 }
2560 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2561
2562 #endif /* CONFIG_PROC_FS*/