Linux kernel : sysctl registering table under same proc name (path)

chaitanya g chaitanyag3.14 at gmail.com
Tue Feb 21 06:41:59 EST 2012


Hello there,



I am creating a sysctl kernel module to register 2 hierarchy under same
proc name. For e.g.



  my_net

  |          |

net1  net2

 |         |

t1        t2



So, I used register_sysctl_paths() API for registering the sysctl tables
net1 net2 under path name my_net.



Problem is when unregistering the tables dmesg shows a warning and call
trace.



# rmmod  sysctl.ko

# dmesg

------------[ cut here ]------------

WARNING: at kernel/sysctl.c:2270 unregister_sysctl_table+0xb1/0x120()
(Tainted: P        W  ---------------- )

Hardware name: VMware Virtual Platform

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]

Pid: 22463, comm: rmmod Tainted: P        W  ----------------
 2.6.32-71.el6.x86_64 #1

Call Trace:

 [<ffffffff8106b857>] warn_slowpath_common+0x87/0xc0

 [<ffffffff8106b8aa>] warn_slowpath_null+0x1a/0x20

 [<ffffffff81076251>] unregister_sysctl_table+0xb1/0x120

 [<ffffffff810c611c>] ? stop_machine_destroy+0x4c/0x50

 [<ffffffff810c621b>] ? stop_machine+0x4b/0x60

 [<ffffffffa002d021>] sysctl_module_exit+0x21/0x23 [sysctl]

 [<ffffffff810ac706>] sys_delete_module+0x1a6/0x280

 [<ffffffff8101ea88>] ? syscall_trace_enter+0x1d8/0x1e0

 [<ffffffff81013387>] tracesys+0xd9/0xde

---[ end trace fee2c1c8e41aeb36 ]---





Kindly, help me to resolve this warning.





Following is module.



#include <linux/kernel.h>

#include <linux/module.h>

#include <linux/sysctl.h>





static struct ctl_table_header * test_sysctl_header1;

static struct ctl_table_header * test_sysctl_header2;



int value1 = 0;

int value2 = 1;

int min = 10;

int max = 20;



static ctl_table test_table1[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "value1",


.data                                     = &value1,


.maxlen                              = sizeof(int),


.mode                                 = 0644,

                                                .proc_handler
= &proc_dointvec_minmax,

                                                .strategy    =
&sysctl_intvec,

                                                .extra1         = &min,

                                                .extra2         = &max

                        },

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "value2",


.data                                     = &value2,


.maxlen                              = sizeof(int),


.mode                                 = 0644,

                                                .proc_handler
= &proc_dointvec_minmax,

                                                .strategy    =
&sysctl_intvec,

                                                .extra1         = &min,

                                                .extra2         = &max

                        },

                        { .ctl_name = 0 }

};



static ctl_table test_table2[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "value1",


.data                                     = &value1,


.maxlen                              = sizeof(int),


.mode                                 = 0644,

                                                .proc_handler
= &proc_dointvec_minmax,

                                                .strategy    =
&sysctl_intvec,

                                                .extra1         = &min,

                                                .extra2         = &max

                        },

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "value2",


.data                                     = &value2,


.maxlen                              = sizeof(int),


.mode                                 = 0644,

                                                .proc_handler
= &proc_dointvec_minmax,

                                                .strategy    =
&sysctl_intvec,

                                                .extra1         = &min,

                                                .extra2         = &max

                        },

                        { .ctl_name = 0 }

};



static ctl_table test_net_table1[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "test1",


.mode                                 = 0555,


.child                                   = test_table1

                        },

                        { .ctl_name = 0 }

};



static ctl_table test_net_table2[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "test2",


.mode                                 = 0555,


.child                                   = test_table2

                        },

                        { .ctl_name = 0 }

};



static ctl_table test_root_table1[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "net1",


.mode                                 = 0555,


.child                                   = test_net_table1

                        },

                        { .ctl_name = 0 }

};



static ctl_table test_root_table2[] = {

                        {


.ctl_name                         = CTL_UNNUMBERED,


.procname                       = "net2",


.mode                                 = 0555,


.child                                   = test_net_table2

                        },

                        { .ctl_name = 0 }

};





static struct ctl_path net1_path[] = {

        { .procname = "my_net", .ctl_name = CTL_UNNUMBERED },

        { }

};





static int __init sysctl_module_init(void)

{

                        test_sysctl_header1 =
register_sysctl_paths(net1_path, test_root_table1);

                        test_sysctl_header2 =
register_sysctl_paths(net1_path, test_root_table2);

                        return 0;

}



static void __exit sysctl_module_exit(void)

{

                        unregister_sysctl_table(test_sysctl_header1);

                        unregister_sysctl_table(test_sysctl_header2);

}



module_init(sysctl_module_init);

module_exit(sysctl_module_exit);

MODULE_LICENSE("GPL");



Thanks,

Chaitanya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120221/b349fcb5/attachment-0001.html 


More information about the Kernelnewbies mailing list