File ioemu-blktap-zero-size.patch of Package xen

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
@@ -67,6 +67,7 @@ int read_fd;
 int write_fd;
 
 static pid_t process;
+int connected_disks = 0;
 fd_list_entry_t *fd_start = NULL;
 
 extern char* get_snapshot_name(int devid);
@@ -260,6 +261,12 @@ static int open_disk(struct td_state *s,
 	s->size = bs->total_sectors;
 	s->sector_size = 512;
 
+	if (s->size == 0) {
+		fprintf(stderr, "Error: Disk image %s is too small\n",
+			path);
+		return -ENOMEM;
+	}
+
 	s->info = ((s->flags & TD_RDONLY) ? VDISK_READONLY : 0);
 
 #ifndef QEMU_TOOL
@@ -563,6 +570,7 @@ static void handle_blktap_ctrlmsg(void* 
 
 			/* Allocate the disk structs */
 			s = state_init();
+			connected_disks++;
 
 			/*Open file*/
 			if (s == NULL || open_disk(s, path, msg->drivertype, msg->readonly)) {
@@ -645,7 +653,8 @@ static void handle_blktap_ctrlmsg(void* 
 		case CTLMSG_CLOSE:
 			s = get_state(msg->cookie);
 			if (s) unmap_disk(s);
-			break;			
+			connected_disks--;
+			break;
 
 		case CTLMSG_PID:
 			memset(buf, 0x00, MSG_SIZE);
Index: xen-3.3.1-testing/tools/ioemu-remote/tapdisk-ioemu.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/tapdisk-ioemu.c
+++ xen-3.3.1-testing/tools/ioemu-remote/tapdisk-ioemu.c
@@ -18,6 +18,7 @@ extern void *qemu_mallocz(size_t size);
 extern void qemu_free(void *ptr);
 
 extern void *fd_start;
+extern int connected_disks;
 
 int domid = 0;
 FILE* logfile;
@@ -98,7 +99,7 @@ int main(void) 
     int max_fd;
     fd_set rfds;
     struct timeval tv;
-    void *old_fd_start = NULL;
+    int old_connected_disks = 0;
 
     /* Daemonize */
     if (fork() != 0)
@@ -153,11 +154,17 @@ int main(void) 
                 pioh = &ioh->next;
         }
 
+	if (old_connected_disks != connected_disks)
+            fprintf(stderr, "connected disks: %d => %d\n",
+	        old_connected_disks, connected_disks);
+
         /* Exit when the last image has been closed */
-        if (old_fd_start != NULL && fd_start == NULL)
+        if (old_connected_disks != 0 && connected_disks == 0) {
+	    fprintf(stderr, "Last image is closed, exiting.\n");
             exit(0);
+	}
 
-        old_fd_start = fd_start;
+        old_connected_disks = connected_disks;
     }
     return 0;
 }
Index: xen-3.3.1-testing/tools/examples/blktap
===================================================================
--- xen-3.3.1-testing.orig/tools/examples/blktap
+++ xen-3.3.1-testing/tools/examples/blktap
@@ -75,6 +75,7 @@ fi
 if [ "$command" = 'add' ]
 then
     [ -e "$file" ] || { fatal $file does not exist; }
+    [ $(stat --format="%s" "$file") -ge 512 ] || { fatal $file is too small; }
 
     FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
     FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
Index: xen-3.3.1-testing/tools/python/xen/xend/server/DevController.py
===================================================================
--- xen-3.3.1-testing.orig/tools/python/xen/xend/server/DevController.py
+++ xen-3.3.1-testing/tools/python/xen/xend/server/DevController.py
@@ -182,7 +182,7 @@ class DevController:
                           (devid, self.deviceClass))
 
         elif status == Error:
-            self.destroyDevice(devid, False)
+            self.destroyDevice(devid, True)
             if err is None:
                 raise VmError("Device %s (%s) could not be connected. "
                               "Backend device not found." %
openSUSE Build Service is sponsored by