]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
network: Fix upgrade from libvirt older than 1.2.4
authorJiri Denemark <jdenemar@redhat.com>
Wed, 26 Nov 2014 15:24:27 +0000 (16:24 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 27 Nov 2014 08:58:54 +0000 (09:58 +0100)
Starting from libvirt-1.2.4, network state XML files moved to another
directory (see commit b9e95491) and libvirt automatically migrates the
network state files to a new location. However, the code used
dirent.d_type which is not supported by all filesystems. Thus, when
libvirt was upgraded on a host which used such filesystem, network state
XMLs were not properly moved and running networks disappeared from
libvirt.

This patch falls back to lstat() whenever dirent.d_type is DT_UNKNOWN to
fix this issue.

https://bugzilla.redhat.com/show_bug.cgi?id=1167145
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/network/bridge_driver.c

index 6cb421c5285041ad8569825d5646ce336b7d77e0..52d2b98872409f7644b7e4320a4a6c03b2b9c63d 100644 (file)
@@ -499,15 +499,34 @@ networkMigrateStateFiles(void)
     }
 
     while ((direrr = virDirRead(dir, &entry, oldStateDir)) > 0) {
+        if (entry->d_type != DT_UNKNOWN &&
+            entry->d_type != DT_REG)
+            continue;
 
-        if (entry->d_type != DT_REG ||
-            STREQ(entry->d_name, ".") ||
+        if (STREQ(entry->d_name, ".") ||
             STREQ(entry->d_name, ".."))
             continue;
 
         if (virAsprintf(&oldPath, "%s/%s",
                         oldStateDir, entry->d_name) < 0)
             goto cleanup;
+
+        if (entry->d_type == DT_UNKNOWN) {
+            struct stat st;
+
+            if (lstat(oldPath, &st) < 0) {
+                virReportSystemError(errno,
+                                     _("failed to stat network status file '%s'"),
+                                     oldPath);
+                goto cleanup;
+            }
+
+            if (!S_ISREG(st.st_mode)) {
+                VIR_FREE(oldPath);
+                continue;
+            }
+        }
+
         if (virFileReadAll(oldPath, 1024*1024, &contents) < 0)
             goto cleanup;