Example #1
0
void
bwatchInit(void)
{
	map.lk = vtLockAlloc();
	wp = privalloc();
	*wp = nil;
}
Example #2
0
File: rpc.c Project: aahud/harvey
VtSession *
vtAlloc(void)
{
	VtSession *z;

	z = vtMemAllocZ(sizeof(VtSession));
	z->lk = vtLockAlloc();
//	z->inHash = vtSha1Alloc();
	z->inLock = vtLockAlloc();
	z->part = packetAlloc();
//	z->outHash = vtSha1Alloc();
	z->outLock = vtLockAlloc();
	z->fd = -1;
	z->uid = vtStrDup("anonymous");
	z->sid = vtStrDup("anonymous");
	return z;
}
Example #3
0
File: 9srv.c Project: aahud/harvey
int
srvInit(void)
{
	sbox.lock = vtLockAlloc();

	cliAddCmd("srv", cmdSrv);

	return 1;
}
Example #4
0
int
lstnInit(void)
{
	lbox.lock = vtLockAlloc();

	cliAddCmd("listen", cmdLstn);

	return 1;
}
Example #5
0
int
usersInit(void)
{
	fmtinstall('U', userFmt);

	ubox.lock = vtLockAlloc();
	uboxInit(usersDefault, sizeof(usersDefault));

	cliAddCmd("users", cmdUsers);
	cliAddCmd("uname", cmdUname);

	return 1;
}
Example #6
0
static File *
fileAlloc(Fs *fs)
{
	File *f;

	f = vtMemAllocZ(sizeof(File));
	f->lk = vtLockAlloc();
	f->ref = 1;
	f->fs = fs;
	f->boff = NilBlock;
	f->mode = fs->mode;
	return f;
}
Example #7
0
File: 9fid.c Project: 99years/plan9
static Fid*
fidAlloc(void)
{
	Fid *fid;

	vtLock(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();
	}
	fbox.inuse++;
	vtUnlock(fbox.lock);

	fid->con = nil;
	fid->fidno = NOFID;
	fid->ref = 0;
	fid->flags = 0;
	fid->open = FidOCreate;
	assert(fid->fsys == nil);
	assert(fid->file == nil);
	fid->qid = (Qid){0, 0, 0};
	assert(fid->uid == nil);
	assert(fid->uname == nil);
	assert(fid->db == nil);
	assert(fid->excl == nil);
	assert(fid->rpc == nil);
	assert(fid->cuname == nil);
	fid->hash = fid->next = fid->prev = nil;

	return fid;
}
Example #8
0
File: fs.c Project: bhanug/harvey
static Snap*
snapInit(Fs *fs)
{
	Snap *s;

	s = vtMemAllocZ(sizeof(Snap));
	s->fs = fs;
	s->tick = periodicAlloc(snapEvent, s, 10*1000);
	s->lk = vtLockAlloc();
	s->snapMinutes = -1;
	s->archMinute = -1;
	s->snapLife = -1;
	s->ignore = 5*2;	/* wait five minutes for clock to stabilize */
	return s;
}
Example #9
0
Periodic *
periodicAlloc(void (*f)(void*), void *a, int msec)
{
	Periodic *p;

	p = vtMemAllocZ(sizeof(Periodic));
	p->lk = vtLockAlloc();
	p->f = f;
	p->a = a;
	p->msec = msec;
	if(p->msec < 10)
		p->msec = 10;

	vtThread(periodicThread, p);
	return p;
}
Example #10
0
Arch *
archInit(Cache *c, Disk *disk, Fs *fs, VtSession *z)
{
	Arch *a;

	a = vtMemAllocZ(sizeof(Arch));

	a->c = c;
	a->z = z;
	a->fs = fs;
	a->blockSize = diskBlockSize(disk);
	a->lk = vtLockAlloc();
	a->starve = vtRendezAlloc(a->lk);

	a->ref = 2;
	vtThread(archThread, a);

	return a;
}
Example #11
0
File: fs.c Project: bhanug/harvey
Fs *
fsOpen(char *file, VtSession *z, int32_t ncache, int mode)
{
	int fd, m;
	uint8_t oscore[VtScoreSize];
	Block *b, *bs;
	Disk *disk;
	Fs *fs;
	Super super;

	switch(mode){
	default:
		vtSetError(EBadMode);
		return nil;
	case OReadOnly:
		m = OREAD;
		break;
	case OReadWrite:
		m = ORDWR;
		break;
	}
	fd = open(file, m);
	if(fd < 0){
		vtSetError("open %s: %r", file);
		return nil;
	}

	bwatchInit();
	disk = diskAlloc(fd);
	if(disk == nil){
		vtSetError("diskAlloc: %R");
		close(fd);
		return nil;
	}

	fs = vtMemAllocZ(sizeof(Fs));
	fs->mode = mode;
	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);
	fs->z = z;

	b = cacheLocal(fs->cache, PartSuper, 0, mode);
	if(b == nil)
		goto Err;
	if(!superUnpack(&super, b->data)){
		blockPut(b);
		vtSetError("bad super block");
		goto Err;
	}
	blockPut(b);

	fs->ehi = super.epochHigh;
	fs->elo = super.epochLow;

//fprint(2, "%s: fs->ehi %d fs->elo %d active=%d\n", argv0, fs->ehi, fs->elo, super.active);

	fs->source = sourceRoot(fs, super.active, mode);
	if(fs->source == nil){
		/*
		 * Perhaps it failed because the block is copy-on-write.
		 * Do the copy and try again.
		 */
		if(mode == OReadOnly || strcmp(vtGetError(), EBadRoot) != 0)
			goto Err;
		b = cacheLocalData(fs->cache, super.active, BtDir, RootTag,
			OReadWrite, 0);
		if(b == nil){
			vtSetError("cacheLocalData: %R");
			goto Err;
		}
		if(b->l.epoch == fs->ehi){
			blockPut(b);
			vtSetError("bad root source block");
			goto Err;
		}
		b = blockCopy(b, RootTag, fs->ehi, fs->elo);
		if(b == nil)
			goto Err;
		localToGlobal(super.active, oscore);
		super.active = b->addr;
		bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite);
		if(bs == nil){
			blockPut(b);
			vtSetError("cacheLocal: %R");
			goto Err;
		}
		superPack(&super, bs->data);
		blockDependency(bs, b, 0, oscore, nil);
		blockPut(b);
		blockDirty(bs);
		blockRemoveLink(bs, globalToLocal(oscore), BtDir, RootTag, 0);
		blockPut(bs);
		fs->source = sourceRoot(fs, super.active, mode);
		if(fs->source == nil){
			vtSetError("sourceRoot: %R");
			goto Err;
		}
	}

//fprint(2, "%s: got fs source\n", argv0);

	vtRLock(fs->elk);
	fs->file = fileRoot(fs->source);
	fs->source->file = fs->file;		/* point back */
	vtRUnlock(fs->elk);
	if(fs->file == nil){
		vtSetError("fileRoot: %R");
		goto Err;
	}

//fprint(2, "%s: got file root\n", argv0);

	if(mode == OReadWrite){
		fs->metaFlush = periodicAlloc(fsMetaFlush, fs, 1000);
		fs->snap = snapInit(fs);
	}
	return fs;

Err:
fprint(2, "%s: fsOpen error\n", argv0);
	fsClose(fs);
	return nil;
}
Example #12
0
void
exclInit(void)
{
	ebox.lock = vtLockAlloc();
}
Example #13
0
File: source.c Project: npe9/harvey
static Source *
sourceAlloc(Fs *fs, Block *b, Source *p, uint32_t offset, int mode,
            int issnapshot)
{
    int epb;
    uint32_t epoch;
    char *pname = nil;
    Source *r;
    Entry e;

    assert(p==nil || sourceIsLocked(p));

    if(p == nil) {
        assert(offset == 0);
        epb = 1;
    } else
        epb = p->dsize / VtEntrySize;

    if(b->l.type != BtDir)
        goto Bad;

    /*
     * a non-active entry is the only thing that
     * can legitimately happen here. all the others
     * get prints.
     */
    if(!entryUnpack(&e, b->data, offset % epb)) {
        pname = sourceName(p);
        consPrint("%s: %s %V: sourceAlloc: entryUnpack failed\n",
                  fs->name, pname, b->score);
        goto Bad;
    }
    if(!(e.flags & VtEntryActive)) {
        pname = sourceName(p);
        if(0) consPrint("%s: %s %V: sourceAlloc: not active\n",
                            fs->name, pname, e.score);
        goto Bad;
    }
    if(e.psize < 256 || e.dsize < 256) {
        pname = sourceName(p);
        consPrint("%s: %s %V: sourceAlloc: psize %ud or dsize %ud < 256\n",
                  fs->name, pname, e.score, e.psize, e.dsize);
        goto Bad;
    }

    if(e.depth < sizeToDepth(e.size, e.psize, e.dsize)) {
        pname = sourceName(p);
        consPrint("%s: %s %V: sourceAlloc: depth %ud size %llud "
                  "psize %ud dsize %ud\n", fs->name, pname,
                  e.score, e.depth, e.size, e.psize, e.dsize);
        goto Bad;
    }

    if((e.flags & VtEntryLocal) && e.tag == 0) {
        pname = sourceName(p);
        consPrint("%s: %s %V: sourceAlloc: flags %#ux tag %#ux\n",
                  fs->name, pname, e.score, e.flags, e.tag);
        goto Bad;
    }

    if(e.dsize > fs->blockSize || e.psize > fs->blockSize) {
        pname = sourceName(p);
        consPrint("%s: %s %V: sourceAlloc: psize %ud or dsize %ud "
                  "> blocksize %ud\n", fs->name, pname, e.score,
                  e.psize, e.dsize, fs->blockSize);
        goto Bad;
    }

    epoch = b->l.epoch;
    if(mode == OReadWrite) {
        if(e.snap != 0) {
            vtSetError(ESnapRO);
            return nil;
        }
    } else if(e.snap != 0) {
        if(e.snap < fs->elo) {
            vtSetError(ESnapOld);
            return nil;
        }
        if(e.snap >= fs->ehi)
            goto Bad;
        epoch = e.snap;
    }

    r = vtMemAllocZ(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->ref = 1;
    r->parent = p;
    if(p) {
        vtLock(p->lk);
        assert(mode == OReadOnly || p->mode == OReadWrite);
        p->ref++;
        vtUnlock(p->lk);
    }
    r->epoch = epoch;
//	consPrint("sourceAlloc: have %V be.%d fse.%d %s\n", b->score,
//		b->l.epoch, r->fs->ehi, mode == OReadWrite? "rw": "ro");
    memmove(r->score, b->score, VtScoreSize);
    r->scoreEpoch = b->l.epoch;
    r->offset = offset;
    r->epb = epb;
    r->tag = b->l.tag;

//	consPrint("%s: sourceAlloc: %p -> %V %d\n", r, r->score, r->offset);

    return r;
Bad:
    free(pname);
    vtSetError(EBadEntry);
    return nil;
}
Example #14
0
File: 9fid.c Project: 99years/plan9
void
fidInit(void)
{
	fbox.lock = vtLockAlloc();
}