Bug 1019926 - Virtual machine does not start if CD is not in drive
Virtual machine does not start if CD is not in drive
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.4
All Linux
unspecified Severity high
: rc
: ---
Assigned To: Martin Kletzander
Virtualization Bugs
:
: 1065507 (view as bug list)
Depends On: 868673
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-16 12:00 EDT by Mikulas Patocka
Modified: 2014-10-14 00:17 EDT (History)
6 users (show)

See Also:
Fixed In Version: libvirt-0.10.2-35.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-10-14 00:17:48 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Mikulas Patocka 2013-10-16 12:00:45 EDT
Description of problem:
If virtual machine's virtual CD drive is assigned to a physical CD drive and
there is no CD in the physical CD drive, the virtual machine does not start.

Version-Release number of selected component (if applicable):
RHEL6.4

How reproducible:
Always

Steps to Reproduce:
1. Have some virtual machine
2. Put some CD into the physical CD drive
3. Go to virt manager, attach the physical CD drive to the virtual machine
4. Turn off the virtual machine
5. Remove the CD from the drive
6. Try to start the virtual machine again

Actual results:
You get this error:
Error starting domain: nelze otevřít soubor '/dev/sr0': Médium nebylo nalezeno
Details:
Error starting domain: nelze otevřít soubor '/dev/sr0': Médium nebylo nalezeno

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 44, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 65, in tmpcb
    callback(*args, **kwargs)
  File "/usr/share/virt-manager/virtManager/domain.py", line 1063, in startup
    self._backend.create()
  File "/usr/lib64/python2.6/site-packages/libvirt.py", line 678, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirtError: nelze otevřít soubor '/dev/sr0': Médium nebylo nalezeno

Expected results:
The virtual machine should start.

Additional info:
Note - if you use O_NONBLOCK flag to the open syscall, you can open a CDROM
drive (/dev/sr0) even if there is no CD in it. If you don't use the O_NONBLOCK
flag, you can't open a device /dev/sr0 if there is no CD in it - it fails with
-ENOMEDIUM. You should modify virt manager to use O_NONBLOCK so that it doesn't
fail when there is no CD in the drive.
Comment 2 Martin Kletzander 2014-02-20 03:21:13 EST
The thing is that virt-manager cannot yet specify startupPolicy for disks and libvirt can specify that for block device only upstream.  Can you attach the output of 'virsh dumpxml <domain_name>' in here?  Thank you.

Due to these not being specified, libvirt will fail starting a domain when some of the disks (cdroms, etc.) are missing and this is on purpose.
Comment 4 Mikulas Patocka 2014-02-20 18:40:29 EST
(In reply to Martin Kletzander from comment #2)
> The thing is that virt-manager cannot yet specify startupPolicy for disks
> and libvirt can specify that for block device only upstream.  Can you attach
> the output of 'virsh dumpxml <domain_name>' in here?  Thank you.
> 
> Due to these not being specified, libvirt will fail starting a domain when
> some of the disks (cdroms, etc.) are missing and this is on purpose.

The problem is not that the cdrom is missing. The cdrom is there; there is no CD
in it.

You should find a piece of code in libvirtd that generated this error:
"Error starting domain: nelze otevřít soubor '/dev/sr0': Médium nebylo nalezeno"
and modify that code so that it passes O_NONBLOCK flag to the open syscall.

I believe that when you use O_NONBLOCK flag when opening the cdrom, it will work.
Comment 5 Martin Kletzander 2014-02-21 02:22:00 EST
Let me explain a bit differently.  Previously, libvirt was designed so it prevents starting of incomplete guests.  By incomplete I mean missing a disk, cd or even CD in that drive.  Libvirt cannot know whether you want the CD to be attached and empty or whether that's a mistake.  If it is not and you want the drive to be empty (in the guest), you should acknowledge it by removing the 'dev' attribute or the 'source' element.  virt-manager can do that by clicking 'disconnect' on that drive.  On newer libvirt this can be done automatically, but starting qemu with a block drive which has no medium in it is unsupported.

So I guess there's a solution for every use case.
Comment 6 Mikulas Patocka 2014-02-21 03:04:01 EST
The problem is that if the virtual machine is being used by a user without
computer science skills (as it was in this case when this bug happened), your
solution doesn't work.

The user doesn't know what "/dev/sr0" is. She can't decode the stacktrace. She
doesn't know that she should go to the virtual machine configuration panel,
select the cd-rom and click on the "disconnect" button - the error message
doesn't tell that she should do it!

The user simply expects that the machine just works. Why should she be forced to
do extra tasks when she removes or inserts CD to a drive? Why does she get a
completely cryptic error message with a stacktrace?

If you start a virtual machine with CD in the drive and then remove the CD, the
virtual machine continues to run correctly. The virtual machine can run without
CD in the drive. If the virtual machine can run without CD in the drive, there is
no reason why do we need to prevent it from starting without CD in the drive.

I understand that you don't want to start a virtual machine when some device is
missing because it may cause a lot of trouble. However, in this case, the device
is not missing - /dev/sr0 is there, and you can open it (if you added O_NONBLOCK
to the open syscall) and attach it to the virtual machine.

I think that adding O_NONBLOCK to relevant places will fix this problem.
Comment 7 Jiri Denemark 2014-03-27 06:25:33 EDT
*** Bug 1065507 has been marked as a duplicate of this bug. ***
Comment 8 chhu 2014-04-03 06:12:16 EDT
Reproduced with packages:
libvirt-0.10.2-29.el6.x86_64
qemu-kvm-0.12.1.2-2.423.el6.x86_64

Test steps:
1. make sure there is no CD in the cdrom, start a guest with xml below:
# virsh define r6-test.xml 
Domain r6 defined from r6-test.xml

# virsh dumpxml r6| grep disk -A 7
    ......
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw' cache='writeback'/>
      <source dev='/dev/sr0'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>

# virsh start r6
error: Failed to start domain r6
error: cannot open file '/dev/sr0': No medium found

Test results:
failed to start the guest without CD in the cdrom with source dev in xml.
Comment 10 Martin Kletzander 2014-04-24 11:09:41 EDT
Fixed upstream with v1.2.3-173-g9556681:

commit 955668138873f2dd9b2e9989fecaddb33dc149c7
Author: Martin Kletzander <mkletzan@redhat.com>
Date:   Wed Apr 16 17:31:50 2014 +0200

    qemu: don't check for backing chains for formats w/o snapshot support
Comment 14 chhu 2014-05-11 23:53:58 EDT
Reproduced on libvirt-0.10.2-33.el6.x86_64,

Verified with packages:
libvirt-0.10.2-35.el6.x86_64

Test steps:
1. make sure there is no CD in the cdrom, start a guest with xml below successfully.
# virsh create r6-test.xml 
Domain r6-qcow2 created from r6-test.xml

# virsh dumpxml r6-qcow2| grep disk -A 8
......
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw' cache='writeback'/>
      <source dev='/dev/sr0'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>

2. Create another domain, put a CD into the physical CD drive, go to virt manager, attach the physical CD drive to the virtual machine, turn off the virtual machine, remove the CD from the drive, then start the virtual machine again successfully.

Test results:
command work well.
Comment 16 errata-xmlrpc 2014-10-14 00:17:48 EDT
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.

http://rhn.redhat.com/errata/RHBA-2014-1374.html

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