]> xenbits.xensource.com Git - libvirt.git/commitdiff
Generate unique socket file
authorScott Garfinkle <seg@us.ibm.com>
Tue, 25 Jul 2017 14:33:50 +0000 (09:33 -0500)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 25 Jul 2017 20:38:35 +0000 (22:38 +0200)
It's possible to have more than one unnamed virtio-serial unix channel.
We need to generate a unique name for each channel. Currently, we use
".../unknown.sock" for all of them. Better practice would be to specify
an explicit target path name; however, in the absence of that, we need
uniqueness in the names we generate internally.

Before the changes we'd get /var/lib/libvirt/qemu/channel/target/unknown.sock
for each instance of
    <channel type='unix'>
        <source mode='bind'/>
        <target type='virtio'/>
    </channel>

Now, we get vioser-00-00-01.sock, vioser-00-00-02.sock, etc.

Signed-off-by: Scott Garfinkle <seg@us.ibm.com>
src/qemu/qemu_domain.c
tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-unix.args

index e3b5c94ded46bb0e75ccd56b71fb7ad36754cecd..dcdbfc9701623b1ce5222e1bb6ea0e178e31d392 100644 (file)
@@ -7254,18 +7254,28 @@ 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/vioser-%02d-%02d-%02d.sock",
+                        domainChannelTargetDir,
+                        channel->info.addr.vioserial.controller,
+                        channel->info.addr.vioserial.bus,
+                        channel->info.addr.vioserial.port) < 0)
             return -1;
-
-        channel->source->data.nix.listen = true;
     }
 
+    channel->source->data.nix.listen = true;
+
     return 0;
 }
 
index 2b7296531a23823dd44081c550ff5f17c25f33f8..8e0452a9f31c3c8e60d30ccc06c28f8a8503d8f8 100644 (file)
@@ -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/vioser-00-00-02.sock,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,\