9119d9
From 7567a5cad149ac0ea17e0bfc32f07ada642cd921 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <7567a5cad149ac0ea17e0bfc32f07ada642cd921@dist-git>
9119d9
From: Jiri Denemark <jdenemar@redhat.com>
9119d9
Date: Wed, 26 Nov 2014 16:24:27 +0100
9119d9
Subject: [PATCH] network: Fix upgrade from libvirt older than 1.2.4
9119d9
9119d9
Starting from libvirt-1.2.4, network state XML files moved to another
9119d9
directory (see commit b9e95491) and libvirt automatically migrates the
9119d9
network state files to a new location. However, the code used
9119d9
dirent.d_type which is not supported by all filesystems. Thus, when
9119d9
libvirt was upgraded on a host which used such filesystem, network state
9119d9
XMLs were not properly moved and running networks disappeared from
9119d9
libvirt.
9119d9
9119d9
This patch falls back to lstat() whenever dirent.d_type is DT_UNKNOWN to
9119d9
fix this issue.
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1167145
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
(cherry picked from commit dabb23e6d95dc7d81e7fb2a3f6c942167f4c45af)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/network/bridge_driver.c | 23 +++++++++++++++++++++--
9119d9
 1 file changed, 21 insertions(+), 2 deletions(-)
9119d9
9119d9
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
9119d9
index 9746099..488409d 100644
9119d9
--- a/src/network/bridge_driver.c
9119d9
+++ b/src/network/bridge_driver.c
9119d9
@@ -508,15 +508,34 @@ networkMigrateStateFiles(virNetworkDriverStatePtr driver)
9119d9
     }
9119d9
 
9119d9
     while ((direrr = virDirRead(dir, &entry, oldStateDir)) > 0) {
9119d9
+        if (entry->d_type != DT_UNKNOWN &&
9119d9
+            entry->d_type != DT_REG)
9119d9
+            continue;
9119d9
 
9119d9
-        if (entry->d_type != DT_REG ||
9119d9
-            STREQ(entry->d_name, ".") ||
9119d9
+        if (STREQ(entry->d_name, ".") ||
9119d9
             STREQ(entry->d_name, ".."))
9119d9
             continue;
9119d9
 
9119d9
         if (virAsprintf(&oldPath, "%s/%s",
9119d9
                         oldStateDir, entry->d_name) < 0)
9119d9
             goto cleanup;
9119d9
+
9119d9
+        if (entry->d_type == DT_UNKNOWN) {
9119d9
+            struct stat st;
9119d9
+
9119d9
+            if (lstat(oldPath, &st) < 0) {
9119d9
+                virReportSystemError(errno,
9119d9
+                                     _("failed to stat network status file '%s'"),
9119d9
+                                     oldPath);
9119d9
+                goto cleanup;
9119d9
+            }
9119d9
+
9119d9
+            if (!S_ISREG(st.st_mode)) {
9119d9
+                VIR_FREE(oldPath);
9119d9
+                continue;
9119d9
+            }
9119d9
+        }
9119d9
+
9119d9
         if (virFileReadAll(oldPath, 1024*1024, &contents) < 0)
9119d9
             goto cleanup;
9119d9
 
9119d9
-- 
9119d9
2.1.3
9119d9