thebeanogamer / rpms / qemu-kvm

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