From: Amit Shah <amit.shah@redhat.com>
To: Virtualization List <virtualization@lists.linux-foundation.org>
Cc: Amit Shah <amit.shah@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
Subject: [RFC PATCH 6/8] virtio: console: Add freeze and restore handlers to support S4
Date: Thu, 28 Jul 2011 20:05:11 +0530 [thread overview]
Message-ID: <e07039ebeb115501adaaa86081423eb5851cb7a0.1311863438.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1311863438.git.amit.shah@redhat.com>
In-Reply-To: <cover.1311863438.git.amit.shah@redhat.com>
Remove all vqs and associated buffers in the freeze callback which
prepares us to go into hibernation state. On restore, re-create all the
vqs and populate the input vqs with buffers to get to the pre-hibernate
state.
Note: Any outstanding unconsumed buffers are discarded; which means
there's a possibility of data loss in case the host or the guest didn't
consume any data already present in the vqs. This can be addressed in a
later patch series, perhaps in virtio common code.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
drivers/char/virtio_console.c | 71 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index a7dfd02..9648cea 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -25,6 +25,7 @@
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/list.h>
+#include <linux/pm.h>
#include <linux/poll.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -1801,6 +1802,72 @@ static unsigned int features[] = {
VIRTIO_CONSOLE_F_MULTIPORT,
};
+#ifdef CONFIG_PM
+static int virtcons_freeze(struct virtio_device *vdev)
+{
+ struct ports_device *portdev;
+ struct port *port;
+ struct port_buffer *buf;
+ unsigned int len;
+
+ portdev = vdev->priv;
+
+ if (use_multiport(portdev)) {
+ while ((buf = virtqueue_get_buf(portdev->c_ivq, &len)))
+ free_buf(buf);
+
+ while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq)))
+ free_buf(buf);
+ }
+ list_for_each_entry(port, &portdev->ports, list) {
+ /*
+ * We'll ask the host later if the new invocation has
+ * the port opened or closed.
+ */
+ port->host_connected = false;
+ discard_port_data(port);
+ reclaim_consumed_buffers(port);
+
+ while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
+ free_buf(buf);
+ }
+ portdev->vdev->config->del_vqs(portdev->vdev);
+ kfree(portdev->in_vqs);
+ kfree(portdev->out_vqs);
+
+ return 0;
+}
+
+static int virtcons_restore(struct virtio_device *vdev)
+{
+ struct ports_device *portdev;
+ struct port *port;
+ int ret;
+
+ portdev = vdev->priv;
+
+ ret = init_vqs(portdev);
+ if (ret)
+ return ret;
+
+ if (use_multiport(portdev)) {
+ fill_queue(portdev->c_ivq, &portdev->cvq_lock);
+ }
+
+ list_for_each_entry(port, &portdev->ports, list) {
+ port->in_vq = portdev->in_vqs[port->id];
+ port->out_vq = portdev->out_vqs[port->id];
+
+ fill_queue(port->in_vq, &port->inbuf_lock);
+
+ /* XXX: Should this be done in 'complete' instead of 'restore'? */
+ /* Get port open/close status on the host */
+ send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
+ }
+ return 0;
+}
+#endif
+
static struct virtio_driver virtio_console = {
.feature_table = features,
.feature_table_size = ARRAY_SIZE(features),
@@ -1810,6 +1877,10 @@ static struct virtio_driver virtio_console = {
.probe = virtcons_probe,
.remove = virtcons_remove,
.config_changed = config_intr,
+#ifdef CONFIG_PM
+ .freeze = virtcons_freeze,
+ .restore = virtcons_restore,
+#endif
};
static int __init init(void)
--
1.7.6
next prev parent reply other threads:[~2011-07-28 14:35 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 ` Amit Shah [this message]
2011-07-28 14:35 ` [RFC PATCH 7/8] virtio: block: Add freeze, restore handlers to support S4 Amit Shah
2011-07-28 14:35 ` [RFC PATCH 8/8] virtio: net: " Amit Shah
2011-07-29 4:13 ` Michael S. Tsirkin
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=e07039ebeb115501adaaa86081423eb5851cb7a0.1311863438.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=mst@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).