xen/snapshot-ioemu-restore.patch

125 lines
4.0 KiB
Diff

Index: xen-3.3.1-testing/tools/blktap/drivers/blktapctrl.c
===================================================================
--- xen-3.3.1-testing.orig/tools/blktap/drivers/blktapctrl.c
+++ xen-3.3.1-testing/tools/blktap/drivers/blktapctrl.c
@@ -305,6 +305,7 @@ static int write_msg(int fd, int msgtype
msg_dev = (msg_newdev_t *)(buf + sizeof(msg_hdr_t));
msg_dev->devnum = blkif->minor;
msg_dev->domid = blkif->domid;
+ msg_dev->be_id = blkif->be_id;
break;
Index: xen-3.3.1-testing/tools/blktap/lib/blktaplib.h
===================================================================
--- xen-3.3.1-testing.orig/tools/blktap/lib/blktaplib.h
+++ xen-3.3.1-testing/tools/blktap/lib/blktaplib.h
@@ -189,6 +189,7 @@ typedef struct msg_hdr {
typedef struct msg_newdev {
uint8_t devnum;
uint16_t domid;
+ uint32_t be_id;
} msg_newdev_t;
typedef struct msg_pid {
Index: xen-3.3.1-testing/tools/ioemu-remote/hw/xen_blktap.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/hw/xen_blktap.c
+++ xen-3.3.1-testing/tools/ioemu-remote/hw/xen_blktap.c
@@ -69,6 +69,8 @@ int write_fd;
static pid_t process;
fd_list_entry_t *fd_start = NULL;
+extern char* get_snapshot_name(int devid);
+
static void handle_blktap_iomsg(void* private);
struct aiocb_info {
@@ -502,6 +504,10 @@ static void handle_blktap_ctrlmsg(void*
char buf[MSG_SIZE];
+#ifndef QEMU_TOOL
+ char *snapshot;
+#endif
+
length = read(read_fd, buf, MSG_SIZE);
if (length > 0 && length >= sizeof(msg_hdr_t))
@@ -557,7 +563,18 @@ static void handle_blktap_ctrlmsg(void*
if (s != NULL) {
ret = ((map_new_dev(s, msg_dev->devnum)
== msg_dev->devnum ? 0: -1));
- }
+ }
+
+#ifndef QEMU_TOOL
+ fprintf(stderr, "Reading snapshot name for %d\n", msg_dev->be_id);
+ snapshot = get_snapshot_name(msg_dev->be_id);
+ if (snapshot) {
+ // TODO Error handling
+ fprintf(stderr, "Using snapshot %s\n", snapshot);
+ if (bdrv_snapshot_goto(s->bs, snapshot) < 0)
+ fprintf(stderr, "Could not load snapshot");
+ }
+#endif
memset(buf, 0x00, MSG_SIZE);
msglen = sizeof(msg_hdr_t);
Index: xen-3.3.1-testing/tools/ioemu-remote/xenstore.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/xenstore.c
+++ xen-3.3.1-testing/tools/ioemu-remote/xenstore.c
@@ -37,6 +37,8 @@ static QEMUTimer *insert_timer = NULL;
#define UWAIT_MAX (30*1000000) /* thirty seconds */
#define UWAIT (100000) /* 1/10th second */
+char* get_snapshot_name(int devid);
+
static int pasprintf(char **buf, const char *fmt, ...)
{
va_list ap;
@@ -373,8 +375,17 @@ void xenstore_parse_domain_config(int hv
}
}
pstrcpy(bs->filename, sizeof(bs->filename), params);
- if (bdrv_open2(bs, params, 0 /* snapshot */, format) < 0)
+ if (bdrv_open2(bs, params, 0 /* snapshot */, format) < 0) {
fprintf(stderr, "qemu: could not open vbd '%s' or hard disk image '%s' (drv '%s' format '%s')\n", buf, params, drv ? drv : "?", format ? format->format_name : "0");
+ } else {
+ char* snapshot = get_snapshot_name(atoi(e[i]));
+ if (snapshot) {
+ // TODO Error handling
+ fprintf(stderr, "Using snapshot %s\n", snapshot);
+ if (bdrv_snapshot_goto(bs, snapshot) < 0)
+ fprintf(stderr, "Could not load snapshot");
+ }
+ }
}
drives_table[nb_drives].bdrv = bs;
@@ -471,6 +482,23 @@ void xenstore_parse_domain_config(int hv
return;
}
+
+char* get_snapshot_name(int devid)
+{
+ char* path = NULL;
+ char* name = NULL;
+ unsigned int len;
+
+ if (pasprintf(&path,
+ "/local/domain/0/backend/tap/%u/%u/snapshot", domid, devid) == -1)
+ return NULL;
+ name = xs_read(xsh, XBT_NULL, path, &len);
+
+ free(path);
+ return name;
+}
+
+
int xenstore_fd(void)
{
if (xsh)