Skip to contentSkip to conversation

vmdk: align end of file to a sector boundary

PATCH In review [email protected] 2 participants 5 messages Sep 13, 2018 – Oct 8, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 vmdk: align end of file to a sector boundary

From: yuchenlin <[email protected]>

There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary.

There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os.

---
v2 -> v3:
* Update commit message

thanks

 block/vmdk.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
block/vmdk.c +21 -0
index a9d0084e36..2c9e86d98f 100644
@@ -1698,6 +1698,27 @@ static int coroutine_fn
 vmdk_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
                            uint64_t bytes, QEMUIOVector *qiov)
 {
+    if (bytes == 0) {
+        /* The caller will write bytes 0 to signal EOF.
+         * When receive it, we align EOF to a sector boundary. */
+        BDRVVmdkState *s = bs->opaque;
+        int i, ret;
+        int64_t length;
+
+        for (i = 0; i < s->num_extents; i++) {
+            length = bdrv_getlength(s->extents[i].file->bs);
+            if (length < 0) {
+                return length;
+            }
+            length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
+            ret = bdrv_truncate(s->extents[i].file, length,
+                                PREALLOC_MODE_OFF, NULL);
+            if (ret < 0) {
+                return ret;
+            }
+        }
+        return 0;
+    }
     return vmdk_co_pwritev(bs, offset, bytes, qiov, 0);
 }
 
Signature · 1 line
2.18.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 14 lines · On Thu, 09/13 16:29, [email protected] wrote:

From: yuchenlin <[email protected]>

There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary.

There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os.

Quoted 1 line
author
#2 lore raw

Ping?

Quoted 18 lines · Fam Zheng
Quoted 14 lines · On Thu, 09/13 16:29, [email protected] wrote:

From: yuchenlin <[email protected]>

There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary.

There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os.

Quoted 1 line
#3 lore raw
Quoted 1 line · yuchenlin

Ping?

Hi,

This was merged as 51b3c6b73acae1e3fd3c7d441fc86dd17356695f.

Fam

Quoted 21 lines · Fam Zheng
Quoted 18 lines · On Thu, 09/13 16:29, [email protected] wrote:
Quoted 14 lines

From: yuchenlin <[email protected]>

There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary.

There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os.

Quoted 1 line
author
#4 lore raw
Quoted 9 lines · Fam Zheng
Quoted 1 line · yuchenlin

Ping?

Hi,

This was merged as 51b3c6b73acae1e3fd3c7d441fc86dd17356695f.

Fam

Hi,

Thank you for your information.

yuchenlin

Quoted 21 lines
Quoted 21 lines · Fam Zheng
Quoted 18 lines · On Thu, 09/13 16:29, [email protected] wrote:
Quoted 14 lines

From: yuchenlin <[email protected]>

There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary.

There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os.

Quoted 1 line