ch: Add support for Unix mode to serial port dev

With Unix mode, pass a socket path to cloud-hypervisor.
Cloud-Hypervisor will attach guest's serial port to this socket path.
Users can connect to the serial port using one of the following commands:

`socat -,crnl UNIX-CONNECT:<path/to/socket>`

OR

`minicom --device unix#<path/to/socket>`

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>
This commit is contained in:
Praveen K Paladugu 2024-03-05 14:57:04 -06:00 committed by Michal Privoznik
parent b2e43609fd
commit b51b06eceb
2 changed files with 30 additions and 10 deletions

View File

@ -89,21 +89,34 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef)
} }
static int static int
virCHMonitorBuildPTYJson(virJSONValue *content, virDomainDef *vmdef) virCHMonitorBuildConsoleJson(virJSONValue *content,
virDomainDef *vmdef)
{ {
if (vmdef->nconsoles) { g_autoptr(virJSONValue) console = virJSONValueNewObject();
g_autoptr(virJSONValue) pty = virJSONValueNewObject(); g_autoptr(virJSONValue) serial = virJSONValueNewObject();
if (virJSONValueObjectAppendString(pty, "mode", "Pty") < 0)
if (vmdef->nconsoles &&
vmdef->consoles[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
if (virJSONValueObjectAppendString(console, "mode", "Pty") < 0)
return -1; return -1;
if (virJSONValueObjectAppend(content, "console", &pty) < 0) if (virJSONValueObjectAppend(content, "console", &console) < 0)
return -1; return -1;
} }
if (vmdef->nserials) { if (vmdef->nserials) {
g_autoptr(virJSONValue) pty = virJSONValueNewObject(); if (vmdef->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
if (virJSONValueObjectAppendString(pty, "mode", "Pty") < 0) if (virJSONValueObjectAppendString(serial, "mode", "Pty") < 0)
return -1; return -1;
if (virJSONValueObjectAppend(content, "serial", &pty) < 0) } else if (vmdef->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_UNIX) {
if (virJSONValueObjectAppendString(serial, "mode", "Socket") < 0)
return -1;
if (virJSONValueObjectAppendString(serial,
"socket",
vmdef->serials[0]->source->data.file.path) < 0)
return -1;
}
if (virJSONValueObjectAppend(content, "serial", &serial) < 0)
return -1; return -1;
} }
@ -415,7 +428,7 @@ virCHMonitorBuildVMJson(virCHDriver *driver, virDomainDef *vmdef,
return -1; return -1;
} }
if (virCHMonitorBuildPTYJson(content, vmdef) < 0) if (virCHMonitorBuildConsoleJson(content, vmdef) < 0)
return -1; return -1;
if (virCHMonitorBuildCPUJson(content, vmdef) < 0) if (virCHMonitorBuildCPUJson(content, vmdef) < 0)

View File

@ -69,6 +69,13 @@ virCHProcessUpdateConsoleDevice(virDomainObj *vm,
if (!config) if (!config)
return; return;
/* This method is used to extract pty info from cloud-hypervisor and capture
* it in domain configuration. This step can be skipped for serial devices
* with unix backend.*/
if (STREQ(device, "serial") &&
vm->def->serials[0]->source->type == VIR_DOMAIN_CHR_TYPE_UNIX)
return;
dev = virJSONValueObjectGet(config, device); dev = virJSONValueObjectGet(config, device);
if (!dev) { if (!dev) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,