[virt-tools-list] [PATCH libosinfo] Handle distinction of OS vs kernel version correctly.

Daniel P. Berrange berrange at redhat.com
Wed Apr 25 16:40:43 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

We currently record a version number against any product (ie OS
or Hypervisor).  The data we are recording against Windows OS
though is not actually an OS version, rather it is the Windows
kernel version. This becomes clear when you wonder why both
Vista and Win2k8 show the same version number - they share
the same kernel, but they are obviously different versions of
the Windows OS

This introduces an explicit 'kernel-version' property against
OS objects, and adjusts the windows metadata to use this.
---
 data/oses/windows.xml      |   34 ++++++++++++++++++++++------------
 data/schemas/libosinfo.rng |    5 +++++
 osinfo/libosinfo.syms      |    5 +++++
 osinfo/osinfo_loader.c     |    1 +
 osinfo/osinfo_os.c         |   39 +++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_os.h         |    6 ++++--
 tools/osinfo-query.c       |    2 ++
 7 files changed, 78 insertions(+), 14 deletions(-)

diff --git a/data/oses/windows.xml b/data/oses/windows.xml
index bcf0eb6..50364c3 100644
--- a/data/oses/windows.xml
+++ b/data/oses/windows.xml
@@ -82,6 +82,7 @@
     <family>win16</family>
     <distro>win</distro>
     <version>1.0</version>
+    <kernel-version>1.0</kernel-version>
 
     <release-date>1985-11-20</release-date>
     <eol-date>2001-12-31</eol-date>
@@ -94,6 +95,7 @@
     <family>win16</family>
     <distro>win</distro>
     <version>2.0</version>
+    <kernel-version>2.0</kernel-version>
     <upgrades id="http://microsoft.com/win/1.0"/>
     <derives-from id="http://microsoft.com/win/1.0"/>
 
@@ -108,6 +110,7 @@
     <family>win16</family>
     <distro>win</distro>
     <version>2.1</version>
+    <kernel-version>2.1</kernel-version>
     <upgrades id="http://microsoft.com/win/2.0"/>
     <derives-from id="http://microsoft.com/win/2.0"/>
 
@@ -122,6 +125,7 @@
     <family>win16</family>
     <distro>win</distro>
     <version>3.1</version>
+    <kernel-version>3.1</kernel-version>
     <upgrades id="http://microsoft.com/win/2.1"/>
     <derives-from id="http://microsoft.com/win/2.1"/>
 
@@ -136,6 +140,7 @@
     <family>winnt</family>
     <distro>winnt</distro>
     <version>3.1</version>
+    <kernel-version>3.1</kernel-version>
     <release-date>1993-07-27</release-date>
     <eol-date>2000-12-31</eol-date>
   </os>
@@ -147,6 +152,7 @@
     <family>winnt</family>
     <distro>winnt</distro>
     <version>3.5</version>
+    <kernel-version>3.5</kernel-version>
     <upgrades id="http://microsoft.com/winnt/3.1"/>
     <derives-from id="http://microsoft.com/winnt/3.1"/>
 
@@ -161,6 +167,7 @@
     <family>winnt</family>
     <distro>winnt</distro>
     <version>3.51</version>
+    <kernel-version>3.51</kernel-version>
     <upgrades id="http://microsoft.com/winnt/3.5"/>
     <derives-from id="http://microsoft.com/winnt/3.5"/>
 
@@ -175,6 +182,7 @@
     <family>winnt</family>
     <distro>winnt</distro>
     <version>4.0</version>
+    <kernel-version>4.0</kernel-version>
     <upgrades id="http://microsoft.com/winnt/3.51"/>
     <derives-from id="http://microsoft.com/winnt/3.51"/>
 
@@ -185,7 +193,7 @@
   <os id="http://microsoft.com/win/95">
     <short-id>win95</short-id>
     <name>Microsoft Windows 95</name>
-    <version>4.0</version>
+    <kernel-version>4.0</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>win9x</family>
     <distro>win</distro>
@@ -214,7 +222,7 @@
   <os id="http://microsoft.com/win/98">
     <short-id>win98</short-id>
     <name>Microsoft Windows 98</name>
-    <version>4.1</version>
+    <kernel-version>4.1</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>win9x</family>
     <distro>win</distro>
@@ -241,7 +249,7 @@
   <os id="http://microsoft.com/win/me">
     <short-id>winme</short-id>
     <name>Microsoft Windows Millennium Edition</name>
-    <version>4.9</version>
+    <kernel-version>4.9</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>win9x</family>
     <distro>win</distro>
@@ -269,7 +277,7 @@
   <os id="http://microsoft.com/win/2k">
     <short-id>win2k</short-id>
     <name>Microsoft Windows 2000</name>
-    <version>5.0</version>
+    <kernel-version>5.0</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -312,7 +320,7 @@
   <os id="http://microsoft.com/win/xp">
     <short-id>winxp</short-id>
     <name>Microsoft Windows XP</name>
-    <version>5.1</version>
+    <kernel-version>5.1</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -364,7 +372,7 @@
   <os id="http://microsoft.com/win/2k3">
     <short-id>win2k3</short-id>
     <name>Microsoft Windows Server 2003</name>
-    <version>5.2</version>
+    <kernel-version>5.2</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -425,7 +433,7 @@
   <os id="http://microsoft.com/win/2k3r2">
     <short-id>win2k3r2</short-id>
     <name>Microsoft Windows Server 2003 R2</name>
-    <version>5.2</version>
+    <kernel-version>5.2</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -480,7 +488,7 @@
   <os id="http://microsoft.com/win/2k8">
     <short-id>win2k8</short-id>
     <name>Microsoft Windows Server 2008</name>
-    <version>6.0</version>
+    <kernel-version>6.0</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -537,7 +545,7 @@
   <os id="http://microsoft.com/win/2k8r2">
     <short-id>win2k8r2</short-id>
     <name>Microsoft Windows Server 2008 R2</name>
-    <version>6.1</version>
+    <kernel-version>6.1</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -579,7 +587,7 @@
   <os id="http://microsoft.com/win/vista">
     <short-id>winvista</short-id>
     <name>Microsoft Windows Vista</name>
-    <version>6.0</version>
+    <kernel-version>6.0</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -621,7 +629,8 @@
   <os id="http://microsoft.com/win/7">
     <short-id>win7</short-id>
     <name>Microsoft Windows 7</name>
-    <version>6.1</version>
+    <version>7</version>
+    <kernel-version>6.1</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
@@ -670,7 +679,8 @@
   <os id="http://microsoft.com/win/8">
     <short-id>win8</short-id>
     <name>Microsoft Windows 8</name>
-    <version>6.2</version>
+    <version>8</version>
+    <kernel-version>6.2</kernel-version>
     <vendor>Microsoft Corporation</vendor>
     <family>winnt</family>
     <distro>win</distro>
diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 78fde35..049ceef 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -118,6 +118,11 @@
           <text/>
         </element>
       </optional>
+      <optional>
+        <element name='kernel-version'>
+          <text/>
+        </element>
+      </optional>
     </interleave>
   </define>
 
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index dcf12ab..747d6bf 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -235,6 +235,11 @@ LIBOSINFO_0.1.0 {
 	osinfo_treelist_new_union;
 } LIBOSINFO_0.0.6;
 
+LIBOSINFO_0.1.2 {
+    global:
+	osinfo_os_get_kernel_version;
+} LIBOSINFO_0.1.0;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 21d9c7a..98b113f 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -695,6 +695,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
     const gchar *const keys[] = {
         OSINFO_OS_PROP_FAMILY,
         OSINFO_OS_PROP_DISTRO,
+        OSINFO_OS_PROP_KERNEL_VERSION,
         NULL
     };
     if (!id) {
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 9b503cb..9b002cb 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -63,6 +63,7 @@ enum {
 
     PROP_FAMILY,
     PROP_DISTRO,
+    PROP_KERNEL_VERSION,
 };
 
 static void osinfo_os_finalize (GObject *object);
@@ -92,6 +93,11 @@ osinfo_os_get_property (GObject    *object,
                                 osinfo_entity_get_param_value (entity,
                                                                "distro"));
             break;
+        case PROP_KERNEL_VERSION:
+            g_value_set_string (value,
+                                osinfo_entity_get_param_value (entity,
+                                                               "kernel-version"));
+            break;
         default:
             /* We don't have any other property... */
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -160,6 +166,24 @@ osinfo_os_class_init (OsinfoOsClass *klass)
     g_object_class_install_property (g_klass,
                                      PROP_DISTRO,
                                      pspec);
+
+    /**
+     * OsinfoOs:kernel-version:
+     *
+     * The version number of the kernel running the OS.
+     */
+    pspec = g_param_spec_string ("kernel-version",
+                                 "KernelVersion",
+                                 "Kernel version",
+                                 NULL /* default value */,
+                                 G_PARAM_READABLE |
+                                 G_PARAM_STATIC_NAME |
+                                 G_PARAM_STATIC_NICK |
+                                 G_PARAM_STATIC_BLURB);
+    g_object_class_install_property (g_klass,
+                                     PROP_KERNEL_VERSION,
+                                     pspec);
+
 }
 
 static void
@@ -389,6 +413,21 @@ const gchar *osinfo_os_get_distro(OsinfoOs *os)
 }
 
 /**
+ * osinfo_os_get_kernel_version:
+ * @os: a OsinfoOs
+ *
+ * Retrieves the version number of the kernel running the OS @os
+ *
+ * Returns: (transfer none): the kernel version of this os
+ */
+const gchar *osinfo_os_get_kernel_version(OsinfoOs *os)
+{
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(os), "kernel-version");
+}
+
+/**
  * osinfo_os_get_media_list:
  * @os: an operating system
  *
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 862498c..30c42e1 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -52,8 +52,9 @@ typedef struct _OsinfoOsClass   OsinfoOsClass;
 
 typedef struct _OsinfoOsPrivate OsinfoOsPrivate;
 
-#define OSINFO_OS_PROP_FAMILY    "family"
-#define OSINFO_OS_PROP_DISTRO    "distro"
+#define OSINFO_OS_PROP_FAMILY         "family"
+#define OSINFO_OS_PROP_DISTRO         "distro"
+#define OSINFO_OS_PROP_KERNEL_VERSION "kernel-version"
 
 /* object */
 struct _OsinfoOs
@@ -89,6 +90,7 @@ OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoFilter *fil
 OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev);
 const gchar *osinfo_os_get_family(OsinfoOs *os);
 const gchar *osinfo_os_get_distro(OsinfoOs *os);
+const gchar *osinfo_os_get_kernel_version(OsinfoOs *os);
 OsinfoMediaList *osinfo_os_get_media_list(OsinfoOs *os);
 void osinfo_os_add_media(OsinfoOs *os, OsinfoMedia *media);
 OsinfoTreeList *osinfo_os_get_tree_list(OsinfoOs *os);
diff --git a/tools/osinfo-query.c b/tools/osinfo-query.c
index 69b789a..f1c4305 100644
--- a/tools/osinfo-query.c
+++ b/tools/osinfo-query.c
@@ -61,6 +61,8 @@ static struct OsinfoLabel os_labels[] = {
       "Family", FALSE, 12 },
     { OSINFO_OS_PROP_DISTRO,
       "Distro", FALSE, 12 },
+    { OSINFO_OS_PROP_KERNEL_VERSION,
+      "Kernel", FALSE, 8 },
     { OSINFO_PRODUCT_PROP_VENDOR,
       "Vendor", FALSE, 25 },
     { OSINFO_PRODUCT_PROP_RELEASE_DATE,
-- 
1.7.7.6




More information about the virt-tools-list mailing list