[libvirt] [PATCH] [v3] storage: Ignore dangling symbolic link for filesystem pool

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 | 10 +++++++++- src/storage/storage_backend_fs.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 10ea33c..f4a17a2 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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,13 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb; if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { + if (stat(path, &sb) < 0 && + (errno == ENOENT || errno == ELOOP)) { + VIR_WARN(_("cannot open volume '%s' :%s"), path, + strerror(errno)); + return -2; + } + virReportSystemError(errno, _("cannot open volume '%s'"), path); diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index d916d2d..ff39d48 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -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; -- 1.7.3.2

On 12/20/2010 11:45 PM, Osier Yang wrote:
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 | 10 +++++++++- src/storage/storage_backend_fs.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
@@ -986,6 +987,13 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb;
if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { + if (stat(path, &sb) < 0 && + (errno == ENOENT || errno == ELOOP)) { + VIR_WARN(_("cannot open volume '%s' :%s"), path, + strerror(errno)); + return -2; + }
Given my comments here: https://www.redhat.com/archives/libvir-list/2010-December/msg00826.html I'm squashing this in, then pushing. Thanks for tackling this one. diff --git i/src/storage/storage_backend.c w/src/storage/storage_backend.c index efdd258..66775e9 100644 --- i/src/storage/storage_backend.c +++ w/src/storage/storage_backend.c @@ -987,8 +987,8 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb; if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { - if (stat(path, &sb) < 0 && - (errno == ENOENT || errno == ELOOP)) { + if ((errno == ENOENT || errno == ELOOP) && + lstat(path, &sb) == 0) { VIR_WARN(_("cannot open volume '%s' :%s"), path, strerror(errno)); return -2; -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 12/20/2010 11:45 PM, Osier Yang wrote:
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.
if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { + if (stat(path, &sb) < 0 && + (errno == ENOENT || errno == ELOOP)) { + VIR_WARN(_("cannot open volume '%s' :%s"), path,
Oh, and 'make syntax-check' didn't like _() marking inside VIR_WARN. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Osier Yang