您的位置:首页 > 运维架构 > Linux

centos 7.3 安装vmtools,解决无法编译共享文件夹模块

2017-05-04 17:17 519 查看
环境说明:

vmware 12.5.0 build-4352439

centos 7.3.1611 64位,内核版本:Linux version 3.10.0-514.16.1.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) )

在安装vmtools 时,编译共享文件时会报错,错误信息如下:

/tmp/modconfig-xkFtz3/vmhgfs-only/page.c: 在函数‘HgfsWbRequestWait’中:
/tmp/modconfig-xkFtz3/vmhgfs-only/page.c:1649:23: 警告:传递‘wait_on_bit’的第 3 个参数时将指针赋给整数,未作类型转换 [默认启用]
TASK_UNINTERRUPTIBLE);
^
In file included from include/linux/mmzone.h:9:0,
from include/linux/gfp.h:5,
from include/linux/mm.h:9,
from include/linux/pagemap.h:7,
from /tmp/modconfig-xkFtz3/vmhgfs-only/page.c:28:
include/linux/wait.h:1044:1: 附注:需要类型‘unsigned int’,但实参的类型为‘int (*)(void *)’
wait_on_bit(void *word, int bit, unsigned mode)
^
/tmp/modconfig-xkFtz3/vmhgfs-only/page.c:1649:23: 错误:提供给函数‘wait_on_bit’的实参太多
TASK_UNINTERRUPTIBLE);
^
In file included from include/linux/mmzone.h:9:0,
from include/linux/gfp.h:5,
from include/linux/mm.h:9,
from include/linux/pagemap.h:7,
from /tmp/modconfig-xkFtz3/vmhgfs-only/page.c:28:
include/linux/wait.h:1044:1: 附注:在此声明
wait_on_bit(void *word, int bit, unsigned mode)
^
make[2]: *** [/tmp/modconfig-xkFtz3/vmhgfs-only/page.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[1]: *** [_module_/tmp/modconfig-xkFtz3/vmhgfs-only] 错误 2
make[1]: 离开目录“/usr/src/kernels/3.10.0-514.16.1.el7.x86_64”
make: *** [vmhgfs.ko] 错误 2


大概意思就是由于 vmhgfs-only/page.c 文件中1649 行出现了wait_on_bit函数调用错误,传递的实参太多了

查看include/linux/wait.h 的文件,该文件为操作系统的头文件,在我个人机器上全路径为/usr/src/kernels/3.10.0-514.el7.x86_64/include/linux/wait.h。

wait_on_bit 函数的定义如下

wait_on_bit(void *word, int bit, unsigned mode)
{
if (!test_bit(bit, word))
return 0;
return out_of_line_wait_on_bit(word, bit,
bit_wait,
mode);
}


我们再翻看page.c 的源码,page.c 源码在 /opt/vmware-tools-distrib/lib/modules/source/vmhgfs.tar 压缩文件中。

大家可以直接解压

解压命令为

tar -xvf vmhgfs.tar


查看page.c 文件

vi /opt/vmware-tools-distrib/lib/modules/source/vmhgfs-only/page.c


查看page.c 1649 行这个HgfsWbRequestWait函数定义

1636 int
1637 HgfsWbRequestWait(HgfsWbPage *req)  // IN: request of page data to write
1638 {
1639 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
1640    return wait_on_bit_io(&req->wb_flags,
1641                          PG_BUSY,
1642                          TASK_UNINTERRUPTIBLE);
1643 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
1644    return wait_on_bit(&req->wb_flags,
1645                       PG_BUSY,
1646 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
1647                       HgfsWbRequestWaitUninterruptible,
1648 #endif
1649                       TASK_UNINTERRUPTIBLE);
1650 #else
1651    wait_event(req->wb_queue,
1652               !test_bit(PG_BUSY, &req->wb_flags));
1653    return 0;
1654 #endif
1655 }


可以发现在1649 行,程序在调用wait_on_bit 函数时,当 LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13) 并且 LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) 时,会为 wait_on_bit 函数传递 4 个参数,不符合wait_on_bit 函数的定义。

所以到这里解决的方式就很简单了,只要将第三个参数人为去掉就可以了,修改后的HgfsWbRequestWait 函数代码

1636 int
1637 HgfsWbRequestWait(HgfsWbPage *req)  // IN: request of page data to write
1638 {
1639 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
1640    return wait_on_bit_io(&req->wb_flags,
1641                          PG_BUSY,
1642                          TASK_UNINTERRUPTIBLE);
1643 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
1644    return wait_on_bit(&req->wb_flags,
1645                       PG_BUSY,
1646                       TASK_UNINTERRUPTIBLE);
1647 #else
1648    wait_event(req->wb_queue,
1649               !test_bit(PG_BUSY, &req->wb_flags));
1650    return 0;
1651 #endif
1652 }


然后大家再对修改后的 vmhgfs-only 源码文件夹重新打包,打包命令如下

tar -cvf vmhgfs.tar vmhgfs-only/*


然后大家重新安装vmtools 软件就可以了,安装命令

/opt/vmware-tools-distrib/vmware-install.pl


大家一路回车确认即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐