環境說明:
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
大家一路回車確認即可