WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 4/5] minios: console based save/restore

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 4/5] minios: console based save/restore
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 19 Jan 2011 13:53:30 +0000
Delivery-date: Wed, 19 Jan 2011 05:56:20 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
Use the second PV console to send the qemu-xen save file and the third
PV console to receive the qemu-xen save file on restore.

Fix the console shutdown function free_consfront that is called when the
qemu save file is closed.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

diff -r 34e519b679cf extras/mini-os/console/xencons_ring.c
--- a/extras/mini-os/console/xencons_ring.c     Wed Jan 19 12:47:24 2011 +0000
+++ b/extras/mini-os/console/xencons_ring.c     Wed Jan 19 12:48:05 2011 +0000
@@ -184,16 +184,43 @@ struct consfront_dev *xencons_ring_init(
 
 void free_consfront(struct consfront_dev *dev)
 {
+    char* err = NULL;
+    XenbusState state;
+
+    char path[strlen(dev->backend) + 1 + 5 + 1];
+    char nodename[strlen(dev->nodename) + 1 + 5 + 1];
+
+    snprintf(path, sizeof(path), "%s/state", dev->backend);
+    snprintf(nodename, sizeof(nodename), "%s/state", dev->nodename);
+
+    if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosing)) != 
NULL) {
+        printk("free_consfront: error changing state to %d: %s\n",
+                XenbusStateClosing, err);
+        goto close;
+    }
+    state = xenbus_read_integer(path);
+    while (err == NULL && state < XenbusStateClosing)
+        err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
+
+    if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
+        printk("free_consfront: error changing state to %d: %s\n",
+                XenbusStateClosed, err);
+        goto close;
+    }
+
+close:
+    if (err) free(err);
+    xenbus_unwatch_path_token(XBT_NIL, path, path);
+
     mask_evtchn(dev->evtchn);
-
+    unbind_evtchn(dev->evtchn);
     free(dev->backend);
+    free(dev->nodename);
 
     gnttab_end_access(dev->ring_ref);
+
     free_page(dev->ring);
-
-    unbind_evtchn(dev->evtchn);
-
-    free(dev->nodename);
     free(dev);
 }
 
@@ -206,7 +233,7 @@ struct consfront_dev *init_consfront(cha
     char* msg = NULL;
     char nodename[256];
     char path[256];
-    static int consfrontends = 1;
+    static int consfrontends = 3;
     struct consfront_dev *dev;
     int res;
 
diff -r 34e519b679cf extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h      Wed Jan 19 12:47:24 2011 +0000
+++ b/extras/mini-os/include/lib.h      Wed Jan 19 12:48:05 2011 +0000
@@ -146,6 +146,7 @@ enum fd_type {
     FTYPE_KBD,
     FTYPE_FB,
     FTYPE_MEM,
+    FTYPE_SAVEFILE,
 };
 
 #define MAX_EVTCHN_PORTS 16
diff -r 34e519b679cf extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Wed Jan 19 12:47:24 2011 +0000
+++ b/extras/mini-os/lib/sys.c  Wed Jan 19 12:48:05 2011 +0000
@@ -154,6 +154,9 @@ char *getcwd(char *buf, size_t size)
 }
 
 #define LOG_PATH "/var/log/"
+#define SAVE_PATH "/var/lib/xen"
+#define SAVE_CONSOLE 1
+#define RESTORE_CONSOLE 2
 
 int mkdir(const char *pathname, mode_t mode)
 {
@@ -175,6 +178,21 @@ int posix_openpt(int flags)
     return(dev->fd);
 }
 
+int open_savefile(char *path, int save)
+{
+    struct consfront_dev *dev;
+    char *nodename[64];
+
+    snprintf(nodename, sizeof(nodename), "device/console/%d", save ? 
SAVE_CONSOLE : RESTORE_CONSOLE);
+
+    dev = init_consfront(nodename);
+    dev->fd = alloc_fd(FTYPE_SAVEFILE);
+    files[dev->fd].cons.dev = dev;
+
+    printk("fd(%d) = open_savefile\n", dev->fd);
+    return(dev->fd);
+}
+
 int open(const char *pathname, int flags, ...)
 {
     int fd;
@@ -191,6 +209,8 @@ int open(const char *pathname, int flags
     }
     if (!strncmp(pathname, "/dev/ptmx", strlen("/dev/ptmx")))
         return posix_openpt(flags);
+    if (!strncmp(pathname,SAVE_PATH,strlen(SAVE_PATH)))
+        return open_savefile(pathname, flags & O_WRONLY);
     errno = EIO;
     return -1;
 }
@@ -203,6 +223,7 @@ int read(int fd, void *buf, size_t nbyte
 int read(int fd, void *buf, size_t nbytes)
 {
     switch (files[fd].type) {
+        case FTYPE_SAVEFILE:
        case FTYPE_CONSOLE: {
            int ret;
             DEFINE_WAIT(w);
@@ -260,6 +281,15 @@ int write(int fd, const void *buf, size_
 int write(int fd, const void *buf, size_t nbytes)
 {
     switch (files[fd].type) {
+        case FTYPE_SAVEFILE: {
+                int ret = 0, tot = nbytes;
+                while (nbytes > 0) {
+                    ret = xencons_ring_send(files[fd].cons.dev, (char *)buf, 
nbytes);
+                    nbytes -= ret;
+                    buf += ret;
+                }
+                return tot - nbytes;
+            }
        case FTYPE_CONSOLE:
            console_print(files[fd].cons.dev, (char *)buf, nbytes);
            return nbytes;
@@ -331,6 +361,7 @@ int close(int fd)
             shutdown_fbfront(files[fd].fb.dev);
             files[fd].type = FTYPE_NONE;
             return 0;
+        case FTYPE_SAVEFILE:
         case FTYPE_CONSOLE:
             fini_console(files[fd].cons.dev);
             files[fd].type = FTYPE_NONE;
@@ -364,9 +395,15 @@ int fstat(int fd, struct stat *buf)
 {
     init_stat(buf);
     switch (files[fd].type) {
+       case FTYPE_SAVEFILE:
        case FTYPE_CONSOLE:
        case FTYPE_SOCKET: {
-           buf->st_mode = (files[fd].type == FTYPE_CONSOLE?S_IFCHR:S_IFSOCK) | 
S_IRUSR|S_IWUSR;
+            if (files[fd].type == FTYPE_CONSOLE)
+                buf->st_mode = S_IFCHR|S_IRUSR|S_IWUSR;
+            else if (files[fd].type == FTYPE_SOCKET)
+                buf->st_mode = S_IFSOCK|S_IRUSR|S_IWUSR;
+            else if (files[fd].type == FTYPE_SAVEFILE)
+                buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR;
            buf->st_uid = 0;
            buf->st_gid = 0;
            buf->st_size = 0;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>