DM: virtio-console: bug fix for parsing options

Bug fix for parsing options, as the vritio-console support multiple
virtio serial ports, and the parameters is split by ',':

virtio-console,[@]stdio|tty|pty|file:portname[=portpath]\
   [,[@]stdio|tty|pty|file:portname[=portpath]]

But the previous patch "refine console options parse code" not
cover this case, can only parse one port config. Fix it in this patch.

Tracked-On: #3337
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
This commit is contained in:
Conghui Chen 2019-06-18 02:06:34 +08:00 committed by ACRN System Integration
parent 4d88b2bb65
commit 8badd0b486

View File

@ -792,7 +792,7 @@ virtio_console_get_be_type(const char *backend)
}
static int
virtio_console_add_backend(struct virtio_console *console, char *opts)
virtio_console_add_backend(struct virtio_console *console, char *opt)
{
struct virtio_console_backend *be;
int error = 0, fd = -1;
@ -801,15 +801,9 @@ virtio_console_add_backend(struct virtio_console *console, char *opts)
char *portname = NULL;
char *portpath = NULL;
char *socket_type = NULL;
char *opt;
enum virtio_console_be_type be_type = VIRTIO_CONSOLE_BE_INVALID;
/* virtio-console,[@]stdio|tty|pty|file:portname[=portpath]
* [,[@]stdio|tty|pty|file:portname[=portpath][:socket_type]]
*/
while ((opt = strsep(&opts, ",")) != NULL) {
backend = strsep(&opt, ":");
if (backend == NULL) {
WPRINTF(("vtcon: no backend is specified!\n"));
error = -1;
@ -839,6 +833,11 @@ virtio_console_add_backend(struct virtio_console *console, char *opts)
portname = strsep(&opt, "=");
portpath = opt;
}
if (portname == NULL) {
WPRINTF(("vtcon: portname missing \n"));
error = -1;
goto parse_fail;
}
if (portpath == NULL
&& be_type != VIRTIO_CONSOLE_BE_STDIO
&& be_type != VIRTIO_CONSOLE_BE_PTY
@ -848,7 +847,10 @@ virtio_console_add_backend(struct virtio_console *console, char *opts)
error = -1;
goto parse_fail;
}
}
} else {
WPRINTF(("vtcon: please at least config portname\n"));
error = -1;
goto parse_fail;
}
be = calloc(1, sizeof(struct virtio_console_backend));
@ -916,11 +918,24 @@ out:
}
parse_fail:
WPRINTF(("vtcon: add port failed %s\n", portname));
return error;
}
static int
virtio_console_add_backends(struct virtio_console *console, char *opts)
{
char *opt;
/* virtio-console,[@]stdio|tty|pty|file:portname[=portpath]
* [,[@]stdio|tty|pty|file:portname[=portpath][:socket_type]]
*/
while ((opt = strsep(&opts, ",")) != NULL) {
if (virtio_console_add_backend(console, opt))
return -1;
}
return 0;
}
static void
virtio_console_close_backend(struct virtio_console_backend *be)
{
@ -1102,7 +1117,7 @@ virtio_console_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
console->control_port.rxq = 3;
console->control_port.cb = virtio_console_control_tx;
console->control_port.enabled = true;
if (virtio_console_add_backend(console, opts) < 0) {
if (virtio_console_add_backends(console, opts) < 0) {
return -1;
}