mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu: Regenerate VNC socket paths
Similarly to what commit7140807917
did with some internal paths, clear vnc socket paths that were generated by us. Having such path in the definition can cause trouble when restoring the domain. The path is generated to the per-domain directory that contains the domain ID. However, that ID will be different upon restoration, so qemu won't be able to create that socket because the directory will not be prepared. To be able to migrate to older libvirt, skip formatting the socket path in migratable XML if it was autogenerated. And mark it as autogenerated if it already exists and we're parsing live XML. Best viewed with '-C'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1326270 Signed-off-by: Martin Kletzander <mkletzan@redhat.com> (cherry picked from commit55320c23dd
)
This commit is contained in:
parent
086b022d56
commit
082deb52ac
@ -21298,7 +21298,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
|
||||
if (def->data.vnc.socket) {
|
||||
virBufferEscapeString(buf, " socket='%s'", def->data.vnc.socket);
|
||||
if (!def->data.vnc.socketAutogenerated ||
|
||||
!(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) {
|
||||
virBufferEscapeString(buf, " socket='%s'",
|
||||
def->data.vnc.socket);
|
||||
}
|
||||
} else {
|
||||
if (def->data.vnc.port &&
|
||||
(!def->data.vnc.autoport || !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
|
||||
|
@ -1554,6 +1554,7 @@ struct _virDomainGraphicsDef {
|
||||
bool autoport;
|
||||
char *keymap;
|
||||
char *socket;
|
||||
bool socketAutogenerated;
|
||||
virDomainGraphicsAuthDef auth;
|
||||
int sharePolicy;
|
||||
} vnc;
|
||||
|
@ -7241,10 +7241,13 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
|
||||
}
|
||||
|
||||
if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) {
|
||||
if (!graphics->data.vnc.socket &&
|
||||
virAsprintf(&graphics->data.vnc.socket,
|
||||
"%s/vnc.sock", domainLibDir) == -1)
|
||||
goto error;
|
||||
if (!graphics->data.vnc.socket) {
|
||||
if (virAsprintf(&graphics->data.vnc.socket,
|
||||
"%s/vnc.sock", domainLibDir) < 0)
|
||||
goto error;
|
||||
|
||||
graphics->data.vnc.socketAutogenerated = true;
|
||||
}
|
||||
|
||||
virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket);
|
||||
|
||||
|
@ -1409,10 +1409,32 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
qemuDomainRecheckInternalPaths(virDomainDefPtr def,
|
||||
virQEMUDriverConfigPtr cfg,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < def->ngraphics; ++i) {
|
||||
virDomainGraphicsDefPtr graphics = def->graphics[i];
|
||||
|
||||
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
|
||||
graphics->data.vnc.socket &&
|
||||
STRPREFIX(graphics->data.vnc.socket, cfg->libDir)) {
|
||||
if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)
|
||||
VIR_FREE(graphics->data.vnc.socket);
|
||||
else
|
||||
graphics->data.vnc.socketAutogenerated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainDefPostParse(virDomainDefPtr def,
|
||||
virCapsPtr caps,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags,
|
||||
void *opaque)
|
||||
{
|
||||
virQEMUDriverPtr driver = opaque;
|
||||
@ -1458,6 +1480,8 @@ qemuDomainDefPostParse(virDomainDefPtr def,
|
||||
|
||||
qemuDomainDefEnableDefaultFeatures(def);
|
||||
|
||||
qemuDomainRecheckInternalPaths(def, cfg, parseFlags);
|
||||
|
||||
if (virSecurityManagerVerify(driver->securityManager, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
LC_ALL=C \
|
||||
PATH=/bin \
|
||||
HOME=/home/test \
|
||||
USER=test \
|
||||
LOGNAME=test \
|
||||
QEMU_AUDIO_DRV=none \
|
||||
/usr/bin/qemu \
|
||||
-name QEMUGuest1 \
|
||||
-S \
|
||||
-M pc \
|
||||
-m 214 \
|
||||
-smp 1 \
|
||||
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
|
||||
-nodefaults \
|
||||
-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
|
||||
-no-acpi \
|
||||
-boot c \
|
||||
-usb \
|
||||
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
|
||||
-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
|
||||
-vnc unix:/tmp/lib/domain--1-QEMUGuest1/vnc.socket \
|
||||
-vga cirrus
|
@ -0,0 +1,34 @@
|
||||
<domain type='qemu'>
|
||||
<name>QEMUGuest1</name>
|
||||
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>219100</memory>
|
||||
<currentMemory unit='KiB'>219100</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='i686' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu</emulator>
|
||||
<disk type='block' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source dev='/dev/HostVG/QEMUGuest1'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0'/>
|
||||
<controller type='ide' index='0'/>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='vnc' socket='/tmp/lib/domain-99-QEMUGuest1/delete.this.socket'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
<memballoon model='none'/>
|
||||
</devices>
|
||||
</domain>
|
@ -0,0 +1,39 @@
|
||||
<domain type='qemu'>
|
||||
<name>QEMUGuest1</name>
|
||||
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>219100</memory>
|
||||
<currentMemory unit='KiB'>219100</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='i686' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu</emulator>
|
||||
<disk type='block' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source dev='/dev/HostVG/QEMUGuest1'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='ide' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<memballoon model='none'/>
|
||||
</devices>
|
||||
</domain>
|
@ -261,6 +261,7 @@ mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct testInfo info;
|
||||
virQEMUDriverConfigPtr cfg = NULL;
|
||||
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
@ -761,6 +762,12 @@ mymain(void)
|
||||
DO_TEST("virtio-input");
|
||||
DO_TEST("virtio-input-passthrough");
|
||||
|
||||
cfg = virQEMUDriverGetConfig(&driver);
|
||||
cfg->vncAutoUnixSocket = true;
|
||||
DO_TEST_FULL("graphics-vnc-autosocket", WHEN_INACTIVE, NONE);
|
||||
cfg->vncAutoUnixSocket = false;
|
||||
|
||||
virObjectUnref(cfg);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
Loading…
Reference in New Issue
Block a user