File libvirt-Log-warning-if-storage-magic-matches-but-version-does-not.patch of Package libvirt

From 7c6fab20ddbe61939ba32d09ec0f5b99cfd23ed8 Mon Sep 17 00:00:00 2001
Message-Id: <7c6fab20ddbe61939ba32d09ec0f5b99cfd23ed8.1373271637.git.jdenemar@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Mon, 25 Feb 2013 16:21:44 -0700
Subject: [PATCH] Log warning if storage magic matches, but version does not

https://bugzilla.redhat.com/show_bug.cgi?id=903248

To help us detect when new storage file versions come into
existance log a warning if the storage file magic matches,
but the version does not

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit dfba37048a6cb684ee6938131d7f557ddf16d53d)
---
 src/util/storage_file.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index 50f64ae..a5402fd 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -756,16 +756,26 @@ virStorageFileProbeFormatFromBuf(const char *path,
 {
     int format = VIR_STORAGE_FILE_RAW;
     int i;
+    int possibleFormat = VIR_STORAGE_FILE_RAW;
+    VIR_DEBUG("path=%s", path);
 
     /* First check file magic */
     for (i = 0 ; i < VIR_STORAGE_FILE_LAST ; i++) {
-        if (virStorageFileMatchesMagic(i, buf, buflen) &&
-            virStorageFileMatchesVersion(i, buf, buflen)) {
+        if (virStorageFileMatchesMagic(i, buf, buflen)) {
+            if (!virStorageFileMatchesVersion(i, buf, buflen)) {
+                possibleFormat = i;
+                continue;
+            }
             format = i;
             goto cleanup;
         }
     }
 
+    if (possibleFormat != VIR_STORAGE_FILE_RAW)
+        VIR_WARN("File %s matches %s magic, but version is wrong. "
+                 "Please report new version to libvir-list@redhat.com",
+                 path, virStorageFileFormatTypeToString(possibleFormat));
+
     /* No magic, so check file extension */
     for (i = 0 ; i < VIR_STORAGE_FILE_LAST ; i++) {
         if (virStorageFileMatchesExtension(i, path)) {
-- 
1.8.2.1

openSUSE Build Service is sponsored by