QEMU Guest Agent

It is a daemon program running inside the domain which is supposed to help management applications with executing functions which need assistance of the guest OS. For example, freezing and thawing filesystems, entering suspend. However, guest agent (GA) is not bullet proof, and hostile guest OS can send spurious replies.

 

Setting QEMU GA up

Currently, QEMU exposes GA via virtio serial port. There are some attempts to allow applications to use qemu monitor for communication with GA, but virtio serial port should remain supported. These are internals, though.

To be able to use GA users needs to create virtio serial port with special name org.qemu.guest_agent.0. In other words, one needs to add this to his/her domain XML under <devices>:

<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>

If you use libvirt 1.0.6 or newer, you can omit the path='...' attribute of the <source> element, and libvirt will manage things automatically on your behalf.

 

Usage

Libvirt does not guarantee any support of direct use of the guest agent. If you don't mind using libvirt-qemu.so, you can use the virDomainQemuAgentCommand API (exposed by virsh qemu-agent-command); but be aware that this is unsupported, and any changes you make to the agent that change state behind libvirt's back may cause libvirt to misbehave. Meanwhile, the guest agent may be used internally by several supported libvirt APIs, often by passing flags to request its use. For example, virDomainShutdownFlags supports:

VIR_DOMAIN_SHUTDOWN_DEFAULT        = 0,
VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1 << 0),
VIR_DOMAIN_SHUTDOWN_GUEST_AGENT = (1 << 1),

Simmilar applies for the reboot API:

VIR_DOMAIN_REBOOT_DEFAULT        = 0,
VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1 << 0),
VIR_DOMAIN_REBOOT_GUEST_AGENT = (1 << 1),

In virsh, users can select shutdown/reboot method via --mode acpi|agent:

virsh reboot --mode agent $DOMAIN
virsh shutdown --mode agent $DOMAIN

If users is creating snapshots he/she might want to freeze before and thaw filesystems after. This can be done by specifying VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE flag to virDomainSnapshotCreate API or:

virsh snapshot-create --quiesce $DOMAIN
virsh snapshot-create-as --quiesce $DOMAIN

in virsh.

Warning: Like any monitor command, GA commands can block indefinitely esp. when GA is not running. Currently, there is no reliable method/API to tell if GA is running. Libvirt implements some basic check to determine if there is a qemu-ga instance running or not. Basically a guest-sync command is issued prior every useful command. If it returns, then libvirt considers guest agent up and running and issues the real command. However, guest agent can die or be terminated meanwhile. The guest-sync command is issued with a timeout which if hit guest agent is considered as not present.

 

Configure guest agent without libvirt interference

In some cases, users might want to configure a guest agent in their domain XML but don't want libvirt to connect to guest agent socket at all. Because libvirt connects to a guest agent channel if and only if it is a virtio channel with org.qemu.guest_agent.0 name, all one need to do is void at least one of these conditions. However, the most feasible way is to change the target's name:

<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/>
<target type='virtio' name='org.qemu.guest_agent.1'/>
</channel>

If you do change name, you'll need to tell it to qemu GA as well:

 # qemu-ga -p /dev/virtio-ports/$name
 

Guest requirements

One thing has been already mentioned - the domain configuration for virtio serial port. However, guest must have the GA installed. Fortunately, it is already distributed as rpm, so all one needs to do is:

yum install qemu-guest-agent
 

Related links

If you want to read further:

 

QEMU Guest Agent的更多相关文章

  1. 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...

  2. KVM 介绍(7):使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照 (Nova Instances Snapshot Libvirt)

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

  3. 使用QEMU创建虚拟机

    下载安装: wget http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2 tar xjvf qemu- ./configure --ena ...

  4. KVM(七)使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照

    本文将梳理 QEMU/KVM 快照相关的知识,以及在 OpenStack Nova 中使用 libvirt 来对 QEMU/KVM 虚机做快照的过程. 1. QEMU/KVM 快照 1.1 概念 QE ...

  5. KVM 虚拟化 初体验

    KVM 是 Kernel-based Virtual Machine 的简称,是 Linux 下 x86 硬件平台上的全功能虚拟化解决方案: 使用 KVM ,可允许运行多个虚拟机,包括 Linux 和 ...

  6. 对consistencygroup的一些研究和实践

    声明: 本博客欢迎转载,但请保留原作者信息! 作者:李人可 团队:华为杭州OpenStack团队 consistency group,直译是一致性组,是Juno版本号cinder新引进的一个概念.顾名 ...

  7. (转)如何阅读OpenStack源码

    1 关于该项目 本项目使用在线绘图工具web sequencediagrams完成,目标是图形化OpenStack的所有操作流程,通过操作序列图能快速学习Openstack的工作原理,理清各个组件的关 ...

  8. 开源虚拟化KVM(一)搭建部署与概述

    一,KVM概述 1.1 虚拟化概述 在计算机技术中,虚拟化意味着创建设备或资源的虚拟版本,如服务器,存储设备,网络或者操作系统等等 [x] 虚拟化技术分类: 系统虚拟化(我们主要讨论的反向) 存储虚拟 ...

  9. 【Linux】Cent OS 虚拟机开机自启动配置

    一次断电,导致实体机关机了,虚拟机也连不上去,只好手动来起来. 我想增加一下自启动,让硬件开机的时候,自动启动虚拟机: 其实是有办法的,尝试了一下,也成功了,这里简单标记下. virsh autost ...

随机推荐

  1. mapreduce 输入输出类型

    默认的mapper是IdentityMapper,默认的reducer是IdentityReducer,它们将输入的键和值原封不动地写到输出中. 默认的partitioner是HashPartitin ...

  2. 介绍开源的.net通信框架NetworkComms

    Networkcomms 是一款C# 语言编写的TCP/UDP通信框架  作者是英国人  以前是收费的 目前作者已经开源  开源地址是:https://github.com/MarcFletcher/ ...

  3. wordpress 中禁止更新提示

    前言: 在此之前每每打开blog的时候总是有那么个数字在那边显示,如果是很重要的更新显示在那也就算了,有时候就算一个破主题他还一直在那边,很是让小猪纠结.最关键的是要是更新了主题,那么之前所有自定义的 ...

  4. java之socket

    socket系java中网络编程的内容. 1客户端: package com.wtd.socket; import java.io.BufferedReader; import java.io.IOE ...

  5. java软件设计的三层结构

    接口: package dao; public interface Dao { String getData(); } package biz; import dao.Dao; public inte ...

  6. js 数组去除空值

    for(var i = 0 ;i<wordarr.length;i++)                {                    if(wordarr[i] == "& ...

  7. Andriod——区别DVM与JVM

    区别DVM与JVM 1.首要差别 Dalvik: 基于寄存器,编译和运行都会更快些 JVM: 基于栈, 编译和运行都会慢些 2.字节码的区别 Dalvik: 执行.dex格式的字节码,是对.class ...

  8. Oracle连接的若干错误

    用PL/SQL连接Oracle时会抛若干错误,如下: 1.ora-12154:TNS:无法解析指定的连接标识符 答:plsql在%Oracle_Home%\Network\Admin或者c:\inst ...

  9. IT公司100题-14-排序数组中和为给定值的两个数字

    问题描述: 输入一个升序排序的数组,给定一个目标值target,求数组的两个数a和b,a+b=target.如果有多个组合满足这个条件,输出任意一对即可. 例如,输入升序数组[1, 3, 4, 5, ...

  10. MonoRail学习:可重复组件ViewComponents的使用

    在MonoRail中我们可以定义一些可重用的组件,在其他需要使用的页面引入这个组件就可以了.有点相当于.NET中的自定义控件,可以节约代码,方便开发,提高重用性. 在MonoRail中把这一功能叫做V ...