help on inter module communication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hello group,

 i am new to kernel programming. i want to have a communication between
 two modules. i found out from
http://kernelnewbies.org/documents/kdoc/kernel-api/x7404.html that
 inter module communication can be acheived. i am trying out the inter
module communciation and i find that i send info from one module(say
module A) to the another(say module B) and make changes to the values in
module A. the values in module B reflect post chances?. is there any
other way that two modules can communicate in such a way thatthat the
infomation is queued.


 i am sending my code and the output i got. can anyone tell me what
 went wrong.


 can anyone tell me if i can use EXPORT_SYMBOLS to achecive communication
between the modules.


 thanks in advance


 gkgodava


 output:


 Hello, world - this is the kernel speaking :: foo 10 bar 100
 Hello 1, world - this is the kernel speaking :: foo 123 bar 321
 Hello 2, world - this is the kernel speaking :: foo 123 bar 321


 expected output
 Hello, world - this is the kernel speaking :: foo 10 bar 100
 Hello 1, world - this is the kernel speaking :: foo 10 bar 100


 /**************************hello.h**********************************/


 typedef struct {


 int fooptr;


 int barptr;


 } my_type_t;


 /**************************end of hello.h**************************/


 /******************module 1*************************************/


 /* The necessary header files */


 /* Standard in kernel modules */


 /* Deal with CONFIG_MODVERSIONS */


 my_type_t mydata;


 /* Initialize the module */


 int init_module()


 {


 mydata.fooptr = 10;


 mydata.barptr = 100;


 printk("Hello, world - this is the kernel speaking :: foo %d bar %d
 n",


 mydata.fooptr, mydata.barptr);


 inter_module_register(MY_STRING, THIS_MODULE, &mydata);


 (void) inter_module_put(MY_STRING);


 mydata.fooptr = 123;


 mydata.barptr = 321;


 /* If we return a non zero value, it means that


 * init_module failed and the kernel module


 * can't be loaded */


 return 0;


 }


 /* Cleanup - undid whatever init_module did */


 void cleanup_module()


 {


 inter_module_unregister(MY_STRING);


 printk("Short is the life of a kernel module n");


 }


 MODULE_LICENSE("GPL");


 /*******************end of module 1 *********************************/


 /******************module 1*************************************/


 /* Standard in kernel modules */


 /* Deal with CONFIG_MODVERSIONS */


 my_type_t *dataptr;


 int *modified;


 /* Initialize the module */


 int init_module()


 {


 int foo;


 int bar;


 dataptr = (my_type_t *)inter_module_get(MY_STRING);


 foo = dataptr->fooptr;


 bar = dataptr->barptr;


 printk("Hello 1, world - this is the kernel speaking :: foo %d bar


 %d n",foo,bar);


 (void)inter_module_put(MY_STRING);


 dataptr = (my_type_t *)inter_module_get(MY_STRING);


 foo = dataptr->fooptr;


 bar = dataptr->barptr;


 printk("Hello 2, world - this is the kernel speaking :: foo %d bar


 %d n",foo,bar);


 /* If we return a non zero value, it means that


 * init_module failed and the kernel module


 * can't be loaded */


 return 0;


 }


 /* Cleanup - undid whatever init_module did */


 void cleanup_module()


 {


 printk("Short is the life of a kernel module n");


 }


 MODULE_LICENSE("GPL");


 /*******************end of module 1 *********************************/




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux