Skip to contentSkip to conversation

If user doesn't specify a uuid, generate a random one

PATCH In review Serge E. Hallyn 4 participants 7 messages Mar 26, 2012 – Mar 27, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 If user doesn't specify a uuid, generate a random one

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros? If not, can a patch like this one be applied?

---
 vl.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
vl.c +11 -0
index 112b0e0..2b53b62 100644
@@ -247,7 +247,9 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
 
+#include <uuid/uuid.h>
 uint8_t qemu_uuid[16];
+bool uuid_set = false;
 
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;
@@ -3030,6 +3032,7 @@ int main(int argc, char **argv, char **envp)
                             " Wrong format.\n");
                     exit(1);
                 }
+                uuid_set = true;
                 break;
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
@@ -3200,6 +3203,14 @@ int main(int argc, char **argv, char **envp)
         exit(0);
     }
 
+    if (!uuid_set) {
+        uuid_t uuid;
+        uuid_generate(uuid);
+        for (i = 0; i < 16; i++) {
+            qemu_uuid[i] = uuid[i];
+        }
+    }
+
     /* Open the logfile at this point, if necessary. We can't open the logfile
      * when encountering either of the logging options (-d or -D) because the
      * other one may be encountered later on the command line, changing the
Signature · 1 line
1.7.9.1
#1 lore raw

Am 26.03.2012 17:13, schrieb Serge E. Hallyn:

Quoted 4 lines

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros?

Yes, documented somewhere in the archives, we wanted to have reproducible defaults in QEMU (cf. MAC address, IP addresses) so that it doesn't change for each invocation or depending on host.

As a general rule, randomization should be done either explicitly (-uuid uuidgen or -generate-me-a-uuid) or via frontends such as libvirt.

If all zeros causes genuine problems then we should change the default, taking care of backwards compatibility as usual.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 9 lines · Andreas Färber

Am 26.03.2012 17:13, schrieb Serge E. Hallyn:

Quoted 4 lines

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros?

Yes, documented somewhere in the archives, we wanted to have reproducible defaults in QEMU (cf. MAC address, IP addresses) so that it doesn't change for each invocation or depending on host.

Thanks. Though I don't know of a case offhand, I guess I could imagine a case where a guest's userspace acts differently (and mis-behaves) based on the random uuid...

Quoted 5 lines

As a general rule, randomization should be done either explicitly (-uuid uuidgen or -generate-me-a-uuid) or via frontends such as libvirt.

If all zeros causes genuine problems then we should change the default, taking care of backwards compatibility as usual.

The bug this was in reply to is at http://pad.lv/959308 . IIUC the main problem is that our crash database uses the uuid, so users need to set one to report bugs. (There was also a suggestion that Microsoft requires it for Logo Certification.) My suggestion was also to have callers specify it, but the crash db issue means we'd have to wrap all calls to qemu.

So thanks - I understand if this patch doesn't make it upstream. I'll just carry a patch in our package in that case.

thanks,
-serge

#3 lore raw
In reply to Serge E. Hallyn
Quoted 16 lines · Serge E. Hallyn

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros? If not, can a patch like this one be applied?

---
 vl.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
vl.c +0 -0
index 112b0e0..2b53b62 100644

vl.c int nb_numa_nodes; · line 249

Quoted 3 lines
vl.c +1 -0
@@ -247,7 +247,9 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
+#include <uuid/uuid.h>

This adds a hard dep on libuuid (prior to this it's optional and only impacts the vdi block driver).

Quoted 29 lines
vl.c +10 -0
 uint8_t qemu_uuid[16];
+bool uuid_set = false;
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;
@@ -3030,6 +3032,7 @@ int main(int argc, char **argv, char **envp)
                             " Wrong format.\n");
                     exit(1);
                 }
+                uuid_set = true;
                 break;
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
@@ -3200,6 +3203,14 @@ int main(int argc, char **argv, char **envp)
         exit(0);
     }
+    if (!uuid_set) {
+        uuid_t uuid;
+        uuid_generate(uuid);
+        for (i = 0; i < 16; i++) {
+            qemu_uuid[i] = uuid[i];
+        }
+    }
+
     /* Open the logfile at this point, if necessary. We can't open the  

logfile
* when encountering either of the logging options (-d or -D)
because the
* other one may be encountered later on the command line, changing
the

#4 lore raw
Quoted 14 lines · Brian Jackson
Quoted 11 lines · Serge E. Hallyn

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros? If not, can a patch like this one be applied?

---
vl.c | 11 +++++++++++

1 files changed, 11 insertions(+), 0 deletions(-)
Quoted 13 lines

vl.c int nb_numa_nodes; · line 249

Quoted 8 lines
vl.c +1 -0
index 112b0e0..2b53b62 100644
@@ -247,7 +247,9 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
+#include <uuid/uuid.h>

This adds a hard dep on libuuid (prior to this it's optional and only impacts the vdi block driver).

Yup. If that's a problem we can re-implement our own, if the change in default behavior is acceptable.

Quoted 29 lines
Quoted 29 lines
vl.c +10 -0
 uint8_t qemu_uuid[16];
+bool uuid_set = false;
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;
@@ -3030,6 +3032,7 @@ int main(int argc, char **argv, char **envp)
                            " Wrong format.\n");
                    exit(1);
                }
+                uuid_set = true;
                break;
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
@@ -3200,6 +3203,14 @@ int main(int argc, char **argv, char **envp)
        exit(0);
    }
+    if (!uuid_set) {
+        uuid_t uuid;
+        uuid_generate(uuid);
+        for (i = 0; i < 16; i++) {
+            qemu_uuid[i] = uuid[i];
+        }
+    }
+
    /* Open the logfile at this point, if necessary. We can't

open the logfile
* when encountering either of the logging options (-d or -D)
because the
* other one may be encountered later on the command line,
changing the

#5 lore raw
In reply to Serge E. Hallyn
Quoted 7 lines · Serge E. Hallyn

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros? If not, can a patch like this one be applied?

The other hypervisors don't have a concept of a transient guest like QEMU does.

There is no state preserved between invocations of QEMU.

Setting a random UUID doesn't seem like the right answer to me as it would potentially break Windows VMs.

Perhaps if the DMI UUID isn't set, you could look at the root filesystem's UUID?

Not all platforms have a notion of platform UUID so as Ubuntu supports more architectures, this problem would have to be dealt with eventually.

Regards,

Anthony Liguori

Quoted 41 lines
---
  vl.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)
vl.c +11 -0
index 112b0e0..2b53b62 100644
@@ -247,7 +247,9 @@ int nb_numa_nodes;
  uint64_t node_mem[MAX_NODES];
  uint64_t node_cpumask[MAX_NODES];
 
+#include<uuid/uuid.h>
  uint8_t qemu_uuid[16];
+bool uuid_set = false;
 
  static QEMUBootSetHandler *boot_set_handler;
  static void *boot_set_opaque;
@@ -3030,6 +3032,7 @@ int main(int argc, char **argv, char **envp)
                              " Wrong format.\n");
                      exit(1);
                  }
+                uuid_set = true;
                  break;
  	    case QEMU_OPTION_option_rom:
  		if (nb_option_roms>= MAX_OPTION_ROMS) {
@@ -3200,6 +3203,14 @@ int main(int argc, char **argv, char **envp)
          exit(0);
      }
 
+    if (!uuid_set) {
+        uuid_t uuid;
+        uuid_generate(uuid);
+        for (i = 0; i<  16; i++) {
+            qemu_uuid[i] = uuid[i];
+        }
+    }
+
      /* Open the logfile at this point, if necessary. We can't open the logfile
       * when encountering either of the logging options (-d or -D) because the
       * other one may be encountered later on the command line, changing the
#6 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 7 lines · Serge E. Hallyn

Currently, if the user doesn't pass a uuid, the system uuid is set to all zeros. This patch generates a random one instead.

Is there a reason to prefer all zeros? If not, can a patch like this one be applied?

The other hypervisors don't have a concept of a transient guest like QEMU does.

True, and I generally don't like arguments of the form "but (some other) does it like this," but...

Quoted 1 line

There is no state preserved between invocations of QEMU.

Right, and I really don't know how many users (besides me) run kvm by hand, as opposed to using libvirt or testdrive. Perhaps testdrive should be extended.

Quoted 4 lines

Setting a random UUID doesn't seem like the right answer to me as it would potentially break Windows VMs.

Perhaps if the DMI UUID isn't set, you could look at the root filesystem's UUID?

Interesting idea. I don't know enough to know at which point in the code qemu would know that, but I can take a look.

Quoted 3 lines

Not all platforms have a notion of platform UUID so as Ubuntu supports more architectures, this problem would have to be dealt with eventually.

So it sounds like in this form certainly it's nacked :)

thanks,
-serge