qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/4] block: Introduce requires_growing_file


From: Max Reitz
Subject: [Qemu-devel] [PATCH 2/4] block: Introduce requires_growing_file
Date: Sat, 12 Jul 2014 00:23:05 +0200

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]