qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Harper <ryanh@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: kvm-devel@lists.sourceforge.net
Subject: [Qemu-devel] [PATCH 3 of 3] Add -uuid command line flag
Date: Tue, 11 Dec 2007 14:08:53 -0600	[thread overview]
Message-ID: <f1372e77455459b3e21a.1197403733@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1197403730@localhost.localdomain>

3 files changed, 61 insertions(+), 6 deletions(-)
smbios.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
sysemu.h |    1 +
vl.c     |    8 ++++++++


# HG changeset patch
# User Ryan Harper <ryanh@us.ibm.com>
# Date 1197402122 21600
# Node ID f1372e77455459b3e21ae908bb56cd43356159fd
# Parent  115f40a4994be1d5b44ef193b3ccbe8e26410eef
Add -uuid command line flag

This patch allows users to specify a uuid.  If no uuid is specified, then one is
generated.

Now supports -uuid both with and without libuuid
Moved some includes into hw/hw.h and sysemh.h
Reduced the number of CONFIG_UUID defines

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>

diff -r 115f40a4994b -r f1372e774554 smbios.c
--- a/smbios.c	Tue Dec 11 13:42:02 2007 -0600
+++ b/smbios.c	Tue Dec 11 13:42:02 2007 -0600
@@ -32,11 +32,47 @@
 
 #ifdef CONFIG_UUID
 #include <uuid/uuid.h>
-#endif
+
+static int qemu_uuid_parse(const char *in, uint8_t *uu)
+{
+    if (uuid_parse(in, *((uuid_t *)uu)) < 0)
+        return -1;
+
+    return 0;
+}
+
+#define qemu_uuid_generate(x) (uuid_generate(*((uuid_t *)x)))
+
+#else
+#define UUID2 "%02x%02x"
+#define UUID4 "%02x%02x%02x%02x"
+#define UUID6 "%02x%02x%02x%02x%02x%02x"
+#define UUID_FMT UUID4"-"UUID2"-"UUID2"-"UUID2"-"UUID6
+
+static int qemu_uuid_parse(const char *in, uint8_t *uu)
+{
+    unsigned int u[16];
+    int rv, i;
+
+    /* NB: sscanf requires %x format to store values in unsigned int */
+    rv = sscanf(in, UUID_FMT, u, u+1, u+2, u+3, u+4, u+5, u+6, u+7, u+8,
+                u+9, u+10, u+11, u+12, u+13, u+14, u+15);
+
+    if (rv != 16)
+        return -1;
+
+    for (i=0; i<16; i++)
+        uu[i] = (uint8_t)u[i];
+
+    return 0;
+}
+#define qemu_uuid_generate(x) (memcpy(x, "QEMUQEMUQEMUQEMU", 16))
+
+#endif /* CONFIG_UUID */
 
 /* Write a two-character hex representation of 'byte' to digits[].
    Pre-condition: sizeof(digits) >= 2 */
-void
+static void
 byte_to_hex(char *digits, uint8_t byte)
 {
     uint8_t nybbel = byte >> 4;
@@ -493,12 +529,22 @@ load_smbios_tables(uint8_t *entry, uint8
     uint32_t major_version = 0;
     uint32_t minor_version = 9;
 #ifdef CONFIG_UUID
-    uuid_t uuid;
-
-    uuid_generate(uuid);
+    uuid_t u;
+    uint8_t *uuid = (char *)&u;
 #else
-    uint8_t uuid[16] = "QEMUQEMUQEMUQEMU";
+    uint8_t uuid[16];
 #endif
+
+    /* parse user-specified uuid if present */
+    if (qemu_uuid != NULL) {
+        if (qemu_uuid_parse(qemu_uuid, uuid) < 0) {
+            fprintf(stderr, "SMBIOS: Could not parse user UUID"
+                            " string, check format.\n");
+            return -1;
+        }
+    } else {
+        qemu_uuid_generate(uuid);
+    }
 
     len = write_smbios_tables(entry, table, phys_table_start,
                               smp_cpus, (ram_size >> 20),
diff -r 115f40a4994b -r f1372e774554 sysemu.h
--- a/sysemu.h	Tue Dec 11 13:42:02 2007 -0600
+++ b/sysemu.h	Tue Dec 11 13:42:02 2007 -0600
@@ -90,6 +90,7 @@ extern int autostart;
 extern int autostart;
 extern int old_param;
 extern const char *bootp_filename;
+extern const char *qemu_uuid;
 
 
 #ifdef USE_KQEMU
diff -r 115f40a4994b -r f1372e774554 vl.c
--- a/vl.c	Tue Dec 11 13:42:02 2007 -0600
+++ b/vl.c	Tue Dec 11 13:42:02 2007 -0600
@@ -138,6 +138,7 @@ int inet_aton(const char *cp, struct in_
 #else
 #define SMBD_COMMAND "/usr/sbin/smbd"
 #endif
+const char *qemu_uuid;
 
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
@@ -7545,6 +7546,8 @@ static void help(int exitcode)
            "-no-reboot      exit instead of rebooting\n"
            "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
 	   "-vnc display    start a VNC server on display\n"
+           "-uuid %%08x-%%04x-%%04x-%%04x-%%012x\n"
+           "                specify machine UUID\n"
 #ifndef _WIN32
 	   "-daemonize      daemonize QEMU after initializing\n"
 #endif
@@ -7647,6 +7650,7 @@ enum {
     QEMU_OPTION_vnc,
     QEMU_OPTION_no_acpi,
     QEMU_OPTION_no_reboot,
+    QEMU_OPTION_uuid,
     QEMU_OPTION_show_cursor,
     QEMU_OPTION_daemonize,
     QEMU_OPTION_option_rom,
@@ -7742,6 +7746,7 @@ const QEMUOption qemu_options[] = {
     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
     { "smp", HAS_ARG, QEMU_OPTION_smp },
     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
+    { "uuid", HAS_ARG, QEMU_OPTION_uuid },
 
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
@@ -8527,6 +8532,9 @@ int main(int argc, char **argv)
 	    case QEMU_OPTION_daemonize:
 		daemonize = 1;
 		break;
+            case QEMU_OPTION_uuid:
+                qemu_uuid = optarg;
+                break;
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
 		    fprintf(stderr, "Too many option ROMs\n");

  parent reply	other threads:[~2007-12-11 20:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-11 20:08 [Qemu-devel] [PATCH 0 of 3] Add SMBIOS/DMI table generation to PC machine Ryan Harper
2007-12-11 20:08 ` [Qemu-devel] [PATCH 1 of 3] export SMBIOS/DMI tables to PC machines Ryan Harper
2007-12-11 20:08 ` [Qemu-devel] [PATCH 2 of 3] Optionally link against libuuid if present Ryan Harper
2007-12-11 21:19   ` Filip Navara
2007-12-12 22:51     ` Fabrice Bellard
2008-01-03 19:55     ` Ryan Harper
2008-01-20 13:17       ` Filip Navara
2008-01-20 14:25         ` Paul Brook
2008-01-20 15:26           ` Filip Navara
2008-01-20 16:20         ` [kvm-devel] " Alexander Graf
2008-01-20 16:37           ` Filip Navara
2008-01-20 16:53             ` Alexander Graf
2008-01-20 17:01               ` Filip Navara
2007-12-11 21:21   ` Filip Navara
2007-12-11 20:08 ` Ryan Harper [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-12-07 20:45 [Qemu-devel] [PATCH 0 of 3] Add SMBIOS/DMI table generation to PC machine Ryan Harper
2007-12-07 20:45 ` [Qemu-devel] [PATCH 3 of 3] Add -uuid command line flag Ryan Harper

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=f1372e77455459b3e21a.1197403733@localhost.localdomain \
    --to=ryanh@us.ibm.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=qemu-devel@nongnu.org \
    /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).