Mailing List Archive

r1826 - in branches/1.1: . bin/varnishd
Author: des
Date: 2007-08-10 11:33:39 +0200 (Fri, 10 Aug 2007)
New Revision: 1826

Modified:
branches/1.1/
branches/1.1/bin/varnishd/storage_file.c
Log:
Merged revisions 1794 via svnmerge from
file:///var/lib/svn/varnish/trunk/varnish-cache

........
r1794 | des | 2007-08-03 20:50:05 +0200 (Fri, 03 Aug 2007) | 3 lines

Try harder to avoid integer overflows in cache file size calculations
on 32-bit platforms.
........



Property changes on: branches/1.1
___________________________________________________________________
Name: svnmerge-integrated
- /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817,1819,1823
+ /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823

Modified: branches/1.1/bin/varnishd/storage_file.c
===================================================================
--- branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:30:07 UTC (rev 1825)
+++ branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:33:39 UTC (rev 1826)
@@ -126,6 +126,7 @@

AN(sc);
AZ(fstat(sc->fd, &st));
+ xxxassert(S_ISREG(st.st_mode));

AZ(fstatfs(sc->fd, &fsst));

@@ -133,9 +134,10 @@
bs = sc->pagesize;
if (bs < fsst.f_bsize)
bs = fsst.f_bsize;
+ xxxassert(bs % sc->pagesize == 0);
+ xxxassert(bs % fsst.f_bsize == 0);
+ fssize = fsst.f_bsize * fsst.f_bavail;

- xxxassert(S_ISREG(st.st_mode));
-
i = sscanf(size, "%ju%1s", &l, suff); /* can return -1, 0, 1 or 2 */

explicit = i;
@@ -175,7 +177,7 @@
l *= (uintmax_t)(1024UL * 1024UL) *
(uintmax_t)(1024UL * 1024UL);
else if (suff[0] == '%') {
- l *= fsst.f_bsize * fsst.f_bavail;
+ l *= fssize;
l /= 100;
}
}
@@ -196,14 +198,14 @@

if (l < st.st_size) {
AZ(ftruncate(sc->fd, l));
- } else if (l - st.st_size > fsst.f_bsize * fsst.f_bavail) {
- l = ((uintmax_t)fsst.f_bsize * fsst.f_bavail * 80) / 100;
+ } else if (l - st.st_size > fssize) {
+ l = fssize * 80 / 100;
fprintf(stderr, "WARNING: storage file size reduced"
" to %ju (80%% of available disk space)\n", l);
}
}

- /* round down to of filesystem blocksize or pagesize */
+ /* round down to multiple of filesystem blocksize or pagesize */
l -= (l % bs);

if (l < MINPAGES * (uintmax_t)sc->pagesize) {