RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1160565 - Libvirt should check if the parent defined in xml matches the wwn of vHBA when starting pool
Summary: Libvirt should check if the parent defined in xml matches the wwn of vHBA whe...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.1
Hardware: x86_64
OS: Linux
medium
high
Target Milestone: rc
: ---
Assignee: John Ferlan
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-11-05 07:38 UTC by Yang Yang
Modified: 2015-03-05 07:46 UTC (History)
7 users (show)

Fixed In Version: libvirt-1.2.8-7.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-03-05 07:46:52 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:0323 0 normal SHIPPED_LIVE Low: libvirt security, bug fix, and enhancement update 2015-03-05 12:10:54 UTC

Description Yang Yang 2014-11-05 07:38:23 UTC
Description of problem:
There already exists the vHBA with wwn "2101001b32a90002:2101001b32a90003". Define a 'fc_host' adapter pool with wwn "2101001b32a90002:2101001b32a90003" and a mismatch 'parent'. The pool can be started. However, destroying pool failed. 
With current code, when starting the pool, libvirt will check if the vHBA with same "wwpn:wwpn" already exists and do NOT care about 'parent' defining in xml. It will lead error out when destroying pool because 'parent' mismatches.

Version-Release number of selected component (if applicable):
libvirt-1.2.8-6.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Discover the HBA
# virsh nodedev-list --cap vports
scsi_host4
scsi_host5

2. Create a vHBA using 'scsi_host5' as parent
# cat vHBA.xml
<device>
    <parent>scsi_host5</parent>
    <capability type='scsi_host'>
    <capability type='fc_host'>
    <wwnn>2101001b32a90002</wwnn>
    <wwpn>2101001b32a90003</wwpn>
    <capability type='vport_ops'/>
    </capability>
    </capability>
    </device>
# virsh nodedev-create vHBA.xml
Node device scsi_host6 created from vHBA.xml

3. check the dumpxml
# virsh nodedev-dumpxml scsi_host6
<device>
  <name>scsi_host6</name>
  <path>/sys/devices/pci0000:00/0000:00:0d.0/0000:04:00.1/host5/vport-5:0-0/host6</path>
  <parent>scsi_host5</parent>
  <capability type='scsi_host'>
    <host>6</host>
    <unique_id>6</unique_id>
    <capability type='fc_host'>
      <wwnn>2101001b32a90002</wwnn>
      <wwpn>2101001b32a90003</wwpn>
      <fabric_wwn>2001000dec9877c1</fabric_wwn>
    </capability>
  </capability>
</device>

4. define/start a 'fc_host' pool with a mismatch parent defining in xml
# cat fc-pool.xml
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' parent='scsi_host4' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>   ----> 'parent' is not match. 'scsi_host5' is the right one.
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-define fc-pool.xml
Pool fc-pool defined from fc-pool.xml
# virsh pool-start fc-pool
Pool fc-pool started

# virsh pool-dumpxml fc-pool

<pool type='scsi'>
  <name>fc-pool</name>
  <uuid>312516b7-ce83-4955-bd9f-5e1d5f919d2b</uuid>
  <capacity unit='bytes'>10737418240</capacity>
  <allocation unit='bytes'>10737418240</allocation>
  <available unit='bytes'>0</available>
  <source>
    <adapter type='fc_host' parent='scsi_host4' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
  </source>
  <target>
    <path>/dev/disk/by-path</path>
    <permissions>
      <mode>0700</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

5. destroy the pool
# virsh pool-destroy fc-pool
error: Failed to destroy pool fc-pool
error: Write of '2101001b32a90003:2101001b32a90002' to '/sys/class/fc_host//host4/vport_delete' during vport create/delete failed: No such device

Actual Result:
In step 4. scsi pool can be started when the parent dismatch the wwn defined in xml
In step 5. scsi pool can NOT be destroyed

Expected Result:
In step 4. libvirt should check if the parent defined in xml matches the wwn of vHBA when starting pool

Additional info:
Hi John,
I put the issue I asked in e-mail here because that issue is also related to 'parent' attribute.
As 'parent' attribute is optional, currently I can create a vHBA using 'fc_host' pool NOT using 'parent' attribute. However, when destroying pool the vHBA is NOT destroyed.

Thanks
Yang

Comment 2 John Ferlan 2014-11-05 21:48:35 UTC
Yeah - it seems the "assumption" was that parent would be "valid" if the initial fetch of the name was successful.  What wasn't checked is if the name fetched is the same as the parent. I'm searching for a way to do that, although outside of the nodedev database, I'm not sure how it'll be known.  It's tricky to explain, but there's no direct connection from the storage driver stack to the node_device driver stack in order to make the correllation.

Also, since you mentioned it here and there's not yet a bug on it...

I can reproduce the not able to destroy if no parent is supplied now. It's not quite the same issue, but is one where I believe an assumption by the original coder that the 'parent' value created at startup would be carried over (eg, kept in memory) until shutdown, see:

http://libvirt.org/git/?p=libvirt.git;a=commit;h=f5a610872a5e5e152e438f82949e7928f38747a6

and a later commit:

http://libvirt.org/git/?p=libvirt.git;a=commit;h=b96651dec09850dcc9fdace5a149c06a793f611e

When I add extra debugging I find that the parent is NULL in the deleteVport, thus returning right away and not making the virManagePort() call to delete the vHBA.

Comment 3 Yang Yang 2014-11-06 02:15:26 UTC
(In reply to John Ferlan from comment #2)

> 
> Also, since you mentioned it here and there's not yet a bug on it...
> 
> I can reproduce the not able to destroy if no parent is supplied now. It's
> not quite the same issue, but is one where I believe an assumption by the
> original coder that the 'parent' value created at startup would be carried
> over (eg, kept in memory) until shutdown, see:
> 
> http://libvirt.org/git/?p=libvirt.git;a=commit;
> h=f5a610872a5e5e152e438f82949e7928f38747a6
> 
> and a later commit:
> 
> http://libvirt.org/git/?p=libvirt.git;a=commit;
> h=b96651dec09850dcc9fdace5a149c06a793f611e
> 
> When I add extra debugging I find that the parent is NULL in the
> deleteVport, thus returning right away and not making the virManagePort()
> call to delete the vHBA.

Thanks John.

Opened a separate bug to track the issue.
https://bugzilla.redhat.com/show_bug.cgi?id=1160926

Thanks
Yang

Comment 4 John Ferlan 2014-11-06 16:51:23 UTC
This is proving to be a bit tricky, but I know what has to be done. I suspect the answer to the following is yes, but I'll ask to be sure!  

Should we also be checking that provided parent attribute is vport capable?

Theoretically (in your environment), someone could pass along 'scsi_host3' as the parent along with a valid wwnn/wwpn and currently the code would ignore it.

IOW: there's two errors that need to be fixed here:

#1. Check that the provided 'parent' is a valid FC Host (vport capable)

#2. Check that the provided 'parent' comes from the same source as the wwnn/wwpn. So far, the only way I can figure to do this is query the nodedev database (e.g. the tricky part).

The needs info is just validation of #1 - can you think of any valid reason the incoming parent shouldn't be vport capable.

Comment 5 Yang Yang 2014-11-07 07:24:31 UTC
(In reply to John Ferlan from comment #4)
> This is proving to be a bit tricky, but I know what has to be done. I
> suspect the answer to the following is yes, but I'll ask to be sure!  
> 
> Should we also be checking that provided parent attribute is vport capable?
> 

Yes. It seems that with current code 'parent' attribute would be checked whether it is vport capable. But it does not work well for offline HBA. We also can grep "<capability type='vport_ops'>" from the nodedev-dumpxml for offline HBA. But the <fabric_wwn> of offline HBA is 'ffffffffffffffff' which is quite different from online HBA. So does it deserve to check that provided parent attribute is online?

- An example for providing a non-vport capable host# to 'parent'. It seems libvirt error out.
# virsh pool-create fc-pool.xml 
error: Failed to create pool from fc-pool.xml
error: Requested operation is not valid: vport operation 'vport_create' is not supported for host1


- An example for providing an offline HBA to 'parent'.

scsi_host1 is vport capable but offline

# cat /sys/class/fc_host/host1/port_state 
Linkdown
# virsh nodedev-dumpxml scsi_host1
<device>
  <name>scsi_host1</name>
  <path>/sys/devices/pci0000:00/0000:00:09.0/0000:18:00.0/host1</path>
  <parent>pci_0000_18_00_0</parent>
  <capability type='scsi_host'>
    <host>1</host>
    <unique_id>1</unique_id>
    <capability type='fc_host'>
      <wwnn>20000024ff370478</wwnn>
      <wwpn>21000024ff370478</wwpn>
      <fabric_wwn>ffffffffffffffff</fabric_wwn>
    </capability>
    <capability type='vport_ops'>
      <max_vports>254</max_vports>
      <vports>0</vports>
    </capability>
  </capability>
</device>

create 'fc_host' pool by providing the offline HBA as 'parent'. It leads kernel error out.
# virsh pool-create fc-pool.xml
error: Failed to create pool from fc-pool.xml
error: Write of '2101001b32a90003:2101001b32a90002' to '/sys/class/fc_host//host1/vport_create' during vport create/delete failed: Operation not supported

> Theoretically (in your environment), someone could pass along 'scsi_host3'
> as the parent along with a valid wwnn/wwpn and currently the code would
> ignore it.
> 
> IOW: there's two errors that need to be fixed here:
> 
> #1. Check that the provided 'parent' is a valid FC Host (vport capable)
> 
> #2. Check that the provided 'parent' comes from the same source as the
> wwnn/wwpn. So far, the only way I can figure to do this is query the nodedev
> database (e.g. the tricky part).
> 
> The needs info is just validation of #1 - can you think of any valid reason
> the incoming parent shouldn't be vport capable.

From aspect of qa, it's a negative test. I mean, if a customer know which host# are vport capable, he won't use a non-vport capable as 'parent'.

Comment 6 John Ferlan 2014-11-12 17:42:13 UTC
This was pushed upstream today, commit id's:

844c1d7e3283be652bffddf17254c392d68c405d
42a021c1204d7dcb531f5d476e65b53a8bd4f704

Comment 9 Yang Yang 2014-12-17 07:27:35 UTC
Verified it with libvirt-1.2.8-10.el7.x86_64

1. create fc_host pool, meanwhile genarating vHBA.
# virsh nodedev-list scsi_host
scsi_host0
scsi_host1
scsi_host2
scsi_host3
scsi_host4
scsi_host5

# virsh nodedev-list --cap vports
scsi_host1
scsi_host5

# cat fc-pool.xml 
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' parent='scsi_host5' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-define fc-pool.xml 
Pool fc-pool defined from fc-pool.xml

# virsh pool-start fc-pool
Pool fc-pool started

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              active     no       

# virsh nodedev-list scsi_host
scsi_host0
scsi_host1
scsi_host2
scsi_host3
scsi_host4
scsi_host5
scsi_host6  ---> genated while pool startup

# virsh pool-autostart fc-pool
Pool fc-pool marked as autostarted

# virsh pool-destroy fc-pool
Pool fc-pool destroyed

# virsh nodedev-list scsi_host
scsi_host0
scsi_host1
scsi_host2
scsi_host3
scsi_host4
scsi_host5

# service libvirtd restart
Redirecting to /bin/systemctl restart  libvirtd.service

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              active     yes    

# virsh nodedev-list scsi_host
scsi_host0
scsi_host1
scsi_host2
scsi_host3
scsi_host4
scsi_host5
scsi_host7

# virsh vol-list fc-pool
 Name                 Path                                    
------------------------------------------------------------------------------
 unit:0:2:0           /dev/disk/by-path/pci-0000:04:00.1-fc-0x203600a0b85b5dd4-lun-0

# virsh pool-destroy fc-pool
Pool fc-pool destroyed

# virsh pool-undefine fc-pool
Pool fc-pool has been undefined

2. create fc_host pool with the vHBA ever created by node device driver
> parent matches the wwpn/wwnn
# cat vHBA.xml 
<device>
    <parent>scsi_host5</parent>
    <capability type='scsi_host'>
    <capability type='fc_host'>
    <wwnn>2101001b32a90002</wwnn>
    <wwpn>2101001b32a90003</wwpn>
    <capability type='vport_ops'/>
    </capability>
    </capability>
    </device>

# virsh nodedev-create vHBA.xml 
Node device scsi_host8 created from vHBA.xml

# cat fc-pool.xml 
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' parent='scsi_host5' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-define fc-pool.xml 
Pool fc-pool defined from fc-pool.xml

# virsh pool-start fc-pool
Pool fc-pool started

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              active     no    

# virsh pool-dumpxml fc-pool
<pool type='scsi'>
  <name>fc-pool</name>
  <uuid>41dae1e1-133a-431e-8ef3-1a27b2b2f774</uuid>
  <capacity unit='bytes'>10737418240</capacity>
  <allocation unit='bytes'>10737418240</allocation>
  <available unit='bytes'>0</available>
  <source>
    <adapter type='fc_host' parent='scsi_host5' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
  </source>
  <target>
    <path>/dev/disk/by-path</path>
    <permissions>
      <mode>0700</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

# virsh pool-autostart fc-pool
Pool fc-pool marked as autostarted

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              active     yes

# virsh pool-destroy fc-pool
Pool fc-pool destroyed

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              inactive   yes       

# service libvirtd restart
Redirecting to /bin/systemctl restart  libvirtd.service

# virsh pool-list --all
 Name                 State      Autostart 
-------------------------------------------
 default              active     no        
 fc-pool              active     yes   

# virsh vol-list fc-pool
 Name                 Path                                    
------------------------------------------------------------------------------
 unit:0:2:0           /dev/disk/by-path/pci-0000:04:00.1-fc-0x203600a0b85b5dd4-lun-0

# virsh pool-destroy fc-pool
Pool fc-pool destroyed

# virsh pool-undefine fc-pool
Pool fc-pool has been undefined

> parent mismatches wwpn/wwnn and set managed to 'yes'

# virsh nodedev-dumpxml scsi_host8
<device>
  <name>scsi_host8</name>
  <path>/sys/devices/pci0000:00/0000:00:0d.0/0000:04:00.1/host5/vport-5:0-2/host8</path>
  <parent>scsi_host5</parent>
  <capability type='scsi_host'>
    <host>8</host>
    <unique_id>8</unique_id>
    <capability type='fc_host'>
      <wwnn>2101001b32a90002</wwnn>
      <wwpn>2101001b32a90003</wwpn>
      <fabric_wwn>2001000dec9877c1</fabric_wwn>
    </capability>
  </capability>
</device>

# cat fc-pool.xml 
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' managed='yes' parent='scsi_host1' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-define fc-pool.xml 
Pool fc-pool defined from fc-pool.xml

# virsh pool-start fc-pool
error: Failed to start pool fc-pool
error: XML error: Parent attribute 'scsi_host1' does not match parent 'scsi_host5' determined for the 'host8' wwnn/wwpn lookup.

# virsh pool-undefine fc-pool
Pool fc-pool has been undefined

> parent mismatches wwpn/wwnn and set managed to 'no'
# cat fc-pool.xml 
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' managed='no' parent='scsi_host1' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-define fc-pool.xml 
Pool fc-pool defined from fc-pool.xml

# virsh pool-start fc-pool
error: Failed to start pool fc-pool
error: XML error: Parent attribute 'scsi_host1' does not match parent 'scsi_host5' determined for the 'host8' wwnn/wwpn lookup.

# virsh pool-undefine fc-pool
Pool fc-pool has been undefined

3. create fc_host pool specifying parent with an non-vport-capable card
# cat fc-pool.xml 
<pool type='scsi'>
<name>fc-pool</name>
<source>
<adapter type='fc_host' managed='no' parent='scsi_host2' wwnn='2101001b32a90002' wwpn='2101001b32a90003'/>
</source>
<target>
<path>/dev/disk/by-path</path>
<permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>

# virsh pool-create fc-pool.xml 
error: Failed to create pool from fc-pool.xml
error: XML error: parent 'scsi_host2' specified for vHBA is not vport capable

As all the steps got the expected results, set it to verified

Comment 11 errata-xmlrpc 2015-03-05 07:46:52 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, 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://rhn.redhat.com/errata/RHSA-2015-0323.html


Note You need to log in before you can comment on or make changes to this bug.