Bug 1837495

Summary: [detach-device][s390x] can't detach virtio interface device by its address only (no mac)
Product: Red Hat Enterprise Linux 8 Reporter: smitterl
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: smitterl
Severity: low Docs Contact:
Priority: medium    
Version: 8.3CC: bfiuczyn, cohuck, jdenemar, jsuchane, jtomko, lcapitulino, thuth, virt-maint
Target Milestone: rcKeywords: Automation, Patch, Triaged
Target Release: 8.4   
Hardware: s390x   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-6.0.0-29.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-18 15:21:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
libvirtd debug log none

Description smitterl 2020-05-19 14:46:49 UTC
Created attachment 1689905 [details]
libvirtd debug log

Description of problem:
Can't detach interface specified by its address but not mac


Version-Release number of selected component (if applicable):
libvirt-6.0.0-19.module+el8.2.1+6538+c148631f.s390x

How reproducible:
100%

Preconditions
Guest has two interfaces of same type but on different addresses, e.g.
A. Given iface.xml = 
<interface type='network'>
      <source network='default'/>
      <model type='virtio'/>
</interface>
B. Run virsh attach-device vm iface.xml twice on vm (previously without any interface devices).

Steps to Reproduce:
1. Add iface address of one of the interfaces to iface.xml, e.g.
<interface type='network'>
      <source network='default'/>
      <model type='virtio'/>
      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0009'/>
</interface>
2. virsh detach-device vm iface.xml

Actual results:
error: Failed to detach device from iface.xml
error: operation failed: multiple matching devices found

Expected results:
Device detached successfully

Additional info:
1. The ccw addresses in dumpxml after B. were confirmed to be different (interfaces correctly attached)
2. Expected result can be established when running steps on x86_64 using pci type address.
3. Using <mac/> instead of <address/> in step 1. leads to correct results
4. libvirtd.log indicates src/conf/domain_conf.c->virDomainNetFindIdx is involved but that code makes explicit reference only to PCI:
int
virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
{
...
    bool PCIAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI);
 
    for (i = 0; i < def->nnets; i++) {
...
        if (PCIAddrSpecified &&
            !virPCIDeviceAddressEqual(&def->nets[i]->info.addr.pci,
                                      &net->info.addr.pci))
            continue;
 
        if (matchidx >= 0) {
            /* there were multiple matches on mac address, and no
             * qualifying guest-side PCI address was given, so we must
             * fail (NB: a USB address isn't adequate, since it may
             * specify only vendor and product ID, and there may be
             * multiples of those.
             */
            if (MACAddrSpecified) {
                virReportError(VIR_ERR_OPERATION_FAILED,
                               _("multiple devices matching MAC address %s found"),
                               virMacAddrFormat(&net->mac, mac));
            } else {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                               _("multiple matching devices found"));
            }
 
            return -1;
        }
 
        matchidx = i;
    }
 
    if (matchidx < 0) {
        if (MACAddrSpecified && PCIAddrSpecified) {
            virReportError(VIR_ERR_DEVICE_MISSING,
...
        } else if (PCIAddrSpecified) {
            virReportError(VIR_ERR_DEVICE_MISSING,
...
        } else if (MACAddrSpecified) {
            virReportError(VIR_ERR_DEVICE_MISSING,
                           _("no device matching MAC address %s found"),
                           virMacAddrFormat(&net->mac, mac));
        } else {
            virReportError(VIR_ERR_DEVICE_MISSING, "%s",
                           _("no matching device found"));
        }
    }
    return matchidx;
}

Comment 2 Cornelia Huck 2020-09-24 12:11:34 UTC
Proposed upstream patch:
https://www.redhat.com/archives/libvir-list/2020-September/msg01359.html

Comment 3 Ján Tomko 2020-09-24 12:18:34 UTC
Pushed upstream:
commit 2fefbd03ab09f32b1b15d093096fa44870817751
Author:     Cornelia Huck <cohuck>
CommitDate: 2020-09-24 13:48:31 +0200

    virDomainNetFindIdx: add support for CCW addresses
    
    Allow to match with CCW addresses in addition to PCI addresses
    (and MAC addresses).
    
    Signed-off-by: Cornelia Huck <cohuck>
    Reviewed-by: Ján Tomko <jtomko>
    Signed-off-by: Ján Tomko <jtomko>

git describe: v6.7.0-344-g2fefbd03ab

Comment 9 smitterl 2020-11-04 16:46:38 UTC
Verified with:
libvirt-6.0.0-29.module+el8.4.0+8389+a260c754.s390x

Manual:

Steps:
s. Description

Actual result:

stdout: Device detached successfully
virsh dumpxml confirms correct iface (out of the two) was detached


Automation (name includes "pci" but is actually type agnostic, i.e. ccw type is used):

# avocado run --vt-type libvirt --vt-machine-type s390-virtio --vt-connect-uri qemu:///system virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test
JOB ID     : 21d192389b6e69bf50f44d450685f16b13b74b89
JOB LOG    : /root/avocado/job-results/job-2020-11-04T11.32-21d1923/job.log
 (1/5) type_specific.io-github-autotest-libvirt.virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test.by_pci: PASS (88.74 s)
 (2/5) type_specific.io-github-autotest-libvirt.virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test.by_mac_pci: PASS (89.00 s)
 (3/5) type_specific.io-github-autotest-libvirt.virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test.by_mac: PASS (92.14 s)
 (4/5) type_specific.io-github-autotest-libvirt.virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test.by_wrong_mac: PASS (91.04 s)
 (5/5) type_specific.io-github-autotest-libvirt.virtual_network.iface_hotplug.at_device.iface_attach.model_virtio.detach_match_test.by_wrong_pci: PASS (90.38 s)
RESULTS    : PASS 5 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 452.94 s

Comment 11 errata-xmlrpc 2021-05-18 15:21:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: virt:rhel and virt-devel:rhel security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2021:1762