From patchwork Thu May 5 18:34:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 757892 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p45IZXin029142 for ; Thu, 5 May 2011 18:35:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086Ab1EESfY (ORCPT ); Thu, 5 May 2011 14:35:24 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:35336 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932073Ab1EESfX (ORCPT ); Thu, 5 May 2011 14:35:23 -0400 Received: by wya21 with SMTP id 21so1836344wya.19 for ; Thu, 05 May 2011 11:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=FWOmmbIJnsMXPBHGNWwYQIfO/MlG73Sc6FsbAD5MfsE=; b=aLuFcybkl/PEGjE61AT2ooST8OopZpshHiHPcbbnAzTC6mg3PAI3wFcZt/xy24ZHFT jFI90yJHsokvKVuXN+7nXZHer0HaCWgpaVU3Gz3X+h3tSDv/EIaJHpvFaWTzrSNAJCIc 6CJz665dpw5l7gMWhzV/EIcNqdlInzncxagPo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=SHgd8JftA9zcZrDT/N4uHa9f+At97LwkBnw+tde3zmCK5Yvhxoy6Vh3GYu5L1yrwLx xtOCAtvuzG4bTyyax3FGWLnOnKYES6EhBKaj+svuf8XmMKwx7w+H0TR5ryXlGbkykF5r zG0AtzVS+uER+jRq/CSiXPFN1I5/W6GucVMZM= Received: by 10.227.197.83 with SMTP id ej19mr2763751wbb.105.1304620521778; Thu, 05 May 2011 11:35:21 -0700 (PDT) Received: from localhost.localdomain ([109.65.211.213]) by mx.google.com with ESMTPS id x13sm1037449wby.25.2011.05.05.11.35.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2011 11:35:21 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 3/5] kvm tools: virtio-console code cleanup Date: Thu, 5 May 2011 21:34:33 +0300 Message-Id: <1304620475-10289-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1304620475-10289-1-git-send-email-levinsasha928@gmail.com> References: <1304620475-10289-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 05 May 2011 18:35:33 +0000 (UTC) Clean coding style and naming within virtio-console. Signed-off-by: Sasha Levin --- tools/kvm/virtio/console.c | 69 +++++++++++++++++++++---------------------- 1 files changed, 34 insertions(+), 35 deletions(-) diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index 3be65d3..6ccb1ef 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -31,7 +31,7 @@ #define VIRTIO_CONSOLE_TX_QUEUE 1 #define PCI_VIRTIO_CONSOLE_DEVNUM 2 -struct console_device { +struct con_dev { pthread_mutex_t mutex; struct virt_queue vqs[VIRTIO_CONSOLE_NUM_QUEUES]; @@ -45,7 +45,7 @@ struct console_device { void *jobs[VIRTIO_CONSOLE_NUM_QUEUES]; }; -static struct console_device console_device = { +static struct con_dev cdev = { .mutex = PTHREAD_MUTEX_INITIALIZER, .console_config = { @@ -68,7 +68,7 @@ static void virtio_console__inject_interrupt_callback(struct kvm *self, void *pa u16 head; int len; - mutex_lock(&console_device.mutex); + mutex_lock(&cdev.mutex); vq = param; @@ -79,17 +79,17 @@ static void virtio_console__inject_interrupt_callback(struct kvm *self, void *pa kvm__irq_line(self, VIRTIO_CONSOLE_IRQ, 1); } - mutex_unlock(&console_device.mutex); + mutex_unlock(&cdev.mutex); } void virtio_console__inject_interrupt(struct kvm *self) { - thread_pool__do_job(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]); + thread_pool__do_job(cdev.jobs[VIRTIO_CONSOLE_RX_QUEUE]); } static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long offset, int size, u32 count) { - u8 *config_space = (u8 *) &console_device.console_config; + u8 *config_space = (u8 *) &cdev.console_config; if (size != 1 || count != 1) return false; @@ -107,17 +107,17 @@ static bool virtio_console_pci_io_in(struct kvm *self, u16 port, void *data, int unsigned long offset = port - IOPORT_VIRTIO_CONSOLE; bool ret = true; - mutex_lock(&console_device.mutex); + mutex_lock(&cdev.mutex); switch (offset) { case VIRTIO_PCI_HOST_FEATURES: - ioport__write32(data, console_device.host_features); + ioport__write32(data, cdev.host_features); break; case VIRTIO_PCI_GUEST_FEATURES: ret = false; break; case VIRTIO_PCI_QUEUE_PFN: - ioport__write32(data, console_device.vqs[console_device.queue_selector].pfn); + ioport__write32(data, cdev.vqs[cdev.queue_selector].pfn); break; case VIRTIO_PCI_QUEUE_NUM: ioport__write16(data, VIRTIO_CONSOLE_QUEUE_SIZE); @@ -127,31 +127,31 @@ static bool virtio_console_pci_io_in(struct kvm *self, u16 port, void *data, int ret = false; break; case VIRTIO_PCI_STATUS: - ioport__write8(data, console_device.status); + ioport__write8(data, cdev.status); break; case VIRTIO_PCI_ISR: ioport__write8(data, 0x1); kvm__irq_line(self, VIRTIO_CONSOLE_IRQ, 0); break; case VIRTIO_MSI_CONFIG_VECTOR: - ioport__write16(data, console_device.config_vector); + ioport__write16(data, cdev.config_vector); break; default: ret = virtio_console_pci_io_device_specific_in(data, offset, size, count); }; - mutex_unlock(&console_device.mutex); + mutex_unlock(&cdev.mutex); return ret; } static void virtio_console_handle_callback(struct kvm *self, void *param) { - struct iovec iov[VIRTIO_CONSOLE_QUEUE_SIZE]; - struct virt_queue *vq; - u16 out, in; - u16 head; - u32 len; + struct iovec iov[VIRTIO_CONSOLE_QUEUE_SIZE]; + struct virt_queue *vq; + u16 out, in; + u16 head; + u32 len; vq = param; @@ -166,58 +166,57 @@ static void virtio_console_handle_callback(struct kvm *self, void *param) static bool virtio_console_pci_io_out(struct kvm *self, u16 port, void *data, int size, u32 count) { - unsigned long offset = port - IOPORT_VIRTIO_CONSOLE; - bool ret = true; + unsigned long offset = port - IOPORT_VIRTIO_CONSOLE; + bool ret = true; - mutex_lock(&console_device.mutex); + mutex_lock(&cdev.mutex); switch (offset) { case VIRTIO_PCI_GUEST_FEATURES: - console_device.guest_features = ioport__read32(data); + cdev.guest_features = ioport__read32(data); break; case VIRTIO_PCI_QUEUE_PFN: { struct virt_queue *queue; void *p; - assert(console_device.queue_selector < VIRTIO_CONSOLE_NUM_QUEUES); + assert(cdev.queue_selector < VIRTIO_CONSOLE_NUM_QUEUES); - queue = &console_device.vqs[console_device.queue_selector]; + queue = &cdev.vqs[cdev.queue_selector]; queue->pfn = ioport__read32(data); p = guest_flat_to_host(self, queue->pfn << 12); vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096); - if (console_device.queue_selector == VIRTIO_CONSOLE_TX_QUEUE) - console_device.jobs[console_device.queue_selector] = + if (cdev.queue_selector == VIRTIO_CONSOLE_TX_QUEUE) + cdev.jobs[cdev.queue_selector] = thread_pool__add_job(self, virtio_console_handle_callback, queue); - else if (console_device.queue_selector == VIRTIO_CONSOLE_RX_QUEUE) - console_device.jobs[console_device.queue_selector] = + else if (cdev.queue_selector == VIRTIO_CONSOLE_RX_QUEUE) + cdev.jobs[cdev.queue_selector] = thread_pool__add_job(self, virtio_console__inject_interrupt_callback, queue); break; } case VIRTIO_PCI_QUEUE_SEL: - console_device.queue_selector = ioport__read16(data); + cdev.queue_selector = ioport__read16(data); break; case VIRTIO_PCI_QUEUE_NOTIFY: { - u16 queue_index; - queue_index = ioport__read16(data); - thread_pool__do_job(console_device.jobs[queue_index]); + u16 queue_index = ioport__read16(data); + thread_pool__do_job(cdev.jobs[queue_index]); break; } case VIRTIO_PCI_STATUS: - console_device.status = ioport__read8(data); + cdev.status = ioport__read8(data); break; case VIRTIO_MSI_CONFIG_VECTOR: - console_device.config_vector = VIRTIO_MSI_NO_VECTOR; + cdev.config_vector = VIRTIO_MSI_NO_VECTOR; break; case VIRTIO_MSI_QUEUE_VECTOR: break; default: - ret = false; + ret = false; }; - mutex_unlock(&console_device.mutex); + mutex_unlock(&cdev.mutex); return ret; }