osdep: Change default value of qemu_hw_version() to "2.5+"
authorEduardo Habkost <ehabkost@redhat.com>
Thu, 12 Nov 2015 17:29:54 +0000 (15:29 -0200)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 25 Nov 2015 11:42:37 +0000 (13:42 +0200)
There are two issues with qemu_hw_version() today:

1) If a machine has hw_version set, the value returned by it is
   not very useful, because it is not the actual QEMU version.
2) If a machine does't set hw_version, the return value of
   qemu_hw_version() is broken, because it will change when
   upgrading QEMU.

For those reasons, using qemu_hw_version() is strongly
discouraged, and should be used only in code that used
QEMU_VERSION in the past and needs to keep compatibility.

To fix (2), instead of making every machine broken by default
unless they set hw_version, make qemu_hw_version() simply return
"2.5+" if qemu_set_hw_version() is not called.

Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
include/hw/boards.h
include/qemu/osdep.h
util/osdep.c

index 24eb6f0e770c7fd7e9a935b482be8fc380af100a..5da4fb00eeda22f3e204f3316993180d23a730ea 100644 (file)
@@ -51,6 +51,11 @@ bool machine_mem_merge(MachineState *machine);
  *    used to provide @cpu_index to socket number mapping, allowing
  *    a machine to group CPU threads belonging to the same socket/package
  *    Returns: socket number given cpu_index belongs to.
+ * @hw_version:
+ *    Value of QEMU_VERSION when the machine was added to QEMU.
+ *    Set only by old machines because they need to keep
+ *    compatibility on code that exposed QEMU_VERSION to guests in
+ *    the past (and now use qemu_hw_version()).
  */
 struct MachineClass {
     /*< private >*/
index 861d84b4e44d298bd02ebdb372f0a5954109dbd0..84e84ac700c2f8aadf180b9ab6bf00a571136eec 100644 (file)
@@ -256,6 +256,10 @@ static inline void qemu_timersub(const struct timeval *val1,
 
 void qemu_set_cloexec(int fd);
 
+/* QEMU "hardware version" setting. Used to replace code that exposed
+ * QEMU_VERSION to guests in the past and need to keep compatibilty.
+ * Do not use qemu_hw_version() in new code.
+ */
 void qemu_set_hw_version(const char *);
 const char *qemu_hw_version(void);
 
index 80c6bfeeb2ed99586d882b3a28bd1eeec711a89f..534b51147c5bcbe11aadc0f3cecf0d5f89588726 100644 (file)
@@ -52,7 +52,14 @@ extern int madvise(caddr_t, size_t, int);
 
 static bool fips_enabled = false;
 
-static const char *hw_version = QEMU_VERSION;
+/* Starting on QEMU 2.5, qemu_hw_version() returns "2.5+" by default
+ * instead of QEMU_VERSION, so setting hw_version on MachineClass
+ * is no longer mandatory.
+ *
+ * Do NOT change this string, or it will break compatibility on all
+ * machine classes that don't set hw_version.
+ */
+static const char *hw_version = "2.5+";
 
 int socket_set_cork(int fd, int v)
 {