]> xenbits.xensource.com Git - libvirt.git/commitdiff
ch: Add Cap checks for unix backend of serial port
authorPraveen K Paladugu <praveenkpaladugu@gmail.com>
Tue, 5 Mar 2024 20:57:03 +0000 (14:57 -0600)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 7 Mar 2024 14:27:12 +0000 (15:27 +0100)
Unix Socket backend is only supported for serial port in
cloud-hypervisor. Add relevant checks in chValidateDomainDeviceDef.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_capabilities.c
src/ch/ch_capabilities.h
src/ch/ch_domain.c

index b9e62d2d5bf535c46ffd730f16ebe815538cf61a..5941851500f0c902818fe6190f9100b8b8a0f590 100644 (file)
@@ -59,6 +59,12 @@ virCHCapsInitCHVersionCaps(int version)
     if (version >= 22000000)
         virCHCapsSet(chCaps, CH_MULTIFD_IN_ADDNET);
 
+    /* Starting v36, Cloud-Hypervisor accepts Unix Socket as a backend for
+     * guest's serial port.
+     * https://github.com/cloud-hypervisor/cloud-hypervisor/releases/tag/v36.0 */
+    if (version >= 36000000)
+        virCHCapsSet(chCaps, CH_SOCKET_BACKEND_SERIAL_PORT);
+
     return g_steal_pointer(&chCaps);
 
 }
index ffb8881a11170f02a924f88572aceb2fbf55a8b5..03932511f65747240446f88f12968440670dd3f6 100644 (file)
@@ -27,6 +27,7 @@ typedef enum {
     CH_KERNEL_API_DEPRCATED, /* Use `payload` in place of `kernel` api */
     CH_SERIAL_CONSOLE_IN_PARALLEL, /* Serial and Console ports can work in parallel */
     CH_MULTIFD_IN_ADDNET, /* Cloud-hypervisor can accept multiple FDs in add-net api */
+    CH_SOCKET_BACKEND_SERIAL_PORT, /* Support Unix socket as a backend for a serial port */
 
     CH_CAPS_LAST /* this must always be the last item */
 } virCHCapsFlags;
index a6bf749d8947332cdfb3dfd06f571a69cf67abf6..acadd76edcf9ed1ba4d6c7a8b63b283bc1d7d6f3 100644 (file)
@@ -195,16 +195,15 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
 
     if (!virBitmapIsBitSet(driver->chCaps, CH_SERIAL_CONSOLE_IN_PARALLEL)) {
         if ((def->nconsoles &&
-                def->consoles[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY)
-            && (def->nserials &&
-                def->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY)) {
+             def->consoles[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY) &&
+            (def->nserials &&
+             def->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY)) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Only a single console or serial can be configured for this domain"));
+                           _("Only a single console or serial can be configured for this domain"));
             return -1;
         }
     }
 
-
     if (def->nconsoles > 1) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Only a single console can be configured for this domain"));
@@ -219,15 +218,25 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
 
     if (def->nconsoles && def->consoles[0]->source->type != VIR_DOMAIN_CHR_TYPE_PTY) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Console can only be enabled for a PTY"));
+                       _("Console only works in PTY mode"));
         return -1;
     }
 
-    if (def->nserials && def->serials[0]->source->type != VIR_DOMAIN_CHR_TYPE_PTY) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Serial can only be enabled for a PTY"));
-        return -1;
+    if (def->nserials) {
+        if (def->serials[0]->source->type != VIR_DOMAIN_CHR_TYPE_PTY &&
+            def->serials[0]->source->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Serial only works in UNIX/PTY modes"));
+            return -1;
+        }
+        if (!virBitmapIsBitSet(driver->chCaps, CH_SOCKET_BACKEND_SERIAL_PORT) &&
+            def->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_UNIX) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Unix Socket backend is not supported by this version of ch."));
+            return -1;
+        }
     }
+
     return 0;
 }