                                                                                                                                                                                                                                                               
Delivered-To: blauwirbel@gmail.com
Received: by 10.143.166.2 with SMTP id t2cs69767wfo;
        Thu, 28 Aug 2008 10:17:11 -0700 (PDT)
Received: by 10.114.161.11 with SMTP id j11mr1715606wae.2.1219943831029;
        Thu, 28 Aug 2008 10:17:11 -0700 (PDT)
Return-Path: <qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [199.232.76.165])
        by mx.google.com with ESMTP id 5si1429640ywd.8.2008.08.28.10.17.10;
        Thu, 28 Aug 2008 10:17:10 -0700 (PDT)
Received-SPF: pass (google.com: domain of qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org designates 199.232.76.165 as permitted sender) client-ip=199.232.76.165;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org designates 199.232.76.165 as permitted sender) smtp.mail=qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org
Received: from localhost ([127.0.0.1]:36354 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43)
	id 1KYkow-0001Ws-Fu
	for blauwirbel@gmail.com; Thu, 28 Aug 2008 12:58:06 -0400
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1KYkjk-0008QP-QQ
	for qemu-devel@nongnu.org; Thu, 28 Aug 2008 12:52:44 -0400
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1KYkjk-0008PM-26
	for qemu-devel@nongnu.org; Thu, 28 Aug 2008 12:52:44 -0400
Received: from [199.232.76.173] (port=36283 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1KYkjj-0008P2-TT
	for qemu-devel@nongnu.org; Thu, 28 Aug 2008 12:52:43 -0400
Received: from il.qumranet.com ([212.179.150.194]:48326)
	by monty-python.gnu.org with esmtp (Exim 4.60)
	(envelope-from <gleb@qumranet.com>) id 1KYkjj-0004kR-Jn
	for qemu-devel@nongnu.org; Thu, 28 Aug 2008 12:52:44 -0400
Received: from gleb-debian.qumranet.com (gleb-debian.qumranet.com.qumranet.com
	[172.16.15.143])
	by il.qumranet.com (Postfix) with ESMTP id 7B592250DB2
	for <qemu-devel@nongnu.org>; Thu, 28 Aug 2008 19:52:42 +0300 (IDT)
Received: from gleb-debian.qumranet.com.qumranet.com (localhost [127.0.0.1])
	by gleb-debian.qumranet.com (Postfix) with ESMTP id 79D1B18D48F
	for <qemu-devel@nongnu.org>; Thu, 28 Aug 2008 19:52:42 +0300 (IDT)
From: Gleb Natapov <gleb@qumranet.com>
To: qemu-devel@nongnu.org
Date: Thu, 28 Aug 2008 19:52:42 +0300
Message-ID: <20080828165242.22851.90099.stgit@gleb-debian.qumranet.com.qumranet.com>
In-Reply-To: <20080828165232.22851.77678.stgit@gleb-debian.qumranet.com.qumranet.com>
References: <20080828165232.22851.77678.stgit@gleb-debian.qumranet.com.qumranet.com>
User-Agent: StGIT/0.14.2
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 1)
Subject: [Qemu-devel] [PATCH v3 2/6] Add -uuid command line option.
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.5
Precedence: list
Reply-To: qemu-devel@nongnu.org
List-Id: qemu-devel.nongnu.org
List-Unsubscribe: <http://lists.nongnu.org/mailman/listinfo/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <http://lists.nongnu.org/mailman/listinfo/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Sender: qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org
Errors-To: qemu-devel-bounces+blauwirbel=gmail.com@nongnu.org

Let user specify UUID of the virtual machine.

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 sysemu.h |    2 ++
 vl.c     |   29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

Index: qemu/sysemu.h
===================================================================
--- qemu.orig/sysemu.h	2008-08-31 12:34:25.000000000 +0000
+++ qemu/sysemu.h	2008-08-31 12:35:30.000000000 +0000
@@ -8,6 +8,8 @@
 
 extern int vm_running;
 extern const char *qemu_name;
+extern uint8_t qemu_uuid[];
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
 typedef struct vm_change_state_entry VMChangeStateEntry;
 typedef void VMChangeStateHandler(void *opaque, int running);
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2008-08-31 12:34:25.000000000 +0000
+++ qemu/vl.c	2008-08-31 12:35:30.000000000 +0000
@@ -257,6 +257,8 @@
 QEMUTimer *icount_rt_timer;
 QEMUTimer *icount_vm_timer;
 
+uint8_t qemu_uuid[16];
+
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /***********************************************************/
@@ -7710,6 +7712,7 @@
            "-g WxH[xDEPTH]  Set the initial graphical resolution and depth\n"
 #endif
            "-name string    set the name of the guest\n"
+           "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
            "\n"
            "Network options:\n"
            "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
@@ -7904,6 +7907,7 @@
     QEMU_OPTION_startdate,
     QEMU_OPTION_tb_size,
     QEMU_OPTION_icount,
+    QEMU_OPTION_uuid,
 };
 
 typedef struct QEMUOption {
@@ -7992,6 +7996,7 @@
 #ifdef CONFIG_CURSES
     { "curses", 0, QEMU_OPTION_curses },
 #endif
+    { "uuid", HAS_ARG, QEMU_OPTION_uuid },
 
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
@@ -8202,6 +8207,23 @@
 }
 #endif
 
+static int qemu_uuid_parse(const char *str, uint8_t *uuid)
+{
+    int ret;
+
+    if(strlen(str) != 36)
+        return -1;
+
+    ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
+            &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
+            &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], &uuid[15]);
+
+    if(ret != 16)
+        return -1;
+
+    return 0;
+}
+
 #define MAX_NET_CLIENTS 32
 
 #ifndef _WIN32
@@ -8780,6 +8802,13 @@
             case QEMU_OPTION_show_cursor:
                 cursor_hide = 0;
                 break;
+            case QEMU_OPTION_uuid:
+                if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
+                    fprintf(stderr, "Fail to parse UUID string."
+                            " Wrong format.\n");
+                    exit(1);
+                }
+                break;
 	    case QEMU_OPTION_daemonize:
 		daemonize = 1;
 		break;
