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 1377212 - libvirt: SCSI: hostdev / controller host-plug related fixes
Summary: libvirt: SCSI: hostdev / controller host-plug related fixes
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks: 1380309
TreeView+ depends on / blocked
 
Reported: 2016-09-19 08:32 UTC by Kashyap Chamarthy
Modified: 2017-01-30 14:01 UTC (History)
8 users (show)

Fixed In Version: libvirt-2.0.0-1.el7
Doc Type: Bug Fix
Doc Text:
Previously, hot plugging a SCSI device to a guest with no usable SCSI controller failed. This update ensures that the automatic addition of the SCSI controller is performed in the correct order, and the SCSI hot plug now works properly in the described circumstances.
Clone Of:
: 1380309 (view as bug list)
Environment:
Last Closed: 2016-11-03 18:54:47 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Attach two SCSI disks to a SCSI controller '2'. The smaller controller indices '1' and '0' should be automatically created. (1.16 KB, application/x-shellscript)
2016-09-19 12:41 UTC, Kashyap Chamarthy
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2577 0 normal SHIPPED_LIVE Moderate: libvirt security, bug fix, and enhancement update 2016-11-03 12:07:06 UTC

Description Kashyap Chamarthy 2016-09-19 08:32:44 UTC
The below fixes are by an OpenStack Nova customer to be included in RHEL 7.3 (and RHEL 7.2.z), in context of this bug[x]:

    http://libvirt.org/git/?p=libvirt.git;a=commit;h=105794c -- qemu:
    Automatic SCSI controller creation in SCSI disk hotplug broken

    http://libvirt.org/git/?p=libvirt.git;a=commit;h=12ec22b -- qemu: 
    SCSI hostdev hot-plug: Fix automatic creation of SCSI controllers


[x] https://bugzilla.redhat.com/show_bug.cgi?id=1343302 -- libvirt Could 
not find scsi controller with index 1 required for device

Comment 1 Kashyap Chamarthy 2016-09-19 08:55:01 UTC
A related fix (that was submitted as part of a patch series[1] upstream, along with the patch "qemu: SCSI hostdev hot-plug: Fix automatic creation of SCSI controllers")

commit 696ab0a1256a2c6a726005e30ea9f1ee4536334e
Author: Marc Hartmayer <mhartmay.ibm.com>
Date:   Mon Jun 27 16:43:46 2016 +0200

    qemu: hot-plug: Fix broken SCSI disk hot-plug
    
    The commit "qemu: hot-plug: Assume support for -device in
    qemuDomainAttachSCSIDisk" dropped the code for the automatic SCSI
    controller creation used in SCSI disk hot-plugging. If we are
    hot-plugging a SCSI disk to a domain and there is no proper SCSI
    controller defined, it results in an "error: internal error: Could not
    find scsi controller with index X required for device" error.
    
    For that reason reverting a hunk of the commit
    d4d32005d6e8b2cc0a2f26b483ca1de10171db6d.
    
    This patch also adds an extra comment to the code to clarify the
    loop.

[1] http://www.redhat.com/archives/libvir-list/2016-June/msg02053.html

Comment 3 Kashyap Chamarthy 2016-09-19 12:40:25 UTC
Description of the problem
--------------------------

When you hot-plug SCSI disks on a second SCSI controller, attaching the
the SCSI disks will fail, because the controllers with smaller indices
(1 and 0) are not auto-generated.

With these patches, it will succeed.

Steps to reproduce the issue
----------------------------

I attached the test script, which can be used to test with and without
these patches.

(I've tested from Git Master, here's the result.)


(1) Start and ensure the guest is running:

    $ sudo ./run ./tools/virsh start cvm1
    $ sudo ./run ./tools/virsh list
     Id    Name                           State
    ----------------------------------------------------
     6     cvm1                           running
    
(2) Enumerate the current block device in use:

    $ sudo ./run ./tools/virsh domblklist cvm1
    Target     Source
    ------------------------------------------------
    vda        /export/vmimages/sn1.qcow2
    
(3) Check for existing SCSI controller devices for the guest (there are
    none):

    $ sudo ./run ./tools/virsh dumpxml cvm1 | grep controller.*scsi
    $ echo $?
    1
    
(4) Run the script attached (which attaches two SCSI disks on SCSI
    controller '2')

    $ ./attach-scsi-device.bash

With a libvirt _without_ these patches, step (4) will fail with:

    error: Failed to attach device
    error: internal error: Could not find scsi controller with index X required for device

* * *

With the fixes mentioned in the description of the bug, step (4) will succeed.  And, you can verify that with:

(5) Now, again, numerate the block devices in use by the guest:

    $ sudo ./run ./tools/virsh domblklist cvm1
    Target     Source
    ------------------------------------------------
    vda        /export/vmimages/sn1.qcow2
    sdb        /export/vmimages/b.raw
    sdc        /export/vmimages/c.raw
    
(6) Verify the existence of SCSI controller devices (now you see, SCSI
    controller indexes, 0,1,2):

    $ sudo ./run ./tools/virsh dumpxml cvm1 | grep controller.*scsi
        <controller type='scsi' index='0'>
        <controller type='scsi' index='1'>
        <controller type='scsi' index='2'>

(7) Verify that SCSI controller the two disks ('sdb', and 'sdc') are
    indeed attached to SCSI controller '2':

    $ sudo ./run ./tools/virsh dumpxml cvm1 | grep scsi
          <target dev='sdb' bus='scsi'/>
          <alias name='scsi2-0-2'/>
          <target dev='sdc' bus='scsi'/>
          <alias name='scsi2-0-3'/>
        <controller type='scsi' index='0'>
          <alias name='scsi0'/>
        <controller type='scsi' index='1'>
          <alias name='scsi1'/>
        <controller type='scsi' index='2'>
          <alias name='scsi2'/>

Comment 4 Kashyap Chamarthy 2016-09-19 12:41:48 UTC
Created attachment 1202473 [details]
Attach two SCSI disks to a SCSI controller '2'.  The smaller controller indices '1' and '0' should  be automatically created.

Comment 5 Ján Tomko 2016-09-19 13:26:13 UTC
Fixed upstream for SCSI disk by:
commit 105794cd434d815e483f87732f2084f55ae62c42
Author:     Boris Fiuczynski <fiuczy.ibm.com>
CommitDate: 2015-12-04 13:50:06 -0500

    qemu: Automatic SCSI controller creation in SCSI disk hotplug broken
    
git describe: v1.3.0-rc1-12-g105794c contains: v1.3.0-rc2~1

And for SCSI hostdevs by:
commit 12ec22b68befce0ae8020635e7fd71d783b1d716
Author:     Marc Hartmayer <mhartmay.ibm.com>
CommitDate: 2016-06-30 12:48:51 +0200

    qemu: SCSI hostdev hot-plug: Fix automatic creation of SCSI controllers
    
    Ensure that the given controller and all controllers with a smaller
    index exist; there must not be any missing index in between.
    
    Reviewed-by: Boris Fiuczynski <fiuczy.ibm.com>
    Reviewed-by: Bjoern Walk <bwalk.ibm.com>
    Signed-off-by: Marc Hartmayer <mhartmay.ibm.com>

git describe: v2.0.0-rc2-5-g12ec22b contains: v2.0.0~6

Comment 7 yisun 2016-09-21 06:17:21 UTC
Verified on libvirt-2.0.0-9.el7.x86_64

test with test script with tiny modification:
cat test.sh

#!/bin/bash

# Purpose: Attach two SCSI disks to a SCSI controller '2'.  The smaller
# controller indices '1' and '0' should be automatically created.

set -x
image_dir="/var/lib/libvirt/images"
vm_name="virtlab_test_copy"
disk_scsi_index="2"

# Create three raw disk images
function create_disk() {
    for i in {b..c}; 
        do 
            qemu-img create -f raw $image_dir/$i.raw 512M; 
        done
}

# This is incrementing the 'unit' (a "2-digit unit number on a bus")
# attribute, for the 'address' sub-element, which describes where the
# device is placed on the virtual bus presented to the guest.
# http://libvirt.org/formatdomain.html#elementsAddress

virsh dumpxml $vm_name | grep scsi

j=1

# Construct a guest XML by attaching two SCSI disks onto the *second* controller
# (and manually increment the 'unit' number)

function attach_device() {
    for i in {b..c}; do
        j=$(expr $j + 1)
        cat << EOF > disk-$i.xml
<disk type='file' device='disk'>
  <source file='$image_dir/$i.raw'/>
  <target dev='sd$i' bus='scsi'/>
  <address type='drive' controller='$disk_scsi_index' model='virtio-scsi' bus='0' target='0' unit='$j'/>
</disk>
EOF

        # Attach the device; it takes effect on next boot
        virsh attach-device $vm_name disk-$i.xml  --live
	virsh dumpxml $vm_name | grep scsi
    done
}

create_disk
attach_device

=============set disk_scsi_index="2" in script=========
result expected with scsi controller 0, 1 and 2 automatically generated:
[root@localhost 1377212]# virsh destroy virtlab_test_copy
Domain virtlab_test_copy destroyed

[root@localhost 1377212]# virsh start virtlab_test_copy
Domain virtlab_test_copy started

[root@localhost 1377212]# sh test.sh 
+ image_dir=/var/lib/libvirt/images
+ vm_name=virtlab_test_copy
+ disk_scsi_index=2
+ virsh dumpxml virtlab_test_copy
+ grep scsi
+ j=1
+ create_disk
+ for i in '{b..c}'
+ qemu-img create -f raw /var/lib/libvirt/images/b.raw 512M
Formatting '/var/lib/libvirt/images/b.raw', fmt=raw size=536870912
+ for i in '{b..c}'
+ qemu-img create -f raw /var/lib/libvirt/images/c.raw 512M
Formatting '/var/lib/libvirt/images/c.raw', fmt=raw size=536870912
+ attach_device
+ for i in '{b..c}'
++ expr 1 + 1
+ j=2
+ cat
+ virsh attach-device virtlab_test_copy disk-b.xml --live
Device attached successfully

+ virsh dumpxml virtlab_test_copy
+ grep scsi
      <target dev='sdb' bus='scsi'/>
      <alias name='scsi2-0-0-2'/>
    <controller type='scsi' index='0'>
      <alias name='scsi0'/>
    <controller type='scsi' index='1'>
      <alias name='scsi1'/>
    <controller type='scsi' index='2'>
      <alias name='scsi2'/>
+ for i in '{b..c}'
++ expr 2 + 1
+ j=3
+ cat
+ virsh attach-device virtlab_test_copy disk-c.xml --live
Device attached successfully

+ virsh dumpxml virtlab_test_copy
+ grep scsi
      <target dev='sdb' bus='scsi'/>
      <alias name='scsi2-0-0-2'/>
      <target dev='sdc' bus='scsi'/>
      <alias name='scsi2-0-0-3'/>
    <controller type='scsi' index='0'>
      <alias name='scsi0'/>
    <controller type='scsi' index='1'>
      <alias name='scsi1'/>
    <controller type='scsi' index='2'>
      <alias name='scsi2'/>

=============set disk_scsi_index="10" in script=========
result expected with scsi controller 0..10 automatically generated:
[root@localhost 1377212]# virsh destroy virtlab_test_copy
Domain virtlab_test_copy destroyed

[root@localhost 1377212]# virsh start virtlab_test_copy
Domain virtlab_test_copy started
[root@localhost 1377212]# sh test.sh 
+ image_dir=/var/lib/libvirt/images
+ vm_name=virtlab_test_copy
+ disk_scsi_index=10
+ virsh dumpxml virtlab_test_copy
+ grep scsi
+ j=1
+ create_disk
+ for i in '{b..c}'
+ qemu-img create -f raw /var/lib/libvirt/images/b.raw 512M
Formatting '/var/lib/libvirt/images/b.raw', fmt=raw size=536870912
+ for i in '{b..c}'
+ qemu-img create -f raw /var/lib/libvirt/images/c.raw 512M
Formatting '/var/lib/libvirt/images/c.raw', fmt=raw size=536870912
+ attach_device
+ for i in '{b..c}'
++ expr 1 + 1
+ j=2
+ cat
+ virsh attach-device virtlab_test_copy disk-b.xml --live
Device attached successfully

+ virsh dumpxml virtlab_test_copy
+ grep scsi
      <target dev='sdb' bus='scsi'/>
      <alias name='scsi10-0-0-2'/>
    <controller type='scsi' index='0'>
      <alias name='scsi0'/>
    <controller type='scsi' index='1'>
      <alias name='scsi1'/>
    <controller type='scsi' index='2'>
      <alias name='scsi2'/>
    <controller type='scsi' index='3'>
      <alias name='scsi3'/>
    <controller type='scsi' index='4'>
      <alias name='scsi4'/>
    <controller type='scsi' index='5'>
      <alias name='scsi5'/>
    <controller type='scsi' index='6'>
      <alias name='scsi6'/>
    <controller type='scsi' index='7'>
      <alias name='scsi7'/>
    <controller type='scsi' index='8'>
      <alias name='scsi8'/>
    <controller type='scsi' index='9'>
      <alias name='scsi9'/>
    <controller type='scsi' index='10'>
      <alias name='scsi10'/>
+ for i in '{b..c}'
++ expr 2 + 1
+ j=3
+ cat
+ virsh attach-device virtlab_test_copy disk-c.xml --live
Device attached successfully

+ virsh dumpxml virtlab_test_copy
+ grep scsi
      <target dev='sdb' bus='scsi'/>
      <alias name='scsi10-0-0-2'/>
      <target dev='sdc' bus='scsi'/>
      <alias name='scsi10-0-0-3'/>
    <controller type='scsi' index='0'>
      <alias name='scsi0'/>
    <controller type='scsi' index='1'>
      <alias name='scsi1'/>
    <controller type='scsi' index='2'>
      <alias name='scsi2'/>
    <controller type='scsi' index='3'>
      <alias name='scsi3'/>
    <controller type='scsi' index='4'>
      <alias name='scsi4'/>
    <controller type='scsi' index='5'>
      <alias name='scsi5'/>
    <controller type='scsi' index='6'>
      <alias name='scsi6'/>
    <controller type='scsi' index='7'>
      <alias name='scsi7'/>
    <controller type='scsi' index='8'>
      <alias name='scsi8'/>
    <controller type='scsi' index='9'>
      <alias name='scsi9'/>
    <controller type='scsi' index='10'>
      <alias name='scsi10'/>

Comment 10 errata-xmlrpc 2016-11-03 18:54:47 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-2016-2577.html


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