aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2013-09-23 23:16:25 +0200
committerDavid du Colombier <0intro@gmail.com>2013-09-23 23:16:25 +0200
commit4b5766580559d101dd1c29cc575b3ffa9f51c2d7 (patch)
treef35364a39e255b1336482ee30217d68279ba8699 /src/cmd/fossil
parent6f4d00ee45693290fae042b27536b54f77b96acd (diff)
downloadplan9port-4b5766580559d101dd1c29cc575b3ffa9f51c2d7.tar.gz
plan9port-4b5766580559d101dd1c29cc575b3ffa9f51c2d7.tar.bz2
plan9port-4b5766580559d101dd1c29cc575b3ffa9f51c2d7.zip
fossil: move from liboventi to libthread and libventi
R=rsc https://codereview.appspot.com/13504049
Diffstat (limited to 'src/cmd/fossil')
-rw-r--r--src/cmd/fossil/9.h20
-rw-r--r--src/cmd/fossil/9auth.c56
-rw-r--r--src/cmd/fossil/9dir.c12
-rw-r--r--src/cmd/fossil/9excl.c27
-rw-r--r--src/cmd/fossil/9fid.c65
-rw-r--r--src/cmd/fossil/9fsys.c333
-rw-r--r--src/cmd/fossil/9lstn.c44
-rw-r--r--src/cmd/fossil/9p.c182
-rw-r--r--src/cmd/fossil/9ping.c1
-rw-r--r--src/cmd/fossil/9proc.c215
-rw-r--r--src/cmd/fossil/9srv.c52
-rw-r--r--src/cmd/fossil/9user.c203
-rw-r--r--src/cmd/fossil/Ccli.c33
-rw-r--r--src/cmd/fossil/Ccmd.c43
-rw-r--r--src/cmd/fossil/Ccons.c107
-rw-r--r--src/cmd/fossil/archive.c119
-rw-r--r--src/cmd/fossil/bwatch.c19
-rw-r--r--src/cmd/fossil/cache.c324
-rw-r--r--src/cmd/fossil/check.c64
-rw-r--r--src/cmd/fossil/dat.h11
-rw-r--r--src/cmd/fossil/disk.c100
-rw-r--r--src/cmd/fossil/epoch.c6
-rw-r--r--src/cmd/fossil/file.c132
-rw-r--r--src/cmd/fossil/flchk.c21
-rw-r--r--src/cmd/fossil/flfmt.c96
-rw-r--r--src/cmd/fossil/flfmt9660.c64
-rw-r--r--src/cmd/fossil/fns.h6
-rw-r--r--src/cmd/fossil/fossil.c21
-rw-r--r--src/cmd/fossil/fs.c157
-rw-r--r--src/cmd/fossil/fs.h13
-rw-r--r--src/cmd/fossil/mkfile4
-rw-r--r--src/cmd/fossil/pack.c16
-rw-r--r--src/cmd/fossil/periodic.c22
-rw-r--r--src/cmd/fossil/source.c60
-rw-r--r--src/cmd/fossil/stdinc.h5
-rw-r--r--src/cmd/fossil/vac.c38
-rw-r--r--src/cmd/fossil/view.c91
-rw-r--r--src/cmd/fossil/walk.c2
38 files changed, 1360 insertions, 1424 deletions
diff --git a/src/cmd/fossil/9.h b/src/cmd/fossil/9.h
index b7bdec26..d25d151f 100644
--- a/src/cmd/fossil/9.h
+++ b/src/cmd/fossil/9.h
@@ -57,31 +57,31 @@ struct Con {
int isconsole; /* immutable */
int flags; /* immutable */
char remote[128]; /* immutable */
- VtLock* lock;
+ QLock lock;
int state;
int fd;
Msg* version;
u32int msize; /* negotiated with Tversion */
- VtRendez* rendez;
+ Rendez rendez;
Con* anext; /* alloc */
Con* cnext; /* in use */
Con* cprev;
- VtLock* alock;
+ RWLock alock;
int aok; /* authentication done */
- VtLock* mlock;
+ QLock mlock;
Msg* mhead; /* all Msgs on this connection */
Msg* mtail;
- VtRendez* mrendez;
+ Rendez mrendez;
- VtLock* wlock;
+ QLock wlock;
Msg* whead; /* write queue */
Msg* wtail;
- VtRendez* wrendez;
+ Rendez wrendez;
- VtLock* fidlock; /* */
+ QLock fidlock; /* */
Fid* fidhash[NFidHash];
Fid* fhead;
Fid* ftail;
@@ -98,7 +98,7 @@ enum {
};
struct Fid {
- VtLock* lock;
+ RWLock lock;
Con* con;
u32int fidno;
int ref; /* inc/dec under Con.fidlock */
@@ -113,7 +113,7 @@ struct Fid {
DirBuf* db;
Excl* excl;
- VtLock* alock; /* Tauth/Tattach */
+ QLock alock; /* Tauth/Tattach */
AuthRpc* rpc;
char* cuname;
diff --git a/src/cmd/fossil/9auth.c b/src/cmd/fossil/9auth.c
index 72b1f016..2926f91e 100644
--- a/src/cmd/fossil/9auth.c
+++ b/src/cmd/fossil/9auth.c
@@ -8,44 +8,44 @@ authRead(Fid* afid, void* data, int count)
AuthRpc *rpc;
if((rpc = afid->rpc) == nil){
- vtSetError("not an auth fid");
+ werrstr("not an auth fid");
return -1;
}
switch(auth_rpc(rpc, "read", nil, 0)){
default:
- vtSetError("fossil authRead: auth protocol not finished");
+ werrstr("fossil authRead: auth protocol not finished");
return -1;
case ARdone:
if((ai = auth_getinfo(rpc)) == nil){
- vtSetError("%r");
+ werrstr("%r");
break;
}
if(ai->cuid == nil || *ai->cuid == '\0'){
- vtSetError("auth with no cuid");
+ werrstr("auth with no cuid");
auth_freeAI(ai);
break;
}
assert(afid->cuname == nil);
- afid->cuname = vtStrDup(ai->cuid);
+ afid->cuname = vtstrdup(ai->cuid);
auth_freeAI(ai);
if(Dflag)
fprint(2, "authRead cuname %s\n", afid->cuname);
assert(afid->uid == nil);
if((afid->uid = uidByUname(afid->cuname)) == nil){
- vtSetError("unknown user %#q", afid->cuname);
+ werrstr("unknown user %#q", afid->cuname);
break;
}
return 0;
case ARok:
if(count < rpc->narg){
- vtSetError("not enough data in auth read");
+ werrstr("not enough data in auth read");
break;
}
memmove(data, rpc->arg, rpc->narg);
return rpc->narg;
case ARphase:
- vtSetError("%r");
+ werrstr("%r");
break;
}
return -1;
@@ -82,7 +82,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
* The console is allowed to attach without
* authentication.
*/
- vtRLock(con->alock);
+ rlock(&con->alock);
if(con->isconsole){
/* anything goes */
}else if((con->flags&ConNoneAllow) || con->aok){
@@ -91,21 +91,21 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
if(noneprint++ < 10)
consPrint("attach %s as %s: allowing as none\n",
fsysGetName(fsys), fid->uname);
- vtMemFree(fid->uname);
- fid->uname = vtStrDup(unamenone);
+ vtfree(fid->uname);
+ fid->uname = vtstrdup(unamenone);
}else{
- vtRUnlock(con->alock);
+ runlock(&con->alock);
consPrint("attach %s as %s: connection not authenticated, not console\n",
fsysGetName(fsys), fid->uname);
- vtSetError("cannot attach as none before authentication");
+ werrstr("cannot attach as none before authentication");
return 0;
}
- vtRUnlock(con->alock);
+ runlock(&con->alock);
if((fid->uid = uidByUname(fid->uname)) == nil){
consPrint("attach %s as %s: unknown uname\n",
fsysGetName(fsys), fid->uname);
- vtSetError("unknown user");
+ werrstr("unknown user");
return 0;
}
return 1;
@@ -114,7 +114,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
if((afid = fidGet(con, t->afid, 0)) == nil){
consPrint("attach %s as %s: bad afid\n",
fsysGetName(fsys), fid->uname);
- vtSetError("bad authentication fid");
+ werrstr("bad authentication fid");
return 0;
}
@@ -126,7 +126,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
consPrint("attach %s as %s: afid not an auth file\n",
fsysGetName(fsys), fid->uname);
fidPut(afid);
- vtSetError("bad authentication fid");
+ werrstr("bad authentication fid");
return 0;
}
if(strcmp(afid->uname, fid->uname) != 0 || afid->fsys != fsys){
@@ -134,42 +134,42 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
fsysGetName(fsys), fid->uname,
fsysGetName(afid->fsys), afid->uname);
fidPut(afid);
- vtSetError("attach/auth mismatch");
+ werrstr("attach/auth mismatch");
return 0;
}
- vtLock(afid->alock);
+ qlock(&afid->alock);
if(afid->cuname == nil){
if(authRead(afid, buf, 0) != 0 || afid->cuname == nil){
- vtUnlock(afid->alock);
- consPrint("attach %s as %s: %R\n",
+ qunlock(&afid->alock);
+ consPrint("attach %s as %s: %r\n",
fsysGetName(fsys), fid->uname);
fidPut(afid);
- vtSetError("fossil authCheck: auth protocol not finished");
+ werrstr("fossil authCheck: auth protocol not finished");
return 0;
}
}
- vtUnlock(afid->alock);
+ qunlock(&afid->alock);
assert(fid->uid == nil);
if((fid->uid = uidByUname(afid->cuname)) == nil){
consPrint("attach %s as %s: unknown cuname %s\n",
fsysGetName(fsys), fid->uname, afid->cuname);
fidPut(afid);
- vtSetError("unknown user");
+ werrstr("unknown user");
return 0;
}
- vtMemFree(fid->uname);
- fid->uname = vtStrDup(afid->cuname);
+ vtfree(fid->uname);
+ fid->uname = vtstrdup(afid->cuname);
fidPut(afid);
/*
* Allow "none" once the connection has been authenticated.
*/
- vtLock(con->alock);
+ wlock(&con->alock);
con->aok = 1;
- vtUnlock(con->alock);
+ wunlock(&con->alock);
return 1;
}
diff --git a/src/cmd/fossil/9dir.c b/src/cmd/fossil/9dir.c
index 09b483bd..fdba20d0 100644
--- a/src/cmd/fossil/9dir.c
+++ b/src/cmd/fossil/9dir.c
@@ -14,11 +14,11 @@ dirBufAlloc(File* file)
{
DirBuf *db;
- db = vtMemAllocZ(sizeof(DirBuf));
+ db = vtmallocz(sizeof(DirBuf));
db->dee = deeOpen(file);
if(db->dee == nil){
/* can happen if dir is removed from under us */
- vtMemFree(db);
+ vtfree(db);
return nil;
}
return db;
@@ -33,7 +33,7 @@ dirBufFree(DirBuf* db)
if(db->valid)
deCleanup(&db->de);
deeClose(db->dee);
- vtMemFree(db);
+ vtfree(db);
}
int
@@ -82,9 +82,9 @@ dirDe2M(DirEntry* de, uchar* p, int np)
n = convD2M(&dir, p, np);
- vtMemFree(dir.muid);
- vtMemFree(dir.gid);
- vtMemFree(dir.uid);
+ vtfree(dir.muid);
+ vtfree(dir.gid);
+ vtfree(dir.uid);
return n;
}
diff --git a/src/cmd/fossil/9excl.c b/src/cmd/fossil/9excl.c
index 6fce280a..9cefe58f 100644
--- a/src/cmd/fossil/9excl.c
+++ b/src/cmd/fossil/9excl.c
@@ -3,7 +3,7 @@
#include "9.h"
static struct {
- VtLock* lock;
+ QLock lock;
Excl* head;
Excl* tail;
@@ -31,7 +31,7 @@ exclAlloc(Fid* fid)
assert(fid->excl == nil);
t = time(0L);
- vtLock(ebox.lock);
+ qlock(&ebox.lock);
for(excl = ebox.head; excl != nil; excl = excl->next){
if(excl->fsys != fid->fsys || excl->path != fid->qid.path)
continue;
@@ -44,8 +44,8 @@ exclAlloc(Fid* fid)
* a new one.
*/
if(excl->time >= t){
- vtUnlock(ebox.lock);
- vtSetError("exclusive lock");
+ qunlock(&ebox.lock);
+ werrstr("exclusive lock");
return 0;
}
excl->fsys = nil;
@@ -55,7 +55,7 @@ exclAlloc(Fid* fid)
* Not found or timed-out.
* Alloc a new one and initialise.
*/
- excl = vtMemAllocZ(sizeof(Excl));
+ excl = vtmallocz(sizeof(Excl));
excl->fsys = fid->fsys;
excl->path = fid->qid.path;
excl->time = t+LifeTime;
@@ -69,7 +69,7 @@ exclAlloc(Fid* fid)
}
ebox.tail = excl;
excl->next = nil;
- vtUnlock(ebox.lock);
+ qunlock(&ebox.lock);
fid->excl = excl;
return 1;
@@ -84,14 +84,14 @@ exclUpdate(Fid* fid)
excl = fid->excl;
t = time(0L);
- vtLock(ebox.lock);
+ qlock(&ebox.lock);
if(excl->time < t || excl->fsys != fid->fsys){
- vtUnlock(ebox.lock);
- vtSetError("exclusive lock broken");
+ qunlock(&ebox.lock);
+ werrstr("exclusive lock broken");
return 0;
}
excl->time = t+LifeTime;
- vtUnlock(ebox.lock);
+ qunlock(&ebox.lock);
return 1;
}
@@ -105,7 +105,7 @@ exclFree(Fid* fid)
return;
fid->excl = nil;
- vtLock(ebox.lock);
+ qlock(&ebox.lock);
if(excl->prev != nil)
excl->prev->next = excl->next;
else
@@ -114,13 +114,12 @@ exclFree(Fid* fid)
excl->next->prev = excl->prev;
else
ebox.tail = excl->prev;
- vtUnlock(ebox.lock);
+ qunlock(&ebox.lock);
- vtMemFree(excl);
+ vtfree(excl);
}
void
exclInit(void)
{
- ebox.lock = vtLockAlloc();
}
diff --git a/src/cmd/fossil/9fid.c b/src/cmd/fossil/9fid.c
index ea7de5ab..49fab0b9 100644
--- a/src/cmd/fossil/9fid.c
+++ b/src/cmd/fossil/9fid.c
@@ -3,7 +3,7 @@
#include "9.h"
static struct {
- VtLock* lock;
+ QLock lock;
Fid* free;
int nfree;
@@ -14,11 +14,11 @@ static void
fidLock(Fid* fid, int flags)
{
if(flags & FidFWlock){
- vtLock(fid->lock);
+ wlock(&fid->lock);
fid->flags = flags;
}
else
- vtRLock(fid->lock);
+ rlock(&fid->lock);
/*
* Callers of file* routines are expected to lock fsys->fs->elk
@@ -47,10 +47,10 @@ fidUnlock(Fid* fid)
fsysFsRUnlock(fid->fsys);
if(fid->flags & FidFWlock){
fid->flags = 0;
- vtUnlock(fid->lock);
+ wunlock(&fid->lock);
return;
}
- vtRUnlock(fid->lock);
+ runlock(&fid->lock);
}
static Fid*
@@ -58,19 +58,17 @@ fidAlloc(void)
{
Fid *fid;
- vtLock(fbox.lock);
+ qlock(&fbox.lock);
if(fbox.nfree > 0){
fid = fbox.free;
fbox.free = fid->hash;
fbox.nfree--;
}
else{
- fid = vtMemAllocZ(sizeof(Fid));
- fid->lock = vtLockAlloc();
- fid->alock = vtLockAlloc();
+ fid = vtmallocz(sizeof(Fid));
}
fbox.inuse++;
- vtUnlock(fbox.lock);
+ qunlock(&fbox.lock);
fid->con = nil;
fid->fidno = NOFID;
@@ -105,11 +103,11 @@ fidFree(Fid* fid)
fidUnlock(fid);
if(fid->uid != nil){
- vtMemFree(fid->uid);
+ vtfree(fid->uid);
fid->uid = nil;
}
if(fid->uname != nil){
- vtMemFree(fid->uname);
+ vtfree(fid->uname);
fid->uname = nil;
}
if(fid->excl != nil)
@@ -124,11 +122,11 @@ fidFree(Fid* fid)
fid->fsys = nil;
}
if(fid->cuname != nil){
- vtMemFree(fid->cuname);
+ vtfree(fid->cuname);
fid->cuname = nil;
}
- vtLock(fbox.lock);
+ qlock(&fbox.lock);
fbox.inuse--;
if(fbox.nfree < 10){
fid->hash = fbox.free;
@@ -136,11 +134,9 @@ fidFree(Fid* fid)
fbox.nfree++;
}
else{
- vtLockFree(fid->alock);
- vtLockFree(fid->lock);
- vtMemFree(fid);
+ vtfree(fid);
}
- vtUnlock(fbox.lock);
+ qunlock(&fbox.lock);
}
static void
@@ -182,7 +178,7 @@ fidGet(Con* con, u32int fidno, int flags)
return nil;
hash = &con->fidhash[fidno % NFidHash];
- vtLock(con->fidlock);
+ qlock(&con->fidlock);
for(fid = *hash; fid != nil; fid = fid->hash){
if(fid->fidno != fidno)
continue;
@@ -192,17 +188,17 @@ fidGet(Con* con, u32int fidno, int flags)
* when called from attach, clone or walk.
*/
if(flags & FidFCreate){
- vtUnlock(con->fidlock);
- vtSetError("%s: fid 0x%ud in use", argv0, fidno);
+ qunlock(&con->fidlock);
+ werrstr("%s: fid 0x%ud in use", argv0, fidno);
return nil;
}
fid->ref++;
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
fidLock(fid, flags);
if((fid->open & FidOCreate) || fid->fidno == NOFID){
fidPut(fid);
- vtSetError("%s: fid invalid", argv0);
+ werrstr("%s: fid invalid", argv0);
return nil;
}
return fid;
@@ -228,7 +224,7 @@ fidGet(Con* con, u32int fidno, int flags)
fid->next = nil;
con->nfid++;
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
/*
* The FidOCreate flag is used to prevent any
@@ -239,19 +235,19 @@ fidGet(Con* con, u32int fidno, int flags)
fid->open &= ~FidOCreate;
return fid;
}
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
- vtSetError("%s: fid not found", argv0);
+ werrstr("%s: fid not found", argv0);
return nil;
}
void
fidPut(Fid* fid)
{
- vtLock(fid->con->fidlock);
+ qlock(&fid->con->fidlock);
assert(fid->ref > 0);
fid->ref--;
- vtUnlock(fid->con->fidlock);
+ qunlock(&fid->con->fidlock);
if(fid->ref == 0 && fid->fidno == NOFID){
fidFree(fid);
@@ -265,12 +261,12 @@ fidClunk(Fid* fid)
{
assert(fid->flags & FidFWlock);
- vtLock(fid->con->fidlock);
+ qlock(&fid->con->fidlock);
assert(fid->ref > 0);
fid->ref--;
fidUnHash(fid);
fid->fidno = NOFID;
- vtUnlock(fid->con->fidlock);
+ qunlock(&fid->con->fidlock);
if(fid->ref > 0){
/* not reached - fidUnHash requires ref == 0 */
@@ -286,19 +282,18 @@ fidClunkAll(Con* con)
Fid *fid;
u32int fidno;
- vtLock(con->fidlock);
+ qlock(&con->fidlock);
while(con->fhead != nil){
fidno = con->fhead->fidno;
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
if((fid = fidGet(con, fidno, FidFWlock)) != nil)
fidClunk(fid);
- vtLock(con->fidlock);
+ qlock(&con->fidlock);
}
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
}
void
fidInit(void)
{
- fbox.lock = vtLockAlloc();
}
diff --git a/src/cmd/fossil/9fsys.c b/src/cmd/fossil/9fsys.c
index 4e139f70..ac724251 100644
--- a/src/cmd/fossil/9fsys.c
+++ b/src/cmd/fossil/9fsys.c
@@ -5,14 +5,14 @@
#include "9.h"
struct Fsys {
- VtLock* lock;
+ QLock lock;
char* name; /* copy here & Fs to ease error reporting */
char* dev;
char* venti;
Fs* fs;
- VtSession* session;
+ VtConn* session;
int ref;
int noauth;
@@ -27,7 +27,7 @@ int mempcnt; /* from fossil.c */
int fsGetBlockSize(Fs *fs);
static struct {
- VtLock* lock;
+ RWLock lock;
Fsys* head;
Fsys* tail;
@@ -49,10 +49,10 @@ static char *
ventihost(char *host)
{
if(host != nil)
- return vtStrDup(host);
+ return vtstrdup(host);
host = getenv("venti");
if(host == nil)
- host = vtStrDup("$venti");
+ host = vtstrdup("$venti");
return host;
}
@@ -67,18 +67,18 @@ prventihost(char *host)
free(vh);
}
-static VtSession *
-myDial(char *host, int canfail)
+static VtConn *
+myDial(char *host)
{
prventihost(host);
- return vtDial(host, canfail);
+ return vtdial(host);
}
static int
-myRedial(VtSession *z, char *host)
+myRedial(VtConn *z, char *host)
{
prventihost(host);
- return vtRedial(z, host);
+ return vtredial(z, host);
}
static Fsys*
@@ -89,16 +89,16 @@ _fsysGet(char* name)
if(name == nil || name[0] == '\0')
name = "main";
- vtRLock(sbox.lock);
+ rlock(&sbox.lock);
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
if(strcmp(name, fsys->name) == 0){
fsys->ref++;
break;
}
}
- vtRUnlock(sbox.lock);
+ runlock(&sbox.lock);
if(fsys == nil)
- vtSetError(EFsysNotFound, name);
+ werrstr(EFsysNotFound, name);
return fsys;
}
@@ -116,14 +116,14 @@ cmdPrintConfig(int argc, char* argv[])
if(argc)
return cliError(usage);
- vtRLock(sbox.lock);
+ rlock(&sbox.lock);
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
consPrint("\tfsys %s config %s\n", fsys->name, fsys->dev);
if(fsys->venti && fsys->venti[0])
consPrint("\tfsys %s venti %q\n", fsys->name,
fsys->venti);
}
- vtRUnlock(sbox.lock);
+ runlock(&sbox.lock);
return 1;
}
@@ -135,14 +135,14 @@ fsysGet(char* name)
if((fsys = _fsysGet(name)) == nil)
return nil;
- vtLock(fsys->lock);
+ qlock(&fsys->lock);
if(fsys->fs == nil){
- vtSetError(EFsysNotOpen, fsys->name);
- vtUnlock(fsys->lock);
+ werrstr(EFsysNotOpen, fsys->name);
+ qunlock(&fsys->lock);
fsysPut(fsys);
return nil;
}
- vtUnlock(fsys->lock);
+ qunlock(&fsys->lock);
return fsys;
}
@@ -156,9 +156,9 @@ fsysGetName(Fsys* fsys)
Fsys*
fsysIncRef(Fsys* fsys)
{
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
fsys->ref++;
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
return fsys;
}
@@ -166,10 +166,10 @@ fsysIncRef(Fsys* fsys)
void
fsysPut(Fsys* fsys)
{
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
assert(fsys->ref > 0);
fsys->ref--;
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
}
Fs*
@@ -183,13 +183,13 @@ fsysGetFs(Fsys* fsys)
void
fsysFsRlock(Fsys* fsys)
{
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
}
void
fsysFsRUnlock(Fsys* fsys)
{
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
}
int
@@ -285,19 +285,18 @@ fsysAlloc(char* name, char* dev)
{
Fsys *fsys;
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
if(strcmp(fsys->name, name) != 0)
continue;
- vtSetError(EFsysExists, name);
- vtUnlock(sbox.lock);
+ werrstr(EFsysExists, name);
+ wunlock(&sbox.lock);
return nil;
}
- fsys = vtMemAllocZ(sizeof(Fsys));
- fsys->lock = vtLockAlloc();
- fsys->name = vtStrDup(name);
- fsys->dev = vtStrDup(dev);
+ fsys = vtmallocz(sizeof(Fsys));
+ fsys->name = vtstrdup(name);
+ fsys->dev = vtstrdup(dev);
fsys->ref = 1;
@@ -306,7 +305,7 @@ fsysAlloc(char* name, char* dev)
else
sbox.head = fsys;
sbox.tail = fsys;
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
return fsys;
}
@@ -334,7 +333,7 @@ fsysClose(Fsys* fsys, int argc, char* argv[])
* More thought and care needed here.
fsClose(fsys->fs);
fsys->fs = nil;
- vtClose(fsys->session);
+ vtfreeconn(fsys->session);
fsys->session = nil;
if(sbox.curfsys != nil && strcmp(fsys->name, sbox.curfsys) == 0){
@@ -566,19 +565,19 @@ fsysRemove(Fsys* fsys, int argc, char* argv[])
if(argc == 0)
return cliError(usage);
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
while(argc > 0){
if((file = fileOpen(fsys->fs, argv[0])) == nil)
- consPrint("%s: %R\n", argv[0]);
+ consPrint("%s: %r\n", argv[0]);
else{
if(!fileRemove(file, uidadm))
- consPrint("%s: %R\n", argv[0]);
+ consPrint("%s: %r\n", argv[0]);
fileDecRef(file);
}
argc--;
argv++;
}
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 1;
}
@@ -595,14 +594,14 @@ fsysClri(Fsys* fsys, int argc, char* argv[])
if(argc == 0)
return cliError(usage);
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
while(argc > 0){
if(!fileClriPath(fsys->fs, argv[0], uidadm))
- consPrint("clri %s: %R\n", argv[0]);
+ consPrint("clri %s: %r\n", argv[0]);
argc--;
argv++;
}
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 1;
}
@@ -628,7 +627,7 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
return cliError(usage);
r = 0;
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
fs = fsys->fs;
addr = strtoul(argv[0], 0, 0);
@@ -663,11 +662,11 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
if(blockWrite(bb, Waitlock)){
while(bb->iostate != BioClean){
assert(bb->iostate == BioWriting);
- vtSleep(bb->ioready);
+ rsleep(&bb->ioready);
}
break;
}
- consPrint("blockWrite: %R\n");
+ consPrint("blockWrite: %r\n");
if(n++ >= 5){
consPrint("giving up\n");
break;
@@ -680,7 +679,7 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
Out1:
blockPut(b);
Out0:
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return r;
}
@@ -710,7 +709,7 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
addr = strtoul(argv[0], 0, 0);
offset = strtoul(argv[1], 0, 0);
if(offset < 0 || offset >= fs->blockSize){
- vtSetError("bad offset");
+ werrstr("bad offset");
return 0;
}
if(argc > 2)
@@ -720,12 +719,12 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
if(offset+count > fs->blockSize)
count = fs->blockSize - count;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
if(b == nil){
- vtSetError("cacheLocal %#ux: %R", addr);
- vtRUnlock(fs->elk);
+ werrstr("cacheLocal %#ux: %r", addr);
+ runlock(&fs->elk);
return 0;
}
@@ -735,10 +734,10 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
if(argc == 4){
s = argv[3];
if(strlen(s) != 2*count){
- vtSetError("bad data count");
+ werrstr("bad data count");
goto Out;
}
- buf = vtMemAllocZ(count);
+ buf = vtmallocz(count);
for(i = 0; i < count*2; i++){
if(s[i] >= '0' && s[i] <= '9')
c = s[i] - '0';
@@ -747,8 +746,8 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
else if(s[i] >= 'A' && s[i] <= 'F')
c = s[i] - 'A' + 10;
else{
- vtSetError("bad hex");
- vtMemFree(buf);
+ werrstr("bad hex");
+ vtfree(buf);
goto Out;
}
if((i & 1) == 0)
@@ -763,7 +762,7 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
Out:
blockPut(b);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 1;
}
@@ -789,18 +788,18 @@ fsysBfree(Fsys* fsys, int argc, char* argv[])
return cliError(usage);
fs = fsys->fs;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
while(argc > 0){
addr = strtoul(argv[0], &p, 0);
if(*p != '\0'){
consPrint("bad address - '%ud'\n", addr);
/* syntax error; let's stop */
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 0;
}
b = cacheLocal(fs->cache, PartData, addr, OReadOnly);
if(b == nil){
- consPrint("loading %#ux: %R\n", addr);
+ consPrint("loading %#ux: %r\n", addr);
continue;
}
l = b->l;
@@ -815,13 +814,13 @@ fsysBfree(Fsys* fsys, int argc, char* argv[])
l.epoch = 0;
l.epochClose = 0;
if(!blockSetLabel(b, &l, 0))
- consPrint("freeing %#ux: %R\n", addr);
+ consPrint("freeing %#ux: %r\n", addr);
}
blockPut(b);
argc--;
argv++;
}
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 1;
}
@@ -870,24 +869,24 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
return cliError(usage, ch);
fs = fsys->fs;
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
addr = strtoul(argv[0], 0, 0);
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
if(b == nil){
- vtSetError("cacheLocal %#ux: %R", addr);
+ werrstr("cacheLocal %#ux: %r", addr);
Err:
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 0;
}
switch(ch){
default:
- vtSetError("clrep");
+ werrstr("clrep");
goto Err;
case 'e':
if(b->l.type != BtDir){
- vtSetError("wrong block type");
+ werrstr("wrong block type");
goto Err;
}
sz = VtEntrySize;
@@ -896,11 +895,11 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
break;
case 'p':
if(b->l.type == BtDir || b->l.type == BtData){
- vtSetError("wrong block type");
+ werrstr("wrong block type");
goto Err;
}
sz = VtScoreSize;
- memmove(zero, vtZeroScore, VtScoreSize);
+ memmove(zero, vtzeroscore, VtScoreSize);
break;
}
max = fs->blockSize/sz;
@@ -916,7 +915,7 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
}
blockDirty(b);
blockPut(b);
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 1;
}
@@ -951,17 +950,17 @@ fsysEsearch1(File* f, char* s, u32int elo)
for(;;){
r = deeRead(dee, &de);
if(r < 0){
- consPrint("\tdeeRead %s/%s: %R\n", s, de.elem);
+ consPrint("\tdeeRead %s/%s: %r\n", s, de.elem);
break;
}
if(r == 0)
break;
if(de.mode & ModeSnapshot){
if((ff = fileWalk(f, de.elem)) == nil)
- consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
+ consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
else{
if(!fileGetSources(ff, &e, &ee))
- consPrint("\tcannot get sources for %s/%s: %R\n", s, de.elem);
+ consPrint("\tcannot get sources for %s/%s: %r\n", s, de.elem);
else if(e.snap != 0 && e.snap < elo){
consPrint("\t%ud\tclri %s/%s\n", e.snap, s, de.elem);
n++;
@@ -971,11 +970,11 @@ fsysEsearch1(File* f, char* s, u32int elo)
}
else if(de.mode & ModeDir){
if((ff = fileWalk(f, de.elem)) == nil)
- consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
+ consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
else{
t = smprint("%s/%s", s, de.elem);
n += fsysEsearch1(ff, t, elo);
- vtMemFree(t);
+ vtfree(t);
fileDecRef(ff);
}
}
@@ -999,7 +998,7 @@ fsysEsearch(Fs* fs, char* path, u32int elo)
if(f == nil)
return 0;
if(!fileGetDir(f, &de)){
- consPrint("\tfileGetDir %s failed: %R\n", path);
+ consPrint("\tfileGetDir %s failed: %r\n", path);
fileDecRef(f);
return 0;
}
@@ -1046,16 +1045,16 @@ fsysEpoch(Fsys* fsys, int argc, char* argv[])
fs = fsys->fs;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
consPrint("\tlow %ud hi %ud\n", fs->elo, fs->ehi);
if(low == ~(u32int)0){
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 1;
}
n = fsysEsearch(fsys->fs, "/archive", low);
n += fsysEsearch(fsys->fs, "/snapshot", low);
consPrint("\t%d snapshot%s found with epoch < %ud\n", n, n==1 ? "" : "s", low);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
/*
* There's a small race here -- a new snapshot with epoch < low might
@@ -1070,7 +1069,7 @@ fsysEpoch(Fsys* fsys, int argc, char* argv[])
}
old = fs->elo;
if(!fsEpochLow(fs, low))
- consPrint("\tfsEpochLow: %R\n");
+ consPrint("\tfsEpochLow: %r\n");
else{
consPrint("\told: epoch%s %ud\n", force ? " -y" : "", old);
consPrint("\tnew: epoch%s %ud\n", force ? " -y" : "", fs->elo);
@@ -1108,8 +1107,8 @@ fsysCreate(Fsys* fsys, int argc, char* argv[])
if(strcmp(argv[1], uidnoworld) == 0)
return cliError("permission denied");
- vtRLock(fsys->fs->elk);
- path = vtStrDup(argv[0]);
+ rlock(&fsys->fs->elk);
+ path = vtstrdup(argv[0]);
if((p = strrchr(path, '/')) != nil){
*p++ = '\0';
elem = p;
@@ -1129,20 +1128,20 @@ fsysCreate(Fsys* fsys, int argc, char* argv[])
file = fileCreate(parent, elem, mode, argv[1]);
fileDecRef(parent);
if(file == nil){
- vtSetError("create %s/%s: %R", p, elem);
+ werrstr("create %s/%s: %r", p, elem);
goto out;
}
if(!fileGetDir(file, &de)){
- vtSetError("stat failed after create: %R");
+ werrstr("stat failed after create: %r");
goto out1;
}
if(strcmp(de.gid, argv[2]) != 0){
- vtMemFree(de.gid);
- de.gid = vtStrDup(argv[2]);
+ vtfree(de.gid);
+ de.gid = vtstrdup(argv[2]);
if(!fileSetDir(file, &de, argv[1])){
- vtSetError("wstat failed after create: %R");
+ werrstr("wstat failed after create: %r");
goto out2;
}
}
@@ -1153,8 +1152,8 @@ out2:
out1:
fileDecRef(file);
out:
- vtMemFree(path);
- vtRUnlock(fsys->fs->elk);
+ vtfree(path);
+ runlock(&fsys->fs->elk);
return r;
}
@@ -1186,14 +1185,14 @@ fsysStat(Fsys* fsys, int argc, char* argv[])
if(argc == 0)
return cliError(usage);
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
for(i=0; i<argc; i++){
if((f = fileOpen(fsys->fs, argv[i])) == nil){
- consPrint("%s: %R\n", argv[i]);
+ consPrint("%s: %r\n", argv[i]);
continue;
}
if(!fileGetDir(f, &de)){
- consPrint("%s: %R\n", argv[i]);
+ consPrint("%s: %r\n", argv[i]);
fileDecRef(f);
continue;
}
@@ -1201,7 +1200,7 @@ fsysStat(Fsys* fsys, int argc, char* argv[])
deCleanup(&de);
fileDecRef(f);
}
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 1;
}
@@ -1222,79 +1221,79 @@ fsysWstat(Fsys *fsys, int argc, char* argv[])
if(argc != 6)
return cliError(usage);
- vtRLock(fsys->fs->elk);
+ rlock(&fsys->fs->elk);
if((f = fileOpen(fsys->fs, argv[0])) == nil){
- vtSetError("console wstat - walk - %R");
- vtRUnlock(fsys->fs->elk);
+ werrstr("console wstat - walk - %r");
+ runlock(&fsys->fs->elk);
return 0;
}
if(!fileGetDir(f, &de)){
- vtSetError("console wstat - stat - %R");
+ werrstr("console wstat - stat - %r");
fileDecRef(f);
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 0;
}
fsysPrintStat("\told: w", argv[0], &de);
if(strcmp(argv[1], "-") != 0){
if(!validFileName(argv[1])){
- vtSetError("console wstat - bad elem");
+ werrstr("console wstat - bad elem");
goto error;
}
- vtMemFree(de.elem);
- de.elem = vtStrDup(argv[1]);
+ vtfree(de.elem);
+ de.elem = vtstrdup(argv[1]);
}
if(strcmp(argv[2], "-") != 0){
if(!validUserName(argv[2])){
- vtSetError("console wstat - bad uid");
+ werrstr("console wstat - bad uid");
goto error;
}
- vtMemFree(de.uid);
- de.uid = vtStrDup(argv[2]);
+ vtfree(de.uid);
+ de.uid = vtstrdup(argv[2]);
}
if(strcmp(argv[3], "-") != 0){
if(!validUserName(argv[3])){
- vtSetError("console wstat - bad gid");
+ werrstr("console wstat - bad gid");
goto error;
}
- vtMemFree(de.gid);
- de.gid = vtStrDup(argv[3]);
+ vtfree(de.gid);
+ de.gid = vtstrdup(argv[3]);
}
if(strcmp(argv[4], "-") != 0){
if(!fsysParseMode(argv[4], &de.mode)){
- vtSetError("console wstat - bad mode");
+ werrstr("console wstat - bad mode");
goto error;
}
}
if(strcmp(argv[5], "-") != 0){
de.size = strtoull(argv[5], &p, 0);
if(argv[5][0] == '\0' || *p != '\0' || (vlong)de.size < 0){
- vtSetError("console wstat - bad length");
+ werrstr("console wstat - bad length");
goto error;
}
}
if(!fileSetDir(f, &de, uidadm)){
- vtSetError("console wstat - %R");
+ werrstr("console wstat - %r");
goto error;
}
deCleanup(&de);
if(!fileGetDir(f, &de)){
- vtSetError("console wstat - stat2 - %R");
+ werrstr("console wstat - stat2 - %r");
goto error;
}
fsysPrintStat("\tnew: w", argv[0], &de);
deCleanup(&de);
fileDecRef(f);
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 1;
error:
deCleanup(&de); /* okay to do this twice */
fileDecRef(f);
- vtRUnlock(fsys->fs->elk);
+ runlock(&fsys->fs->elk);
return 0;
}
@@ -1330,7 +1329,7 @@ fsckClose(Fsck *fsck, Block *b, u32int epoch)
l.state = BsFree;
if(!blockSetLabel(b, &l, 0))
- consPrint("%#ux setlabel: %R\n", b->addr);
+ consPrint("%#ux setlabel: %r\n", b->addr);
}
static void
@@ -1358,7 +1357,7 @@ fsckClrp(Fsck *fsck, Block *b, int offset)
consPrint("bad clre\n");
return;
}
- memmove(b->data+offset*VtScoreSize, vtZeroScore, VtScoreSize);
+ memmove(b->data+offset*VtScoreSize, vtzeroscore, VtScoreSize);
blockDirty(b);
}
@@ -1459,13 +1458,13 @@ fsysVenti(char* name, int argc, char* argv[])
if((fsys = _fsysGet(name)) == nil)
return 0;
- vtLock(fsys->lock);
+ qlock(&fsys->lock);
if(host == nil)
host = fsys->venti;
else{
- vtMemFree(fsys->venti);
+ vtfree(fsys->venti);
if(host[0])
- fsys->venti = vtStrDup(host);
+ fsys->venti = vtstrdup(host);
else{
host = nil;
fsys->venti = nil;
@@ -1475,26 +1474,26 @@ fsysVenti(char* name, int argc, char* argv[])
/* already open: do a redial */
if(fsys->fs != nil){
if(fsys->session == nil){
- vtSetError("file system was opened with -V");
+ werrstr("file system was opened with -V");
r = 0;
goto out;
}
r = 1;
- if(!myRedial(fsys->session, host)
- || !vtConnect(fsys->session, 0))
+ if(myRedial(fsys->session, host) < 0
+ || vtconnect(fsys->session) < 0)
r = 0;
goto out;
}
/* not yet open: try to dial */
if(fsys->session)
- vtClose(fsys->session);
+ vtfreeconn(fsys->session);
r = 1;
- if((fsys->session = myDial(host, 0)) == nil
- || !vtConnect(fsys->session, 0))
+ if((fsys->session = myDial(host)) == nil
+ || vtconnect(fsys->session) < 0)
r = 0;
out:
- vtUnlock(fsys->lock);
+ qunlock(&fsys->lock);
fsysPut(fsys);
return r;
}
@@ -1593,17 +1592,17 @@ fsysOpen(char* name, int argc, char* argv[])
ncache = 100;
}
- vtLock(fsys->lock);
+ qlock(&fsys->lock);
if(fsys->fs != nil){
- vtSetError(EFsysBusy, fsys->name);
- vtUnlock(fsys->lock);
+ werrstr(EFsysBusy, fsys->name);
+ qunlock(&fsys->lock);
fsysPut(fsys);
return 0;
}
if(noventi){
if(fsys->session){
- vtClose(fsys->session);
+ vtfreeconn(fsys->session);
fsys->session = nil;
}
}
@@ -1612,13 +1611,14 @@ fsysOpen(char* name, int argc, char* argv[])
host = fsys->venti;
else
host = nil;
- fsys->session = myDial(host, 1);
- if(!vtConnect(fsys->session, nil) && !noventi)
- fprint(2, "warning: connecting to venti: %R\n");
+
+ if((fsys->session = myDial(host)) == nil
+ || vtconnect(fsys->session) < 0 && !noventi)
+ fprint(2, "warning: connecting to venti: %r\n");
}
if((fsys->fs = fsOpen(fsys->dev, fsys->session, ncache, rflag)) == nil){
- vtSetError("fsOpen: %R");
- vtUnlock(fsys->lock);
+ werrstr("fsOpen: %r");
+ qunlock(&fsys->lock);
fsysPut(fsys);
return 0;
}
@@ -1627,7 +1627,7 @@ fsysOpen(char* name, int argc, char* argv[])
fsys->noperm = noperm;
fsys->wstatallow = wstatallow;
fsys->fs->noatimeupd = noatimeupd;
- vtUnlock(fsys->lock);
+ qunlock(&fsys->lock);
fsysPut(fsys);
if(strcmp(name, "main") == 0)
@@ -1649,7 +1649,7 @@ fsysUnconfig(char* name, int argc, char* argv[])
if(argc)
return cliError(usage);
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
fp = &sbox.head;
for(fsys = *fp; fsys != nil; fsys = fsys->next){
if(strcmp(fsys->name, name) == 0)
@@ -1657,29 +1657,27 @@ fsysUnconfig(char* name, int argc, char* argv[])
fp = &fsys->next;
}
if(fsys == nil){
- vtSetError(EFsysNotFound, name);
- vtUnlock(sbox.lock);
+ werrstr(EFsysNotFound, name);
+ wunlock(&sbox.lock);
return 0;
}
if(fsys->ref != 0 || fsys->fs != nil){
- vtSetError(EFsysBusy, fsys->name);
- vtUnlock(sbox.lock);
+ werrstr(EFsysBusy, fsys->name);
+ wunlock(&sbox.lock);
return 0;
}
*fp = fsys->next;
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
- if(fsys->session != nil){
- vtClose(fsys->session);
- vtFree(fsys->session);
- }
+ if(fsys->session != nil)
+ vtfreeconn(fsys->session);
if(fsys->venti != nil)
- vtMemFree(fsys->venti);
+ vtfree(fsys->venti);
if(fsys->dev != nil)
- vtMemFree(fsys->dev);
+ vtfree(fsys->dev);
if(fsys->name != nil)
- vtMemFree(fsys->name);
- vtMemFree(fsys);
+ vtfree(fsys->name);
+ vtfree(fsys);
return 1;
}
@@ -1704,16 +1702,16 @@ fsysConfig(char* name, int argc, char* argv[])
part = argv[0];
if((fsys = _fsysGet(part)) != nil){
- vtLock(fsys->lock);
+ qlock(&fsys->lock);
if(fsys->fs != nil){
- vtSetError(EFsysBusy, fsys->name);
- vtUnlock(fsys->lock);
+ werrstr(EFsysBusy, fsys->name);
+ qunlock(&fsys->lock);
fsysPut(fsys);
return 0;
}
- vtMemFree(fsys->dev);
- fsys->dev = vtStrDup(part);
- vtUnlock(fsys->lock);
+ vtfree(fsys->dev);
+ fsys->dev = vtstrdup(part);
+ qunlock(&fsys->lock);
}
else if((fsys = fsysAlloc(name, part)) == nil)
return 0;
@@ -1762,22 +1760,22 @@ fsysXXX1(Fsys *fsys, int i, int argc, char* argv[])
{
int r;
- vtLock(fsys->lock);
+ qlock(&fsys->lock);
if(fsys->fs == nil){
- vtUnlock(fsys->lock);
- vtSetError(EFsysNotOpen, fsys->name);
+ qunlock(&fsys->lock);
+ werrstr(EFsysNotOpen, fsys->name);
return 0;
}
if(fsys->fs->halted
&& fsyscmd[i].f != fsysUnhalt && fsyscmd[i].f != fsysCheck){
- vtSetError("file system %s is halted", fsys->name);
- vtUnlock(fsys->lock);
+ werrstr("file system %s is halted", fsys->name);
+ qunlock(&fsys->lock);
return 0;
}
r = (*fsyscmd[i].f)(fsys, argc, argv);
- vtUnlock(fsys->lock);
+ qunlock(&fsys->lock);
return r;
}
@@ -1793,14 +1791,14 @@ fsysXXX(char* name, int argc, char* argv[])
}
if(fsyscmd[i].cmd == nil){
- vtSetError("unknown command - '%s'", argv[0]);
+ werrstr("unknown command - '%s'", argv[0]);
return 0;
}
/* some commands want the name... */
if(fsyscmd[i].f1 != nil){
if(strcmp(name, FsysAll) == 0){
- vtSetError("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
+ werrstr("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
return 0;
}
return (*fsyscmd[i].f1)(name, argc, argv);
@@ -1809,13 +1807,13 @@ fsysXXX(char* name, int argc, char* argv[])
/* ... but most commands want the Fsys */
if(strcmp(name, FsysAll) == 0){
r = 1;
- vtRLock(sbox.lock);
+ rlock(&sbox.lock);
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
fsys->ref++;
r = fsysXXX1(fsys, i, argc, argv) && r;
fsys->ref--;
}
- vtRUnlock(sbox.lock);
+ runlock(&sbox.lock);
}else{
if((fsys = _fsysGet(name)) == nil)
return 0;
@@ -1831,7 +1829,7 @@ cmdFsysXXX(int argc, char* argv[])
char *name;
if((name = sbox.curfsys) == nil){
- vtSetError(EFsysNoCurrent, argv[0]);
+ werrstr(EFsysNoCurrent, argv[0]);
return 0;
}
@@ -1850,18 +1848,18 @@ cmdFsys(int argc, char* argv[])
}ARGEND
if(argc == 0){
- vtRLock(sbox.lock);
+ rlock(&sbox.lock);
currfsysname = sbox.head->name;
for(fsys = sbox.head; fsys != nil; fsys = fsys->next)
consPrint("\t%s\n", fsys->name);
- vtRUnlock(sbox.lock);
+ runlock(&sbox.lock);
return 1;
}
if(argc == 1){
fsys = nil;
if(strcmp(argv[0], FsysAll) != 0 && (fsys = fsysGet(argv[0])) == nil)
return 0;
- sbox.curfsys = vtStrDup(argv[0]);
+ sbox.curfsys = vtstrdup(argv[0]);
consPrompt(sbox.curfsys);
if(fsys)
fsysPut(fsys);
@@ -1878,11 +1876,8 @@ fsysInit(void)
fmtinstall('H', encodefmt);
fmtinstall('V', scoreFmt);
- fmtinstall('R', vtErrFmt);
fmtinstall('L', labelFmt);
- sbox.lock = vtLockAlloc();
-
cliAddCmd("fsys", cmdFsys);
for(i = 0; fsyscmd[i].cmd != nil; i++){
if(fsyscmd[i].f != nil)
diff --git a/src/cmd/fossil/9lstn.c b/src/cmd/fossil/9lstn.c
index 9ba508f4..b4023e8b 100644
--- a/src/cmd/fossil/9lstn.c
+++ b/src/cmd/fossil/9lstn.c
@@ -14,7 +14,7 @@ struct Lstn {
};
static struct {
- VtLock* lock;
+ RWLock lock;
Lstn* head;
Lstn* tail;
@@ -23,7 +23,7 @@ static struct {
static void
lstnFree(Lstn* lstn)
{
- vtLock(lbox.lock);
+ wlock(&lbox.lock);
if(lstn->prev != nil)
lstn->prev->next = lstn->next;
else
@@ -32,12 +32,12 @@ lstnFree(Lstn* lstn)
lstn->next->prev = lstn->prev;
else
lbox.tail = lstn->prev;
- vtUnlock(lbox.lock);
+ wunlock(&lbox.lock);
if(lstn->afd != -1)
close(lstn->afd);
- vtMemFree(lstn->address);
- vtMemFree(lstn);
+ vtfree(lstn->address);
+ vtfree(lstn);
}
static void
@@ -47,7 +47,7 @@ lstnListen(void* a)
int dfd, lfd;
char newdir[NETPATHLEN];
- vtThreadSetName("listen");
+ threadsetname("listen");
lstn = a;
for(;;){
@@ -71,24 +71,24 @@ lstnAlloc(char* address, int flags)
Lstn *lstn;
char dir[NETPATHLEN];
- vtLock(lbox.lock);
+ wlock(&lbox.lock);
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
if(strcmp(lstn->address, address) != 0)
continue;
- vtSetError("listen: already serving '%s'", address);
- vtUnlock(lbox.lock);
+ werrstr("listen: already serving '%s'", address);
+ wunlock(&lbox.lock);
return nil;
}
if((afd = announce(address, dir)) < 0){
- vtSetError("listen: announce '%s': %r", address);
- vtUnlock(lbox.lock);
+ werrstr("listen: announce '%s': %r", address);
+ wunlock(&lbox.lock);
return nil;
}
- lstn = vtMemAllocZ(sizeof(Lstn));
+ lstn = vtmallocz(sizeof(Lstn));
lstn->afd = afd;
- lstn->address = vtStrDup(address);
+ lstn->address = vtstrdup(address);
lstn->flags = flags;
memmove(lstn->dir, dir, NETPATHLEN);
@@ -101,10 +101,10 @@ lstnAlloc(char* address, int flags)
lstn->prev = nil;
}
lbox.tail = lstn;
- vtUnlock(lbox.lock);
+ wunlock(&lbox.lock);
- if(vtThread(lstnListen, lstn) < 0){
- vtSetError("listen: thread '%s': %r", lstn->address);
+ if(proccreate(lstnListen, lstn, STACK) < 0){
+ werrstr("listen: thread '%s': %r", lstn->address);
lstnFree(lstn);
return nil;
}
@@ -139,10 +139,10 @@ cmdLstn(int argc, char* argv[])
default:
return cliError(usage);
case 0:
- vtRLock(lbox.lock);
+ rlock(&lbox.lock);
for(lstn = lbox.head; lstn != nil; lstn = lstn->next)
consPrint("\t%s\t%s\n", lstn->address, lstn->dir);
- vtRUnlock(lbox.lock);
+ runlock(&lbox.lock);
break;
case 1:
if(!dflag){
@@ -151,7 +151,7 @@ cmdLstn(int argc, char* argv[])
break;
}
- vtLock(lbox.lock);
+ wlock(&lbox.lock);
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
if(strcmp(lstn->address, argv[0]) != 0)
continue;
@@ -161,10 +161,10 @@ cmdLstn(int argc, char* argv[])
}
break;
}
- vtUnlock(lbox.lock);
+ wunlock(&lbox.lock);
if(lstn == nil){
- vtSetError("listen: '%s' not found", argv[0]);
+ werrstr("listen: '%s' not found", argv[0]);
return 0;
}
break;
@@ -176,8 +176,6 @@ cmdLstn(int argc, char* argv[])
int
lstnInit(void)
{
- lbox.lock = vtLockAlloc();
-
cliAddCmd("listen", cmdLstn);
return 1;
diff --git a/src/cmd/fossil/9p.c b/src/cmd/fossil/9p.c
index c3fae5ad..c4c95799 100644
--- a/src/cmd/fossil/9p.c
+++ b/src/cmd/fossil/9p.c
@@ -35,11 +35,11 @@ permFile(File* file, Fid* fid, int perm)
*/
if((u = unameByUid(de.uid)) != nil){
if(strcmp(fid->uname, u) == 0 && ((perm<<6) & de.mode)){
- vtMemFree(u);
+ vtfree(u);
deCleanup(&de);
return 1;
}
- vtMemFree(u);
+ vtfree(u);
}
if(groupMember(de.gid, fid->uname) && ((perm<<3) & de.mode)){
deCleanup(&de);
@@ -60,7 +60,7 @@ permFile(File* file, Fid* fid, int perm)
deCleanup(&de);
return 1;
}
- vtSetError(EPermission);
+ werrstr(EPermission);
deCleanup(&de);
return 0;
@@ -91,19 +91,19 @@ validFileName(char* name)
char *p;
if(name == nil || name[0] == '\0'){
- vtSetError("no file name");
+ werrstr("no file name");
return 0;
}
if(name[0] == '.'){
if(name[1] == '\0' || (name[1] == '.' && name[2] == '\0')){
- vtSetError(". and .. illegal as file name");
+ werrstr(". and .. illegal as file name");
return 0;
}
}
for(p = name; *p != '\0'; p++){
if((*p & 0xFF) < 040){
- vtSetError("bad character in file name");
+ werrstr("bad character in file name");
return 0;
}
}
@@ -128,20 +128,20 @@ rTwstat(Msg* m)
retval = 0;
if(strcmp(fid->uname, unamenone) == 0 || (fid->qid.type & QTAUTH)){
- vtSetError(EPermission);
+ werrstr(EPermission);
goto error0;
}
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
- vtSetError("read-only filesystem");
+ werrstr("read-only filesystem");
goto error0;
}
if(!fileGetDir(fid->file, &de))
goto error0;
- strs = vtMemAlloc(m->t.nstat);
+ strs = vtmalloc(m->t.nstat);
if(convM2D(m->t.stat, m->t.nstat, &dir, strs) == 0){
- vtSetError("wstat -- protocol botch");
+ werrstr("wstat -- protocol botch");
goto error;
}
@@ -160,28 +160,28 @@ rTwstat(Msg* m)
tsync = 1;
if(dir.qid.path != ~0){
if(dir.qid.path != de.qid){
- vtSetError("wstat -- attempt to change qid.path");
+ werrstr("wstat -- attempt to change qid.path");
goto error;
}
tsync = 0;
}
if(dir.qid.vers != ~0){
if(dir.qid.vers != de.mcount){
- vtSetError("wstat -- attempt to change qid.vers");
+ werrstr("wstat -- attempt to change qid.vers");
goto error;
}
tsync = 0;
}
if(dir.muid != nil && *dir.muid != '\0'){
if((uid = uidByUname(dir.muid)) == nil){
- vtSetError("wstat -- unknown muid");
+ werrstr("wstat -- unknown muid");
goto error;
}
if(strcmp(uid, de.mid) != 0){
- vtSetError("wstat -- attempt to change muid");
+ werrstr("wstat -- attempt to change muid");
goto error;
}
- vtMemFree(uid);
+ vtfree(uid);
uid = nil;
tsync = 0;
}
@@ -191,7 +191,7 @@ rTwstat(Msg* m)
*/
if(dir.qid.type != (uchar)~0 && dir.mode != ~0){
if(dir.qid.type != ((dir.mode>>24) & 0xFF)){
- vtSetError("wstat -- qid.type/mode mismatch");
+ werrstr("wstat -- qid.type/mode mismatch");
goto error;
}
}
@@ -206,7 +206,7 @@ rTwstat(Msg* m)
if(dir.mode == ~0)
dir.mode = (dir.qid.type<<24)|(de.mode & 0777);
if(dir.mode & ~(DMDIR|DMAPPEND|DMEXCL|DMTMP|0777)){
- vtSetError("wstat -- unknown bits in qid.type/mode");
+ werrstr("wstat -- unknown bits in qid.type/mode");
goto error;
}
@@ -224,7 +224,7 @@ rTwstat(Msg* m)
mode |= ModeTemporary;
if((de.mode^mode) & ModeDir){
- vtSetError("wstat -- attempt to change directory bit");
+ werrstr("wstat -- attempt to change directory bit");
goto error;
}
@@ -251,11 +251,11 @@ rTwstat(Msg* m)
* If we're changing the append bit, it's okay.
*/
if(de.mode & oldmode & ModeAppend){
- vtSetError("wstat -- attempt to change length of append-only file");
+ werrstr("wstat -- attempt to change length of append-only file");
goto error;
}
if(de.mode & ModeDir){
- vtSetError("wstat -- attempt to change length of directory");
+ werrstr("wstat -- attempt to change length of directory");
goto error;
}
de.size = dir.length;
@@ -271,13 +271,13 @@ rTwstat(Msg* m)
*/
if(dir.gid != nil && *dir.gid != '\0'){
if((gid = uidByUname(dir.gid)) == nil){
- vtSetError("wstat -- unknown gid");
+ werrstr("wstat -- unknown gid");
goto error;
}
tsync = 0;
}
else
- gid = vtStrDup(de.gid);
+ gid = vtstrdup(de.gid);
wstatallow = (fsysWstatAllow(fid->fsys) || (m->con->flags&ConWstatAllow));
@@ -289,7 +289,7 @@ rTwstat(Msg* m)
if(op && !wstatallow){
if(strcmp(fid->uid, de.uid) != 0 && !gl){
- vtSetError("wstat -- not owner or group leader");
+ werrstr("wstat -- not owner or group leader");
goto error;
}
}
@@ -303,10 +303,10 @@ rTwstat(Msg* m)
if(!wstatallow
&& !(strcmp(fid->uid, de.uid) == 0 && groupMember(gid, fid->uname))
&& !(gl == 2)){
- vtSetError("wstat -- not owner and not group leaders");
+ werrstr("wstat -- not owner and not group leaders");
goto error;
}
- vtMemFree(de.gid);
+ vtfree(de.gid);
de.gid = gid;
gid = nil;
op = 1;
@@ -324,8 +324,8 @@ rTwstat(Msg* m)
if(strcmp(dir.name, de.elem) != 0){
if(permParent(fid, PermW) <= 0)
goto error;
- vtMemFree(de.elem);
- de.elem = vtStrDup(dir.name);
+ vtfree(de.elem);
+ de.elem = vtstrdup(dir.name);
op = 1;
}
tsync = 0;
@@ -336,19 +336,19 @@ rTwstat(Msg* m)
*/
if(dir.uid != nil && *dir.uid != '\0'){
if((uid = uidByUname(dir.uid)) == nil){
- vtSetError("wstat -- unknown uid");
+ werrstr("wstat -- unknown uid");
goto error;
}
if(strcmp(uid, de.uid) != 0){
if(!wstatallow){
- vtSetError("wstat -- not owner");
+ werrstr("wstat -- not owner");
goto error;
}
if(strcmp(uid, uidnoworld) == 0){
- vtSetError(EPermission);
+ werrstr(EPermission);
goto error;
}
- vtMemFree(de.uid);
+ vtfree(de.uid);
de.uid = uid;
uid = nil;
op = 1;
@@ -372,11 +372,11 @@ rTwstat(Msg* m)
error:
deCleanup(&de);
- vtMemFree(strs);
+ vtfree(strs);
if(gid != nil)
- vtMemFree(gid);
+ vtfree(gid);
if(uid != nil)
- vtMemFree(uid);
+ vtfree(uid);
error0:
fidPut(fid);
return retval;
@@ -404,7 +404,7 @@ rTstat(Msg* m)
dir.muid = fid->uname;
if((m->r.nstat = convD2M(&dir, m->data, m->con->msize)) == 0){
- vtSetError("stat QTAUTH botch");
+ werrstr("stat QTAUTH botch");
fidPut(fid);
return 0;
}
@@ -479,24 +479,24 @@ rTwrite(Msg* m)
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
return 0;
if(!(fid->open & FidOWrite)){
- vtSetError("fid not open for write");
+ werrstr("fid not open for write");
goto error;
}
count = m->t.count;
if(count < 0 || count > m->con->msize-IOHDRSZ){
- vtSetError("write count too big");
+ werrstr("write count too big");
goto error;
}
if(m->t.offset < 0){
- vtSetError("write offset negative");
+ werrstr("write offset negative");
goto error;
}
if(fid->excl != nil && !exclUpdate(fid))
goto error;
if(fid->qid.type & QTDIR){
- vtSetError("is a directory");
+ werrstr("is a directory");
goto error;
}
else if(fid->qid.type & QTAUTH)
@@ -527,17 +527,17 @@ rTread(Msg* m)
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
return 0;
if(!(fid->open & FidORead)){
- vtSetError("fid not open for read");
+ werrstr("fid not open for read");
goto error;
}
count = m->t.count;
if(count < 0 || count > m->con->msize-IOHDRSZ){
- vtSetError("read count too big");
+ werrstr("read count too big");
goto error;
}
if(m->t.offset < 0){
- vtSetError("read offset negative");
+ werrstr("read offset negative");
goto error;
}
if(fid->excl != nil && !exclUpdate(fid))
@@ -579,15 +579,15 @@ rTcreate(Msg* m)
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
return 0;
if(fid->open){
- vtSetError("fid open for I/O");
+ werrstr("fid open for I/O");
goto error;
}
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
- vtSetError("read-only filesystem");
+ werrstr("read-only filesystem");
goto error;
}
if(!fileIsDir(fid->file)){
- vtSetError("not a directory");
+ werrstr("not a directory");
goto error;
}
if(permFid(fid, PermW) <= 0)
@@ -595,7 +595,7 @@ rTcreate(Msg* m)
if(!validFileName(m->t.name))
goto error;
if(strcmp(fid->uid, uidnoworld) == 0){
- vtSetError(EPermission);
+ werrstr(EPermission);
goto error;
}
@@ -607,16 +607,16 @@ rTcreate(Msg* m)
if(omode == OWRITE || omode == ORDWR)
open |= FidOWrite;
if((open & (FidOWrite|FidORead)) == 0){
- vtSetError("unknown mode");
+ werrstr("unknown mode");
goto error;
}
if(m->t.perm & DMDIR){
if((m->t.mode & (ORCLOSE|OTRUNC)) || (open & FidOWrite)){
- vtSetError("illegal mode");
+ werrstr("illegal mode");
goto error;
}
if(m->t.perm & DMAPPEND){
- vtSetError("illegal perm");
+ werrstr("illegal perm");
goto error;
}
}
@@ -681,7 +681,7 @@ rTopen(Msg* m)
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
return 0;
if(fid->open){
- vtSetError("fid open for I/O");
+ werrstr("fid open for I/O");
goto error;
}
@@ -691,11 +691,11 @@ rTopen(Msg* m)
if(m->t.mode & ORCLOSE){
if(isdir){
- vtSetError("is a directory");
+ werrstr("is a directory");
goto error;
}
if(rofs){
- vtSetError("read-only filesystem");
+ werrstr("read-only filesystem");
goto error;
}
if(permParent(fid, PermW) <= 0)
@@ -712,11 +712,11 @@ rTopen(Msg* m)
}
if(omode == OWRITE || omode == ORDWR || (m->t.mode & OTRUNC)){
if(isdir){
- vtSetError("is a directory");
+ werrstr("is a directory");
goto error;
}
if(rofs){
- vtSetError("read-only filesystem");
+ werrstr("read-only filesystem");
goto error;
}
if(permFid(fid, PermW) <= 0)
@@ -725,7 +725,7 @@ rTopen(Msg* m)
}
if(omode == OEXEC){
if(isdir){
- vtSetError("is a directory");
+ werrstr("is a directory");
goto error;
}
if(permFid(fid, PermX) <= 0)
@@ -733,7 +733,7 @@ rTopen(Msg* m)
open |= FidORead;
}
if((open & (FidOWrite|FidORead)) == 0){
- vtSetError("unknown mode");
+ werrstr("unknown mode");
goto error;
}
@@ -792,7 +792,7 @@ rTwalk(Msg* m)
if((ofid = fidGet(m->con, t->fid, wlock)) == nil)
return 0;
if(ofid->open){
- vtSetError("file open for I/O");
+ werrstr("file open for I/O");
fidPut(ofid);
return 0;
}
@@ -808,7 +808,7 @@ rTwalk(Msg* m)
if(t->fid != t->newfid){
nfid = fidGet(m->con, t->newfid, FidFWlock|FidFCreate);
if(nfid == nil){
- vtSetError("%s: walk: newfid 0x%ud in use",
+ werrstr("%s: walk: newfid 0x%ud in use",
argv0, t->newfid);
fidPut(ofid);
return 0;
@@ -816,8 +816,8 @@ rTwalk(Msg* m)
nfid->open = ofid->open & ~FidORclose;
nfid->file = fileIncRef(ofid->file);
nfid->qid = ofid->qid;
- nfid->uid = vtStrDup(ofid->uid);
- nfid->uname = vtStrDup(ofid->uname);
+ nfid->uid = vtstrdup(ofid->uid);
+ nfid->uname = vtstrdup(ofid->uname);
nfid->fsys = fsysIncRef(ofid->fsys);
fid = nfid;
}
@@ -848,7 +848,7 @@ rTwalk(Msg* m)
* to walk out of it.
*/
if(!(qid.type & QTDIR)){
- vtSetError("not a directory");
+ werrstr("not a directory");
break;
}
switch(permFile(file, fid, PermX)){
@@ -925,9 +925,9 @@ parseAname(char *aname, char **fsname, char **path)
char *s;
if(aname && aname[0])
- s = vtStrDup(aname);
+ s = vtstrdup(aname);
else
- s = vtStrDup("main/active");
+ s = vtstrdup("main/active");
*fsname = s;
if((*path = strchr(s, '/')) != nil)
*(*path)++ = '\0';
@@ -949,7 +949,7 @@ conIPCheck(Con* con)
if(con->flags&ConIPCheck){
if(con->remote[0] == 0){
- vtSetError("cannot verify unknown remote address");
+ werrstr("cannot verify unknown remote address");
return 0;
}
if(access("/mnt/ipok/ok", AEXIST) < 0){
@@ -958,7 +958,7 @@ conIPCheck(Con* con)
&& mount(fd, -1, "/mnt/ipok", MREPL, "") < 0)
close(fd);
if(access("/mnt/ipok/ok", AEXIST) < 0){
- vtSetError("cannot verify remote address");
+ werrstr("cannot verify remote address");
return 0;
}
}
@@ -966,7 +966,7 @@ conIPCheck(Con* con)
if((p = strchr(ok, '!')) != nil)
*p = 0;
if(access(ok, AEXIST) < 0){
- vtSetError("restricted remote address");
+ werrstr("restricted remote address");
return 0;
}
}
@@ -986,29 +986,29 @@ rTattach(Msg* m)
parseAname(m->t.aname, &fsname, &path);
if((fsys = fsysGet(fsname)) == nil){
fidClunk(fid);
- vtMemFree(fsname);
+ vtfree(fsname);
return 0;
}
fid->fsys = fsys;
if(m->t.uname[0] != '\0')
- fid->uname = vtStrDup(m->t.uname);
+ fid->uname = vtstrdup(m->t.uname);
else
- fid->uname = vtStrDup(unamenone);
+ fid->uname = vtstrdup(unamenone);
if((fid->con->flags&ConIPCheck) && !conIPCheck(fid->con)){
- consPrint("reject %s from %s: %R\n", fid->uname, fid->con->remote);
+ consPrint("reject %s from %s: %r\n", fid->uname, fid->con->remote);
fidClunk(fid);
- vtMemFree(fsname);
+ vtfree(fsname);
return 0;
}
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
if((fid->uid = uidByUname(fid->uname)) == nil)
- fid->uid = vtStrDup(unamenone);
+ fid->uid = vtstrdup(unamenone);
}
else if(!authCheck(&m->t, fid, fsys)){
fidClunk(fid);
- vtMemFree(fsname);
+ vtfree(fsname);
return 0;
}
@@ -1016,11 +1016,11 @@ rTattach(Msg* m)
if((fid->file = fsysGetRoot(fsys, path)) == nil){
fsysFsRUnlock(fsys);
fidClunk(fid);
- vtMemFree(fsname);
+ vtfree(fsname);
return 0;
}
fsysFsRUnlock(fsys);
- vtMemFree(fsname);
+ vtfree(fsname);
fid->qid = (Qid){fileGetId(fid->file), 0, QTDIR};
m->r.qid = fid->qid;
@@ -1040,19 +1040,19 @@ rTauth(Msg* m)
parseAname(m->t.aname, &fsname, &path);
if((fsys = fsysGet(fsname)) == nil){
- vtMemFree(fsname);
+ vtfree(fsname);
return 0;
}
- vtMemFree(fsname);
+ vtfree(fsname);
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
m->con->aok = 1;
- vtSetError("authentication disabled");
+ werrstr("authentication disabled");
fsysPut(fsys);
return 0;
}
if(strcmp(m->t.uname, unamenone) == 0){
- vtSetError("user 'none' requires no authentication");
+ werrstr("user 'none' requires no authentication");
fsysPut(fsys);
return 0;
}
@@ -1065,18 +1065,18 @@ rTauth(Msg* m)
afid->fsys = fsys;
if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
- vtSetError("can't open \"/mnt/factotum/rpc\"");
+ werrstr("can't open \"/mnt/factotum/rpc\"");
fidClunk(afid);
return 0;
}
if((afid->rpc = auth_allocrpc(afd)) == nil){
close(afd);
- vtSetError("can't auth_allocrpc");
+ werrstr("can't auth_allocrpc");
fidClunk(afid);
return 0;
}
if(auth_rpc(afid->rpc, "start", "proto=p9any role=server", 23) != ARok){
- vtSetError("can't auth_rpc");
+ werrstr("can't auth_rpc");
fidClunk(afid);
return 0;
}
@@ -1084,7 +1084,7 @@ rTauth(Msg* m)
afid->open = FidOWrite|FidORead;
afid->qid.type = QTAUTH;
afid->qid.path = m->t.afid;
- afid->uname = vtStrDup(m->t.uname);
+ afid->uname = vtstrdup(m->t.uname);
m->r.qid = afid->qid;
@@ -1103,10 +1103,10 @@ rTversion(Msg* m)
r = &m->r;
con = m->con;
- vtLock(con->lock);
+ qlock(&con->lock);
if(con->state != ConInit){
- vtUnlock(con->lock);
- vtSetError("Tversion: down");
+ qunlock(&con->lock);
+ werrstr("Tversion: down");
return 0;
}
con->state = ConNew;
@@ -1119,14 +1119,14 @@ rTversion(Msg* m)
fidClunkAll(con);
if(t->tag != NOTAG){
- vtUnlock(con->lock);
- vtSetError("Tversion: invalid tag");
+ qunlock(&con->lock);
+ werrstr("Tversion: invalid tag");
return 0;
}
if(t->msize < 256){
- vtUnlock(con->lock);
- vtSetError("Tversion: message size too small");
+ qunlock(&con->lock);
+ werrstr("Tversion: message size too small");
return 0;
}
if(t->msize < con->msize)
@@ -1159,7 +1159,7 @@ rTversion(Msg* m)
m->state = MsgF;
}
}
- vtUnlock(con->lock);
+ qunlock(&con->lock);
return 1;
}
diff --git a/src/cmd/fossil/9ping.c b/src/cmd/fossil/9ping.c
index a21eea9b..dbf628c5 100644
--- a/src/cmd/fossil/9ping.c
+++ b/src/cmd/fossil/9ping.c
@@ -106,4 +106,3 @@ main(int argc, char *argv[])
exits(0);
}
-
diff --git a/src/cmd/fossil/9proc.c b/src/cmd/fossil/9proc.c
index bddd3baa..f87cdc4d 100644
--- a/src/cmd/fossil/9proc.c
+++ b/src/cmd/fossil/9proc.c
@@ -12,18 +12,18 @@ enum {
};
static struct {
- VtLock* alock; /* alloc */
+ QLock alock; /* alloc */
Msg* ahead;
- VtRendez* arendez;
+ Rendez arendez;
int maxmsg;
int nmsg;
int nmsgstarve;
- VtLock* rlock; /* read */
+ QLock rlock; /* read */
Msg* rhead;
Msg* rtail;
- VtRendez* rrendez;
+ Rendez rrendez;
int maxproc;
int nproc;
@@ -33,11 +33,11 @@ static struct {
} mbox;
static struct {
- VtLock* alock; /* alloc */
+ QLock alock; /* alloc */
Con* ahead;
- VtRendez* arendez;
+ Rendez arendez;
- VtLock* clock;
+ RWLock clock;
Con* chead;
Con* ctail;
@@ -66,7 +66,7 @@ conFree(Con* con)
con->flags = 0;
con->isconsole = 0;
- vtLock(cbox.alock);
+ qlock(&cbox.alock);
if(con->cprev != nil)
con->cprev->cnext = con->cnext;
else
@@ -79,25 +79,18 @@ conFree(Con* con)
if(cbox.ncon > cbox.maxcon){
if(con->name != nil)
- vtMemFree(con->name);
- vtLockFree(con->fidlock);
- vtMemFree(con->data);
- vtRendezFree(con->wrendez);
- vtLockFree(con->wlock);
- vtRendezFree(con->mrendez);
- vtLockFree(con->mlock);
- vtRendezFree(con->rendez);
- vtLockFree(con->lock);
- vtMemFree(con);
+ vtfree(con->name);
+ vtfree(con->data);
+ vtfree(con);
cbox.ncon--;
- vtUnlock(cbox.alock);
+ qunlock(&cbox.alock);
return;
}
con->anext = cbox.ahead;
cbox.ahead = con;
if(con->anext == nil)
- vtWakeup(cbox.arendez);
- vtUnlock(cbox.alock);
+ rwakeup(&cbox.arendez);
+ qunlock(&cbox.alock);
}
static void
@@ -106,19 +99,19 @@ msgFree(Msg* m)
assert(m->rwnext == nil);
assert(m->flush == nil);
- vtLock(mbox.alock);
+ qlock(&mbox.alock);
if(mbox.nmsg > mbox.maxmsg){
- vtMemFree(m->data);
- vtMemFree(m);
+ vtfree(m->data);
+ vtfree(m);
mbox.nmsg--;
- vtUnlock(mbox.alock);
+ qunlock(&mbox.alock);
return;
}
m->anext = mbox.ahead;
mbox.ahead = m;
if(m->anext == nil)
- vtWakeup(mbox.arendez);
- vtUnlock(mbox.alock);
+ rwakeup(&mbox.arendez);
+ qunlock(&mbox.alock);
}
static Msg*
@@ -126,15 +119,15 @@ msgAlloc(Con* con)
{
Msg *m;
- vtLock(mbox.alock);
+ qlock(&mbox.alock);
while(mbox.ahead == nil){
if(mbox.nmsg >= mbox.maxmsg){
mbox.nmsgstarve++;
- vtSleep(mbox.arendez);
+ rsleep(&mbox.arendez);
continue;
}
- m = vtMemAllocZ(sizeof(Msg));
- m->data = vtMemAlloc(mbox.msize);
+ m = vtmallocz(sizeof(Msg));
+ m->data = vtmalloc(mbox.msize);
m->msize = mbox.msize;
mbox.nmsg++;
mbox.ahead = m;
@@ -143,7 +136,7 @@ msgAlloc(Con* con)
m = mbox.ahead;
mbox.ahead = m->anext;
m->anext = nil;
- vtUnlock(mbox.alock);
+ qunlock(&mbox.alock);
m->con = con;
m->state = MsgR;
@@ -188,9 +181,9 @@ msgFlush(Msg* m)
* If it's not found must assume Elvis has already
* left the building and reply normally.
*/
- vtLock(con->mlock);
+ qlock(&con->mlock);
if(m->state == MsgF){
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
return;
}
for(old = con->mhead; old != nil; old = old->mnext)
@@ -199,7 +192,7 @@ msgFlush(Msg* m)
if(old == nil){
if(Dflag)
fprint(2, "msgFlush: cannot find %d\n", m->t.oldtag);
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
return;
}
@@ -253,17 +246,17 @@ msgFlush(Msg* m)
if(Dflag)
fprint(2, "msgFlush: add %d to %d queue\n",
m->t.tag, old->t.tag);
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
}
static void
msgProc(void*)
{
Msg *m;
- char *e;
+ char e[ERRMAX];
Con *con;
- vtThreadSetName("msgProc");
+ threadsetname("msgProc");
for(;;){
/*
@@ -271,64 +264,64 @@ msgProc(void*)
* If not, wait for and pull a message off
* the read queue.
*/
- vtLock(mbox.rlock);
+ qlock(&mbox.rlock);
if(mbox.nproc > mbox.maxproc){
mbox.nproc--;
- vtUnlock(mbox.rlock);
+ qunlock(&mbox.rlock);
break;
}
while(mbox.rhead == nil)
- vtSleep(mbox.rrendez);
+ rsleep(&mbox.rrendez);
m = mbox.rhead;
mbox.rhead = m->rwnext;
m->rwnext = nil;
- vtUnlock(mbox.rlock);
+ qunlock(&mbox.rlock);
con = m->con;
- e = nil;
+ *e = 0;
/*
* If the message has been flushed before
* any 9P processing has started, mark it so
* none will be attempted.
*/
- vtLock(con->mlock);
+ qlock(&con->mlock);
if(m->state == MsgF)
- e = "flushed";
+ strcpy(e, "flushed");
else
m->state = Msg9;
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
- if(e == nil){
+ if(*e == 0){
/*
* explain this
*/
- vtLock(con->lock);
+ qlock(&con->lock);
if(m->t.type == Tversion){
con->version = m;
con->state = ConDown;
while(con->mhead != m)
- vtSleep(con->rendez);
+ rsleep(&con->rendez);
assert(con->state == ConDown);
if(con->version == m){
con->version = nil;
con->state = ConInit;
}
else
- e = "Tversion aborted";
+ strcpy(e, "Tversion aborted");
}
else if(con->state != ConUp)
- e = "connection not ready";
- vtUnlock(con->lock);
+ strcpy(e, "connection not ready");
+ qunlock(&con->lock);
}
/*
* Dispatch if not error already.
*/
m->r.tag = m->t.tag;
- if(e == nil && !(*rFcall[m->t.type])(m))
- e = vtGetError();
- if(e != nil){
+ if(*e == 0 && !(*rFcall[m->t.type])(m))
+ rerrstr(e, sizeof e);
+ if(*e != 0){
m->r.type = Rerror;
m->r.ename = e;
}
@@ -340,14 +333,14 @@ msgProc(void*)
* write queue and wakeup the write process.
*/
if(!m->nowq){
- vtLock(con->wlock);
+ qlock(&con->wlock);
if(con->whead == nil)
con->whead = m;
else
con->wtail->rwnext = m;
con->wtail = m;
- vtWakeup(con->wrendez);
- vtUnlock(con->wlock);
+ rwakeup(&con->wrendez);
+ qunlock(&con->wlock);
}
}
}
@@ -359,7 +352,7 @@ msgRead(void* v)
Con *con;
int eof, fd, n;
- vtThreadSetName("msgRead");
+ threadsetname("msgRead");
con = v;
fd = con->fd;
@@ -388,7 +381,7 @@ msgRead(void* v)
if(Dflag)
fprint(2, "msgRead %p: t %F\n", con, &m->t);
- vtLock(con->mlock);
+ qlock(&con->mlock);
if(con->mtail != nil){
m->mprev = con->mtail;
con->mtail->mnext = m;
@@ -398,14 +391,14 @@ msgRead(void* v)
m->mprev = nil;
}
con->mtail = m;
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
- vtLock(mbox.rlock);
+ qlock(&mbox.rlock);
if(mbox.rhead == nil){
mbox.rhead = m;
- if(!vtWakeup(mbox.rrendez)){
+ if(!rwakeup(&mbox.rrendez)){
if(mbox.nproc < mbox.maxproc){
- if(vtThread(msgProc, nil) > 0)
+ if(proccreate(msgProc, nil, STACK) > 0)
mbox.nproc++;
}
else
@@ -413,13 +406,13 @@ msgRead(void* v)
}
/*
* don't need this surely?
- vtWakeup(mbox.rrendez);
+ rwakeup(&mbox.rrendez);
*/
}
else
mbox.rtail->rwnext = m;
mbox.rtail = m;
- vtUnlock(mbox.rlock);
+ qunlock(&mbox.rlock);
}
}
@@ -430,10 +423,10 @@ msgWrite(void* v)
int eof, n;
Msg *flush, *m;
- vtThreadSetName("msgWrite");
+ threadsetname("msgWrite");
con = v;
- if(vtThread(msgRead, con) < 0){
+ if(proccreate(msgRead, con, STACK) < 0){
conFree(con);
return;
}
@@ -442,14 +435,14 @@ msgWrite(void* v)
/*
* Wait for and pull a message off the write queue.
*/
- vtLock(con->wlock);
+ qlock(&con->wlock);
while(con->whead == nil)
- vtSleep(con->wrendez);
+ rsleep(&con->wrendez);
m = con->whead;
con->whead = m->rwnext;
m->rwnext = nil;
assert(!m->nowq);
- vtUnlock(con->wlock);
+ qunlock(&con->wlock);
eof = 0;
@@ -457,7 +450,7 @@ msgWrite(void* v)
* Write each message (if it hasn't been flushed)
* followed by any messages waiting for it to complete.
*/
- vtLock(con->mlock);
+ qlock(&con->mlock);
while(m != nil){
msgMunlink(m);
@@ -467,13 +460,13 @@ msgWrite(void* v)
if(m->state != MsgF){
m->state = MsgW;
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
n = convS2M(&m->r, con->data, con->msize);
if(write(con->fd, con->data, n) != n)
eof = 1;
- vtLock(con->mlock);
+ qlock(&con->mlock);
}
if((flush = m->flush) != nil){
@@ -483,21 +476,21 @@ msgWrite(void* v)
msgFree(m);
m = flush;
}
- vtUnlock(con->mlock);
+ qunlock(&con->mlock);
- vtLock(con->lock);
+ qlock(&con->lock);
if(eof && con->fd >= 0){
close(con->fd);
con->fd = -1;
}
if(con->state == ConDown)
- vtWakeup(con->rendez);
+ rwakeup(&con->rendez);
if(con->state == ConMoribund && con->mhead == nil){
- vtUnlock(con->lock);
+ qunlock(&con->lock);
conFree(con);
break;
}
- vtUnlock(con->lock);
+ qunlock(&con->lock);
}
}
@@ -508,24 +501,19 @@ conAlloc(int fd, char* name, int flags)
char buf[128], *p;
int rfd, n;
- vtLock(cbox.alock);
+ qlock(&cbox.alock);
while(cbox.ahead == nil){
if(cbox.ncon >= cbox.maxcon){
cbox.nconstarve++;
- vtSleep(cbox.arendez);
+ rsleep(&cbox.arendez);
continue;
}
- con = vtMemAllocZ(sizeof(Con));
- con->lock = vtLockAlloc();
- con->rendez = vtRendezAlloc(con->lock);
- con->data = vtMemAlloc(cbox.msize);
+ con = vtmallocz(sizeof(Con));
+ con->rendez.l = &con->lock;
+ con->data = vtmalloc(cbox.msize);
con->msize = cbox.msize;
- con->alock = vtLockAlloc();
- con->mlock = vtLockAlloc();
- con->mrendez = vtRendezAlloc(con->mlock);
- con->wlock = vtLockAlloc();
- con->wrendez = vtRendezAlloc(con->wlock);
- con->fidlock = vtLockAlloc();
+ con->mrendez.l = &con->mlock;
+ con->wrendez.l = &con->wlock;
cbox.ncon++;
cbox.ahead = con;
@@ -553,13 +541,13 @@ conAlloc(int fd, char* name, int flags)
con->state = ConNew;
con->fd = fd;
if(con->name != nil){
- vtMemFree(con->name);
+ vtfree(con->name);
con->name = nil;
}
if(name != nil)
- con->name = vtStrDup(name);
+ con->name = vtstrdup(name);
else
- con->name = vtStrDup("unknown");
+ con->name = vtstrdup("unknown");
con->remote[0] = 0;
snprint(buf, sizeof buf, "%s/remote", con->name);
if((rfd = open(buf, OREAD)) >= 0){
@@ -574,9 +562,9 @@ conAlloc(int fd, char* name, int flags)
}
con->flags = flags;
con->isconsole = 0;
- vtUnlock(cbox.alock);
+ qunlock(&cbox.alock);
- if(vtThread(msgWrite, con) < 0){
+ if(proccreate(msgWrite, con, STACK) < 0){
conFree(con);
return nil;
}
@@ -616,21 +604,21 @@ cmdMsg(int argc, char* argv[])
if(argc)
return cliError(usage);
- vtLock(mbox.alock);
+ qlock(&mbox.alock);
if(maxmsg)
mbox.maxmsg = maxmsg;
maxmsg = mbox.maxmsg;
nmsg = mbox.nmsg;
nmsgstarve = mbox.nmsgstarve;
- vtUnlock(mbox.alock);
+ qunlock(&mbox.alock);
- vtLock(mbox.rlock);
+ qlock(&mbox.rlock);
if(maxproc)
mbox.maxproc = maxproc;
maxproc = mbox.maxproc;
nproc = mbox.nproc;
nprocstarve = mbox.nprocstarve;
- vtUnlock(mbox.rlock);
+ qunlock(&mbox.rlock);
consPrint("\tmsg -m %d -p %d\n", maxmsg, maxproc);
consPrint("\tnmsg %d nmsgstarve %d nproc %d nprocstarve %d\n",
@@ -717,7 +705,7 @@ cmdWho(int argc, char* argv[])
if(argc > 0)
return cliError(usage);
- vtRLock(cbox.clock);
+ rlock(&cbox.clock);
l1 = 0;
l2 = 0;
for(con=cbox.chead; con; con=con->cnext){
@@ -728,7 +716,7 @@ cmdWho(int argc, char* argv[])
}
for(con=cbox.chead; con; con=con->cnext){
consPrint("\t%-*s %-*s", l1, con->name, l2, con->remote);
- vtLock(con->fidlock);
+ qlock(&con->fidlock);
last = nil;
for(i=0; i<NFidHash; i++)
for(fid=con->fidhash[i]; fid; fid=fid->hash)
@@ -741,21 +729,19 @@ cmdWho(int argc, char* argv[])
for(; fid; last=fid, fid=fid->sort)
if(last==nil || strcmp(fid->uname, last->uname) != 0)
consPrint(" %q", fid->uname);
- vtUnlock(con->fidlock);
+ qunlock(&con->fidlock);
consPrint("\n");
}
- vtRUnlock(cbox.clock);
+ runlock(&cbox.clock);
return 1;
}
void
msgInit(void)
{
- mbox.alock = vtLockAlloc();
- mbox.arendez = vtRendezAlloc(mbox.alock);
+ mbox.arendez.l = &mbox.alock;
- mbox.rlock = vtLockAlloc();
- mbox.rrendez = vtRendezAlloc(mbox.rlock);
+ mbox.rrendez.l = &mbox.rlock;
mbox.maxmsg = NMsgInit;
mbox.maxproc = NMsgProcInit;
@@ -789,22 +775,22 @@ cmdCon(int argc, char* argv[])
if(argc)
return cliError(usage);
- vtLock(cbox.clock);
+ wlock(&cbox.clock);
if(maxcon)
cbox.maxcon = maxcon;
maxcon = cbox.maxcon;
ncon = cbox.ncon;
nconstarve = cbox.nconstarve;
- vtUnlock(cbox.clock);
+ wunlock(&cbox.clock);
consPrint("\tcon -m %d\n", maxcon);
consPrint("\tncon %d nconstarve %d\n", ncon, nconstarve);
- vtRLock(cbox.clock);
+ rlock(&cbox.clock);
for(con = cbox.chead; con != nil; con = con->cnext){
consPrint("\t%s\n", con->name);
}
- vtRUnlock(cbox.clock);
+ runlock(&cbox.clock);
return 1;
}
@@ -812,10 +798,7 @@ cmdCon(int argc, char* argv[])
void
conInit(void)
{
- cbox.alock = vtLockAlloc();
- cbox.arendez = vtRendezAlloc(cbox.alock);
-
- cbox.clock = vtLockAlloc();
+ cbox.arendez.l = &cbox.alock;
cbox.maxcon = NConInit;
cbox.msize = NMsizeInit;
diff --git a/src/cmd/fossil/9srv.c b/src/cmd/fossil/9srv.c
index 84696268..94e67245 100644
--- a/src/cmd/fossil/9srv.c
+++ b/src/cmd/fossil/9srv.c
@@ -14,7 +14,7 @@ struct Srv {
};
static struct {
- VtLock* lock;
+ RWLock lock;
Srv* head;
Srv* tail;
@@ -33,11 +33,11 @@ srvFd(char* name, int mode, int fd, char** mntpnt)
*/
p = smprint("/srv/%s", name);
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
- vtMemFree(p);
+ vtfree(p);
p = smprint("#s/%s", name);
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
- vtSetError("create %s: %r", p);
- vtMemFree(p);
+ werrstr("create %s: %r", p);
+ vtfree(p);
return -1;
}
}
@@ -45,8 +45,8 @@ srvFd(char* name, int mode, int fd, char** mntpnt)
n = snprint(buf, sizeof(buf), "%d", fd);
if(write(srvfd, buf, n) < 0){
close(srvfd);
- vtSetError("write %s: %r", p);
- vtMemFree(p);
+ werrstr("write %s: %r", p);
+ vtfree(p);
return -1;
}
@@ -69,9 +69,9 @@ srvFree(Srv* srv)
if(srv->srvfd != -1)
close(srv->srvfd);
- vtMemFree(srv->service);
- vtMemFree(srv->mntpnt);
- vtMemFree(srv);
+ vtfree(srv->service);
+ vtfree(srv->mntpnt);
+ vtfree(srv);
}
static Srv*
@@ -82,7 +82,7 @@ srvAlloc(char* service, int mode, int fd)
int srvfd;
char *mntpnt;
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
for(srv = sbox.head; srv != nil; srv = srv->next){
if(strcmp(srv->service, service) != 0)
continue;
@@ -92,8 +92,8 @@ srvAlloc(char* service, int mode, int fd)
*/
if((dir = dirfstat(srv->srvfd)) != nil){
free(dir);
- vtSetError("srv: already serving '%s'", service);
- vtUnlock(sbox.lock);
+ werrstr("srv: already serving '%s'", service);
+ wunlock(&sbox.lock);
return nil;
}
srvFree(srv);
@@ -101,14 +101,14 @@ srvAlloc(char* service, int mode, int fd)
}
if((srvfd = srvFd(service, mode, fd, &mntpnt)) < 0){
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
return nil;
}
close(fd);
- srv = vtMemAllocZ(sizeof(Srv));
+ srv = vtmallocz(sizeof(Srv));
srv->srvfd = srvfd;
- srv->service = vtStrDup(service);
+ srv->service = vtstrdup(service);
srv->mntpnt = mntpnt;
if(sbox.tail != nil){
@@ -120,7 +120,7 @@ srvAlloc(char* service, int mode, int fd)
srv->prev = nil;
}
sbox.tail = srv;
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
return srv;
}
@@ -168,7 +168,7 @@ cmdSrv(int argc, char* argv[])
}ARGEND
if(pflag && (conflags&ConNoPermCheck)){
- vtSetError("srv: cannot use -P with -p");
+ werrstr("srv: cannot use -P with -p");
return 0;
}
@@ -176,27 +176,27 @@ cmdSrv(int argc, char* argv[])
default:
return cliError(usage);
case 0:
- vtRLock(sbox.lock);
+ rlock(&sbox.lock);
for(srv = sbox.head; srv != nil; srv = srv->next)
consPrint("\t%s\t%d\n", srv->service, srv->srvfd);
- vtRUnlock(sbox.lock);
+ runlock(&sbox.lock);
return 1;
case 1:
if(!dflag)
break;
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
for(srv = sbox.head; srv != nil; srv = srv->next){
if(strcmp(srv->service, argv[0]) != 0)
continue;
srvFree(srv);
break;
}
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
if(srv == nil){
- vtSetError("srv: '%s' not found", argv[0]);
+ werrstr("srv: '%s' not found", argv[0]);
return 0;
}
@@ -204,7 +204,7 @@ cmdSrv(int argc, char* argv[])
}
if(pipe(fd) < 0){
- vtSetError("srv pipe: %r");
+ werrstr("srv pipe: %r");
return 0;
}
if((srv = srvAlloc(argv[0], mode, fd[0])) == nil){
@@ -223,9 +223,9 @@ cmdSrv(int argc, char* argv[])
}
if(r == 0){
close(fd[1]);
- vtLock(sbox.lock);
+ wlock(&sbox.lock);
srvFree(srv);
- vtUnlock(sbox.lock);
+ wunlock(&sbox.lock);
}
return r;
@@ -234,8 +234,6 @@ cmdSrv(int argc, char* argv[])
int
srvInit(void)
{
- sbox.lock = vtLockAlloc();
-
cliAddCmd("srv", cmdSrv);
return 1;
diff --git a/src/cmd/fossil/9user.c b/src/cmd/fossil/9user.c
index 98203d0b..f24ef4af 100644
--- a/src/cmd/fossil/9user.c
+++ b/src/cmd/fossil/9user.c
@@ -34,7 +34,7 @@ struct Ubox {
};
static struct {
- VtLock* lock;
+ RWLock lock;
Ubox* box;
} ubox;
@@ -83,7 +83,7 @@ _userByUid(Ubox* box, char* uid)
return u;
}
}
- vtSetError("uname: uid '%s' not found", uid);
+ werrstr("uname: uid '%s' not found", uid);
return nil;
}
@@ -93,13 +93,13 @@ unameByUid(char* uid)
User *u;
char *uname;
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
if((u = _userByUid(ubox.box, uid)) == nil){
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return nil;
}
- uname = vtStrDup(u->uname);
- vtRUnlock(ubox.lock);
+ uname = vtstrdup(u->uname);
+ runlock(&ubox.lock);
return uname;
}
@@ -115,7 +115,7 @@ _userByUname(Ubox* box, char* uname)
return u;
}
}
- vtSetError("uname: uname '%s' not found", uname);
+ werrstr("uname: uname '%s' not found", uname);
return nil;
}
@@ -125,13 +125,13 @@ uidByUname(char* uname)
User *u;
char *uid;
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
if((u = _userByUname(ubox.box, uname)) == nil){
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return nil;
}
- uid = vtStrDup(u->uid);
- vtRUnlock(ubox.lock);
+ uid = vtstrdup(u->uid);
+ runlock(&ubox.lock);
return uid;
}
@@ -182,9 +182,9 @@ groupWriteMember(char* uname)
* use this functionality, we could cache the write group lookup.
*/
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
ret = _groupMember(ubox.box, "write", uname, 1);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return ret;
}
@@ -202,14 +202,14 @@ _groupRemMember(Ubox* box, User* g, char* member)
}
if(i >= g->ngroup){
if(strcmp(g->uname, member) == 0)
- vtSetError("uname: '%s' always in own group", member);
+ werrstr("uname: '%s' always in own group", member);
else
- vtSetError("uname: '%s' not in group '%s'",
+ werrstr("uname: '%s' not in group '%s'",
member, g->uname);
return 0;
}
- vtMemFree(g->group[i]);
+ vtfree(g->group[i]);
box->len -= strlen(member);
if(g->ngroup > 1)
@@ -217,14 +217,14 @@ _groupRemMember(Ubox* box, User* g, char* member)
g->ngroup--;
switch(g->ngroup){
case 0:
- vtMemFree(g->group);
+ vtfree(g->group);
g->group = nil;
break;
default:
for(; i < g->ngroup; i++)
g->group[i] = g->group[i+1];
g->group[i] = nil; /* prevent accidents */
- g->group = vtMemRealloc(g->group, g->ngroup * sizeof(char*));
+ g->group = vtrealloc(g->group, g->ngroup * sizeof(char*));
break;
}
@@ -240,15 +240,15 @@ _groupAddMember(Ubox* box, User* g, char* member)
return 0;
if(_groupMember(box, g->uid, u->uname, 0)){
if(strcmp(g->uname, member) == 0)
- vtSetError("uname: '%s' always in own group", member);
+ werrstr("uname: '%s' always in own group", member);
else
- vtSetError("uname: '%s' already in group '%s'",
+ werrstr("uname: '%s' already in group '%s'",
member, g->uname);
return 0;
}
- g->group = vtMemRealloc(g->group, (g->ngroup+1)*sizeof(char*));
- g->group[g->ngroup] = vtStrDup(member);
+ g->group = vtrealloc(g->group, (g->ngroup+1)*sizeof(char*));
+ g->group[g->ngroup] = vtstrdup(member);
box->len += strlen(member);
g->ngroup++;
if(g->ngroup > 1)
@@ -265,9 +265,9 @@ groupMember(char* group, char* member)
if(group == nil)
return 0;
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
r = _groupMember(ubox.box, group, member, 0);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return r;
}
@@ -286,21 +286,21 @@ groupLeader(char* group, char* member)
if(strcmp(member, unamenone) == 0 || group == nil)
return 0;
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
if((g = _userByUid(ubox.box, group)) == nil){
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return 0;
}
if(g->leader != nil){
if(strcmp(g->leader, member) == 0){
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return 1;
}
r = 0;
}
else
r = _groupMember(ubox.box, group, member, 0);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return r;
}
@@ -310,16 +310,16 @@ userFree(User* u)
{
int i;
- vtMemFree(u->uid);
- vtMemFree(u->uname);
+ vtfree(u->uid);
+ vtfree(u->uname);
if(u->leader != nil)
- vtMemFree(u->leader);
+ vtfree(u->leader);
if(u->ngroup){
for(i = 0; i < u->ngroup; i++)
- vtMemFree(u->group[i]);
- vtMemFree(u->group);
+ vtfree(u->group[i]);
+ vtfree(u->group);
}
- vtMemFree(u);
+ vtfree(u);
}
static User*
@@ -327,9 +327,9 @@ userAlloc(char* uid, char* uname)
{
User *u;
- u = vtMemAllocZ(sizeof(User));
- u->uid = vtStrDup(uid);
- u->uname = vtStrDup(uname);
+ u = vtmallocz(sizeof(User));
+ u->uid = vtstrdup(uid);
+ u->uname = vtstrdup(uname);
return u;
}
@@ -404,7 +404,7 @@ usersFileWrite(Ubox* box)
if(!fileTruncate(file, uidadm))
goto tidy;
- p = s = vtMemAlloc(box->len+1);
+ p = s = vtmalloc(box->len+1);
q = p + box->len+1;
for(u = box->head; u != nil; u = u->next){
p += snprint(p, q-p, "%s:%s:", u->uid, u->uname);
@@ -419,7 +419,7 @@ usersFileWrite(Ubox* box)
p += snprint(p, q-p, "\n");
}
r = fileWrite(file, s, box->len, 0, uidadm);
- vtMemFree(s);
+ vtfree(s);
tidy:
if(file != nil)
@@ -506,7 +506,7 @@ uboxFree(Ubox* box)
next = u->next;
userFree(u);
}
- vtMemFree(box);
+ vtfree(box);
}
static int
@@ -525,7 +525,7 @@ uboxInit(char* users, int len)
blank = 1;
comment = nline = 0;
- s = p = buf = vtMemAlloc(len+1);
+ s = p = buf = vtmalloc(len+1);
for(q = users; *q != '\0'; q++){
if(*q == '\r' || *q == '\t' || *q == ' ')
continue;
@@ -549,18 +549,18 @@ uboxInit(char* users, int len)
}
*p = '\0';
- line = vtMemAllocZ((nline+2)*sizeof(char*));
+ line = vtmallocz((nline+2)*sizeof(char*));
if((i = gettokens(buf, line, nline+2, "\n")) != nline){
fprint(2, "nline %d (%d) botch\n", nline, i);
- vtMemFree(line);
- vtMemFree(buf);
+ vtfree(line);
+ vtfree(buf);
return 0;
}
/*
* Everything is updated in a local Ubox until verified.
*/
- box = vtMemAllocZ(sizeof(Ubox));
+ box = vtmallocz(sizeof(Ubox));
/*
* First pass - check format, check for duplicates
@@ -568,35 +568,35 @@ uboxInit(char* users, int len)
*/
nuser = 0;
for(i = 0; i < nline; i++){
- s = vtStrDup(line[i]);
+ s = vtstrdup(line[i]);
if(getfields(s, f, nelem(f), 0, ":") != 4){
fprint(2, "bad line '%s'\n", line[i]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
if(*f[0] == '\0' || *f[1] == '\0'){
fprint(2, "bad line '%s'\n", line[i]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
if(!validUserName(f[0])){
fprint(2, "invalid uid '%s'\n", f[0]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
if(_userByUid(box, f[0]) != nil){
fprint(2, "duplicate uid '%s'\n", f[0]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
if(!validUserName(f[1])){
fprint(2, "invalid uname '%s'\n", f[0]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
if(_userByUname(box, f[1]) != nil){
fprint(2, "duplicate uname '%s'\n", f[1]);
- vtMemFree(s);
+ vtfree(s);
continue;
}
@@ -605,7 +605,7 @@ uboxInit(char* users, int len)
line[nuser] = line[i];
nuser++;
- vtMemFree(s);
+ vtfree(s);
}
assert(box->nuser == nuser);
@@ -613,15 +613,15 @@ uboxInit(char* users, int len)
* Second pass - fill in leader and group information.
*/
for(i = 0; i < nuser; i++){
- s = vtStrDup(line[i]);
+ s = vtstrdup(line[i]);
getfields(s, f, nelem(f), 0, ":");
assert(g = _userByUname(box, f[1]));
if(*f[2] != '\0'){
if((u = _userByUname(box, f[2])) == nil)
- g->leader = vtStrDup(g->uname);
+ g->leader = vtstrdup(g->uname);
else
- g->leader = vtStrDup(u->uname);
+ g->leader = vtstrdup(u->uname);
box->len += strlen(g->leader);
}
for(p = f[3]; p != nil; p = q){
@@ -632,30 +632,30 @@ uboxInit(char* users, int len)
}
}
- vtMemFree(s);
+ vtfree(s);
}
- vtMemFree(line);
- vtMemFree(buf);
+ vtfree(line);
+ vtfree(buf);
for(i = 0; usersMandatory[i] != nil; i++){
if((u = _userByUid(box, usersMandatory[i])) == nil){
- vtSetError("user '%s' is mandatory", usersMandatory[i]);
+ werrstr("user '%s' is mandatory", usersMandatory[i]);
uboxFree(box);
return 0;
}
if(strcmp(u->uid, u->uname) != 0){
- vtSetError("uid/uname for user '%s' must match",
+ werrstr("uid/uname for user '%s' must match",
usersMandatory[i]);
uboxFree(box);
return 0;
}
}
- vtLock(ubox.lock);
+ wlock(&ubox.lock);
obox = ubox.box;
ubox.box = box;
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
if(obox != nil)
uboxFree(obox);
@@ -683,7 +683,7 @@ usersFileRead(char* path)
if((file = fileOpen(fsysGetFs(fsys), path)) != nil){
if(fileGetSize(file, &size)){
len = size;
- p = vtMemAlloc(size+1);
+ p = vtmalloc(size+1);
if(fileRead(file, p, len, 0) == len){
p[len] = '\0';
r = uboxInit(p, len);
@@ -720,9 +720,9 @@ cmdUname(int argc, char* argv[])
if(argc < 1){
if(!dflag)
return cliError(usage);
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
uboxDump(ubox.box);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return 1;
}
@@ -730,37 +730,37 @@ cmdUname(int argc, char* argv[])
argc--; argv++;
if(argc == 0){
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
if((u = _userByUname(ubox.box, uname)) == nil){
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return 0;
}
consPrint("\t%U\n", u);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return 1;
}
- vtLock(ubox.lock);
+ wlock(&ubox.lock);
u = _userByUname(ubox.box, uname);
while(argc--){
if(argv[0][0] == '%'){
if(u == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
p = &argv[0][1];
if((up = _userByUname(ubox.box, p)) != nil){
- vtSetError("uname: uname '%s' already exists",
+ werrstr("uname: uname '%s' already exists",
up->uname);
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
for(i = 0; usersMandatory[i] != nil; i++){
if(strcmp(usersMandatory[i], uname) != 0)
continue;
- vtSetError("uname: uname '%s' is mandatory",
+ werrstr("uname: uname '%s' is mandatory",
uname);
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
@@ -768,80 +768,80 @@ cmdUname(int argc, char* argv[])
for(up = ubox.box->head; up != nil; up = up->next){
if(up->leader != nil){
if(strcmp(up->leader, u->uname) == 0){
- vtMemFree(up->leader);
- up->leader = vtStrDup(p);
+ vtfree(up->leader);
+ up->leader = vtstrdup(p);
ubox.box->len += d;
}
}
for(i = 0; i < up->ngroup; i++){
if(strcmp(up->group[i], u->uname) != 0)
continue;
- vtMemFree(up->group[i]);
- up->group[i] = vtStrDup(p);
+ vtfree(up->group[i]);
+ up->group[i] = vtstrdup(p);
ubox.box->len += d;
break;
}
}
uboxRemUser(ubox.box, u);
- vtMemFree(u->uname);
- u->uname = vtStrDup(p);
+ vtfree(u->uname);
+ u->uname = vtstrdup(p);
uboxAddUser(ubox.box, u);
}
else if(argv[0][0] == '='){
if(u == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
if(argv[0][1] != '\0'){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
}
if(u->leader != nil){
ubox.box->len -= strlen(u->leader);
- vtMemFree(u->leader);
+ vtfree(u->leader);
u->leader = nil;
}
if(up != nil){
- u->leader = vtStrDup(up->uname);
+ u->leader = vtstrdup(up->uname);
ubox.box->len += strlen(u->leader);
}
}
else if(argv[0][0] == '+'){
if(u == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if(!_groupAddMember(ubox.box, u, up->uname)){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
}
else if(argv[0][0] == '-'){
if(u == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if(!_groupRemMember(ubox.box, u, up->uname)){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
}
else{
if(u != nil){
- vtSetError("uname: uname '%s' already exists",
+ werrstr("uname: uname '%s' already exists",
u->uname);
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
@@ -849,9 +849,9 @@ cmdUname(int argc, char* argv[])
if(*uid == ':')
uid++;
if((u = _userByUid(ubox.box, uid)) != nil){
- vtSetError("uname: uid '%s' already exists",
+ werrstr("uname: uid '%s' already exists",
u->uid);
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
@@ -861,9 +861,9 @@ cmdUname(int argc, char* argv[])
// should have an option for the mode and gid
p = smprint(createfmt, uname, uname, uname);
r = cliExec(p);
- vtMemFree(p);
+ vtfree(p);
if(r == 0){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
}
@@ -872,12 +872,12 @@ cmdUname(int argc, char* argv[])
}
if(usersFileWrite(ubox.box) == 0){
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 0;
}
if(dflag)
uboxDump(ubox.box);
- vtUnlock(ubox.lock);
+ wunlock(&ubox.lock);
return 1;
}
@@ -922,14 +922,14 @@ cmdUsers(int argc, char* argv[])
return 0;
}
- vtRLock(ubox.lock);
+ rlock(&ubox.lock);
box = ubox.box;
consPrint("\tnuser %d len %d\n", box->nuser, box->len);
r = 1;
if(wflag)
r = usersFileWrite(box);
- vtRUnlock(ubox.lock);
+ runlock(&ubox.lock);
return r;
}
@@ -938,7 +938,6 @@ usersInit(void)
{
fmtinstall('U', userFmt);
- ubox.lock = vtLockAlloc();
uboxInit(usersDefault, sizeof(usersDefault));
cliAddCmd("users", cmdUsers);
diff --git a/src/cmd/fossil/Ccli.c b/src/cmd/fossil/Ccli.c
index 775cb620..52a91474 100644
--- a/src/cmd/fossil/Ccli.c
+++ b/src/cmd/fossil/Ccli.c
@@ -8,7 +8,7 @@ typedef struct {
} Cmd;
static struct {
- VtLock* lock;
+ QLock lock;
Cmd* cmd;
int ncmd;
int hi;
@@ -26,7 +26,7 @@ cliError(char* fmt, ...)
va_start(arg, fmt);
p = vsmprint(fmt, arg);
- vtSetError("%s", p);
+ werrstr("%s", p);
free(p);
va_end(arg);
@@ -39,32 +39,32 @@ cliExec(char* buf)
int argc, i, r;
char *argv[20], *p;
- p = vtStrDup(buf);
+ p = vtstrdup(buf);
if((argc = tokenize(p, argv, nelem(argv)-1)) == 0){
- vtMemFree(p);
+ vtfree(p);
return 1;
}
argv[argc] = 0;
if(argv[0][0] == '#'){
- vtMemFree(p);
+ vtfree(p);
return 1;
}
- vtLock(cbox.lock);
+ qlock(&cbox.lock);
for(i = 0; i < cbox.hi; i++){
if(strcmp(cbox.cmd[i].argv0, argv[0]) == 0){
- vtUnlock(cbox.lock);
+ qunlock(&cbox.lock);
if(!(r = cbox.cmd[i].cmd(argc, argv)))
- consPrint("%s\n", vtGetError());
- vtMemFree(p);
+ consPrint("%r\n");
+ vtfree(p);
return r;
}
}
- vtUnlock(cbox.lock);
+ qunlock(&cbox.lock);
consPrint("%s: - eh?\n", argv[0]);
- vtMemFree(p);
+ vtfree(p);
return 0;
}
@@ -75,16 +75,16 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
int i;
Cmd *opt;
- vtLock(cbox.lock);
+ qlock(&cbox.lock);
for(i = 0; i < cbox.hi; i++){
if(strcmp(argv0, cbox.cmd[i].argv0) == 0){
- vtUnlock(cbox.lock);
+ qunlock(&cbox.lock);
return 0;
}
}
if(i >= cbox.hi){
if(cbox.hi >= cbox.ncmd){
- cbox.cmd = vtMemRealloc(cbox.cmd,
+ cbox.cmd = vtrealloc(cbox.cmd,
(cbox.ncmd+NCmdIncr)*sizeof(Cmd));
memset(&cbox.cmd[cbox.ncmd], 0, NCmdIncr*sizeof(Cmd));
cbox.ncmd += NCmdIncr;
@@ -95,7 +95,7 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
opt->argv0 = argv0;
opt->cmd = cmd;
cbox.hi++;
- vtUnlock(cbox.lock);
+ qunlock(&cbox.lock);
return 1;
}
@@ -103,8 +103,7 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
int
cliInit(void)
{
- cbox.lock = vtLockAlloc();
- cbox.cmd = vtMemAllocZ(NCmdIncr*sizeof(Cmd));
+ cbox.cmd = vtmallocz(NCmdIncr*sizeof(Cmd));
cbox.ncmd = NCmdIncr;
cbox.hi = 0;
diff --git a/src/cmd/fossil/Ccmd.c b/src/cmd/fossil/Ccmd.c
index 806c62ff..3e062889 100644
--- a/src/cmd/fossil/Ccmd.c
+++ b/src/cmd/fossil/Ccmd.c
@@ -3,7 +3,7 @@
#include "9.h"
static struct {
- VtLock* lock;
+ QLock lock;
Con* con;
int confd[2];
@@ -53,7 +53,7 @@ cmd9pTwstat(Fcall* f, int, char **argv)
f->stat = buf;
f->nstat = convD2M(&d, buf, sizeof buf);
if(f->nstat < BIT16SZ){
- vtSetError("Twstat: convD2M failed (internal error)");
+ werrstr("Twstat: convD2M failed (internal error)");
return 0;
}
@@ -131,14 +131,14 @@ cmd9pTwalk(Fcall* f, int argc, char** argv)
int i;
if(argc < 2){
- vtSetError("usage: Twalk tag fid newfid [name...]");
+ werrstr("usage: Twalk tag fid newfid [name...]");
return 0;
}
f->fid = strtol(argv[0], 0, 0);
f->newfid = strtol(argv[1], 0, 0);
f->nwname = argc-2;
if(f->nwname > MAXWELEM){
- vtSetError("Twalk: too many names");
+ werrstr("Twalk: too many names");
return 0;
}
for(i = 0; i < argc-2; i++)
@@ -181,7 +181,7 @@ cmd9pTversion(Fcall* f, int, char** argv)
{
f->msize = strtoul(argv[0], 0, 0);
if(f->msize > cbox.con->msize){
- vtSetError("msize too big");
+ werrstr("msize too big");
return 0;
}
f->version = argv[1];
@@ -242,7 +242,7 @@ cmd9p(int argc, char* argv[])
argc--;
argv++;
if(cmd9pTmsg[i].argc && argc != cmd9pTmsg[i].argc){
- vtSetError("usage: %s %s",
+ werrstr("usage: %s %s",
cmd9pTmsg[i].name, cmd9pTmsg[i].usage);
return 0;
}
@@ -256,33 +256,33 @@ cmd9p(int argc, char* argv[])
msize = cbox.con->msize;
if(!cmd9pTmsg[i].f(&t, argc, argv))
return 0;
- buf = vtMemAlloc(msize);
+ buf = vtmalloc(msize);
n = convS2M(&t, buf, msize);
if(n <= BIT16SZ){
- vtSetError("%s: convS2M error", cmd9pTmsg[i].name);
- vtMemFree(buf);
+ werrstr("%s: convS2M error", cmd9pTmsg[i].name);
+ vtfree(buf);
return 0;
}
if(write(cbox.confd[0], buf, n) != n){
- vtSetError("%s: write error: %r", cmd9pTmsg[i].name);
- vtMemFree(buf);
+ werrstr("%s: write error: %r", cmd9pTmsg[i].name);
+ vtfree(buf);
return 0;
}
consPrint("\t-> %F\n", &t);
if((n = read9pmsg(cbox.confd[0], buf, msize)) <= 0){
- vtSetError("%s: read error: %r", cmd9pTmsg[i].name);
- vtMemFree(buf);
+ werrstr("%s: read error: %r", cmd9pTmsg[i].name);
+ vtfree(buf);
return 0;
}
if(convM2S(buf, n, &f) == 0){
- vtSetError("%s: convM2S error", cmd9pTmsg[i].name);
- vtMemFree(buf);
+ werrstr("%s: convM2S error", cmd9pTmsg[i].name);
+ vtfree(buf);
return 0;
}
consPrint("\t<- %F\n", &f);
- vtMemFree(buf);
+ vtfree(buf);
return 1;
}
@@ -316,9 +316,9 @@ cmdDot(int argc, char* argv[])
*/
if((fd = open(argv[0], OREAD)) < 0)
return cliError(". open %s: %r", argv[0]);
- f = vtMemAlloc(dir->length+1);
+ f = vtmalloc(dir->length+1);
if((l = read(fd, f, length)) < 0){
- vtMemFree(f);
+ vtfree(f);
close(fd);
return cliError(". read %s: %r", argv[0]);
}
@@ -333,16 +333,16 @@ cmdDot(int argc, char* argv[])
*p = '\0';
if(cliExec(s) == 0){
r = 0;
- consPrint("%s: %R\n", s);
+ consPrint("%s: %r\n", s);
}
s = p+1;
}
}
- vtMemFree(f);
+ vtfree(f);
}
if(r == 0)
- vtSetError("errors in . %#q", argv[0]);
+ werrstr("errors in . %#q", argv[0]);
return r;
}
@@ -435,7 +435,6 @@ cmdBind(int argc, char* argv[])
int
cmdInit(void)
{
- cbox.lock = vtLockAlloc();
cbox.confd[0] = cbox.confd[1] = -1;
cliAddCmd(".", cmdDot);
diff --git a/src/cmd/fossil/Ccons.c b/src/cmd/fossil/Ccons.c
index 65b9a409..afa02561 100644
--- a/src/cmd/fossil/Ccons.c
+++ b/src/cmd/fossil/Ccons.c
@@ -8,9 +8,9 @@ enum {
};
typedef struct Q {
- VtLock* lock;
- VtRendez* full;
- VtRendez* empty;
+ QLock lock;
+ Rendez full;
+ Rendez empty;
char q[Nq];
int n;
@@ -19,7 +19,7 @@ typedef struct Q {
} Q;
typedef struct Cons {
- VtLock* lock;
+ QLock lock;
int ref;
int closed;
int fd;
@@ -45,18 +45,18 @@ static struct {
static void
consClose(Cons* cons)
{
- vtLock(cons->lock);
+ qlock(&cons->lock);
cons->closed = 1;
cons->ref--;
if(cons->ref > 0){
- vtLock(cons->iq->lock);
- vtWakeup(cons->iq->full);
- vtUnlock(cons->iq->lock);
- vtLock(cons->oq->lock);
- vtWakeup(cons->oq->empty);
- vtUnlock(cons->oq->lock);
- vtUnlock(cons->lock);
+ qlock(&cons->iq->lock);
+ rwakeup(&cons->iq->full);
+ qunlock(&cons->iq->lock);
+ qlock(&cons->oq->lock);
+ rwakeup(&cons->oq->empty);
+ qunlock(&cons->oq->lock);
+ qunlock(&cons->lock);
return;
}
@@ -72,9 +72,8 @@ consClose(Cons* cons)
close(cons->fd);
cons->fd = -1;
}
- vtUnlock(cons->lock);
- vtLockFree(cons->lock);
- vtMemFree(cons);
+ qunlock(&cons->lock);
+ vtfree(cons);
console.nopens--;
}
@@ -86,7 +85,7 @@ consIProc(void* v)
int n, w;
char buf[Nq/4];
- vtThreadSetName("consI");
+ threadsetname("consI");
cons = v;
q = cons->iq;
@@ -97,9 +96,9 @@ consIProc(void* v)
*/
if(cons->closed || (n = read(cons->fd, buf, Nq/4)) < 0)
break;
- vtLock(q->lock);
+ qlock(&q->lock);
while(Nq - q->n < n && !cons->closed)
- vtSleep(q->full);
+ rsleep(&q->full);
w = Nq - q->w;
if(w < n){
memmove(&q->q[q->w], buf, w);
@@ -109,8 +108,8 @@ consIProc(void* v)
memmove(&q->q[q->w], buf, n);
q->w = (q->w + n) % Nq;
q->n += n;
- vtWakeup(q->empty);
- vtUnlock(q->lock);
+ rwakeup(&q->empty);
+ qunlock(&q->lock);
}
consClose(cons);
}
@@ -123,15 +122,15 @@ consOProc(void* v)
char buf[Nq];
int lastn, n, r;
- vtThreadSetName("consO");
+ threadsetname("consO");
cons = v;
q = cons->oq;
- vtLock(q->lock);
+ qlock(&q->lock);
lastn = 0;
for(;;){
while(lastn == q->n && !cons->closed)
- vtSleep(q->empty);
+ rsleep(&q->empty);
if((n = q->n - lastn) > Nq)
n = Nq;
if(n > q->w){
@@ -142,11 +141,11 @@ consOProc(void* v)
else
memmove(buf, &q->q[q->w - n], n);
lastn = q->n;
- vtUnlock(q->lock);
+ qunlock(&q->lock);
if(cons->closed || write(cons->fd, buf, n) < 0)
break;
- vtLock(q->lock);
- vtWakeup(q->empty);
+ qlock(&q->lock);
+ rwakeup(&q->empty);
}
consClose(cons);
}
@@ -156,8 +155,7 @@ consOpen(int fd, int srvfd, int ctlfd)
{
Cons *cons;
- cons = vtMemAllocZ(sizeof(Cons));
- cons->lock = vtLockAlloc();
+ cons = vtmallocz(sizeof(Cons));
cons->fd = fd;
cons->srvfd = srvfd;
cons->ctlfd = ctlfd;
@@ -165,20 +163,20 @@ consOpen(int fd, int srvfd, int ctlfd)
cons->oq = console.oq;
console.nopens++;
- vtLock(cons->lock);
+ qlock(&cons->lock);
cons->ref = 2;
cons->closed = 0;
- if(vtThread(consOProc, cons) < 0){
+ if(proccreate(consOProc, cons, STACK) < 0){
cons->ref--;
- vtUnlock(cons->lock);
+ qunlock(&cons->lock);
consClose(cons);
return 0;
}
- vtUnlock(cons->lock);
+ qunlock(&cons->lock);
if(ctlfd >= 0)
consIProc(cons);
- else if(vtThread(consIProc, cons) < 0){
+ else if(proccreate(consIProc, cons, STACK) < 0){
consClose(cons);
return 0;
}
@@ -191,7 +189,7 @@ qWrite(Q* q, char* p, int n)
{
int w;
- vtLock(q->lock);
+ qlock(&q->lock);
if(n > Nq - q->w){
w = Nq - q->w;
memmove(&q->q[q->w], p, w);
@@ -203,8 +201,8 @@ qWrite(Q* q, char* p, int n)
q->w += n;
}
q->n += n;
- vtWakeup(q->empty);
- vtUnlock(q->lock);
+ rwakeup(&q->empty);
+ qunlock(&q->lock);
return n;
}
@@ -214,10 +212,9 @@ qAlloc(void)
{
Q *q;
- q = vtMemAllocZ(sizeof(Q));
- q->lock = vtLockAlloc();
- q->full = vtRendezAlloc(q->lock);
- q->empty = vtRendezAlloc(q->lock);
+ q = vtmallocz(sizeof(Q));
+ q->full.l = &q->lock;
+ q->empty.l = &q->lock;
q->n = q->r = q->w = 0;
return q;
@@ -232,14 +229,14 @@ consProc(void*)
char procname[64];
snprint(procname, sizeof procname, "cons %s", currfsysname);
- vtThreadSetName(procname);
+ threadsetname(procname);
q = console.iq;
qWrite(console.oq, console.prompt, console.np);
- vtLock(q->lock);
+ qlock(&q->lock);
for(;;){
while((n = q->n) == 0)
- vtSleep(q->empty);
+ rsleep(&q->empty);
r = Nq - q->r;
if(r < n){
memmove(buf, &q->q[q->r], r);
@@ -249,8 +246,8 @@ consProc(void*)
memmove(buf, &q->q[q->r], n);
q->r = (q->r + n) % Nq;
q->n -= n;
- vtWakeup(q->full);
- vtUnlock(q->lock);
+ rwakeup(&q->full);
+ qunlock(&q->lock);
for(i = 0; i < n; i++){
switch(buf[i]){
@@ -281,7 +278,7 @@ consProc(void*)
break;
case '\027': /* ^W */
console.l[console.nl] = '\0';
- wbuf = vtMemAlloc(console.nl+1);
+ wbuf = vtmalloc(console.nl+1);
memmove(wbuf, console.l, console.nl+1);
argc = tokenize(wbuf, argv, nelem(argv));
if(argc > 0)
@@ -291,7 +288,7 @@ consProc(void*)
for(i = 0; i < argc; i++)
lp += sprint(lp, "%q ", argv[i]);
console.nl = lp - console.l;
- vtMemFree(wbuf);
+ vtfree(wbuf);
qWrite(console.oq, "^W\n", 3);
if(console.nl == 0)
break;
@@ -311,7 +308,7 @@ consProc(void*)
qWrite(console.oq, console.prompt, console.np);
}
- vtLock(q->lock);
+ qlock(&q->lock);
}
}
@@ -333,9 +330,9 @@ consPrompt(char* prompt)
if(prompt == nil)
prompt = "prompt";
- vtMemFree(console.prompt);
+ vtfree(console.prompt);
console.np = snprint(buf, sizeof(buf), "%s: ", prompt);
- console.prompt = vtStrDup(buf);
+ console.prompt = vtstrdup(buf);
return console.np;
}
@@ -350,7 +347,7 @@ consTTY(void)
if((fd = open(name, ORDWR)) < 0){
name = "#c/cons";
if((fd = open(name, ORDWR)) < 0){
- vtSetError("consTTY: open %s: %r", name);
+ werrstr("consTTY: open %s: %r", name);
return 0;
}
}
@@ -358,14 +355,14 @@ consTTY(void)
p = smprint("%sctl", name);
if((ctl = open(p, OWRITE)) < 0){
close(fd);
- vtSetError("consTTY: open %s: %r", p);
+ werrstr("consTTY: open %s: %r", p);
free(p);
return 0;
}
if(write(ctl, "rawon", 5) < 0){
close(ctl);
close(fd);
- vtSetError("consTTY: write %s: %r", p);
+ werrstr("consTTY: write %s: %r", p);
free(p);
return 0;
}
@@ -389,8 +386,8 @@ consInit(void)
consPrompt(nil);
- if(vtThread(consProc, nil) < 0){
- vtFatal("can't start console proc");
+ if(proccreate(consProc, nil, STACK) < 0){
+ sysfatal("can't start console proc");
return 0;
}
diff --git a/src/cmd/fossil/archive.c b/src/cmd/fossil/archive.c
index fc09e719..e862f70a 100644
--- a/src/cmd/fossil/archive.c
+++ b/src/cmd/fossil/archive.c
@@ -20,29 +20,28 @@ struct Arch
uint diskSize;
Cache *c;
Fs *fs;
- VtSession *z;
+ VtConn *z;
- VtLock *lk;
- VtRendez *starve;
- VtRendez *die;
+ QLock lk;
+ Rendez starve;
+ Rendez die;
};
Arch *
-archInit(Cache *c, Disk *disk, Fs *fs, VtSession *z)
+archInit(Cache *c, Disk *disk, Fs *fs, VtConn *z)
{
Arch *a;
- a = vtMemAllocZ(sizeof(Arch));
+ a = vtmallocz(sizeof(Arch));
a->c = c;
a->z = z;
a->fs = fs;
a->blockSize = diskBlockSize(disk);
- a->lk = vtLockAlloc();
- a->starve = vtRendezAlloc(a->lk);
+ a->starve.l = &a->lk;
a->ref = 2;
- vtThread(archThread, a);
+ proccreate(archThread, a, STACK);
return a;
}
@@ -51,16 +50,13 @@ void
archFree(Arch *a)
{
/* kill slave */
- vtLock(a->lk);
- a->die = vtRendezAlloc(a->lk);
- vtWakeup(a->starve);
+ qlock(&a->lk);
+ a->die.l = &a->lk;
+ rwakeup(&a->starve);
while(a->ref > 1)
- vtSleep(a->die);
- vtUnlock(a->lk);
- vtRendezFree(a->starve);
- vtRendezFree(a->die);
- vtLockFree(a->lk);
- vtMemFree(a);
+ rsleep(&a->die);
+ qunlock(&a->lk);
+ vtfree(a);
}
static int
@@ -71,21 +67,21 @@ ventiSend(Arch *a, Block *b, uchar *data)
if(DEBUG > 1)
fprint(2, "ventiSend: sending %#ux %L to venti\n", b->addr, &b->l);
- n = vtZeroTruncate(vtType[b->l.type], data, a->blockSize);
+ n = vtzerotruncate(vtType[b->l.type], data, a->blockSize);
if(DEBUG > 1)
fprint(2, "ventiSend: truncate %d to %d\n", a->blockSize, n);
- if(!vtWrite(a->z, score, vtType[b->l.type], data, n)){
- fprint(2, "ventiSend: vtWrite block %#ux failed: %R\n", b->addr);
+ if(vtwrite(a->z, score, vtType[b->l.type], data, n) < 0){
+ fprint(2, "ventiSend: vtwrite block %#ux failed: %r\n", b->addr);
return 0;
}
- if(!vtSha1Check(score, data, n)){
+ if(vtsha1check(score, data, n) < 0){
uchar score2[VtScoreSize];
- vtSha1(score2, data, n);
- fprint(2, "ventiSend: vtWrite block %#ux failed vtSha1Check %V %V\n",
+ vtsha1(score2, data, n);
+ fprint(2, "ventiSend: vtwrite block %#ux failed vtsha1check %V %V\n",
b->addr, score, score2);
return 0;
}
- if(!vtSync(a->z))
+ if(vtsync(a->z) < 0)
return 0;
return 1;
}
@@ -129,7 +125,7 @@ struct Param
static void
shaBlock(uchar score[VtScoreSize], Block *b, uchar *data, uint bsize)
{
- vtSha1(score, data, vtZeroTruncate(vtType[b->l.type], data, bsize));
+ vtsha1(score, data, vtzerotruncate(vtType[b->l.type], data, bsize));
}
static uint
@@ -137,7 +133,7 @@ etype(Entry *e)
{
uint t;
- if(e->flags&VtEntryDir)
+ if(e->flags&_VtEntryDir)
t = BtDir;
else
t = BtData;
@@ -149,7 +145,7 @@ copyBlock(Block *b, u32int blockSize)
{
uchar *data;
- data = vtMemAlloc(blockSize);
+ data = vtmalloc(blockSize);
if(data == nil)
return nil;
memmove(data, b->data, blockSize);
@@ -183,15 +179,17 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
Label l;
Entry *e;
WalkPtr w;
+ char err[ERRMAX];
p->nvisit++;
b = cacheLocalData(p->c, addr, type, tag, OReadWrite,0);
if(b == nil){
- fprint(2, "archive(%ud, %#ux): cannot find block: %R\n", p->snapEpoch, addr);
- if(strcmp(vtGetError(), ELabelMismatch) == 0){
+ fprint(2, "archive(%ud, %#ux): cannot find block: %r\n", p->snapEpoch, addr);
+ rerrstr(err, sizeof err);
+ if(strcmp(err, ELabelMismatch) == 0){
/* might as well plod on so we write _something_ to Venti */
- memmove(p->score, vtZeroScore, VtScoreSize);
+ memmove(p->score, vtzeroscore, VtScoreSize);
return ArchFaked;
}
return ArchFailure;
@@ -221,7 +219,7 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
}
w.data = data;
}
- memmove(e->score, vtZeroScore, VtScoreSize);
+ memmove(e->score, vtzeroscore, VtScoreSize);
e->depth = 0;
e->size = 0;
e->tag = 0;
@@ -239,15 +237,15 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
p->dsize= e->dsize;
p->psize = e->psize;
}
- vtUnlock(b->lk);
+ qunlock(&b->lk);
x = archWalk(p, addr, type, tag);
- vtLock(b->lk);
+ qlock(&b->lk);
if(e){
p->dsize = dsize;
p->psize = psize;
}
while(b->iostate != BioClean && b->iostate != BioDirty)
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
switch(x){
case ArchFailure:
fprint(2, "archWalk %#ux failed; ptr is in %#ux offset %d\n",
@@ -331,7 +329,7 @@ if(0) fprint(2, "ventisend %V %p %p %p\n", p->score, data, b->data, w.data);
p->l = b->l;
Out:
if(data != b->data)
- vtMemFree(data);
+ vtfree(data);
p->depth--;
blockPut(b);
return ret;
@@ -349,15 +347,15 @@ archThread(void *v)
uchar rbuf[VtRootSize];
VtRoot root;
- vtThreadSetName("arch");
+ threadsetname("arch");
for(;;){
/* look for work */
- vtLock(a->fs->elk);
+ wlock(&a->fs->elk);
b = superGet(a->c, &super);
if(b == nil){
- vtUnlock(a->fs->elk);
- fprint(2, "archThread: superGet: %R\n");
+ wunlock(&a->fs->elk);
+ fprint(2, "archThread: superGet: %r\n");
sleep(60*1000);
continue;
}
@@ -370,15 +368,15 @@ archThread(void *v)
}else
addr = super.current;
blockPut(b);
- vtUnlock(a->fs->elk);
+ wunlock(&a->fs->elk);
if(addr == NilBlock){
/* wait for work */
- vtLock(a->lk);
- vtSleep(a->starve);
- if(a->die != nil)
+ qlock(&a->lk);
+ rsleep(&a->starve);
+ if(a->die.l != nil)
goto Done;
- vtUnlock(a->lk);
+ qunlock(&a->lk);
continue;
}
@@ -396,7 +394,7 @@ sleep(10*1000); /* window of opportunity to provoke races */
default:
abort();
case ArchFailure:
- fprint(2, "archiveBlock %#ux: %R\n", addr);
+ fprint(2, "archiveBlock %#ux: %r\n", addr);
sleep(60*1000);
continue;
case ArchSuccess:
@@ -414,26 +412,25 @@ sleep(10*1000); /* window of opportunity to provoke races */
/* tie up vac root */
memset(&root, 0, sizeof root);
- root.version = VtRootVersion;
strecpy(root.type, root.type+sizeof root.type, "vac");
strecpy(root.name, root.name+sizeof root.name, "fossil");
memmove(root.score, p.score, VtScoreSize);
memmove(root.prev, super.last, VtScoreSize);
- root.blockSize = a->blockSize;
- vtRootPack(&root, rbuf);
- if(!vtWrite(a->z, p.score, VtRootType, rbuf, VtRootSize)
- || !vtSha1Check(p.score, rbuf, VtRootSize)){
- fprint(2, "vtWriteBlock %#ux: %R\n", addr);
+ root.blocksize = a->blockSize;
+ vtrootpack(&root, rbuf);
+ if(vtwrite(a->z, p.score, VtRootType, rbuf, VtRootSize) < 0
+ || vtsha1check(p.score, rbuf, VtRootSize) < 0){
+ fprint(2, "vtWriteBlock %#ux: %r\n", addr);
sleep(60*1000);
continue;
}
/* record success */
- vtLock(a->fs->elk);
+ wlock(&a->fs->elk);
b = superGet(a->c, &super);
if(b == nil){
- vtUnlock(a->fs->elk);
- fprint(2, "archThread: superGet: %R\n");
+ wunlock(&a->fs->elk);
+ fprint(2, "archThread: superGet: %r\n");
sleep(60*1000);
continue;
}
@@ -442,15 +439,15 @@ sleep(10*1000); /* window of opportunity to provoke races */
superPack(&super, b->data);
blockDirty(b);
blockPut(b);
- vtUnlock(a->fs->elk);
+ wunlock(&a->fs->elk);
consPrint("archive vac:%V\n", p.score);
}
Done:
a->ref--;
- vtWakeup(a->die);
- vtUnlock(a->lk);
+ rwakeup(&a->die);
+ qunlock(&a->lk);
}
void
@@ -460,7 +457,7 @@ archKick(Arch *a)
fprint(2, "warning: archKick nil\n");
return;
}
- vtLock(a->lk);
- vtWakeup(a->starve);
- vtUnlock(a->lk);
+ qlock(&a->lk);
+ rwakeup(&a->starve);
+ qunlock(&a->lk);
}
diff --git a/src/cmd/fossil/bwatch.c b/src/cmd/fossil/bwatch.c
index 51deb762..8cd0956e 100644
--- a/src/cmd/fossil/bwatch.c
+++ b/src/cmd/fossil/bwatch.c
@@ -44,7 +44,7 @@ struct WEntry
struct WMap
{
- VtLock *lk;
+ QLock lk;
WEntry *hchild[HashSize];
WEntry *hparent[HashSize];
@@ -84,7 +84,7 @@ allocWEntry(void)
w = pool;
if(w == nil){
- w = vtMemAllocZ(1024*sizeof(WEntry));
+ w = vtmallocz(1024*sizeof(WEntry));
for(i=0; i<1024; i++)
freeWEntry(&w[i]);
w = pool;
@@ -195,16 +195,15 @@ addChild(uchar p[VtEntrySize], uchar c[VtEntrySize], int off)
void
bwatchReset(uchar score[VtScoreSize])
{
- vtLock(map.lk);
+ qlock(&map.lk);
_bwatchResetParent(score);
_bwatchResetChild(score);
- vtUnlock(map.lk);
+ qunlock(&map.lk);
}
void
bwatchInit(void)
{
- map.lk = vtLockAlloc();
wp = privalloc();
*wp = nil;
}
@@ -222,7 +221,7 @@ getWThread(void)
w = *wp;
if(w == nil || w->pid != getpid()){
- w = vtMemAllocZ(sizeof(WThread));
+ w = vtmallocz(sizeof(WThread));
*wp = w;
w->pid = getpid();
}
@@ -241,7 +240,7 @@ bwatchDependency(Block *b)
if(bwatchDisabled)
return;
- vtLock(map.lk);
+ qlock(&map.lk);
_bwatchResetParent(b->score);
switch(b->l.type){
@@ -264,7 +263,7 @@ bwatchDependency(Block *b)
addChild(b->score, b->data+i*VtScoreSize, i);
break;
}
- vtUnlock(map.lk);
+ qunlock(&map.lk);
}
static int
@@ -376,7 +375,7 @@ bwatchLock(Block *b)
if(b->part != PartData)
return;
- vtLock(map.lk);
+ qlock(&map.lk);
w = getWThread();
for(i=0; i<w->nb; i++){
if(lockConflicts(w->b[i]->score, b->score)){
@@ -385,7 +384,7 @@ bwatchLock(Block *b)
stop();
}
}
- vtUnlock(map.lk);
+ qunlock(&map.lk);
if(w->nb >= MaxLock){
fprint(2, "%d: too many blocks held\n", w->pid);
stop();
diff --git a/src/cmd/fossil/cache.c b/src/cmd/fossil/cache.c
index e812f6b6..f473d211 100644
--- a/src/cmd/fossil/cache.c
+++ b/src/cmd/fossil/cache.c
@@ -21,14 +21,14 @@ enum {
struct Cache
{
- VtLock *lk;
+ QLock lk;
int ref;
int mode;
Disk *disk;
int size; /* block size */
int ndmap; /* size of per-block dirty pointer map used in blockWrite */
- VtSession *z;
+ VtConn *z;
u32int now; /* ticks for usage timestamps */
Block **heads; /* hash table for finding address */
int nheap; /* number of available victims */
@@ -38,7 +38,7 @@ struct Cache
u8int *mem; /* memory for all block data & blists */
BList *blfree;
- VtRendez *blrend;
+ Rendez blrend;
int ndirty; /* number of dirty blocks in the cache */
int maxdirty; /* max number of dirty blocks */
@@ -48,11 +48,11 @@ struct Cache
FreeList *fl;
- VtRendez *die; /* daemon threads should die when != nil */
+ Rendez die; /* daemon threads should die when QLock != nil */
- VtRendez *flush;
- VtRendez *flushwait;
- VtRendez *heapwait;
+ Rendez flush;
+ Rendez flushwait;
+ Rendez heapwait;
BAddr *baddr;
int bw, br, be;
int nflush;
@@ -62,7 +62,7 @@ struct Cache
/* unlink daemon */
BList *uhead;
BList *utail;
- VtRendez *unlink;
+ Rendez unlink;
/* block counts */
int nused;
@@ -95,7 +95,7 @@ struct BAddr {
};
struct FreeList {
- VtLock *lk;
+ QLock lk;
u32int last; /* last block allocated */
u32int end; /* end of data partition */
u32int nused; /* number of used blocks */
@@ -123,28 +123,28 @@ static void doRemoveLink(Cache*, BList*);
*/
int vtType[BtMax] = {
VtDataType, /* BtData | 0 */
- VtPointerType0, /* BtData | 1 */
- VtPointerType1, /* BtData | 2 */
- VtPointerType2, /* BtData | 3 */
- VtPointerType3, /* BtData | 4 */
- VtPointerType4, /* BtData | 5 */
- VtPointerType5, /* BtData | 6 */
- VtPointerType6, /* BtData | 7 */
+ VtDataType+1, /* BtData | 1 */
+ VtDataType+2, /* BtData | 2 */
+ VtDataType+3, /* BtData | 3 */
+ VtDataType+4, /* BtData | 4 */
+ VtDataType+5, /* BtData | 5 */
+ VtDataType+6, /* BtData | 6 */
+ VtDataType+7, /* BtData | 7 */
VtDirType, /* BtDir | 0 */
- VtPointerType0, /* BtDir | 1 */
- VtPointerType1, /* BtDir | 2 */
- VtPointerType2, /* BtDir | 3 */
- VtPointerType3, /* BtDir | 4 */
- VtPointerType4, /* BtDir | 5 */
- VtPointerType5, /* BtDir | 6 */
- VtPointerType6, /* BtDir | 7 */
+ VtDirType+1, /* BtDir | 1 */
+ VtDirType+2, /* BtDir | 2 */
+ VtDirType+3, /* BtDir | 3 */
+ VtDirType+4, /* BtDir | 4 */
+ VtDirType+5, /* BtDir | 5 */
+ VtDirType+6, /* BtDir | 6 */
+ VtDirType+7, /* BtDir | 7 */
};
/*
* Allocate the memory cache.
*/
Cache *
-cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
+cacheAlloc(Disk *disk, VtConn *z, ulong nblocks, int mode)
{
int i;
Cache *c;
@@ -153,12 +153,11 @@ cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
u8int *p;
int nbl;
- c = vtMemAllocZ(sizeof(Cache));
+ c = vtmallocz(sizeof(Cache));
/* reasonable number of BList elements */
nbl = nblocks * 4;
- c->lk = vtLockAlloc();
c->ref = 1;
c->disk = disk;
c->z = z;
@@ -169,21 +168,20 @@ bwatchSetBlockSize(c->size);
c->ndmap = (c->size/20 + 7) / 8;
c->nblocks = nblocks;
c->hashSize = nblocks;
- c->heads = vtMemAllocZ(c->hashSize*sizeof(Block*));
- c->heap = vtMemAllocZ(nblocks*sizeof(Block*));
- c->blocks = vtMemAllocZ(nblocks*sizeof(Block));
- c->mem = vtMemAllocZ(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
- c->baddr = vtMemAllocZ(nblocks * sizeof(BAddr));
+ c->heads = vtmallocz(c->hashSize*sizeof(Block*));
+ c->heap = vtmallocz(nblocks*sizeof(Block*));
+ c->blocks = vtmallocz(nblocks*sizeof(Block));
+ c->mem = vtmallocz(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
+ c->baddr = vtmallocz(nblocks * sizeof(BAddr));
c->mode = mode;
c->vers++;
p = c->mem;
for(i = 0; i < nblocks; i++){
b = &c->blocks[i];
- b->lk = vtLockAlloc();
b->c = c;
b->data = p;
b->heap = i;
- b->ioready = vtRendezAlloc(b->lk);
+ b->ioready.l = &b->lk;
c->heap[i] = b;
p += c->size;
}
@@ -201,22 +199,22 @@ bwatchSetBlockSize(c->size);
p += c->ndmap;
}
- c->blrend = vtRendezAlloc(c->lk);
+ c->blrend.l = &c->lk;
c->maxdirty = nblocks*(DirtyPercentage*0.01);
c->fl = flAlloc(diskSize(disk, PartData));
- c->unlink = vtRendezAlloc(c->lk);
- c->flush = vtRendezAlloc(c->lk);
- c->flushwait = vtRendezAlloc(c->lk);
- c->heapwait = vtRendezAlloc(c->lk);
+ c->unlink.l = &c->lk;
+ c->flush.l = &c->lk;
+ c->flushwait.l = &c->lk;
+ c->heapwait.l = &c->lk;
c->sync = periodicAlloc(cacheSync, c, 30*1000);
if(mode == OReadWrite){
c->ref += 2;
- vtThread(unlinkThread, c);
- vtThread(flushThread, c);
+ proccreate(unlinkThread, c, STACK);
+ proccreate(flushThread, c, STACK);
}
cacheCheck(c);
@@ -232,42 +230,38 @@ cacheFree(Cache *c)
int i;
/* kill off daemon threads */
- vtLock(c->lk);
- c->die = vtRendezAlloc(c->lk);
+ qlock(&c->lk);
+ c->die.l = &c->lk;
periodicKill(c->sync);
- vtWakeup(c->flush);
- vtWakeup(c->unlink);
+ rwakeup(&c->flush);
+ rwakeup(&c->unlink);
while(c->ref > 1)
- vtSleep(c->die);
+ rsleep(&c->die);
/* flush everything out */
do {
unlinkBody(c);
- vtUnlock(c->lk);
+ qunlock(&c->lk);
while(cacheFlushBlock(c))
;
diskFlush(c->disk);
- vtLock(c->lk);
+ qlock(&c->lk);
} while(c->uhead || c->ndirty);
- vtUnlock(c->lk);
+ qunlock(&c->lk);
cacheCheck(c);
for(i = 0; i < c->nblocks; i++){
assert(c->blocks[i].ref == 0);
- vtRendezFree(c->blocks[i].ioready);
- vtLockFree(c->blocks[i].lk);
}
flFree(c->fl);
- vtMemFree(c->baddr);
- vtMemFree(c->heads);
- vtMemFree(c->blocks);
- vtMemFree(c->mem);
- vtLockFree(c->lk);
+ vtfree(c->baddr);
+ vtfree(c->heads);
+ vtfree(c->blocks);
+ vtfree(c->mem);
diskFree(c->disk);
- vtRendezFree(c->blrend);
/* don't close vtSession */
- vtMemFree(c);
+ vtfree(c);
}
static void
@@ -297,22 +291,22 @@ cacheCheck(Cache *c)
for(i = 0; i < c->nheap; i++){
if(c->heap[i]->heap != i)
- vtFatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
+ sysfatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
if(i > 0 && c->heap[(i - 1) >> 1]->used - now > c->heap[i]->used - now)
- vtFatal("bad heap ordering");
+ sysfatal("bad heap ordering");
k = (i << 1) + 1;
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
- vtFatal("bad heap ordering");
+ sysfatal("bad heap ordering");
k++;
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
- vtFatal("bad heap ordering");
+ sysfatal("bad heap ordering");
}
refed = 0;
for(i = 0; i < c->nblocks; i++){
b = &c->blocks[i];
if(b->data != &c->mem[i * size])
- vtFatal("mis-blocked at %d", i);
+ sysfatal("mis-blocked at %d", i);
if(b->ref && b->heap == BadHeap){
refed++;
}
@@ -352,8 +346,8 @@ cacheBumpBlock(Cache *c)
printed = 0;
if(c->nheap == 0){
while(c->nheap == 0){
- vtWakeup(c->flush);
- vtSleep(c->heapwait);
+ rwakeup(&c->flush);
+ rsleep(&c->heapwait);
if(c->nheap == 0){
printed = 1;
fprint(2, "%s: entire cache is busy, %d dirty "
@@ -414,27 +408,27 @@ _cacheLocalLookup(Cache *c, int part, u32int addr, u32int vers,
/*
* look for the block in the cache
*/
- vtLock(c->lk);
+ qlock(&c->lk);
for(b = c->heads[h]; b != nil; b = b->next){
if(b->part == part && b->addr == addr)
break;
}
if(b == nil || b->vers != vers){
- vtUnlock(c->lk);
+ qunlock(&c->lk);
return nil;
}
- if(!waitlock && !vtCanLock(b->lk)){
+ if(!waitlock && !canqlock(&b->lk)){
*lockfailure = 1;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
return nil;
}
heapDel(b);
b->ref++;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
bwatchLock(b);
if(waitlock)
- vtLock(b->lk);
+ qlock(&b->lk);
b->nlock = 1;
for(;;){
@@ -452,15 +446,15 @@ _cacheLocalLookup(Cache *c, int part, u32int addr, u32int vers,
return b;
case BioReading:
case BioWriting:
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
break;
case BioVentiError:
blockPut(b);
- vtSetError("venti i/o error block 0x%.8ux", addr);
+ werrstr("venti i/o error block 0x%.8ux", addr);
return nil;
case BioReadError:
blockPut(b);
- vtSetError("error reading block 0x%.8ux", addr);
+ werrstr("error reading block 0x%.8ux", addr);
return nil;
}
}
@@ -490,14 +484,14 @@ _cacheLocal(Cache *c, int part, u32int addr, int mode, u32int epoch)
/*
* look for the block in the cache
*/
- vtLock(c->lk);
+ qlock(&c->lk);
for(b = c->heads[h]; b != nil; b = b->next){
if(b->part != part || b->addr != addr)
continue;
if(epoch && b->l.epoch != epoch){
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
- vtUnlock(c->lk);
- vtSetError(ELabelMismatch);
+ qunlock(&c->lk);
+ werrstr(ELabelMismatch);
return nil;
}
heapDel(b);
@@ -520,7 +514,7 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
b->prev = &c->heads[h];
}
- vtUnlock(c->lk);
+ qunlock(&c->lk);
/*
* BUG: what if the epoch changes right here?
@@ -534,7 +528,7 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr);
bwatchLock(b);
- vtLock(b->lk);
+ qlock(&b->lk);
b->nlock = 1;
if(part == PartData && b->iostate == BioEmpty){
@@ -547,7 +541,7 @@ if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr)
if(epoch && b->l.epoch != epoch){
blockPut(b);
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
- vtSetError(ELabelMismatch);
+ werrstr(ELabelMismatch);
return nil;
}
@@ -566,19 +560,19 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
/* fall through */
case BioEmpty:
diskRead(c->disk, b);
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
break;
case BioClean:
case BioDirty:
return b;
case BioReading:
case BioWriting:
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
break;
case BioReadError:
blockSetIOState(b, BioEmpty);
blockPut(b);
- vtSetError("error reading block 0x%.8ux", addr);
+ werrstr("error reading block 0x%.8ux", addr);
return nil;
}
}
@@ -607,7 +601,7 @@ cacheLocalData(Cache *c, u32int addr, int type, u32int tag, int mode, u32int epo
if(b->l.type != type || b->l.tag != tag){
fprint(2, "%s: cacheLocalData: addr=%d type got %d exp %d: tag got %ux exp %ux\n",
argv0, addr, b->l.type, type, b->l.tag, tag);
- vtSetError(ELabelMismatch);
+ werrstr(ELabelMismatch);
blockPut(b);
return nil;
}
@@ -641,7 +635,7 @@ cacheGlobal(Cache *c, uchar score[VtScoreSize], int type, u32int tag, int mode)
/*
* look for the block in the cache
*/
- vtLock(c->lk);
+ qlock(&c->lk);
for(b = c->heads[h]; b != nil; b = b->next){
if(b->part != PartVenti || memcmp(b->score, score, VtScoreSize) != 0 || b->l.type != type)
continue;
@@ -667,10 +661,10 @@ if(0)fprint(2, "%s: cacheGlobal %V %d\n", argv0, score, type);
b->next->prev = &b->next;
b->prev = &c->heads[h];
}
- vtUnlock(c->lk);
+ qunlock(&c->lk);
bwatchLock(b);
- vtLock(b->lk);
+ qlock(&b->lk);
b->nlock = 1;
b->pc = getcallerpc(&c);
@@ -678,27 +672,27 @@ if(0)fprint(2, "%s: cacheGlobal %V %d\n", argv0, score, type);
default:
abort();
case BioEmpty:
- n = vtRead(c->z, score, vtType[type], b->data, c->size);
- if(n < 0 || !vtSha1Check(score, b->data, n)){
+ n = vtread(c->z, score, vtType[type], b->data, c->size);
+ if(n < 0 || vtsha1check(score, b->data, n) < 0){
blockSetIOState(b, BioVentiError);
blockPut(b);
- vtSetError(
+ werrstr(
"venti error reading block %V or wrong score: %r",
score);
return nil;
}
- vtZeroExtend(vtType[type], b->data, n, c->size);
+ vtzeroextend(vtType[type], b->data, n, c->size);
blockSetIOState(b, BioClean);
return b;
case BioClean:
return b;
case BioVentiError:
blockPut(b);
- vtSetError("venti i/o error or wrong score, block %V", score);
+ werrstr("venti i/o error or wrong score, block %V", score);
return nil;
case BioReadError:
blockPut(b);
- vtSetError("error reading block %V", b->score);
+ werrstr("error reading block %V", b->score);
return nil;
}
/* NOT REACHED */
@@ -722,12 +716,12 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
n = c->size / LabelSize;
fl = c->fl;
- vtLock(fl->lk);
+ qlock(&fl->lk);
addr = fl->last;
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
if(b == nil){
- fprint(2, "%s: cacheAllocBlock: xxx %R\n", argv0);
- vtUnlock(fl->lk);
+ fprint(2, "%s: cacheAllocBlock: xxx %r\n", argv0);
+ qunlock(&fl->lk);
return nil;
}
nwrap = 0;
@@ -736,16 +730,16 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
addr = 0;
if(++nwrap >= 2){
blockPut(b);
- vtSetError("disk is full");
+ werrstr("disk is full");
/*
* try to avoid a continuous spew of console
* messages.
*/
if (fl->last != 0)
- fprint(2, "%s: cacheAllocBlock: xxx1 %R\n",
+ fprint(2, "%s: cacheAllocBlock: xxx1 %r\n",
argv0);
fl->last = 0;
- vtUnlock(fl->lk);
+ qunlock(&fl->lk);
return nil;
}
}
@@ -754,8 +748,8 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
if(b == nil){
fl->last = addr;
- fprint(2, "%s: cacheAllocBlock: xxx2 %R\n", argv0);
- vtUnlock(fl->lk);
+ fprint(2, "%s: cacheAllocBlock: xxx2 %r\n", argv0);
+ qunlock(&fl->lk);
return nil;
}
}
@@ -771,7 +765,7 @@ Found:
blockPut(b);
b = cacheLocal(c, PartData, addr, OOverWrite);
if(b == nil){
- fprint(2, "%s: cacheAllocBlock: xxx3 %R\n", argv0);
+ fprint(2, "%s: cacheAllocBlock: xxx3 %r\n", argv0);
return nil;
}
assert(b->iostate == BioLabel || b->iostate == BioClean);
@@ -782,17 +776,17 @@ assert(b->iostate == BioLabel || b->iostate == BioClean);
lab.epoch = epoch;
lab.epochClose = ~(u32int)0;
if(!blockSetLabel(b, &lab, 1)){
- fprint(2, "%s: cacheAllocBlock: xxx4 %R\n", argv0);
+ fprint(2, "%s: cacheAllocBlock: xxx4 %r\n", argv0);
blockPut(b);
return nil;
}
- vtZeroExtend(vtType[type], b->data, 0, c->size);
+ vtzeroextend(vtType[type], b->data, 0, c->size);
if(0)diskWrite(c->disk, b);
if(0)fprint(2, "%s: fsAlloc %ud type=%d tag = %ux\n", argv0, addr, type, tag);
lastAlloc = addr;
fl->nused++;
- vtUnlock(fl->lk);
+ qunlock(&fl->lk);
b->pc = getcallerpc(&c);
return b;
}
@@ -815,11 +809,11 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
fl = c->fl;
n = c->size / LabelSize;
*bsize = c->size;
- vtLock(fl->lk);
+ qlock(&fl->lk);
if(fl->epochLow == epochLow){
*used = fl->nused;
*total = fl->end;
- vtUnlock(fl->lk);
+ qunlock(&fl->lk);
return;
}
b = nil;
@@ -829,7 +823,7 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
blockPut(b);
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
if(b == nil){
- fprint(2, "%s: flCountUsed: loading %ux: %R\n",
+ fprint(2, "%s: flCountUsed: loading %ux: %r\n",
argv0, addr/n);
break;
}
@@ -850,7 +844,7 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
}
*used = nused;
*total = fl->end;
- vtUnlock(fl->lk);
+ qunlock(&fl->lk);
return;
}
@@ -859,8 +853,7 @@ flAlloc(u32int end)
{
FreeList *fl;
- fl = vtMemAllocZ(sizeof(*fl));
- fl->lk = vtLockAlloc();
+ fl = vtmallocz(sizeof(*fl));
fl->last = 0;
fl->end = end;
return fl;
@@ -869,8 +862,7 @@ flAlloc(u32int end)
static void
flFree(FreeList *fl)
{
- vtLockFree(fl->lk);
- vtMemFree(fl);
+ vtfree(fl);
}
u32int
@@ -914,8 +906,8 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
/*
* b->nlock should probably stay at zero while
- * the block is unlocked, but diskThread and vtSleep
- * conspire to assume that they can just vtLock(b->lk); blockPut(b),
+ * the block is unlocked, but diskThread and rsleep
+ * conspire to assume that they can just qlock(&b->lk); blockPut(b),
* so we have to keep b->nlock set to 1 even
* when the block is unlocked.
*/
@@ -924,12 +916,12 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
// b->pc = 0;
bwatchUnlock(b);
- vtUnlock(b->lk);
+ qunlock(&b->lk);
c = b->c;
- vtLock(c->lk);
+ qlock(&c->lk);
if(--b->ref > 0){
- vtUnlock(c->lk);
+ qunlock(&c->lk);
return;
}
@@ -950,7 +942,7 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
case BioDirty:
break;
}
- vtUnlock(c->lk);
+ qunlock(&c->lk);
}
/*
@@ -1098,12 +1090,12 @@ blockDirty(Block *b)
return 1;
assert(b->iostate == BioClean || b->iostate == BioLabel);
- vtLock(c->lk);
+ qlock(&c->lk);
b->iostate = BioDirty;
c->ndirty++;
if(c->ndirty > (c->maxdirty>>1))
- vtWakeup(c->flush);
- vtUnlock(c->lk);
+ rwakeup(&c->flush);
+ qunlock(&c->lk);
return 1;
}
@@ -1288,7 +1280,7 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
* queue to the cache unlink queue.
*/
if(b->iostate == BioDirty || b->iostate == BioWriting){
- vtLock(c->lk);
+ qlock(&c->lk);
c->ndirty--;
b->iostate = iostate; /* change here to keep in sync with ndirty */
b->vers = c->vers++;
@@ -1296,13 +1288,13 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
/* add unlink blocks to unlink queue */
if(c->uhead == nil){
c->uhead = b->uhead;
- vtWakeup(c->unlink);
+ rwakeup(&c->unlink);
}else
c->utail->next = b->uhead;
c->utail = b->utail;
b->uhead = nil;
}
- vtUnlock(c->lk);
+ qunlock(&c->lk);
}
assert(!b->uhead);
dowakeup = 1;
@@ -1313,9 +1305,9 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
* Bump a version count, leave it dirty.
*/
if(b->iostate == BioWriting){
- vtLock(c->lk);
+ qlock(&c->lk);
b->vers = c->vers++;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
dowakeup = 1;
}
break;
@@ -1327,9 +1319,9 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
* This is here because we need to lock c->lk to
* manipulate the ref count.
*/
- vtLock(c->lk);
+ qlock(&c->lk);
b->ref++;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
break;
case BioReadError:
case BioVentiError:
@@ -1344,7 +1336,7 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
* Now that the state has changed, we can wake the waiters.
*/
if(dowakeup)
- vtWakeupAll(b->ioready);
+ rwakeupall(&b->ioready);
}
/*
@@ -1571,11 +1563,11 @@ doRemoveLink(Cache *c, BList *p)
l.state |= BsClosed;
l.epochClose = p->epoch;
if(l.epochClose == l.epoch){
- vtLock(c->fl->lk);
+ qlock(&c->fl->lk);
if(l.epoch == c->fl->epochLow)
c->fl->nused--;
blockSetLabel(b, &l, 0);
- vtUnlock(c->fl->lk);
+ qunlock(&c->fl->lk);
}else
blockSetLabel(b, &l, 0);
blockPut(b);
@@ -1603,7 +1595,7 @@ blistAlloc(Block *b)
}
c = b->c;
- vtLock(c->lk);
+ qlock(&c->lk);
if(c->blfree == nil){
/*
* No free BLists. What are our options?
@@ -1611,7 +1603,7 @@ blistAlloc(Block *b)
/* Block has no priors? Just write it. */
if(b->prior == nil){
- vtUnlock(c->lk);
+ qunlock(&c->lk);
diskWriteAndWait(c->disk, b);
return nil;
}
@@ -1629,8 +1621,8 @@ blistAlloc(Block *b)
* so it can't deadlock like we can.)
*/
while(c->blfree == nil){
- vtWakeup(c->flush);
- vtSleep(c->blrend);
+ rwakeup(&c->flush);
+ rsleep(&c->blrend);
if(c->blfree == nil)
fprint(2, "%s: flushing for blists\n", argv0);
}
@@ -1638,18 +1630,18 @@ blistAlloc(Block *b)
p = c->blfree;
c->blfree = p->next;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
return p;
}
static void
blistFree(Cache *c, BList *bl)
{
- vtLock(c->lk);
+ qlock(&c->lk);
bl->next = c->blfree;
c->blfree = bl;
- vtWakeup(c->blrend);
- vtUnlock(c->lk);
+ rwakeup(&c->blrend);
+ qunlock(&c->lk);
}
char*
@@ -1843,7 +1835,7 @@ heapIns(Block *b)
{
assert(b->heap == BadHeap);
upHeap(b->c->nheap++, b);
- vtWakeup(b->c->heapwait);
+ rwakeup(&b->c->heapwait);
}
/*
@@ -1884,9 +1876,9 @@ unlinkBody(Cache *c)
while(c->uhead != nil){
p = c->uhead;
c->uhead = p->next;
- vtUnlock(c->lk);
+ qunlock(&c->lk);
doRemoveLink(c, p);
- vtLock(c->lk);
+ qlock(&c->lk);
p->next = c->blfree;
c->blfree = p;
}
@@ -1900,19 +1892,19 @@ unlinkThread(void *a)
{
Cache *c = a;
- vtThreadSetName("unlink");
+ threadsetname("unlink");
- vtLock(c->lk);
+ qlock(&c->lk);
for(;;){
- while(c->uhead == nil && c->die == nil)
- vtSleep(c->unlink);
- if(c->die != nil)
+ while(c->uhead == nil && c->die.l == nil)
+ rsleep(&c->unlink);
+ if(c->die.l != nil)
break;
unlinkBody(c);
}
c->ref--;
- vtWakeup(c->die);
- vtUnlock(c->lk);
+ rwakeup(&c->die);
+ qunlock(&c->lk);
}
static int
@@ -1943,9 +1935,9 @@ flushFill(Cache *c)
BAddr *p;
Block *b;
- vtLock(c->lk);
+ qlock(&c->lk);
if(c->ndirty == 0){
- vtUnlock(c->lk);
+ qunlock(&c->lk);
return;
}
@@ -1969,7 +1961,7 @@ flushFill(Cache *c)
argv0, c->ndirty, ndirty);
c->ndirty = ndirty;
}
- vtUnlock(c->lk);
+ qunlock(&c->lk);
c->bw = p - c->baddr;
qsort(c->baddr, c->bw, sizeof(BAddr), baddrCmp);
@@ -2043,11 +2035,11 @@ flushThread(void *a)
Cache *c = a;
int i;
- vtThreadSetName("flush");
- vtLock(c->lk);
- while(c->die == nil){
- vtSleep(c->flush);
- vtUnlock(c->lk);
+ threadsetname("flush");
+ qlock(&c->lk);
+ while(c->die.l == nil){
+ rsleep(&c->flush);
+ qunlock(&c->lk);
for(i=0; i<FlushSize; i++)
if(!cacheFlushBlock(c)){
/*
@@ -2073,12 +2065,12 @@ flushThread(void *a)
*/
sleep(100);
}
- vtLock(c->lk);
- vtWakeupAll(c->flushwait);
+ qlock(&c->lk);
+ rwakeupall(&c->flushwait);
}
c->ref--;
- vtWakeup(c->die);
- vtUnlock(c->lk);
+ rwakeup(&c->die);
+ qunlock(&c->lk);
}
/*
@@ -2087,18 +2079,18 @@ flushThread(void *a)
void
cacheFlush(Cache *c, int wait)
{
- vtLock(c->lk);
+ qlock(&c->lk);
if(wait){
while(c->ndirty){
// consPrint("cacheFlush: %d dirty blocks, uhead %p\n",
// c->ndirty, c->uhead);
- vtWakeup(c->flush);
- vtSleep(c->flushwait);
+ rwakeup(&c->flush);
+ rsleep(&c->flushwait);
}
// consPrint("cacheFlush: done (uhead %p)\n", c->ndirty, c->uhead);
}else if(c->ndirty)
- vtWakeup(c->flush);
- vtUnlock(c->lk);
+ rwakeup(&c->flush);
+ qunlock(&c->lk);
}
/*
diff --git a/src/cmd/fossil/check.c b/src/cmd/fossil/check.c
index 03ece44a..88c36611 100644
--- a/src/cmd/fossil/check.c
+++ b/src/cmd/fossil/check.c
@@ -61,7 +61,7 @@ fsCheck(Fsck *chk)
checkInit(chk);
b = superGet(chk->cache, &super);
if(b == nil){
- chk->print("could not load super block: %R");
+ chk->print("could not load super block: %r");
return;
}
blockPut(b);
@@ -69,9 +69,9 @@ fsCheck(Fsck *chk)
chk->hint = super.active;
checkEpochs(chk);
- chk->smap = vtMemAllocZ(chk->nblocks/8+1);
+ chk->smap = vtmallocz(chk->nblocks/8+1);
checkDirs(chk);
- vtMemFree(chk->smap);
+ vtfree(chk->smap);
}
static void checkEpoch(Fsck*, u32int);
@@ -87,10 +87,10 @@ checkEpochs(Fsck *chk)
uint nb;
nb = chk->nblocks;
- chk->amap = vtMemAllocZ(nb/8+1);
- chk->emap = vtMemAllocZ(nb/8+1);
- chk->xmap = vtMemAllocZ(nb/8+1);
- chk->errmap = vtMemAllocZ(nb/8+1);
+ chk->amap = vtmallocz(nb/8+1);
+ chk->emap = vtmallocz(nb/8+1);
+ chk->xmap = vtmallocz(nb/8+1);
+ chk->errmap = vtmallocz(nb/8+1);
for(e = chk->fs->ehi; e >= chk->fs->elo; e--){
memset(chk->emap, 0, chk->nblocks/8+1);
@@ -98,10 +98,10 @@ checkEpochs(Fsck *chk)
checkEpoch(chk, e);
}
checkLeak(chk);
- vtMemFree(chk->amap);
- vtMemFree(chk->emap);
- vtMemFree(chk->xmap);
- vtMemFree(chk->errmap);
+ vtfree(chk->amap);
+ vtfree(chk->emap);
+ vtfree(chk->xmap);
+ vtfree(chk->errmap);
}
static void
@@ -131,7 +131,7 @@ checkEpoch(Fsck *chk, u32int epoch)
a = (a+chk->hint)%chk->nblocks;
b = cacheLocalData(chk->cache, a, BtDir, RootTag, OReadOnly, 0);
if(b == nil){
- error(chk, "could not read root block 0x%.8#ux: %R", a);
+ error(chk, "could not read root block 0x%.8#ux: %r", a);
return;
}
@@ -146,7 +146,7 @@ checkEpoch(Fsck *chk, u32int epoch)
* just a convenience to help the search.
*/
if(!entryUnpack(&e, b->data, 0)){
- error(chk, "could not unpack root block 0x%.8#ux: %R", a);
+ error(chk, "could not unpack root block 0x%.8#ux: %r", a);
blockPut(b);
return;
}
@@ -186,7 +186,7 @@ walkEpoch(Fsck *chk, Block *b, uchar score[VtScoreSize], int type, u32int tag,
bb = cacheGlobal(chk->cache, score, type, tag, OReadOnly);
if(bb == nil){
- error(chk, "could not load block %V type %d tag %ux: %R",
+ error(chk, "could not load block %V type %d tag %ux: %r",
score, type, tag);
chk->walkdepth--;
return 0;
@@ -284,7 +284,7 @@ walkEpoch(Fsck *chk, Block *b, uchar score[VtScoreSize], int type, u32int tag,
case BtDir:
for(i = 0; i < chk->bsize/VtEntrySize; i++){
if(!entryUnpack(&e, bb->data, i)){
- // error(chk, "walk: could not unpack entry: %ux[%d]: %R",
+ // error(chk, "walk: could not unpack entry: %ux[%d]: %r",
// addr, i);
setBit(chk->errmap, bb->addr);
chk->clre(chk, bb, i);
@@ -360,7 +360,7 @@ checkLeak(Fsck *chk)
for(a = 0; a < chk->nblocks; a++){
if(!readLabel(chk->cache, &l, a)){
- error(chk, "could not read label: addr 0x%ux %d %d: %R",
+ error(chk, "could not read label: addr 0x%ux %d %d: %r",
a, l.type, l.state);
continue;
}
@@ -416,7 +416,7 @@ openSource(Fsck *chk, Source *s, char *name, uchar *bm, u32int offset,
r = sourceOpen(s, offset, OReadOnly, 0);
if(r == nil){
- warn(chk, "could not open source: %s -> %d: %R", name, offset);
+ warn(chk, "could not open source: %s -> %d: %r", name, offset);
goto Err;
}
@@ -469,7 +469,7 @@ chkMetaBlock(MetaBlock *mb)
int oo, o, n, i;
uchar *p;
- mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
+ mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
p = mb->buf + MetaHeaderSize;
for(i = 0; i < mb->nindex; i++){
mc[i].offset = p[0]<<8 | p[1];
@@ -494,7 +494,7 @@ chkMetaBlock(MetaBlock *mb)
if(o+n > mb->size || mb->size - oo != mb->free)
goto Err;
- vtMemFree(mc);
+ vtfree(mc);
return 1;
Err:
@@ -509,7 +509,7 @@ if(0){
fprint(2, "\tused=%d size=%d free=%d free2=%d\n",
oo, mb->size, mb->free, mb->size - oo);
}
- vtMemFree(mc);
+ vtfree(mc);
return 0;
}
@@ -571,11 +571,11 @@ chkDir(Fsck *chk, char *name, Source *source, Source *meta)
return;
if(!sourceLock2(source, meta, OReadOnly)){
- warn(chk, "could not lock sources for %s: %R", name);
+ warn(chk, "could not lock sources for %s: %r", name);
return;
}
if(!sourceGetEntry(source, &e1) || !sourceGetEntry(meta, &e2)){
- warn(chk, "could not load entries for %s: %R", name);
+ warn(chk, "could not load entries for %s: %r", name);
return;
}
a1 = globalToLocal(e1.score);
@@ -589,13 +589,13 @@ chkDir(Fsck *chk, char *name, Source *source, Source *meta)
setBit(chk->smap, a1);
setBit(chk->smap, a2);
- bm = vtMemAllocZ(sourceGetDirSize(source)/8 + 1);
+ bm = vtmallocz(sourceGetDirSize(source)/8 + 1);
nb = (sourceGetSize(meta) + meta->dsize - 1)/meta->dsize;
for(o = 0; o < nb; o++){
b = sourceBlock(meta, o, OReadOnly);
if(b == nil){
- error(chk, "could not read block in meta file: %s[%ud]: %R",
+ error(chk, "could not read block in meta file: %s[%ud]: %r",
name, o);
continue;
}
@@ -606,13 +606,13 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
b->addr, name);
if(!mbUnpack(&mb, b->data, meta->dsize)){
- error(chk, "could not unpack meta block: %s[%ud]: %R",
+ error(chk, "could not unpack meta block: %s[%ud]: %r",
name, o);
blockPut(b);
continue;
}
if(!chkMetaBlock(&mb)){
- error(chk, "bad meta block: %s[%ud]: %R", name, o);
+ error(chk, "bad meta block: %s[%ud]: %r", name, o);
blockPut(b);
continue;
}
@@ -621,7 +621,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
meUnpack(&me, &mb, i);
if(!deUnpack(&de, &me)){
error(chk,
- "could not unpack dir entry: %s[%ud][%d]: %R",
+ "could not unpack dir entry: %s[%ud][%d]: %r",
name, o, i);
continue;
}
@@ -629,8 +629,8 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
error(chk,
"dir entry out of order: %s[%ud][%d] = %s last = %s",
name, o, i, de.elem, s);
- vtMemFree(s);
- s = vtStrDup(de.elem);
+ vtfree(s);
+ s = vtstrdup(de.elem);
nn = smprint("%s/%s", name, de.elem);
if(nn == nil){
error(chk, "out of memory");
@@ -684,7 +684,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
deCleanup(&de);
}
- vtMemFree(s);
+ vtfree(s);
blockPut(b);
}
@@ -710,7 +710,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
sourceUnlock(source);
sourceUnlock(meta);
- vtMemFree(bm);
+ vtfree(bm);
}
static void
@@ -760,7 +760,7 @@ error(Fsck *chk, char *fmt, ...)
chk->print("error: %s\n", buf);
// if(nerr++ > 20)
-// vtFatal("too many errors");
+// sysfatal("too many errors");
}
static void
diff --git a/src/cmd/fossil/dat.h b/src/cmd/fossil/dat.h
index 9c9a5707..d01dedb6 100644
--- a/src/cmd/fossil/dat.h
+++ b/src/cmd/fossil/dat.h
@@ -37,7 +37,6 @@ enum {
Nowaitlock,
Waitlock,
- NilBlock = (~0UL),
MaxBlock = (1UL<<31),
};
@@ -79,7 +78,7 @@ struct Fs {
int mode; /* immutable */
int noatimeupd; /* immutable */
int blockSize; /* immutable */
- VtSession *z; /* immutable */
+ VtConn *z; /* immutable */
Snap *snap; /* immutable */
/* immutable; copy here & Fsys to ease error reporting */
char *name;
@@ -94,7 +93,7 @@ struct Fs {
* Deletion and creation of snapshots occurs under a write lock of elk,
* ensuring no file operations are occurring concurrently.
*/
- VtLock *elk; /* epoch lock */
+ RWLock elk; /* epoch lock */
u32int ehi; /* epoch high */
u32int elo; /* epoch low */
@@ -136,7 +135,7 @@ struct Source {
Source *parent; /* immutable */
File *file; /* immutable; point back */
- VtLock *lk;
+ QLock lk;
int ref;
/*
* epoch for the source
@@ -233,7 +232,7 @@ struct Block {
int nlock;
uintptr pc; /* pc that fetched this block from the cache */
- VtLock *lk;
+ QLock lk;
int part;
u32int addr;
@@ -261,7 +260,7 @@ struct Block {
Block *ionext;
int iostate;
- VtRendez *ioready;
+ Rendez ioready;
};
/* tree walker, for gc and archiver */
diff --git a/src/cmd/fossil/disk.c b/src/cmd/fossil/disk.c
index 3ae43fb6..8491a4b9 100644
--- a/src/cmd/fossil/disk.c
+++ b/src/cmd/fossil/disk.c
@@ -15,16 +15,16 @@ enum {
};
struct Disk {
- VtLock *lk;
+ QLock lk;
int ref;
int fd;
Header h;
- VtRendez *flow;
- VtRendez *starve;
- VtRendez *flush;
- VtRendez *die;
+ Rendez flow;
+ Rendez starve;
+ Rendez flush;
+ Rendez die;
int nqueue;
@@ -49,25 +49,23 @@ diskAlloc(int fd)
Disk *disk;
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize){
- vtSetError("short read: %r");
- vtOSError();
+ werrstr("short read: %r");
return nil;
}
if(!headerUnpack(&h, buf)){
- vtSetError("bad disk header");
+ werrstr("bad disk header");
return nil;
}
- disk = vtMemAllocZ(sizeof(Disk));
- disk->lk = vtLockAlloc();
- disk->starve = vtRendezAlloc(disk->lk);
- disk->flow = vtRendezAlloc(disk->lk);
- disk->flush = vtRendezAlloc(disk->lk);
+ disk = vtmallocz(sizeof(Disk));
+ disk->starve.l = &disk->lk;
+ disk->flow.l = &disk->lk;
+ disk->flush.l = &disk->lk;
disk->fd = fd;
disk->h = h;
disk->ref = 2;
- vtThread(diskThread, disk);
+ proccreate(diskThread, disk, STACK);
return disk;
}
@@ -78,18 +76,14 @@ diskFree(Disk *disk)
diskFlush(disk);
/* kill slave */
- vtLock(disk->lk);
- disk->die = vtRendezAlloc(disk->lk);
- vtWakeup(disk->starve);
+ qlock(&disk->lk);
+ disk->die.l = &disk->lk;
+ rwakeup(&disk->starve);
while(disk->ref > 1)
- vtSleep(disk->die);
- vtUnlock(disk->lk);
- vtRendezFree(disk->flow);
- vtRendezFree(disk->starve);
- vtRendezFree(disk->die);
- vtLockFree(disk->lk);
+ rsleep(&disk->die);
+ qunlock(&disk->lk);
close(disk->fd);
- vtMemFree(disk);
+ vtfree(disk);
}
static u32int
@@ -134,7 +128,7 @@ diskReadRaw(Disk *disk, int part, u32int addr, uchar *buf)
end = partEnd(disk, part);
if(addr >= end-start){
- vtSetError(EBadAddr);
+ werrstr(EBadAddr);
return 0;
}
@@ -143,11 +137,11 @@ diskReadRaw(Disk *disk, int part, u32int addr, uchar *buf)
while(n > 0){
nn = pread(disk->fd, buf, n, offset);
if(nn < 0){
- vtOSError();
+ werrstr("%r");
return 0;
}
if(nn == 0){
- vtSetError("eof reading disk");
+ werrstr("eof reading disk");
return 0;
}
n -= nn;
@@ -168,18 +162,18 @@ diskWriteRaw(Disk *disk, int part, u32int addr, uchar *buf)
end = partEnd(disk, part);
if(addr >= end - start){
- vtSetError(EBadAddr);
+ werrstr(EBadAddr);
return 0;
}
offset = ((u64int)(addr + start))*disk->h.blockSize;
n = pwrite(disk->fd, buf, disk->h.blockSize, offset);
if(n < 0){
- vtOSError();
+ werrstr("%r");
return 0;
}
if(n < disk->h.blockSize) {
- vtSetError("short write");
+ werrstr("short write");
return 0;
}
@@ -191,9 +185,9 @@ diskQueue(Disk *disk, Block *b)
{
Block **bp, *bb;
- vtLock(disk->lk);
+ qlock(&disk->lk);
while(disk->nqueue >= QueueSize)
- vtSleep(disk->flow);
+ rsleep(&disk->flow);
if(disk->cur == nil || b->addr > disk->cur->addr)
bp = &disk->cur;
else
@@ -207,9 +201,9 @@ diskQueue(Disk *disk, Block *b)
b->ionext = bb;
*bp = b;
if(disk->nqueue == 0)
- vtWakeup(disk->starve);
+ rwakeup(&disk->starve);
disk->nqueue++;
- vtUnlock(disk->lk);
+ qunlock(&disk->lk);
}
@@ -238,7 +232,7 @@ diskWriteAndWait(Disk *disk, Block *b)
/*
* If b->nlock > 1, the block is aliased within
* a single thread. That thread is us.
- * DiskWrite does some funny stuff with VtLock
+ * DiskWrite does some funny stuff with QLock
* and blockPut that basically assumes b->nlock==1.
* We humor diskWrite by temporarily setting
* nlock to 1. This needs to be revisited.
@@ -248,7 +242,7 @@ diskWriteAndWait(Disk *disk, Block *b)
b->nlock = 1;
diskWrite(disk, b);
while(b->iostate != BioClean)
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
b->nlock = nlock;
}
@@ -263,15 +257,15 @@ diskFlush(Disk *disk)
{
Dir dir;
- vtLock(disk->lk);
+ qlock(&disk->lk);
while(disk->nqueue > 0)
- vtSleep(disk->flush);
- vtUnlock(disk->lk);
+ rsleep(&disk->flush);
+ qunlock(&disk->lk);
/* there really should be a cleaner interface to flush an fd */
nulldir(&dir);
if(dirfwstat(disk->fd, &dir) < 0){
- vtOSError();
+ werrstr("%r");
return 0;
}
return 1;
@@ -308,13 +302,13 @@ diskThread(void *a)
double t;
int nio;
- vtThreadSetName("disk");
+ threadsetname("disk");
//fprint(2, "diskThread %d\n", getpid());
- buf = vtMemAlloc(disk->h.blockSize);
+ buf = vtmalloc(disk->h.blockSize);
- vtLock(disk->lk);
+ qlock(&disk->lk);
if (Timing) {
nio = 0;
t = -nsec();
@@ -330,9 +324,9 @@ diskThread(void *a)
t = 0;
}
}
- if(disk->die != nil)
+ if(disk->die.l != nil)
goto Done;
- vtSleep(disk->starve);
+ rsleep(&disk->starve);
if (Timing)
t -= nsec();
}
@@ -344,7 +338,7 @@ diskThread(void *a)
}
b = disk->cur;
disk->cur = b->ionext;
- vtUnlock(disk->lk);
+ qunlock(&disk->lk);
/*
* no one should hold onto blocking in the
@@ -353,7 +347,7 @@ diskThread(void *a)
*/
if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
bwatchLock(b);
- vtLock(b->lk);
+ qlock(&b->lk);
b->pc = mypc(0);
assert(b->nlock == 1);
switch(b->iostate){
@@ -388,19 +382,19 @@ if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
}
blockPut(b); /* remove extra reference, unlock */
- vtLock(disk->lk);
+ qlock(&disk->lk);
disk->nqueue--;
if(disk->nqueue == QueueSize-1)
- vtWakeup(disk->flow);
+ rwakeup(&disk->flow);
if(disk->nqueue == 0)
- vtWakeup(disk->flush);
+ rwakeup(&disk->flush);
if(Timing)
nio++;
}
Done:
//fprint(2, "diskThread done\n");
disk->ref--;
- vtWakeup(disk->die);
- vtUnlock(disk->lk);
- vtMemFree(buf);
+ rwakeup(&disk->die);
+ qunlock(&disk->lk);
+ vtfree(buf);
}
diff --git a/src/cmd/fossil/epoch.c b/src/cmd/fossil/epoch.c
index 6aa73bbf..cce53f12 100644
--- a/src/cmd/fossil/epoch.c
+++ b/src/cmd/fossil/epoch.c
@@ -8,11 +8,11 @@ void
usage(void)
{
fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
- exits("usage");
+ threadexitsall("usage");
}
void
-main(int argc, char **argv)
+threadmain(int argc, char **argv)
{
int fd;
Header h;
@@ -47,5 +47,5 @@ main(int argc, char **argv)
if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
sysfatal("writing super block: %r");
}
- exits(0);
+ threadexitsall(0);
}
diff --git a/src/cmd/fossil/file.c b/src/cmd/fossil/file.c
index 5566df33..3c94cdb0 100644
--- a/src/cmd/fossil/file.c
+++ b/src/cmd/fossil/file.c
@@ -26,7 +26,7 @@ struct File {
File *next; /* sibling */
/* data for file */
- VtLock *lk; /* lock for the following */
+ RWLock lk; /* lock for the following */
Source *source;
Source *msource; /* for directories: meta data for children */
File *down; /* children */
@@ -51,8 +51,7 @@ fileAlloc(Fs *fs)
{
File *f;
- f = vtMemAllocZ(sizeof(File));
- f->lk = vtLockAlloc();
+ f = vtmallocz(sizeof(File));
f->ref = 1;
f->fs = fs;
f->boff = NilBlock;
@@ -64,12 +63,11 @@ static void
fileFree(File *f)
{
sourceClose(f->source);
- vtLockFree(f->lk);
sourceClose(f->msource);
deCleanup(&f->dir);
memset(f, ~0, sizeof(File));
- vtMemFree(f);
+ vtfree(f);
}
/*
@@ -115,7 +113,7 @@ dirLookup(File *f, char *elem)
blockPut(b);
b = nil;
}
- vtSetError(ENoFile);
+ werrstr(ENoFile);
/* fall through */
Err:
sourceUnlock(meta);
@@ -216,7 +214,7 @@ fileOpenSource(File *f, u32int offset, u32int gen, int dir, uint mode,
if(r == nil)
return nil;
if(r->gen != gen){
- vtSetError(ERemoved);
+ werrstr(ERemoved);
goto Err;
}
if(r->dir != dir && r->mode != -1){
@@ -229,7 +227,7 @@ fileOpenSource(File *f, u32int offset, u32int gen, int dir, uint mode,
free(rname);
free(fname);
- vtSetError(EBadMeta);
+ werrstr(EBadMeta);
goto Err;
}
return r;
@@ -246,12 +244,12 @@ _fileWalk(File *f, char *elem, int partial)
fileRAccess(f);
if(elem[0] == 0){
- vtSetError(EBadPath);
+ werrstr(EBadPath);
return nil;
}
if(!fileIsDir(f)){
- vtSetError(ENotDir);
+ werrstr(ENotDir);
return nil;
}
@@ -347,14 +345,14 @@ _fileOpen(Fs *fs, char *path, int partial)
n = p - path;
if(n > 0){
if(n > VtMaxStringSize){
- vtSetError("%s: element too long", EBadPath);
+ werrstr("%s: element too long", EBadPath);
goto Err;
}
memmove(elem, path, n);
elem[n] = 0;
ff = _fileWalk(f, elem, partial && *p=='\0');
if(ff == nil){
- vtSetError("%.*s: %R", utfnlen(opath, p-opath),
+ werrstr("%.*s: %r", utfnlen(opath, p-opath),
opath);
goto Err;
}
@@ -422,20 +420,20 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
for(ff = f->down; ff; ff=ff->next){
if(strcmp(elem, ff->dir.elem) == 0 && !ff->removed){
ff = nil;
- vtSetError(EExists);
+ werrstr(EExists);
goto Err1;
}
}
ff = dirLookup(f, elem);
if(ff != nil){
- vtSetError(EExists);
+ werrstr(EExists);
goto Err1;
}
pr = f->source;
if(pr->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
goto Err1;
}
@@ -455,7 +453,7 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
}
dir = &ff->dir;
- dir->elem = vtStrDup(elem);
+ dir->elem = vtstrdup(elem);
dir->entry = r->offset;
dir->gen = r->gen;
if(isdir){
@@ -465,9 +463,9 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
dir->size = 0;
if(!fsNextQid(f->fs, &dir->qid))
goto Err;
- dir->uid = vtStrDup(uid);
- dir->gid = vtStrDup(f->dir.gid);
- dir->mid = vtStrDup(uid);
+ dir->uid = vtstrdup(uid);
+ dir->gid = vtstrdup(f->dir.gid);
+ dir->mid = vtstrdup(uid);
dir->mtime = time(0L);
dir->mcount = 0;
dir->ctime = dir->mtime;
@@ -541,7 +539,7 @@ if(0)fprint(2, "fileRead: %s %d, %lld\n", f->dir.elem, cnt, offset);
return -1;
if(offset < 0){
- vtSetError(EBadOffset);
+ werrstr(EBadOffset);
goto Err1;
}
@@ -607,12 +605,12 @@ fileMapBlock(File *f, ulong bn, uchar score[VtScoreSize], ulong tag)
s = nil;
if(f->dir.mode & ModeDir){
- vtSetError(ENotFile);
+ werrstr(ENotFile);
goto Err;
}
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
goto Err;
}
@@ -656,11 +654,11 @@ fileSetSize(File *f, uvlong size)
return 0;
r = 0;
if(f->dir.mode & ModeDir){
- vtSetError(ENotFile);
+ werrstr(ENotFile);
goto Err;
}
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
goto Err;
}
if(!sourceLock(f->source, -1))
@@ -689,16 +687,16 @@ if(0)fprint(2, "fileWrite: %s %d, %lld\n", f->dir.elem, cnt, offset);
s = nil;
if(f->dir.mode & ModeDir){
- vtSetError(ENotFile);
+ werrstr(ENotFile);
goto Err;
}
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
goto Err;
}
if(offset < 0){
- vtSetError(EBadOffset);
+ werrstr(EBadOffset);
goto Err;
}
@@ -773,7 +771,7 @@ int
fileTruncate(File *f, char *uid)
{
if(fileIsDir(f)){
- vtSetError(ENotFile);
+ werrstr(ENotFile);
return 0;
}
@@ -781,7 +779,7 @@ fileTruncate(File *f, char *uid)
return 0;
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
fileUnlock(f);
return 0;
}
@@ -812,7 +810,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
/* can not set permissions for the root */
if(fileIsRoot(f)){
- vtSetError(ERoot);
+ werrstr(ERoot);
return 0;
}
@@ -820,7 +818,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
return 0;
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
fileUnlock(f);
return 0;
}
@@ -831,7 +829,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
if(strcmp(f->dir.elem, dir->elem) != 0){
for(ff = f->up->down; ff; ff=ff->next){
if(strcmp(dir->elem, ff->dir.elem) == 0 && !ff->removed){
- vtSetError(EExists);
+ werrstr(EExists);
goto Err;
}
}
@@ -839,7 +837,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
ff = dirLookup(f->up, dir->elem);
if(ff != nil){
fileDecRef(ff);
- vtSetError(EExists);
+ werrstr(EExists);
goto Err;
}
}
@@ -868,17 +866,17 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
oelem = nil;
if(strcmp(f->dir.elem, dir->elem) != 0){
oelem = f->dir.elem;
- f->dir.elem = vtStrDup(dir->elem);
+ f->dir.elem = vtstrdup(dir->elem);
}
if(strcmp(f->dir.uid, dir->uid) != 0){
- vtMemFree(f->dir.uid);
- f->dir.uid = vtStrDup(dir->uid);
+ vtfree(f->dir.uid);
+ f->dir.uid = vtstrdup(dir->uid);
}
if(strcmp(f->dir.gid, dir->gid) != 0){
- vtMemFree(f->dir.gid);
- f->dir.gid = vtStrDup(dir->gid);
+ vtfree(f->dir.gid);
+ f->dir.gid = vtstrdup(dir->gid);
}
f->dir.mtime = dir->mtime;
@@ -892,7 +890,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
//fprint(2, "->%x\n", f->dir.mode);
fileMetaFlush2(f, oelem);
- vtMemFree(oelem);
+ vtfree(oelem);
fileMetaUnlock(f);
fileUnlock(f);
@@ -1025,7 +1023,7 @@ fileMetaFlush(File *f, int rec)
nkids = 0;
for(p=f->down; p; p=p->next)
nkids++;
- kids = vtMemAlloc(nkids*sizeof(File*));
+ kids = vtmalloc(nkids*sizeof(File*));
i = 0;
for(p=f->down; p; p=p->next){
kids[i++] = p;
@@ -1037,7 +1035,7 @@ fileMetaFlush(File *f, int rec)
rv |= fileMetaFlush(kids[i], 1);
fileDecRef(kids[i]);
}
- vtMemFree(kids);
+ vtfree(kids);
return rv;
}
@@ -1204,7 +1202,7 @@ fileCheckEmpty(File *f)
if(!mbUnpack(&mb, b->data, r->dsize))
goto Err;
if(mb.nindex > 0){
- vtSetError(ENotEmpty);
+ werrstr(ENotEmpty);
goto Err;
}
blockPut(b);
@@ -1222,7 +1220,7 @@ fileRemove(File *f, char *uid)
/* can not remove the root */
if(fileIsRoot(f)){
- vtSetError(ERoot);
+ werrstr(ERoot);
return 0;
}
@@ -1230,7 +1228,7 @@ fileRemove(File *f, char *uid)
return 0;
if(f->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
goto Err1;
}
if(!sourceLock2(f->source, f->msource, -1))
@@ -1273,7 +1271,7 @@ clri(File *f, char *uid)
if(f == nil)
return 0;
if(f->up->source->mode != OReadWrite){
- vtSetError(EReadOnly);
+ werrstr(EReadOnly);
fileDecRef(f);
return 0;
}
@@ -1359,7 +1357,7 @@ deeOpen(File *f)
File *p;
if(!fileIsDir(f)){
- vtSetError(ENotDir);
+ werrstr(ENotDir);
fileDecRef(f);
return nil;
}
@@ -1371,7 +1369,7 @@ deeOpen(File *f)
fileMetaFlush2(p, nil);
fileUnlock(f);
- dee = vtMemAllocZ(sizeof(DirEntryEnum));
+ dee = vtmallocz(sizeof(DirEntryEnum));
dee->file = fileIncRef(f);
return dee;
@@ -1422,7 +1420,7 @@ deeFill(DirEntryEnum *dee)
/* clean up first */
for(i=dee->i; i<dee->n; i++)
deCleanup(dee->buf+i);
- vtMemFree(dee->buf);
+ vtfree(dee->buf);
dee->buf = nil;
dee->i = 0;
dee->n = 0;
@@ -1439,7 +1437,7 @@ deeFill(DirEntryEnum *dee)
goto Err;
n = mb.nindex;
- dee->buf = vtMemAlloc(n * sizeof(DirEntry));
+ dee->buf = vtmalloc(n * sizeof(DirEntry));
for(i=0; i<n; i++){
de = dee->buf + i;
@@ -1467,7 +1465,7 @@ deeRead(DirEntryEnum *dee, DirEntry *de)
u32int nb;
if(dee == nil){
- vtSetError("cannot happen in deeRead");
+ werrstr("cannot happen in deeRead");
return -1;
}
@@ -1517,9 +1515,9 @@ deeClose(DirEntryEnum *dee)
return;
for(i=dee->i; i<dee->n; i++)
deCleanup(dee->buf+i);
- vtMemFree(dee->buf);
+ vtfree(dee->buf);
fileDecRef(dee->file);
- vtMemFree(dee);
+ vtfree(dee);
}
/*
@@ -1574,7 +1572,7 @@ fileMetaAlloc(File *f, DirEntry *dir, u32int start)
/* mbAlloc might have changed block */
mbPack(&mb);
blockDirty(b);
- vtSetError(EBadMeta);
+ werrstr(EBadMeta);
goto Err;
}
@@ -1617,7 +1615,7 @@ chkSource(File *f)
return 1;
if(f->source == nil || (f->dir.mode & ModeDir) && f->msource == nil){
- vtSetError(ERemoved);
+ werrstr(ERemoved);
return 0;
}
return 1;
@@ -1626,8 +1624,8 @@ chkSource(File *f)
static int
fileRLock(File *f)
{
- assert(!vtCanLock(f->fs->elk));
- vtRLock(f->lk);
+ assert(!canwlock(&f->fs->elk));
+ rlock(&f->lk);
if(!chkSource(f)){
fileRUnlock(f);
return 0;
@@ -1638,14 +1636,14 @@ fileRLock(File *f)
static void
fileRUnlock(File *f)
{
- vtRUnlock(f->lk);
+ runlock(&f->lk);
}
static int
fileLock(File *f)
{
- assert(!vtCanLock(f->fs->elk));
- vtLock(f->lk);
+ assert(!canwlock(&f->fs->elk));
+ wlock(&f->lk);
if(!chkSource(f)){
fileUnlock(f);
return 0;
@@ -1656,7 +1654,7 @@ fileLock(File *f)
static void
fileUnlock(File *f)
{
- vtUnlock(f->lk);
+ wunlock(&f->lk);
}
/*
@@ -1670,14 +1668,14 @@ fileMetaLock(File *f)
if(f->up == nil)
fprint(2, "f->elem = %s\n", f->dir.elem);
assert(f->up != nil);
- assert(!vtCanLock(f->fs->elk));
- vtLock(f->up->lk);
+ assert(!canwlock(&f->fs->elk));
+ wlock(&f->up->lk);
}
static void
fileMetaUnlock(File *f)
{
- vtUnlock(f->up->lk);
+ wunlock(&f->up->lk);
}
/*
@@ -1709,8 +1707,8 @@ fileWAccess(File* f, char *mid)
fileMetaLock(f);
f->dir.atime = f->dir.mtime = time(0L);
if(strcmp(f->dir.mid, mid) != 0){
- vtMemFree(f->dir.mid);
- f->dir.mid = vtStrDup(mid);
+ vtfree(f->dir.mid);
+ f->dir.mid = vtstrdup(mid);
}
f->dir.mcount++;
f->dirty = 1;
@@ -1842,11 +1840,11 @@ fileName(File *f)
static char root[] = "/";
if (f == nil)
- return vtStrDup("/**GOK**");
+ return vtstrdup("/**GOK**");
p = fileGetParent(f);
if (p == f)
- name = vtStrDup(root);
+ name = vtstrdup(root);
else {
pname = fileName(p);
if (strcmp(pname, root) == 0)
diff --git a/src/cmd/fossil/flchk.c b/src/cmd/fossil/flchk.c
index b19fd5be..0506c682 100644
--- a/src/cmd/fossil/flchk.c
+++ b/src/cmd/fossil/flchk.c
@@ -10,7 +10,7 @@ static void
usage(void)
{
fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
- exits("usage");
+ threadexitsall("usage");
}
#pragma varargck argpos flprint 1
@@ -52,10 +52,10 @@ flclose(Fsck*, Block *b, u32int epoch)
}
void
-main(int argc, char *argv[])
+threadmain(int argc, char *argv[])
{
int csize = 1000;
- VtSession *z;
+ VtConn *z;
char *host = nil;
fsck.useventi = 1;
@@ -82,28 +82,25 @@ main(int argc, char *argv[])
if(argc != 1)
usage();
- vtAttach();
-
fmtinstall('L', labelFmt);
fmtinstall('V', scoreFmt);
- fmtinstall('R', vtErrFmt);
/*
* Connect to Venti.
*/
- z = vtDial(host, 0);
+ z = vtdial(host);
if(z == nil){
if(fsck.useventi)
- vtFatal("could not connect to server: %s", vtGetError());
- }else if(!vtConnect(z, 0))
- vtFatal("vtConnect: %s", vtGetError());
+ sysfatal("could not connect to server: %r");
+ }else if(vtconnect(z) < 0)
+ sysfatal("vtconnect: %r");
/*
* Initialize file system.
*/
fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
if(fsck.fs == nil)
- vtFatal("could not open file system: %R");
+ sysfatal("could not open file system: %r");
fsck.print = flprint;
fsck.clre = flclre;
@@ -113,6 +110,6 @@ main(int argc, char *argv[])
fsCheck(&fsck);
- exits(0);
+ threadexitsall(0);
}
diff --git a/src/cmd/fossil/flfmt.c b/src/cmd/fossil/flfmt.c
index 687c41e3..4bb354eb 100644
--- a/src/cmd/fossil/flfmt.c
+++ b/src/cmd/fossil/flfmt.c
@@ -18,7 +18,7 @@ static u32int rootInit(Entry *e);
static void topLevel(char *name);
static int parseScore(uchar[VtScoreSize], char*);
static u32int ventiRoot(char*, char*);
-static VtSession *z;
+static VtConn *z;
#define TWID64 ((u64int)~(u64int)0)
@@ -46,7 +46,7 @@ confirm(char *msg)
}
void
-main(int argc, char *argv[])
+threadmain(int argc, char *argv[])
{
int fd, force;
Header h;
@@ -96,28 +96,25 @@ main(int argc, char *argv[])
usage();
if(iso9660file && score)
- vtFatal("cannot use -i with -v");
-
- vtAttach();
+ sysfatal("cannot use -i with -v");
fmtinstall('V', scoreFmt);
- fmtinstall('R', vtErrFmt);
fmtinstall('L', labelFmt);
fd = open(argv[0], ORDWR);
if(fd < 0)
- vtFatal("could not open file: %s: %r", argv[0]);
+ sysfatal("could not open file: %s: %r", argv[0]);
- buf = vtMemAllocZ(bsize);
+ buf = vtmallocz(bsize);
if(pread(fd, buf, bsize, HeaderOffset) != bsize)
- vtFatal("could not read fs header block: %r");
+ sysfatal("could not read fs header block: %r");
if(headerUnpack(&h, buf) && !force
&& !confirm("fs header block already exists; are you sure?"))
goto Out;
if((d = dirfstat(fd)) == nil)
- vtFatal("dirfstat: %r");
+ sysfatal("dirfstat: %r");
if(d->type == 'M' && !force
&& !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?"))
@@ -126,11 +123,11 @@ main(int argc, char *argv[])
partition(fd, bsize, &h);
headerPack(&h, buf);
if(pwrite(fd, buf, bsize, HeaderOffset) < bsize)
- vtFatal("could not write fs header: %r");
+ sysfatal("could not write fs header: %r");
disk = diskAlloc(fd);
if(disk == nil)
- vtFatal("could not open disk: %r");
+ sysfatal("could not open disk: %r");
if(iso9660file)
iso9660init(fd, &h, iso9660file, iso9660off);
@@ -150,15 +147,14 @@ main(int argc, char *argv[])
root = rootInit(&e);
}
- superInit(label, root, vtZeroScore);
+ superInit(label, root, vtzeroscore);
diskFree(disk);
if(score == nil)
topLevel(argv[0]);
Out:
- vtDetach();
- exits(0);
+ threadexitsall(0);
}
static u64int
@@ -169,7 +165,7 @@ fdsize(int fd)
dir = dirfstat(fd);
if(dir == nil)
- vtFatal("could not stat file: %r");
+ sysfatal("could not stat file: %r");
size = dir->length;
free(dir);
return size;
@@ -180,7 +176,7 @@ usage(void)
{
fprint(2, "usage: %s [-b blocksize] [-h host] [-i file offset] "
"[-l label] [-v score] [-y] file\n", argv0);
- exits("usage");
+ threadexitsall("usage");
}
static void
@@ -203,7 +199,7 @@ partition(int fd, int bsize, Header *h)
/* sanity check */
if(nblock < (HeaderOffset*10)/bsize)
- vtFatal("file too small");
+ sysfatal("file too small");
h->super = (HeaderOffset + 2*bsize)/bsize;
h->label = h->super + 1;
@@ -236,7 +232,7 @@ entryInit(Entry *e)
e->flags = VtEntryActive;
e->depth = 0;
e->size = 0;
- memmove(e->score, vtZeroScore, VtScoreSize);
+ memmove(e->score, vtzeroscore, VtScoreSize);
e->tag = tagGen();
e->snap = 0;
e->archive = 0;
@@ -252,16 +248,16 @@ rootMetaInit(Entry *e)
MetaEntry me;
memset(&de, 0, sizeof(de));
- de.elem = vtStrDup("root");
+ de.elem = vtstrdup("root");
de.entry = 0;
de.gen = 0;
de.mentry = 1;
de.mgen = 0;
de.size = 0;
de.qid = qid++;
- de.uid = vtStrDup("adm");
- de.gid = vtStrDup("adm");
- de.mid = vtStrDup("adm");
+ de.uid = vtstrdup("adm");
+ de.gid = vtstrdup("adm");
+ de.mid = vtstrdup("adm");
de.mtime = time(0);
de.mcount = 0;
de.ctime = time(0);
@@ -306,7 +302,7 @@ rootInit(Entry *e)
entryPack(e, buf, 2);
entryInit(e);
- e->flags |= VtEntryDir;
+ e->flags |= _VtEntryDir;
entryPack(e, buf, 0);
entryInit(e);
@@ -315,7 +311,7 @@ rootInit(Entry *e)
blockWrite(PartData, addr);
entryInit(e);
- e->flags |= VtEntryLocal|VtEntryDir;
+ e->flags |= VtEntryLocal|_VtEntryDir;
e->size = VtEntrySize*3;
e->tag = tag;
localToGlobal(addr, e->score);
@@ -341,9 +337,9 @@ blockAlloc(int type, u32int tag)
blockRead(PartLabel, addr/lpb);
if(!labelUnpack(&l, buf, addr % lpb))
- vtFatal("bad label: %r");
+ sysfatal("bad label: %r");
if(l.state != BsFree)
- vtFatal("want to allocate block already in use");
+ sysfatal("want to allocate block already in use");
l.epoch = 1;
l.epochClose = ~(u32int)0;
l.type = type;
@@ -403,14 +399,14 @@ static void
blockRead(int part, u32int addr)
{
if(!diskReadRaw(disk, part, addr, buf))
- vtFatal("read failed: %r");
+ sysfatal("read failed: %r");
}
static void
blockWrite(int part, u32int addr)
{
if(!diskWriteRaw(disk, part, addr, buf))
- vtFatal("write failed: %r");
+ sysfatal("write failed: %r");
}
static void
@@ -420,7 +416,7 @@ addFile(File *root, char *name, uint mode)
f = fileCreate(root, name, mode | ModeDir, "adm");
if(f == nil)
- vtFatal("could not create file: %s: %r", name);
+ sysfatal("could not create file: %s: %r", name);
fileDecRef(f);
}
@@ -433,18 +429,18 @@ topLevel(char *name)
/* ok, now we can open as a fs */
fs = fsOpen(name, z, 100, OReadWrite);
if(fs == nil)
- vtFatal("could not open file system: %r");
- vtRLock(fs->elk);
+ sysfatal("could not open file system: %r");
+ rlock(&fs->elk);
root = fsGetRoot(fs);
if(root == nil)
- vtFatal("could not open root: %r");
+ sysfatal("could not open root: %r");
addFile(root, "active", 0555);
addFile(root, "archive", 0555);
addFile(root, "snapshot", 0555);
fileDecRef(root);
if(iso9660file)
iso9660copy(fs);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
fsClose(fs);
}
@@ -453,10 +449,10 @@ ventiRead(uchar score[VtScoreSize], int type)
{
int n;
- n = vtRead(z, score, type, buf, bsize);
+ n = vtread(z, score, type, buf, bsize);
if(n < 0)
- vtFatal("ventiRead %V (%d) failed: %R", score, type);
- vtZeroExtend(type, buf, n, bsize);
+ sysfatal("ventiRead %V (%d) failed: %r", score, type);
+ vtzeroextend(type, buf, n, bsize);
return n;
}
@@ -473,18 +469,18 @@ ventiRoot(char *host, char *s)
VtRoot root;
if(!parseScore(score, s))
- vtFatal("bad score '%s'", s);
+ sysfatal("bad score '%s'", s);
- if((z = vtDial(host, 0)) == nil
- || !vtConnect(z, nil))
- vtFatal("connect to venti: %R");
+ if((z = vtdial(host)) == nil
+ || vtconnect(z) < 0)
+ sysfatal("connect to venti: %r");
tag = tagGen();
addr = blockAlloc(BtDir, tag);
ventiRead(score, VtRootType);
- if(!vtRootUnpack(&root, buf))
- vtFatal("corrupted root: vtRootUnpack");
+ if(vtrootunpack(&root, buf) < 0)
+ sysfatal("corrupted root: vtrootunpack");
n = ventiRead(root.score, VtDirType);
/*
@@ -493,7 +489,7 @@ ventiRoot(char *host, char *s)
*/
if(n <= 2*VtEntrySize){
if(!entryUnpack(&e, buf, 0))
- vtFatal("bad root: top entry");
+ sysfatal("bad root: top entry");
n = ventiRead(e.score, VtDirType);
}
@@ -505,11 +501,11 @@ ventiRoot(char *host, char *s)
|| !(e.flags&VtEntryActive)
|| e.psize < 256
|| e.dsize < 256)
- vtFatal("bad root: entry %d", i);
+ sysfatal("bad root: entry %d", i);
fprint(2, "%V\n", e.score);
}
if(n > 3*VtEntrySize)
- vtFatal("bad root: entry count");
+ sysfatal("bad root: entry count");
blockWrite(PartData, addr);
@@ -518,19 +514,19 @@ ventiRoot(char *host, char *s)
*/
ventiRead(e.score, VtDataType);
if(!mbUnpack(&mb, buf, bsize))
- vtFatal("bad root: mbUnpack");
+ sysfatal("bad root: mbUnpack");
meUnpack(&me, &mb, 0);
if(!deUnpack(&de, &me))
- vtFatal("bad root: dirUnpack");
+ sysfatal("bad root: dirUnpack");
if(!de.qidSpace)
- vtFatal("bad root: no qidSpace");
+ sysfatal("bad root: no qidSpace");
qid = de.qidMax;
/*
* Recreate the top layer of source.
*/
entryInit(&e);
- e.flags |= VtEntryLocal|VtEntryDir;
+ e.flags |= VtEntryLocal|_VtEntryDir;
e.size = VtEntrySize*3;
e.tag = tag;
localToGlobal(addr, e.score);
diff --git a/src/cmd/fossil/flfmt9660.c b/src/cmd/fossil/flfmt9660.c
index 4464c9fb..d4097957 100644
--- a/src/cmd/fossil/flfmt9660.c
+++ b/src/cmd/fossil/flfmt9660.c
@@ -28,7 +28,7 @@ enum{
#pragma varargck type "L" uchar*
#pragma varargck type "B" uchar*
#pragma varargck type "N" uchar*
-#pragma varargck type "T" uchar*
+#pragma varargck type "C" uchar*
#pragma varargck type "D" uchar*
typedef struct Voldesc Voldesc;
@@ -73,8 +73,8 @@ dumpbootvol(void *a)
if(v->magic[0] == 0xFF)
return;
- print("system %.32T\n", v->systemid);
- print("volume %.32T\n", v->volumeid);
+ print("system %.32C\n", v->systemid);
+ print("volume %.32C\n", v->volumeid);
print("volume size %.4N\n", v->volsize);
print("charset %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n",
v->charset[0], v->charset[1], v->charset[2], v->charset[3],
@@ -88,13 +88,13 @@ dumpbootvol(void *a)
print("mpath loc %.4B\n", v->mpathloc);
print("opt mpath loc %.4B\n", v->ompathloc);
print("rootdir %D\n", v->rootdir);
- print("volume set identifier %.128T\n", v->volsetid);
- print("publisher %.128T\n", v->publisher);
- print("preparer %.128T\n", v->prepid);
- print("application %.128T\n", v->applid);
- print("notice %.37T\n", v->notice);
- print("abstract %.37T\n", v->abstract);
- print("biblio %.37T\n", v->biblio);
+ print("volume set identifier %.128C\n", v->volsetid);
+ print("publisher %.128C\n", v->publisher);
+ print("preparer %.128C\n", v->prepid);
+ print("application %.128C\n", v->applid);
+ print("notice %.37C\n", v->notice);
+ print("abstract %.37C\n", v->abstract);
+ print("biblio %.37C\n", v->biblio);
print("creation date %.17s\n", v->cdate);
print("modification date %.17s\n", v->mdate);
print("expiration date %.17s\n", v->xdate);
@@ -129,7 +129,7 @@ Dfmt(Fmt *fmt)
snprint(buf, sizeof buf, ".%s dloc %.4N dlen %.4N",
c->name[0] ? "." : "", c->dloc, c->dlen);
} else {
- snprint(buf, sizeof buf, "%.*T dloc %.4N dlen %.4N", c->namelen, c->name,
+ snprint(buf, sizeof buf, "%.*C dloc %.4N dlen %.4N", c->namelen, c->name,
c->dloc, c->dlen);
}
fmtstrcpy(fmt, buf);
@@ -239,7 +239,7 @@ asciiTfmt(Fmt *fmt)
static void
ascii(void)
{
- fmtinstall('T', asciiTfmt);
+ fmtinstall('C', asciiTfmt);
}
static int
@@ -299,35 +299,35 @@ iso9660init(int xfd, Header *xh, char *xfile9660, int xoff9660)
off9660 = xoff9660;
if((b = Bopen(file9660, OREAD)) == nil)
- vtFatal("Bopen %s: %r", file9660);
+ sysfatal("Bopen %s: %r", file9660);
getsect(root, 16);
ascii();
v = (Voldesc*)root;
if(memcmp(v->magic, "\x01CD001\x01\x00", 8) != 0)
- vtFatal("%s not a cd image", file9660);
+ sysfatal("%s not a cd image", file9660);
startoff = iso9660start((Cdir*)v->rootdir)*Blocksize;
endoff = little(v->volsize, 4); /* already in bytes */
fsoff = off9660 + h->data*h->blockSize;
if(fsoff > startoff)
- vtFatal("fossil data starts after cd data");
+ sysfatal("fossil data starts after cd data");
if(off9660 + (vlong)h->end*h->blockSize < endoff)
- vtFatal("fossil data ends before cd data");
+ sysfatal("fossil data ends before cd data");
if(fsoff%h->blockSize)
- vtFatal("cd offset not a multiple of fossil block size");
+ sysfatal("cd offset not a multiple of fossil block size");
/* Read "same" block via CD image and via Fossil image */
getsect(sect, startoff/Blocksize);
if(seek(fd, startoff-off9660, 0) < 0)
- vtFatal("cannot seek to first data sector on cd via fossil");
+ sysfatal("cannot seek to first data sector on cd via fossil");
fprint(2, "look for %lud at %lud\n", startoff, startoff-off9660);
if(readn(fd, sect2, Blocksize) != Blocksize)
- vtFatal("cannot read first data sector on cd via fossil");
+ sysfatal("cannot read first data sector on cd via fossil");
if(memcmp(sect, sect2, Blocksize) != 0)
- vtFatal("iso9660 offset is a lie %08ux %08ux", *(long*)sect, *(long*)sect2);
+ sysfatal("iso9660 offset is a lie %08lux %08lux", *(long*)sect, *(long*)sect2);
}
void
@@ -339,10 +339,10 @@ iso9660labels(Disk *disk, uchar *buf, void (*write)(int, u32int))
uchar sect[Blocksize];
if(!diskReadRaw(disk, PartData, (startoff-fsoff)/h->blockSize, buf))
- vtFatal("disk read failed: %r");
+ sysfatal("disk read failed: %r");
getsect(sect, startoff/Blocksize);
if(memcmp(buf, sect, Blocksize) != 0)
- vtFatal("fsoff is wrong");
+ sysfatal("fsoff is wrong");
sb = (startoff-fsoff)/h->blockSize;
eb = (endoff-fsoff+h->blockSize-1)/h->blockSize;
@@ -378,10 +378,10 @@ iso9660copy(Fs *fs)
root = fileOpen(fs, "/active");
iso9660copydir(fs, root, (Cdir*)v->rootdir);
fileDecRef(root);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
if(!fsSnapshot(fs, nil, nil, 0))
- vtFatal("snapshot failed: %R");
- vtRLock(fs->elk);
+ sysfatal("snapshot failed: %r");
+ rlock(&fs->elk);
}
/*
@@ -400,7 +400,7 @@ iso9660start(Cdir *c)
c = (Cdir*)((uchar*)c+c->len); /* skip dotdot */
/* oops: might happen if leftmost directory is empty or leftmost file is zero length! */
if(little(c->dloc, 4) == 0)
- vtFatal("error parsing cd image or unfortunate cd image");
+ sysfatal("error parsing cd image or unfortunate cd image");
}
return little(c->dloc, 4);
}
@@ -519,7 +519,7 @@ iso9660copyfile(Fs *fs, File *dir, Cdir *c)
p++;
sysl = (uchar*)c + c->len - p;
if(sysl <= 0)
- vtFatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
+ sysfatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
d.name = getname(&p);
d.uid = getname(&p);
d.gid = getname(&p);
@@ -537,7 +537,7 @@ if(d.mode&DMDIR) print("%*scopy %s %s %s %luo\n", ind*2, "", d.name, d.uid, d.gi
if(d.mode&DMDIR)
mode |= ModeDir;
if((f = fileCreate(dir, d.name, mode, d.uid)) == nil)
- vtFatal("could not create file '%s': %r", d.name);
+ sysfatal("could not create file '%s': %r", d.name);
if(d.mode&DMDIR)
iso9660copydir(fs, f, c);
else{
@@ -546,20 +546,20 @@ if(d.mode&DMDIR) print("%*scopy %s %s %s %luo\n", ind*2, "", d.name, d.uid, d.gi
for(foff=0; foff<len; foff+=h->blockSize){
localToGlobal((off+foff-fsoff)/h->blockSize, score);
if(!fileMapBlock(f, foff/h->blockSize, score, Tag))
- vtFatal("fileMapBlock: %R");
+ sysfatal("fileMapBlock: %r");
}
if(!fileSetSize(f, len))
- vtFatal("fileSetSize: %R");
+ sysfatal("fileSetSize: %r");
}
if(!fileGetDir(f, &de))
- vtFatal("fileGetDir: %R");
+ sysfatal("fileGetDir: %r");
de.uid = d.uid;
de.gid = d.gid;
de.mtime = d.mtime;
de.atime = d.atime;
de.mode = d.mode&0777;
if(!fileSetDir(f, &de, "sys"))
- vtFatal("fileSetDir: %R");
+ sysfatal("fileSetDir: %r");
fileDecRef(f);
ind--;
}
diff --git a/src/cmd/fossil/fns.h b/src/cmd/fossil/fns.h
index c22d3b79..daf9db7c 100644
--- a/src/cmd/fossil/fns.h
+++ b/src/cmd/fossil/fns.h
@@ -18,7 +18,7 @@ int sourceTruncate(Source*);
void sourceUnlock(Source*);
Block* cacheAllocBlock(Cache*, int, u32int, u32int, u32int);
-Cache* cacheAlloc(Disk*, VtSession*, ulong, int);
+Cache* cacheAlloc(Disk*, VtConn*, ulong, int);
void cacheCountUsed(Cache*, u32int, u32int*, u32int*, u32int*);
int cacheDirty(Cache*);
void cacheFlush(Cache*, int);
@@ -81,11 +81,11 @@ int fileGetSources(File*, Entry*, Entry*);
File* fileRoot(Source*);
int fileSnapshot(File*, File*, u32int, int);
int fsNextQid(Fs*, u64int*);
-int mkVac(VtSession*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
+int mkVac(VtConn*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
Block* superGet(Cache*, Super*);
void archFree(Arch*);
-Arch* archInit(Cache*, Disk*, Fs*, VtSession*);
+Arch* archInit(Cache*, Disk*, Fs*, VtConn*);
void archKick(Arch*);
void bwatchDependency(Block*);
diff --git a/src/cmd/fossil/fossil.c b/src/cmd/fossil/fossil.c
index 8ef68080..bdfc8ada 100644
--- a/src/cmd/fossil/fossil.c
+++ b/src/cmd/fossil/fossil.c
@@ -12,7 +12,7 @@ static void
usage(void)
{
fprint(2, "usage: %s [-Dt] [-c cmd] [-f partition] [-m %%]\n", argv0);
- exits("usage");
+ threadexitsall("usage");
}
static void
@@ -44,7 +44,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
for(i=0; i<nf; i++){
if(f[i][0] == '#')
continue;
- cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
+ cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
/* expand argument '*' to mean current file */
if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){
memmove(tbuf, f[i], p-f[i]);
@@ -52,7 +52,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1);
f[i] = tbuf;
}
- cmd[ncmd++] = vtStrDup(f[i]);
+ cmd[ncmd++] = vtstrdup(f[i]);
}
close(fd);
*pcmd = cmd;
@@ -60,7 +60,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
}
void
-main(int argc, char* argv[])
+threadmain(int argc, char* argv[])
{
char **cmd, *p;
int i, ncmd, tflag;
@@ -84,8 +84,6 @@ main(int argc, char* argv[])
cmd = nil;
ncmd = tflag = 0;
- vtAttach();
-
ARGBEGIN{
case '?':
default:
@@ -94,7 +92,7 @@ main(int argc, char* argv[])
case 'c':
p = EARGF(usage());
currfsysname = p;
- cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
+ cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
cmd[ncmd++] = p;
break;
case 'D':
@@ -132,12 +130,11 @@ main(int argc, char* argv[])
for(i = 0; i < ncmd; i++)
if(cliExec(cmd[i]) == 0)
- fprint(2, "%s: %R\n", cmd[i]);
- vtMemFree(cmd);
+ fprint(2, "%s: %r\n", cmd[i]);
+ vtfree(cmd);
if(tflag && consTTY() == 0)
- consPrint("%s\n", vtGetError());
+ consPrint("%r\n");
- vtDetach();
- exits(0);
+ threadexits(0);
}
diff --git a/src/cmd/fossil/fs.c b/src/cmd/fossil/fs.c
index ba15e661..5f8a1cfd 100644
--- a/src/cmd/fossil/fs.c
+++ b/src/cmd/fossil/fs.c
@@ -8,7 +8,7 @@ static Snap *snapInit(Fs*);
static void snapClose(Snap*);
Fs *
-fsOpen(char *file, VtSession *z, long ncache, int mode)
+fsOpen(char *file, VtConn *z, long ncache, int mode)
{
int fd, m;
uchar oscore[VtScoreSize];
@@ -16,10 +16,11 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
Disk *disk;
Fs *fs;
Super super;
+ char e[ERRMAX];
switch(mode){
default:
- vtSetError(EBadMode);
+ werrstr(EBadMode);
return nil;
case OReadOnly:
m = OREAD;
@@ -30,23 +31,22 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
}
fd = open(file, m);
if(fd < 0){
- vtSetError("open %s: %r", file);
+ werrstr("open %s: %r", file);
return nil;
}
bwatchInit();
disk = diskAlloc(fd);
if(disk == nil){
- vtSetError("diskAlloc: %R");
+ werrstr("diskAlloc: %r");
close(fd);
return nil;
}
- fs = vtMemAllocZ(sizeof(Fs));
+ fs = vtmallocz(sizeof(Fs));
fs->mode = mode;
- fs->name = vtStrDup(file);
+ fs->name = vtstrdup(file);
fs->blockSize = diskBlockSize(disk);
- fs->elk = vtLockAlloc();
fs->cache = cacheAlloc(disk, z, ncache, mode);
if(mode == OReadWrite && z)
fs->arch = archInit(fs->cache, disk, fs, z);
@@ -57,7 +57,7 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
goto Err;
if(!superUnpack(&super, b->data)){
blockPut(b);
- vtSetError("bad super block");
+ werrstr("bad super block");
goto Err;
}
blockPut(b);
@@ -73,17 +73,18 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
* Perhaps it failed because the block is copy-on-write.
* Do the copy and try again.
*/
- if(mode == OReadOnly || strcmp(vtGetError(), EBadRoot) != 0)
+ rerrstr(e, sizeof e);
+ if(mode == OReadOnly || strcmp(e, EBadRoot) != 0)
goto Err;
b = cacheLocalData(fs->cache, super.active, BtDir, RootTag,
OReadWrite, 0);
if(b == nil){
- vtSetError("cacheLocalData: %R");
+ werrstr("cacheLocalData: %r");
goto Err;
}
if(b->l.epoch == fs->ehi){
blockPut(b);
- vtSetError("bad root source block");
+ werrstr("bad root source block");
goto Err;
}
b = blockCopy(b, RootTag, fs->ehi, fs->elo);
@@ -94,7 +95,7 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite);
if(bs == nil){
blockPut(b);
- vtSetError("cacheLocal: %R");
+ werrstr("cacheLocal: %r");
goto Err;
}
superPack(&super, bs->data);
@@ -105,19 +106,19 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
blockPut(bs);
fs->source = sourceRoot(fs, super.active, mode);
if(fs->source == nil){
- vtSetError("sourceRoot: %R");
+ werrstr("sourceRoot: %r");
goto Err;
}
}
//fprint(2, "%s: got fs source\n", argv0);
- vtRLock(fs->elk);
+ rlock(&fs->elk);
fs->file = fileRoot(fs->source);
fs->source->file = fs->file; /* point back */
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
if(fs->file == nil){
- vtSetError("fileRoot: %R");
+ werrstr("fileRoot: %r");
goto Err;
}
@@ -138,32 +139,31 @@ fprint(2, "%s: fsOpen error\n", argv0);
void
fsClose(Fs *fs)
{
- vtRLock(fs->elk);
+ rlock(&fs->elk);
periodicKill(fs->metaFlush);
snapClose(fs->snap);
if(fs->file){
fileMetaFlush(fs->file, 0);
if(!fileDecRef(fs->file))
- vtFatal("fsClose: files still in use: %r\n");
+ sysfatal("fsClose: files still in use: %r");
}
fs->file = nil;
sourceClose(fs->source);
cacheFree(fs->cache);
if(fs->arch)
archFree(fs->arch);
- vtMemFree(fs->name);
- vtRUnlock(fs->elk);
- vtLockFree(fs->elk);
+ vtfree(fs->name);
+ runlock(&fs->elk);
memset(fs, ~0, sizeof(Fs));
- vtMemFree(fs);
+ vtfree(fs);
}
int
fsRedial(Fs *fs, char *host)
{
- if(!vtRedial(fs->z, host))
+ if(vtredial(fs->z, host) < 0)
return 0;
- if(!vtConnect(fs->z, 0))
+ if(vtconnect(fs->z) < 0)
return 0;
return 1;
}
@@ -186,11 +186,11 @@ superGet(Cache *c, Super* super)
Block *b;
if((b = cacheLocal(c, PartSuper, 0, OReadWrite)) == nil){
- fprint(2, "%s: superGet: cacheLocal failed: %R\n", argv0);
+ fprint(2, "%s: superGet: cacheLocal failed: %r\n", argv0);
return nil;
}
if(!superUnpack(super, b->data)){
- fprint(2, "%s: superGet: superUnpack failed: %R\n", argv0);
+ fprint(2, "%s: superGet: superUnpack failed: %r\n", argv0);
blockPut(b);
return nil;
}
@@ -212,7 +212,7 @@ superWrite(Block* b, Super* super, int forceWrite)
}
while(b->iostate != BioClean && b->iostate != BioDirty){
assert(b->iostate == BioWriting);
- vtSleep(b->ioready);
+ rsleep(&b->ioready);
}
/*
* it's okay that b might still be dirty.
@@ -361,13 +361,13 @@ fsNeedArch(Fs *fs, uint archMinute)
snprint(buf, sizeof buf, "/archive/%d/%02d%02d",
now.year+1900, now.mon+1, now.mday);
need = 1;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
f = fileOpen(fs, buf);
if(f){
need = 0;
fileDecRef(f);
}
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return need;
}
@@ -377,15 +377,15 @@ fsEpochLow(Fs *fs, u32int low)
Block *bs;
Super super;
- vtLock(fs->elk);
+ wlock(&fs->elk);
if(low > fs->ehi){
- vtSetError("bad low epoch (must be <= %ud)", fs->ehi);
- vtUnlock(fs->elk);
+ werrstr("bad low epoch (must be <= %ud)", fs->ehi);
+ wunlock(&fs->elk);
return 0;
}
if((bs = superGet(fs->cache, &super)) == nil){
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
return 0;
}
@@ -393,7 +393,7 @@ fsEpochLow(Fs *fs, u32int low)
fs->elo = low;
superWrite(bs, &super, 1);
blockPut(bs);
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
return 1;
}
@@ -421,14 +421,14 @@ bumpEpoch(Fs *fs, int doarchive)
return 0;
memset(&e, 0, sizeof e);
- e.flags = VtEntryActive | VtEntryLocal | VtEntryDir;
+ e.flags = VtEntryActive | VtEntryLocal | _VtEntryDir;
memmove(e.score, b->score, VtScoreSize);
e.tag = RootTag;
e.snap = b->l.epoch;
b = blockCopy(b, RootTag, fs->ehi+1, fs->elo);
if(b == nil){
- fprint(2, "%s: bumpEpoch: blockCopy: %R\n", argv0);
+ fprint(2, "%s: bumpEpoch: blockCopy: %r\n", argv0);
return 0;
}
@@ -507,14 +507,14 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
dst = nil;
if(fs->halted){
- vtSetError("file system is halted");
+ werrstr("file system is halted");
return 0;
}
/*
* Freeze file system activity.
*/
- vtLock(fs->elk);
+ wlock(&fs->elk);
/*
* Get the root of the directory we're going to save.
@@ -599,7 +599,7 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
goto Err;
}
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
/* BUG? can fs->arch fall out from under us here? */
if(doarchive && fs->arch)
@@ -608,12 +608,12 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
return 1;
Err:
- fprint(2, "%s: fsSnapshot: %R\n", argv0);
+ fprint(2, "%s: fsSnapshot: %r\n", argv0);
if(src)
fileDecRef(src);
if(dst)
fileDecRef(dst);
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
return 0;
}
@@ -625,37 +625,37 @@ fsVac(Fs *fs, char *name, uchar score[VtScoreSize])
Entry e, ee;
File *f;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
f = fileOpen(fs, name);
if(f == nil){
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 0;
}
if(!fileGetSources(f, &e, &ee) || !fileGetDir(f, &de)){
fileDecRef(f);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return 0;
}
fileDecRef(f);
r = mkVac(fs->z, fs->blockSize, &e, &ee, &de, score);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
return r;
}
static int
-vtWriteBlock(VtSession *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
+vtWriteBlock(VtConn *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
{
- if(!vtWrite(z, score, type, buf, n))
+ if(vtwrite(z, score, type, buf, n) < 0)
return 0;
- if(!vtSha1Check(score, buf, n))
+ if(vtsha1check(score, buf, n) < 0)
return 0;
return 1;
}
int
-mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
+mkVac(VtConn *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
{
uchar buf[8192];
int i;
@@ -673,7 +673,7 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
if(globalToLocal(e.score) != NilBlock
|| (ee.flags&VtEntryActive && globalToLocal(ee.score) != NilBlock)){
- vtSetError("can only vac paths already stored on venti");
+ werrstr("can only vac paths already stored on venti");
return 0;
}
@@ -682,7 +682,7 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
*/
n = deSize(&de);
if(n+MetaHeaderSize+MetaIndexSize > sizeof buf){
- vtSetError("DirEntry too big");
+ werrstr("DirEntry too big");
return 0;
}
memset(buf, 0, sizeof buf);
@@ -721,11 +721,10 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
/*
* Save root.
*/
- root.version = VtRootVersion;
strecpy(root.type, root.type+sizeof root.type, "vac");
strecpy(root.name, root.name+sizeof root.name, de.elem);
- root.blockSize = blockSize;
- vtRootPack(&root, buf);
+ root.blocksize = blockSize;
+ vtrootpack(&root, buf);
if(!vtWriteBlock(z, buf, VtRootSize, VtRootType, score))
return 0;
@@ -735,17 +734,17 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
int
fsSync(Fs *fs)
{
- vtLock(fs->elk);
+ wlock(&fs->elk);
fileMetaFlush(fs->file, 1);
cacheFlush(fs->cache, 1);
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
return 1;
}
int
fsHalt(Fs *fs)
{
- vtLock(fs->elk);
+ wlock(&fs->elk);
fs->halted = 1;
fileMetaFlush(fs->file, 1);
cacheFlush(fs->cache, 1);
@@ -758,7 +757,7 @@ fsUnhalt(Fs *fs)
if(!fs->halted)
return 0;
fs->halted = 0;
- vtUnlock(fs->elk);
+ wunlock(&fs->elk);
return 1;
}
@@ -789,9 +788,9 @@ fsMetaFlush(void *a)
int rv;
Fs *fs = a;
- vtRLock(fs->elk);
+ rlock(&fs->elk);
rv = fileMetaFlush(fs->file, 1);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
if(rv > 0)
cacheFlush(fs->cache, 0);
}
@@ -828,7 +827,7 @@ fsEsearch1(File *f, char *path, u32int savetime, u32int *plo)
if((ff = fileWalk(f, de.elem)) != nil){
t = smprint("%s/%s", path, de.elem);
n += fsEsearch1(ff, t, savetime, plo);
- vtMemFree(t);
+ vtfree(t);
fileDecRef(ff);
}
}
@@ -876,11 +875,11 @@ fsSnapshotCleanup(Fs *fs, u32int age)
* given that we need to save all the unventied archives
* and all the snapshots younger than age.
*/
- vtRLock(fs->elk);
+ rlock(&fs->elk);
lo = fs->ehi;
fsEsearch(fs, "/archive", 0, &lo);
fsEsearch(fs, "/snapshot", time(0)-age*60, &lo);
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
fsEpochLow(fs, lo);
fsSnapshotRemove(fs);
@@ -895,7 +894,7 @@ fsRsearch1(File *f, char *s)
DirEntry de;
DirEntryEnum *dee;
File *ff;
- char *t;
+ char *t, e[ERRMAX];
dee = deeOpen(f);
if(dee == nil)
@@ -908,9 +907,10 @@ fsRsearch1(File *f, char *s)
break;
n++;
if(de.mode & ModeSnapshot){
+ rerrstr(e, sizeof e);
if((ff = fileWalk(f, de.elem)) != nil)
fileDecRef(ff);
- else if(strcmp(vtGetError(), ESnapOld) == 0){
+ else if(strcmp(e, ESnapOld) == 0){
if(fileClri(f, de.elem, "adm"))
n--;
}
@@ -921,7 +921,7 @@ fsRsearch1(File *f, char *s)
if(fsRsearch1(ff, t) == 0)
if(fileRemove(ff, "adm"))
n--;
- vtMemFree(t);
+ vtfree(t);
fileDecRef(ff);
}
}
@@ -961,16 +961,16 @@ fsRsearch(Fs *fs, char *path)
void
fsSnapshotRemove(Fs *fs)
{
- vtRLock(fs->elk);
+ rlock(&fs->elk);
fsRsearch(fs, "/snapshot");
- vtRUnlock(fs->elk);
+ runlock(&fs->elk);
}
struct Snap
{
Fs *fs;
Periodic*tick;
- VtLock *lk;
+ QLock lk;
uint snapMinutes;
uint archMinute;
uint snapLife;
@@ -992,7 +992,7 @@ snapEvent(void *v)
s = v;
now = time(0)/60;
- vtLock(s->lk);
+ qlock(&s->lk);
/*
* Snapshots happen every snapMinutes minutes.
@@ -1002,7 +1002,7 @@ snapEvent(void *v)
if(s->snapMinutes != ~0 && s->snapMinutes != 0
&& now%s->snapMinutes==0 && now != s->lastSnap){
if(!fsSnapshot(s->fs, nil, nil, 0))
- fprint(2, "%s: fsSnapshot snap: %R\n", argv0);
+ fprint(2, "%s: fsSnapshot snap: %r\n", argv0);
s->lastSnap = now;
}
@@ -1038,7 +1038,7 @@ snapEvent(void *v)
fsSnapshotCleanup(s->fs, s->snapLife);
s->lastCleanup = now;
}
- vtUnlock(s->lk);
+ qunlock(&s->lk);
}
static Snap*
@@ -1046,10 +1046,9 @@ snapInit(Fs *fs)
{
Snap *s;
- s = vtMemAllocZ(sizeof(Snap));
+ s = vtmallocz(sizeof(Snap));
s->fs = fs;
s->tick = periodicAlloc(snapEvent, s, 10*1000);
- s->lk = vtLockAlloc();
s->snapMinutes = -1;
s->archMinute = -1;
s->snapLife = -1;
@@ -1067,11 +1066,11 @@ snapGetTimes(Snap *s, u32int *arch, u32int *snap, u32int *snaplen)
return;
}
- vtLock(s->lk);
+ qlock(&s->lk);
*snap = s->snapMinutes;
*arch = s->archMinute;
*snaplen = s->snapLife;
- vtUnlock(s->lk);
+ qunlock(&s->lk);
}
void
@@ -1080,11 +1079,11 @@ snapSetTimes(Snap *s, u32int arch, u32int snap, u32int snaplen)
if(s == nil)
return;
- vtLock(s->lk);
+ qlock(&s->lk);
s->snapMinutes = snap;
s->archMinute = arch;
s->snapLife = snaplen;
- vtUnlock(s->lk);
+ qunlock(&s->lk);
}
static void
@@ -1094,6 +1093,6 @@ snapClose(Snap *s)
return;
periodicKill(s->tick);
- vtMemFree(s);
+ vtfree(s);
}
diff --git a/src/cmd/fossil/fs.h b/src/cmd/fossil/fs.h
index 67314d1f..67792ce7 100644
--- a/src/cmd/fossil/fs.h
+++ b/src/cmd/fossil/fs.h
@@ -6,6 +6,17 @@ typedef struct DirEntryEnum DirEntryEnum;
#pragma incomplete File
#pragma incomplete DirEntryEnum
+enum
+{
+ STACK = 32*1024,
+};
+
+enum
+{
+ // XXX What to do here?
+ VtMaxLumpSize = 65536,
+};
+
/* modes */
enum {
@@ -21,7 +32,7 @@ void fsClose(Fs*);
int fsEpochLow(Fs*, u32int);
File *fsGetRoot(Fs*);
int fsHalt(Fs*);
-Fs *fsOpen(char*, VtSession*, long, int);
+Fs *fsOpen(char*, VtConn*, long, int);
int fsRedial(Fs*, char*);
void fsSnapshotCleanup(Fs*, u32int);
int fsSnapshot(Fs*, char*, char*, int);
diff --git a/src/cmd/fossil/mkfile b/src/cmd/fossil/mkfile
index cf2b0bdc..7b76af76 100644
--- a/src/cmd/fossil/mkfile
+++ b/src/cmd/fossil/mkfile
@@ -1,7 +1,7 @@
</$objtype/mkfile
BIN=/$objtype/bin/fossil
-TARG=fossil flchk flfmt conf last
+TARG=fossil flchk flfmt conf last view
LIBFILES=\
9p\
@@ -37,7 +37,7 @@ LIBOFILES=${LIBFILES:%=%.$O}
LIB=libfs.a$O
HFILES=\
- /sys/include/oventi.h\
+ /sys/include/venti.h\
stdinc.h\
vac.h\
dat.h\
diff --git a/src/cmd/fossil/pack.c b/src/cmd/fossil/pack.c
index 9fd2070c..1dc33470 100644
--- a/src/cmd/fossil/pack.c
+++ b/src/cmd/fossil/pack.c
@@ -35,12 +35,12 @@ int
headerUnpack(Header *h, uchar *p)
{
if(U32GET(p) != HeaderMagic){
- vtSetError("vac header bad magic");
+ werrstr("vac header bad magic");
return 0;
}
h->version = U16GET(p+4);
if(h->version != HeaderVersion){
- vtSetError("vac header bad version");
+ werrstr("vac header bad version");
return 0;
}
h->blockSize = U16GET(p+6);
@@ -74,7 +74,7 @@ labelUnpack(Label *l, uchar *p, int i)
if(l->type > BtMax){
Bad:
- vtSetError(EBadLabel);
+ werrstr(EBadLabel);
fprint(2, "%s: labelUnpack: bad label: 0x%.2ux 0x%.2ux 0x%.8ux "
"0x%.8ux 0x%.8ux\n", argv0, l->state, l->type, l->epoch,
l->epochClose, l->tag);
@@ -124,7 +124,7 @@ entryPack(Entry *e, uchar *p, int index)
U32PUT(p, e->gen);
U16PUT(p+4, e->psize);
U16PUT(p+6, e->dsize);
- flags = e->flags | ((e->depth << VtEntryDepthShift) & VtEntryDepthMask);
+ flags = e->flags | ((e->depth << _VtEntryDepthShift) & _VtEntryDepthMask);
U8PUT(p+8, flags);
memset(p+9, 0, 5);
U48PUT(p+14, e->size, t32);
@@ -150,8 +150,8 @@ entryUnpack(Entry *e, uchar *p, int index)
e->psize = U16GET(p+4);
e->dsize = U16GET(p+6);
e->flags = U8GET(p+8);
- e->depth = (e->flags & VtEntryDepthMask) >> VtEntryDepthShift;
- e->flags &= ~VtEntryDepthMask;
+ e->depth = (e->flags & _VtEntryDepthMask) >> _VtEntryDepthShift;
+ e->flags &= ~_VtEntryDepthMask;
e->size = U48GET(p+14);
if(e->flags & VtEntryLocal){
@@ -173,7 +173,7 @@ entryUnpack(Entry *e, uchar *p, int index)
int
entryType(Entry *e)
{
- return (((e->flags & VtEntryDir) != 0) << 3) | e->depth;
+ return (((e->flags & _VtEntryDir) != 0) << 3) | e->depth;
}
@@ -219,7 +219,7 @@ superUnpack(Super *s, uchar *p)
return 1;
Err:
memset(s, 0, sizeof(*s));
- vtSetError(EBadSuper);
+ werrstr(EBadSuper);
return 0;
}
diff --git a/src/cmd/fossil/periodic.c b/src/cmd/fossil/periodic.c
index 8a0c2084..634f975d 100644
--- a/src/cmd/fossil/periodic.c
+++ b/src/cmd/fossil/periodic.c
@@ -4,7 +4,7 @@
#include "error.h"
struct Periodic {
- VtLock *lk;
+ QLock lk;
int die; /* flag: quit if set */
void (*f)(void*); /* call this each period */
void *a; /* argument to f */
@@ -18,15 +18,14 @@ periodicAlloc(void (*f)(void*), void *a, int msec)
{
Periodic *p;
- p = vtMemAllocZ(sizeof(Periodic));
- p->lk = vtLockAlloc();
+ p = vtmallocz(sizeof(Periodic));
p->f = f;
p->a = a;
p->msec = msec;
if(p->msec < 10)
p->msec = 10;
- vtThread(periodicThread, p);
+ proccreate(periodicThread, p, STACK);
return p;
}
@@ -35,16 +34,15 @@ periodicKill(Periodic *p)
{
if(p == nil)
return;
- vtLock(p->lk);
+ qlock(&p->lk);
p->die = 1;
- vtUnlock(p->lk);
+ qunlock(&p->lk);
}
static void
periodicFree(Periodic *p)
{
- vtLockFree(p->lk);
- vtMemFree(p);
+ vtfree(p);
}
static void
@@ -53,7 +51,7 @@ periodicThread(void *a)
Periodic *p = a;
vlong t, ct, ts; /* times in ms. */
- vtThreadSetName("periodic");
+ threadsetname("periodic");
ct = nsec() / 1000000;
t = ct + p->msec; /* call p->f at or after this time */
@@ -65,9 +63,9 @@ periodicThread(void *a)
if(ts > 0)
sleep(ts); /* wait for cycle's start */
- vtLock(p->lk);
+ qlock(&p->lk);
if(p->die){
- vtUnlock(p->lk);
+ qunlock(&p->lk);
break;
}
ct = nsec() / 1000000;
@@ -77,7 +75,7 @@ periodicThread(void *a)
while(t <= ct) /* advance t to future cycle start */
t += p->msec;
}
- vtUnlock(p->lk);
+ qunlock(&p->lk);
}
periodicFree(p);
}
diff --git a/src/cmd/fossil/source.c b/src/cmd/fossil/source.c
index aa614192..d5bb297b 100644
--- a/src/cmd/fossil/source.c
+++ b/src/cmd/fossil/source.c
@@ -83,12 +83,12 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
epoch = b->l.epoch;
if(mode == OReadWrite){
if(e.snap != 0){
- vtSetError(ESnapRO);
+ werrstr(ESnapRO);
return nil;
}
}else if(e.snap != 0){
if(e.snap < fs->elo){
- vtSetError(ESnapOld);
+ werrstr(ESnapOld);
return nil;
}
if(e.snap >= fs->ehi)
@@ -96,21 +96,20 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
epoch = e.snap;
}
- r = vtMemAllocZ(sizeof(Source));
+ r = vtmallocz(sizeof(Source));
r->fs = fs;
r->mode = mode;
r->issnapshot = issnapshot;
r->dsize = e.dsize;
r->gen = e.gen;
- r->dir = (e.flags & VtEntryDir) != 0;
- r->lk = vtLockAlloc();
+ r->dir = (e.flags & _VtEntryDir) != 0;
r->ref = 1;
r->parent = p;
if(p){
- vtLock(p->lk);
+ qlock(&p->lk);
assert(mode == OReadOnly || p->mode == OReadWrite);
p->ref++;
- vtUnlock(p->lk);
+ qunlock(&p->lk);
}
r->epoch = epoch;
// consPrint("sourceAlloc: have %V be.%d fse.%d %s\n", b->score,
@@ -126,7 +125,7 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
return r;
Bad:
free(pname);
- vtSetError(EBadEntry);
+ werrstr(EBadEntry);
return nil;
}
@@ -144,7 +143,7 @@ sourceRoot(Fs *fs, u32int addr, int mode)
consPrint("sourceRoot: fs->ehi = %ud, b->l = %L\n",
fs->ehi, &b->l);
blockPut(b);
- vtSetError(EBadRoot);
+ werrstr(EBadRoot);
return nil;
}
@@ -163,7 +162,7 @@ sourceOpen(Source *r, ulong offset, int mode, int issnapshot)
if(r->mode == OReadWrite)
assert(r->epoch == r->b->l.epoch);
if(!r->dir){
- vtSetError(ENotDir);
+ werrstr(ENotDir);
return nil;
}
@@ -189,7 +188,7 @@ sourceCreate(Source *r, int dsize, int dir, u32int offset)
assert(sourceIsLocked(r));
if(!r->dir){
- vtSetError(ENotDir);
+ werrstr(ENotDir);
return nil;
}
@@ -219,7 +218,7 @@ sourceCreate(Source *r, int dsize, int dir, u32int offset)
blockPut(b);
if(offset == size){
fprint(2, "sourceCreate: cannot happen\n");
- vtSetError("sourceCreate: cannot happen");
+ werrstr("sourceCreate: cannot happen");
return nil;
}
offset = size;
@@ -232,10 +231,10 @@ Found:
assert(psize && dsize);
e.flags = VtEntryActive;
if(dir)
- e.flags |= VtEntryDir;
+ e.flags |= _VtEntryDir;
e.depth = 0;
e.size = 0;
- memmove(e.score, vtZeroScore, VtScoreSize);
+ memmove(e.score, vtzeroscore, VtScoreSize);
e.tag = 0;
e.snap = 0;
e.archive = 0;
@@ -294,7 +293,7 @@ sourceKill(Source *r, int doremove)
e.depth = 0;
e.size = 0;
e.tag = 0;
- memmove(e.score, vtZeroScore, VtScoreSize);
+ memmove(e.score, vtzeroscore, VtScoreSize);
entryPack(&e, b->data, r->offset % r->epb);
blockDirty(b);
if(addr != NilBlock)
@@ -370,7 +369,7 @@ sourceShrinkSize(Source *r, Entry *e, uvlong size)
i = (size+ptrsz-1)/ptrsz;
for(; i<ppb; i++){
addr = globalToLocal(b->data+i*VtScoreSize);
- memmove(b->data+i*VtScoreSize, vtZeroScore, VtScoreSize);
+ memmove(b->data+i*VtScoreSize, vtzeroscore, VtScoreSize);
blockDirty(b);
if(addr != NilBlock)
blockRemoveLink(b, addr, type-1, e->tag, 1);
@@ -420,7 +419,7 @@ sourceSetSize(Source *r, uvlong size)
return sourceTruncate(r);
if(size > VtMaxFileSize || size > ((uvlong)MaxBlock)*r->dsize){
- vtSetError(ETooBig);
+ werrstr(ETooBig);
return 0;
}
@@ -637,7 +636,7 @@ sourceGrowDepth(Source *r, Block *p, Entry *e, int depth)
type++;
e->tag = tag;
e->flags |= VtEntryLocal;
- blockDependency(bb, b, 0, vtZeroScore, nil);
+ blockDependency(bb, b, 0, vtzeroscore, nil);
blockPut(b);
b = bb;
blockDirty(b);
@@ -718,7 +717,7 @@ sourceShrinkDepth(Source *r, Block *p, Entry *e, int depth)
blockDirty(p);
/* (ii) */
- memmove(ob->data, vtZeroScore, VtScoreSize);
+ memmove(ob->data, vtzeroscore, VtScoreSize);
blockDependency(ob, p, 0, b->score, nil);
blockDirty(ob);
@@ -761,7 +760,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
return nil;
if(r->issnapshot && (e.flags & VtEntryNoArchive)){
blockPut(b);
- vtSetError(ENotArchived);
+ werrstr(ENotArchived);
return nil;
}
@@ -770,7 +769,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
e.tag = tag;
else if(e.tag != tag){
fprint(2, "tag mismatch\n");
- vtSetError("tag mismatch");
+ werrstr("tag mismatch");
goto Err;
}
}
@@ -779,7 +778,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
memset(index, 0, sizeof(index));
for(i=0; bn > 0; i++){
if(i >= VtPointerDepth){
- vtSetError(EBadAddr);
+ werrstr(EBadAddr);
goto Err;
}
index[i] = bn % np;
@@ -788,7 +787,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
if(i > e.depth){
if(mode == OReadOnly){
- vtSetError(EBadAddr);
+ werrstr(EBadAddr);
goto Err;
}
if(!sourceGrowDepth(r, b, &e, i))
@@ -827,19 +826,18 @@ sourceClose(Source *r)
{
if(r == nil)
return;
- vtLock(r->lk);
+ qlock(&r->lk);
r->ref--;
if(r->ref){
- vtUnlock(r->lk);
+ qunlock(&r->lk);
return;
}
assert(r->ref == 0);
- vtUnlock(r->lk);
+ qunlock(&r->lk);
if(r->parent)
sourceClose(r->parent);
- vtLockFree(r->lk);
memset(r, ~0, sizeof(*r));
- vtMemFree(r);
+ vtfree(r);
}
/*
@@ -858,6 +856,7 @@ sourceLoadBlock(Source *r, int mode)
{
u32int addr;
Block *b;
+ char e[ERRMAX];
switch(r->mode){
default:
@@ -912,7 +911,8 @@ sourceLoadBlock(Source *r, int mode)
* a snapshot. (Or else the file system is read-only, but then
* the archiver isn't going around deleting blocks.)
*/
- if(strcmp(vtGetError(), ELabelMismatch) == 0){
+ rerrstr(e, sizeof e);
+ if(strcmp(e, ELabelMismatch) == 0){
if(!sourceLock(r->parent, OReadOnly))
return nil;
b = sourceBlock(r->parent, r->offset/r->epb, OReadOnly);
@@ -1027,7 +1027,7 @@ sourceLoad(Source *r, Entry *e)
if(!entryUnpack(e, b->data, r->offset % r->epb))
return nil;
if(e->gen != r->gen){
- vtSetError(ERemoved);
+ werrstr(ERemoved);
return nil;
}
blockDupLock(b);
diff --git a/src/cmd/fossil/stdinc.h b/src/cmd/fossil/stdinc.h
index ef611898..e18ad91a 100644
--- a/src/cmd/fossil/stdinc.h
+++ b/src/cmd/fossil/stdinc.h
@@ -1,11 +1,12 @@
#include <u.h>
#include <libc.h>
+#include <libsec.h>
+#include <thread.h>
typedef uvlong u64int;
typedef uchar u8int;
typedef ushort u16int;
-#include "oventi.h"
+#include "venti.h"
#include "vac.h"
#include "fs.h"
-
diff --git a/src/cmd/fossil/vac.c b/src/cmd/fossil/vac.c
index 526ff971..85f0c7f2 100644
--- a/src/cmd/fossil/vac.c
+++ b/src/cmd/fossil/vac.c
@@ -45,7 +45,7 @@ stringUnpack(char **s, uchar **p, int *n)
*n -= 2;
if(nn > *n)
return 0;
- *s = vtMemAlloc(nn+1);
+ *s = vtmalloc(nn+1);
memmove(*s, *p, nn);
(*s)[nn] = 0;
*p += nn;
@@ -99,7 +99,7 @@ if(0)fprint(2, "mbSearch %s\n", elem);
*ri = b; /* b is the index to insert this entry */
memset(me, 0, sizeof(*me));
- vtSetError(ENoFile);
+ werrstr(ENoFile);
return 0;
}
@@ -164,7 +164,7 @@ mbUnpack(MetaBlock *mb, uchar *p, int n)
return 1;
Err:
- vtSetError(EBadMeta);
+ werrstr(EBadMeta);
return 0;
}
@@ -375,7 +375,7 @@ metaChunks(MetaBlock *mb)
int oo, o, n, i;
uchar *p;
- mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
+ mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
p = mb->buf + MetaHeaderSize;
for(i = 0; i<mb->nindex; i++){
mc[i].offset = U16GET(p);
@@ -411,8 +411,8 @@ fprint(2, "\t%d: %d %d\n", i, mc[i].offset, mc[i].offset + mc[i].size);
oo += mc[i].size;
}
fprint(2, "\tused=%d size=%d free=%d free2=%d\n", oo, mb->size, mb->free, mb->size - oo);
- vtSetError(EBadMeta);
- vtMemFree(mc);
+ werrstr(EBadMeta);
+ vtfree(mc);
return nil;
}
@@ -461,23 +461,23 @@ fprint(2, "mbAlloc: metaChunks failed: %r\n");
o = MetaHeaderSize + mb->maxindex*MetaIndexSize;
for(i=0; i<mb->nindex; i++){
if(mc[i].offset - o >= n){
- vtMemFree(mc);
+ vtfree(mc);
return mb->buf + o;
}
o = mc[i].offset + mc[i].size;
}
if(mb->maxsize - o >= n){
- vtMemFree(mc);
+ vtfree(mc);
return mb->buf + o;
}
/* compact and return off the end */
mbCompact(mb, mc);
- vtMemFree(mc);
+ vtfree(mc);
if(mb->maxsize - mb->size < n){
- vtSetError(EBadMeta);
+ werrstr(EBadMeta);
return nil;
}
return mb->buf + mb->size;
@@ -717,7 +717,7 @@ if(0)print("deUnpack: correct size\n");
return 1;
Err:
if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
- vtSetError(EBadMeta);
+ werrstr(EBadMeta);
deCleanup(dir);
return 0;
}
@@ -725,13 +725,13 @@ if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
void
deCleanup(DirEntry *dir)
{
- vtMemFree(dir->elem);
+ vtfree(dir->elem);
dir->elem = nil;
- vtMemFree(dir->uid);
+ vtfree(dir->uid);
dir->uid = nil;
- vtMemFree(dir->gid);
+ vtfree(dir->gid);
dir->gid = nil;
- vtMemFree(dir->mid);
+ vtfree(dir->mid);
dir->mid = nil;
}
@@ -739,8 +739,8 @@ void
deCopy(DirEntry *dst, DirEntry *src)
{
*dst = *src;
- dst->elem = vtStrDup(src->elem);
- dst->uid = vtStrDup(src->uid);
- dst->gid = vtStrDup(src->gid);
- dst->mid = vtStrDup(src->mid);
+ dst->elem = vtstrdup(src->elem);
+ dst->uid = vtstrdup(src->uid);
+ dst->gid = vtstrdup(src->gid);
+ dst->mid = vtstrdup(src->mid);
}
diff --git a/src/cmd/fossil/view.c b/src/cmd/fossil/view.c
index c2ac9976..54a55861 100644
--- a/src/cmd/fossil/view.c
+++ b/src/cmd/fossil/view.c
@@ -52,9 +52,10 @@ Tnode *initxdatablock(Block*, uint);
Tnode *initxroot(char *name, uchar[VtScoreSize]);
int fd;
+int mainstacksize = STACK;
Header h;
Super super;
-VtSession *z;
+VtConn *z;
VtRoot vac;
int showinactive;
@@ -107,7 +108,6 @@ btStr(int type)
return bttab[type];
return "unknown";
}
-#pragma varargck argpos stringnode 1
Block*
allocBlock(void)
@@ -197,21 +197,21 @@ readBlock(int part, u32int addr)
int vtType[BtMax] = {
VtDataType, /* BtData | 0 */
- VtPointerType0, /* BtData | 1 */
- VtPointerType1, /* BtData | 2 */
- VtPointerType2, /* BtData | 3 */
- VtPointerType3, /* BtData | 4 */
- VtPointerType4, /* BtData | 5 */
- VtPointerType5, /* BtData | 6 */
- VtPointerType6, /* BtData | 7 */
+ VtDataType+1, /* BtData | 1 */
+ VtDataType+2, /* BtData | 2 */
+ VtDataType+3, /* BtData | 3 */
+ VtDataType+4, /* BtData | 4 */
+ VtDataType+5, /* BtData | 5 */
+ VtDataType+6, /* BtData | 6 */
+ VtDataType+7, /* BtData | 7 */
VtDirType, /* BtDir | 0 */
- VtPointerType0, /* BtDir | 1 */
- VtPointerType1, /* BtDir | 2 */
- VtPointerType2, /* BtDir | 3 */
- VtPointerType3, /* BtDir | 4 */
- VtPointerType4, /* BtDir | 5 */
- VtPointerType5, /* BtDir | 6 */
- VtPointerType6, /* BtDir | 7 */
+ VtDirType+1, /* BtDir | 1 */
+ VtDirType+2, /* BtDir | 2 */
+ VtDirType+3, /* BtDir | 3 */
+ VtDirType+4, /* BtDir | 4 */
+ VtDirType+5, /* BtDir | 5 */
+ VtDirType+6, /* BtDir | 6 */
+ VtDirType+7, /* BtDir | 7 */
};
Block*
@@ -224,13 +224,13 @@ ventiBlock(uchar score[VtScoreSize], uint type)
memmove(b->score, score, VtScoreSize);
b->addr = NilBlock;
- n = vtRead(z, b->score, vtType[type], b->data, h.blockSize);
+ n = vtread(z, b->score, vtType[type], b->data, h.blockSize);
if(n < 0){
- fprint(2, "vtRead returns %d: %R\n", n);
+ fprint(2, "vtread returns %d: %r\n", n);
blockPut(b);
return nil;
}
- vtZeroExtend(vtType[type], b->data, n, h.blockSize);
+ vtzeroextend(vtType[type], b->data, n, h.blockSize);
b->l.type = type;
b->l.state = 0;
b->l.tag = 0;
@@ -255,7 +255,7 @@ dataBlock(uchar score[VtScoreSize], uint type, uint tag)
if(bl == nil)
return nil;
if(!labelUnpack(&l, bl->data, addr%lpb)){
- werrstr("%R");
+ werrstr("%r");
blockPut(bl);
return nil;
}
@@ -363,7 +363,7 @@ initxheader(void)
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize)
return stringnode("error reading header: %r");
if(!headerUnpack(&h, buf))
- return stringnode("error unpacking header: %R");
+ return stringnode("error unpacking header: %r");
t = stringnode("header "
"version=%#ux (%d) "
@@ -403,7 +403,7 @@ initxsuper(void)
return stringnode("reading super: %r");
if(!superUnpack(&super, b->data)){
blockPut(b);
- return stringnode("unpacking super: %R");
+ return stringnode("unpacking super: %r");
}
blockPut(b);
t = stringnode("super "
@@ -440,15 +440,15 @@ initxvacroot(uchar score[VtScoreSize])
uchar buf[VtRootSize];
int n;
- if((n = vtRead(z, score, VtRootType, buf, VtRootSize)) < 0)
- return stringnode("reading root %V: %R", score);
+ if((n = vtread(z, score, VtRootType, buf, VtRootSize)) < 0)
+ return stringnode("reading root %V: %r", score);
- if(!vtRootUnpack(&vac, buf))
- return stringnode("unpack %d-byte root: %R", n);
+ if(vtrootunpack(&vac, buf) < 0)
+ return stringnode("unpack %d-byte root: %r", n);
- h.blockSize = vac.blockSize;
- t = stringnode("vac version=%#ux name=%s type=%s blockSize=%ud score=%V prev=%V",
- vac.version, vac.name, vac.type, vac.blockSize, vac.score, vac.prev);
+ h.blockSize = vac.blocksize;
+ t = stringnode("vac version=%#ux name=%s type=%s blocksize=%lud score=%V prev=%V",
+ VtRootVersion, vac.name, vac.type, vac.blocksize, vac.score, vac.prev);
t->expand = xvacrootexpand;
return t;
}
@@ -603,7 +603,7 @@ ptrgen(void *v, Block *b, int o, Tnode **tp)
e = *ed;
e.depth--;
memmove(e.score, b->data+o*VtScoreSize, VtScoreSize);
- if(memcmp(e.score, vtZeroScore, VtScoreSize) == 0)
+ if(memcmp(e.score, vtzeroscore, VtScoreSize) == 0)
return 0;
*tp = initxsource(e, 0);
return 1;
@@ -614,7 +614,7 @@ etype(int flags, int depth)
{
uint t;
- if(flags&VtEntryDir)
+ if(flags&_VtEntryDir)
t = BtDir;
else
t = BtData;
@@ -635,12 +635,12 @@ initxsource(Entry e, int dowrap)
return stringnode("inactive Entry");
if(e.depth == 0){
- if(e.flags & VtEntryDir)
+ if(e.flags & _VtEntryDir)
tt = initxentryblock(b, copyEntry(e));
else
tt = initxdatablock(b, e.dsize);
}else{
- tt = initxblock(b, smprint("%s+%d pointer", (e.flags & VtEntryDir) ? "BtDir" : "BtData", e.depth),
+ tt = initxblock(b, smprint("%s+%d pointer", (e.flags & _VtEntryDir) ? "BtDir" : "BtData", e.depth),
ptrgen, copyEntry(e));
}
@@ -679,7 +679,7 @@ initxlocalroot(char *name, u32int addr)
localToGlobal(addr, score);
b = dataBlock(score, BtDir, RootTag);
if(b == nil)
- return stringnode("read data block %#ux: %R", addr);
+ return stringnode("read data block %#ux: %r", addr);
return initxblock(b, smprint("'%s' fs root", name), xlocalrootgen, nil);
}
@@ -702,7 +702,7 @@ initxroot(char *name, uchar score[VtScoreSize])
b = dataBlock(score, BtDir, RootTag);
if(b == nil)
- return stringnode("read data block %V: %R", score);
+ return stringnode("read data block %V: %r", score);
return initxblock(b, smprint("'%s' fs root", name), xvacrootgen, nil);
}
Tnode*
@@ -712,7 +712,7 @@ initxdirentry(MetaEntry *me)
Tnode *t;
if(!deUnpack(&dir, me))
- return stringnode("deUnpack: %R");
+ return stringnode("deUnpack: %r");
t = stringnode("dirEntry elem=%s size=%llud data=%#lux/%#lux meta=%#lux/%#lux", dir.elem, dir.size, dir.entry, dir.gen, dir.mentry, dir.mgen);
t->nkid = 1;
@@ -845,16 +845,13 @@ atreeinit(char *arg)
Atree *a;
uchar score[VtScoreSize];
- vtAttach();
-
fmtinstall('V', scoreFmt);
- fmtinstall('R', vtErrFmt);
- z = vtDial(nil, 1);
+ z = vtdial(nil);
if(z == nil)
- fprint(2, "warning: cannot dial venti: %R\n");
- if(!vtConnect(z, 0)){
- fprint(2, "warning: cannot connect to venti: %R\n");
+ fprint(2, "warning: cannot dial venti: %r\n");
+ else if(vtconnect(z) < 0){
+ fprint(2, "warning: cannot connect to venti: %r\n");
z = nil;
}
a = mallocz(sizeof(Atree), 1);
@@ -999,8 +996,8 @@ findnode(Tnode *t, Point p)
void
usage(void)
{
- fprint(2, "usage: vtree /dev/sdC0/fossil\n");
- exits("usage");
+ fprint(2, "usage: fossil/view /dev/sdC0/fossil\n");
+ threadexitsall("usage");
}
Tree t;
@@ -1030,7 +1027,7 @@ enum { IExit, };
Menu menu;
void
-main(int argc, char **argv)
+threadmain(int argc, char **argv)
{
int n;
char *dir;
@@ -1106,7 +1103,7 @@ main(int argc, char **argv)
break;
switch(n){
case IExit:
- exits(nil);
+ threadexitsall(nil);
}
break;
case Right:
diff --git a/src/cmd/fossil/walk.c b/src/cmd/fossil/walk.c
index 802af640..632e3e5e 100644
--- a/src/cmd/fossil/walk.c
+++ b/src/cmd/fossil/walk.c
@@ -11,7 +11,7 @@ etype(Entry *e)
{
uint t;
- if(e->flags&VtEntryDir)
+ if(e->flags&_VtEntryDir)
t = BtDir;
else
t = BtData;