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

时间:2023-03-09 02:35:21
centos 7.3 安装vmtools,解决无法编译共享文件夹模块

环境说明:

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

大概意思就是由于 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 ;
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函数定义

    int
HgfsWbRequestWait(HgfsWbPage *req) // IN: request of page data to write
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
return wait_on_bit_io(&req->wb_flags,
PG_BUSY,
TASK_UNINTERRUPTIBLE);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
return wait_on_bit(&req->wb_flags,
PG_BUSY,
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
HgfsWbRequestWaitUninterruptible,
#endif
TASK_UNINTERRUPTIBLE);
#else
wait_event(req->wb_queue,
!test_bit(PG_BUSY, &req->wb_flags));
return ;
#endif
}

可以发现在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 函数代码

    int
HgfsWbRequestWait(HgfsWbPage *req) // IN: request of page data to write
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
return wait_on_bit_io(&req->wb_flags,
PG_BUSY,
TASK_UNINTERRUPTIBLE);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
return wait_on_bit(&req->wb_flags,
PG_BUSY,
TASK_UNINTERRUPTIBLE);
#else
wait_event(req->wb_queue,
!test_bit(PG_BUSY, &req->wb_flags));
return ;
#endif
}

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

tar -cvf vmhgfs.tar vmhgfs-only/*

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

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

大家一路回车确认即可