From: "Michael S. Tsirkin" <mst@redhat.com>
To: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Cc: libvir-list@redhat.com, izumi.taku@jp.fujitsu.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC 4/7] qemu-agent: add qemuAgentCreateBond interface
Date: Tue, 19 May 2015 11:13:43 +0200 [thread overview]
Message-ID: <20150519111209-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <8c75b9fdf0d95c02292507e50abe3176f414bf3a.1429256889.git.chen.fan.fnst@cn.fujitsu.com>
On Fri, Apr 17, 2015 at 04:53:06PM +0800, Chen Fan wrote:
> via initialize callback to create bond device.
>
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> ---
> src/qemu/qemu_agent.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_agent.h | 10 ++++
> src/qemu/qemu_domain.c | 70 ++++++++++++++++++++++++++++
> src/qemu/qemu_domain.h | 7 +++
> src/qemu/qemu_process.c | 4 ++
> 5 files changed, 209 insertions(+)
>
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index cee0f8b..b8eba01 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -2169,3 +2169,121 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
>
> goto cleanup;
> }
> +
> +static virDomainInterfacePtr
> +findInterfaceByMac(virDomainInterfacePtr *info,
> + size_t len,
> + const char *macstr)
> +{
> + size_t i;
> + bool found = false;
> +
> + for (i = 0; i < len; i++) {
> + if (info[i]->hwaddr &&
> + STREQ(info[i]->hwaddr, macstr)) {
> + found = true;
> + break;
> + }
> + }
> +
> + if (found) {
> + return info[i];
> + }
> +
> + return NULL;
> +}
> +
I think PCI addresses are a better way to identify the devices
for this purpose. This will mean softmac doesn't break this
functionality.
See anything wrong with it?
> +/*
> + * qemuAgentSetInterface:
> + */
> +int
> +qemuAgentCreateBond(qemuAgentPtr mon,
> + virDomainHostdevSubsysPCIPtr pcisrc)
> +{
> + int ret = -1;
> + virJSONValuePtr cmd = NULL;
> + virJSONValuePtr reply = NULL;
> + size_t i;
> + char macstr[VIR_MAC_STRING_BUFLEN];
> + virDomainInterfacePtr *interfaceInfo = NULL;
> + virDomainInterfacePtr interface;
> + virJSONValuePtr new_interface = NULL;
> + virJSONValuePtr subInterfaces = NULL;
> + virJSONValuePtr subInterface = NULL;
> + int len;
> +
> + if (!(pcisrc->nmac || pcisrc->macs))
> + return ret;
> +
> + len = qemuAgentGetInterfaces(mon, &interfaceInfo);
> + if (len < 0)
> + return ret;
> +
> + if (!(new_interface = virJSONValueNewObject()))
> + goto cleanup;
> +
> + if (virJSONValueObjectAppendString(new_interface, "type", "bond") < 0)
> + goto cleanup;
> +
> + if (virJSONValueObjectAppendString(new_interface, "name", "bond0") < 0)
> + goto cleanup;
> +
> + if (virJSONValueObjectAppendString(new_interface, "onboot", "onboot") < 0)
> + goto cleanup;
> +
> + if (!(subInterfaces = virJSONValueNewArray()))
> + goto cleanup;
> +
> + for (i = 0; i < pcisrc->nmac; i++) {
> + virMacAddrFormat(&pcisrc->macs[i], macstr);
> + interface = findInterfaceByMac(interfaceInfo, len, macstr);
> + if (!interface) {
> + goto cleanup;
> + }
> +
> + if (!(subInterface = virJSONValueNewObject()))
> + goto cleanup;
> +
> + if (virJSONValueObjectAppendString(subInterface, "name", interface->name) < 0)
> + goto cleanup;
> +
> + if (virJSONValueArrayAppend(subInterfaces, subInterface) < 0)
> + goto cleanup;
> +
> + subInterface = NULL;
> + }
> +
> + if (i && virJSONValueObjectAppend(new_interface, "subInterfaces", subInterfaces) < 0)
> + goto cleanup;
> +
> + cmd = qemuAgentMakeCommand("guest-network-set-interface",
> + "a:interface", new_interface,
> + NULL);
> +
> + if (!cmd)
> + goto cleanup;
> +
> + subInterfaces = NULL;
> + new_interface = NULL;
> +
> + if (qemuAgentCommand(mon, cmd, &reply, true,
> + VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
> + goto cleanup;
> +
> + if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("malformed return value"));
> + }
> +
> + cleanup:
> + virJSONValueFree(subInterfaces);
> + virJSONValueFree(subInterface);
> + virJSONValueFree(new_interface);
> + virJSONValueFree(cmd);
> + virJSONValueFree(reply);
> + if (interfaceInfo)
> + for (i = 0; i < len; i++)
> + virDomainInterfaceFree(interfaceInfo[i]);
> + VIR_FREE(interfaceInfo);
> + return ret;
> +}
> diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
> index 42414a7..744cb0a 100644
> --- a/src/qemu/qemu_agent.h
> +++ b/src/qemu/qemu_agent.h
> @@ -97,6 +97,13 @@ struct _qemuAgentCPUInfo {
> bool offlinable; /* true if the CPU can be offlined */
> };
>
> +typedef struct _qemuAgentInterfaceInfo qemuAgentInterfaceInfo;
> +typedef qemuAgentInterfaceInfo *qemuAgentInterfaceInfoPtr;
> +struct _qemuAgentInterfaceInfo {
> + char *name;
> + char *hardware_address;
> +};
> +
> int qemuAgentGetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr *info);
> int qemuAgentSetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr cpus, size_t ncpus);
> int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
> @@ -114,4 +121,7 @@ int qemuAgentSetTime(qemuAgentPtr mon,
> int qemuAgentGetInterfaces(qemuAgentPtr mon,
> virDomainInterfacePtr **ifaces);
>
> +int qemuAgentCreateBond(qemuAgentPtr mon,
> + virDomainHostdevSubsysPCIPtr pcisrc);
> +
> #endif /* __QEMU_AGENT_H__ */
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 603360f..584fefb 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -2722,6 +2722,46 @@ qemuDomainCleanupRun(virQEMUDriverPtr driver,
> priv->ncleanupCallbacks_max = 0;
> }
>
> +/*
> + * The vm must be locked when any of the following init functions is
> + * called.
> + */
> +int
> +qemuDomainInitAdd(virDomainObjPtr vm,
> + qemuDomainInitCallback cb)
> +{
> + qemuDomainObjPrivatePtr priv = vm->privateData;
> + size_t i;
> +
> + VIR_DEBUG("vm=%s, cb=%p", vm->def->name, cb);
> +
> + for (i = 0; i < priv->nInitCallbacks; i++) {
> + if (priv->initCallbacks[i] == cb)
> + return 0;
> + }
> +
> + if (VIR_RESIZE_N(priv->initCallbacks,
> + priv->nInitCallbacks_max,
> + priv->nInitCallbacks, 1) < 0)
> + return -1;
> +
> + priv->initCallbacks[priv->nInitCallbacks++] = cb;
> + return 0;
> +}
> +
> +void
> +qemuDomainInitCleanup(virDomainObjPtr vm)
> +{
> + qemuDomainObjPrivatePtr priv = vm->privateData;
> +
> + VIR_DEBUG("vm=%s", vm->def->name);
> +
> + VIR_FREE(priv->cleanupCallbacks);
> + priv->ncleanupCallbacks = 0;
> + priv->ncleanupCallbacks_max = 0;
> +}
> +
> +
> static void
> qemuDomainGetImageIds(virQEMUDriverConfigPtr cfg,
> virDomainObjPtr vm,
> @@ -3083,3 +3123,33 @@ qemuDomainSupportsBlockJobs(virDomainObjPtr vm,
>
> return 0;
> }
> +
> +void
> +qemuDomainPrepareHostdevInit(virDomainObjPtr vm)
> +{
> + qemuDomainObjPrivatePtr priv = vm->privateData;
> + virDomainDefPtr def = vm->def;
> + int i;
> +
> + if (!def->nhostdevs)
> + return;
> +
> + if (!qemuDomainAgentAvailable(vm, false))
> + return;
> +
> + if (!virDomainObjIsActive(vm))
> + return;
> +
> + for (i = 0; i < def->nhostdevs; i++) {
> + virDomainHostdevDefPtr hostdev = def->hostdevs[i];
> + virDomainHostdevSubsysPCIPtr pcisrc = &hostdev->source.subsys.u.pci;
> +
> + if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
> + hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO &&
> + hostdev->source.subsys.u.pci.device == VIR_DOMAIN_HOSTDEV_PCI_DEVICE_BOND) {
> + qemuDomainObjEnterAgent(vm);
> + qemuAgentCreateBond(priv->agent, pcisrc);
> + qemuDomainObjExitAgent(vm);
> + }
> + }
> +}
> diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
> index 19f4b27..3244ca0 100644
> --- a/src/qemu/qemu_domain.h
> +++ b/src/qemu/qemu_domain.h
> @@ -403,6 +403,10 @@ void qemuDomainCleanupRemove(virDomainObjPtr vm,
> void qemuDomainCleanupRun(virQEMUDriverPtr driver,
> virDomainObjPtr vm);
>
> +int qemuDomainInitAdd(virDomainObjPtr vm,
> + qemuDomainInitCallback cb);
> +void qemuDomainInitCleanup(virDomainObjPtr vm);
> +
> extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
> extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
> extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
> @@ -444,4 +448,7 @@ void qemuDomObjEndAPI(virDomainObjPtr *vm);
> int qemuDomainAlignMemorySizes(virDomainDefPtr def);
> void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);
>
> +void
> +qemuDomainPrepareHostdevInit(virDomainObjPtr vm);
> +
> #endif /* __QEMU_DOMAIN_H__ */
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index fcc0566..0a72aca 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -4444,6 +4444,9 @@ int qemuProcessStart(virConnectPtr conn,
> hostdev_flags) < 0)
> goto cleanup;
>
> + if (qemuDomainInitAdd(vm, qemuDomainPrepareHostdevInit))
> + goto cleanup;
> +
> VIR_DEBUG("Preparing chr devices");
> if (virDomainChrDefForeach(vm->def,
> true,
> @@ -5186,6 +5189,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
> VIR_QEMU_PROCESS_KILL_NOCHECK));
>
> qemuDomainCleanupRun(driver, vm);
> + qemuDomainInitCleanup(vm);
>
> /* Stop autodestroy in case guest is restarted */
> qemuProcessAutoDestroyRemove(driver, vm);
> --
> 1.9.3
>
next prev parent reply other threads:[~2015-05-19 9:13 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-17 8:53 [Qemu-devel] [RFC 0/7] Live Migration with Pass-through Devices proposal Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 1/7] qemu-agent: add agent init callback when detecting guest setup Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 2/7] qemu: add guest init event callback to do the initialize work for guest Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 3/7] hostdev: add a 'bond' type element in <hostdev> element Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 4/7] qemu-agent: add qemuAgentCreateBond interface Chen Fan
2015-05-19 9:13 ` Michael S. Tsirkin [this message]
2015-05-29 7:37 ` Michal Privoznik
2015-04-17 8:53 ` [Qemu-devel] [RFC 5/7] hostdev: add parse ip and route for bond configure Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 6/7] migrate: hot remove hostdev at perform phase for bond device Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 7/7] migrate: add hostdev migrate status to support hostdev migration Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 0/3] add support migration with passthrough device Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 1/3] qemu-agent: add guest-network-set-interface command Chen Fan
2015-05-21 13:52 ` Olga Krishtal
2015-05-21 14:43 ` [Qemu-devel] [libvirt] " Eric Blake
2015-04-17 8:53 ` [Qemu-devel] [RFC 2/3] qemu-agent: add guest-network-delete-interface command Chen Fan
2015-04-17 8:53 ` [Qemu-devel] [RFC 3/3] qemu-agent: add notify for qemu-ga boot Chen Fan
2015-04-21 23:38 ` Eric Blake
2015-04-19 22:29 ` [Qemu-devel] [libvirt] [RFC 0/7] Live Migration with Pass-through Devices proposal Laine Stump
2015-04-22 4:22 ` Chen Fan
2015-04-23 14:14 ` Laine Stump
2015-04-23 8:34 ` Chen Fan
2015-04-23 15:01 ` Laine Stump
2015-05-19 9:10 ` Michael S. Tsirkin
2015-04-22 9:23 ` [Qemu-devel] " Daniel P. Berrange
2015-04-22 13:05 ` Daniel P. Berrange
2015-04-22 17:01 ` Dr. David Alan Gilbert
2015-04-22 17:06 ` Daniel P. Berrange
2015-04-22 17:12 ` Dr. David Alan Gilbert
2015-04-22 17:15 ` Daniel P. Berrange
2015-04-22 17:20 ` Dr. David Alan Gilbert
2015-04-23 16:35 ` [Qemu-devel] [libvirt] " Laine Stump
2015-05-19 9:04 ` Michael S. Tsirkin
2015-05-19 9:07 ` [Qemu-devel] " Michael S. Tsirkin
2015-05-19 14:15 ` [Qemu-devel] [libvirt] " Laine Stump
2015-05-19 14:21 ` Daniel P. Berrange
2015-05-19 15:03 ` Dr. David Alan Gilbert
2015-05-19 15:18 ` Michael S. Tsirkin
2015-05-19 15:35 ` Daniel P. Berrange
2015-05-19 15:39 ` Michael S. Tsirkin
2015-05-19 15:45 ` Daniel P. Berrange
2015-05-19 16:08 ` Michael S. Tsirkin
2015-05-19 16:13 ` Daniel P. Berrange
2015-05-19 16:27 ` Dr. David Alan Gilbert
2015-05-19 15:21 ` Michael S. Tsirkin
2015-05-19 15:14 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150519111209-mutt-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=chen.fan.fnst@cn.fujitsu.com \
--cc=izumi.taku@jp.fujitsu.com \
--cc=libvir-list@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).