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
, 11, "%u", (val
>= 0) ? val
: -val
);
476 len
= snprintf(str
, sizeof(str
), "%lx", spl_hostid
);
480 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
492 proc_doavailrmem(struct ctl_table
*table
, int write
, struct file
*filp
,
493 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
502 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)availrmem
);
506 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
518 proc_dofreemem(struct ctl_table
*table
, int write
, struct file
*filp
,
519 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
528 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)freemem
);
532 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
545 mutex_seq_show_headers(struct seq_file
*f
)
547 seq_printf(f
, "%-36s %-4s %-16s\t"
548 "e_tot\te_nh\te_sp\te_sl\tte_tot\tte_nh\n",
549 "name", "type", "owner");
553 mutex_seq_show(struct seq_file
*f
, void *p
)
559 ASSERT(mp
->km_magic
== KM_MAGIC
);
561 switch (mp
->km_type
) {
562 case MUTEX_DEFAULT
: t
= 'D'; break;
563 case MUTEX_SPIN
: t
= 'S'; break;
564 case MUTEX_ADAPTIVE
: t
= 'A'; break;
568 seq_printf(f
, "%-36s %c ", mp
->km_name
, t
);
570 seq_printf(f
, "%p\t", mp
->km_owner
);
572 seq_printf(f
, "%-16s\t", "<not held>");
574 for (i
= 0; i
< MUTEX_STATS_SIZE
; i
++)
575 seq_printf(f
, "%d%c", mp
->km_stats
[i
],
576 (i
+ 1 == MUTEX_STATS_SIZE
) ? '\n' : '\t');
582 mutex_seq_start(struct seq_file
*f
, loff_t
*pos
)
588 spin_lock(&mutex_stats_lock
);
590 mutex_seq_show_headers(f
);
592 p
= mutex_stats_list
.next
;
595 if (p
== &mutex_stats_list
)
599 RETURN(list_entry(p
, kmutex_t
, km_list
));
603 mutex_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
609 RETURN((mp
->km_list
.next
== &mutex_stats_list
) ?
610 NULL
: list_entry(mp
->km_list
.next
, kmutex_t
, km_list
));
614 mutex_seq_stop(struct seq_file
*f
, void *v
)
616 spin_unlock(&mutex_stats_lock
);
619 static struct seq_operations mutex_seq_ops
= {
620 .show
= mutex_seq_show
,
621 .start
= mutex_seq_start
,
622 .next
= mutex_seq_next
,
623 .stop
= mutex_seq_stop
,
627 proc_mutex_open(struct inode
*inode
, struct file
*filp
)
629 return seq_open(filp
, &mutex_seq_ops
);
632 static struct file_operations proc_mutex_operations
= {
633 .open
= proc_mutex_open
,
636 .release
= seq_release
,
638 #endif /* DEBUG_MUTEX */
642 slab_seq_show_headers(struct seq_file
*f
)
644 seq_printf(f
, "%-36s\n", "name");
648 slab_seq_show(struct seq_file
*f
, void *p
)
650 spl_kmem_cache_t
*skc
= p
;
652 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
654 spin_lock(&skc
->skc_lock
);
655 seq_printf(f
, "%-36s ", skc
->skc_name
);
656 seq_printf(f
, "%u %u %u - %lu %lu %lu - %lu %lu %lu - %lu %lu %lu\n",
657 (unsigned)skc
->skc_obj_size
,
658 (unsigned)skc
->skc_slab_objs
,
659 (unsigned)skc
->skc_slab_size
,
660 (long unsigned)skc
->skc_slab_fail
,
661 (long unsigned)skc
->skc_slab_create
,
662 (long unsigned)skc
->skc_slab_destroy
,
663 (long unsigned)skc
->skc_slab_total
,
664 (long unsigned)skc
->skc_slab_alloc
,
665 (long unsigned)skc
->skc_slab_max
,
666 (long unsigned)skc
->skc_obj_total
,
667 (long unsigned)skc
->skc_obj_alloc
,
668 (long unsigned)skc
->skc_obj_max
);
670 spin_unlock(&skc
->skc_lock
);
676 slab_seq_start(struct seq_file
*f
, loff_t
*pos
)
682 down_read(&spl_kmem_cache_sem
);
684 slab_seq_show_headers(f
);
686 p
= spl_kmem_cache_list
.next
;
689 if (p
== &spl_kmem_cache_list
)
693 RETURN(list_entry(p
, spl_kmem_cache_t
, skc_list
));
697 slab_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
699 spl_kmem_cache_t
*skc
= p
;
703 RETURN((skc
->skc_list
.next
== &spl_kmem_cache_list
) ?
704 NULL
: list_entry(skc
->skc_list
.next
, spl_kmem_cache_t
, skc_list
));
708 slab_seq_stop(struct seq_file
*f
, void *v
)
710 up_read(&spl_kmem_cache_sem
);
713 static struct seq_operations slab_seq_ops
= {
714 .show
= slab_seq_show
,
715 .start
= slab_seq_start
,
716 .next
= slab_seq_next
,
717 .stop
= slab_seq_stop
,
721 proc_slab_open(struct inode
*inode
, struct file
*filp
)
723 return seq_open(filp
, &slab_seq_ops
);
726 static struct file_operations proc_slab_operations
= {
727 .open
= proc_slab_open
,
730 .release
= seq_release
,
732 #endif /* DEBUG_KMEM */
734 static struct ctl_table spl_debug_table
[] = {
736 .ctl_name
= CTL_DEBUG_SUBSYS
,
737 .procname
= "subsystem",
738 .data
= &spl_debug_subsys
,
739 .maxlen
= sizeof(unsigned long),
741 .proc_handler
= &proc_dobitmasks
744 .ctl_name
= CTL_DEBUG_MASK
,
746 .data
= &spl_debug_mask
,
747 .maxlen
= sizeof(unsigned long),
749 .proc_handler
= &proc_dobitmasks
752 .ctl_name
= CTL_DEBUG_PRINTK
,
753 .procname
= "printk",
754 .data
= &spl_debug_printk
,
755 .maxlen
= sizeof(unsigned long),
757 .proc_handler
= &proc_dobitmasks
760 .ctl_name
= CTL_DEBUG_MB
,
763 .proc_handler
= &proc_debug_mb
,
766 .ctl_name
= CTL_DEBUG_BINARY
,
767 .procname
= "binary",
768 .data
= &spl_debug_binary
,
769 .maxlen
= sizeof(int),
771 .proc_handler
= &proc_dointvec
,
774 .ctl_name
= CTL_DEBUG_CATASTROPHE
,
775 .procname
= "catastrophe",
776 .data
= &spl_debug_catastrophe
,
777 .maxlen
= sizeof(int),
779 .proc_handler
= &proc_dointvec
,
782 .ctl_name
= CTL_DEBUG_PANIC_ON_BUG
,
783 .procname
= "panic_on_bug",
784 .data
= &spl_debug_panic_on_bug
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= &proc_dointvec
790 .ctl_name
= CTL_DEBUG_PATH
,
792 .data
= spl_debug_file_path
,
793 .maxlen
= sizeof(spl_debug_file_path
),
795 .proc_handler
= &proc_dostring
,
798 .ctl_name
= CTL_DEBUG_DUMP
,
801 .proc_handler
= &proc_dump_kernel
,
803 { .ctl_name
= CTL_DEBUG_FORCE_BUG
,
804 .procname
= "force_bug",
806 .proc_handler
= &proc_force_bug
,
809 .ctl_name
= CTL_CONSOLE_RATELIMIT
,
810 .procname
= "console_ratelimit",
811 .data
= &spl_console_ratelimit
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= &proc_dointvec
,
817 .ctl_name
= CTL_CONSOLE_MAX_DELAY_CS
,
818 .procname
= "console_max_delay_centisecs",
819 .maxlen
= sizeof(int),
821 .proc_handler
= &proc_console_max_delay_cs
,
824 .ctl_name
= CTL_CONSOLE_MIN_DELAY_CS
,
825 .procname
= "console_min_delay_centisecs",
826 .maxlen
= sizeof(int),
828 .proc_handler
= &proc_console_min_delay_cs
,
831 .ctl_name
= CTL_CONSOLE_BACKOFF
,
832 .procname
= "console_backoff",
833 .maxlen
= sizeof(int),
835 .proc_handler
= &proc_console_backoff
,
838 .ctl_name
= CTL_DEBUG_STACK_SIZE
,
839 .procname
= "stack_max",
840 .data
= &spl_debug_stack
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= &proc_dointvec
,
848 static struct ctl_table spl_vm_table
[] = {
850 .ctl_name
= CTL_VM_MINFREE
,
851 .procname
= "minfree",
853 .maxlen
= sizeof(int),
855 .proc_handler
= &proc_dointvec
,
858 .ctl_name
= CTL_VM_DESFREE
,
859 .procname
= "desfree",
861 .maxlen
= sizeof(int),
863 .proc_handler
= &proc_dointvec
,
866 .ctl_name
= CTL_VM_LOTSFREE
,
867 .procname
= "lotsfree",
869 .maxlen
= sizeof(int),
871 .proc_handler
= &proc_dointvec
,
874 .ctl_name
= CTL_VM_NEEDFREE
,
875 .procname
= "needfree",
877 .maxlen
= sizeof(int),
879 .proc_handler
= &proc_dointvec
,
882 .ctl_name
= CTL_VM_SWAPFS_MINFREE
,
883 .procname
= "swapfs_minfree",
884 .data
= &swapfs_minfree
,
885 .maxlen
= sizeof(int),
887 .proc_handler
= &proc_dointvec
,
890 .ctl_name
= CTL_VM_SWAPFS_RESERVE
,
891 .procname
= "swapfs_reserve",
892 .data
= &swapfs_reserve
,
893 .maxlen
= sizeof(int),
895 .proc_handler
= &proc_dointvec
,
898 .ctl_name
= CTL_VM_AVAILRMEM
,
899 .procname
= "availrmem",
901 .proc_handler
= &proc_doavailrmem
,
904 .ctl_name
= CTL_VM_FREEMEM
,
905 .procname
= "freemem",
907 .maxlen
= sizeof(int),
909 .proc_handler
= &proc_dofreemem
,
912 .ctl_name
= CTL_VM_PHYSMEM
,
913 .procname
= "physmem",
915 .maxlen
= sizeof(int),
917 .proc_handler
= &proc_dointvec
,
923 static struct ctl_table spl_mutex_table
[] = {
925 .ctl_name
= CTL_MUTEX_STATS
,
927 .data
= &mutex_stats
,
928 .maxlen
= sizeof(int) * MUTEX_STATS_SIZE
,
930 .proc_handler
= &proc_dointvec
,
933 .ctl_name
= CTL_MUTEX_SPIN_MAX
,
934 .procname
= "spin_max",
935 .data
= &mutex_spin_max
,
936 .maxlen
= sizeof(int),
938 .proc_handler
= &proc_dointvec
,
942 #endif /* DEBUG_MUTEX */
945 static struct ctl_table spl_kmem_table
[] = {
947 .ctl_name
= CTL_KMEM_KMEMUSED
,
948 .procname
= "kmem_used",
949 .data
= &kmem_alloc_used
,
950 .maxlen
= sizeof(atomic64_t
),
952 .proc_handler
= &proc_doatomic64
,
955 .ctl_name
= CTL_KMEM_KMEMMAX
,
956 .procname
= "kmem_max",
957 .data
= &kmem_alloc_max
,
958 .maxlen
= sizeof(unsigned long),
959 .extra1
= &table_min
,
960 .extra2
= &table_max
,
962 .proc_handler
= &proc_doulongvec_minmax
,
965 .ctl_name
= CTL_KMEM_VMEMUSED
,
966 .procname
= "vmem_used",
967 .data
= &vmem_alloc_used
,
968 .maxlen
= sizeof(atomic64_t
),
970 .proc_handler
= &proc_doatomic64
,
973 .ctl_name
= CTL_KMEM_VMEMMAX
,
974 .procname
= "vmem_max",
975 .data
= &vmem_alloc_max
,
976 .maxlen
= sizeof(unsigned long),
977 .extra1
= &table_min
,
978 .extra2
= &table_max
,
980 .proc_handler
= &proc_doulongvec_minmax
,
984 #endif /* DEBUG_KMEM */
987 static struct ctl_table spl_kstat_table
[] = {
990 #endif /* DEBUG_KSTAT */
992 static struct ctl_table spl_table
[] = {
993 /* NB No .strategy entries have been provided since
994 * sysctl(8) prefers to go via /proc for portability.
997 .ctl_name
= CTL_VERSION
,
998 .procname
= "version",
1000 .maxlen
= sizeof(spl_version
),
1002 .proc_handler
= &proc_dostring
,
1005 .ctl_name
= CTL_HOSTID
,
1006 .procname
= "hostid",
1007 .data
= &spl_hostid
,
1008 .maxlen
= sizeof(unsigned long),
1010 .proc_handler
= &proc_dohostid
,
1013 .ctl_name
= CTL_HW_SERIAL
,
1014 .procname
= "hw_serial",
1016 .maxlen
= sizeof(hw_serial
),
1018 .proc_handler
= &proc_dostring
,
1021 .ctl_name
= CTL_SPL_DEBUG
,
1022 .procname
= "debug",
1024 .child
= spl_debug_table
,
1027 .ctl_name
= CTL_SPL_VM
,
1030 .child
= spl_vm_table
,
1034 .ctl_name
= CTL_SPL_MUTEX
,
1035 .procname
= "mutex",
1037 .child
= spl_mutex_table
,
1042 .ctl_name
= CTL_SPL_KMEM
,
1045 .child
= spl_kmem_table
,
1050 .ctl_name
= CTL_SPL_KSTAT
,
1051 .procname
= "kstat",
1053 .child
= spl_kstat_table
,
1059 static struct ctl_table spl_dir
[] = {
1061 .ctl_name
= CTL_SPL
,
1069 static struct ctl_table spl_root
[] = {
1071 .ctl_name
= CTL_KERN
,
1072 .procname
= "kernel",
1080 proc_dir_entry_match(int len
, const char *name
, struct proc_dir_entry
*de
)
1082 if (de
->namelen
!= len
)
1085 return !memcmp(name
, de
->name
, len
);
1088 struct proc_dir_entry
*
1089 proc_dir_entry_find(struct proc_dir_entry
*root
, const char *str
)
1091 struct proc_dir_entry
*de
;
1093 for (de
= root
->subdir
; de
; de
= de
->next
)
1094 if (proc_dir_entry_match(strlen(str
), str
, de
))
1101 proc_dir_entries(struct proc_dir_entry
*root
)
1103 struct proc_dir_entry
*de
;
1106 for (de
= root
->subdir
; de
; de
= de
->next
)
1118 #ifdef CONFIG_SYSCTL
1119 spl_header
= spl_register_sysctl_table(spl_root
, 0);
1120 if (spl_header
== NULL
)
1122 #endif /* CONFIG_SYSCTL */
1124 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1125 proc_spl
= proc_mkdir("spl", NULL
);
1126 if (proc_spl
== NULL
)
1127 GOTO(out
, rc
= -EUNATCH
);
1130 proc_spl_mutex
= proc_mkdir("mutex", proc_spl
);
1131 if (proc_spl_mutex
== NULL
)
1132 GOTO(out
, rc
= -EUNATCH
);
1134 proc_spl_mutex_stats
= create_proc_entry("stats_per", 0444,
1136 if (proc_spl_mutex_stats
== NULL
)
1137 GOTO(out
, rc
= -EUNATCH
);
1139 proc_spl_mutex_stats
->proc_fops
= &proc_mutex_operations
;
1140 #endif /* DEBUG_MUTEX */
1143 proc_spl_kmem
= proc_mkdir("kmem", proc_spl
);
1144 if (proc_spl_kmem
== NULL
)
1145 GOTO(out
, rc
= -EUNATCH
);
1147 proc_spl_kmem_slab
= create_proc_entry("slab", 0444, proc_spl_kmem
);
1148 if (proc_spl_kmem_slab
== NULL
)
1149 GOTO(out
, rc
= -EUNATCH
);
1151 proc_spl_kmem_slab
->proc_fops
= &proc_slab_operations
;
1152 #endif /* DEBUG_KMEM */
1155 proc_spl_kstat
= proc_mkdir("kstat", proc_spl
);
1156 if (proc_spl_kstat
== NULL
)
1157 GOTO(out
, rc
= -EUNATCH
);
1158 #endif /* DEBUG_KSTAT */
1162 remove_proc_entry("kstat", proc_spl
);
1164 remove_proc_entry("slab", proc_spl_kmem
);
1166 remove_proc_entry("kmem", proc_spl
);
1168 remove_proc_entry("stats_per", proc_spl_mutex
);
1170 remove_proc_entry("mutex", proc_spl
);
1171 remove_proc_entry("spl", NULL
);
1172 #ifdef CONFIG_SYSCTL
1173 spl_unregister_sysctl_table(spl_header
);
1174 #endif /* CONFIG_SYSCTL */
1176 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1186 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1187 remove_proc_entry("kstat", proc_spl
);
1189 remove_proc_entry("slab", proc_spl_kmem
);
1191 remove_proc_entry("kmem", proc_spl
);
1193 remove_proc_entry("stats_per", proc_spl_mutex
);
1195 remove_proc_entry("mutex", proc_spl
);
1196 remove_proc_entry("spl", NULL
);
1197 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1199 #ifdef CONFIG_SYSCTL
1200 ASSERT(spl_header
!= NULL
);
1201 spl_unregister_sysctl_table(spl_header
);
1202 #endif /* CONFIG_SYSCTL */