aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/net.c
diff options
context:
space:
mode:
authorKrishna Kumar <krkumar2@in.ibm.com>2011-03-01 06:36:37 -0500
committerMichael S. Tsirkin <mst@redhat.com>2011-03-08 11:02:47 -0500
commitd47effe1be0c4fc983306a9c704632e3a087eed8 (patch)
treed0705237c61d02734e79c02440bad7a439b6ac68 /drivers/vhost/net.c
parent1fc050a13473348f5c439de2bb41c8e92dba5588 (diff)
vhost: Cleanup vhost.c and net.c
Minor cleanup of vhost.c and net.c to match coding style. Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost/net.c')
-rw-r--r--drivers/vhost/net.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index f616cefc95ba..59dad9fe52dd 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -60,6 +60,7 @@ static int move_iovec_hdr(struct iovec *from, struct iovec *to,
60{ 60{
61 int seg = 0; 61 int seg = 0;
62 size_t size; 62 size_t size;
63
63 while (len && seg < iov_count) { 64 while (len && seg < iov_count) {
64 size = min(from->iov_len, len); 65 size = min(from->iov_len, len);
65 to->iov_base = from->iov_base; 66 to->iov_base = from->iov_base;
@@ -79,6 +80,7 @@ static void copy_iovec_hdr(const struct iovec *from, struct iovec *to,
79{ 80{
80 int seg = 0; 81 int seg = 0;
81 size_t size; 82 size_t size;
83
82 while (len && seg < iovcount) { 84 while (len && seg < iovcount) {
83 size = min(from->iov_len, len); 85 size = min(from->iov_len, len);
84 to->iov_base = from->iov_base; 86 to->iov_base = from->iov_base;
@@ -296,17 +298,16 @@ static void handle_rx_big(struct vhost_net *net)
296 .msg_iov = vq->iov, 298 .msg_iov = vq->iov,
297 .msg_flags = MSG_DONTWAIT, 299 .msg_flags = MSG_DONTWAIT,
298 }; 300 };
299
300 struct virtio_net_hdr hdr = { 301 struct virtio_net_hdr hdr = {
301 .flags = 0, 302 .flags = 0,
302 .gso_type = VIRTIO_NET_HDR_GSO_NONE 303 .gso_type = VIRTIO_NET_HDR_GSO_NONE
303 }; 304 };
304
305 size_t len, total_len = 0; 305 size_t len, total_len = 0;
306 int err; 306 int err;
307 size_t hdr_size; 307 size_t hdr_size;
308 /* TODO: check that we are running from vhost_worker? */ 308 /* TODO: check that we are running from vhost_worker? */
309 struct socket *sock = rcu_dereference_check(vq->private_data, 1); 309 struct socket *sock = rcu_dereference_check(vq->private_data, 1);
310
310 if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue)) 311 if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue))
311 return; 312 return;
312 313
@@ -405,18 +406,17 @@ static void handle_rx_mergeable(struct vhost_net *net)
405 .msg_iov = vq->iov, 406 .msg_iov = vq->iov,
406 .msg_flags = MSG_DONTWAIT, 407 .msg_flags = MSG_DONTWAIT,
407 }; 408 };
408
409 struct virtio_net_hdr_mrg_rxbuf hdr = { 409 struct virtio_net_hdr_mrg_rxbuf hdr = {
410 .hdr.flags = 0, 410 .hdr.flags = 0,
411 .hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE 411 .hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE
412 }; 412 };
413
414 size_t total_len = 0; 413 size_t total_len = 0;
415 int err, headcount; 414 int err, headcount;
416 size_t vhost_hlen, sock_hlen; 415 size_t vhost_hlen, sock_hlen;
417 size_t vhost_len, sock_len; 416 size_t vhost_len, sock_len;
418 /* TODO: check that we are running from vhost_worker? */ 417 /* TODO: check that we are running from vhost_worker? */
419 struct socket *sock = rcu_dereference_check(vq->private_data, 1); 418 struct socket *sock = rcu_dereference_check(vq->private_data, 1);
419
420 if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue)) 420 if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue))
421 return; 421 return;
422 422
@@ -654,6 +654,7 @@ static struct socket *get_raw_socket(int fd)
654 } uaddr; 654 } uaddr;
655 int uaddr_len = sizeof uaddr, r; 655 int uaddr_len = sizeof uaddr, r;
656 struct socket *sock = sockfd_lookup(fd, &r); 656 struct socket *sock = sockfd_lookup(fd, &r);
657
657 if (!sock) 658 if (!sock)
658 return ERR_PTR(-ENOTSOCK); 659 return ERR_PTR(-ENOTSOCK);
659 660
@@ -682,6 +683,7 @@ static struct socket *get_tap_socket(int fd)
682{ 683{
683 struct file *file = fget(fd); 684 struct file *file = fget(fd);
684 struct socket *sock; 685 struct socket *sock;
686
685 if (!file) 687 if (!file)
686 return ERR_PTR(-EBADF); 688 return ERR_PTR(-EBADF);
687 sock = tun_get_socket(file); 689 sock = tun_get_socket(file);
@@ -696,6 +698,7 @@ static struct socket *get_tap_socket(int fd)
696static struct socket *get_socket(int fd) 698static struct socket *get_socket(int fd)
697{ 699{
698 struct socket *sock; 700 struct socket *sock;
701
699 /* special case to disable backend */ 702 /* special case to disable backend */
700 if (fd == -1) 703 if (fd == -1)
701 return NULL; 704 return NULL;
@@ -741,9 +744,9 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
741 oldsock = rcu_dereference_protected(vq->private_data, 744 oldsock = rcu_dereference_protected(vq->private_data,
742 lockdep_is_held(&vq->mutex)); 745 lockdep_is_held(&vq->mutex));
743 if (sock != oldsock) { 746 if (sock != oldsock) {
744 vhost_net_disable_vq(n, vq); 747 vhost_net_disable_vq(n, vq);
745 rcu_assign_pointer(vq->private_data, sock); 748 rcu_assign_pointer(vq->private_data, sock);
746 vhost_net_enable_vq(n, vq); 749 vhost_net_enable_vq(n, vq);
747 } 750 }
748 751
749 mutex_unlock(&vq->mutex); 752 mutex_unlock(&vq->mutex);
@@ -768,6 +771,7 @@ static long vhost_net_reset_owner(struct vhost_net *n)
768 struct socket *tx_sock = NULL; 771 struct socket *tx_sock = NULL;
769 struct socket *rx_sock = NULL; 772 struct socket *rx_sock = NULL;
770 long err; 773 long err;
774
771 mutex_lock(&n->dev.mutex); 775 mutex_lock(&n->dev.mutex);
772 err = vhost_dev_check_owner(&n->dev); 776 err = vhost_dev_check_owner(&n->dev);
773 if (err) 777 if (err)
@@ -829,6 +833,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
829 struct vhost_vring_file backend; 833 struct vhost_vring_file backend;
830 u64 features; 834 u64 features;
831 int r; 835 int r;
836
832 switch (ioctl) { 837 switch (ioctl) {
833 case VHOST_NET_SET_BACKEND: 838 case VHOST_NET_SET_BACKEND:
834 if (copy_from_user(&backend, argp, sizeof backend)) 839 if (copy_from_user(&backend, argp, sizeof backend))