[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 68/73] vmdk: Use g_random_int to generate CID
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 68/73] vmdk: Use g_random_int to generate CID |
Date: |
Wed, 10 Dec 2014 11:34:34 +0100 |
From: Fam Zheng <address@hidden>
This replaces two "time(NULL)" invocations with "g_random_int()".
According to VMDK spec, CID "is a random 32‐bit value updated the first
time the content of the virtual disk is modified after the virtual disk
is opened". Using "seconds since epoch" is just a "lame way" to generate
it, and not completely safe because of the low precision.
Suggested-by: Markus Armbruster <address@hidden>
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Don Koch <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 2cbfd3e..ebb4b70 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -28,6 +28,7 @@
#include "qemu/module.h"
#include "migration/migration.h"
#include <zlib.h>
+#include <glib.h>
#define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
#define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
@@ -1538,7 +1539,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t
sector_num,
/* update CID on the first write every time the virtual disk is
* opened */
if (!s->cid_updated) {
- ret = vmdk_write_cid(bs, time(NULL));
+ ret = vmdk_write_cid(bs, g_random_int());
if (ret < 0) {
return ret;
}
@@ -1922,7 +1923,7 @@ static int vmdk_create(const char *filename, QemuOpts
*opts, Error **errp)
}
/* generate descriptor file */
desc = g_strdup_printf(desc_template,
- (uint32_t)time(NULL),
+ g_random_int(),
parent_cid,
fmt,
parent_desc_line,
--
1.8.3.1
- [Qemu-devel] [PULL 56/73] qemu-img: Check create_opts before image creation, (continued)
- [Qemu-devel] [PULL 56/73] qemu-img: Check create_opts before image creation, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 57/73] qemu-img: Check create_opts before image amendment, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 55/73] block: Check create_opts before image creation, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 58/73] iotests: Only kill NBD server if it runs, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 60/73] qcow2: Prevent numerical overflow, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 62/73] qcow2: Respect bdrv_truncate() error, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 61/73] qcow2: Flushing the caches in qcow2_close may fail, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 65/73] block: remove BLOCK_OPT_NOCOW from vdi_create_opts, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 63/73] block/raw-posix: Fix ret in raw_open_common(), Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 66/73] block: remove BLOCK_OPT_NOCOW from vpc_create_opts, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 68/73] vmdk: Use g_random_int to generate CID,
Kevin Wolf <=
- [Qemu-devel] [PULL 69/73] vmdk: Fix comment to match code of extent lines, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when reading it, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 70/73] vmdk: Clean up descriptor file reading, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 67/73] block: Use g_new0() for a bit of extra type checking, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 73/73] vmdk: Set errp on failures in vmdk_open_vmdk4, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 72/73] vmdk: Remove unnecessary initialization, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 64/73] qemu-iotests: Skip 099 for VMDK subformats with desc file, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 43/73] qcow2.py: Add required padding for header extensions, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 05/73] qjson: Drop trailing space for pretty formatting, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 59/73] iotests: Add test for unsupported image creation, Kevin Wolf, 2014/12/10