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_MUTEX CTL_UNNUMBERED
64 #define CTL_SPL_KMEM CTL_UNNUMBERED
65 #define CTL_SPL_KSTAT CTL_UNNUMBERED
67 #define CTL_VERSION CTL_UNNUMBERED /* Version */
68 #define CTL_HOSTID CTL_UNNUMBERED /* Host id by /usr/bin/hostid */
69 #define CTL_HW_SERIAL CTL_UNNUMBERED /* HW serial number by hostid */
71 #define CTL_DEBUG_SUBSYS CTL_UNNUMBERED /* Debug subsystem */
72 #define CTL_DEBUG_MASK CTL_UNNUMBERED /* Debug mask */
73 #define CTL_DEBUG_PRINTK CTL_UNNUMBERED /* All messages to console */
74 #define CTL_DEBUG_MB CTL_UNNUMBERED /* Debug buffer size */
75 #define CTL_DEBUG_BINARY CTL_UNNUMBERED /* Binary data in buffer */
76 #define CTL_DEBUG_CATASTROPHE CTL_UNNUMBERED /* Set if BUG'd or panic'd */
77 #define CTL_DEBUG_PANIC_ON_BUG CTL_UNNUMBERED /* Should panic on BUG */
78 #define CTL_DEBUG_PATH CTL_UNNUMBERED /* Dump log location */
79 #define CTL_DEBUG_DUMP CTL_UNNUMBERED /* Dump debug buffer to file */
80 #define CTL_DEBUG_FORCE_BUG CTL_UNNUMBERED /* Hook to force a BUG */
81 #define CTL_DEBUG_STACK_SIZE CTL_UNNUMBERED /* Max observed stack size */
83 #define CTL_CONSOLE_RATELIMIT CTL_UNNUMBERED /* Ratelimit console messages */
84 #define CTL_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED /* Max delay skip messages */
85 #define CTL_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED /* Init delay skip messages */
86 #define CTL_CONSOLE_BACKOFF CTL_UNNUMBERED /* Delay increase factor */
89 #define CTL_KMEM_KMEMUSED CTL_UNNUMBERED /* Alloc'd kmem bytes */
90 #define CTL_KMEM_KMEMMAX CTL_UNNUMBERED /* Max alloc'd by kmem bytes */
91 #define CTL_KMEM_VMEMUSED CTL_UNNUMBERED /* Alloc'd vmem bytes */
92 #define CTL_KMEM_VMEMMAX CTL_UNNUMBERED /* Max alloc'd by vmem bytes */
93 #define CTL_KMEM_ALLOC_FAILED CTL_UNNUMBERED /* Cache allocations failed */
96 #define CTL_MUTEX_STATS CTL_UNNUMBERED /* Global mutex statistics */
97 #define CTL_MUTEX_STATS_PER CTL_UNNUMBERED /* Per mutex statistics */
98 #define CTL_MUTEX_SPIN_MAX CTL_UNNUMBERED /* Max mutex spin iterations */
100 #else /* HAVE_CTL_UNNUMBERED */
103 #define CTL_SPL_DEBUG 0x88
104 #define CTL_SPL_MUTEX 0x89
105 #define CTL_SPL_KMEM 0x90
106 #define CTL_SPL_KSTAT 0x91
109 CTL_VERSION
= 1, /* Version */
110 CTL_HOSTID
, /* Host id reported by /usr/bin/hostid */
111 CTL_HW_SERIAL
, /* Hardware serial number from hostid */
113 CTL_DEBUG_SUBSYS
, /* Debug subsystem */
114 CTL_DEBUG_MASK
, /* Debug mask */
115 CTL_DEBUG_PRINTK
, /* Force all messages to console */
116 CTL_DEBUG_MB
, /* Debug buffer size */
117 CTL_DEBUG_BINARY
, /* Include binary data in buffer */
118 CTL_DEBUG_CATASTROPHE
, /* Set if we have BUG'd or panic'd */
119 CTL_DEBUG_PANIC_ON_BUG
, /* Set if we should panic on BUG */
120 CTL_DEBUG_PATH
, /* Dump log location */
121 CTL_DEBUG_DUMP
, /* Dump debug buffer to file */
122 CTL_DEBUG_FORCE_BUG
, /* Hook to force a BUG */
123 CTL_DEBUG_STACK_SIZE
, /* Max observed stack size */
125 CTL_CONSOLE_RATELIMIT
, /* Ratelimit console messages */
126 CTL_CONSOLE_MAX_DELAY_CS
, /* Max delay at which we skip messages */
127 CTL_CONSOLE_MIN_DELAY_CS
, /* Init delay at which we skip messages */
128 CTL_CONSOLE_BACKOFF
, /* Delay increase factor */
131 CTL_KMEM_KMEMUSED
, /* Alloc'd kmem bytes */
132 CTL_KMEM_KMEMMAX
, /* Max alloc'd by kmem bytes */
133 CTL_KMEM_VMEMUSED
, /* Alloc'd vmem bytes */
134 CTL_KMEM_VMEMMAX
, /* Max alloc'd by vmem bytes */
137 CTL_MUTEX_STATS
, /* Global mutex statistics */
138 CTL_MUTEX_STATS_PER
, /* Per mutex statistics */
139 CTL_MUTEX_SPIN_MAX
, /* Maximum mutex spin iterations */
141 #endif /* HAVE_CTL_UNNUMBERED */
144 proc_copyin_string(char *kbuffer
, int kbuffer_size
,
145 const char *ubuffer
, int ubuffer_size
)
149 if (ubuffer_size
> kbuffer_size
)
152 if (copy_from_user((void *)kbuffer
, (void *)ubuffer
, ubuffer_size
))
155 /* strip trailing whitespace */
156 size
= strnlen(kbuffer
, ubuffer_size
);
158 if (!isspace(kbuffer
[size
]))
165 /* no space to terminate */
166 if (size
== kbuffer_size
)
169 kbuffer
[size
+ 1] = 0;
174 proc_copyout_string(char *ubuffer
, int ubuffer_size
,
175 const char *kbuffer
, char *append
)
177 /* NB if 'append' != NULL, it's a single character to append to the
178 * copied out string - usually "\n", for /proc entries and
179 * (i.e. a terminating zero byte) for sysctl entries
181 int size
= MIN(strlen(kbuffer
), ubuffer_size
);
183 if (copy_to_user(ubuffer
, kbuffer
, size
))
186 if (append
!= NULL
&& size
< ubuffer_size
) {
187 if (copy_to_user(ubuffer
+ size
, append
, 1))
197 proc_dobitmasks(struct ctl_table
*table
, int write
, struct file
*filp
,
198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
200 unsigned long *mask
= table
->data
;
201 int is_subsys
= (mask
== &spl_debug_subsys
) ? 1 : 0;
202 int is_printk
= (mask
== &spl_debug_printk
) ? 1 : 0;
207 str
= kmem_alloc(size
, KM_SLEEP
);
212 rc
= proc_copyin_string(str
, size
, buffer
, *lenp
);
216 rc
= spl_debug_str2mask(mask
, str
, is_subsys
);
217 /* Always print BUG/ASSERT to console, so keep this mask */
223 rc
= spl_debug_mask2str(str
, size
, *mask
, is_subsys
);
227 rc
= proc_copyout_string(buffer
, *lenp
,
235 kmem_free(str
, size
);
240 proc_debug_mb(struct ctl_table
*table
, int write
, struct file
*filp
,
241 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
248 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
252 rc
= spl_debug_set_mb(simple_strtoul(str
, NULL
, 0));
255 len
= snprintf(str
, sizeof(str
), "%d", spl_debug_get_mb());
259 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
271 proc_dump_kernel(struct ctl_table
*table
, int write
, struct file
*filp
,
272 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
277 spl_debug_dumplog(0);
287 proc_force_bug(struct ctl_table
*table
, int write
, struct file
*filp
,
288 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
293 CERROR("Crashing due to forced SBUG\n");
304 proc_console_max_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
305 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
307 int rc
, max_delay_cs
;
308 struct ctl_table dummy
= *table
;
312 dummy
.data
= &max_delay_cs
;
313 dummy
.proc_handler
= &proc_dointvec
;
317 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
321 if (max_delay_cs
<= 0)
324 d
= (max_delay_cs
* HZ
) / 100;
325 if (d
== 0 || d
< spl_console_min_delay
)
328 spl_console_max_delay
= d
;
330 max_delay_cs
= (spl_console_max_delay
* 100) / HZ
;
331 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
338 proc_console_min_delay_cs(struct ctl_table
*table
, int write
, struct file
*filp
,
339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
341 int rc
, min_delay_cs
;
342 struct ctl_table dummy
= *table
;
346 dummy
.data
= &min_delay_cs
;
347 dummy
.proc_handler
= &proc_dointvec
;
351 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
355 if (min_delay_cs
<= 0)
358 d
= (min_delay_cs
* HZ
) / 100;
359 if (d
== 0 || d
> spl_console_max_delay
)
362 spl_console_min_delay
= d
;
364 min_delay_cs
= (spl_console_min_delay
* 100) / HZ
;
365 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
372 proc_console_backoff(struct ctl_table
*table
, int write
, struct file
*filp
,
373 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
376 struct ctl_table dummy
= *table
;
379 dummy
.data
= &backoff
;
380 dummy
.proc_handler
= &proc_dointvec
;
384 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
391 spl_console_backoff
= backoff
;
393 backoff
= spl_console_backoff
;
394 rc
= proc_dointvec(&dummy
, write
, filp
, buffer
, lenp
, ppos
);
402 proc_doatomic64(struct ctl_table
*table
, int write
, struct file
*filp
,
403 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
406 unsigned long min
= 0, max
= ~0, val
;
407 struct ctl_table dummy
= *table
;
411 dummy
.proc_handler
= &proc_dointvec
;
418 val
= atomic64_read((atomic64_t
*)table
->data
);
419 rc
= proc_doulongvec_minmax(&dummy
, write
, filp
,
425 #endif /* DEBUG_KMEM */
428 proc_dohostid(struct ctl_table
*table
, int write
, struct file
*filp
,
429 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
437 /* We can't use proc_doulongvec_minmax() in the write
438 * case hear because hostid while a hex value has no
439 * leading 0x which confuses the helper function. */
440 rc
= proc_copyin_string(str
, sizeof(str
), buffer
, *lenp
);
444 val
= simple_strtol(str
, &end
, 16);
448 spl_hostid
= (long)val
;
449 (void)snprintf(hw_serial
, 11, "%u", (val
>= 0) ? val
: -val
);
452 len
= snprintf(str
, sizeof(str
), "%lx", spl_hostid
);
456 rc
= proc_copyout_string(buffer
, *lenp
, str
+ *ppos
, "\n");
469 mutex_seq_show_headers(struct seq_file
*f
)
471 seq_printf(f
, "%-36s %-4s %-16s\t"
472 "e_tot\te_nh\te_sp\te_sl\tte_tot\tte_nh\n",
473 "name", "type", "owner");
477 mutex_seq_show(struct seq_file
*f
, void *p
)
483 ASSERT(mp
->km_magic
== KM_MAGIC
);
485 switch (mp
->km_type
) {
486 case MUTEX_DEFAULT
: t
= 'D'; break;
487 case MUTEX_SPIN
: t
= 'S'; break;
488 case MUTEX_ADAPTIVE
: t
= 'A'; break;
492 seq_printf(f
, "%-36s %c ", mp
->km_name
, t
);
494 seq_printf(f
, "%p\t", mp
->km_owner
);
496 seq_printf(f
, "%-16s\t", "<not held>");
498 for (i
= 0; i
< MUTEX_STATS_SIZE
; i
++)
499 seq_printf(f
, "%d%c", mp
->km_stats
[i
],
500 (i
+ 1 == MUTEX_STATS_SIZE
) ? '\n' : '\t');
506 mutex_seq_start(struct seq_file
*f
, loff_t
*pos
)
512 spin_lock(&mutex_stats_lock
);
514 mutex_seq_show_headers(f
);
516 p
= mutex_stats_list
.next
;
519 if (p
== &mutex_stats_list
)
523 RETURN(list_entry(p
, kmutex_t
, km_list
));
527 mutex_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
533 RETURN((mp
->km_list
.next
== &mutex_stats_list
) ?
534 NULL
: list_entry(mp
->km_list
.next
, kmutex_t
, km_list
));
538 mutex_seq_stop(struct seq_file
*f
, void *v
)
540 spin_unlock(&mutex_stats_lock
);
543 static struct seq_operations mutex_seq_ops
= {
544 .show
= mutex_seq_show
,
545 .start
= mutex_seq_start
,
546 .next
= mutex_seq_next
,
547 .stop
= mutex_seq_stop
,
551 proc_mutex_open(struct inode
*inode
, struct file
*filp
)
553 return seq_open(filp
, &mutex_seq_ops
);
556 static struct file_operations proc_mutex_operations
= {
557 .open
= proc_mutex_open
,
560 .release
= seq_release
,
562 #endif /* DEBUG_MUTEX */
566 slab_seq_show_headers(struct seq_file
*f
)
568 seq_printf(f
, "%-36s\n", "name");
572 slab_seq_show(struct seq_file
*f
, void *p
)
574 spl_kmem_cache_t
*skc
= p
;
576 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
578 spin_lock(&skc
->skc_lock
);
579 seq_printf(f
, "%-36s ", skc
->skc_name
);
580 seq_printf(f
, "%u %u %u - %lu %lu %lu - %lu %lu %lu - %lu %lu %lu\n",
581 (unsigned)skc
->skc_obj_size
,
582 (unsigned)skc
->skc_slab_objs
,
583 (unsigned)skc
->skc_slab_size
,
584 (long unsigned)skc
->skc_slab_fail
,
585 (long unsigned)skc
->skc_slab_create
,
586 (long unsigned)skc
->skc_slab_destroy
,
587 (long unsigned)skc
->skc_slab_total
,
588 (long unsigned)skc
->skc_slab_alloc
,
589 (long unsigned)skc
->skc_slab_max
,
590 (long unsigned)skc
->skc_obj_total
,
591 (long unsigned)skc
->skc_obj_alloc
,
592 (long unsigned)skc
->skc_obj_max
);
594 spin_unlock(&skc
->skc_lock
);
600 slab_seq_start(struct seq_file
*f
, loff_t
*pos
)
606 down_read(&spl_kmem_cache_sem
);
608 slab_seq_show_headers(f
);
610 p
= spl_kmem_cache_list
.next
;
613 if (p
== &spl_kmem_cache_list
)
617 RETURN(list_entry(p
, spl_kmem_cache_t
, skc_list
));
621 slab_seq_next(struct seq_file
*f
, void *p
, loff_t
*pos
)
623 spl_kmem_cache_t
*skc
= p
;
627 RETURN((skc
->skc_list
.next
== &spl_kmem_cache_list
) ?
628 NULL
: list_entry(skc
->skc_list
.next
, spl_kmem_cache_t
, skc_list
));
632 slab_seq_stop(struct seq_file
*f
, void *v
)
634 up_read(&spl_kmem_cache_sem
);
637 static struct seq_operations slab_seq_ops
= {
638 .show
= slab_seq_show
,
639 .start
= slab_seq_start
,
640 .next
= slab_seq_next
,
641 .stop
= slab_seq_stop
,
645 proc_slab_open(struct inode
*inode
, struct file
*filp
)
647 return seq_open(filp
, &slab_seq_ops
);
650 static struct file_operations proc_slab_operations
= {
651 .open
= proc_slab_open
,
654 .release
= seq_release
,
656 #endif /* DEBUG_KMEM */
658 static struct ctl_table spl_debug_table
[] = {
660 .ctl_name
= CTL_DEBUG_SUBSYS
,
661 .procname
= "subsystem",
662 .data
= &spl_debug_subsys
,
663 .maxlen
= sizeof(unsigned long),
665 .proc_handler
= &proc_dobitmasks
668 .ctl_name
= CTL_DEBUG_MASK
,
670 .data
= &spl_debug_mask
,
671 .maxlen
= sizeof(unsigned long),
673 .proc_handler
= &proc_dobitmasks
676 .ctl_name
= CTL_DEBUG_PRINTK
,
677 .procname
= "printk",
678 .data
= &spl_debug_printk
,
679 .maxlen
= sizeof(unsigned long),
681 .proc_handler
= &proc_dobitmasks
684 .ctl_name
= CTL_DEBUG_MB
,
687 .proc_handler
= &proc_debug_mb
,
690 .ctl_name
= CTL_DEBUG_BINARY
,
691 .procname
= "binary",
692 .data
= &spl_debug_binary
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
698 .ctl_name
= CTL_DEBUG_CATASTROPHE
,
699 .procname
= "catastrophe",
700 .data
= &spl_debug_catastrophe
,
701 .maxlen
= sizeof(int),
703 .proc_handler
= &proc_dointvec
,
706 .ctl_name
= CTL_DEBUG_PANIC_ON_BUG
,
707 .procname
= "panic_on_bug",
708 .data
= &spl_debug_panic_on_bug
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= &proc_dointvec
714 .ctl_name
= CTL_DEBUG_PATH
,
716 .data
= spl_debug_file_path
,
717 .maxlen
= sizeof(spl_debug_file_path
),
719 .proc_handler
= &proc_dostring
,
722 .ctl_name
= CTL_DEBUG_DUMP
,
725 .proc_handler
= &proc_dump_kernel
,
727 { .ctl_name
= CTL_DEBUG_FORCE_BUG
,
728 .procname
= "force_bug",
730 .proc_handler
= &proc_force_bug
,
733 .ctl_name
= CTL_CONSOLE_RATELIMIT
,
734 .procname
= "console_ratelimit",
735 .data
= &spl_console_ratelimit
,
736 .maxlen
= sizeof(int),
738 .proc_handler
= &proc_dointvec
,
741 .ctl_name
= CTL_CONSOLE_MAX_DELAY_CS
,
742 .procname
= "console_max_delay_centisecs",
743 .maxlen
= sizeof(int),
745 .proc_handler
= &proc_console_max_delay_cs
,
748 .ctl_name
= CTL_CONSOLE_MIN_DELAY_CS
,
749 .procname
= "console_min_delay_centisecs",
750 .maxlen
= sizeof(int),
752 .proc_handler
= &proc_console_min_delay_cs
,
755 .ctl_name
= CTL_CONSOLE_BACKOFF
,
756 .procname
= "console_backoff",
757 .maxlen
= sizeof(int),
759 .proc_handler
= &proc_console_backoff
,
762 .ctl_name
= CTL_DEBUG_STACK_SIZE
,
763 .procname
= "stack_max",
764 .data
= &spl_debug_stack
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= &proc_dointvec
,
773 static struct ctl_table spl_mutex_table
[] = {
775 .ctl_name
= CTL_MUTEX_STATS
,
777 .data
= &mutex_stats
,
778 .maxlen
= sizeof(int) * MUTEX_STATS_SIZE
,
780 .proc_handler
= &proc_dointvec
,
783 .ctl_name
= CTL_MUTEX_SPIN_MAX
,
784 .procname
= "spin_max",
785 .data
= &mutex_spin_max
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= &proc_dointvec
,
792 #endif /* DEBUG_MUTEX */
795 static struct ctl_table spl_kmem_table
[] = {
797 .ctl_name
= CTL_KMEM_KMEMUSED
,
798 .procname
= "kmem_used",
799 .data
= &kmem_alloc_used
,
800 .maxlen
= sizeof(atomic64_t
),
802 .proc_handler
= &proc_doatomic64
,
805 .ctl_name
= CTL_KMEM_KMEMMAX
,
806 .procname
= "kmem_max",
807 .data
= &kmem_alloc_max
,
808 .maxlen
= sizeof(unsigned long),
809 .extra1
= &table_min
,
810 .extra2
= &table_max
,
812 .proc_handler
= &proc_doulongvec_minmax
,
815 .ctl_name
= CTL_KMEM_VMEMUSED
,
816 .procname
= "vmem_used",
817 .data
= &vmem_alloc_used
,
818 .maxlen
= sizeof(atomic64_t
),
820 .proc_handler
= &proc_doatomic64
,
823 .ctl_name
= CTL_KMEM_VMEMMAX
,
824 .procname
= "vmem_max",
825 .data
= &vmem_alloc_max
,
826 .maxlen
= sizeof(unsigned long),
827 .extra1
= &table_min
,
828 .extra2
= &table_max
,
830 .proc_handler
= &proc_doulongvec_minmax
,
834 #endif /* DEBUG_KMEM */
837 static struct ctl_table spl_kstat_table
[] = {
840 #endif /* DEBUG_KSTAT */
842 static struct ctl_table spl_table
[] = {
843 /* NB No .strategy entries have been provided since
844 * sysctl(8) prefers to go via /proc for portability.
847 .ctl_name
= CTL_VERSION
,
848 .procname
= "version",
850 .maxlen
= sizeof(spl_version
),
852 .proc_handler
= &proc_dostring
,
855 .ctl_name
= CTL_HOSTID
,
856 .procname
= "hostid",
858 .maxlen
= sizeof(unsigned long),
860 .proc_handler
= &proc_dohostid
,
863 .ctl_name
= CTL_HW_SERIAL
,
864 .procname
= "hw_serial",
866 .maxlen
= sizeof(hw_serial
),
868 .proc_handler
= &proc_dostring
,
871 .ctl_name
= CTL_SPL_DEBUG
,
874 .child
= spl_debug_table
,
878 .ctl_name
= CTL_SPL_MUTEX
,
881 .child
= spl_mutex_table
,
886 .ctl_name
= CTL_SPL_KMEM
,
889 .child
= spl_kmem_table
,
894 .ctl_name
= CTL_SPL_KSTAT
,
897 .child
= spl_kstat_table
,
903 static struct ctl_table spl_dir
[] = {
913 static struct ctl_table spl_root
[] = {
915 .ctl_name
= CTL_KERN
,
916 .procname
= "kernel",
924 proc_dir_entry_match(int len
, const char *name
, struct proc_dir_entry
*de
)
926 if (de
->namelen
!= len
)
929 return !memcmp(name
, de
->name
, len
);
932 struct proc_dir_entry
*
933 proc_dir_entry_find(struct proc_dir_entry
*root
, const char *str
)
935 struct proc_dir_entry
*de
;
937 for (de
= root
->subdir
; de
; de
= de
->next
)
938 if (proc_dir_entry_match(strlen(str
), str
, de
))
945 proc_dir_entries(struct proc_dir_entry
*root
)
947 struct proc_dir_entry
*de
;
950 for (de
= root
->subdir
; de
; de
= de
->next
)
963 spl_header
= spl_register_sysctl_table(spl_root
, 0);
964 if (spl_header
== NULL
)
966 #endif /* CONFIG_SYSCTL */
968 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
969 proc_spl
= proc_mkdir("spl", NULL
);
970 if (proc_spl
== NULL
)
971 GOTO(out
, rc
= -EUNATCH
);
974 proc_spl_mutex
= proc_mkdir("mutex", proc_spl
);
975 if (proc_spl_mutex
== NULL
)
976 GOTO(out
, rc
= -EUNATCH
);
978 proc_spl_mutex_stats
= create_proc_entry("stats_per", 0444,
980 if (proc_spl_mutex_stats
== NULL
)
981 GOTO(out
, rc
= -EUNATCH
);
983 proc_spl_mutex_stats
->proc_fops
= &proc_mutex_operations
;
984 #endif /* DEBUG_MUTEX */
987 proc_spl_kmem
= proc_mkdir("kmem", proc_spl
);
988 if (proc_spl_kmem
== NULL
)
989 GOTO(out
, rc
= -EUNATCH
);
991 proc_spl_kmem_slab
= create_proc_entry("slab", 0444, proc_spl_kmem
);
992 if (proc_spl_kmem_slab
== NULL
)
993 GOTO(out
, rc
= -EUNATCH
);
995 proc_spl_kmem_slab
->proc_fops
= &proc_slab_operations
;
996 #endif /* DEBUG_KMEM */
999 proc_spl_kstat
= proc_mkdir("kstat", proc_spl
);
1000 if (proc_spl_kstat
== NULL
)
1001 GOTO(out
, rc
= -EUNATCH
);
1002 #endif /* DEBUG_KSTAT */
1006 remove_proc_entry("kstat", proc_spl
);
1008 remove_proc_entry("slab", proc_spl_kmem
);
1010 remove_proc_entry("kmem", proc_spl
);
1012 remove_proc_entry("stats_per", proc_spl_mutex
);
1014 remove_proc_entry("mutex", proc_spl
);
1015 remove_proc_entry("spl", NULL
);
1016 #ifdef CONFIG_SYSCTL
1017 spl_unregister_sysctl_table(spl_header
);
1018 #endif /* CONFIG_SYSCTL */
1020 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1030 #if defined(DEBUG_MUTEX) || defined(DEBUG_KMEM) || defined(DEBUG_KSTAT)
1031 remove_proc_entry("kstat", proc_spl
);
1033 remove_proc_entry("slab", proc_spl_kmem
);
1035 remove_proc_entry("kmem", proc_spl
);
1037 remove_proc_entry("stats_per", proc_spl_mutex
);
1039 remove_proc_entry("mutex", proc_spl
);
1040 remove_proc_entry("spl", NULL
);
1041 #endif /* DEBUG_MUTEX || DEBUG_KMEM || DEBUG_KSTAT */
1043 #ifdef CONFIG_SYSCTL
1044 ASSERT(spl_header
!= NULL
);
1045 spl_unregister_sysctl_table(spl_header
);
1046 #endif /* CONFIG_SYSCTL */