On Wed, Nov 04, 2009 at 02:37:26PM +0100, Daniel Veillard wrote:
On Tue, Nov 03, 2009 at 02:49:59PM -0500, Daniel P. Berrange wrote:
> Introduce a new qemuDomainObjPrivate object which is used to store
> the private QEMU specific data associated with each virDomainObjPtr
> instance. This contains a single member, an instance of the new
> qemuMonitorPtr object which encapsulates the QEMU monitor state.
> The internals of the latter are private to the qemu_monitor* files,
> not to be shown to qemu_driver.c
>
> * src/qemu/qemu_conf.h: Definition of qemuDomainObjPrivate.
> * src/qemu/qemu_driver.c: Register a functions for creating
> and freeing qemuDomainObjPrivate instances with the domain
> capabilities. Remove the qemudDispatchVMEvent() watch since
> I/O watches are now handled by the monitor code itself. Pass
> a new qemuHandleMonitorEOF() callback into qemuMonitorOpen
> to allow notification when the monitor quits.
> * src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Introduce
> the 'qemuMonitor' object. Temporarily add new APIs
> qemuMonitorWrite, qemuMonitorRead, qemuMonitorWaitForInput
> to allow text based monitor impl to perform I/O.
> * src/qemu/qemu_monitor_text.c: Call APIs for reading/writing
> to monitor instead of accessing the file handle directly.
[...]
> +int qemuMonitorWriteWithFD(qemuMonitorPtr mon,
> + const char *data,
> + size_t len,
> + int fd)
> +{
> + struct msghdr msg;
> + struct iovec iov[1];
> + ssize_t ret;
> + char control[CMSG_SPACE(sizeof(int))];
> + struct cmsghdr *cmsg;
> +
> + if (!mon->hasSendFD) {
> + errno = EINVAL;
> return -1;
> }
> +
> + memset(&msg, 0, sizeof(msg));
> +
> + iov[0].iov_base = (void *)data;
> + iov[0].iov_len = len;
> +
> + msg.msg_iov = iov;
> + msg.msg_iovlen = 1;
> +
> + msg.msg_control = control;
> + msg.msg_controllen = sizeof(control);
> +
> + cmsg = CMSG_FIRSTHDR(&msg);
> + cmsg->cmsg_len = CMSG_LEN(sizeof(int));
> + cmsg->cmsg_level = SOL_SOCKET;
> + cmsg->cmsg_type = SCM_RIGHTS;
> + memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
> +
> + do {
> + ret = sendmsg(mon->fd, &msg, 0);
> + } while (ret < 0 && errno == EINTR);
> +
> + return ret == len ? 0 : -1;
> +}
I must admit I'm a bit puzzled by this function, we are sending both
data and a file descriptor ? But it's an in-process exchange, why would
that be needed, I'm at loss ...
The need to send a file descriptor is pretty rare. It is only used when
hottplugging network device. libvirt sends the FD of the TAP device
over to QEMU. In all other places this capability is unused.
Regards,
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|