xen/16945-blktap-strip.patch

50 lines
1.6 KiB
Diff

Index: xen-3.2-testing/tools/ioemu/xenstore.c
===================================================================
--- xen-3.2-testing.orig/tools/ioemu/xenstore.c
+++ xen-3.2-testing/tools/ioemu/xenstore.c
@@ -418,7 +418,7 @@ void xenstore_record_dm_state(char *stat
void xenstore_process_event(void *opaque)
{
- char **vec, *image = NULL;
+ char **vec, *offset, *bpath = NULL, *buf = NULL, *drv = NULL, *image = NULL;
unsigned int len, num, hd_index;
vec = xs_read_watch(xsh, &num);
@@ -440,8 +440,23 @@ void xenstore_process_event(void *opaque
goto out;
hd_index = vec[XS_WATCH_TOKEN][2] - 'a';
image = xs_read(xsh, XBT_NULL, vec[XS_WATCH_PATH], &len);
- if (image == NULL || !strcmp(image, bs_table[hd_index]->filename))
- goto out; /* gone or identical */
+ if (image == NULL)
+ goto out; /* gone */
+
+ /* Strip off blktap sub-type prefix */
+ bpath = strdup(vec[XS_WATCH_PATH]);
+ if (bpath == NULL)
+ goto out;
+ if ((offset = strrchr(bpath, '/')) != NULL)
+ *offset = '\0';
+ if (pasprintf(&buf, "%s/type", bpath) == -1)
+ goto out;
+ drv = xs_read(xsh, XBT_NULL, buf, &len);
+ if (drv && !strcmp(drv, "tap") && ((offset = strchr(image, ':')) != NULL))
+ memmove(image, offset+1, strlen(offset+1)+1);
+
+ if (!strcmp(image, bs_table[hd_index]->filename))
+ goto out; /* identical */
do_eject(0, vec[XS_WATCH_TOKEN]);
bs_table[hd_index]->filename[0] = 0;
@@ -456,6 +471,9 @@ void xenstore_process_event(void *opaque
}
out:
+ free(drv);
+ free(buf);
+ free(bpath);
free(image);
free(vec);
}