9ae3a8
From bf9dd867ef8d4164685cac6451e88b6c32b190b1 Mon Sep 17 00:00:00 2001
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Mon, 15 Feb 2016 09:28:15 +0100
9ae3a8
Subject: [PATCH 02/18] vmdk: Use g_random_int to generate CID
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1455528511-9357-3-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 69168
9ae3a8
O-Subject: [RHEL-7.3 qemu-kvm PATCH 02/18] vmdk: Use g_random_int to generate CID
9ae3a8
Bugzilla: 1299250
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299250
9ae3a8
9ae3a8
This replaces two "time(NULL)" invocations with "g_random_int()".
9ae3a8
According to VMDK spec, CID "is a random 32‐bit value updated the first
9ae3a8
time the content of the virtual disk is modified after the virtual disk
9ae3a8
is opened". Using "seconds since epoch" is just a "lame way" to generate
9ae3a8
it, and not completely safe because of the low precision.
9ae3a8
9ae3a8
Suggested-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Reviewed-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Don Koch <dkoch@verizon.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: 1417649314-13704-2-git-send-email-famz@redhat.com
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit e5dc64b8ff09cc4c186273e4461c7479739db2ae)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vmdk.c | 5 +++--
9ae3a8
 1 file changed, 3 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index fa53d2f..a9f5bab 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -28,6 +28,7 @@
9ae3a8
 #include "qemu/module.h"
9ae3a8
 #include "migration/migration.h"
9ae3a8
 #include <zlib.h>
9ae3a8
+#include <glib.h>
9ae3a8
 
9ae3a8
 #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
9ae3a8
 #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
9ae3a8
@@ -1540,7 +1541,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
9ae3a8
         /* update CID on the first write every time the virtual disk is
9ae3a8
          * opened */
9ae3a8
         if (!s->cid_updated) {
9ae3a8
-            ret = vmdk_write_cid(bs, time(NULL));
9ae3a8
+            ret = vmdk_write_cid(bs, g_random_int());
9ae3a8
             if (ret < 0) {
9ae3a8
                 return ret;
9ae3a8
             }
9ae3a8
@@ -1927,7 +1928,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
     }
9ae3a8
     /* generate descriptor file */
9ae3a8
     desc = g_strdup_printf(desc_template,
9ae3a8
-                           (uint32_t)time(NULL),
9ae3a8
+                           g_random_int(),
9ae3a8
                            parent_cid,
9ae3a8
                            fmt,
9ae3a8
                            parent_desc_line,
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8