mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
qemuDomainAttachDeviceMknodHelper: Remove symlink before creating it
https://bugzilla.redhat.com/show_bug.cgi?id=1528502 So imagine you have /dev/blah symlink which points to /dev/sda. You attach /dev/blah as disk to your domain. Libvirt correctly creates the /dev/blah -> /dev/sda symlink in the qemu namespace. However, then you detach the disk, change the symlink so that it points to /dev/sdb and tries to attach the disk again. This time, however, the attach fails (well, qemu attaches wrong disk) because the code assumes that symlinks don't change. Well they do. This is inspired by test fix written by Eduardo Habkost. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
parent
2b041dc8c7
commit
db98e7f67e
@ -9745,13 +9745,23 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
VIR_DEBUG("Creating symlink %s -> %s", data->file, data->target);
|
VIR_DEBUG("Creating symlink %s -> %s", data->file, data->target);
|
||||||
|
|
||||||
|
/* First, unlink the symlink target. Symlinks change and
|
||||||
|
* therefore we have no guarantees that pre-existing
|
||||||
|
* symlink is still valid. */
|
||||||
|
if (unlink(data->file) < 0 &&
|
||||||
|
errno != ENOENT) {
|
||||||
|
virReportSystemError(errno,
|
||||||
|
_("Unable to remove symlink %s"),
|
||||||
|
data->file);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (symlink(data->target, data->file) < 0) {
|
if (symlink(data->target, data->file) < 0) {
|
||||||
if (errno != EEXIST) {
|
virReportSystemError(errno,
|
||||||
virReportSystemError(errno,
|
_("Unable to create symlink %s (pointing to %s)"),
|
||||||
_("Unable to create symlink %s"),
|
data->file, data->target);
|
||||||
data->target);
|
goto cleanup;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
delDevice = true;
|
delDevice = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user