8 int writestodevnull = 0;
11 static Packet *readilump(Lump *u, IAddr *ia, u8int *score);
14 * Some of this logic is duplicated in hdisk.c
17 readlump(u8int *score, int type, u32int size, int *cached)
24 trace(TraceLump, "readlump enter");
30 if(scorecmp(score, zeroscore) == 0)
32 u = lookuplump(score, type);
34 trace(TraceLump, "readlump lookuplump hit");
37 n = packetsize(u->data);
39 seterr(EOk, "read too small: asked for %d need at least %d", size, n);
44 p = packetdup(u->data, 0, n);
52 if(lookupscore(score, type, &ia) < 0){
53 /* ZZZ place to check for someone trying to guess scores */
54 seterr(EOk, "no block with score %V/%d exists", score, type);
60 seterr(EOk, "read too small 1: asked for %d need at least %d", size, ia.size);
66 trace(TraceLump, "readlump readilump");
67 p = readilump(u, &ia, score);
70 trace(TraceLump, "readlump exit");
75 * save away a lump, and return it's score.
76 * doesn't store duplicates, but checks that the data is really the same.
79 writelump(Packet *p, u8int *score, int type, u32int creator, uint ms)
91 if(packetsize(p) == 0 || writestodevnull==1){
96 u = lookuplump(score, type);
99 if(packetcmp(p, u->data) != 0){
100 uchar nscore[VtScoreSize];
102 packetsha1(u->data, nscore);
103 if(scorecmp(u->score, score) != 0)
104 seterr(EStrange, "lookuplump returned bad score %V not %V", u->score, score);
105 else if(scorecmp(u->score, nscore) != 0)
106 seterr(EStrange, "lookuplump returned bad data %V not %V", nscore, u->score);
108 seterr(EStrange, "score collision %V", score);
116 if(writestodevnull==2){
122 return queuewrite(u, p, creator, ms);
124 ok = writeqlump(u, p, creator, ms);
131 writeqlump(Lump *u, Packet *p, int creator, uint ms)
138 if(lookupscore(u->score, u->type, &ia) == 0){
139 if(verifywrites == 0){
140 /* assume the data is here! */
143 addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms);
149 * assume it was corrupted data and store the block again
151 old = readilump(u, &ia, u->score);
154 if(packetcmp(p, old) != 0){
155 uchar nscore[VtScoreSize];
157 packetsha1(old, nscore);
158 if(scorecmp(u->score, nscore) != 0)
159 seterr(EStrange, "readilump returned bad data %V not %V", nscore, u->score);
161 seterr(EStrange, "score collision %V", u->score);
168 addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms);
171 logerr(EAdmin, "writelump: read %V failed, rewriting: %r\n", u->score);
174 flat = packet2zblock(p, packetsize(p));
175 ok = storeclump(mainindex, flat, u->score, u->type, creator, &ia);
189 addstat2(StatRpcWriteNew, 1, StatRpcWriteNewTime, ms);
194 readilump(Lump *u, IAddr *ia, u8int *score)
201 u8int sc[VtScoreSize];
203 trace(TraceLump, "readilump enter");
204 arena = amapitoa(mainindex, ia->addr, &aa);
206 trace(TraceLump, "readilump amapitoa failed");
210 trace(TraceLump, "readilump loadclump");
211 zb = loadclump(arena, aa, ia->blocks, &cl, sc, paranoid);
213 trace(TraceLump, "readilump loadclump failed");
217 if(ia->size != cl.info.uncsize){
218 seterr(EInconsist, "index and clump size mismatch");
222 if(ia->type != cl.info.type){
223 seterr(EInconsist, "index and clump type mismatch");
227 if(scorecmp(score, sc) != 0){
228 seterr(ECrash, "score mismatch");
233 trace(TraceLump, "readilump success");
234 p = zblock2packet(zb, cl.info.uncsize);
236 pp = packetdup(p, 0, packetsize(p));
237 trace(TraceLump, "readilump insertlump");
239 trace(TraceLump, "readilump exit");