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 */
71 #define CTL_KALLSYMS CTL_UNNUMBERED /* kallsyms_lookup_name addr */
73 #define CTL_DEBUG_SUBSYS CTL_UNNUMBERED /* Debug subsystem */
74 #define CTL_DEBUG_MASK CTL_UNNUMBERED /* Debug mask */
75 #define CTL_DEBUG_PRINTK CTL_UNNUMBERED /* All messages to console */
76 #define CTL_DEBUG_MB CTL_UNNUMBERED /* Debug buffer size */
77 #define CTL_DEBUG_BINARY CTL_UNNUMBERED /* Binary data in buffer */
78 #define CTL_DEBUG_CATASTROPHE CTL_UNNUMBERED /* Set if BUG'd or panic'd */
79 #define CTL_DEBUG_PANIC_ON_BUG CTL_UNNUMBERED /* Should panic on BUG */
80 #define CTL_DEBUG_PATH CTL_UNNUMBERED /* Dump log location */
81 #define CTL_DEBUG_DUMP CTL_UNNUMBERED /* Dump debug buffer to file */
82 #define CTL_DEBUG_FORCE_BUG CTL_UNNUMBERED /* Hook to force a BUG */
83 #define CTL_DEBUG_STACK_SIZE CTL_UNNUMBERED /* Max observed stack size */
85 #define CTL_CONSOLE_RATELIMIT CTL_UNNUMBERED /* Ratelimit console messages */
86 #define CTL_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED /* Max delay skip messages */
87 #define CTL_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED /* Init delay skip messages */
88 #define CTL_CONSOLE_BACKOFF CTL_UNNUMBERED /* Delay increase factor */
90 #define CTL_VM_MINFREE CTL_UNNUMBERED /* Minimum free memory */
91 #define CTL_VM_DESFREE CTL_UNNUMBERED /* Desired free memory */
92 #define CTL_VM_LOTSFREE CTL_UNNUMBERED /* Lots of free memory */
93 #define CTL_VM_NEEDFREE CTL_UNNUMBERED /* Need free memory */
94 #define CTL_VM_SWAPFS_MINFREE CTL_UNNUMBERED /* Minimum swapfs memory */
95 #define CTL_VM_SWAPFS_RESERVE CTL_UNNUMBERED /* Reserved swapfs memory */
96 #define CTL_VM_AVAILRMEM CTL_UNNUMBERED /* Easily available memory */
97 #define CTL_VM_FREEMEM CTL_UNNUMBERED /* Free memory */
98 #define CTL_VM_PHYSMEM CTL_UNNUMBERED /* Total physical memory */
101 #define CTL_KMEM_KMEMUSED CTL_UNNUMBERED /* Alloc'd kmem bytes */
102 #define CTL_KMEM_KMEMMAX CTL_UNNUMBERED /* Max alloc'd by kmem bytes */
103 #define CTL_KMEM_VMEMUSED CTL_UNNUMBERED /* Alloc'd vmem bytes */
104 #define CTL_KMEM_VMEMMAX CTL_UNNUMBERED /* Max alloc'd by vmem bytes */
105 #define CTL_KMEM_ALLOC_FAILED CTL_UNNUMBERED /* Cache allocations failed */
108 #define CTL_MUTEX_STATS CTL_UNNUMBERED /* Global mutex statistics */
109 #define CTL_MUTEX_STATS_PER CTL_UNNUMBERED /* Per mutex statistics */
110 #define CTL_MUTEX_SPIN_MAX CTL_UNNUMBERED /* Max mutex spin iterations */
112 #else /* HAVE_CTL_UNNUMBERED */
116 CTL_SPL_DEBUG
= 0x88,
118 CTL_SPL_MUTEX
= 0x90,
120 CTL_SPL_KSTAT
= 0x92,
124 CTL_VERSION
= 1, /* Version */
125 CTL_HOSTID
, /* Host id reported by /usr/bin/hostid */
126 CTL_HW_SERIAL
, /* Hardware serial number from hostid */
127 CTL_KALLSYMS
, /* Address of kallsyms_lookup_name */
129 CTL_DEBUG_SUBSYS
, /* Debug subsystem */
130 CTL_DEBUG_MASK
, /* Debug mask */
131 CTL_DEBUG_PRINTK
, /* Force all messages to console */
132 CTL_DEBUG_MB
, /* Debug buffer size */
133 CTL_DEBUG_BINARY
, /* Include binary data in buffer */
134 CTL_DEBUG_CATASTROPHE
, /* Set if we have BUG'd or panic'd */
135 CTL_DEBUG_PANIC_ON_BUG
, /* Set if we should panic on BUG */
136 CTL_DEBUG_PATH
, /* Dump log location */
137 CTL_DEBUG_DUMP
, /* Dump debug buffer to file */
138 CTL_DEBUG_FORCE_BUG
, /* Hook to force a BUG */
139 CTL_DEBUG_STACK_SIZE
, /* Max observed stack size */
141 CTL_CONSOLE_RATELIMIT
, /* Ratelimit console messages */
142 CTL_CONSOLE_MAX_DELAY_CS
, /* Max delay which we skip messages */
143 CTL_CONSOLE_MIN_DELAY_CS
, /* Init delay which we skip messages */
144 CTL_CONSOLE_BACKOFF
, /* Delay increase factor */
146 CTL_VM_MINFREE
, /* Minimum free memory threshold */
147 CTL_VM_DESFREE
, /* Desired free memory threshold */
148 CTL_VM_LOTSFREE
, /* Lots of free memory threshold */
149 CTL_VM_NEEDFREE
, /* Need free memory deficit */
150 CTL_VM_SWAPFS_MINFREE
, /* Minimum swapfs memory */
151 CTL_VM_SWAPFS_RESERVE
, /* Reserved swapfs memory */
152 CTL_VM_AVAILRMEM
, /* Easily available memory */
153 CTL_VM_FREEMEM
, /* Free memory */
154 CTL_VM_PHYSMEM
, /* Total physical memory */
157 CTL_KMEM_KMEMUSED
, /* Alloc'd kmem bytes */
158 CTL_KMEM_KMEMMAX
, /* Max alloc'd by kmem bytes */
159 CTL_KMEM_VMEMUSED
, /* Alloc'd vmem bytes */
160 CTL_KMEM_VMEMMAX
, /* Max alloc'd by vmem bytes */
163 CTL_MUTEX_STATS
, /* Global mutex statistics */
164 CTL_MUTEX_STATS_PER
, /* Per mutex statistics */
165 CTL_MUTEX_SPIN_MAX
, /* Maximum mutex spin iterations */
167 #endif /* HAVE_CTL_UNNUMBERED */
170 proc_copyin_string(char *kbuffer
, int kbuffer_size
,
171 const char *ubuffer
, int ubuffer_size
)
175 if (ubuffer_size
> kbuffer_size
)
178 if (copy_from_user((void *)kbuffer
, (void *)ubuffer
, ubuffer_size
))
181 /* strip trailing whitespace */
182 size
= strnlen(kbuffer
, ubuffer_size
);
184 if (!isspace(kbuffer
[size
]))
191 /* no space to terminate */
192 if (size
== kbuffer_size
)
195 kbuffer
[size
+ 1] = 0;
200 proc_copyout_string(char *ubuffer
, int ubuffer_size
,
201 const char *kbuffer
, char *append
)
203 /* NB if 'append' != NULL, it's a single character to append to the
204 * copied out string - usually "\n", for /proc entries and
205 * (i.e. a terminating zero byte) for sysctl entries
207 int size
= MIN(strlen(kbuffer
), ubuffer_size
);
209 if (copy_to_user(ubuffer
, kbuffer
, size
))
212 if (append
!= NULL
&& size
< ubuffer_size
) {
213 if (copy_to_user(ubuffer
+ size
, append
, 1))
223 proc_dobitmasks(struct ctl_table
*table
, int write
, struct file
*filp
,
224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
226 unsigned long *mask
= table
->data
;
227 int is_subsys
= (mask
== &spl_debug_subsys
) ? 1 : 0;
228 int is_printk
= (mask
== &spl_debug_printk
) ? 1 : 0;
233 str
= kmem_alloc(size
, KM_SLEEP
);
238 rc
= proc_copyin_string(str
, size
, buffer
, *lenp
);
242 rc
= spl_debug_str2mask(mask
, str
, is_subsys
);
243 /* Always print BUG/ASSERT to console, so keep this mask */
249 rc
= spl_debug_mask2str(str
, size
, *mask
, is_subsys
);
253 rc
= proc_copyout_string(buffer
, *lenp
,
261 kmem_free(str
, size
);
266 proc_debug_mb(struct ctl_table
*table
, int write
, struct file
*filp
,
267 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
274 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
278 rc
= spl_debug_set_mb(simple_strtoul(str
, NULL
, 0));
281 len
= snprintf(str
, sizeof(str
), "%d", spl_debug_get_mb());
285 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
297 proc_dump_kernel(struct ctl_table
*table
, int write
, struct file
*filp
,
298 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
303 spl_debug_dumplog(0);
313 proc_force_bug(struct ctl_table
*table
, int write
, struct file
*filp
,
314 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
319 CERROR("Crashing due to forced SBUG\n");
330 proc_console_max_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
331 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
333 int rc
, max_delay_cs
;
334 struct ctl_table dummy
= *table
;
338 dummy
.data
= &max_delay_cs
;
339 dummy
.proc_handler
= &proc_dointvec
;
343 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
347 if (max_delay_cs
<= 0)
350 d
= (max_delay_cs
* HZ
) / 100;
351 if (d
== 0 || d
< spl_console_min_delay
)
354 spl_console_max_delay
= d
;
356 max_delay_cs
= (spl_console_max_delay
* 100) / HZ
;
357 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
364 proc_console_min_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
365 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
367 int rc
, min_delay_cs
;
368 struct ctl_table dummy
= *table
;
372 dummy
.data
= &min_delay_cs
;
373 dummy
.proc_handler
= &proc_dointvec
;
377 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
381 if (min_delay_cs
<= 0)
384 d
= (min_delay_cs
* HZ
) / 100;
385 if (d
== 0 || d
> spl_console_max_delay
)
388 spl_console_min_delay
= d
;
390 min_delay_cs
= (spl_console_min_delay
* 100) / HZ
;
391 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
398 proc_console_backoff(struct ctl_table
*table
, int write
, struct file
*filp
,
399 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
402 struct ctl_table dummy
= *table
;
405 dummy
.data
= &backoff
;
406 dummy
.proc_handler
= &proc_dointvec
;
410 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
417 spl_console_backoff
= backoff
;
419 backoff
= spl_console_backoff
;
420 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
428 proc_doatomic64(struct ctl_table
*table
, int write
, struct file
*filp
,
429 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
432 unsigned long min
= 0, max
= ~0, val
;
433 struct ctl_table dummy
= *table
;
437 dummy
.proc_handler
= &proc_dointvec
;
444 val
= atomic64_read((atomic64_t
*)table
->data
);
445 rc
= proc_doulongvec_minmax(&dummy
, write
, filp
,
451 #endif /* DEBUG_KMEM */
454 proc_dohostid(struct ctl_table
*table
, int write
, struct file
*filp
,
455 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
463 /* We can't use proc_doulongvec_minmax() in the write
464 * case hear because hostid while a hex value has no
465 * leading 0x which confuses the helper function. */
466 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
470 val
= simple_strtol(str
, &end
, 16);
474 spl_hostid
= (long)val
;
475 (void)snprintf(hw_serial
, HW_HOSTID_LEN
-1, "%u",
476 (val
>= 0) ? val
: -val
);
479 len
= snprintf(str
, sizeof(str
), "%lx", spl_hostid
);
483 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
494 #ifndef HAVE_KALLSYMS_LOOKUP_NAME
496 proc_dokallsyms_lookup_name(struct ctl_table
*table
, int write
,
497 struct file
*filp
, void __user
*buffer
,
498 size_t *lenp
, loff_t
*ppos
) {
504 /* This may only be set once at module load time */
505 if (spl_kallsyms_lookup_name_fn
)
508 /* We can't use proc_doulongvec_minmax() in the write
509 * case hear because the address while a hex value has no
510 * leading 0x which confuses the helper function. */
511 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
515 spl_kallsyms_lookup_name_fn
=
516 (kallsyms_lookup_name_t
)simple_strtoul(str
, &end
, 16);
522 len
= snprintf(str
, sizeof(str
), "%lx",
523 (unsigned long)spl_kallsyms_lookup_name_fn
);
527 rc
= proc_copyout_string(buffer
,*lenp
,str
+*ppos
,"\n");
537 #endif /* HAVE_KALLSYMS_LOOKUP_NAME */
540 proc_doavailrmem(struct ctl_table
*table
, int write
, struct file
*filp
,
541 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
550 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)availrmem
);
554 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
566 proc_dofreemem(struct ctl_table
*table
, int write
, struct file
*filp
,
567 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
576 len
= snprintf(str
, sizeof(str
), "%lu", (unsigned long)freemem
);
580 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
593 mutex_seq_show_headers(struct seq_file
*f
)
595 seq_printf(f
, "%-36s %-4s %-16s\t"
596 "e_tot\te_nh\te_sp\te_sl\tte_tot\tte_nh\n",
597 "name", "type", "owner");
601 mutex_seq_show(struct seq_file
*f
, void *p
)
607 ASSERT(mp
->km_magic
== KM_MAGIC
);
609 switch (mp
->km_type
) {
610 case MUTEX_DEFAULT
: t
= 'D'; break;
611 case MUTEX_SPIN
: t
= 'S'; break;
612 case MUTEX_ADAPTIVE
: t
= 'A'; break;
616 seq_printf(f
, "%-36s %c ", mp
->km_name
, t
);
618 seq_printf(f
, "%p\t", mp
->km_owner
);
620 seq_printf(f
, "%-16s\t", "<not held>");
622 for (i
= 0; i
< MUTEX_STATS_SIZE
; i
++)
623 seq_printf(f
, "%d%c", mp
->km_stats
[i
],
624 (i
+ 1 == MUTEX_STATS_SIZE
) ? '\n' : '\t');
630 mutex_seq_start(struct seq_file
*f
, loff_t
*pos
)
636 spin_lock(&mutex_stats_lock
);
638 mutex_seq_show_headers(f
);
640 p
= mutex_stats_list
.next
;
643 if (p
== &mutex_stats_list
)
647 RETURN(list_entry(p
, kmutex_t
, km_list
));
651 mutex_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
657 RETURN((mp
->km_list
.next
== &mutex_stats_list
) ?
658 NULL
: list_entry(mp
->km_list
.next
, kmutex_t
, km_list
));
662 mutex_seq_stop(struct seq_file
*f
, void *v
)
664 spin_unlock(&mutex_stats_lock
);
667 static struct seq_operations mutex_seq_ops
= {
668 .show
= mutex_seq_show
,
669 .start
= mutex_seq_start
,
670 .next
= mutex_seq_next
,
671 .stop
= mutex_seq_stop
,
675 proc_mutex_open(struct inode
*inode
, struct file
*filp
)
677 return seq_open(filp
, &mutex_seq_ops
);
680 static struct file_operations proc_mutex_operations
= {
681 .open
= proc_mutex_open
,
684 .release
= seq_release
,
686 #endif /* DEBUG_MUTEX */
690 slab_seq_show_headers(struct seq_file
*f
)
692 seq_printf(f
, "%-36s\n", "name");
696 slab_seq_show(struct seq_file
*f
, void *p
)
698 spl_kmem_cache_t
*skc
= p
;
700 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
702 spin_lock(&skc
->skc_lock
);
703 seq_printf(f
, "%-36s ", skc
->skc_name
);
704 seq_printf(f
, "%u %u %u - %lu %lu %lu - %lu %lu %lu - %lu %lu %lu\n",
705 (unsigned)skc
->skc_obj_size
,
706 (unsigned)skc
->skc_slab_objs
,
707 (unsigned)skc
->skc_slab_size
,
708 (long unsigned)skc
->skc_slab_fail
,
709 (long unsigned)skc
->skc_slab_create
,
710 (long unsigned)skc
->skc_slab_destroy
,
711 (long unsigned)skc
->skc_slab_total
,
712 (long unsigned)skc
->skc_slab_alloc
,
713 (long unsigned)skc
->skc_slab_max
,
714 (long unsigned)skc
->skc_obj_total
,
715 (long unsigned)skc
->skc_obj_alloc
,
716 (long unsigned)skc
->skc_obj_max
);
718 spin_unlock(&skc
->skc_lock
);
724 slab_seq_start(struct seq_file
*f
, loff_t
*pos
)
730 down_read(&spl_kmem_cache_sem
);
732 slab_seq_show_headers(f
);
734 p
= spl_kmem_cache_list
.next
;
737 if (p
== &spl_kmem_cache_list
)
741 RETURN(list_entry(p
, spl_kmem_cache_t
, skc_list
));
745 slab_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
747 spl_kmem_cache_t
*skc
= p
;
751 RETURN((skc
->skc_list
.next
== &spl_kmem_cache_list
) ?
752 NULL
: list_entry(skc
->skc_list
.next
, spl_kmem_cache_t
, skc_list
));
756 slab_seq_stop(struct seq_file
*f
, void *v
)
758 up_read(&spl_kmem_cache_sem
);
761 static struct seq_operations slab_seq_ops
= {
762 .show
= slab_seq_show
,
763 .start
= slab_seq_start
,
764 .next
= slab_seq_next
,
765 .stop
= slab_seq_stop
,
769 proc_slab_open(struct inode
*inode
, struct file
*filp
)
771 return seq_open(filp
, &slab_seq_ops
);
774 static struct file_operations proc_slab_operations
= {
775 .open
= proc_slab_open
,
778 .release
= seq_release
,
780 #endif /* DEBUG_KMEM */
782 static struct ctl_table spl_debug_table
[] = {
784 .ctl_name
= CTL_DEBUG_SUBSYS
,
785 .procname
= "subsystem",
786 .data
= &spl_debug_subsys
,
787 .maxlen
= sizeof(unsigned long),
789 .proc_handler
= &proc_dobitmasks
792 .ctl_name
= CTL_DEBUG_MASK
,
794 .data
= &spl_debug_mask
,
795 .maxlen
= sizeof(unsigned long),
797 .proc_handler
= &proc_dobitmasks
800 .ctl_name
= CTL_DEBUG_PRINTK
,
801 .procname
= "printk",
802 .data
= &spl_debug_printk
,
803 .maxlen
= sizeof(unsigned long),
805 .proc_handler
= &proc_dobitmasks
808 .ctl_name
= CTL_DEBUG_MB
,
811 .proc_handler
= &proc_debug_mb
,
814 .ctl_name
= CTL_DEBUG_BINARY
,
815 .procname
= "binary",
816 .data
= &spl_debug_binary
,
817 .maxlen
= sizeof(int),
819 .proc_handler
= &proc_dointvec
,
822 .ctl_name
= CTL_DEBUG_CATASTROPHE
,
823 .procname
= "catastrophe",
824 .data
= &spl_debug_catastrophe
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= &proc_dointvec
,
830 .ctl_name
= CTL_DEBUG_PANIC_ON_BUG
,
831 .procname
= "panic_on_bug",
832 .data
= &spl_debug_panic_on_bug
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= &proc_dointvec
838 .ctl_name
= CTL_DEBUG_PATH
,
840 .data
= spl_debug_file_path
,
841 .maxlen
= sizeof(spl_debug_file_path
),
843 .proc_handler
= &proc_dostring
,
846 .ctl_name
= CTL_DEBUG_DUMP
,
849 .proc_handler
= &proc_dump_kernel
,
851 { .ctl_name
= CTL_DEBUG_FORCE_BUG
,
852 .procname
= "force_bug",
854 .proc_handler
= &proc_force_bug
,
857 .ctl_name
= CTL_CONSOLE_RATELIMIT
,
858 .procname
= "console_ratelimit",
859 .data
= &spl_console_ratelimit
,
860 .maxlen
= sizeof(int),
862 .proc_handler
= &proc_dointvec
,
865 .ctl_name
= CTL_CONSOLE_MAX_DELAY_CS
,
866 .procname
= "console_max_delay_centisecs",
867 .maxlen
= sizeof(int),
869 .proc_handler
= &proc_console_max_delay_cs
,
872 .ctl_name
= CTL_CONSOLE_MIN_DELAY_CS
,
873 .procname
= "console_min_delay_centisecs",
874 .maxlen
= sizeof(int),
876 .proc_handler
= &proc_console_min_delay_cs
,
879 .ctl_name
= CTL_CONSOLE_BACKOFF
,
880 .procname
= "console_backoff",
881 .maxlen
= sizeof(int),
883 .proc_handler
= &proc_console_backoff
,
886 .ctl_name
= CTL_DEBUG_STACK_SIZE
,
887 .procname
= "stack_max",
888 .data
= &spl_debug_stack
,
889 .maxlen
= sizeof(int),
891 .proc_handler
= &proc_dointvec
,
896 static struct ctl_table spl_vm_table
[] = {
898 .ctl_name
= CTL_VM_MINFREE
,
899 .procname
= "minfree",
901 .maxlen
= sizeof(int),
903 .proc_handler
= &proc_dointvec
,
906 .ctl_name
= CTL_VM_DESFREE
,
907 .procname
= "desfree",
909 .maxlen
= sizeof(int),
911 .proc_handler
= &proc_dointvec
,
914 .ctl_name
= CTL_VM_LOTSFREE
,
915 .procname
= "lotsfree",
917 .maxlen
= sizeof(int),
919 .proc_handler
= &proc_dointvec
,
922 .ctl_name
= CTL_VM_NEEDFREE
,
923 .procname
= "needfree",
925 .maxlen
= sizeof(int),
927 .proc_handler
= &proc_dointvec
,
930 .ctl_name
= CTL_VM_SWAPFS_MINFREE
,
931 .procname
= "swapfs_minfree",
932 .data
= &swapfs_minfree
,
933 .maxlen
= sizeof(int),
935 .proc_handler
= &proc_dointvec
,
938 .ctl_name
= CTL_VM_SWAPFS_RESERVE
,
939 .procname
= "swapfs_reserve",
940 .data
= &swapfs_reserve
,
941 .maxlen
= sizeof(int),
943 .proc_handler
= &proc_dointvec
,
946 .ctl_name
= CTL_VM_AVAILRMEM
,
947 .procname
= "availrmem",
949 .proc_handler
= &proc_doavailrmem
,
952 .ctl_name
= CTL_VM_FREEMEM
,
953 .procname
= "freemem",
955 .maxlen
= sizeof(int),
957 .proc_handler
= &proc_dofreemem
,
960 .ctl_name
= CTL_VM_PHYSMEM
,
961 .procname
= "physmem",
963 .maxlen
= sizeof(int),
965 .proc_handler
= &proc_dointvec
,
971 static struct ctl_table spl_mutex_table
[] = {
973 .ctl_name
= CTL_MUTEX_STATS
,
975 .data
= &mutex_stats
,
976 .maxlen
= sizeof(int) * MUTEX_STATS_SIZE
,
978 .proc_handler
= &proc_dointvec
,
981 .ctl_name
= CTL_MUTEX_SPIN_MAX
,
982 .procname
= "spin_max",
983 .data
= &mutex_spin_max
,
984 .maxlen
= sizeof(int),
986 .proc_handler
= &proc_dointvec
,
990 #endif /* DEBUG_MUTEX */
993 static struct ctl_table spl_kmem_table
[] = {
995 .ctl_name
= CTL_KMEM_KMEMUSED
,
996 .procname
= "kmem_used",
997 .data
= &kmem_alloc_used
,
998 .maxlen
= sizeof(atomic64_t
),
1000 .proc_handler
= &proc_doatomic64
,
1003 .ctl_name
= CTL_KMEM_KMEMMAX
,
1004 .procname
= "kmem_max",
1005 .data
= &kmem_alloc_max
,
1006 .maxlen
= sizeof(unsigned long),
1007 .extra1
= &table_min
,
1008 .extra2
= &table_max
,
1010 .proc_handler
= &proc_doulongvec_minmax
,
1013 .ctl_name
= CTL_KMEM_VMEMUSED
,
1014 .procname
= "vmem_used",
1015 .data
= &vmem_alloc_used
,
1016 .maxlen
= sizeof(atomic64_t
),
1018 .proc_handler
= &proc_doatomic64
,
1021 .ctl_name
= CTL_KMEM_VMEMMAX
,
1022 .procname
= "vmem_max",
1023 .data
= &vmem_alloc_max
,
1024 .maxlen
= sizeof(unsigned long),
1025 .extra1
= &table_min
,
1026 .extra2
= &table_max
,
1028 .proc_handler
= &proc_doulongvec_minmax
,
1032 #endif /* DEBUG_KMEM */
1035 static struct ctl_table spl_kstat_table
[] = {
1038 #endif /* DEBUG_KSTAT */
1040 static struct ctl_table spl_table
[] = {
1041 /* NB No .strategy entries have been provided since
1042 * sysctl(8) prefers to go via /proc for portability.
1045 .ctl_name
= CTL_VERSION
,
1046 .procname
= "version",
1047 .data
= spl_version
,
1048 .maxlen
= sizeof(spl_version
),
1050 .proc_handler
= &proc_dostring
,
1053 .ctl_name
= CTL_HOSTID
,
1054 .procname
= "hostid",
1055 .data
= &spl_hostid
,
1056 .maxlen
= sizeof(unsigned long),
1058 .proc_handler
= &proc_dohostid
,
1061 .ctl_name
= CTL_HW_SERIAL
,
1062 .procname
= "hw_serial",
1064 .maxlen
= sizeof(hw_serial
),
1066 .proc_handler
= &proc_dostring
,
1068 #ifndef HAVE_KALLSYMS_LOOKUP_NAME
1070 .ctl_name
= CTL_KALLSYMS
,
1071 .procname
= "kallsyms_lookup_name",
1072 .data
= &spl_kallsyms_lookup_name_fn
,
1073 .maxlen
= sizeof(unsigned long),
1075 .proc_handler
= &proc_dokallsyms_lookup_name
,
1079 .ctl_name
= CTL_SPL_DEBUG
,
1080 .procname
= "debug",
1082 .child
= spl_debug_table
,
1085 .ctl_name
= CTL_SPL_VM
,
1088 .child
= spl_vm_table
,
1092 .ctl_name
= CTL_SPL_MUTEX
,
1093 .procname
= "mutex",
1095 .child
= spl_mutex_table
,
1100 .ctl_name
= CTL_SPL_KMEM
,
1103 .child
= spl_kmem_table
,
1108 .ctl_name
= CTL_SPL_KSTAT
,
1109 .procname
= "kstat",
1111 .child
= spl_kstat_table
,
1117 static struct ctl_table spl_dir
[] = {
1119 .ctl_name
= CTL_SPL
,
1127 static struct ctl_table spl_root
[] = {
1129 .ctl_name
= CTL_KERN
,
1130 .procname
= "kernel",
1138 proc_dir_entry_match(int len
, const char *name
, struct proc_dir_entry
*de
)
1140 if (de
->namelen
!= len
)
1143 return !memcmp(name
, de
->name
, len
);
1146 struct proc_dir_entry
*
1147 proc_dir_entry_find(struct proc_dir_entry
*root
, const char *str
)
1149 struct proc_dir_entry
*de
;
1151 for (de
= root
->subdir
; de
; de
= de
->next
)
1152 if (proc_dir_entry_match(strlen(str
), str
, de
))
1159 proc_dir_entries(struct proc_dir_entry
*root
)
1161 struct proc_dir_entry
*de
;
1164 for (de
= root
->subdir
; de
; de
= de
->next
)
1176 #ifdef CONFIG_SYSCTL
1177 spl_header
= spl_register_sysctl_table(spl_root
, 0);
1178 if (spl_header
== NULL
)
1180 #endif /* CONFIG_SYSCTL */
1182 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1183 proc_spl
= proc_mkdir("spl", NULL
);
1184 if (proc_spl
== NULL
)
1185 GOTO(out
, rc
= -EUNATCH
);
1188 proc_spl_mutex
= proc_mkdir("mutex", proc_spl
);
1189 if (proc_spl_mutex
== NULL
)
1190 GOTO(out
, rc
= -EUNATCH
);
1192 proc_spl_mutex_stats
= create_proc_entry("stats_per", 0444,
1194 if (proc_spl_mutex_stats
== NULL
)
1195 GOTO(out
, rc
= -EUNATCH
);
1197 proc_spl_mutex_stats
->proc_fops
= &proc_mutex_operations
;
1198 #endif /* DEBUG_MUTEX */
1201 proc_spl_kmem
= proc_mkdir("kmem", proc_spl
);
1202 if (proc_spl_kmem
== NULL
)
1203 GOTO(out
, rc
= -EUNATCH
);
1205 proc_spl_kmem_slab
= create_proc_entry("slab", 0444, proc_spl_kmem
);
1206 if (proc_spl_kmem_slab
== NULL
)
1207 GOTO(out
, rc
= -EUNATCH
);
1209 proc_spl_kmem_slab
->proc_fops
= &proc_slab_operations
;
1210 #endif /* DEBUG_KMEM */
1213 proc_spl_kstat
= proc_mkdir("kstat", proc_spl
);
1214 if (proc_spl_kstat
== NULL
)
1215 GOTO(out
, rc
= -EUNATCH
);
1216 #endif /* DEBUG_KSTAT */
1220 remove_proc_entry("kstat", proc_spl
);
1222 remove_proc_entry("slab", proc_spl_kmem
);
1224 remove_proc_entry("kmem", proc_spl
);
1226 remove_proc_entry("stats_per", proc_spl_mutex
);
1228 remove_proc_entry("mutex", proc_spl
);
1229 remove_proc_entry("spl", NULL
);
1230 #ifdef CONFIG_SYSCTL
1231 spl_unregister_sysctl_table(spl_header
);
1232 #endif /* CONFIG_SYSCTL */
1234 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1244 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1245 remove_proc_entry("kstat", proc_spl
);
1247 remove_proc_entry("slab", proc_spl_kmem
);
1249 remove_proc_entry("kmem", proc_spl
);
1251 remove_proc_entry("stats_per", proc_spl_mutex
);
1253 remove_proc_entry("mutex", proc_spl
);
1254 remove_proc_entry("spl", NULL
);
1255 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1257 #ifdef CONFIG_SYSCTL
1258 ASSERT(spl_header
!= NULL
);
1259 spl_unregister_sysctl_table(spl_header
);
1260 #endif /* CONFIG_SYSCTL */