From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xvi3D-0006ba-83 for qemu-devel@nongnu.org; Tue, 02 Dec 2014 02:39:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xvi37-0003xG-2V for qemu-devel@nongnu.org; Tue, 02 Dec 2014 02:39:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xvi36-0003x0-Ql for qemu-devel@nongnu.org; Tue, 02 Dec 2014 02:39:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB27d4gW028137 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 2 Dec 2014 02:39:04 -0500 From: Fam Zheng Date: Tue, 2 Dec 2014 15:39:12 +0800 Message-Id: <1417505957-2666-2-git-send-email-famz@redhat.com> In-Reply-To: <1417505957-2666-1-git-send-email-famz@redhat.com> References: <1417505957-2666-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-2.3 1/6] vmdk: Use g_random_int to generate CID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Markus Armbruster , Stefan Hajnoczi This replaces two "time(NULL)" invocations with "g_random_int()". According to VMDK spec, CID "is a random 32=E2=80=90bit 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 Signed-off-by: Fam Zheng --- 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 +#include =20 #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 =3D vmdk_write_cid(bs, time(NULL)); + ret =3D vmdk_write_cid(bs, g_random_int()); if (ret < 0) { return ret; } @@ -1922,7 +1923,7 @@ static int vmdk_create(const char *filename, QemuOp= ts *opts, Error **errp) } /* generate descriptor file */ desc =3D g_strdup_printf(desc_template, - (uint32_t)time(NULL), + g_random_int(), parent_cid, fmt, parent_desc_line, --=20 1.9.3