block/stream: Don't stream unbacked devices
authorMax Reitz <mreitz@redhat.com>
Wed, 13 Nov 2013 19:37:58 +0000 (20:37 +0100)
committerKevin Wolf <kwolf@redhat.com>
Thu, 28 Nov 2013 10:39:31 +0000 (11:39 +0100)
If a block device is unbacked, a streaming blockjob should immediately
finish instead of beginning to try to stream, then noticing the backing
file does not contain even the first sector (since it does not exist)
and then finishing normally.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/stream.c

index 694fd42e41a855489fe7460c694df521bbbd773d..46bec7d37965fabe3b825944e9b3d43eceaf4775 100644 (file)
@@ -88,6 +88,11 @@ static void coroutine_fn stream_run(void *opaque)
     int n = 0;
     void *buf;
 
+    if (!bs->backing_hd) {
+        block_job_completed(&s->common, 0);
+        return;
+    }
+
     s->common.len = bdrv_getlength(bs);
     if (s->common.len < 0) {
         block_job_completed(&s->common, s->common.len);