Blob Blame History Raw
From c40bd80dcb6de62d1bd48af22a4dcbd73cf66506 Mon Sep 17 00:00:00 2001
Message-Id: <c40bd80dcb6de62d1bd48af22a4dcbd73cf66506@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Wed, 26 Feb 2014 14:54:27 +0100
Subject: [PATCH] storage: improve handling of symlinks in gluster

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

With this patch, dangling and looping symlinks are silently
ignored, while links to files and directories are treated the
same as the underlying file or directory.  This is the same
behavior as both 'directory' and 'netfs' pools.

* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Treat symlinks similar to
directory and netfs pools.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 79eb21f9765495841daecee2e3ec6bf402022327)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage/storage_backend_gluster.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 685ad57..f0ec357 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -166,6 +166,17 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     if (STREQ(name, ".") || STREQ(name, ".."))
         return 0;
 
+    /* Follow symlinks; silently skip broken links and loops.  */
+    if (S_ISLNK(st->st_mode) && glfs_stat(state->vol, name, st) < 0) {
+        if (errno == ENOENT || errno == ELOOP) {
+            VIR_WARN("ignoring dangling symlink '%s'", name);
+            ret = 0;
+        } else {
+            virReportSystemError(errno, _("cannot stat '%s'"), name);
+        }
+        return ret;
+    }
+
     if (VIR_ALLOC(vol) < 0)
         goto cleanup;
 
-- 
1.9.0