static int hicacheflush(HConnect *c) { Hio *hout; int r; r = hsettext(c); if(r < 0) return r; hout = &c->hout; flushicache(); hprint(hout, "flushed icache\n"); hflush(hout); return 0; }
int writeqlump(Lump *u, Packet *p, int creator, uint ms) { ZBlock *flat; Packet *old; IAddr ia; int ok; if(lookupscore(u->score, u->type, &ia) == 0){ if(verifywrites == 0){ /* assume the data is here! */ packetfree(p); ms = msec() - ms; addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms); return 0; } /* * if the read fails, * assume it was corrupted data and store the block again */ old = readilump(u, &ia, u->score); if(old != nil){ ok = 0; if(packetcmp(p, old) != 0){ uchar nscore[VtScoreSize]; packetsha1(old, nscore); if(scorecmp(u->score, nscore) != 0) seterr(EStrange, "readilump returned bad data %V not %V", nscore, u->score); else seterr(EStrange, "score collision %V", u->score); ok = -1; } packetfree(p); packetfree(old); ms = msec() - ms; addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms); return ok; } logerr(EAdmin, "writelump: read %V failed, rewriting: %r\n", u->score); } flat = packet2zblock(p, packetsize(p)); ok = storeclump(mainindex, flat, u->score, u->type, creator, &ia); freezblock(flat); if(ok == 0) insertlump(u, p); else packetfree(p); if(syncwrites){ flushdcache(); flushicache(); flushdcache(); } ms = msec() - ms; addstat2(StatRpcWriteNew, 1, StatRpcWriteNewTime, ms); return ok; }
static void ventiserver(void *v) { Packet *p; VtReq *r; char err[ERRMAX]; uint ms; int cached, ok; USED(v); threadsetname("ventiserver"); trace(TraceWork, "start"); while((r = vtgetreq(ventisrv)) != nil){ trace(TraceWork, "finish"); trace(TraceWork, "start request %F", &r->tx); trace(TraceRpc, "<- %F", &r->tx); r->rx.msgtype = r->tx.msgtype+1; addstat(StatRpcTotal, 1); if(0) print("req (arenas[0]=%p sects[0]=%p) %F\n", mainindex->arenas[0], mainindex->sects[0], &r->tx); switch(r->tx.msgtype){ default: vtrerror(r, "unknown request"); break; case VtTread: ms = msec(); r->rx.data = readlump(r->tx.score, r->tx.blocktype, r->tx.count, &cached); ms = msec() - ms; addstat2(StatRpcRead, 1, StatRpcReadTime, ms); if(r->rx.data == nil){ addstat(StatRpcReadFail, 1); rerrstr(err, sizeof err); vtrerror(r, err); }else{ addstat(StatRpcReadBytes, packetsize(r->rx.data)); addstat(StatRpcReadOk, 1); if(cached) addstat2(StatRpcReadCached, 1, StatRpcReadCachedTime, ms); else addstat2(StatRpcReadUncached, 1, StatRpcReadUncachedTime, ms); } break; case VtTwrite: if(readonly){ vtrerror(r, "read only"); break; } p = r->tx.data; r->tx.data = nil; addstat(StatRpcWriteBytes, packetsize(p)); ms = msec(); ok = writelump(p, r->rx.score, r->tx.blocktype, 0, ms); ms = msec() - ms; addstat2(StatRpcWrite, 1, StatRpcWriteTime, ms); if(ok < 0){ addstat(StatRpcWriteFail, 1); rerrstr(err, sizeof err); vtrerror(r, err); } break; case VtTsync: flushqueue(); flushdcache(); break; } trace(TraceRpc, "-> %F", &r->rx); vtrespond(r); trace(TraceWork, "start"); } flushdcache(); flushicache(); threadexitsall(0); }