qemu-guest-agent windows下的监控开发
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
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' }
- 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;
- }
- int64_t qmp_guest_file_create(const char *path, Error **err)
- {
- error_set(err, QERR_UNSUPPORTED);
- return -1;
- }
修改代码后打包替换掉SOURCES中的tar.gz包,会生成新的rpm包或者直接在BUILD中qemu-kvm-win32-build下拷贝qemu-ga.exe。
利用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 \var\lib\libvirt\qemu\test.org.qemu.ga.0 –
- {“execute”:”guest-file-create”,”arguments”:{“path”:”c:\\test.txt”}}
6、已有功能
目前qga最新版本为1.5.50,linux已经实现下面的所有功能,windows仅支持加*的那些功能:
Ø guest-sync-delimited*:宿主机发送一个int数字给qga,qga返回这个数字,并且在后续返回字符串响应中加入ascii码为0xff的字符,其作用是检查宿主机与qga通信的同步状态,主要用在宿主机上多客户端与qga通信的情况下客户端间切换过程的状态同步检查,比如有两个客户端A、B,qga发送给A的响应,由于A已经退出,目前B连接到qga的socket,所以这个响应可能被B收到,如果B连接到socket之后,立即发送该请求给qga,响应中加入了这个同步码就能区分是A的响应还是B的响应;在qga返回宿主机客户端发送的int数字之前,qga返回的所有响应都要忽略;
Ø guest-sync*:与上面相同,只是不在响应中加入0xff字符;
Ø guest-ping*:Ping the guest agent, a non-error return implies success;
Ø guest-get-time*:获取虚拟机时间(返回值为相对于1970-01-01 in UTC,Time in nanoseconds.);
Ø guest-set-time*:设置虚拟机时间(输入为相对于1970-01-01 in UTC,Time in nanoseconds.);
Ø guest-info*:返回qga支持的所有命令;
Ø guest-shutdown*:关闭虚拟机(支持halt、powerdown、reboot,默认动作为powerdown);
Ø guest-file-open:打开虚拟机内的某个文件(返回文件句柄);
Ø guest-file-close:关闭打开的虚拟机内的文件;
Ø guest-file-read:根据文件句柄读取虚拟机内的文件内容(返回base64格式的文件内容);
Ø guest-file-write:根据文件句柄写入文件内容到虚拟机内的文件;
Ø guest-file-seek:Seek to a position in the file, as with fseek(), and return the current file position afterward. Also encapsulates ftell()'s functionality, just Set offset=0, whence=SEEK_CUR;
Ø guest-file-flush:Write file changes bufferred in userspace to disk/kernel buffers;
Ø guest-fsfreeze-status:Get guest fsfreeze state. error state indicates;
Ø guest-fsfreeze-freeze:Sync and freeze all freezable, local guest filesystems;
Ø guest-fsfreeze-thaw:Unfreeze all frozen guest filesystems;
Ø guest-fstrim:Discard (or "trim") blocks which are not in use by the filesystem;
Ø guest-suspend-disk*:Suspend guest to disk;
Ø guest-suspend-ram*:Suspend guest to ram;
Ø guest-suspend-hybrid:Save guest state to disk and suspend to ram(This command requires the pm-utils package to be installed in the guest.);
Ø guest-network-get-interfaces:Get list of guest IP addresses, MAC addresses and netmasks;
Ø guest-get-vcpus:Retrieve the list of the guest's logical processors;
guest-set-vcpus:Attempt to reconfigure (currently: enable/disable) logical processors inside the guest。
7、参考
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
参考:http://blog.csdn.net/hbsong75/article/details/9465683
参考:http://www.csdn123.com/html/itweb/20130729/27101_27081_27076.htm
更多推荐



所有评论(0)