dat.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. typedef struct Source Source;
  2. typedef struct VacFile VacFile;
  3. typedef struct MetaBlock MetaBlock;
  4. typedef struct MetaEntry MetaEntry;
  5. typedef struct Lump Lump;
  6. typedef struct Cache Cache;
  7. #pragma incomplete Cache
  8. enum {
  9. NilBlock = (~0UL),
  10. MaxBlock = (1UL<<31),
  11. };
  12. struct VacFS {
  13. int ref;
  14. /* need a read write lock? */
  15. uchar score[VtScoreSize];
  16. VacFile *root;
  17. VtSession *z;
  18. int readOnly;
  19. int bsize; /* maximum block size */
  20. uvlong qid; /* next qid */
  21. Cache *cache;
  22. };
  23. struct Source {
  24. VtLock *lk;
  25. Cache *cache; /* immutable */
  26. int readOnly; /* immutable */
  27. VacFile *vf; /* pointer back */
  28. Lump *lump; /* lump containing venti dir entry */
  29. ulong block; /* block number within parent: immutable */
  30. int entry; /* which entry in the block: immutable */
  31. /* most of a VtEntry, except the score */
  32. ulong gen; /* generation: immutable */
  33. int dir; /* dir flags: immutable */
  34. int depth; /* number of levels of pointer blocks */
  35. int psize; /* pointer block size: immutable */
  36. int dsize; /* data block size: immutable */
  37. uvlong size; /* size in bytes of file */
  38. int epb; /* dir entries per block = dize/VtEntrySize: immutable */
  39. };
  40. struct MetaEntry {
  41. uchar *p;
  42. ushort size;
  43. };
  44. struct MetaBlock {
  45. int maxsize; /* size of block */
  46. int size; /* size used */
  47. int free; /* free space within used size */
  48. int maxindex; /* entries allocated for table */
  49. int nindex; /* amount of table used */
  50. int unbotch;
  51. uchar *buf;
  52. };
  53. /*
  54. * contains a one block buffer
  55. * to avoid problems of the block changing underfoot
  56. * and to enable an interface that supports unget.
  57. */
  58. struct VacDirEnum {
  59. VacFile *file;
  60. ulong block; /* current block */
  61. MetaBlock mb; /* parsed version of block */
  62. int index; /* index in block */
  63. };
  64. /* Lump states */
  65. enum {
  66. LumpFree,
  67. LumpVenti, /* on venti server: score > 2^32: just a cached copy */
  68. LumpActive, /* active */
  69. LumpActiveRO, /* active: read only block */
  70. LumpActiveA, /* active: achrived */
  71. LumpSnap, /* snapshot: */
  72. LumpSnapRO, /* snapshot: read only */
  73. LumpSnapA, /* snapshot: achived */
  74. LumpZombie, /* block with no pointer to it: waiting to be freed */
  75. LumpMax
  76. };
  77. /*
  78. * Each lump has a state and generation
  79. * The following invariants are maintained
  80. * Each lump has no more than than one parent per generation
  81. * For Active*, no child has a parent of a greater generation
  82. * For Snap*, there is a snap parent of given generation and there are
  83. * no parents of greater gen - implies no children of a greater gen
  84. * For *RO, the lump is fixed - no change can be made - all pointers
  85. * are valid venti addresses
  86. * For *A, the lump is on the venti server
  87. * There are no pointers to Zombie lumps
  88. *
  89. * Transitions
  90. * Archiver at generation g
  91. * Mutator at generation h
  92. *
  93. * Want to modify a lump
  94. * Venti: create new Active(h)
  95. * Active(x): x == h: do nothing
  96. * Acitve(x): x < h: change to Snap(h-1) + add Active(h)
  97. * ActiveRO(x): change to SnapRO(h-1) + add Active(h)
  98. * ActiveA(x): add Active(h)
  99. * Snap*(x): should not occur
  100. * Zombie(x): should not occur
  101. * Want to archive
  102. * Active(x): x != g: should never happen
  103. * Active(x): x == g fix children and free them: move to ActoveRO(g);
  104. * ActiveRO(x): x != g: should never happen
  105. * ActiveRO(x): x == g: wait until it hits ActiveA or SnapA
  106. * ActiveA(x): done
  107. * Active(x): x < g: should never happen
  108. * Snap(x): x >= g: fix children, freeing all SnapA(y) x == y;
  109. * SnapRO(x): wait until it hits SnapA
  110. *
  111. */
  112. struct Lump {
  113. int ref;
  114. Cache *c;
  115. VtLock *lk;
  116. int state;
  117. ulong gen;
  118. uchar *data;
  119. uchar score[VtScoreSize]; /* score of packet */
  120. uchar vscore[VtScoreSize]; /* venti score - when archived */
  121. u8int type; /* type of packet */
  122. int dir; /* part of a directory - extension of type */
  123. u16int asize; /* allocated size of block */
  124. Lump *next; /* doubly linked hash chains */
  125. Lump *prev;
  126. u32int heap; /* index in heap table */
  127. u32int used; /* last reference times */
  128. u32int used2;
  129. u32int addr; /* mutable block address */
  130. };