Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. crs.h
  5. Abstract:
  6. Consistency replica set data structures and API
  7. Author:
  8. Ahmed Mohamed (ahmedm) 1-Feb-2000
  9. Revision History:
  10. --*/
  11. #ifndef _CRS_DEF
  12. #define _CRS_DEF
  13. #include <windows.h>
  14. #include <assert.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #define CRS_VERSION 1
  18. #define CRS_TAG ( (CRS_VERSION << 24) | ('crs'))
  19. // sizes must be power of 2
  20. #define CRS_RECORD_SZ 64
  21. #define CRS_SECTOR_SZ 512
  22. #define CRS_RECORDS_PER_SECTOR (CRS_SECTOR_SZ / CRS_RECORD_SZ)
  23. #define CRS_SECTOR_MASK (CRS_RECORDS_PER_SECTOR - 1)
  24. #define CRS_MAX_GROUP_SZ 16
  25. #define CRS_QUORUM(sz, total) ((sz == total) || (sz > total/2) || ((DWORD)sz > CrsForcedQuorumSize)? 1: 0)
  26. #define CRS_PREPARE 0x1
  27. #define CRS_COMMIT 0x2
  28. #define CRS_ABORT 0x4
  29. #define CRS_EPOCH 0x8
  30. #define CRS_DUBIOUS 0x10
  31. typedef ULONGLONG crs_id_t[2];
  32. typedef ULONGLONG crs_epoch_t;
  33. typedef ULONGLONG crs_seq_t;
  34. typedef struct {
  35. crs_epoch_t epoch;
  36. crs_seq_t seq;
  37. UINT state;
  38. UINT tag;
  39. }CrsHdr_t;
  40. typedef struct {
  41. CrsHdr_t hdr;
  42. char data[CRS_RECORD_SZ - sizeof(CrsHdr_t)];
  43. }CrsRecord_t;
  44. typedef NTSTATUS (WINAPI *crs_callback_t)(PVOID hd, int nid,
  45. CrsRecord_t *singlerec,
  46. int action, int mid);
  47. #define CRS_STATE_INIT 0
  48. #define CRS_STATE_RECOVERY 1
  49. #define CRS_STATE_READ 2
  50. #define CRS_STATE_WRITE 3
  51. typedef struct {
  52. CRITICAL_SECTION lock;
  53. // log file handle
  54. HANDLE fh;
  55. crs_epoch_t epoch; // current epoch
  56. crs_seq_t seq; // current sequence
  57. CrsRecord_t *buf; // current sector
  58. int last_record; // last record in this sector
  59. int max_records; // max number of records in update file
  60. USHORT refcnt;
  61. USHORT leader_id;
  62. USHORT lid;
  63. USHORT state; // write, read, recovery, init
  64. BOOLEAN pending;
  65. // client call back routine
  66. crs_callback_t callback;
  67. PVOID callback_arg;
  68. }CrsInfo_t;
  69. typedef struct _CrsRecoveryBlk_t {
  70. CrsInfo_t *info, *minfo;
  71. int nid, mid;
  72. }CrsRecoveryBlk_t;
  73. #if defined(QFS_DBG)
  74. extern void WINAPI debug_log(char *, ...);
  75. #define CrsLog(_x_) debug_log _x_
  76. #else
  77. #define CrsLog(_x_)
  78. #endif
  79. #define CRS_ACTION_REPLAY 0x0 // apply record on specified node
  80. #define CRS_ACTION_UNDO 0x1 // undo update record
  81. #define CRS_ACTION_COPY 0x2 // copy one replica to other
  82. #define CRS_ACTION_QUERY 0x3 // ask about outcome of specified record
  83. #define CRS_ACTION_DONE 0x4 // signal send of recovery
  84. extern DWORD CrsForcedQuorumSize;
  85. void
  86. WINAPI
  87. CrsSetForcedQuorumSize(DWORD size);
  88. DWORD
  89. WINAPI
  90. CrsOpen(crs_callback_t callback, PVOID callback_arg, USHORT lid,
  91. WCHAR *log_name, int max_logsectors, HANDLE *hdl);
  92. void
  93. WINAPI
  94. CrsClose(PVOID hd);
  95. void
  96. WINAPI
  97. CrsFlush(PVOID hd);
  98. DWORD
  99. WINAPI
  100. CrsStart(PVOID hd[], ULONG aset, int cluster_sz,
  101. ULONG *wset, ULONG *rset, ULONG *fset);
  102. PVOID
  103. WINAPI
  104. CrsPrepareRecord(PVOID hd, PVOID lrec, crs_id_t id);
  105. int
  106. WINAPI
  107. CrsCommitOrAbort(PVOID hd, PVOID lrec, int commit);
  108. int
  109. WINAPI
  110. CrsCanWrite(PVOID hd);
  111. #endif