[4.0] 9149a06 Use VFIL_fsinfo in STV_FileSize, and drop the old implementation
Martin Blix Grydeland
martin at varnish-software.com
Tue Feb 24 11:53:12 CET 2015
commit 9149a0604e4584cd23d1e5719faf6189da9d69e9
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Tue Oct 7 13:46:57 2014 +0200
Use VFIL_fsinfo in STV_FileSize, and drop the old implementation
diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c
index 9ce647f..32a447f 100644
--- a/bin/varnishd/storage/stevedore_utils.c
+++ b/bin/varnishd/storage/stevedore_utils.c
@@ -54,6 +54,7 @@
#include "storage/storage.h"
#include "vnum.h"
+#include "vfil.h"
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
@@ -133,38 +134,6 @@ STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx)
}
/*--------------------------------------------------------------------
- * Figure out how much space is in a filesystem
- */
-
-static uintmax_t
-stv_fsspace(int fd, unsigned *bs)
-{
- uintmax_t bsize, bavail;
-#if defined(HAVE_SYS_STATVFS_H)
- struct statvfs fsst;
-
- AZ(fstatvfs(fd, &fsst));
- bsize = fsst.f_frsize;
- bavail = fsst.f_bavail;
-#elif defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H)
- struct statfs fsst;
-
- AZ(fstatfs(sc->fd, &fsst));
- bsize = fsst.f_bsize;
- bavail = fsst.f_bavail;
-#else
-#error no struct statfs / struct statvfs
-#endif
-
- /* We use units of the larger of filesystem blocksize and pagesize */
- if (*bs < bsize)
- *bs = bsize;
- XXXAZ(*bs % bsize);
- return (bsize * bavail);
-}
-
-
-/*--------------------------------------------------------------------
* Decide file size.
*
* If the sizespecification is empty and the file exists with non-zero
@@ -183,12 +152,16 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
off_t o;
struct stat st;
+ AN(granularity);
+ AN(ctx);
+
AZ(fstat(fd, &st));
xxxassert(S_ISREG(st.st_mode));
- bs = *granularity;
- fssize = stv_fsspace(fd, &bs);
- XXXAZ(bs % *granularity);
+ AZ(VFIL_fsinfo(fd, &bs, &fssize, NULL));
+ /* Increase granularity if it is lower than the filesystem block size */
+ if (*granularity < bs)
+ *granularity = bs;
if ((size == NULL || *size == '\0') && st.st_size != 0) {
/*
@@ -239,9 +212,8 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
l = INT32_MAX;
}
- /* round down to multiple of filesystem blocksize or pagesize */
- l -= (l % bs);
+ /* Round down */
+ l -= (l % *granularity);
- *granularity = bs;
return(l);
}
More information about the varnish-commit
mailing list