From patchwork Wed Sep 5 08:31:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406501 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B109840220 for ; Wed, 5 Sep 2012 08:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758063Ab2IEIc2 (ORCPT ); Wed, 5 Sep 2012 04:32:28 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:47853 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752976Ab2IEIcK (ORCPT ); Wed, 5 Sep 2012 04:32:10 -0400 Received: by weyx8 with SMTP id x8so220724wey.19 for ; Wed, 05 Sep 2012 01:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=k29qmWoVy17hp5KydJA6e7jmEfUxDbmz44fBstL9Bjs=; b=uy22QebH+5ATyzt8OX1Y+OocADBN8fAV5lWOQG1e530xGbMP2kScXh8h8ZoOlg1Wfq 8KP9On+8mr5Hu7FQRZOR27V12/DWo/aHi3/Y71OwWQanm4zjvb2DJ7DxVOTXnDiW98Zc YsedpePOI3dXafDfdgUGqpUHZ+c1CueasSzGcwkGr83kj98LlIV6e45aDjvcAa9L253z NNWWQZnWP4WCa2ZsRKwAyEUOnJUgIIZiI6ErIE6ji8LEjuy5jCT+zaMtymle5CwajHVH b3d1gZjnp0bXM1FxXOszY6LKm/wIXoGs60csZTTpTonOb46Nlj6+2fdHxvu31c+2Tyvo EyIw== Received: by 10.216.220.89 with SMTP id n67mr14432077wep.73.1346833929284; Wed, 05 Sep 2012 01:32:09 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.32.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:32:08 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 08/33] kvm tools: move active_console into struct kvm_config Date: Wed, 5 Sep 2012 10:31:42 +0200 Message-Id: <1346833927-15740-9-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This config option was 'extern'ed between different objects. Clean it up and move it into struct kvm_config. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 9 ++++----- tools/kvm/hw/serial.c | 16 ++++++++++------ tools/kvm/include/kvm/kvm-config.h | 1 + tools/kvm/include/kvm/term.h | 10 +++++----- tools/kvm/powerpc/spapr_hvcons.c | 14 ++++++++++---- tools/kvm/term.c | 28 ++++++---------------------- tools/kvm/virtio/console.c | 12 +++++++++--- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 117a9de..2b4315b 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -58,7 +58,6 @@ struct kvm_cpu **kvm_cpus; __thread struct kvm_cpu *current_kvm_cpu; static int kvm_run_wrapper; -extern int active_console; extern int debug_iodelay; bool do_debug_print = false; @@ -1000,11 +999,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) kvm->cfg.console = DEFAULT_CONSOLE; if (!strncmp(kvm->cfg.console, "virtio", 6)) - active_console = CONSOLE_VIRTIO; + kvm->cfg.active_console = CONSOLE_VIRTIO; else if (!strncmp(kvm->cfg.console, "serial", 6)) - active_console = CONSOLE_8250; + kvm->cfg.active_console = CONSOLE_8250; else if (!strncmp(kvm->cfg.console, "hv", 2)) - active_console = CONSOLE_HV; + kvm->cfg.active_console = CONSOLE_HV; else pr_warning("No console!"); @@ -1182,7 +1181,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) } - if (active_console == CONSOLE_VIRTIO) + if (kvm->cfg.active_console == CONSOLE_VIRTIO) virtio_console__init(kvm); if (kvm->cfg.virtio_rng) diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c index 956307c..63dedd0 100644 --- a/tools/kvm/hw/serial.c +++ b/tools/kvm/hw/serial.c @@ -95,12 +95,13 @@ static struct serial8250_device devices[] = { }, }; -static void serial8250_flush_tx(struct serial8250_device *dev) +static void serial8250_flush_tx(struct kvm *kvm, struct serial8250_device *dev) { dev->lsr |= UART_LSR_TEMT | UART_LSR_THRE; if (dev->txcnt) { - term_putc(CONSOLE_8250, dev->txbuf, dev->txcnt, dev->id); + if (kvm->cfg.active_console == CONSOLE_8250) + term_putc(dev->txbuf, dev->txcnt, dev->id); dev->txcnt = 0; } } @@ -149,7 +150,7 @@ static void serial8250_update_irq(struct kvm *kvm, struct serial8250_device *dev * here. */ if (!(dev->ier & UART_IER_THRI)) - serial8250_flush_tx(dev); + serial8250_flush_tx(kvm, dev); } #define SYSRQ_PENDING_NONE 0 @@ -175,7 +176,7 @@ static void serial8250__receive(struct kvm *kvm, struct serial8250_device *dev, * should give the kernel the desired pause. That also flushes * the tx fifo to the terminal. */ - serial8250_flush_tx(dev); + serial8250_flush_tx(kvm, dev); if (dev->mcr & UART_MCR_LOOP) return; @@ -188,10 +189,13 @@ static void serial8250__receive(struct kvm *kvm, struct serial8250_device *dev, return; } - while (term_readable(CONSOLE_8250, dev->id) && + if (kvm->cfg.active_console != CONSOLE_8250) + return; + + while (term_readable(dev->id) && dev->rxcnt < FIFO_LEN) { - c = term_getc(CONSOLE_8250, dev->id); + c = term_getc(dev->id); if (c < 0) break; diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h index e3edf29..fd7a5cd 100644 --- a/tools/kvm/include/kvm/kvm-config.h +++ b/tools/kvm/include/kvm/kvm-config.h @@ -22,6 +22,7 @@ struct kvm_config { u8 image_count; u8 num_net_devices; bool virtio_rng; + int active_console; const char *kernel_cmdline; const char *kernel_filename; const char *vmlinux_filename; diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h index a6a9822..33d96ce 100644 --- a/tools/kvm/include/kvm/term.h +++ b/tools/kvm/include/kvm/term.h @@ -8,12 +8,12 @@ #define CONSOLE_VIRTIO 2 #define CONSOLE_HV 3 -int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term); -int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term); -int term_putc(int who, char *addr, int cnt, int term); -int term_getc(int who, int term); +int term_putc_iov(struct iovec *iov, int iovcnt, int term); +int term_getc_iov(struct iovec *iov, int iovcnt, int term); +int term_putc(char *addr, int cnt, int term); +int term_getc(int term); -bool term_readable(int who, int term); +bool term_readable(int term); void term_set_tty(int term); void term_init(void); diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c index 511dbe1..1fe4bdb 100644 --- a/tools/kvm/powerpc/spapr_hvcons.c +++ b/tools/kvm/powerpc/spapr_hvcons.c @@ -50,7 +50,10 @@ static unsigned long h_put_term_char(struct kvm_cpu *vcpu, unsigned long opcode, do { int ret; - ret = term_putc_iov(CONSOLE_HV, &iov, 1, 0); + if (kvm->cfg.active_console == CONSOLE_HV) + ret = term_putc_iov(&iov, 1, 0); + else + ret = 0; if (ret < 0) { die("term_putc_iov error %d!\n", errno); } @@ -71,11 +74,14 @@ static unsigned long h_get_term_char(struct kvm_cpu *vcpu, unsigned long opcode, union hv_chario data; struct iovec iov; - if (term_readable(CONSOLE_HV, 0)) { + if (kvm->cfg.active_console != CONSOLE_HV) + return H_SUCCESS; + + if (term_readable(0)) { iov.iov_base = data.buf; iov.iov_len = 16; - *len = term_getc_iov(CONSOLE_HV, &iov, 1, 0); + *len = term_getc_iov(&iov, 1, 0); *char0_7 = be64_to_cpu(data.a.char0_7); *char8_15 = be64_to_cpu(data.a.char8_15); } else { @@ -87,7 +93,7 @@ static unsigned long h_get_term_char(struct kvm_cpu *vcpu, unsigned long opcode, void spapr_hvcons_poll(struct kvm *kvm) { - if (term_readable(CONSOLE_HV, 0)) { + if (term_readable(0)) { /* * We can inject an IRQ to guest here if we want. The guest * will happily poll, though, so not required. diff --git a/tools/kvm/term.c b/tools/kvm/term.c index cc0c5a5..8040f5a 100644 --- a/tools/kvm/term.c +++ b/tools/kvm/term.c @@ -23,16 +23,12 @@ static struct termios orig_term; int term_escape_char = 0x01; /* ctrl-a is used for escape */ bool term_got_escape = false; -int active_console; - int term_fds[4][2]; -int term_getc(int who, int term) +int term_getc(int term) { unsigned char c; - if (who != active_console) - return -1; if (read_in_full(term_fds[term][TERM_FD_IN], &c, 1) < 0) return -1; @@ -52,13 +48,10 @@ int term_getc(int who, int term) return c; } -int term_putc(int who, char *addr, int cnt, int term) +int term_putc(char *addr, int cnt, int term) { int ret; - if (who != active_console) - return -1; - while (cnt--) { ret = write(term_fds[term][TERM_FD_OUT], addr++, 1); if (ret < 0) @@ -68,14 +61,11 @@ int term_putc(int who, char *addr, int cnt, int term) return cnt; } -int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term) +int term_getc_iov(struct iovec *iov, int iovcnt, int term) { int c; - if (who != active_console) - return 0; - - c = term_getc(who, term); + c = term_getc(term); if (c < 0) return 0; @@ -85,15 +75,12 @@ int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term) return sizeof(char); } -int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term) +int term_putc_iov(struct iovec *iov, int iovcnt, int term) { - if (who != active_console) - return 0; - return writev(term_fds[term][TERM_FD_OUT], iov, iovcnt); } -bool term_readable(int who, int term) +bool term_readable(int term) { struct pollfd pollfd = (struct pollfd) { .fd = term_fds[term][TERM_FD_IN], @@ -101,9 +88,6 @@ bool term_readable(int who, int term) .revents = 0, }; - if (who != active_console) - return false; - return poll(&pollfd, 1, 0) > 0; } diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index e925a54..4a9ca9f 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -62,13 +62,16 @@ static void virtio_console__inject_interrupt_callback(struct kvm *kvm, void *par u16 head; int len; + if (kvm->cfg.active_console != CONSOLE_VIRTIO) + return; + mutex_lock(&cdev.mutex); vq = param; - if (term_readable(CONSOLE_VIRTIO, 0) && virt_queue__available(vq)) { + if (term_readable(0) && virt_queue__available(vq)) { head = virt_queue__get_iov(vq, iov, &out, &in, kvm); - len = term_getc_iov(CONSOLE_VIRTIO, iov, in, 0); + len = term_getc_iov(iov, in, 0); virt_queue__set_used_elem(vq, head, len); cdev.vdev.ops->signal_vq(kvm, &cdev.vdev, vq - cdev.vqs); } @@ -99,7 +102,10 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param) while (virt_queue__available(vq)) { head = virt_queue__get_iov(vq, iov, &out, &in, kvm); - len = term_putc_iov(CONSOLE_VIRTIO, iov, out, 0); + if (kvm->cfg.active_console == CONSOLE_VIRTIO) + len = term_putc_iov(iov, out, 0); + else + len = 0; virt_queue__set_used_elem(vq, head, len); }