Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. #ifdef MRMPI_SDC_AsyncHash
  2. /**
  3. * Verifies the integrity of messages between replicas using a delayed hash.
  4. * May be called repeatedly on the same request.
  5. * @param req The request type struct to veryify (IN).
  6. * @return MPI_SUCCESS for success (including inconclusive situations
  7. * where the procedure should be called again), or MPI_ERR_OTHER
  8. * for error.
  9. */
  10. int MRMPI_Reqs_verifyintegrity_AsyncHash(MRMPI_ReqTypePtr req) {
  11. if (NULL == req) {
  12. MRMPI_LOG_ERROR(The req parameter is null)
  13. return MPI_ERR_OTHER;
  14. }
  15.  
  16. int hashlen = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
  17. int error, flag;
  18.  
  19. if (!req->myhash && req->checksdc) {
  20. if (NULL == (req->myhash = malloc(hashlen))) {
  21. MRMPI_LOG_ERROR(Unable to allocate the hash storage)
  22. return MPI_ERR_OTHER;
  23. }
  24.  
  25. gcry_md_hash_buffer(GCRY_MD_SHA1, req->myhash, req->userbuffer,
  26. req->bufsize);
  27. }
  28.  
  29. if (MPI_SUCCESS != (error = PMPI_Test(&(req->reqsarray[1]), &flag,
  30. MPI_STATUS_IGNORE))) {
  31. MRMPI_LOG_MPI_ERROR(error,Unable to test async hash request)
  32. return error;
  33. }
  34.  
  35. if (!flag) {
  36. req->incomplete = 1;
  37. return MPI_SUCCESS;
  38. }
  39.  
  40. if (req->checksdc) {
  41. if (memcmp(req->hash, req->myhash, hashlen)) {
  42. MRMPI_LOG_ERROR(Hashes do not match)
  43. return MPI_ERR_OTHER;
  44. }
  45. }
  46.  
  47. MRMPI_Reqs_free(&req);
  48. return MPI_SUCCESS;
  49. }
  50.  
  51. int MRMPI_Reqs_check_AsyncHash() {
  52. int error, i;
  53.  
  54. for (i = 0; i < mrmpi_reqs.count; i++) {
  55. if (mrmpi_reqs.array[i].inuse && mrmpi_reqs.array[i].incomplete) {
  56. /* Check for consistency, possibly initiating correction. */
  57. if (MPI_SUCCESS != (error = MRMPI_Reqs_verifyintegrity_AsyncHash(&mrmpi_reqs.array[i]))) {
  58. MRMPI_LOG_MPI_ERROR(error,Unable to verify integrity)
  59. return error;
  60. }
  61. }
  62. }
  63.  
  64. return MPI_SUCCESS;
  65. }
  66.  
  67. int MRMPI_Reqs_finalize_AsyncHash() {
  68. int error, i;
  69.  
  70. for (i = 0; i < mrmpi_reqs.count; i++) {
  71. if (mrmpi_reqs.array[i].inuse && mrmpi_reqs.array[i].incomplete) {
  72. /* Wait for all requests. */
  73. if (MPI_SUCCESS != (error = PMPI_Waitall(MRMPI_NUM_REQS, mrmpi_reqs.array[i].reqsarray,
  74. MPI_STATUSES_IGNORE))) {
  75. MRMPI_LOG_MPI_ERROR(error,Unable to wait for all requests to complete)
  76. return error;
  77. }
  78. /* Check for consistency, possibly initiating correction. */
  79. if (MPI_SUCCESS != (error = MRMPI_Reqs_verifyintegrity_AsyncHash(&mrmpi_reqs.array[i]))) {
  80. MRMPI_LOG_MPI_ERROR(error,Unable to verify integrity)
  81. return error;
  82. }
  83. }
  84. }
  85.  
  86. return MPI_SUCCESS;
  87. }
  88. #endif
  89.  
  90. #ifdef MRMPI_SDC_Async
  91. /**
  92. * Verifies the integrity of messages between replicas. May be called
  93. * repeatedly on the same request.
  94. * @param req The request type struct to veryify (IN).
  95. * @return MPI_SUCCESS for success (including inconclusive situations
  96. * where the procedure should be called again), or MPI_ERR_OTHER
  97. * for error.
  98. */
  99. int MRMPI_Reqs_verifyintegrity_Async (MRMPI_ReqTypePtr req) {
  100. if (NULL == req) {
  101. MRMPI_LOG_ERROR(The req parameter is null)
  102. return MPI_ERR_OTHER;
  103. }
  104. if (0 == (*req).bufsize || NULL == (*req).buffers) {
  105. /* Return success if the buffer size is 0 which implies no message data. */
  106. /* Return success if there are no buffers to verify. */
  107.  
  108. #ifdef MRMPI_SDC_Async_CopySend
  109. /* Clean up a send request only if all underlying sends are complete. */
  110. if (req->sendbuffer) {
  111. int error, flag;
  112.  
  113. if (MPI_SUCCESS != (error = PMPI_Testall(mrmpi.idegree, req->reqsarray,
  114. &flag, MPI_STATUSES_IGNORE))) {
  115. MRMPI_LOG_MPI_ERROR(error,Unable to testall async send)
  116. return error;
  117. }
  118.  
  119. if (!flag) {
  120. req->incomplete = 1;
  121. return MPI_SUCCESS;
  122. }
  123. }
  124. #endif
  125. MRMPI_Reqs_free(&req);
  126. return MPI_SUCCESS;
  127. }
  128.  
  129. int hashlen = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
  130. int total = 0, matching = 0, i;
  131.  
  132. /* Check status of all requests. If the user's buffer has not yet been filled
  133. * and some request has completed, fill the user's buffer from that of the
  134. * first such request encountered. Count how many requests have a buffer
  135. * matching this first request.
  136. */
  137. for (i = 0; i < mrmpi.idegree; i++) {
  138. if (!req->hashes[i]) {
  139. int error, flag;
  140.  
  141. if(MPI_SUCCESS != (error = PMPI_Test(&(req->reqsarray[i]), &flag,
  142. MPI_STATUS_IGNORE))) {
  143. MRMPI_LOG_MPI_ERROR(error,Unable to test async request)
  144. return error;
  145. }
  146.  
  147. if (flag) {
  148. if (NULL == (req->hashes[i] = malloc(hashlen))) {
  149. MRMPI_LOG_ERROR(Unable to allocate the hash storage)
  150. return MPI_ERR_OTHER;
  151. }
  152. gcry_md_hash_buffer(GCRY_MD_SHA1, req->hashes[i], req->buffers[i],
  153. req->bufsize);
  154. }
  155. }
  156.  
  157. if (req->hashes[i]) {
  158. total++;
  159. if (req->firstindex < 0) {
  160. memcpy(req->userbuffer, req->buffers[i], req->bufsize);
  161. req->firstindex = i;
  162. matching = 1;
  163. } else if (0 == memcmp(req->hashes[i], req->hashes[req->firstindex],
  164. hashlen)) {
  165. matching++;
  166. }
  167.  
  168. /* Buffer contents are no longer needed. */
  169. if (req->buffers[i]) {
  170. free(req->buffers[i]);
  171. req->buffers[i] = NULL;
  172. }
  173. }
  174. }
  175.  
  176. /* If all messages have been received, discard the request entry.
  177. * The buffers cannot be freed before this time.
  178. */
  179. if (total == mrmpi.idegree) {
  180. MRMPI_Reqs_free(&req);
  181.  
  182. /* If a majority of messages match the first, success.
  183. * Otherwise, initiate correction.
  184. */
  185. if (matching > mrmpi.idegree / 2) {
  186. return MPI_SUCCESS;
  187. }
  188. return MPI_ERR_OTHER;
  189. }
  190.  
  191. /* Insufficient information, mark request as incomplete. */
  192. req->incomplete = 1;
  193. return MPI_SUCCESS;
  194. }
  195.  
  196. int MRMPI_Reqs_check_Async() {
  197. int error, i;
  198.  
  199. for (i = 0; i < mrmpi_reqs.count; i++) {
  200. if (mrmpi_reqs.array[i].inuse && mrmpi_reqs.array[i].incomplete) {
  201. /* Check for consistency, possibly initiating correction. */
  202. if (MPI_SUCCESS != (error = MRMPI_Reqs_verifyintegrity_Async(&mrmpi_reqs.array[i]))) {
  203. MRMPI_LOG_MPI_ERROR(error,Unable to verify integrity)
  204. return error;
  205. }
  206. }
  207. }
  208.  
  209. return MPI_SUCCESS;
  210. }
  211.  
  212. int MRMPI_Reqs_finalize_Async() {
  213. int error, i;
  214.  
  215. for (i = 0; i < mrmpi_reqs.count; i++) {
  216. if (mrmpi_reqs.array[i].inuse && mrmpi_reqs.array[i].incomplete) {
  217. /* Wait for all requests. */
  218. if (MPI_SUCCESS != (error = PMPI_Waitall(MRMPI_NUM_REQS, mrmpi_reqs.array[i].reqsarray,
  219. MPI_STATUSES_IGNORE))) {
  220. MRMPI_LOG_MPI_ERROR(error,Unable to wait for all requests to complete)
  221. return error;
  222. }
  223. /* Check for consistency, possibly initiating correction. */
  224. if (MPI_SUCCESS != (error = MRMPI_Reqs_verifyintegrity_Async(&mrmpi_reqs.array[i]))) {
  225. MRMPI_LOG_MPI_ERROR(error,Unable to verify integrity)
  226. return error;
  227. }
  228. }
  229. }
  230.  
  231. return MPI_SUCCESS;
  232. }
  233. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement