Patchwork [6/8] blockdev: Allow image files to auto-enable streaming

login
register
mail settings
Submitter Stefan Hajnoczi
Date April 27, 2011, 1:27 p.m.
Message ID <1303910855-28999-7-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/93046/
State New
Headers show

Comments

Stefan Hajnoczi - April 27, 2011, 1:27 p.m.
Image files that having streaming enabled will automatically begin
streaming when opened.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c     |    5 +++++
 block.h     |    1 +
 block_int.h |    1 +
 blockdev.c  |    9 +++++++++
 4 files changed, 16 insertions(+), 0 deletions(-)
Kevin Wolf - April 29, 2011, 12:20 p.m.
Am 27.04.2011 15:27, schrieb Stefan Hajnoczi:
> Image files that having streaming enabled will automatically begin
> streaming when opened.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Hm... I wasn't really happy about images that do copy on read even if I
didn't tell qemu so on the command line. Now they can start to copy data
and use up my internet connection even without the guest really
accessing the data. This seems to be one step more that I find rather
questionable.

Anyway, same as for copy on read: While we can discuss _allowing_ it in
backing files, it's definitely not suitable as a primary interface.

Kevin

Patch

diff --git a/block.c b/block.c
index 5e3476c..68a97a3 100644
--- a/block.c
+++ b/block.c
@@ -1584,6 +1584,11 @@  const char *bdrv_get_device_name(BlockDriverState *bs)
     return bs->device_name;
 }
 
+int bdrv_stream_enabled(BlockDriverState *bs)
+{
+    return bs->stream;
+}
+
 int bdrv_flush(BlockDriverState *bs)
 {
     if (bs->open_flags & BDRV_O_NO_FLUSH) {
diff --git a/block.h b/block.h
index fad828a..3357c50 100644
--- a/block.h
+++ b/block.h
@@ -189,6 +189,7 @@  int bdrv_is_removable(BlockDriverState *bs);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_sg(BlockDriverState *bs);
 int bdrv_enable_write_cache(BlockDriverState *bs);
+int bdrv_stream_enabled(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
diff --git a/block_int.h b/block_int.h
index 0c125d0..d0fe96c 100644
--- a/block_int.h
+++ b/block_int.h
@@ -155,6 +155,7 @@  struct BlockDriverState {
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
+    int stream;    /* if true, stream from the backing file */
     /* event callback when inserting/removing */
     void (*change_cb)(void *opaque, int reason);
     void *change_opaque;
diff --git a/blockdev.c b/blockdev.c
index 99c0726..5d6cb2b 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -678,6 +678,15 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
         goto err;
     }
 
+    if (bdrv_stream_enabled(dinfo->bdrv)) {
+        const char *device_name = bdrv_get_device_name(dinfo->bdrv);
+
+        if (!stream_start(device_name, 0, false, NULL, NULL)) {
+            fprintf(stderr, "qemu: warning: stream_start failed for '%s'\n",
+                    device_name);
+        }
+    }
+
     if (bdrv_key_required(dinfo->bdrv))
         autostart = 0;
     return dinfo;