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 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; struct virtio_console_backend *be;
int error = 0, fd = -1; int error = 0, fd = -1;
@ -801,54 +801,56 @@ virtio_console_add_backend(struct virtio_console *console, char *opts)
char *portname = NULL; char *portname = NULL;
char *portpath = NULL; char *portpath = NULL;
char *socket_type = NULL; char *socket_type = NULL;
char *opt;
enum virtio_console_be_type be_type = VIRTIO_CONSOLE_BE_INVALID; enum virtio_console_be_type be_type = VIRTIO_CONSOLE_BE_INVALID;
/* virtio-console,[@]stdio|tty|pty|file:portname[=portpath] backend = strsep(&opt, ":");
* [,[@]stdio|tty|pty|file:portname[=portpath][:socket_type]] if (backend == NULL) {
*/ WPRINTF(("vtcon: no backend is specified!\n"));
while ((opt = strsep(&opts, ",")) != NULL) { error = -1;
backend = strsep(&opt, ":"); goto parse_fail;
}
if (backend == NULL) { if (backend[0] == '@') {
WPRINTF(("vtcon: no backend is specified!\n")); is_console = true;
backend++;
} else
is_console = false;
be_type = virtio_console_get_be_type(backend);
if (be_type == VIRTIO_CONSOLE_BE_INVALID) {
WPRINTF(("vtcon: invalid backend %s!\n",
backend));
error = -1;
goto parse_fail;
}
if (opt != NULL) {
if (be_type == VIRTIO_CONSOLE_BE_SOCKET) {
portname = strsep(&opt, "=");
portpath = strsep(&opt, ":");
socket_type = opt;
} else {
portname = strsep(&opt, "=");
portpath = opt;
}
if (portname == NULL) {
WPRINTF(("vtcon: portname missing \n"));
error = -1; error = -1;
goto parse_fail; goto parse_fail;
} }
if (portpath == NULL
if (backend[0] == '@') { && be_type != VIRTIO_CONSOLE_BE_STDIO
is_console = true; && be_type != VIRTIO_CONSOLE_BE_PTY
backend++; && be_type != VIRTIO_CONSOLE_BE_SOCKET) {
} else WPRINTF(("vtcon: portpath missing for %s\n",
is_console = false; portname));
be_type = virtio_console_get_be_type(backend);
if (be_type == VIRTIO_CONSOLE_BE_INVALID) {
WPRINTF(("vtcon: invalid backend %s!\n",
backend));
error = -1; error = -1;
goto parse_fail; goto parse_fail;
} }
} else {
if (opt != NULL) { WPRINTF(("vtcon: please at least config portname\n"));
if (be_type == VIRTIO_CONSOLE_BE_SOCKET) { error = -1;
portname = strsep(&opt, "="); goto parse_fail;
portpath = strsep(&opt, ":");
socket_type = opt;
} else {
portname = strsep(&opt, "=");
portpath = opt;
}
if (portpath == NULL
&& be_type != VIRTIO_CONSOLE_BE_STDIO
&& be_type != VIRTIO_CONSOLE_BE_PTY
&& be_type != VIRTIO_CONSOLE_BE_SOCKET) {
WPRINTF(("vtcon: portpath missing for %s\n",
portname));
error = -1;
goto parse_fail;
}
}
} }
be = calloc(1, sizeof(struct virtio_console_backend)); be = calloc(1, sizeof(struct virtio_console_backend));
@ -916,11 +918,24 @@ out:
} }
parse_fail: parse_fail:
WPRINTF(("vtcon: add port failed %s\n", portname));
return error; 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 static void
virtio_console_close_backend(struct virtio_console_backend *be) 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.rxq = 3;
console->control_port.cb = virtio_console_control_tx; console->control_port.cb = virtio_console_control_tx;
console->control_port.enabled = true; console->control_port.enabled = true;
if (virtio_console_add_backend(console, opts) < 0) { if (virtio_console_add_backends(console, opts) < 0) {
return -1; return -1;
} }