From: Joao Martins <joao.m.martins@oracle.com>
To: Jim Fehlig <jfehlig@suse.com>, libvir-list@redhat.com
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH v2 2/2] libxl: implement virDomainInterfaceStats
Date: Wed, 02 Dec 2015 13:02:40 +0000 [thread overview]
Message-ID: <565EEBF0.7000007@oracle.com> (raw)
In-Reply-To: <565E3F25.3070004@suse.com>
On 12/02/2015 12:45 AM, Jim Fehlig wrote:
> On 11/23/2015 11:57 AM, Joao Martins wrote:
>> Introduce support for domainInterfaceStats API call for querying
>> network interface statistics. Consequently it also enables the
>> use of `virsh domifstat <dom> <interface name>` command plus
>> seeing the interfaces names instead of "-" when doing
>> `virsh domiflist <dom>`.
>>
>> After successful guest creation we fill the network
>> interfaces names based on domain, device id and append suffix
>> if it's emulated in the following form: vif<domid>.<devid>[-emu].
>
> One interesting Xen behavior that has existing for many, many years is that a PV
> nic is implicitly created for each emulated nic specified in the config. The
> guest OS picks which one to use. These days most will use the PV nic, and if
> they are nice, "unplug" the emulated one via the unplug protocol. E.g. an HVM
> guest with
>
> <interface type='bridge'>
> <source bridge='br0'/>
> <mac address='00:16:3e:7a:35:ce'/>
> <script path='/etc/xen/scripts/vif-bridge'/>
> </interface>
>
> results in two vif devices on the host
>
> # ip a | grep vif
> 607: vif519.0-emu: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
> master br0 state UNKNOWN group default qlen 500
> 608: vif519.0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
> master br0 state UNKNOWN group default qlen 512
>
> both are connected to the bridge
>
> # brctl show br0
> bridge name bridge id STP enabled interfaces
> br0 8000.001e676598f5 no eth0
> vif519.0
> vif519.0-emu
>
> In this case, the (not nice) guest OS is using the PV nic but did not unplug the
> emulated one. So we have two interfaces, but the virDomainDef only contains one
>
> # virsh domiflist 519
> Interface Type Source Model MAC
> -------------------------------------------------------
> vif519.0-emu bridge br0 - 00:16:3e:7a:35:ce
>
> Not a fault of this patch, but we'll need to figure out how to handle the
> implicitly created PV nic. The interesting case is identifying emulated nics
> that have been unplugged by a nice guest, and hence no longer exist in the host
> (e.g. vif519.0-emu in the above example).
>
Indeed this is an issue I am aware of but wasn't sure on how to handle it. The
way I test an HVM guest on libvirt with a (explicitly created) PV nic was with
"model=netfront" since there wouldn't be an emulated nic. So perhaps we could
differ it if this was specified on HVM guests. If that wasn't the case we would
add the complementary interface along with checking if indeed the net device
exists. On cleanup we would just delete the second interface that would appear
with the same name.
>> We extract the network interfaces info from libxl in
>> libxlDomainStartCallback() and make ifname . On domain
>> cleanup we also clear ifname, in case it was set by libvirt (i.e.
>> being prefixed with "vif"). We also skip these two steps in case the name
>> of the interface was manually inserted by the adminstrator.
>>
>> For getting the interface statistics we resort to virNetInterfaceStats
>> and let libvirt handle the platform specific nits. Note that the latter
>> is not yet supported in FreeBSD.
>>
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>> Changes since v3:
>> - Use libxl_device_nic_list() for getting each network interface
>> devid in DomainStartCallback.
>> - Improve error reporting by appropriately setting the right error
>> when no interface is known.
>> - Do not unlock vm if libxlDomainObjEndJob() returns false
>> - Set vm->def->net[i]->ifname on DomainStartCallback instead of
>> DomainStart.
>> - Change commit message reflecting the changes on the previous
>> item and mention correct interface names when doing domiflist.
>>
>> Changes since v2:
>> - Clear ifname if it's autogenerated, since otherwise will persist
>> on successive domain starts. Change commit message reflecting this
>> change.
>>
>> Changes since v1:
>> - Fill <virDomainNetDef>.ifname after domain start with generated
>> name from libxl based on domain id and devid returned by libxl.
>> After that path validation don interfaceStats is enterily based
>> on ifname pretty much like the other drivers.
>> - Modify commit message reflecting the changes mentioned in
>> the previous item.
>> - Bump version to 1.2.22
>> ---
>> src/libxl/libxl_domain.c | 29 +++++++++++++++++++++++++++
>> src/libxl/libxl_driver.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 81 insertions(+)
>>
>> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
>> index a7267b0..141f241 100644
>> --- a/src/libxl/libxl_domain.c
>> +++ b/src/libxl/libxl_domain.c
>> @@ -728,6 +728,17 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
>> }
>> }
>>
>> + if ((vm->def->nnets)) {
>> + ssize_t i;
>
> size_t
>
Apologies for the typo.
>> +
>> + for (i = 0; i < vm->def->nnets; i++) {
>> + virDomainNetDefPtr net = vm->def->nets[i];
>> +
>> + if (STRPREFIX(net->ifname, "vif"))
>> + VIR_FREE(net->ifname);
>> + }
>> + }
>> +
>> if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) > 0) {
>> if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
>> VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
>> @@ -857,6 +868,8 @@ static void
>> libxlDomainStartCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
>> {
>> virDomainObjPtr vm = for_callback;
>> + libxl_device_nic *nics;
>> + int nnics;
>> size_t i;
>>
>> virObjectLock(vm);
>> @@ -883,6 +896,22 @@ libxlDomainStartCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
>> VIR_FREE(console);
>> }
>> }
>> +
>> + if ((nics = libxl_device_nic_list(ctx, ev->domid, &nnics)) != NULL) {
>> + for (i = 0; i < vm->def->nnets && i < nnics; i++) {
>> + virDomainNetDefPtr net = vm->def->nets[i];
>> + libxl_device_nic *x_nic = &nics[i];
>> + const char *suffix =
>> + x_nic->nictype != LIBXL_NIC_TYPE_VIF ? "-emu" : "";
>> +
>> + if (net->ifname)
>> + continue;
>> +
>> + if (virAsprintf(&net->ifname, "vif%d.%d%s",
>> + ev->domid, x_nic->devid, suffix) < 0)
>> + continue;
>> + }
>> + }
>
> As mentioned in my reply to 1/2, I think we should simply create the names after
> a successful libxl_domain_create_{new,restore}. Aside from the implicit PV nic
> issue, the patch works for me with the below diff squashed in. What do you think
> of this change? Does it work for you?
>
Looks great, Perhaps just changing the version to 1.3.0 since it's no longer 1.2.22.
Regards,
Joao
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index b3987b9..aa81570 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5472,7 +5472,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
#endif
.nodeGetFreeMemory = libxlNodeGetFreeMemory, /* 0.9.0 */
.nodeGetCellsFreeMemory = libxlNodeGetCellsFreeMemory, /* 1.1.1 */
- .domainInterfaceStats = libxlDomainInterfaceStats, /* 1.2.22 */
+ .domainInterfaceStats = libxlDomainInterfaceStats, /* 1.3.0 */
.domainMemoryStats = libxlDomainMemoryStats, /* 1.3.0 */
.domainGetCPUStats = libxlDomainGetCPUStats, /* 1.3.0 */
.connectDomainEventRegister = libxlConnectDomainEventRegister, /* 0.9.0 */
> Regards,
> Jim
>
>
> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
> index b45cd27..086406b 100644
> --- a/src/libxl/libxl_domain.c
> +++ b/src/libxl/libxl_domain.c
> @@ -729,7 +729,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
> }
>
> if ((vm->def->nnets)) {
> - ssize_t i;
> + size_t i;
>
> for (i = 0; i < vm->def->nnets; i++) {
> virDomainNetDefPtr net = vm->def->nets[i];
> @@ -868,8 +868,6 @@ static void
> libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
> {
> virDomainObjPtr vm = for_callback;
> - libxl_device_nic *nics;
> - int nnics;
> size_t i;
>
> virObjectLock(vm);
> @@ -897,25 +895,35 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void
> *for_callback)
> }
> }
>
> - if ((nics = libxl_device_nic_list(ctx, ev->domid, &nnics)) != NULL) {
> - for (i = 0; i < vm->def->nnets && i < nnics; i++) {
> - virDomainNetDefPtr net = vm->def->nets[i];
> - libxl_device_nic *x_nic = &nics[i];
> - const char *suffix =
> - x_nic->nictype != LIBXL_NIC_TYPE_VIF ? "-emu" : "";
> -
> - if (net->ifname)
> - continue;
> -
> - if (virAsprintf(&net->ifname, "vif%d.%d%s",
> - ev->domid, x_nic->devid, suffix) < 0)
> - continue;
> - }
> - }
> virObjectUnlock(vm);
> libxl_event_free(ctx, ev);
> }
>
> +/*
> + * Create interface names for the network devices in parameter def.
> + * Names are created with the pattern 'vif<domid>.<devid><suffix>'.
> + * devid is extracted from the network devices in the d_config
> + * parameter. User-provided interface names are skipped.
> + */
> +static void
> +libxlDomainCreateIfaceNames(virDomainDefPtr def, libxl_domain_config *d_config)
> +{
> + size_t i;
> +
> + for (i = 0; i < def->nnets && i < d_config->num_nics; i++) {
> + virDomainNetDefPtr net = def->nets[i];
> + libxl_device_nic *x_nic = &d_config->nics[i];
> + const char *suffix =
> + x_nic->nictype != LIBXL_NIC_TYPE_VIF ? "-emu" : "";
> +
> + if (net->ifname)
> + continue;
> +
> + ignore_value(virAsprintf(&net->ifname, "vif%d.%d%s",
> + def->id, x_nic->devid, suffix));
> + }
> +}
> +
>
> /*
> * Start a domain through libxenlight.
> @@ -1056,6 +1064,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
> virDomainObjPtr vm,
> if (libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW))
> goto cleanup_dom;
>
> + libxlDomainCreateIfaceNames(vm->def, &d_config);
>
> if ((dom_xml = virDomainDefFormat(vm->def, 0)) == NULL)
> goto cleanup_dom;
> j
>
next prev parent reply other threads:[~2015-12-02 13:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1448305020-22680-1-git-send-email-joao.m.martins@oracle.com>
2015-11-23 18:56 ` [PATCH v2 1/2] libxl: rename libxlConsoleCallback Joao Martins
2015-11-23 18:57 ` [PATCH v2 2/2] libxl: implement virDomainInterfaceStats Joao Martins
[not found] ` <1448305020-22680-2-git-send-email-joao.m.martins@oracle.com>
2015-12-02 0:08 ` [PATCH v2 1/2] libxl: rename libxlConsoleCallback Jim Fehlig
[not found] ` <565E3695.3060607@suse.com>
2015-12-02 13:02 ` Joao Martins
[not found] ` <1448305020-22680-3-git-send-email-joao.m.martins@oracle.com>
2015-12-02 0:45 ` [PATCH v2 2/2] libxl: implement virDomainInterfaceStats Jim Fehlig
[not found] ` <565E3F25.3070004@suse.com>
2015-12-02 13:02 ` Joao Martins [this message]
2015-12-02 18:50 ` Jim Fehlig
[not found] ` <565F3D81.8080308@suse.com>
2015-12-02 19:26 ` Joao Martins
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=565EEBF0.7000007@oracle.com \
--to=joao.m.martins@oracle.com \
--cc=jfehlig@suse.com \
--cc=libvir-list@redhat.com \
--cc=xen-devel@lists.xen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.