aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vac
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2009-05-25 02:11:27 -0700
committerRuss Cox <rsc@swtch.com>2009-05-25 02:11:27 -0700
commit75d048884cfcb7cc4404b384da50923e22224365 (patch)
treeb918a6a957b1f322ebb2f84c16092e103f91acda /src/cmd/vac
parent33b446b8bbfea80552d462296d27ad4114fbd3fb (diff)
downloadplan9port-75d048884cfcb7cc4404b384da50923e22224365.tar.gz
plan9port-75d048884cfcb7cc4404b384da50923e22224365.tar.bz2
plan9port-75d048884cfcb7cc4404b384da50923e22224365.zip
venti: 32-bit extensions to data structures
Diffstat (limited to 'src/cmd/vac')
-rw-r--r--src/cmd/vac/file.c34
-rw-r--r--src/cmd/vac/pack.c2
-rw-r--r--src/cmd/vac/unvac.c2
-rw-r--r--src/cmd/vac/vac.c14
-rw-r--r--src/cmd/vac/vac.h6
-rw-r--r--src/cmd/vac/vacfs.c37
6 files changed, 66 insertions, 29 deletions
diff --git a/src/cmd/vac/file.c b/src/cmd/vac/file.c
index faa558f3..bf17ea38 100644
--- a/src/cmd/vac/file.c
+++ b/src/cmd/vac/file.c
@@ -1730,7 +1730,7 @@ Err1:
static char EBadVacFormat[] = "bad format for vac file";
static VacFs *
-vacfsalloc(VtConn *z, int bsize, int ncache, int mode)
+vacfsalloc(VtConn *z, int bsize, ulong cachemem, int mode)
{
VacFs *fs;
@@ -1738,7 +1738,7 @@ vacfsalloc(VtConn *z, int bsize, int ncache, int mode)
fs->z = z;
fs->bsize = bsize;
fs->mode = mode;
- fs->cache = vtcachealloc(z, bsize, ncache);
+ fs->cache = vtcachealloc(z, cachemem);
return fs;
}
@@ -1767,7 +1767,7 @@ readscore(int fd, uchar score[VtScoreSize])
}
VacFs*
-vacfsopen(VtConn *z, char *file, int mode, int ncache)
+vacfsopen(VtConn *z, char *file, int mode, ulong cachemem)
{
int fd;
uchar score[VtScoreSize];
@@ -1788,11 +1788,11 @@ vacfsopen(VtConn *z, char *file, int mode, int ncache)
}
close(fd);
}
- return vacfsopenscore(z, score, mode, ncache);
+ return vacfsopenscore(z, score, mode, cachemem);
}
VacFs*
-vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
+vacfsopenscore(VtConn *z, u8int *score, int mode, ulong cachemem)
{
VacFs *fs;
int n;
@@ -1818,13 +1818,19 @@ vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
return nil;
}
- fs = vacfsalloc(z, rt.blocksize, ncache, mode);
+ fs = vacfsalloc(z, rt.blocksize, cachemem, mode);
memmove(fs->score, score, VtScoreSize);
fs->mode = mode;
memmove(e.score, rt.score, VtScoreSize);
e.gen = 0;
+
+ // Don't waste cache memory on directories
+ // when rt.blocksize is large.
e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
+ if(e.psize > 60000)
+ e.psize = (60000/VtEntrySize)*VtEntrySize;
+
e.dsize = rt.blocksize;
e.type = VtDirType;
e.flags = VtEntryActive;
@@ -1925,7 +1931,7 @@ vacfsclose(VacFs *fs)
* Create a fresh vac fs.
*/
VacFs *
-vacfscreate(VtConn *z, int bsize, int ncache)
+vacfscreate(VtConn *z, int bsize, ulong cachemem)
{
VacFs *fs;
VtFile *f;
@@ -1937,18 +1943,24 @@ vacfscreate(VtConn *z, int bsize, int ncache)
MetaEntry me;
int psize;
- if((fs = vacfsalloc(z, bsize, ncache, VtORDWR)) == nil)
+ if((fs = vacfsalloc(z, bsize, cachemem, VtORDWR)) == nil)
return nil;
-
+
/*
* Fake up an empty vac fs.
*/
psize = bsize/VtEntrySize*VtEntrySize;
+ if(psize > 60000)
+ psize = 60000/VtEntrySize*VtEntrySize;
+fprint(2, "create bsize %d psize %d\n", bsize, psize);
+
f = vtfilecreateroot(fs->cache, psize, bsize, VtDirType);
+ if(f == nil)
+ sysfatal("vtfilecreateroot: %r");
vtfilelock(f, VtORDWR);
-
+
/* Write metablock containing root directory VacDir. */
- b = vtcacheallocblock(fs->cache, VtDataType);
+ b = vtcacheallocblock(fs->cache, VtDataType, bsize);
mbinit(&mb, b->data, bsize, bsize/BytesPerEntry);
memset(&vd, 0, sizeof vd);
vd.elem = "/";
diff --git a/src/cmd/vac/pack.c b/src/cmd/vac/pack.c
index 9777464f..5555cc0e 100644
--- a/src/cmd/vac/pack.c
+++ b/src/cmd/vac/pack.c
@@ -77,7 +77,7 @@ mbunpack(MetaBlock *mb, uchar *p, int n)
magic = U32GET(p);
if(magic != MetaMagic && magic != MetaMagic+1) {
- werrstr("bad meta block magic");
+ werrstr("bad meta block magic %#08ux", magic);
return -1;
}
mb->size = U16GET(p+4);
diff --git a/src/cmd/vac/unvac.c b/src/cmd/vac/unvac.c
index ab799cb0..8b2b290d 100644
--- a/src/cmd/vac/unvac.c
+++ b/src/cmd/vac/unvac.c
@@ -94,7 +94,7 @@ threadmain(int argc, char *argv[])
if(vtconnect(conn) < 0)
sysfatal("vtconnect: %r");
- fs = vacfsopen(conn, argv[0], VtOREAD, 128);
+ fs = vacfsopen(conn, argv[0], VtOREAD, 4<<20);
if(fs == nil)
sysfatal("vacfsopen: %r");
diff --git a/src/cmd/vac/vac.c b/src/cmd/vac/vac.c
index d6c17b4b..bf5118b4 100644
--- a/src/cmd/vac/vac.c
+++ b/src/cmd/vac/vac.c
@@ -100,8 +100,6 @@ threadmain(int argc, char **argv)
u = unittoull(EARGF(usage()));
if(u < 512)
u = 512;
- if(u > VtMaxLumpSize)
- u = VtMaxLumpSize;
blocksize = u;
break;
case 'd':
@@ -170,10 +168,10 @@ threadmain(int argc, char **argv)
if((outfd = create(archivefile, OWRITE, 0666)) < 0)
sysfatal("create %s: %r", archivefile);
atexit(removevacfile); // because it is new
- if((fs = vacfscreate(z, blocksize, 512)) == nil)
+ if((fs = vacfscreate(z, blocksize, 4<<20)) == nil)
sysfatal("vacfscreate: %r");
}else{
- if((fs = vacfsopen(z, archivefile, VtORDWR, 512)) == nil)
+ if((fs = vacfsopen(z, archivefile, VtORDWR, 4<<20)) == nil)
sysfatal("vacfsopen %s: %r", archivefile);
if((fdiff = recentarchive(fs, oldpath)) != nil){
if(verbose)
@@ -213,7 +211,7 @@ threadmain(int argc, char **argv)
else if((outfd = create(vacfile, OWRITE, 0666)) < 0)
sysfatal("create %s: %r", vacfile);
atexit(removevacfile);
- if((fs = vacfscreate(z, blocksize, 512)) == nil)
+ if((fs = vacfscreate(z, blocksize, 4<<20)) == nil)
sysfatal("vacfscreate: %r");
f = vacfsgetroot(fs);
@@ -450,7 +448,7 @@ void
vac(VacFile *fp, VacFile *diffp, char *name, Dir *d)
{
char *elem, *s;
- static char buf[65536];
+ static char *buf;
int fd, i, n, bsize;
vlong off;
Dir *dk; // kids
@@ -541,6 +539,8 @@ vac(VacFile *fp, VacFile *diffp, char *name, Dir *d)
}else{
off = 0;
bsize = fs->bsize;
+ if(buf == nil)
+ buf = vtmallocz(bsize);
if(fdiff){
/*
* Copy fdiff's contents into f by moving the score.
@@ -708,7 +708,7 @@ vacmerge(VacFile *fp, char *name)
if(strlen(name) < 4 || strcmp(name+strlen(name)-4, ".vac") != 0)
return -1;
- if((mfs = vacfsopen(z, name, VtOREAD, 100)) == nil)
+ if((mfs = vacfsopen(z, name, VtOREAD, 4<<20)) == nil)
return -1;
if(verbose)
fprint(2, "merging %s\n", name);
diff --git a/src/cmd/vac/vac.h b/src/cmd/vac/vac.h
index cb599a9c..0edd41e4 100644
--- a/src/cmd/vac/vac.h
+++ b/src/cmd/vac/vac.h
@@ -97,9 +97,9 @@ struct VacFs
VtCache *cache;
};
-VacFs *vacfsopen(VtConn *z, char *file, int mode, int ncache);
-VacFs *vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache);
-VacFs *vacfscreate(VtConn *z, int bsize, int ncache);
+VacFs *vacfsopen(VtConn *z, char *file, int mode, ulong cachemem);
+VacFs *vacfsopenscore(VtConn *z, u8int *score, int mode, ulong cachemem);
+VacFs *vacfscreate(VtConn *z, int bsize, ulong cachemem);
void vacfsclose(VacFs *fs);
int vacfssync(VacFs *fs);
int vacfssnapshot(VacFs *fs, char *src, char *dst);
diff --git a/src/cmd/vac/vacfs.c b/src/cmd/vac/vacfs.c
index 5c65cf3b..ad72098f 100644
--- a/src/cmd/vac/vacfs.c
+++ b/src/cmd/vac/vacfs.c
@@ -118,6 +118,31 @@ notifyf(void *a, char *s)
noted(NDFLT);
}
+#define TWID64 ~(u64int)0
+static u64int
+unittoull(char *s)
+{
+ char *es;
+ u64int n;
+
+ if(s == nil)
+ return TWID64;
+ n = strtoul(s, &es, 0);
+ if(*es == 'k' || *es == 'K'){
+ n *= 1024;
+ es++;
+ }else if(*es == 'm' || *es == 'M'){
+ n *= 1024*1024;
+ es++;
+ }else if(*es == 'g' || *es == 'G'){
+ n *= 1024*1024*1024;
+ es++;
+ }
+ if(*es != '\0')
+ return TWID64;
+ return n;
+}
+
void
threadmain(int argc, char *argv[])
{
@@ -125,10 +150,10 @@ threadmain(int argc, char *argv[])
int p[2], fd;
int stdio;
char *host = nil;
- long ncache;
+ ulong mem;
+ mem = 16<<20;
stdio = 0;
- ncache = 256;
fmtinstall('H', encodefmt);
fmtinstall('V', vtscorefmt);
fmtinstall('F', vtfcallfmt);
@@ -140,9 +165,6 @@ threadmain(int argc, char *argv[])
fmtinstall('F', fcallfmt);
dflag = 1;
break;
- case 'c':
- ncache = atoi(EARGF(usage()));
- break;
case 'i':
defmnt = nil;
stdio = 1;
@@ -158,6 +180,9 @@ threadmain(int argc, char *argv[])
case 's':
defsrv = "vacfs";
break;
+ case 'M':
+ mem = unittoull(EARGF(usage()));
+ break;
case 'm':
defmnt = EARGF(usage());
break;
@@ -206,7 +231,7 @@ threadmain(int argc, char *argv[])
if(vtconnect(conn) < 0)
sysfatal("vtconnect: %r");
- fs = vacfsopen(conn, argv[0], VtOREAD, ncache);
+ fs = vacfsopen(conn, argv[0], VtOREAD, mem);
if(fs == nil)
sysfatal("vacfsopen: %r");