qemu-ga windows下的安装及监控开发

时间:2023-02-10 08:52:17

windows安装qemu-ga

  虚拟机配置里添加virtio serial端口

    #virsh edit instance-name

    devices里添加下面这段配置,

1 <channel type='unix'>
2 <source mode='bind' path='/var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-name.sock'/>
3 <target type='virtio' name='org.qemu.guest_agent.0'/>
4 <address type='virtio-serial' controller='0' bus='0' port='1'/>
5 </channel>

 

安装Qemu Guest Agent服务

  #wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo

  #yum install virtio-win

  安装virtio-win包,virtio-win里包含windows virtio设备驱动,及qemu-ga的安装包。

  qemu-ga windows下的安装及监控开发

  将msi安装文件和virtio-win.iso拷贝到windows下。

  virtio-win.iso包含各个windows版本下的virtio serial驱动,安装对应版本的驱动。

  qemu-ga windows下的安装及监控开发

  安装对应版本qemu-ga.msi,至此,qga安装完毕。

 

qga功能扩展

  搭建编译环境:

  添加功能示例(添加内存使用率检测)

    编辑qapi-schema.json,添加自定义结构体及命令声明。

 1     ##  结构体声明
2 # @GuestMemInfo
3 #
4 # Information about Memory usage.
5 #
6 # @total: total size of Memory
7 #
8 # @usage: Memory usage
9 #
10 # Since 2.6
11 ##
12 { 'struct': 'GuestMemInfo',
13 'data': { 'total': 'int', 'usage': 'int' } }
14
15 ## 命令声明
16 # @guest-get-mem-usage:
17 #
18 # Get the memory utilization rate.
19 #
20 # Returns: @GuestMemInfo on success.
21 #
22 # Since 2.6
23 ##
24 { 'command': 'guest-get-mem-usage',
25 'returns': 'GuestMemInfo' }

 

    在commands-win32.c中添加命令实现:

1 GuestMemInfo *qmp_guest_get_mem_usage(Error **errp)
2 {
3 MEMORYSTATUS ms;
4 GuestMemInfo *meminfo = g_new0(GuestMemInfo, 1);
5 GlobalMemoryStatus(&ms);
6 meminfo->usage = (int64_t)ms.dwMemoryLoad;
7 meminfo->total = (int64_t)ms.dwTotalPhys;
8 return meminfo;
9 }

 

  在commands-posix.c中添加命令实现(直接返回QERR_UNSUPPORTED错误):

1 GuestMemInfo *qmp_guest_get_mem_usage(Error **errp)
2 {
3 error_setg(errp, QERR_UNSUPPORTED);
4 }

 

    重新编译qemu-ga.exe,替换C:\Program Files\qemu-ga下的qemu-ga.exe,重启服务即可。

    (dll依赖,在/usr/x86_64-w64-mingw32/sys-root/mingw/bin/下可找到。)

    qemu-ga windows下的安装及监控开发

 

 

参考文献:

http://wiki.qemu.org/Features/QAPI/GuestAgent

http://wiki.libvirt.org/page/Qemu_guest_agent

http://fedoraproject.org/wiki/Windows_Virtio_Drivers

http://lists.gnu.org/archive/html/qemu-discuss/2014-11/msg00027.html