]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Ignore dangling symbolic link for filesystem pool
authorOsier Yang <jyang@redhat.com>
Tue, 21 Dec 2010 06:45:24 +0000 (14:45 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 21 Dec 2010 15:07:09 +0000 (08:07 -0700)
If there is a dangling symbolic link in filesystem pool, the pool
will fail to start or refresh, this patch is to fix it by ignoring
it with a warning log.

src/storage/storage_backend.c
src/storage/storage_backend_fs.c

index 10ea33c13380fb3f49233a5cc57af3d6bc46d9e2..ee08a4a1a0b20f631badbec6eb6e86b1edc5d6c5 100644 (file)
@@ -977,7 +977,8 @@ virStorageBackendForType(int type) {
 /*
  * Allows caller to silently ignore files with improper mode
  *
- * Returns -1 on error, -2 if file mode is unexpected.
+ * Returns -1 on error, -2 if file mode is unexpected or the
+ * volume is a dangling symbolic link.
  */
 int
 virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
@@ -986,6 +987,12 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
     struct stat sb;
 
     if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) {
+        if ((errno == ENOENT || errno == ELOOP) &&
+            lstat(path, &sb) == 0) {
+            VIR_WARN("ignoring dangling symlink '%s'", path);
+            return -2;
+        }
+
         virReportSystemError(errno,
                              _("cannot open volume '%s'"),
                              path);
index d916d2d19efde40a7affe4dbbdface1fcdd372be..ff39d48d6649eee674d5496ab74b7285cf051fe7 100644 (file)
@@ -651,7 +651,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
                 goto cleanup;
             else {
                 /* Silently ignore non-regular files,
-                 * eg '.' '..', 'lost+found' */
+                 * eg '.' '..', 'lost+found', dangling symbolic link */
                 virStorageVolDefFree(vol);
                 vol = NULL;
                 continue;