我编写了一个简单的内核模块,想验证一下内核workqueue的功能。
如下:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/sched.h>
#include <linux/nsproxy.h>
//static struct workqueue_struct *queue=NULL;
//extern int copy_namespaces(unsigned long flags, struct task_struct *tsk);
static struct work_struct work;
static void work_handler(struct work_struct *data)
{
struct task_struct *base_task = find_task_by_vpid(18572);
printk(KERN_ALERT"work handler function.\n");
printk(KERN_ALERT"current--------> %d.\n", current->pid);
//copy_namespaces(CLONE_NEWUTS, current);
get_nsproxy(base_task->nsproxy);
switch_task_namespaces(current, base_task->nsproxy);
}
static int __init test_init(void)
{
//queue=system_unbound_wq
//create_singlethread_workqueue("hello world");/*创建一个单线程的工作队列*/
//if (!queue)
// goto err;
INIT_WORK(&work,work_handler);
queue_work(system_unbound_wq, &work);
return 0;
}
static void __exit test_exit(void)
{
//destroy_workqueue(queue);
printk(KERN_ALERT "caoshufeng module exit");
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);
这是makefile:
obj-m += queue.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
模块make成功,但是无法insomd
dmesg中有如下错误:
[ 9806.426471] queue: Unknown symbol switch_task_namespaces (err 0)
[ 9806.426554] queue: Unknown symbol find_task_by_vpid (err 0)
我已经include了相应的头文件,为啥还是找不到symbol呢?