qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/3] block: Introduce BlockDriver.requires_growing_file
Date: Thu, 19 Mar 2015 15:03:21 -0400	[thread overview]
Message-ID: <1426791801-9042-4-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1426791801-9042-1-git-send-email-mreitz@redhat.com>

This flag is set if write accesses to BDSs managed by the respective
driver may lead to writes beyond the end of the underlying file BDS,
expecting it to increase its size accordingly.

This behavior, however, is only supported by protocol BDSs having the
BDS.growing flag set. If they do not, emit a warning.

An example of such a misconfiguration is exporting a qcow2 file using
the reference NBD server implementation, which cannot interpret the
qcow2 format and will thus expose it directly over the network. When
accessing that export with qemu, qemu's qcow2 driver may try to allocate
clusters over the NBD connection, writing to addresses beyond the size
of the NBD export, which will then fail (without the user knowing why,
without this warning).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c                   | 16 ++++++++++++++++
 block/qcow.c              |  1 +
 block/qcow2.c             |  2 ++
 block/qed.c               |  1 +
 block/vdi.c               |  2 ++
 block/vhdx.c              |  2 ++
 block/vmdk.c              |  1 +
 block/vpc.c               |  2 ++
 include/block/block_int.h |  4 ++++
 9 files changed, 31 insertions(+)

diff --git a/block.c b/block.c
index 6da30f8..2db27b5 100644
--- a/block.c
+++ b/block.c
@@ -1585,6 +1585,22 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         goto fail;
     }
 
+    /* requires_growing_file may only be true for format block drivers */
+    assert(!bs->drv->requires_growing_file || bs->file);
+    if (bs->drv->requires_growing_file && !bs->file->growing &&
+        (flags & BDRV_O_RDWR))
+    {
+        error_report("WARNING: Writes to the image '%s' in format '%s'\n"
+                     "         may require the file to grow which is not "
+                     "supported for protocol '%s'.\n"
+                     "         Please open it read-only or try to export "
+                     "it in a different format\n"
+                     "         over the protocol (e.g. use qemu-nbd "
+                     "instead of nbd-server).",
+                     filename ?: "", drv->format_name,
+                     bs->file->drv->format_name);
+    }
+
     if (file && (bs->file != file)) {
         bdrv_unref(file);
         file = NULL;
diff --git a/block/qcow.c b/block/qcow.c
index 0558969..5719285 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -962,6 +962,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_create            = qcow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
     .supports_backing       = true,
+    .requires_growing_file  = true,
 
     .bdrv_co_readv          = qcow_co_readv,
     .bdrv_co_writev         = qcow_co_writev,
diff --git a/block/qcow2.c b/block/qcow2.c
index b4e2aa3..ad1028b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2944,6 +2944,8 @@ BlockDriver bdrv_qcow2 = {
     .supports_backing           = true,
     .bdrv_change_backing_file   = qcow2_change_backing_file,
 
+    .requires_growing_file      = true,
+
     .bdrv_refresh_limits        = qcow2_refresh_limits,
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
 
diff --git a/block/qed.c b/block/qed.c
index 892b13c..1cd1233 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1662,6 +1662,7 @@ static BlockDriver bdrv_qed = {
     .instance_size            = sizeof(BDRVQEDState),
     .create_opts              = &qed_create_opts,
     .supports_backing         = true,
+    .requires_growing_file    = true,
 
     .bdrv_probe               = bdrv_qed_probe,
     .bdrv_rebind              = bdrv_qed_rebind,
diff --git a/block/vdi.c b/block/vdi.c
index 53bd02f..13ffd91 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -903,6 +903,8 @@ static BlockDriver bdrv_vdi = {
 
     .create_opts = &vdi_create_opts,
     .bdrv_check = vdi_check,
+
+    .requires_growing_file = true,
 };
 
 static void bdrv_vdi_init(void)
diff --git a/block/vhdx.c b/block/vhdx.c
index bb3ed45..bc1aaca 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1970,6 +1970,8 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .create_opts            = &vhdx_create_opts,
+
+    .requires_growing_file  = true,
 };
 
 static void bdrv_vhdx_init(void)
diff --git a/block/vmdk.c b/block/vmdk.c
index 8410a15..31ae764 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2293,6 +2293,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_attach_aio_context      = vmdk_attach_aio_context,
 
     .supports_backing             = true,
+    .requires_growing_file        = true,
     .create_opts                  = &vmdk_create_opts,
 };
 
diff --git a/block/vpc.c b/block/vpc.c
index 43e768e..4c26273 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -924,6 +924,8 @@ static BlockDriver bdrv_vpc = {
 
     .create_opts            = &vpc_create_opts,
     .bdrv_has_zero_init     = vpc_has_zero_init,
+
+    .requires_growing_file  = true,
 };
 
 static void bdrv_vpc_init(void)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 01dee2a..be44c80 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -109,6 +109,10 @@ struct BlockDriver {
     /* Set if a driver can support backing files */
     bool supports_backing;
 
+    /* Set if the underlying BDS.file needs to support writes beyond its size to
+     * be grown implicitly in order for this driver's BDSs to be writable */
+    bool requires_growing_file;
+
     /* For handling image reopen for split or non-split files */
     int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
                                BlockReopenQueue *queue, Error **errp);
-- 
2.1.0

  parent reply	other threads:[~2015-03-19 19:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19 19:03 [Qemu-devel] [PATCH v2 0/3] block: Warn about usage of growing formats over non-growable protocols Max Reitz
2015-03-19 19:03 ` [Qemu-devel] [PATCH v2 1/3] iotests: Make nested read in 072 and 089 read-only Max Reitz
2015-03-19 19:23   ` Eric Blake
2015-03-19 19:03 ` [Qemu-devel] [PATCH v2 2/3] block: Introduce BDS.growing Max Reitz
2015-03-19 20:11   ` Eric Blake
2015-03-19 19:03 ` Max Reitz [this message]
2015-03-19 20:18   ` [Qemu-devel] [PATCH v2 3/3] block: Introduce BlockDriver.requires_growing_file Eric Blake
2015-05-05  9:46 ` [Qemu-devel] [PATCH v2 0/3] block: Warn about usage of growing formats over non-growable protocols Stefan Hajnoczi
2015-05-06 13:04   ` Max Reitz
2015-05-06 15:30     ` Paolo Bonzini
2015-05-06 16:12       ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-05-06 16:20         ` Paolo Bonzini
2015-05-06 16:37           ` Max Reitz
2015-05-06 16:47             ` Paolo Bonzini
2015-05-06 17:23               ` Max Reitz
2015-05-07 12:20                 ` Paolo Bonzini
2015-05-07 12:29                   ` Kevin Wolf
2015-05-07 12:47                     ` Paolo Bonzini
2015-05-07 13:20                       ` Kevin Wolf
2015-05-07 13:55                         ` Paolo Bonzini
2015-05-07 14:07                           ` Kevin Wolf
2015-05-07 14:16                             ` Paolo Bonzini
2015-05-07 14:34                               ` Kevin Wolf
2015-05-07 14:50                                 ` Paolo Bonzini
2015-05-08 10:08                                   ` Kevin Wolf
2015-05-08 10:16                                     ` Paolo Bonzini
2015-05-08 10:34                                       ` Kevin Wolf
2015-05-08 11:00                                         ` Paolo Bonzini
2015-05-08 12:58                                     ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426791801-9042-4-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).