qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] block: Introduce requires_growing_file
Date: Sat, 12 Jul 2014 00:23:05 +0200	[thread overview]
Message-ID: <1405117387-25539-3-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1405117387-25539-1-git-send-email-mreitz@redhat.com>

There are several block drivers which may require the underlying file to
grow on write accesses because new clusters need to be allocated. If
such a format should be used non-read-only over a protocol which does
not allow file growth, emit an appropriate warning.

This is relevant e.g. for qcow2 over NBD, if the user tried to export
the raw image instead of using the qcow2 block driver on the host (e.g.
when using nbd-server).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c                   | 11 +++++++++++
 block/cow.c               |  1 +
 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 ++++
 10 files changed, 27 insertions(+)

diff --git a/block.c b/block.c
index cb95e08..ba0115d 100644
--- a/block.c
+++ b/block.c
@@ -1474,6 +1474,17 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         goto fail;
     }
 
+    if (drv->requires_growing_file && file && !file->growable &&
+        (flags & BDRV_O_RDWR))
+    {
+        error_report("Writes to the image '%s' in format '%s' may require the "
+                     "file to grow which is not supported for this file; "
+                     "please open it read-only or try to export it in a "
+                     "different format over the protocol (e.g. use qemu-nbd "
+                     "instead of nbd-server)",
+                     filename ?: "", drv->format_name);
+    }
+
     if (file && (bs->file != file)) {
         bdrv_unref(file);
         file = NULL;
diff --git a/block/cow.c b/block/cow.c
index 6ee4833..b944074 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -416,6 +416,7 @@ static BlockDriver bdrv_cow = {
     .bdrv_create    = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
     .supports_backing       = true,
+    .requires_growing_file  = true,
 
     .bdrv_read              = cow_co_read,
     .bdrv_write             = cow_co_write,
diff --git a/block/qcow.c b/block/qcow.c
index a874056..2dba733 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -942,6 +942,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 5b52f97..2d2b851 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2429,6 +2429,8 @@ static 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 cd4872b..06170b7 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1675,6 +1675,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 197bd77..4b9ae21 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -873,6 +873,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 fedcf9f..2ceb5a4 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1927,6 +1927,8 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_check             = vhdx_check,
 
     .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 f674127..78054cf 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2180,6 +2180,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 8b376a4..8fc434e 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -934,6 +934,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 b420b37..adfd89c 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -104,6 +104,10 @@ struct BlockDriver {
     /* Set if a driver can support backing files */
     bool supports_backing;
 
+    /* Set if a driver may need its underlying files to be able to grow for
+     * write accesses */
+    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.0.1

  parent reply	other threads:[~2014-07-11 22:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-11 22:23 [Qemu-devel] [PATCH 0/4] block: Warn about usage of growing formats over non-growable protocols Max Reitz
2014-07-11 22:23 ` [Qemu-devel] [PATCH 1/4] block: Correct bs->growable Max Reitz
2014-08-20 11:40   ` Kevin Wolf
2014-08-20 19:13     ` Max Reitz
2014-08-21  8:19       ` Kevin Wolf
2014-08-22 13:26         ` Max Reitz
2014-09-04 20:01     ` Max Reitz
2014-09-05 10:01       ` Kevin Wolf
2014-09-05 12:46         ` Max Reitz
2014-09-05 13:13           ` Kevin Wolf
2014-07-11 22:23 ` Max Reitz [this message]
2014-07-11 22:23 ` [Qemu-devel] [PATCH 3/4] iotests: Make some qemu-io commands read-only Max Reitz
2014-07-11 22:23 ` [Qemu-devel] [PATCH 4/4] iotests: Skip read and write in 040 for length=0 Max Reitz
2014-08-15 15:23 ` [Qemu-devel] [PATCH 0/4] block: Warn about usage of growing formats over non-growable protocols 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=1405117387-25539-3-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --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).