Linux内核:无法使用工作队列加载简单的Linux内核模块

3

我在使用 Linux 内核模块中的工作队列时遇到了问题。我的模块编译没有任何错误,但在加载时失败。 我无法加载以下模块,并在 dmesg 中获得以下错误。

[root@nanderson test_mod]# insmod  workqueue_test.ko 
insmod: ERROR: could not insert module workqueue_test.ko: Unknown symbol in module
[root@nanderson 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)
[root@nanderson 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报告的未知符号。看起来这些符号是可用的,以下是输出结果:

[root@nanderson 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
[root@nanderson test_mod]# 

有人能告诉我可能出了什么问题或者我漏掉了什么吗?
谢谢。
1个回答

2

您需要

MODULE_LICENSE("GPL");

在你的代码中使用GPL符号(使用EXPORT_SYMBOL_GPL导出)。

否则,模块加载程序将无法看到这些符号。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接