[libvirt] [PATCH] Generate unique socket file

Martin Kletzander mkletzan at redhat.com
Tue Jul 25 07:58:10 UTC 2017


On Mon, Jul 24, 2017 at 10:34:49AM -0500, seg at us.ibm.com wrote:
>From: Scott Garfinkle <seg at us.ibm.com>
>

No need to have a cover letter, the information from the cover letter
you sent should instead be here.

>It's possible to have more than one unix channel with type=virtio-serial.
>We need to generate a unique name for each channel. Currently, we use
>"unknown.sock" for all of them.

The reason you get that is because you gave them no target name.  The
right way to do this is to actually give them target names so that you
can differentiate them in the guest nicely.  We might generate some
names for the sockets and let them get just some vportXnY identifiers in
the guest, but I would rather prefer making users name the channels.

>---
> src/qemu/qemu_domain.c                             | 23 +++++++++++++++-------
> .../qemuxml2argv-channel-virtio-unix.args          |  2 +-
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
>diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>index 78e75f1..791d4cf 100644
>--- a/src/qemu/qemu_domain.c
>+++ b/src/qemu/qemu_domain.c
>@@ -7178,18 +7178,27 @@ int
> qemuDomainPrepareChannel(virDomainChrDefPtr channel,
>                          const char *domainChannelTargetDir)
> {
>-    if (channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
>-        channel->source->type == VIR_DOMAIN_CHR_TYPE_UNIX &&
>-        !channel->source->data.nix.path) {
>+    if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO ||
>+        channel->source->type != VIR_DOMAIN_CHR_TYPE_UNIX ||
>+        channel->source->data.nix.path)
>+            return 0;
>+
>+    if (channel->target.name) {
>         if (virAsprintf(&channel->source->data.nix.path,
>                         "%s/%s", domainChannelTargetDir,
>-                        channel->target.name ? channel->target.name
>-                        : "unknown.sock") < 0)
>+                        channel->target.name) < 0)
>+            return -1;
>+    } else {    // Generate a unique name
>+        if (virAsprintf(&channel->source->data.nix.path,
>+                        "%s/unknown.sock%d%d%d", domainChannelTargetDir,
>+                        channel->info.addr.vioserial.controller,
>+                        channel->info.addr.vioserial.bus,
>+                        channel->info.addr.vioserial.port) < 0)

This needs some separator between the numbers, also in this case I would
rename it to something else than "unknown.sock" and most of all, leave
the '.sock' at the end.

>             return -1;
>-
>-        channel->source->data.nix.listen = true;
>     }
>
>+    channel->source->data.nix.listen = true;
>+
>     return 0;
> }
>
>diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-unix.args b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-unix.args
>index 2b72965..c875a09 100644
>--- a/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-unix.args
>+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-unix.args
>@@ -29,7 +29,7 @@ path=/tmp/channel/domain--1-QEMUGuest1/org.qemu.guest_agent.0,server,nowait \
> -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,\
> id=channel0,name=org.qemu.guest_agent.0 \
> -chardev socket,id=charchannel1,\
>-path=/tmp/channel/domain--1-QEMUGuest1/unknown.sock,server,nowait \
>+path=/tmp/channel/domain--1-QEMUGuest1/unknown.sock002,server,nowait \
> -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,\
> id=channel1 \
> -chardev socket,id=charchannel2,path=/tmp/channel/domain--1-QEMUGuest1/ble,\
>--
>1.8.3.1
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170725/d48da5f1/attachment-0001.sig>


More information about the libvir-list mailing list