aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/lib
diff options
context:
space:
mode:
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>2011-01-21 18:06:23 +0000
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>2011-01-21 18:06:23 +0000
commit648429dc4066e47d190484921845871000be217d (patch)
tree24d5fa8792ffe67913d11aaa59be1a53740ffbc6 /extras/mini-os/lib
parente6859a733df7c723b211e447c6f3f3fccace6f8d (diff)
downloadxen-648429dc4066e47d190484921845871000be217d.tar.gz
xen-648429dc4066e47d190484921845871000be217d.tar.bz2
xen-648429dc4066e47d190484921845871000be217d.zip
libxl, minios: stubdom console based save/restore
Add two "special" PV consoles to stubdoms that are going to be used to send and receive the qemu-xen save files on save/restore. 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. Stubdom save/restore is still broken with xend. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'extras/mini-os/lib')
-rw-r--r--extras/mini-os/lib/sys.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c
index 51a801f0ca..7a49886e2d 100644
--- a/extras/mini-os/lib/sys.c
+++ b/extras/mini-os/lib/sys.c
@@ -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 isatty(int fd)
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 read(int fd, void *buf, size_t nbytes)
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;