[libvirt PATCH v4] ch: Fix cloud-hypervisor version processing

Praveen K Paladugu posted 1 patch 8 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20230908222908.43777-1-prapal@linux.microsoft.com
src/ch/ch_conf.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
[libvirt PATCH v4] ch: Fix cloud-hypervisor version processing
Posted by Praveen K Paladugu 8 months, 2 weeks ago
Refactor the version processing logic in ch driver to support versions
from non-release cloud-hypervisor binaries. This version also supports
versions with branch prefixes in them.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
---
 src/ch/ch_conf.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c
index a8565d9537..f421af5121 100644
--- a/src/ch/ch_conf.c
+++ b/src/ch/ch_conf.c
@@ -172,6 +172,29 @@ virCHDriverConfigDispose(void *obj)
 
 #define MIN_VERSION ((15 * 1000000) + (0 * 1000) + (0))
 
+/**
+ * chPreProcessVersionString:
+ *
+ * Returns: a pointer to numerical version without branch/commit info
+ */
+static char *
+chPreProcessVersionString(char *version)
+{
+    char *tmp = strrchr(version, '/');
+
+    if (tmp)
+        version = tmp + 1;
+
+    if (version[0] == 'v')
+        version++;
+
+    tmp = strchr(version, '-');
+    if (tmp)
+        *tmp = '\0';
+
+    return version;
+}
+
 int
 chExtractVersion(virCHDriver *driver)
 {
@@ -193,13 +216,20 @@ chExtractVersion(virCHDriver *driver)
 
     tmp = help;
 
-    /* expected format: cloud-hypervisor v<major>.<minor>.<micro> */
-    if ((tmp = STRSKIP(tmp, "cloud-hypervisor v")) == NULL) {
+    /* Below are example version formats and expected outputs:
+     *  cloud-hypervisor v32.0.0 (expected: 32.0.0)
+     *  cloud-hypervisor v33.0-104-ge0e3779e-dirty (expected: 33.0)
+     *  cloud-hypervisor testing/v32.0.131-1-ga5d6db5c-dirty (expected: 32.0.131)
+     */
+    if ((tmp = STRSKIP(tmp, "cloud-hypervisor ")) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unexpected output of cloud-hypervisor binary"));
         return -1;
     }
 
+    tmp = chPreProcessVersionString(tmp);
+    VIR_DEBUG("Cloud-Hypervisor version detected: %s", tmp);
+
     if (virStringParseVersion(&version, tmp, true) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to parse cloud-hypervisor version: %1$s"), tmp);
-- 
2.41.0
Re: [libvirt PATCH v4] ch: Fix cloud-hypervisor version processing
Posted by Martin Kletzander 8 months, 2 weeks ago
On Fri, Sep 08, 2023 at 05:29:08PM -0500, Praveen K Paladugu wrote:
>Refactor the version processing logic in ch driver to support versions
>from non-release cloud-hypervisor binaries. This version also supports
>versions with branch prefixes in them.
>
>Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

and pushed now.  Thanks

>---
> src/ch/ch_conf.c | 34 ++++++++++++++++++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
>
>diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c
>index a8565d9537..f421af5121 100644
>--- a/src/ch/ch_conf.c
>+++ b/src/ch/ch_conf.c
>@@ -172,6 +172,29 @@ virCHDriverConfigDispose(void *obj)
>
> #define MIN_VERSION ((15 * 1000000) + (0 * 1000) + (0))
>
>+/**
>+ * chPreProcessVersionString:
>+ *
>+ * Returns: a pointer to numerical version without branch/commit info
>+ */
>+static char *
>+chPreProcessVersionString(char *version)
>+{
>+    char *tmp = strrchr(version, '/');
>+
>+    if (tmp)
>+        version = tmp + 1;
>+
>+    if (version[0] == 'v')
>+        version++;
>+
>+    tmp = strchr(version, '-');
>+    if (tmp)
>+        *tmp = '\0';
>+
>+    return version;
>+}
>+
> int
> chExtractVersion(virCHDriver *driver)
> {
>@@ -193,13 +216,20 @@ chExtractVersion(virCHDriver *driver)
>
>     tmp = help;
>
>-    /* expected format: cloud-hypervisor v<major>.<minor>.<micro> */
>-    if ((tmp = STRSKIP(tmp, "cloud-hypervisor v")) == NULL) {
>+    /* Below are example version formats and expected outputs:
>+     *  cloud-hypervisor v32.0.0 (expected: 32.0.0)
>+     *  cloud-hypervisor v33.0-104-ge0e3779e-dirty (expected: 33.0)
>+     *  cloud-hypervisor testing/v32.0.131-1-ga5d6db5c-dirty (expected: 32.0.131)
>+     */
>+    if ((tmp = STRSKIP(tmp, "cloud-hypervisor ")) == NULL) {
>         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>                        _("Unexpected output of cloud-hypervisor binary"));
>         return -1;
>     }
>
>+    tmp = chPreProcessVersionString(tmp);
>+    VIR_DEBUG("Cloud-Hypervisor version detected: %s", tmp);
>+
>     if (virStringParseVersion(&version, tmp, true) < 0) {
>         virReportError(VIR_ERR_INTERNAL_ERROR,
>                        _("Unable to parse cloud-hypervisor version: %1$s"), tmp);
>-- 
>2.41.0
>