Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147963
b: refs/heads/master
c: d2a7ddd
h: refs/heads/master
i:
  147961: c5e29c4
  147959: 1c95ab7
v: v3
  • Loading branch information
Michael S. Tsirkin authored and Rusty Russell committed Jun 12, 2009
1 parent 094ec31 commit 3b19884
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 90 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9499f5e7ed5224c40706f0cec6542a9916bc7606
refs/heads/master: d2a7ddda9ffb1c8961abff6714b0f1eb925c120f
6 changes: 3 additions & 3 deletions trunk/drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int virtblk_probe(struct virtio_device *vdev)
sg_init_table(vblk->sg, vblk->sg_elems);

/* We expect one virtqueue, for output. */
vblk->vq = vdev->config->find_vq(vdev, 0, blk_done, "requests");
vblk->vq = virtio_find_single_vq(vdev, blk_done, "requests");
if (IS_ERR(vblk->vq)) {
err = PTR_ERR(vblk->vq);
goto out_free_vblk;
Expand Down Expand Up @@ -388,7 +388,7 @@ static int virtblk_probe(struct virtio_device *vdev)
out_mempool:
mempool_destroy(vblk->pool);
out_free_vq:
vdev->config->del_vq(vblk->vq);
vdev->config->del_vqs(vdev);
out_free_vblk:
kfree(vblk);
out:
Expand All @@ -409,7 +409,7 @@ static void virtblk_remove(struct virtio_device *vdev)
blk_cleanup_queue(vblk->disk->queue);
put_disk(vblk->disk);
mempool_destroy(vblk->pool);
vdev->config->del_vq(vblk->vq);
vdev->config->del_vqs(vdev);
kfree(vblk);
}

Expand Down
6 changes: 3 additions & 3 deletions trunk/drivers/char/hw_random/virtio-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ static int virtrng_probe(struct virtio_device *vdev)
int err;

/* We expect a single virtqueue. */
vq = vdev->config->find_vq(vdev, 0, random_recv_done, "input");
vq = virtio_find_single_vq(vdev, random_recv_done, "input");
if (IS_ERR(vq))
return PTR_ERR(vq);

err = hwrng_register(&virtio_hwrng);
if (err) {
vdev->config->del_vq(vq);
vdev->config->del_vqs(vdev);
return err;
}

Expand All @@ -112,7 +112,7 @@ static void virtrng_remove(struct virtio_device *vdev)
{
vdev->config->reset(vdev);
hwrng_unregister(&virtio_hwrng);
vdev->config->del_vq(vq);
vdev->config->del_vqs(vdev);
}

static struct virtio_device_id id_table[] = {
Expand Down
26 changes: 11 additions & 15 deletions trunk/drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ static void hvc_handle_input(struct virtqueue *vq)
* Finally we put our input buffer in the input queue, ready to receive. */
static int __devinit virtcons_probe(struct virtio_device *dev)
{
vq_callback_t *callbacks[] = { hvc_handle_input, NULL};
const char *names[] = { "input", "output" };
struct virtqueue *vqs[2];
int err;

vdev = dev;
Expand All @@ -199,20 +202,15 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
goto fail;
}

/* Find the input queue. */
/* Find the queues. */
/* FIXME: This is why we want to wean off hvc: we do nothing
* when input comes in. */
in_vq = vdev->config->find_vq(vdev, 0, hvc_handle_input, "input");
if (IS_ERR(in_vq)) {
err = PTR_ERR(in_vq);
err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names);
if (err)
goto free;
}

out_vq = vdev->config->find_vq(vdev, 1, NULL, "output");
if (IS_ERR(out_vq)) {
err = PTR_ERR(out_vq);
goto free_in_vq;
}
in_vq = vqs[0];
out_vq = vqs[1];

/* Start using the new console output. */
virtio_cons.get_chars = get_chars;
Expand All @@ -233,17 +231,15 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE);
if (IS_ERR(hvc)) {
err = PTR_ERR(hvc);
goto free_out_vq;
goto free_vqs;
}

/* Register the input buffer the first time. */
add_inbuf();
return 0;

free_out_vq:
vdev->config->del_vq(out_vq);
free_in_vq:
vdev->config->del_vq(in_vq);
free_vqs:
vdev->config->del_vqs(vdev);
free:
kfree(inbuf);
fail:
Expand Down
36 changes: 34 additions & 2 deletions trunk/drivers/lguest/lguest_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,38 @@ static void lg_del_vq(struct virtqueue *vq)
kfree(lvq);
}

static void lg_del_vqs(struct virtio_device *vdev)
{
struct virtqueue *vq, *n;

list_for_each_entry_safe(vq, n, &vdev->vqs, list)
lg_del_vq(vq);
}

static int lg_find_vqs(struct virtio_device *vdev, unsigned nvqs,
struct virtqueue *vqs[],
vq_callback_t *callbacks[],
const char *names[])
{
struct lguest_device *ldev = to_lgdev(vdev);
int i;

/* We must have this many virtqueues. */
if (nvqs > ldev->desc->num_vq)
return -ENOENT;

for (i = 0; i < nvqs; ++i) {
vqs[i] = lg_find_vq(vdev, i, callbacks[i], names[i]);
if (IS_ERR(vqs[i]))
goto error;
}
return 0;

error:
lg_del_vqs(vdev);
return PTR_ERR(vqs[i]);
}

/* The ops structure which hooks everything together. */
static struct virtio_config_ops lguest_config_ops = {
.get_features = lg_get_features,
Expand All @@ -322,8 +354,8 @@ static struct virtio_config_ops lguest_config_ops = {
.get_status = lg_get_status,
.set_status = lg_set_status,
.reset = lg_reset,
.find_vq = lg_find_vq,
.del_vq = lg_del_vq,
.find_vqs = lg_find_vqs,
.del_vqs = lg_del_vqs,
};

/* The root device for the lguest virtio devices. This makes them appear as
Expand Down
45 changes: 18 additions & 27 deletions trunk/drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ static int virtnet_probe(struct virtio_device *vdev)
int err;
struct net_device *dev;
struct virtnet_info *vi;
struct virtqueue *vqs[3];
vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL};
const char *names[] = { "input", "output", "control" };
int nvqs;

/* Allocate ourselves a network device with room for our info */
dev = alloc_etherdev(sizeof(struct virtnet_info));
Expand Down Expand Up @@ -905,25 +909,19 @@ static int virtnet_probe(struct virtio_device *vdev)
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
vi->mergeable_rx_bufs = true;

/* We expect two virtqueues, receive then send. */
vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done, "input");
if (IS_ERR(vi->rvq)) {
err = PTR_ERR(vi->rvq);
/* We expect two virtqueues, receive then send,
* and optionally control. */
nvqs = virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ? 3 : 2;

err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names);
if (err)
goto free;
}

vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done, "output");
if (IS_ERR(vi->svq)) {
err = PTR_ERR(vi->svq);
goto free_recv;
}
vi->rvq = vqs[0];
vi->svq = vqs[1];

if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
vi->cvq = vdev->config->find_vq(vdev, 2, NULL, "control");
if (IS_ERR(vi->cvq)) {
err = PTR_ERR(vi->svq);
goto free_send;
}
vi->cvq = vqs[2];

if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
dev->features |= NETIF_F_HW_VLAN_FILTER;
Expand All @@ -941,7 +939,7 @@ static int virtnet_probe(struct virtio_device *vdev)
err = register_netdev(dev);
if (err) {
pr_debug("virtio_net: registering device failed\n");
goto free_ctrl;
goto free_vqs;
}

/* Last of all, set up some receive buffers. */
Expand All @@ -962,13 +960,8 @@ static int virtnet_probe(struct virtio_device *vdev)

unregister:
unregister_netdev(dev);
free_ctrl:
if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
vdev->config->del_vq(vi->cvq);
free_send:
vdev->config->del_vq(vi->svq);
free_recv:
vdev->config->del_vq(vi->rvq);
free_vqs:
vdev->config->del_vqs(vdev);
free:
free_netdev(dev);
return err;
Expand All @@ -994,12 +987,10 @@ static void virtnet_remove(struct virtio_device *vdev)

BUG_ON(vi->num != 0);

vdev->config->del_vq(vi->svq);
vdev->config->del_vq(vi->rvq);
if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
vdev->config->del_vq(vi->cvq);
unregister_netdev(vi->dev);

vdev->config->del_vqs(vi->vdev);

while (vi->pages)
__free_pages(get_a_page(vi, GFP_KERNEL), 0);

Expand Down
36 changes: 34 additions & 2 deletions trunk/drivers/s390/kvm/kvm_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,38 @@ static void kvm_del_vq(struct virtqueue *vq)
KVM_S390_VIRTIO_RING_ALIGN));
}

static void kvm_del_vqs(struct virtio_device *vdev)
{
struct virtqueue *vq, *n;

list_for_each_entry_safe(vq, n, &vdev->vqs, list)
kvm_del_vq(vq);
}

static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
struct virtqueue *vqs[],
vq_callback_t *callbacks[],
const char *names[])
{
struct kvm_device *kdev = to_kvmdev(vdev);
int i;

/* We must have this many virtqueues. */
if (nvqs > kdev->desc->num_vq)
return -ENOENT;

for (i = 0; i < nvqs; ++i) {
vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i]);
if (IS_ERR(vqs[i]))
goto error;
}
return 0;

error:
kvm_del_vqs(vdev);
return PTR_ERR(vqs[i]);
}

/*
* The config ops structure as defined by virtio config
*/
Expand All @@ -238,8 +270,8 @@ static struct virtio_config_ops kvm_vq_configspace_ops = {
.get_status = kvm_get_status,
.set_status = kvm_set_status,
.reset = kvm_reset,
.find_vq = kvm_find_vq,
.del_vq = kvm_del_vq,
.find_vqs = kvm_find_vqs,
.del_vqs = kvm_del_vqs,
};

/*
Expand Down
27 changes: 11 additions & 16 deletions trunk/drivers/virtio/virtio_balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ static int balloon(void *_vballoon)
static int virtballoon_probe(struct virtio_device *vdev)
{
struct virtio_balloon *vb;
struct virtqueue *vqs[2];
vq_callback_t *callbacks[] = { balloon_ack, balloon_ack };
const char *names[] = { "inflate", "deflate" };
int err;

vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
Expand All @@ -218,33 +221,26 @@ static int virtballoon_probe(struct virtio_device *vdev)
vb->vdev = vdev;

/* We expect two virtqueues. */
vb->inflate_vq = vdev->config->find_vq(vdev, 0, balloon_ack, "inflate");
if (IS_ERR(vb->inflate_vq)) {
err = PTR_ERR(vb->inflate_vq);
err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names);
if (err)
goto out_free_vb;
}

vb->deflate_vq = vdev->config->find_vq(vdev, 1, balloon_ack, "deflate");
if (IS_ERR(vb->deflate_vq)) {
err = PTR_ERR(vb->deflate_vq);
goto out_del_inflate_vq;
}
vb->inflate_vq = vqs[0];
vb->deflate_vq = vqs[1];

vb->thread = kthread_run(balloon, vb, "vballoon");
if (IS_ERR(vb->thread)) {
err = PTR_ERR(vb->thread);
goto out_del_deflate_vq;
goto out_del_vqs;
}

vb->tell_host_first
= virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);

return 0;

out_del_deflate_vq:
vdev->config->del_vq(vb->deflate_vq);
out_del_inflate_vq:
vdev->config->del_vq(vb->inflate_vq);
out_del_vqs:
vdev->config->del_vqs(vdev);
out_free_vb:
kfree(vb);
out:
Expand All @@ -264,8 +260,7 @@ static void virtballoon_remove(struct virtio_device *vdev)
/* Now we reset the device so we can clean up the queues. */
vdev->config->reset(vdev);

vdev->config->del_vq(vb->deflate_vq);
vdev->config->del_vq(vb->inflate_vq);
vdev->config->del_vqs(vdev);
kfree(vb);
}

Expand Down
Loading

0 comments on commit 3b19884

Please sign in to comment.