windows下的qemu-guest-agent(简称qga)的名字叫做qemu-guest-agent-win32,目前最新版的版本号是qemu-guest-agent-win32-0.12.1.2-2.355.el6_4.9.x86_64,下载下来是一个rpm包,在centos6上安装后就会出现qemu-ga.exe和一个readme。可以看出windows下的qga是根据el6(rhel6/centos6)上的qemu-guest-agent编译出来的,而qemu-guest-agent的源码是包含在qemu的源码中的,所以我们只需要下载qemu-kvm.el6版本的源码就可以。qemu-kvm-0.12.1.2-2.355.el6_4.9.x86_64是centos6.4上的qemu-kvm版本,为什么不用centos6.5的qemu-kvm呢,那是因为6.4上的src.rpm包里的specfile是直接可以打包出qemu-guest-agent-win32.rpm的,而6.5的src.rpm包里的specfile是没有这一项的,而且6.5对windows版本仅更新了settime和gettime这两个功能,所以如果只是想快速添加自己的功能,可以直接下centos6.4的qemu-kvm。
4、代码的修改
举例:现在我们加入windows下的文件创建功能。
qapi-schema-guest.json中添加功能名称:
## # @guest-file-create: # # create a file in the guest and retrieve a sign for it # # @filepath: Full path to the file in the guest to create. # # Returns: 0 on success,-1 on failure. # # Since: 0.0.1 ## { 'command': 'guest-file-create', 'data': { 'path': 'str' }, 'returns': 'int' }commands-win32.c中添加功能函数:
int64_t qmp_guest_file_create(const char *path, Error **err) { const char *mode; mode = "wb"; FILE *fh; slog("guest-file-create called, filepath: %s", path); fh = fopen(path, mode); if (NULL == fh) { slog("error on open %s", path); error_set(err, QERR_QGA_COMMAND_FAILED, "fopen() failed"); return -1; } fclose(fh); return 0; }commands-posix.c中添加对应函数,可利用现有error不添加功能。
int64_t qmp_guest_file_create(const char *path, Error **err) { error_set(err, QERR_UNSUPPORTED); return -1; }
利用libvirt创建虚拟机win7,在XML文件device中加入
<channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/test.org.qemu.ga.0'/> <target type='virtio' name='org.qemu.ga.0'/> </channel>
qemu-ga.exe –p \\.\Global\org.qemu.ga.0在宿主机端使用socat来快速连接:
socat \var\lib\libvirt\qemu\test.org.qemu.ga.0 –连上后就可以收发命令了
{“execute”:”guest-file-create”,”arguments”:{“path”:”c:\\test.txt”}}如果成功会收到return 0的返回,并且c:\test.txt创建成功。qemu-ga由于是c语言写的,linux下实现的很多功能可以直接拷贝到windows下使用,修改起来还是很方便的。
5、参考
exe(rpm)下载路径:http://linuxsoft.cern.ch/cern/slc64/x86_64/yum/updates/repoview/qemu-guest-agent-win32.html 源码下载路径:http://nl.mirror.eurid.eu/centos-vault/6.4/updates/Source/SPackages/ 参考文献1:http://wiki.qemu.org/Features/QAPI/GuestAgent 参考文献2:http://blog.csdn.net/hbsong75/article/details/9465683 参考文献3:http://www.cnblogs.com/biangbiang/p/3222458.html