<div class="gmail_quote"><p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Hello there,</span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">I am creating a sysctl kernel module to register 2 hierarchy under
same proc name. For e.g. </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> my_net</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> | | </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">net1 net2</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> | |</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">t1 t2</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">So, I used register_sysctl_paths() API for registering the sysctl
tables net1 net2 under path name my_net.</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Problem is when unregistering the tables dmesg shows a warning and
call trace.</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"># rmmod sysctl.ko</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"># dmesg</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">------------[ cut here ]------------</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">WARNING: at kernel/sysctl.c:2270
unregister_sysctl_table+0xb1/0x120() (Tainted: P W
---------------- )</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Hardware name: VMware Virtual Platform</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Modules linked in: sysctl(-)(U) ip6table_filter ip6_tables
ebtable_nat ebtables xt_CHECKSUM iptable_mangle ipt_MASQUERADE iptable_nat
nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_state nf_conntrack ipt_REJECT bridge
autofs4 sunrpc fcoe libfcoe libfc scsi_transport_fc scsi_tgt 8021q garp stp llc
cachefiles fscache ipv6 xt_physdev iptable_filter ip_tables dm_mirror dm_region_hash
dm_log uinput ppdev parport_pc parport e1000 pcnet32 mii vmware_balloon sg
i2c_piix4 i2c_core shpchp ext4 mbcache jbd2 vxspec(P)(U) vxio(P)(U) vxdmp(P)(U)
sd_mod crc_t10dif sr_mod cdrom mptspi mptscsih mptbase scsi_transport_spi
ata_generic pata_acpi ata_piix dm_mod [last unloaded: sysctl]</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Pid: 22463, comm: rmmod Tainted: P W
---------------- 2.6.32-71.el6.x86_64 #1</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Call Trace:</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff8106b857>] warn_slowpath_common+0x87/0xc0</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff8106b8aa>] warn_slowpath_null+0x1a/0x20</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff81076251>]
unregister_sysctl_table+0xb1/0x120</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff810c611c>] ? stop_machine_destroy+0x4c/0x50</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff810c621b>] ? stop_machine+0x4b/0x60</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffffa002d021>] sysctl_module_exit+0x21/0x23
[sysctl]</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff810ac706>] sys_delete_module+0x1a6/0x280</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff8101ea88>] ? syscall_trace_enter+0x1d8/0x1e0</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> [<ffffffff81013387>] tracesys+0xd9/0xde</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">---[ end trace fee2c1c8e41aeb36 ]---</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Kindly, help me to resolve this warning.</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Following is module.</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">#include
<linux/kernel.h></span></p>
<p class="MsoNormal"><span style="font-size:8pt">#include <linux/module.h></span></p>
<p class="MsoNormal"><span style="font-size:8pt">#include
<linux/sysctl.h></span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static struct
ctl_table_header * test_sysctl_header1;</span></p>
<p class="MsoNormal"><span style="font-size:8pt">static struct
ctl_table_header * test_sysctl_header2;</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">int value1 = 0;</span></p>
<p class="MsoNormal"><span style="font-size:8pt">int value2 = 1;</span></p>
<p class="MsoNormal"><span style="font-size:8pt">int min = 10;</span></p>
<p class="MsoNormal"><span style="font-size:8pt">int max = 20;</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_table1[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "value1",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.data
= &value1,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.maxlen
= sizeof(int),</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0644,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.proc_handler
= &proc_dointvec_minmax,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.strategy = &sysctl_intvec,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra1 = &min,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra2 = &max</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "value2",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.data
= &value2,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.maxlen
= sizeof(int),</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0644,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.proc_handler
= &proc_dointvec_minmax,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.strategy = &sysctl_intvec,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra1 = &min,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra2 = &max</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_table2[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "value1",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.data
= &value1,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.maxlen
= sizeof(int),</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0644,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.proc_handler
= &proc_dointvec_minmax,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.strategy = &sysctl_intvec,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra1 = &min,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra2 = &max</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "value2",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.data
= &value2,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.maxlen
= sizeof(int),</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0644,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.proc_handler
= &proc_dointvec_minmax,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.strategy = &sysctl_intvec,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra1 = &min,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.extra2 = &max</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_net_table1[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "test1",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0555,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.child
= test_table1</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_net_table2[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "test2",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0555,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.child
= test_table2</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_root_table1[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "net1",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0555,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.child
= test_net_table1</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static ctl_table
test_root_table2[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.ctl_name
= CTL_UNNUMBERED,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.procname
= "net2",</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.mode
= 0555,</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
.child
= test_net_table2</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
},</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .ctl_name = 0 }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static struct
ctl_path net1_path[] = {</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ .procname = "my_net", .ctl_name = CTL_UNNUMBERED },</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
{ }</span></p>
<p class="MsoNormal"><span style="font-size:8pt">};</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static int __init
sysctl_module_init(void)</span></p>
<p class="MsoNormal"><span style="font-size:8pt">{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
test_sysctl_header1 = register_sysctl_paths(net1_path, test_root_table1);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
test_sysctl_header2 = register_sysctl_paths(net1_path, test_root_table2);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
return 0;</span></p>
<p class="MsoNormal"><span style="font-size:8pt">}</span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">static void __exit
sysctl_module_exit(void)</span></p>
<p class="MsoNormal"><span style="font-size:8pt">{</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
unregister_sysctl_table(test_sysctl_header1);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">
unregister_sysctl_table(test_sysctl_header2);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">} </span></p>
<p class="MsoNormal"><span style="font-size:8pt"> </span></p>
<p class="MsoNormal"><span style="font-size:8pt">module_init(sysctl_module_init);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">module_exit(sysctl_module_exit);</span></p>
<p class="MsoNormal"><span style="font-size:8pt">MODULE_LICENSE("GPL");</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Thanks,</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Chaitanya</span></p>
</div><br>