From 6a9b843ee2431eb07c2cf108c3f48150f9d1e24f Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Thu, 22 Dec 2011 16:58:35 +0530 Subject: [PATCH] --- yaml --- r: 284255 b: refs/heads/master c: e562966dbaf49e7804097cd991e5d3a8934fc148 h: refs/heads/master i: 284253: e887086c8a37adfbab61ef3a93ad2e528ac561bd 284251: e3accd1cc47e61520fd66127a99a9c95a78f2521 284247: 935b357507729f57ee482dfaad5d6fcb6286ee09 284239: b8de77cd2a205cb64bfb835f2789bee06af43db6 284223: 6a08649ccedcfcb6bbd2c2958d76e1ebdf7eef04 v: v3 --- [refs] | 2 +- trunk/drivers/virtio/virtio_balloon.c | 47 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 8cf4925cdc34..1deb5afd3c6d 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: be91c33dd15eff6b0dffc60cee4c8042e75493d2 +refs/heads/master: e562966dbaf49e7804097cd991e5d3a8934fc148 diff --git a/trunk/drivers/virtio/virtio_balloon.c b/trunk/drivers/virtio/virtio_balloon.c index 3368cb6ef193..95aeedf198f8 100644 --- a/trunk/drivers/virtio/virtio_balloon.c +++ b/trunk/drivers/virtio/virtio_balloon.c @@ -364,6 +364,48 @@ static void __devexit virtballoon_remove(struct virtio_device *vdev) kfree(vb); } +#ifdef CONFIG_PM +static int virtballoon_freeze(struct virtio_device *vdev) +{ + /* + * The kthread is already frozen by the PM core before this + * function is called. + */ + + /* Ensure we don't get any more requests from the host */ + vdev->config->reset(vdev); + vdev->config->del_vqs(vdev); + return 0; +} + +static int virtballoon_thaw(struct virtio_device *vdev) +{ + return init_vqs(vdev->priv); +} + +static int virtballoon_restore(struct virtio_device *vdev) +{ + struct virtio_balloon *vb = vdev->priv; + struct page *page, *page2; + + /* We're starting from a clean slate */ + vb->num_pages = 0; + + /* + * If a request wasn't complete at the time of freezing, this + * could have been set. + */ + vb->need_stats_update = 0; + + /* We don't have these pages in the balloon anymore! */ + list_for_each_entry_safe(page, page2, &vb->pages, lru) { + list_del(&page->lru); + totalram_pages++; + } + return init_vqs(vdev->priv); +} +#endif + static unsigned int features[] = { VIRTIO_BALLOON_F_MUST_TELL_HOST, VIRTIO_BALLOON_F_STATS_VQ, @@ -378,6 +420,11 @@ static struct virtio_driver virtio_balloon_driver = { .probe = virtballoon_probe, .remove = __devexit_p(virtballoon_remove), .config_changed = virtballoon_changed, +#ifdef CONFIG_PM + .freeze = virtballoon_freeze, + .restore = virtballoon_restore, + .thaw = virtballoon_thaw, +#endif }; static int __init init(void)