aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vhost/net.c')
-rw-r--r--drivers/vhost/net.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index f11e6bb5b036..d395b59289ae 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -302,54 +302,58 @@ static void handle_rx(struct vhost_net *net)
302 unuse_mm(net->dev.mm); 302 unuse_mm(net->dev.mm);
303} 303}
304 304
305static void handle_tx_kick(struct work_struct *work) 305static void handle_tx_kick(struct vhost_work *work)
306{ 306{
307 struct vhost_virtqueue *vq; 307 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
308 struct vhost_net *net; 308 poll.work);
309 vq = container_of(work, struct vhost_virtqueue, poll.work); 309 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev);
310 net = container_of(vq->dev, struct vhost_net, dev); 310
311 handle_tx(net); 311 handle_tx(net);
312} 312}
313 313
314static void handle_rx_kick(struct work_struct *work) 314static void handle_rx_kick(struct vhost_work *work)
315{ 315{
316 struct vhost_virtqueue *vq; 316 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
317 struct vhost_net *net; 317 poll.work);
318 vq = container_of(work, struct vhost_virtqueue, poll.work); 318 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev);
319 net = container_of(vq->dev, struct vhost_net, dev); 319
320 handle_rx(net); 320 handle_rx(net);
321} 321}
322 322
323static void handle_tx_net(struct work_struct *work) 323static void handle_tx_net(struct vhost_work *work)
324{ 324{
325 struct vhost_net *net; 325 struct vhost_net *net = container_of(work, struct vhost_net,
326 net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_TX].work); 326 poll[VHOST_NET_VQ_TX].work);
327 handle_tx(net); 327 handle_tx(net);
328} 328}
329 329
330static void handle_rx_net(struct work_struct *work) 330static void handle_rx_net(struct vhost_work *work)
331{ 331{
332 struct vhost_net *net; 332 struct vhost_net *net = container_of(work, struct vhost_net,
333 net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_RX].work); 333 poll[VHOST_NET_VQ_RX].work);
334 handle_rx(net); 334 handle_rx(net);
335} 335}
336 336
337static int vhost_net_open(struct inode *inode, struct file *f) 337static int vhost_net_open(struct inode *inode, struct file *f)
338{ 338{
339 struct vhost_net *n = kmalloc(sizeof *n, GFP_KERNEL); 339 struct vhost_net *n = kmalloc(sizeof *n, GFP_KERNEL);
340 struct vhost_dev *dev;
340 int r; 341 int r;
342
341 if (!n) 343 if (!n)
342 return -ENOMEM; 344 return -ENOMEM;
345
346 dev = &n->dev;
343 n->vqs[VHOST_NET_VQ_TX].handle_kick = handle_tx_kick; 347 n->vqs[VHOST_NET_VQ_TX].handle_kick = handle_tx_kick;
344 n->vqs[VHOST_NET_VQ_RX].handle_kick = handle_rx_kick; 348 n->vqs[VHOST_NET_VQ_RX].handle_kick = handle_rx_kick;
345 r = vhost_dev_init(&n->dev, n->vqs, VHOST_NET_VQ_MAX); 349 r = vhost_dev_init(dev, n->vqs, VHOST_NET_VQ_MAX);
346 if (r < 0) { 350 if (r < 0) {
347 kfree(n); 351 kfree(n);
348 return r; 352 return r;
349 } 353 }
350 354
351 vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT); 355 vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT, dev);
352 vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN); 356 vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN, dev);
353 n->tx_poll_state = VHOST_NET_POLL_DISABLED; 357 n->tx_poll_state = VHOST_NET_POLL_DISABLED;
354 358
355 f->private_data = n; 359 f->private_data = n;
@@ -656,25 +660,13 @@ static struct miscdevice vhost_net_misc = {
656 660
657static int vhost_net_init(void) 661static int vhost_net_init(void)
658{ 662{
659 int r = vhost_init(); 663 return misc_register(&vhost_net_misc);
660 if (r)
661 goto err_init;
662 r = misc_register(&vhost_net_misc);
663 if (r)
664 goto err_reg;
665 return 0;
666err_reg:
667 vhost_cleanup();
668err_init:
669 return r;
670
671} 664}
672module_init(vhost_net_init); 665module_init(vhost_net_init);
673 666
674static void vhost_net_exit(void) 667static void vhost_net_exit(void)
675{ 668{
676 misc_deregister(&vhost_net_misc); 669 misc_deregister(&vhost_net_misc);
677 vhost_cleanup();
678} 670}
679module_exit(vhost_net_exit); 671module_exit(vhost_net_exit);
680 672