From d3759d3674ab9453e5fb5a27ab6c28b8ff8d5569 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 18 Apr 2023 17:34:12 +0200 Subject: [PATCH] qemu: Generate shorter channel target paths A device is basically an UNIX socket into guest. Whatever is sent from the host, appears in the guest and vice versa. But because of that, the length of the path to the socket is important (underscored by fact that we derive the path from domain short name). But there are still cases where we might not fit into UNIX_PATH_MAX limit (usually 108 characters), because the path is derived also from other variables, e.g. XDG_CONFIG_HOME for session domains. There are two components though, that are needless: "/target/" and "domain-" prefix. Drop them. This is safe to do, because running domains have their path saved in status XML and even though paths are dropped on migration, they are not part of guest ABI and thus we are free to change them. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Hrdina --- libvirt.spec.in | 1 - src/qemu/qemu_conf.c | 6 +++--- src/qemu/qemu_domain.c | 15 +++++++++------ .../qemuhotplug-qemu-agent-detach.xml | 2 +- .../qemuhotplug-base+qemu-agent-detach.xml | 2 +- .../qemuhotplug-base+qemu-agent.xml | 2 +- .../qemuhotplug-base-live+qemu-agent-detach.xml | 2 +- .../qemuhotplug-base-live+qemu-agent.xml | 2 +- .../qemuxml2argvdata/channel-unix-source-path.xml | 4 ++++ .../channel-unix-source-path-active.xml | 5 +++++ .../channel-unix-source-path-inactive.xml | 4 ++++ tests/testutilsqemu.c | 2 +- 12 files changed, 31 insertions(+), 16 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index 17d5f5ff4a0..3b179d1fd98 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -2136,7 +2136,6 @@ exit 0 %ghost %dir %{_rundir}/libvirt/qemu/swtpm/ %dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/ %dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/ -%dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/target/ %dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/checkpoint/ %dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/dump/ %dir %attr(0751, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/nvram/ diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index bd984448a39..532fe36be36 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -146,7 +146,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->snapshotDir = g_strdup_printf("%s/snapshot", cfg->libDir); cfg->checkpointDir = g_strdup_printf("%s/checkpoint", cfg->libDir); cfg->autoDumpPath = g_strdup_printf("%s/dump", cfg->libDir); - cfg->channelTargetDir = g_strdup_printf("%s/channel/target", cfg->libDir); + cfg->channelTargetDir = g_strdup_printf("%s/channel", cfg->libDir); cfg->nvramDir = g_strdup_printf("%s/nvram", cfg->libDir); cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir); } else if (privileged) { @@ -168,7 +168,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->snapshotDir = g_strdup_printf("%s/snapshot", cfg->libDir); cfg->checkpointDir = g_strdup_printf("%s/checkpoint", cfg->libDir); cfg->autoDumpPath = g_strdup_printf("%s/dump", cfg->libDir); - cfg->channelTargetDir = g_strdup_printf("%s/channel/target", cfg->libDir); + cfg->channelTargetDir = g_strdup_printf("%s/channel", cfg->libDir); cfg->nvramDir = g_strdup_printf("%s/nvram", cfg->libDir); cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir); cfg->swtpmStorageDir = g_strdup_printf("%s/lib/libvirt/swtpm", @@ -202,7 +202,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->checkpointDir = g_strdup_printf("%s/qemu/checkpoint", cfg->configBaseDir); cfg->autoDumpPath = g_strdup_printf("%s/qemu/dump", cfg->configBaseDir); - cfg->channelTargetDir = g_strdup_printf("%s/qemu/channel/target", + cfg->channelTargetDir = g_strdup_printf("%s/qemu/channel", cfg->configBaseDir); cfg->nvramDir = g_strdup_printf("%s/qemu/nvram", cfg->configBaseDir); cfg->memoryBackingDir = g_strdup_printf("%s/qemu/ram", cfg->configBaseDir); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 029238a9d73..224350dabc3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1733,7 +1733,7 @@ qemuDomainSetPrivatePaths(virQEMUDriver *driver, priv->libDir = g_strdup_printf("%s/domain-%s", cfg->libDir, domname); if (!priv->channelTargetDir) - priv->channelTargetDir = g_strdup_printf("%s/domain-%s", + priv->channelTargetDir = g_strdup_printf("%s/%s", cfg->channelTargetDir, domname); return 0; @@ -5157,13 +5157,16 @@ qemuDomainDefaultNetModel(const virDomainDef *def, * Clear auto generated unix socket paths: * * libvirt 1.2.18 and older: - * {cfg->channelTargetDir}/{dom-name}.{target-name} + * {cfg->channelTargetDir}/target/{dom-name}.{target-name} * * libvirt 1.2.19 - 1.3.2: - * {cfg->channelTargetDir}/domain-{dom-name}/{target-name} + * {cfg->channelTargetDir}/target/domain-{dom-name}/{target-name} + * + * libvirt 1.3.3 - 9.7.0: + * {cfg->channelTargetDir}/target/domain-{dom-id}-{short-dom-name}/{target-name} * - * libvirt 1.3.3 and newer: - * {cfg->channelTargetDir}/domain-{dom-id}-{short-dom-name}/{target-name} + * libvirt 9.7.0 and newer: + * {cfg->channelTargetDir}/{dom-id}-{short-dom-name}/{target-name} * * The unix socket path was stored in config XML until libvirt 1.3.0. * If someone specifies the same path as we generate, they shouldn't do it. @@ -5189,7 +5192,7 @@ qemuDomainChrDefDropDefaultPath(virDomainChrDef *chr, cfg = virQEMUDriverGetConfig(driver); virBufferEscapeRegex(&buf, "^%s", cfg->channelTargetDir); - virBufferAddLit(&buf, "/([^/]+\\.)|(domain-[^/]+/)"); + virBufferAddLit(&buf, "/(target/)?([^/]+\\.)|(domain-[^/]+/)|([0-9]+-[^/]+/)"); virBufferEscapeRegex(&buf, "%s$", chr->target.name); regexp = virBufferContentAndReset(&buf); diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-qemu-agent-detach.xml b/tests/qemuhotplugtestdevices/qemuhotplug-qemu-agent-detach.xml index 0c3c70a78e8..7871de59c40 100644 --- a/tests/qemuhotplugtestdevices/qemuhotplug-qemu-agent-detach.xml +++ b/tests/qemuhotplugtestdevices/qemuhotplug-qemu-agent-detach.xml @@ -1,5 +1,5 @@ - +
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent-detach.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent-detach.xml index 728af3391e3..bf2afb67d9c 100644 --- a/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent-detach.xml +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent-detach.xml @@ -39,7 +39,7 @@
- +
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent.xml index 728af3391e3..31917cee92c 100644 --- a/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent.xml +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base+qemu-agent.xml @@ -39,7 +39,7 @@
- +
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent-detach.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent-detach.xml index 728af3391e3..bf2afb67d9c 100644 --- a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent-detach.xml +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent-detach.xml @@ -39,7 +39,7 @@
- +
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent.xml index 0e4c3907bfb..00191a9cb8b 100644 --- a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent.xml +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+qemu-agent.xml @@ -39,7 +39,7 @@
- +
diff --git a/tests/qemuxml2argvdata/channel-unix-source-path.xml b/tests/qemuxml2argvdata/channel-unix-source-path.xml index f24c636147e..db0e99c3d12 100644 --- a/tests/qemuxml2argvdata/channel-unix-source-path.xml +++ b/tests/qemuxml2argvdata/channel-unix-source-path.xml @@ -24,6 +24,10 @@ + + + + diff --git a/tests/qemuxml2xmloutdata/channel-unix-source-path-active.xml b/tests/qemuxml2xmloutdata/channel-unix-source-path-active.xml index 0d6a0295f82..68835ceb151 100644 --- a/tests/qemuxml2xmloutdata/channel-unix-source-path-active.xml +++ b/tests/qemuxml2xmloutdata/channel-unix-source-path-active.xml @@ -41,6 +41,11 @@
+ + + +
+