/* Just for fun and basic usage of list and spinlock, caution , No clean up written*/
#include linux/module.h
#include linux/kernel.h
#include linux/moduleparam.h
#include linux/slab.h
static LIST_HEAD(sys_list);
struct system {
struct list_head node;
char name[10];
struct list_head phy;
spinlock_t phy_lock;
};
struct physical {
struct list_head node;
char m_name[10];
};
int add_list(char *name) {
struct system *sys;
sys= kmalloc(sizeof(struct system), GFP_KERNEL);
strcpy(sys->name,name);
INIT_LIST_HEAD(&sys->phy);
list_add(&(sys->node), &sys_list);
}
#include linux/module.h
#include linux/kernel.h
#include linux/moduleparam.h
#include linux/slab.h
static LIST_HEAD(sys_list);
struct system {
struct list_head node;
char name[10];
struct list_head phy;
spinlock_t phy_lock;
};
struct physical {
struct list_head node;
char m_name[10];
};
int add_list(char *name) {
struct system *sys;
sys= kmalloc(sizeof(struct system), GFP_KERNEL);
strcpy(sys->name,name);
INIT_LIST_HEAD(&sys->phy);
list_add(&(sys->node), &sys_list);
}
int add_phylist(char *key, char *data) {
int i = 0;
struct system *itr;
list_for_each_entry(itr, &sys_list, node) {
if (strcmp(itr->name,key) == 0) {
spin_lock(&itr->phy_lock);
for (i=0 ; i<3 comment-3--="" i="">3>
struct physical *phy;
phy = kmalloc(sizeof(struct physical), GFP_KERNEL);
strcpy(phy->m_name,"abcd");
list_add(&(phy->node) , &(itr->phy));
}
spin_unlock(&itr->phy_lock);
}
}
}
int phyaddr_ret(struct list_head **head, char *key) {
struct system *itr;
list_for_each_entry(itr, &sys_list, node) {
if (strcmp(itr->name,key) == 0) {
*head = &(itr->phy);
}
}
}
void myexit(){
printk("Exit");
}
int myinit(){
add_list("karthu");
add_list("Abhi");
add_phylist("karthu","M1");
struct system *itr;
struct physical *phy_itr;
list_for_each_entry(itr, &sys_list, node) {
printk ("%s", itr->name);
list_for_each_entry(phy_itr, &(itr->phy), node) {
printk ("%s", phy_itr->m_name);
}
}
printk ("----");
struct list_head *head;
phyaddr_ret(&head, "karthu");
list_for_each_entry(phy_itr, head, node) {
printk ("%s", phy_itr->m_name);
}
printk("Hello");
return 0;
}
module_exit(myexit);
module_init(myinit);