2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #ifdef DEBUG_SUBSYSTEM
30 #undef DEBUG_SUBSYSTEM
33 #define DEBUG_SUBSYSTEM S_PROC
36 static unsigned long table_min
= 0;
37 static unsigned long table_max
= ~0;
41 static struct ctl_table_header
*spl_header
= NULL
;
42 #endif /* CONFIG_SYSCTL */
44 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
45 static struct proc_dir_entry
*proc_spl
= NULL
;
47 static struct proc_dir_entry
*proc_spl_mutex
= NULL
;
48 static struct proc_dir_entry
*proc_spl_mutex_stats
= NULL
;
49 #endif /* DEBUG_MUTEX */
51 static struct proc_dir_entry
*proc_spl_kmem
= NULL
;
52 static struct proc_dir_entry
*proc_spl_kmem_slab
= NULL
;
53 #endif /* DEBUG_KMEM */
55 struct proc_dir_entry
*proc_spl_kstat
= NULL
;
56 #endif /* DEBUG_KSTAT */
57 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
59 #ifdef HAVE_CTL_UNNUMBERED
61 #define CTL_SPL CTL_UNNUMBERED
62 #define CTL_SPL_DEBUG CTL_UNNUMBERED
63 #define CTL_SPL_VM CTL_UNNUMBERED
64 #define CTL_SPL_MUTEX CTL_UNNUMBERED
65 #define CTL_SPL_KMEM CTL_UNNUMBERED
66 #define CTL_SPL_KSTAT CTL_UNNUMBERED
68 #define CTL_VERSION CTL_UNNUMBERED /* Version */
69 #define CTL_HOSTID CTL_UNNUMBERED /* Host id by /usr/bin/hostid */
70 #define CTL_HW_SERIAL CTL_UNNUMBERED /* HW serial number by hostid */
72 #define CTL_DEBUG_SUBSYS CTL_UNNUMBERED /* Debug subsystem */
73 #define CTL_DEBUG_MASK CTL_UNNUMBERED /* Debug mask */
74 #define CTL_DEBUG_PRINTK CTL_UNNUMBERED /* All messages to console */
75 #define CTL_DEBUG_MB CTL_UNNUMBERED /* Debug buffer size */
76 #define CTL_DEBUG_BINARY CTL_UNNUMBERED /* Binary data in buffer */
77 #define CTL_DEBUG_CATASTROPHE CTL_UNNUMBERED /* Set if BUG'd or panic'd */
78 #define CTL_DEBUG_PANIC_ON_BUG CTL_UNNUMBERED /* Should panic on BUG */
79 #define CTL_DEBUG_PATH CTL_UNNUMBERED /* Dump log location */
80 #define CTL_DEBUG_DUMP CTL_UNNUMBERED /* Dump debug buffer to file */
81 #define CTL_DEBUG_FORCE_BUG CTL_UNNUMBERED /* Hook to force a BUG */
82 #define CTL_DEBUG_STACK_SIZE CTL_UNNUMBERED /* Max observed stack size */
84 #define CTL_CONSOLE_RATELIMIT CTL_UNNUMBERED /* Ratelimit console messages */
85 #define CTL_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED /* Max delay skip messages */
86 #define CTL_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED /* Init delay skip messages */
87 #define CTL_CONSOLE_BACKOFF CTL_UNNUMBERED /* Delay increase factor */
89 #define CTL_VM_MINFREE CTL_UNNUMBERED /* Minimum free memory */
90 #define CTL_VM_DESFREE CTL_UNNUMBERED /* Desired free memory */
91 #define CTL_VM_LOTSFREE CTL_UNNUMBERED /* Lots of free memory */
92 #define CTL_VM_NEEDFREE CTL_UNNUMBERED /* Need free memory */
93 #define CTL_VM_SWAPFS_MINFREE CTL_UNNUMBERED /* Minimum swapfs memory */
94 #define CTL_VM_SWAPFS_RESERVE CTL_UNNUMBERED /* Reserved swapfs memory */
95 #define CTL_VM_AVAILRMEM CTL_UNNUMBERED /* Easily available memory */
96 #define CTL_VM_FREEMEM CTL_UNNUMBERED /* Free memory */
97 #define CTL_VM_PHYSMEM CTL_UNNUMBERED /* Total physical memory */
100 #define CTL_KMEM_KMEMUSED CTL_UNNUMBERED /* Alloc'd kmem bytes */
101 #define CTL_KMEM_KMEMMAX CTL_UNNUMBERED /* Max alloc'd by kmem bytes */
102 #define CTL_KMEM_VMEMUSED CTL_UNNUMBERED /* Alloc'd vmem bytes */
103 #define CTL_KMEM_VMEMMAX CTL_UNNUMBERED /* Max alloc'd by vmem bytes */
104 #define CTL_KMEM_ALLOC_FAILED CTL_UNNUMBERED /* Cache allocations failed */
107 #define CTL_MUTEX_STATS CTL_UNNUMBERED /* Global mutex statistics */
108 #define CTL_MUTEX_STATS_PER CTL_UNNUMBERED /* Per mutex statistics */
109 #define CTL_MUTEX_SPIN_MAX CTL_UNNUMBERED /* Max mutex spin iterations */
111 #else /* HAVE_CTL_UNNUMBERED */
115 CTL_SPL_DEBUG
= 0x88,
117 CTL_SPL_MUTEX
= 0x90,
119 CTL_SPL_KSTAT
= 0x92,
123 CTL_VERSION
= 1, /* Version */
124 CTL_HOSTID
, /* Host id reported by /usr/bin/hostid */
125 CTL_HW_SERIAL
, /* Hardware serial number from hostid */
127 CTL_DEBUG_SUBSYS
, /* Debug subsystem */
128 CTL_DEBUG_MASK
, /* Debug mask */
129 CTL_DEBUG_PRINTK
, /* Force all messages to console */
130 CTL_DEBUG_MB
, /* Debug buffer size */
131 CTL_DEBUG_BINARY
, /* Include binary data in buffer */
132 CTL_DEBUG_CATASTROPHE
, /* Set if we have BUG'd or panic'd */
133 CTL_DEBUG_PANIC_ON_BUG
, /* Set if we should panic on BUG */
134 CTL_DEBUG_PATH
, /* Dump log location */
135 CTL_DEBUG_DUMP
, /* Dump debug buffer to file */
136 CTL_DEBUG_FORCE_BUG
, /* Hook to force a BUG */
137 CTL_DEBUG_STACK_SIZE
, /* Max observed stack size */
139 CTL_CONSOLE_RATELIMIT
, /* Ratelimit console messages */
140 CTL_CONSOLE_MAX_DELAY_CS
, /* Max delay which we skip messages */
141 CTL_CONSOLE_MIN_DELAY_CS
, /* Init delay which we skip messages */
142 CTL_CONSOLE_BACKOFF
, /* Delay increase factor */
144 CTL_VM_MINFREE
, /* Minimum free memory threshold */
145 CTL_VM_DESFREE
, /* Desired free memory threshold */
146 CTL_VM_LOTSFREE
, /* Lots of free memory threshold */
147 CTL_VM_NEEDFREE
, /* Need free memory deficit */
148 CTL_VM_SWAPFS_MINFREE
, /* Minimum swapfs memory */
149 CTL_VM_SWAPFS_RESERVE
, /* Reserved swapfs memory */
150 CTL_VM_AVAILRMEM
, /* Easily available memory */
151 CTL_VM_FREEMEM
, /* Free memory */
152 CTL_VM_PHYSMEM
, /* Total physical memory */
155 CTL_KMEM_KMEMUSED
, /* Alloc'd kmem bytes */
156 CTL_KMEM_KMEMMAX
, /* Max alloc'd by kmem bytes */
157 CTL_KMEM_VMEMUSED
, /* Alloc'd vmem bytes */
158 CTL_KMEM_VMEMMAX
, /* Max alloc'd by vmem bytes */
161 CTL_MUTEX_STATS
, /* Global mutex statistics */
162 CTL_MUTEX_STATS_PER
, /* Per mutex statistics */
163 CTL_MUTEX_SPIN_MAX
, /* Maximum mutex spin iterations */
165 #endif /* HAVE_CTL_UNNUMBERED */
168 proc_copyin_string(char *kbuffer
, int kbuffer_size
,
169 const char *ubuffer
, int ubuffer_size
)
173 if (ubuffer_size
> kbuffer_size
)
176 if (copy_from_user((void *)kbuffer
, (void *)ubuffer
, ubuffer_size
))
179 /* strip trailing whitespace */
180 size
= strnlen(kbuffer
, ubuffer_size
);
182 if (!isspace(kbuffer
[size
]))
189 /* no space to terminate */
190 if (size
== kbuffer_size
)
193 kbuffer
[size
+ 1] = 0;
198 proc_copyout_string(char *ubuffer
, int ubuffer_size
,
199 const char *kbuffer
, char *append
)
201 /* NB if 'append' != NULL, it's a single character to append to the
202 * copied out string - usually "\n", for /proc entries and
203 * (i.e. a terminating zero byte) for sysctl entries
205 int size
= MIN(strlen(kbuffer
), ubuffer_size
);
207 if (copy_to_user(ubuffer
, kbuffer
, size
))
210 if (append
!= NULL
&& size
< ubuffer_size
) {
211 if (copy_to_user(ubuffer
+ size
, append
, 1))
221 proc_dobitmasks(struct ctl_table
*table
, int write
, struct file
*filp
,
222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
224 unsigned long *mask
= table
->data
;
225 int is_subsys
= (mask
== &spl_debug_subsys
) ? 1 : 0;
226 int is_printk
= (mask
== &spl_debug_printk
) ? 1 : 0;
231 str
= kmem_alloc(size
, KM_SLEEP
);
236 rc
= proc_copyin_string(str
, size
, buffer
, *lenp
);
240 rc
= spl_debug_str2mask(mask
, str
, is_subsys
);
241 /* Always print BUG/ASSERT to console, so keep this mask */
247 rc
= spl_debug_mask2str(str
, size
, *mask
, is_subsys
);
251 rc
= proc_copyout_string(buffer
, *lenp
,
259 kmem_free(str
, size
);
264 proc_debug_mb(struct ctl_table
*table
, int write
, struct file
*filp
,
265 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
272 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
276 rc
= spl_debug_set_mb(simple_strtoul(str
, NULL
, 0));
279 len
= snprintf(str
, sizeof(str
), "%d", spl_debug_get_mb());
283 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
295 proc_dump_kernel(struct ctl_table
*table
, int write
, struct file
*filp
,
296 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
301 spl_debug_dumplog(0);
311 proc_force_bug(struct ctl_table
*table
, int write
, struct file
*filp
,
312 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
317 CERROR("Crashing due to forced SBUG\n");
328 proc_console_max_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
329 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
331 int rc
, max_delay_cs
;
332 struct ctl_table dummy
= *table
;
336 dummy
.data
= &max_delay_cs
;
337 dummy
.proc_handler
= &proc_dointvec
;
341 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
345 if (max_delay_cs
<= 0)
348 d
= (max_delay_cs
* HZ
) / 100;
349 if (d
== 0 || d
< spl_console_min_delay
)
352 spl_console_max_delay
= d
;
354 max_delay_cs
= (spl_console_max_delay
* 100) / HZ
;
355 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
362 proc_console_min_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
363 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
365 int rc
, min_delay_cs
;
366 struct ctl_table dummy
= *table
;
370 dummy
.data
= &min_delay_cs
;
371 dummy
.proc_handler
= &proc_dointvec
;
375 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
379 if (min_delay_cs
<= 0)
382 d
= (min_delay_cs
* HZ
) / 100;
383 if (d
== 0 || d
> spl_console_max_delay
)
386 spl_console_min_delay
= d
;
388 min_delay_cs
= (spl_console_min_delay
* 100) / HZ
;
389 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
396 proc_console_backoff(struct ctl_table
*table
, int write
, struct file
*filp
,
397 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
400 struct ctl_table dummy
= *table
;
403 dummy
.data
= &backoff
;
404 dummy
.proc_handler
= &proc_dointvec
;
408 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
415 spl_console_backoff
= backoff
;
417 backoff
= spl_console_backoff
;
418 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
426 proc_doatomic64(struct ctl_table
*table
, int write
, struct file
*filp
,
427 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
430 unsigned long min
= 0, max
= ~0, val
;
431 struct ctl_table dummy
= *table
;
435 dummy
.proc_handler
= &proc_dointvec
;
442 val
= atomic64_read((atomic64_t
*)table
->data
);
443 rc
= proc_doulongvec_minmax(&dummy
, write
, filp
,
449 #endif /* DEBUG_KMEM */
452 proc_dohostid(struct ctl_table
*table
, int write
, struct file
*filp
,
453 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
461 /* We can't use proc_doulongvec_minmax() in the write
462 * case hear because hostid while a hex value has no
463 * leading 0x which confuses the helper function. */
464 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
468 val
= simple_strtol(str
, &end
, 16);
472 spl_hostid
= (long)val
;
473 (void)snprintf(hw_serial
, HW_HOSTID_LEN
-1, "%u",
474 (val
>= 0) ? val
: -val
);
477 len
= snprintf(str
, sizeof(str
), "%lx", spl_hostid
);
481 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
493 proc_doavailrmem(struct ctl_table
*table
, int write
, struct file
*filp
,
494 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
503 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)availrmem
);
507 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
519 proc_dofreemem(struct ctl_table
*table
, int write
, struct file
*filp
,
520 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
529 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)freemem
);
533 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
546 mutex_seq_show_headers(struct seq_file
*f
)
548 seq_printf(f
, "%-36s %-4s %-16s\t"
549 "e_tot\te_nh\te_sp\te_sl\tte_tot\tte_nh\n",
550 "name", "type", "owner");
554 mutex_seq_show(struct seq_file
*f
, void *p
)
560 ASSERT(mp
->km_magic
== KM_MAGIC
);
562 switch (mp
->km_type
) {
563 case MUTEX_DEFAULT
: t
= 'D'; break;
564 case MUTEX_SPIN
: t
= 'S'; break;
565 case MUTEX_ADAPTIVE
: t
= 'A'; break;
569 seq_printf(f
, "%-36s %c ", mp
->km_name
, t
);
571 seq_printf(f
, "%p\t", mp
->km_owner
);
573 seq_printf(f
, "%-16s\t", "<not held>");
575 for (i
= 0; i
< MUTEX_STATS_SIZE
; i
++)
576 seq_printf(f
, "%d%c", mp
->km_stats
[i
],
577 (i
+ 1 == MUTEX_STATS_SIZE
) ? '\n' : '\t');
583 mutex_seq_start(struct seq_file
*f
, loff_t
*pos
)
589 spin_lock(&mutex_stats_lock
);
591 mutex_seq_show_headers(f
);
593 p
= mutex_stats_list
.next
;
596 if (p
== &mutex_stats_list
)
600 RETURN(list_entry(p
, kmutex_t
, km_list
));
604 mutex_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
610 RETURN((mp
->km_list
.next
== &mutex_stats_list
) ?
611 NULL
: list_entry(mp
->km_list
.next
, kmutex_t
, km_list
));
615 mutex_seq_stop(struct seq_file
*f
, void *v
)
617 spin_unlock(&mutex_stats_lock
);
620 static struct seq_operations mutex_seq_ops
= {
621 .show
= mutex_seq_show
,
622 .start
= mutex_seq_start
,
623 .next
= mutex_seq_next
,
624 .stop
= mutex_seq_stop
,
628 proc_mutex_open(struct inode
*inode
, struct file
*filp
)
630 return seq_open(filp
, &mutex_seq_ops
);
633 static struct file_operations proc_mutex_operations
= {
634 .open
= proc_mutex_open
,
637 .release
= seq_release
,
639 #endif /* DEBUG_MUTEX */
643 slab_seq_show_headers(struct seq_file
*f
)
645 seq_printf(f
, "%-36s\n", "name");
649 slab_seq_show(struct seq_file
*f
, void *p
)
651 spl_kmem_cache_t
*skc
= p
;
653 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
655 spin_lock(&skc
->skc_lock
);
656 seq_printf(f
, "%-36s ", skc
->skc_name
);
657 seq_printf(f
, "%u %u %u - %lu %lu %lu - %lu %lu %lu - %lu %lu %lu\n",
658 (unsigned)skc
->skc_obj_size
,
659 (unsigned)skc
->skc_slab_objs
,
660 (unsigned)skc
->skc_slab_size
,
661 (long unsigned)skc
->skc_slab_fail
,
662 (long unsigned)skc
->skc_slab_create
,
663 (long unsigned)skc
->skc_slab_destroy
,
664 (long unsigned)skc
->skc_slab_total
,
665 (long unsigned)skc
->skc_slab_alloc
,
666 (long unsigned)skc
->skc_slab_max
,
667 (long unsigned)skc
->skc_obj_total
,
668 (long unsigned)skc
->skc_obj_alloc
,
669 (long unsigned)skc
->skc_obj_max
);
671 spin_unlock(&skc
->skc_lock
);
677 slab_seq_start(struct seq_file
*f
, loff_t
*pos
)
683 down_read(&spl_kmem_cache_sem
);
685 slab_seq_show_headers(f
);
687 p
= spl_kmem_cache_list
.next
;
690 if (p
== &spl_kmem_cache_list
)
694 RETURN(list_entry(p
, spl_kmem_cache_t
, skc_list
));
698 slab_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
700 spl_kmem_cache_t
*skc
= p
;
704 RETURN((skc
->skc_list
.next
== &spl_kmem_cache_list
) ?
705 NULL
: list_entry(skc
->skc_list
.next
, spl_kmem_cache_t
, skc_list
));
709 slab_seq_stop(struct seq_file
*f
, void *v
)
711 up_read(&spl_kmem_cache_sem
);
714 static struct seq_operations slab_seq_ops
= {
715 .show
= slab_seq_show
,
716 .start
= slab_seq_start
,
717 .next
= slab_seq_next
,
718 .stop
= slab_seq_stop
,
722 proc_slab_open(struct inode
*inode
, struct file
*filp
)
724 return seq_open(filp
, &slab_seq_ops
);
727 static struct file_operations proc_slab_operations
= {
728 .open
= proc_slab_open
,
731 .release
= seq_release
,
733 #endif /* DEBUG_KMEM */
735 static struct ctl_table spl_debug_table
[] = {
737 .ctl_name
= CTL_DEBUG_SUBSYS
,
738 .procname
= "subsystem",
739 .data
= &spl_debug_subsys
,
740 .maxlen
= sizeof(unsigned long),
742 .proc_handler
= &proc_dobitmasks
745 .ctl_name
= CTL_DEBUG_MASK
,
747 .data
= &spl_debug_mask
,
748 .maxlen
= sizeof(unsigned long),
750 .proc_handler
= &proc_dobitmasks
753 .ctl_name
= CTL_DEBUG_PRINTK
,
754 .procname
= "printk",
755 .data
= &spl_debug_printk
,
756 .maxlen
= sizeof(unsigned long),
758 .proc_handler
= &proc_dobitmasks
761 .ctl_name
= CTL_DEBUG_MB
,
764 .proc_handler
= &proc_debug_mb
,
767 .ctl_name
= CTL_DEBUG_BINARY
,
768 .procname
= "binary",
769 .data
= &spl_debug_binary
,
770 .maxlen
= sizeof(int),
772 .proc_handler
= &proc_dointvec
,
775 .ctl_name
= CTL_DEBUG_CATASTROPHE
,
776 .procname
= "catastrophe",
777 .data
= &spl_debug_catastrophe
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= &proc_dointvec
,
783 .ctl_name
= CTL_DEBUG_PANIC_ON_BUG
,
784 .procname
= "panic_on_bug",
785 .data
= &spl_debug_panic_on_bug
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= &proc_dointvec
791 .ctl_name
= CTL_DEBUG_PATH
,
793 .data
= spl_debug_file_path
,
794 .maxlen
= sizeof(spl_debug_file_path
),
796 .proc_handler
= &proc_dostring
,
799 .ctl_name
= CTL_DEBUG_DUMP
,
802 .proc_handler
= &proc_dump_kernel
,
804 { .ctl_name
= CTL_DEBUG_FORCE_BUG
,
805 .procname
= "force_bug",
807 .proc_handler
= &proc_force_bug
,
810 .ctl_name
= CTL_CONSOLE_RATELIMIT
,
811 .procname
= "console_ratelimit",
812 .data
= &spl_console_ratelimit
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= &proc_dointvec
,
818 .ctl_name
= CTL_CONSOLE_MAX_DELAY_CS
,
819 .procname
= "console_max_delay_centisecs",
820 .maxlen
= sizeof(int),
822 .proc_handler
= &proc_console_max_delay_cs
,
825 .ctl_name
= CTL_CONSOLE_MIN_DELAY_CS
,
826 .procname
= "console_min_delay_centisecs",
827 .maxlen
= sizeof(int),
829 .proc_handler
= &proc_console_min_delay_cs
,
832 .ctl_name
= CTL_CONSOLE_BACKOFF
,
833 .procname
= "console_backoff",
834 .maxlen
= sizeof(int),
836 .proc_handler
= &proc_console_backoff
,
839 .ctl_name
= CTL_DEBUG_STACK_SIZE
,
840 .procname
= "stack_max",
841 .data
= &spl_debug_stack
,
842 .maxlen
= sizeof(int),
844 .proc_handler
= &proc_dointvec
,
849 static struct ctl_table spl_vm_table
[] = {
851 .ctl_name
= CTL_VM_MINFREE
,
852 .procname
= "minfree",
854 .maxlen
= sizeof(int),
856 .proc_handler
= &proc_dointvec
,
859 .ctl_name
= CTL_VM_DESFREE
,
860 .procname
= "desfree",
862 .maxlen
= sizeof(int),
864 .proc_handler
= &proc_dointvec
,
867 .ctl_name
= CTL_VM_LOTSFREE
,
868 .procname
= "lotsfree",
870 .maxlen
= sizeof(int),
872 .proc_handler
= &proc_dointvec
,
875 .ctl_name
= CTL_VM_NEEDFREE
,
876 .procname
= "needfree",
878 .maxlen
= sizeof(int),
880 .proc_handler
= &proc_dointvec
,
883 .ctl_name
= CTL_VM_SWAPFS_MINFREE
,
884 .procname
= "swapfs_minfree",
885 .data
= &swapfs_minfree
,
886 .maxlen
= sizeof(int),
888 .proc_handler
= &proc_dointvec
,
891 .ctl_name
= CTL_VM_SWAPFS_RESERVE
,
892 .procname
= "swapfs_reserve",
893 .data
= &swapfs_reserve
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= &proc_dointvec
,
899 .ctl_name
= CTL_VM_AVAILRMEM
,
900 .procname
= "availrmem",
902 .proc_handler
= &proc_doavailrmem
,
905 .ctl_name
= CTL_VM_FREEMEM
,
906 .procname
= "freemem",
908 .maxlen
= sizeof(int),
910 .proc_handler
= &proc_dofreemem
,
913 .ctl_name
= CTL_VM_PHYSMEM
,
914 .procname
= "physmem",
916 .maxlen
= sizeof(int),
918 .proc_handler
= &proc_dointvec
,
924 static struct ctl_table spl_mutex_table
[] = {
926 .ctl_name
= CTL_MUTEX_STATS
,
928 .data
= &mutex_stats
,
929 .maxlen
= sizeof(int) * MUTEX_STATS_SIZE
,
931 .proc_handler
= &proc_dointvec
,
934 .ctl_name
= CTL_MUTEX_SPIN_MAX
,
935 .procname
= "spin_max",
936 .data
= &mutex_spin_max
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= &proc_dointvec
,
943 #endif /* DEBUG_MUTEX */
946 static struct ctl_table spl_kmem_table
[] = {
948 .ctl_name
= CTL_KMEM_KMEMUSED
,
949 .procname
= "kmem_used",
950 .data
= &kmem_alloc_used
,
951 .maxlen
= sizeof(atomic64_t
),
953 .proc_handler
= &proc_doatomic64
,
956 .ctl_name
= CTL_KMEM_KMEMMAX
,
957 .procname
= "kmem_max",
958 .data
= &kmem_alloc_max
,
959 .maxlen
= sizeof(unsigned long),
960 .extra1
= &table_min
,
961 .extra2
= &table_max
,
963 .proc_handler
= &proc_doulongvec_minmax
,
966 .ctl_name
= CTL_KMEM_VMEMUSED
,
967 .procname
= "vmem_used",
968 .data
= &vmem_alloc_used
,
969 .maxlen
= sizeof(atomic64_t
),
971 .proc_handler
= &proc_doatomic64
,
974 .ctl_name
= CTL_KMEM_VMEMMAX
,
975 .procname
= "vmem_max",
976 .data
= &vmem_alloc_max
,
977 .maxlen
= sizeof(unsigned long),
978 .extra1
= &table_min
,
979 .extra2
= &table_max
,
981 .proc_handler
= &proc_doulongvec_minmax
,
985 #endif /* DEBUG_KMEM */
988 static struct ctl_table spl_kstat_table
[] = {
991 #endif /* DEBUG_KSTAT */
993 static struct ctl_table spl_table
[] = {
994 /* NB No .strategy entries have been provided since
995 * sysctl(8) prefers to go via /proc for portability.
998 .ctl_name
= CTL_VERSION
,
999 .procname
= "version",
1000 .data
= spl_version
,
1001 .maxlen
= sizeof(spl_version
),
1003 .proc_handler
= &proc_dostring
,
1006 .ctl_name
= CTL_HOSTID
,
1007 .procname
= "hostid",
1008 .data
= &spl_hostid
,
1009 .maxlen
= sizeof(unsigned long),
1011 .proc_handler
= &proc_dohostid
,
1014 .ctl_name
= CTL_HW_SERIAL
,
1015 .procname
= "hw_serial",
1017 .maxlen
= sizeof(hw_serial
),
1019 .proc_handler
= &proc_dostring
,
1022 .ctl_name
= CTL_SPL_DEBUG
,
1023 .procname
= "debug",
1025 .child
= spl_debug_table
,
1028 .ctl_name
= CTL_SPL_VM
,
1031 .child
= spl_vm_table
,
1035 .ctl_name
= CTL_SPL_MUTEX
,
1036 .procname
= "mutex",
1038 .child
= spl_mutex_table
,
1043 .ctl_name
= CTL_SPL_KMEM
,
1046 .child
= spl_kmem_table
,
1051 .ctl_name
= CTL_SPL_KSTAT
,
1052 .procname
= "kstat",
1054 .child
= spl_kstat_table
,
1060 static struct ctl_table spl_dir
[] = {
1062 .ctl_name
= CTL_SPL
,
1070 static struct ctl_table spl_root
[] = {
1072 .ctl_name
= CTL_KERN
,
1073 .procname
= "kernel",
1081 proc_dir_entry_match(int len
, const char *name
, struct proc_dir_entry
*de
)
1083 if (de
->namelen
!= len
)
1086 return !memcmp(name
, de
->name
, len
);
1089 struct proc_dir_entry
*
1090 proc_dir_entry_find(struct proc_dir_entry
*root
, const char *str
)
1092 struct proc_dir_entry
*de
;
1094 for (de
= root
->subdir
; de
; de
= de
->next
)
1095 if (proc_dir_entry_match(strlen(str
), str
, de
))
1102 proc_dir_entries(struct proc_dir_entry
*root
)
1104 struct proc_dir_entry
*de
;
1107 for (de
= root
->subdir
; de
; de
= de
->next
)
1119 #ifdef CONFIG_SYSCTL
1120 spl_header
= spl_register_sysctl_table(spl_root
, 0);
1121 if (spl_header
== NULL
)
1123 #endif /* CONFIG_SYSCTL */
1125 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1126 proc_spl
= proc_mkdir("spl", NULL
);
1127 if (proc_spl
== NULL
)
1128 GOTO(out
, rc
= -EUNATCH
);
1131 proc_spl_mutex
= proc_mkdir("mutex", proc_spl
);
1132 if (proc_spl_mutex
== NULL
)
1133 GOTO(out
, rc
= -EUNATCH
);
1135 proc_spl_mutex_stats
= create_proc_entry("stats_per", 0444,
1137 if (proc_spl_mutex_stats
== NULL
)
1138 GOTO(out
, rc
= -EUNATCH
);
1140 proc_spl_mutex_stats
->proc_fops
= &proc_mutex_operations
;
1141 #endif /* DEBUG_MUTEX */
1144 proc_spl_kmem
= proc_mkdir("kmem", proc_spl
);
1145 if (proc_spl_kmem
== NULL
)
1146 GOTO(out
, rc
= -EUNATCH
);
1148 proc_spl_kmem_slab
= create_proc_entry("slab", 0444, proc_spl_kmem
);
1149 if (proc_spl_kmem_slab
== NULL
)
1150 GOTO(out
, rc
= -EUNATCH
);
1152 proc_spl_kmem_slab
->proc_fops
= &proc_slab_operations
;
1153 #endif /* DEBUG_KMEM */
1156 proc_spl_kstat
= proc_mkdir("kstat", proc_spl
);
1157 if (proc_spl_kstat
== NULL
)
1158 GOTO(out
, rc
= -EUNATCH
);
1159 #endif /* DEBUG_KSTAT */
1163 remove_proc_entry("kstat", proc_spl
);
1165 remove_proc_entry("slab", proc_spl_kmem
);
1167 remove_proc_entry("kmem", proc_spl
);
1169 remove_proc_entry("stats_per", proc_spl_mutex
);
1171 remove_proc_entry("mutex", proc_spl
);
1172 remove_proc_entry("spl", NULL
);
1173 #ifdef CONFIG_SYSCTL
1174 spl_unregister_sysctl_table(spl_header
);
1175 #endif /* CONFIG_SYSCTL */
1177 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1187 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1188 remove_proc_entry("kstat", proc_spl
);
1190 remove_proc_entry("slab", proc_spl_kmem
);
1192 remove_proc_entry("kmem", proc_spl
);
1194 remove_proc_entry("stats_per", proc_spl_mutex
);
1196 remove_proc_entry("mutex", proc_spl
);
1197 remove_proc_entry("spl", NULL
);
1198 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1200 #ifdef CONFIG_SYSCTL
1201 ASSERT(spl_header
!= NULL
);
1202 spl_unregister_sysctl_table(spl_header
);
1203 #endif /* CONFIG_SYSCTL */