public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com,
	prasadjoshi124@gmail.com, kvm@vger.kernel.org,
	Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 3/5] kvm tools: virtio-console code cleanup
Date: Thu,  5 May 2011 21:34:33 +0300	[thread overview]
Message-ID: <1304620475-10289-3-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1304620475-10289-1-git-send-email-levinsasha928@gmail.com>

Clean coding style and naming within virtio-console.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 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;
 }
 
-- 
1.7.5.rc3


  parent reply	other threads:[~2011-05-05 18:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05 18:34 [PATCH 1/5] kvm tools: Abolishment of uint*_t types Sasha Levin
2011-05-05 18:34 ` [PATCH 2/5] kvm tools: virtio-blk code cleanup Sasha Levin
2011-05-05 18:34 ` Sasha Levin [this message]
2011-05-05 18:34 ` [PATCH 4/5] kvm tools: virtio-net " Sasha Levin
2011-05-05 18:34 ` [PATCH 5/5] kvm tools: virtio-rng " Sasha Levin
2011-05-05 19:06   ` Ingo Molnar
2011-05-05 19:02 ` [PATCH 1/5] kvm tools: Abolishment of uint*_t types Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304620475-10289-3-git-send-email-levinsasha928@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox