提交 55320c23 编写于 作者: M Martin Kletzander

qemu: Regenerate VNC socket paths

Similarly to what commit 71408079 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=1326270Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 b527e7c8
...@@ -21342,7 +21342,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf, ...@@ -21342,7 +21342,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
switch (def->type) { switch (def->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC: case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
if (def->data.vnc.socket) { 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 { } else {
if (def->data.vnc.port && if (def->data.vnc.port &&
(!def->data.vnc.autoport || !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) (!def->data.vnc.autoport || !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
......
...@@ -1564,6 +1564,7 @@ struct _virDomainGraphicsDef { ...@@ -1564,6 +1564,7 @@ struct _virDomainGraphicsDef {
bool autoport; bool autoport;
char *keymap; char *keymap;
char *socket; char *socket;
bool socketAutogenerated;
virDomainGraphicsAuthDef auth; virDomainGraphicsAuthDef auth;
int sharePolicy; int sharePolicy;
} vnc; } vnc;
......
...@@ -7277,10 +7277,13 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7277,10 +7277,13 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
} }
if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) { if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) {
if (!graphics->data.vnc.socket && if (!graphics->data.vnc.socket) {
virAsprintf(&graphics->data.vnc.socket, if (virAsprintf(&graphics->data.vnc.socket,
"%s/vnc.sock", domainLibDir) == -1) "%s/vnc.sock", domainLibDir) < 0)
goto error; goto error;
graphics->data.vnc.socketAutogenerated = true;
}
virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket); virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket);
......
...@@ -1659,10 +1659,32 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) ...@@ -1659,10 +1659,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 static int
qemuDomainDefPostParse(virDomainDefPtr def, qemuDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps, virCapsPtr caps,
unsigned int parseFlags ATTRIBUTE_UNUSED, unsigned int parseFlags,
void *opaque) void *opaque)
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
...@@ -1708,6 +1730,8 @@ qemuDomainDefPostParse(virDomainDefPtr def, ...@@ -1708,6 +1730,8 @@ qemuDomainDefPostParse(virDomainDefPtr def,
qemuDomainDefEnableDefaultFeatures(def); qemuDomainDefEnableDefaultFeatures(def);
qemuDomainRecheckInternalPaths(def, cfg, parseFlags);
if (virSecurityManagerVerify(driver->securityManager, def) < 0) if (virSecurityManagerVerify(driver->securityManager, def) < 0)
goto cleanup; goto cleanup;
......
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
<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>
<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>
...@@ -263,6 +263,7 @@ mymain(void) ...@@ -263,6 +263,7 @@ mymain(void)
{ {
int ret = 0; int ret = 0;
struct testInfo info; struct testInfo info;
virQEMUDriverConfigPtr cfg = NULL;
if (qemuTestDriverInit(&driver) < 0) if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -774,6 +775,12 @@ mymain(void) ...@@ -774,6 +775,12 @@ mymain(void)
DO_TEST("virtio-input"); DO_TEST("virtio-input");
DO_TEST("virtio-input-passthrough"); 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); qemuTestDriverFree(&driver);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册