私はカーネルコーディングが初めてです。以下のように、カーネル モジュールでワークキューを定義しました。
struct sk_buff_head *g_temp =NULL;
struct workqueue_struct *myqueue; // pointer to your workqueue
void dowork( struct work_struct *data ); // your function.s prototype
DECLARE_DELAYED_WORK( mywork, dowork );
void dowork( struct work_struct *data )
{
printk("\nInside dowork \n");
if(g_temp !=NULL)
{
printk("\n g_temp not NULL\n");
skb_queue_purge(g_temp);
kfree(g_temp);
g_temp = NULL;
}
printk("\n\n I am doing the delayed work right now \n");
queue_delayed_work( myqueue, &mywork, 5000);
}
static int __init my_init(void)
{
myqueue = create_workqueue("mywork");
if ( !queue_delayed_work( myqueue, &mywork, 5000 ) )
return 0;
}
static void __exit my_exit(void)
{
cancel_delayed_work(&mywork); /* no "new ones" */
flush_workqueue(myqueue); /* wait till all "old ones" finished */
destroy_workqueue(myqueue);
}
そして、メモリは次のような別の関数に割り当てられます。
static unsigned int
packet(struct sk_buff *in_skb)
{
g_temp = kzalloc(sizeof(struct sk_buff_head), GFP_ATOMIC);
if( NULL == g_temp)
{
kfree_skb(new_skb);
}
skb_queue_head_init(g_temp);
skb_queue_tail(g_temp, new_skb);
}
私の主なアイデアは、着信パケットを sk_buff_head にキューイングし、5 sce 後にパケットをフラッシュすることです。しかし、それは以下の結果を投げています:
BUG: sleeping function called from invalid context at arch/x86/mm/fault.c
in_atomic(): 0, irqs_disabled(): 1, pid: 4632, name: sh
Pid: 4632, comm: sh Not tainted 2.6.33.3-85.fc13.i686.PAE #1
Call Trace:
[<c042f827>] __might_sleep+0xc5/0xcc
[<c078503b>] do_page_fault+0x1b4/0x2fa
[<c0784e87>] ? do_page_fault+0x0/0x2fa
[<c07832df>] error_code+0x73/0x78
[<c04c86f7>] ? kmem_cache_alloc_notrace+0x78/0xa2
[<c04e44cf>] ? single_open+0x1f/0x90
[<c050b8e4>] ? meminfo_proc_show+0x0/0x3b8
[<c04e44cf>] single_open+0x1f/0x90
[<c050b8e2>] meminfo_proc_open+0x11/0x13
[<c05069bd>] proc_reg_open+0xae/0x111
[<c04e407b>] ? single_release+0x0/0x1f
[<c04cf2e6>] __dentry_open+0x155/0x245
[<c04cf46f>] nameidata_to_filp+0x2c/0x40
[<c050690f>] ? proc_reg_open+0x0/0x111
[<c04d9f34>] do_filp_open+0x440/0x827
[<c05a6680>] ? might_fault+0x19/0x1b
[<c05a675d>] ? strncpy_from_user+0x33/0x4f
[<c04e14f9>] ? alloc_fd+0x53/0xb9
[<c04cf09b>] do_sys_open+0x48/0xdf
[<c0785154>] ? do_page_fault+0x2cd/0x2fa
[<c04cf174>] sys_open+0x1e/0x26
[<c040885f>] sysenter_do_call+0x12/0x28
BUG: unable to handle kernel NULL pointer dereference at 0000022a
IP: [<c04c86f7>] kmem_cache_alloc_notrace+0x78/0xa2
*pdpt = 000000000cad7001 *pde = 0000000000000000