2015-04-28 55 views
3

我在使用我的Linux內核模塊中的工作隊列時遇到問題。 我的模塊編譯時沒有提供任何錯誤,但在加載時失敗。 我無法加載以下模塊並在dmesg中出現跟隨錯誤。Linux內核:無法加載帶有工作隊列的簡單Linux內核模塊

[[email protected] test_mod]# insmod workqueue_test.ko 
insmod: ERROR: could not insert module workqueue_test.ko: Unknown symbol in module 
[[email protected] test_mod]# dmesg -c 
[50404.453417] workqueue_test: Unknown symbol destroy_workqueue (err 0) 
[50404.453437] workqueue_test: Unknown symbol __alloc_workqueue_key (err 0) 
[[email protected] test_mod]# 

以下是模塊代碼: -

1 #include <linux/module.h> 
    2 #include <linux/kernel.h> 
    3 #include <linux/kthread.h> 
    4 #include <linux/blkdev.h> 
    5 #include <linux/fs.h> 
    6 #include <linux/delay.h> 
    7 #include <linux/workqueue.h> 
    8 #include <linux/completion.h> 
    9 
10 
11 #define LOG_ENTRY() \ 
12  do {\ 
13   printk(KERN_INFO "++ %s %d %s\n", __func__, __LINE__,\ 
14           current->comm);\ 
15  } while (0); 
16 
17 #define LOG_INFO() \ 
18  do {\ 
19   printk(KERN_INFO "%s %d %s\n", __func__, __LINE__,\ 
20           current->comm); mdelay(1000);\ 
21  } while (0); 
22 
23 #define LOG_EXIT() \ 
24  do {\ 
25   printk(KERN_INFO "-- %s %d %s\n", __func__, __LINE__,\ 
26           current->comm);\ 
27  } while (0); 
28 
29 
30 void 
31 async_callback(void *data) 
32 { 
33 
34 } 
35 
36 int 
37 init_module(void) 
38 { 
39  struct workqueue_struct *async_queue; 
40 
41  LOG_ENTRY(); 
42  if ((async_queue = create_workqueue("HGST_WORKQUEUE")) == NULL) { 
43   printk(KERN_ERR "failed to create workqueue\n"); 
44   return -1; 
45  }  
46   
47  mdelay(10000); 
48  destroy_workqueue(async_queue); 
49  LOG_EXIT(); 
50  return 0; 
51 } 
52  
53 
54 void 
55 cleanup_module(void) 
56 { 
57  printk(KERN_INFO "Unloading MOdule..\n"); 
58 } 

我也看了成的/ proc/kallsysm由insmod的轉貼未知符號看起來像符號可用以下是輸出: -

[[email protected] test_mod]# cat /proc/kallsyms | grep __alloc_workqueue_key 
ffffffff81084a10 T __alloc_workqueue_key 
ffffffff8187a090 r __ksymtab___alloc_workqueue_key 
ffffffff8188bd70 r __kcrctab___alloc_workqueue_key 
ffffffff81892ba0 r __kstrtab___alloc_workqueue_key 
[[email protected] test_mod]# 

有人可以告訴我可能是什麼問題或者我錯過了什麼嗎?

謝謝。

回答

3

你在你使用GPL符號(使用EXPORT_SYMBOL_GPL出口)的代碼需要

MODULE_LICENSE("GPL"); 

否則模塊加載器根本看不到這樣的符號。

+0

感謝它的工作。 –