Bug 1462060
| Summary: | Failed to attach disk with source file in the /dev/ dir | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | yafu <yafu> |
| Component: | libvirt | Assignee: | Michal Privoznik <mprivozn> |
| Status: | CLOSED ERRATA | QA Contact: | Meina Li <meili> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 7.4 | CC: | dyuan, fjin, jiyan, lizhu, rbalakri, xuzhang, yanqzhan, zpeng |
| Target Milestone: | rc | Keywords: | Upstream |
| Target Release: | --- | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | libvirt-3.7.0-1.el7 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2018-04-10 10:48:37 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: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1473046 | ||
Patches proposed upstream: https://www.redhat.com/archives/libvir-list/2017-June/msg00940.html I've just pushed the patches upstream:
commit e93d844b90aab2676a1ad910a165c9c83c99de3d
Author: Michal Privoznik <mprivozn>
AuthorDate: Mon Jun 19 17:05:31 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemu ns: Create chardev backends more frequently
Currently, the only type of chardev that we create the backend
for in the namespace is type='dev'. This is not enough, other
backends might have files under /dev too. For instance channels
might have a unix socket under /dev (well, bind mounted under
/dev from a different place).
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 7976d1a5146bc5117e7125f0cbbfe537248dc630
Author: Michal Privoznik <mprivozn>
AuthorDate: Thu Jun 15 17:05:06 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemuDomainAttachDeviceMknodRecursive: Support file mount points
https://bugzilla.redhat.com/show_bug.cgi?id=1462060
Just like in the previous commit, when attaching a file based
device which has its source living under /dev (that is not a
device rather than a regular file), calling mknod() is no help.
We need to:
1) bind mount device to some temporary location
2) enter the namespace
3) move the mount point to desired place
4) umount it in the parent namespace from the temporary location
At the same time, the check in qemuDomainNamespaceSetupDisk makes
no longer sense. Therefore remove it.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 4f05f188de5de0d5764699ba5231a7d20b42dc9c
Author: Michal Privoznik <mprivozn>
AuthorDate: Fri Jun 16 13:49:52 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemuDomainCreateDeviceRecursive: Support file mount points
https://bugzilla.redhat.com/show_bug.cgi?id=1462060
When building a qemu namespace we might be dealing with bare
regular files. Files that live under /dev. For instance
/dev/my_awesome_disk:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/my_awesome_disk'/>
<target dev='vdc' bus='virtio'/>
</disk>
# qemu-img create -f qcow2 /dev/my_awesome_disk 10M
So far we were mknod()-ing them which is
obviously wrong. We need to touch the file and bind mount it to
the original:
1) touch /var/run/libvirt/qemu/fedora.dev/my_awesome_disk
2) mount --bind /dev/my_awesome_disk /var/run/libvirt/qemu/fedora.dev/my_awesome_disk
Later, when the new /dev is built and replaces original /dev the
file is going to live at expected location.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 4fedbac6206ad6c754d936ac39f0b42417b7dbd5
Author: Michal Privoznik <mprivozn>
AuthorDate: Thu Jun 15 15:50:39 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemuDomainAttachDeviceMknodHelper: Fail on unsupported file type
Currently, we silently assume that file we are creating in the
namespace is either a link or a device (character or block one).
This is not always the case. Therefore instead of doing something
wrong, claim about unsupported file type.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 89921f54cd4775909f30cfb56313ed3afd3945ca
Author: Michal Privoznik <mprivozn>
AuthorDate: Mon Jun 19 10:56:20 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemuDomainCreateDeviceRecursive: Fail on unsupported file type
Currently, we silently assume that file we are creating in the
namespace is either a link or a device (character or block one).
This is not always the case. Therefore instead of doing something
wrong, claim about unsupported file type.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 4d8a914be00b5d94b7a5ee8dd3a857d26700592d
Author: Michal Privoznik <mprivozn>
AuthorDate: Thu Jun 15 15:48:52 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemu: Move preserved mount points path generation into a separate function
This function is going to be used on other places, so
instead of copying code we can just call the function.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 7154917908d9f712a950a2716c4687e57ccb74e7
Author: Michal Privoznik <mprivozn>
AuthorDate: Tue Jun 20 17:35:54 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
qemuDomainBuildNamespace: Handle special file mount points
https://bugzilla.redhat.com/show_bug.cgi?id=1459592
In 290a00e41d I've tried to fix the process of building a
qemu namespace when dealing with file mount points. What I
haven't realized then is that we might be dealing not with just
regular files but also special files (like sockets). Indeed, try
the following:
1) socat unix-listen:/tmp/soket stdio
2) touch /dev/socket
3) mount --bind /tmp/socket /dev/socket
4) virsh start anyDomain
Problem with my previous approach is that I wasn't creating the
temporary location (where mount points under /dev are moved) for
anything but directories and regular files.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
commit 37ef8763c4ce085d0ea8e7c18b29a9dd27874291
Author: Michal Privoznik <mprivozn>
AuthorDate: Mon Jun 19 16:43:25 2017 +0200
Commit: Michal Privoznik <mprivozn>
CommitDate: Tue Jul 11 14:45:15 2017 +0200
conf: Rename and expose virDomainChrSourceDefPath
It comes very handy to have source path for chardevs. We already
have such function: virDomainAuditChardevPath() but it's static
and has name not suitable for exposing. Moreover, while exposing
it change its name slightly to virDomainChrSourceDefGetPath.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: John Ferlan <jferlan>
v3.5.0-56-ge93d844b9
Verified it on:
libvirt-3.9.0-2.el7.x86_64
qemu-kvm-rhev-2.10.0-6.el7.x86_64
Verified steps:
Scenario 1 - Attach disk source file in the /dev/ dir directly:
1. Prepare a img in the /dev and prepare the disk xml:
# qemu-img create -f qcow2 /dev/test.img 10M
Formatting '/dev/test.img', fmt=qcow2 size=10485760 cluster_size=65536 lazy_refcounts=off refcount_bits=16
# cat disk.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
2. Attach/detach the disk to a running guest:
# virsh attach-device lmn disk.xml
Device attached successfully
# virsh domblklist lmn
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/lmn.qcow2
vdb /dev/test.img
# virsh detach-device lmn disk.xml
Device detached successfully
3. Start a guest which the disk has source file with qcow2 format in the /dev dir:
...
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
...
# virsh start lmn
Domain lmn started
Scenario 2 - Attach disk source file in the /dev/shm dir.
1. Prepare a img in the /dev and prepare the disk xml:
# qemu-img create -f qcow2 /dev/shm/test.img 10M
Formatting '/dev/shm/test.img', fmt=qcow2 size=10485760 cluster_size=65536 lazy_refcounts=off refcount_bits=16
# cat disk.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/shm/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
2. Attach/detach the disk to a running guest:
# virsh attach-device lmn disk.xml
Device attached successfully
# virsh domblklist lmn
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/lmn.qcow2
vdb /dev/shm/test.img
# virsh detach-device lmn disk.xml
Device detached successfully
3. Start a guest which the disk has source file with qcow2 format in the /dev dir:
...
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/shm/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
...
# virsh start lmn
Domain lmn started
Scenario 3 - Attach disk source file in the /dev/ dir that file is mounted on mount points:
1. Prepare a img in the /dev and prepare the disk xml:
# qemu-img create -f qcow2 /dev/test.img 10M
Formatting '/dev/test.img', fmt=qcow2 size=10485760 cluster_size=65536 lazy_refcounts=off refcount_bits=16
# cat disk.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
2. Support file mount points for /dev file:
# touch /tmp/demo.img
# mount --bind /dev/test.img /tmp/demo.img
3. Attach/detach the disk to a running guest:
# virsh attach-device lmn disk.xml
Device attached successfully
# virsh domblklist lmn
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/lmn.qcow2
vdb /dev/test.img
# virsh detach-device lmn disk.xml
Device detached successfully
Scenario 4: Attach disk source file in the /dev/ which has a symlink
1. Prepare a img in the /dev and prepare the disk xml:
# qemu-img create -f qcow2 /dev/test.img 10M
Formatting '/dev/test.img', fmt=qcow2 size=10485760 cluster_size=65536 lazy_refcounts=off refcount_bits=16
# cat disk.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/test.img'/> -->use '/dev/demo.img'is also OK
<target dev='vdb' bus='virtio'/>
</disk>
2. Make symlink for /dev file:
# ln -s /dev/test.img /dev/demo.img
3. Attach/detach the disk to a running guest:
# virsh attach-device lmn disk.xml
Device attached successfully
# virsh domblklist lmn
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/lmn.qcow2
vdb /dev/test.img
# virsh detach-device lmn disk.xml
Device detached successfully
Scenario 5: Attach disk source file in the /dev/ which has a backing chain image
1. Prepare a img in the /dev and prepare the disk xml:
# qemu-img create -f qcow2 /dev/test.img -b /tmp/demo.img 10M
Formatting '/dev/test.img', fmt=qcow2 size=10485760 backing_file=/tmp/demo.img cluster_size=65536 lazy_refcounts=off refcount_bits=16
refcount_bits=16
# cat disk.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/dev/test.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
2. Attach/detach the disk to a running guest:
# virsh attach-device lmn disk.xml
Device attached successfully
# virsh domblklist lmn
Target Source
------------------------------------------------
vda /var/lib/libvirt/images/lmn.qcow2
vdb /dev/test.img
# virsh detach-device lmn disk.xml
Device detached successfully
Move this bug to VERIFIED.
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://access.redhat.com/errata/RHEA-2018:0704 |
Description of problem: Failed to attach disk with source file in the /dev/ dir Version-Release number of selected component (if applicable): libvirt-3.2.0-10.el7.x86_64 How reproducible: 100% Steps to reproduce: 1.Prepare a img in the /dev: #qemu-img create -f qcow2 /dev/test.img 10M 2.Prepare the disk xml: #cat disk.xml <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/dev/test.img'/> <target dev='vdc' bus='virtio'/> </disk> 3.Attach the disk to a running guest: #virsh attach-device full-73 disk.xml error: Failed to attach device from disk.xml error: internal error: child reported: unable to set user and group to '107:107' on '/dev/test.img': No such file or directory Actual results: Failed to attach disk with source file in the /dev dir Expected results: Should attach the disk successfully. Additional info: 1.The guest also can not start if disk having source file with qcwo2 format in the /dev dir: #qemu-img create -f qcow2 /dev/test.img 10M #virsh edit full-73 ... <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/dev/test.img'/> <target dev='vdc' bus='virtio'/> </disk> ... #virsh start full-73 error: Failed to start domain full-73 error: internal error: qemu unexpectedly closed the monitor: 2017-06-15T15:35:11.690410Z qemu-kvm: -chardev pty,id=charserial0: char device redirected to /dev/pts/18 (label charserial0) 2017-06-15T15:35:11.809120Z qemu-kvm: -drive file=/dev/test.img,format=qcow2,if=none,id=drive-virtio-disk4: Image is not in qcow2 format 2.The issues will not occur when turning off namespace.