qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH for-2.3 1/6] vmdk: Use g_random_int to generate CID
Date: Tue,  2 Dec 2014 15:39:12 +0800	[thread overview]
Message-ID: <1417505957-2666-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1417505957-2666-1-git-send-email-famz@redhat.com>

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 <armbru@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 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.9.3

  reply	other threads:[~2014-12-02  7:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02  7:39 [Qemu-devel] [PATCH for-2.3 0/6] vmdk: A few small fixes Fam Zheng
2014-12-02  7:39 ` Fam Zheng [this message]
2014-12-02  7:39 ` [Qemu-devel] [PATCH for-2.3 2/6] vmdk: Fix comment to match code of extent lines Fam Zheng
2014-12-02  7:39 ` [Qemu-devel] [PATCH for-2.3 3/6] vmdk: Clean up descriptor file reading Fam Zheng
2014-12-02 17:10   ` Don Koch
2014-12-03  1:38     ` Fam Zheng
2014-12-02  7:39 ` [Qemu-devel] [PATCH for-2.3 4/6] vmdk: Check descriptor file length when reading it Fam Zheng
2014-12-02  7:39 ` [Qemu-devel] [PATCH for-2.3 5/6] vmdk: Remove unnecessary initialization Fam Zheng
2014-12-02  7:39 ` [Qemu-devel] [PATCH for-2.3 6/6] vmdk: Set errp on failures in vmdk_open_vmdk4 Fam Zheng
2014-12-02  8:28 ` [Qemu-devel] [PATCH for-2.3 0/6] vmdk: A few small fixes Markus Armbruster
2014-12-02 10:36   ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417505957-2666-2-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).