[libvirt] [PATCH] storage: Skip socket and fifo on pool-start

If pool directory contains special files like FIFO or sockets we want to skip those on pool-start or pool-refresh otherwise open() will get an error. --- src/storage/storage_backend.c | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 93c98d6..d30829d 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1013,9 +1013,24 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb; char *base = last_component(path); + if (lstat(path, &sb) < 0) { + virReportSystemError(errno, + _("cannot stat file '%s'"), + path); + return -1; + } + + if (S_ISFIFO(sb.st_mode)) { + VIR_WARN("ignoring FIFO '%s'", path); + return -2; + } else if (S_ISSOCK(sb.st_mode)) { + VIR_WARN("ignoring socket '%s'", path); + return -2; + } + if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { if ((errno == ENOENT || errno == ELOOP) && - lstat(path, &sb) == 0) { + S_ISLNK(sb.st_mode)) { VIR_WARN("ignoring dangling symlink '%s'", path); return -2; } @@ -1026,14 +1041,6 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) return -1; } - if (fstat(fd, &sb) < 0) { - virReportSystemError(errno, - _("cannot stat file '%s'"), - path); - VIR_FORCE_CLOSE(fd); - return -1; - } - if (S_ISREG(sb.st_mode)) mode = VIR_STORAGE_VOL_OPEN_REG; else if (S_ISCHR(sb.st_mode)) -- 1.7.3.4

On Thu, Nov 24, 2011 at 03:22:10PM +0100, Michal Privoznik wrote:
If pool directory contains special files like FIFO or sockets we want to skip those on pool-start or pool-refresh otherwise open() will get an error. --- src/storage/storage_backend.c | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 93c98d6..d30829d 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1013,9 +1013,24 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb; char *base = last_component(path);
+ if (lstat(path, &sb) < 0) { + virReportSystemError(errno, + _("cannot stat file '%s'"), + path); + return -1; + } + + if (S_ISFIFO(sb.st_mode)) { + VIR_WARN("ignoring FIFO '%s'", path); + return -2; + } else if (S_ISSOCK(sb.st_mode)) { + VIR_WARN("ignoring socket '%s'", path); + return -2; + } + if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { if ((errno == ENOENT || errno == ELOOP) && - lstat(path, &sb) == 0) { + S_ISLNK(sb.st_mode)) { VIR_WARN("ignoring dangling symlink '%s'", path); return -2; } @@ -1026,14 +1041,6 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) return -1; }
- if (fstat(fd, &sb) < 0) { - virReportSystemError(errno, - _("cannot stat file '%s'"), - path); - VIR_FORCE_CLOSE(fd); - return -1; - } - if (S_ISREG(sb.st_mode)) mode = VIR_STORAGE_VOL_OPEN_REG; else if (S_ISCHR(sb.st_mode))
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 25.11.2011 03:38, Daniel Veillard wrote:
On Thu, Nov 24, 2011 at 03:22:10PM +0100, Michal Privoznik wrote:
If pool directory contains special files like FIFO or sockets we want to skip those on pool-start or pool-refresh otherwise open() will get an error. --- src/storage/storage_backend.c | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) ACK,
Daniel
Thanks, pushed. Michal

On Thu, Nov 24, 2011 at 15:22:10 +0100, Michal Privoznik wrote:
If pool directory contains special files like FIFO or sockets we want to skip those on pool-start or pool-refresh otherwise open() will get an error. --- src/storage/storage_backend.c | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 93c98d6..d30829d 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1013,9 +1013,24 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) struct stat sb; char *base = last_component(path);
+ if (lstat(path, &sb) < 0) { + virReportSystemError(errno, + _("cannot stat file '%s'"), + path); + return -1; + } + + if (S_ISFIFO(sb.st_mode)) { + VIR_WARN("ignoring FIFO '%s'", path); + return -2; + } else if (S_ISSOCK(sb.st_mode)) { + VIR_WARN("ignoring socket '%s'", path); + return -2; + } + if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0) { if ((errno == ENOENT || errno == ELOOP) && - lstat(path, &sb) == 0) { + S_ISLNK(sb.st_mode)) { VIR_WARN("ignoring dangling symlink '%s'", path); return -2; } @@ -1026,14 +1041,6 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags) return -1; }
- if (fstat(fd, &sb) < 0) { - virReportSystemError(errno, - _("cannot stat file '%s'"), - path); - VIR_FORCE_CLOSE(fd); - return -1; - } -
Oops, you can't remove this fstat since it operates on fd we got by opening path. Information returned by lstat(path) doesn't have to be the same as what fstat(fd) returns. Especially, if path is a symlink, the two calls will provide different results. The following code needs to check st_mode of the real file not a symlink...
if (S_ISREG(sb.st_mode)) mode = VIR_STORAGE_VOL_OPEN_REG; else if (S_ISCHR(sb.st_mode))
Jirka
participants (3)
-
Daniel Veillard
-
Jiri Denemark
-
Michal Privoznik