dat.h 3.9 KB

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