[libvirt] how libvirt communicate with qemu?

i am reading source code, begin with tracing simple command line ,like virsh list and forth. please look at my qurestions 1.how libvirt communicate with qemu? call qemu'lib or open special device/socket? 2. i do not find the implement of function qemuAgentOpen---->qemuAgentInitialize(). i also search qemu-kvm source 3. qemuListAllDomains is the function which corespond to virsh-list. please explain this function . virDomainList(conn, driver->domains.objs, domains, flags); i) it seems driver->domains.objs have gotten all dmains. so when and where driver->domains.objs is assigned. ii)and what is conn,and its definition? thanks.

On 10/21/2012 03:12 PM, yue wrote:
i am reading source code, begin with tracing simple command line ,like virsh list and forth. please look at my qurestions 1.how libvirt communicate with qemu?
For starters, before diving into code, I'm learning it this way, by tracing all the commands(let it be Qemu's QMP or others) virsh is calling: Place the below log filters in /etc/libvirt/libvirtd.conf. ---- log_filters="1:libvirt 1:qemu_monitor 1:util 1:qemu" log_outputs="1:file:/var/log/libvirt/libvirtd.log" ---- And, monitor /var/log/libvirt/libvirtd.log for all the calls libvirt is making. For your other questions, I'll let more qualified people answer it. /kashyap
call qemu'lib or open special device/socket?
2. i do not find the implement of function qemuAgentOpen---->qemuAgentInitialize(). i also search qemu-kvm source
3. qemuListAllDomains is the function which corespond to virsh-list. please explain this function . virDomainList(conn, driver->domains.objs, domains, flags); i) it seems driver->domains.objs have gotten all dmains. so when and where driver->domains.objs is assigned. ii)and what is conn,and its definition?
thanks.
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 2012年10月21日 17:42, yue wrote:
i am reading source code, begin with tracing simple command line ,like virsh list and forth.
virsh edit is not helpful if you want to known how libvirt communicates with qemu. It's completely implemented in libvirt.
please look at my qurestions 1.how libvirt communicate with qemu? call qemu'lib or open special device/socket?
Yeah, socket.
2. i do not find the implement of function qemuAgentOpen---->qemuAgentInitialize(). i also search qemu-kvm source
ctags, cscope will help you.
3. qemuListAllDomains is the function which corespond to virsh-list. please explain this function . virDomainList(conn, driver->domains.objs, domains, flags); i) it seems driver->domains.objs have gotten all dmains. so when and where driver->domains.objs is assigned. ii)and what is conn,and its definition?
Likewise, using good tools always help you.
thanks.
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 10/21/2012 03:42 AM, yue wrote:
i am reading source code, begin with tracing simple command line ,like virsh list and forth. please look at my qurestions 1.how libvirt communicate with qemu? call qemu'lib or open special device/socket?
Socket. Basically, libvirt pre-creates a Unix socket and hooks that up to the qemu -monitor command line argument, and then sends monitor commands over this socket when libvirt needs to tell qemu to do anything.
2. i do not find the implement of function qemuAgentOpen---->qemuAgentInitialize().
src/qemu/qemu_agent.[ch]
i also search qemu-kvm source
qemu is not a library - searching qemu-kvm source won't find you any of the functions used in libvirt. Rather, all libvirt<->qemu communication is done over sockets.
3. qemuListAllDomains is the function which corespond to virsh-list. please explain this function . virDomainList(conn, driver->domains.objs, domains, flags); i) it seems driver->domains.objs have gotten all dmains. so when and where driver->domains.objs is assigned. ii)and what is conn,and its definition?
src/libvirt.c has a list of all public libvirt API. src/driver.h has a callback structure for all driver implementations. src/qemu/qemu_driver.c installs qemuListAllDomains as the callback for the public function virConnectListAllDomains. conn is therefore the virConnectPtr you get when you open a connection to your specified URI (such as qemu:///system), and that conn pointer has enough information to point to the callback, so that virConnectListAllDomains then forwards into the qemuListAllDomains() function. You also need to understand the architecture of remote calls - remember, when virsh (or any other client) connects to qemu:///system, the local instance of virConnectListAllDomains() happens to call into the RPC driver rather than the qemu driver; that is, the local call is handled by src/remote/remote_driver.c which bundles the API call into an RPC packet. Then, in the libvirtd process, daemon/remote.c unbundles the RPC packet, and turns it back into an API call, but this time with the qemu driver instead of the RPC driver. So understanding the full path of a message requires debugging multiple processes. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (4)
-
Eric Blake
-
Kashyap Chamarthy
-
Osier Yang
-
yue