All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Amit Shah <amit.shah@redhat.com>
Cc: Virtualization List <virtualization@lists.linux-foundation.org>
Subject: Re: [RFC PATCH 8/8] virtio: net: Add freeze, restore handlers to support S4
Date: Fri, 29 Jul 2011 07:13:35 +0300	[thread overview]
Message-ID: <20110729041335.GD31888@redhat.com> (raw)
In-Reply-To: <3d2fd91237cfb3ff1e05e464e305df2711b45885.1311863438.git.amit.shah@redhat.com>

On Thu, Jul 28, 2011 at 08:05:13PM +0530, Amit Shah wrote:
> Remove all the vqs on hibernation and re-create them after restoring
> from a hibernated image.  This keeps networking working across
> hibernation.
> 
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  drivers/net/virtio_net.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 51 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 0c7321c..c9aaa8f 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1117,6 +1117,53 @@ static void __devexit virtnet_remove(struct virtio_device *vdev)
>  	free_netdev(vi->dev);
>  }
>  
> +#ifdef CONFIG_PM
> +static int virtnet_freeze(struct virtio_device *vdev)
> +{
> +	struct virtnet_info *vi = vdev->priv;
> +
> +	cancel_delayed_work_sync(&vi->refill);
> +
> +	/* Free unused buffers in both send and recv, if any. */
> +	free_unused_bufs(vi);
> +
> +	vdev->config->del_vqs(vi->vdev);
> +
> +	while (vi->pages)
> +		__free_pages(get_a_page(vi, GFP_KERNEL), 0);
> +
> +	return 0;
> +}
> +
> +static int virtnet_restore(struct virtio_device *vdev)
> +{
> +	struct virtnet_info *vi = vdev->priv;
> +	struct virtqueue *vqs[3];
> +	vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL};
> +	const char *names[] = { "input", "output", "control" };
> +	int nvqs, err;
> +
> +	/* 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)
> +		return err;
> +
> +	vi->rvq = vqs[0];
> +	vi->svq = vqs[1];
> +
> +	if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
> +		vi->cvq = vqs[2];
> +	}
> +
> +	/* Last of all, set up some receive buffers. */
> +	try_fill_recv(vi, GFP_KERNEL);

should probably update carrier status too.

> +	return 0;
> +}
> +#endif
> +
>  static struct virtio_device_id id_table[] = {
>  	{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
>  	{ 0 },
> @@ -1141,6 +1188,10 @@ static struct virtio_driver virtio_net_driver = {
>  	.probe =	virtnet_probe,
>  	.remove =	__devexit_p(virtnet_remove),
>  	.config_changed = virtnet_config_changed,
> +#ifdef CONFIG_PM
> +	.freeze = 	virtnet_freeze,
> +	.restore =	virtnet_restore,
> +#endif
>  };
>  
>  static int __init init(void)
> -- 
> 1.7.6

  reply	other threads:[~2011-07-29  4:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28 14:35 [RFC PATCH 0/8] virtio: Support for hibernation (S4) Amit Shah
2011-07-28 14:35 ` [RFC PATCH 1/8] virtio: pci: switch to new PM API Amit Shah
2011-07-28 14:35 ` [RFC PATCH 2/8] virtio-pci: add PM notification handlers for restore, freeze, thaw, poweroff Amit Shah
2011-07-28 14:35 ` [RFC PATCH 3/8] virtio-pci: save/restore config space across S4 Amit Shah
2011-07-29  4:07   ` Michael S. Tsirkin
2011-07-29  4:20     ` Amit Shah
2011-07-28 14:35 ` [RFC PATCH 4/8] virtio: console: Ignore port name update request if name already set Amit Shah
2011-07-29  4:19   ` Michael S. Tsirkin
2011-07-29  4:26     ` Amit Shah
2011-07-29  4:27       ` Michael S. Tsirkin
2011-07-28 14:35 ` [RFC PATCH 5/8] virtio: console: Use wait_event_freezable instead of _interruptible Amit Shah
2011-07-28 14:35 ` [RFC PATCH 6/8] virtio: console: Add freeze and restore handlers to support S4 Amit Shah
2011-07-28 14:35 ` [RFC PATCH 7/8] virtio: block: Add freeze, " Amit Shah
2011-07-28 14:35 ` [RFC PATCH 8/8] virtio: net: " Amit Shah
2011-07-29  4:13   ` Michael S. Tsirkin [this message]
2011-07-29  4:28     ` Amit Shah
2011-07-29  4:31       ` Michael S. Tsirkin
2011-07-29  5:08         ` Amit Shah
2011-08-10 10:53 ` [RFC PATCH 0/8] virtio: Support for hibernation (S4) Amit Shah

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=20110729041335.GD31888@redhat.com \
    --to=mst@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.