Bug 1277744 - When VirtualBox is running, libguestfs fails with ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy
Summary: When VirtualBox is running, libguestfs fails with ioctl(KVM_CREATE_VM) failed...
Keywords:
Status: NEW
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libguestfs
Version: unspecified
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-11-04 00:12 UTC by igoryonya
Modified: 2019-03-23 17:50 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)
When no VirtualBox VMs with vmdk disk is running (61.49 KB, text/plain)
2017-01-17 03:34 UTC, igoryonya
no flags Details
When VirtualBox VMs with vmdk disk is running (5.05 KB, text/plain)
2017-01-17 03:38 UTC, igoryonya
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1657010 0 None None None 2017-01-17 06:35:10 UTC

Description igoryonya 2015-11-04 00:12:20 UTC
Description of problem:
doing:
sudo virt-filesystems -a /path/to/a/virtual_hd.vmdk
shows errors, instead of partition names.

Version-Release number of selected component (if applicable):
virt-filesystems 1.28.6
VirtualBox 5.0.8 r103449
Ubuntu 15.04 3.19.0-32-generic #37-Ubuntu x86_64
VM's VHD .qcow

How reproducible:
I don't know, if it's caused by qcow, or doesn't matter, so, in my case:
create a virtualmachine on virtualbox, using qcow VHD, and lauch it. Just in case, I have Ubuntu 15.10 amd64 installed on the VM.

Actual results:
when VirtualBoxe's VM is launched, I get:
libguestfs: error: appliance closed the connection unexpectedly.
This usually means the libguestfs appliance crashed.
Do:
  export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1
and run the command again.  For further information, read:
  http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
You can also run 'libguestfs-test-tool' and post the *complete* output
into a bug report or message to the libguestfs mailing list.
libguestfs: error: /usr/bin/qemu-system-x86_64 exited with error status 1.
To see full error messages you may need to enable debugging.
Do:
  export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1
and run the command again.  For further information, read:
  http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
You can also run 'libguestfs-test-tool' and post the *complete* output
into a bug report or message to the libguestfs mailing list.
libguestfs: error: guestfs_launch failed.
This usually means the libguestfs appliance failed to start or crashed.
Do:
  export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1
and run the command again.  For further information, read:
  http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
You can also run 'libguestfs-test-tool' and post the *complete* output
into a bug report or message to the libguestfs mailing list.

Expected results:
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda6

Additional info:
if I do export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1, it gives me exactly the same message, I even diffed both messages to make sure.
---
Closing VirtualBox VM fixes the problem.

Comment 1 Pino Toscano 2015-11-09 16:56:14 UTC
Please run:

  sudo virt-filesystems -v -x -a /path/to/a/virtual_hd.vmdk 2>&1 | tee virt-filesystems.log

and attach to this bug the resulting virt-filesystems.log you get. Enabling debug and verbosity will not cause virt-filesystems to work while it didn't without, but at least we can see what's the actual issue in this case.

Comment 2 igoryonya 2017-01-17 03:34:50 UTC
Created attachment 1241525 [details]
When no VirtualBox VMs with vmdk disk is running

virt-filesystems works wnen no VirtualBoxe's VM is running with qcow/qcow2 or vmdk VHD.

Comment 3 igoryonya 2017-01-17 03:38:49 UTC
Created attachment 1241526 [details]
When VirtualBox VMs with vmdk disk is running

virt-filesystems doesn't work, wnen VirtualBoxe's VM is running with qcow/qcow2 or vmdk VHD.

Comment 4 igoryonya 2017-01-17 03:42:15 UTC
I've added 2 attachments of logs from running those commands:
/tmp/virt-filesystems.log - is when no VB's VM is running with vmdk/qcow/qcow2 disk in it.
/tmp/virt-filesystems-vb.log - is when VB's VM is running with vmdk/qcow/qcow2 disk in it.

Comment 5 igoryonya 2017-01-17 03:50:57 UTC
P.S. VBoxe's VM can have any OS, installed in it. As long as I attach a vmdk/qcow/qcow2 disk to it, the virt-filesystems reveals it's problem.

I am running Ubuntu 16.04 now with kernel: 4.4.0-57-generic x86_64
virt-filesystems 1.32.2
VirtualBox V5.0.20 r106931

Comment 6 Richard W.M. Jones 2017-01-17 06:32:26 UTC
The error is:

  ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy
  failed to initialize KVM: Device or resource busy
  Back to tcg accelerator.
  qemu-system-x86_64: CPU model 'host' requires KVM

This is unfortunate, but it's a real (and very long-standing) bug
in qemu.

The workaround is to set:

  export LIBGUESTFS_BACKEND_SETTINGS=force_tcg

which forces libguestfs to use software emulation.  You only need
to use this when using VirtualBox (and also note that it'll make
libguestfs run a lot slower).

The actual reason why this is happening is best explained by pointing
to the comment in the libguestfs code:

https://github.com/libguestfs/libguestfs/blob/dd519e8a8ea2be89862f3cec99aff9e19c458afa/src/appliance-cpu.c#L64-L66

Comment 7 Richard W.M. Jones 2017-01-17 06:35:11 UTC
I filed a qemu RFE about this:

https://bugs.launchpad.net/qemu/+bug/1657010

Comment 8 igoryonya 2017-01-18 02:31:09 UTC
So, meanwhile, I can probably put it in a rough script, like that, I guess:

var_vbproc=$(pgrep -f '/virtualbox/VirtualBox.*--startvm\>'|wc -l)
if [ "$var_vbproc" -gt 0 ]; then
	export LIBGUESTFS_BACKEND_SETTINGS=force_tcg
fi
virt-filesystems $1 $2 $3 $4 $5 $6 $7 $8 $9
if [ "$var_vbproc" -gt 0 ]; then
	export LIBGUESTFS_BACKEND_SETTINGS=''
fi

Comment 9 igoryonya 2017-01-18 02:48:18 UTC
It worked and I am not very good at bash. Shortly after testing this script, I realized, that exported variable lives only during script's execution, so, I've simplified it a bit (unfortunately, I cannot edit the previous comment):

if [ "$(pgrep -f '/virtualbox/VirtualBox.*--startvm\>'|wc -l)" -gt 0 ]; then
        export LIBGUESTFS_BACKEND_SETTINGS='force_tcg'
fi
virt-filesystems $1 $2 $3 $4 $5 $6 $7 $8 $9

Comment 10 Richard W.M. Jones 2019-03-23 17:50:23 UTC
I suspect that the fix for bug 1605071 which went upstream in around Sept 2018
has also fixed this.


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