From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhlFG-0004Oj-9o for qemu-devel@nongnu.org; Fri, 15 Jul 2011 12:28:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QhlFA-0002TP-Op for qemu-devel@nongnu.org; Fri, 15 Jul 2011 12:28:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhlFA-0002TG-CP for qemu-devel@nongnu.org; Fri, 15 Jul 2011 12:28:00 -0400 Date: Fri, 15 Jul 2011 13:27:45 -0300 From: Luiz Capitulino Message-ID: <20110715132745.332414d0@doriath> In-Reply-To: References: <1310673634-17631-1-git-send-email-mdroth@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [QAPI+QGA 3/3] QEMU Guest Agent (virtagent) v7 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhi Yong Wu Cc: aliguori@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, agl@linux.vnet.ibm.com, Michael Roth , qemu-devel@nongnu.org On Fri, 15 Jul 2011 09:15:18 +0800 Zhi Yong Wu wrote: > On Fri, Jul 15, 2011 at 4:00 AM, Michael Roth = wrote: > > This is Set 3/3 of the QAPI+QGA patchsets. > > > > These patches apply on top of qapi-backport-set2-v6, and can also be ob= tained from: > > git://repo.or.cz/qemu/mdroth.git qapi-backport-set3-v7 > > > > (Set1+2 are a backport of some of the QAPI-related work from Anthony's > > glib tree. The main goal is to get the basic code generation infrastruc= ture in > > place so that it can be used by the guest agent to implement a QMP-like= guest > > interface, and so that future work regarding the QMP conversion to QAPI= can be > > decoupled from the infrastructure bits. Set3 is the Qemu Guest Agent > > (virtagent), rebased on the new code QAPI code generation infrastructur= e. This > > is the first user of QAPI, QMP will follow.) > > ___ > > > > CHANGES SINCE V6: > > =A0- Made "/dev/virtio-ports/org.qemu.guest_agent.0" default device pat= h for agent > > =A0- Consolidated uneeded fcntl() calls into qemu_open() > > =A0- JSON/QMP parse errors now propagated to client > > =A0- Replaced non-assertion uses of g_error() with exit() > > =A0- Added guest-file-flush > > =A0- Removed limit on max read size for guest-file-read > > =A0- 'count' parameters to guest-file-read/guest-file-write are now opt= ional (default to 4KB and size of provided buffer, base64-decoded, respecti= vely) > > =A0- Removed redundant 'file_' and 'shutdown_' prefixes from guest-file= -*/guest-shutdown commands, switched to "-" in place of "_" in parameter na= mes, renamed guest-file-read's "buf" param to "buf-b64" and guest-file-writ= e's "data_b64" param to "buf-b64" for consistency. > > =A0- guest-fsfreeze-freeze now returns error objects on error rather as= part of it's integer return values, and on error will unfreeze previously = frozen filesystems. > > =A0- GUEST_FSFREEZE_STATUS_INPROGRESS removed, GUEST_FSFREEZE_STATUS_ER= ROR now serves the explicit purpose of noting a failure to find a previousl= y mounted filesytem/directory after initial freeze, or failure to unfreeze = 1 or more filesystems. > > =A0- -c/--channel option to qemu-ga is now -m/--method > > > > CHANGES SINCE V5: > > =A0- switched to using qemu malloc/list functions where possible > > =A0- removed unused proxy_path field in struct GAState > > =A0- pid file now opened write-only, removed lockf() in favor of O_EXCL= , added SIGINT/SIGTERM signal handlers to handle cleanup > > =A0- cleaned up error-handling, switched to asserts where appropriate, = removed unecessary gotos and NULL checks for qemu_free()/qobject_decref() > > =A0- refactored send_payload() using helper functions > > =A0- fixed improper handling of pidfile fd=3D=3D0 > > =A0- changed guest-shutdown's "shutdown_mode" param to "mode" > > =A0- switched to using kernel-generated FDs for guest-file-open rather = than an autoincrement value > > =A0- add maximum chunk size of guest-file-read/guest-file-write > > =A0- added checks to avoid guest-file-write from writing data beyond th= e provided data buffer > > =A0- made logging best-effort, removed handling of failures to log as e= rrors > > =A0- guest-shutdown exec errors now logged to guest syslog, clarified s= hutdown's asynchronous, no gauruntee nature in schema. > > > > CHANGES SINCE V4: > > =A0- Removed timeout mechanism via worker thread/pthread_cancel due to = potential memory leak. Will re-introduce guest-side timeout support in futu= re version. > > =A0- Fixed up fsfreeze code to use enums specified within the guest age= nt's qapi schema. > > =A0- Fixed memory leak due to a log statement, and added missing cleanu= p functions for heap-allocated g_error objects. > > =A0- Made "mode" param to guest-file-open optional, defaults to "r" (re= ad-only) > > > > CHANGES SINCE V3: > > =A0- Fixed error-handling issues in fsfreeze commands leading to certai= n mounted directories causing freeze/thaw operations to fail > > =A0- Added cleanup hook to thaw filesystems on graceful guest agent exit > > =A0- Removed unused enum values and added additional details to schema = documentation > > =A0- Fixed build issue that was missed due to deprecated files in sourc= e tree, removed unused includes > > > > CHANGES SINCE V2: > > =A0- Rebased on new QAPI code generation framework > > =A0- Dropped ability for QMP to act as a proxy for the guest agent, wil= l be added when new QMP server is backported from Anthony's glib tree > > =A0- Replaced negotiation/control events with a simple 2-way handshake = implemented by a standard RPC (guest-sync) > > =A0- Removed enforcement of "pristine" sessions, state is now global/pe= rsistant across multiple clients/connections > > =A0- Fixed segfault in logging code > > =A0- Added Jes' filesystem freeze patches > > =A0- General cleanups > > > > CHANGES SINCE V1: > > =A0- Added guest agent worker thread to execute RPCs in the guest. With= this in place we have a reliable timeout mechanism for hung commands, curr= ently set at 30 seconds. > > =A0- Add framework for registering init/cleanup routines for stateful R= PCs to clean up after themselves after a timeout. > > =A0- Added the following RPCs: guest-file-{open,close,read,write,seek},= guest-shutdown, guest-info, and removed stubs for guest-view-file (now dep= recated) > > =A0- Added GUEST_AGENT_UP/GUEST_AGENT_DOWN QMP events > > =A0- Switched to a TCP-style host-initiated 3-way handshake for channel= negotiation, this simplifies client negotiation/interaction over the wire > > =A0- Added configurable log level/log file/pid file options for guest a= gent > > =A0- Various fixes for bugs/memory leaks and checkpatch.pl fixups > > > > ISSUES/TODOS: > > =A0- Add unit tests for guest agent wire protocol > > > > OVERVIEW > > > > For a better overview of what these patches are meant to accomplish, pl= ease reference the RFC for virtagent: > > > > http://comments.gmane.org/gmane.comp.emulators.qemu/96096 > > > > These patches integrate the previous virtagent guest agent work directl= y in QAPI/QMP to leverage it's auto-generated marshalling code. This has nu= merous benefits: > > > > =A0- addresses previous concerns over relying on external libraries to = handle data encapsulation > > =A0- reduces the need for manual unmarshalling of requests/responses, w= hich makes adding new RPCs much safer/less error-prone, as well as cutting = down on redundant code > > =A0- QAPI documentation aligns completely with guest-side RPC implement= ation > > =A0- is Just Better (TM) > > > > BUILD/USAGE > > > > build: > > =A0./configure --target-list=3Dx86_64-softmmu > > =A0make > > =A0make qemu-ga #should be built on|for target guest > HI, Macheal. > Is qemu-ga built in guest? if yes, it will require the guest to set up > a gcc environment. Can we make it built on the host? Yes, if the host OS matches the guest OS or if you can cross-compile. Otherwise I think we'll have to rely on distros making qemu-ga available, and/or use the guest tools iso Michael is planning. Another option would be to compile qemu-ga statically, but this is probably unfeasible. >=20 > > > > start guest: > > =A0qemu \ > > =A0-drive file=3D/home/mdroth/vm/rhel6_64_base.raw,snapshot=3Doff,if=3D= virtio \ > > =A0-net nic,model=3Dvirtio,macaddr=3D52:54:00:12:34:00 \ > > =A0-net tap,script=3D/etc/qemu-ifup \ > > =A0-vnc :1 -m 1024 --enable-kvm \ > > =A0-chardev socket,path=3D/tmp/qga.sock,server,nowait,id=3Dqga0 \ > > =A0-device virtio-serial \ > > =A0-device virtserialport,chardev=3Dqga0,name=3Dorg.qemu.guest_agent.0" > > > > use guest agent: > > =A0./qemu-ga -h > > =A0./qemu-ga -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent= .0 > > > > start/use qmp: > > =A0mdroth@illuin:~$ sudo socat unix-connect:/tmp/qga.sock readline > > =A0{"execute":"guest-sync", "arguments":{"id":1234}} > > =A0{"return": 1234} > > > > =A0{"execute":"guest-ping"} > > =A0{"return": {}} > > > > =A0{"execute": "guest-info"} > > =A0{"return": {"version": "1.0"}} > > > > =A0// write "hello world!\n" to /tmp/testqga > > =A0{"execute":"guest-file-open", "arguments":{"path":"/tmp/testqga","mo= de":"w+"}} > > =A0{"return": 0} > > =A0{"execute":"guest-file-write", "arguments":{"handle":0,"buf-b64":"aG= VsbG8gd29ybGQhCg=3D=3D"}} > > =A0{"return": {"count": 13, "eof": false}} > > =A0{"execute":"guest-file-close", "arguments":{"handle":0}} > > =A0{"return": {}} > > > > =A0// read back the "hello world!\n" from /tmp/testqga > > =A0{"execute":"guest-file-open", "arguments":{"path":"/tmp/testqga","mo= de":"r"}} > > =A0{"return": 1} > > =A0{"execute":"guest-file-read", "arguments":{"handle":1,"count":1024}} > > =A0{"return": {"buf-b64": "aGVsbG8gd29ybGQhCg=3D=3D", "count": 13, "eof= ": true}} > > =A0{"execute":"guest-file-close","arguments":{"handle":1}} > > =A0{"return": {}} > > > > =A0Makefile =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 25 ++- > > =A0configure =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A01 + > > =A0qapi-schema-guest.json =A0 =A0 =A0 =A0 =A0| =A0217 +++++++++++++ > > =A0qemu-ga.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0671 +++++= ++++++++++++++++++++++++++++++++++ > > =A0qerror.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 13 + > > =A0qerror.h =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A06 + > > =A0qga/guest-agent-command-state.c | =A0 73 +++++ > > =A0qga/guest-agent-commands.c =A0 =A0 =A0| =A0512 +++++++++++++++++++++= ++++++++ > > =A0qga/guest-agent-core.h =A0 =A0 =A0 =A0 =A0| =A0 31 ++ > > =A09 files changed, 1544 insertions(+), 5 deletions(-) > > > > > > >=20 >=20 >=20