util.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
  5. **
  6. ** This copyrighted material is made available to anyone wishing to use,
  7. ** modify, copy, or redistribute it subject to the terms and conditions
  8. ** of the GNU General Public License v.2.
  9. **
  10. *******************************************************************************
  11. ******************************************************************************/
  12. #include "dlm_internal.h"
  13. #include "rcom.h"
  14. #include "util.h"
  15. #define DLM_ERRNO_EDEADLK 35
  16. #define DLM_ERRNO_EBADR 53
  17. #define DLM_ERRNO_EBADSLT 57
  18. #define DLM_ERRNO_EPROTO 71
  19. #define DLM_ERRNO_EOPNOTSUPP 95
  20. #define DLM_ERRNO_ETIMEDOUT 110
  21. #define DLM_ERRNO_EINPROGRESS 115
  22. static void header_out(struct dlm_header *hd)
  23. {
  24. hd->h_version = cpu_to_le32(hd->h_version);
  25. hd->h_lockspace = cpu_to_le32(hd->h_lockspace);
  26. hd->h_nodeid = cpu_to_le32(hd->h_nodeid);
  27. hd->h_length = cpu_to_le16(hd->h_length);
  28. }
  29. static void header_in(struct dlm_header *hd)
  30. {
  31. hd->h_version = le32_to_cpu(hd->h_version);
  32. hd->h_lockspace = le32_to_cpu(hd->h_lockspace);
  33. hd->h_nodeid = le32_to_cpu(hd->h_nodeid);
  34. hd->h_length = le16_to_cpu(hd->h_length);
  35. }
  36. /* higher errno values are inconsistent across architectures, so select
  37. one set of values for on the wire */
  38. static int to_dlm_errno(int err)
  39. {
  40. switch (err) {
  41. case -EDEADLK:
  42. return -DLM_ERRNO_EDEADLK;
  43. case -EBADR:
  44. return -DLM_ERRNO_EBADR;
  45. case -EBADSLT:
  46. return -DLM_ERRNO_EBADSLT;
  47. case -EPROTO:
  48. return -DLM_ERRNO_EPROTO;
  49. case -EOPNOTSUPP:
  50. return -DLM_ERRNO_EOPNOTSUPP;
  51. case -ETIMEDOUT:
  52. return -DLM_ERRNO_ETIMEDOUT;
  53. case -EINPROGRESS:
  54. return -DLM_ERRNO_EINPROGRESS;
  55. }
  56. return err;
  57. }
  58. static int from_dlm_errno(int err)
  59. {
  60. switch (err) {
  61. case -DLM_ERRNO_EDEADLK:
  62. return -EDEADLK;
  63. case -DLM_ERRNO_EBADR:
  64. return -EBADR;
  65. case -DLM_ERRNO_EBADSLT:
  66. return -EBADSLT;
  67. case -DLM_ERRNO_EPROTO:
  68. return -EPROTO;
  69. case -DLM_ERRNO_EOPNOTSUPP:
  70. return -EOPNOTSUPP;
  71. case -DLM_ERRNO_ETIMEDOUT:
  72. return -ETIMEDOUT;
  73. case -DLM_ERRNO_EINPROGRESS:
  74. return -EINPROGRESS;
  75. }
  76. return err;
  77. }
  78. void dlm_message_out(struct dlm_message *ms)
  79. {
  80. header_out(&ms->m_header);
  81. ms->m_type = cpu_to_le32(ms->m_type);
  82. ms->m_nodeid = cpu_to_le32(ms->m_nodeid);
  83. ms->m_pid = cpu_to_le32(ms->m_pid);
  84. ms->m_lkid = cpu_to_le32(ms->m_lkid);
  85. ms->m_remid = cpu_to_le32(ms->m_remid);
  86. ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid);
  87. ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid);
  88. ms->m_exflags = cpu_to_le32(ms->m_exflags);
  89. ms->m_sbflags = cpu_to_le32(ms->m_sbflags);
  90. ms->m_flags = cpu_to_le32(ms->m_flags);
  91. ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq);
  92. ms->m_hash = cpu_to_le32(ms->m_hash);
  93. ms->m_status = cpu_to_le32(ms->m_status);
  94. ms->m_grmode = cpu_to_le32(ms->m_grmode);
  95. ms->m_rqmode = cpu_to_le32(ms->m_rqmode);
  96. ms->m_bastmode = cpu_to_le32(ms->m_bastmode);
  97. ms->m_asts = cpu_to_le32(ms->m_asts);
  98. ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result));
  99. }
  100. void dlm_message_in(struct dlm_message *ms)
  101. {
  102. header_in(&ms->m_header);
  103. ms->m_type = le32_to_cpu(ms->m_type);
  104. ms->m_nodeid = le32_to_cpu(ms->m_nodeid);
  105. ms->m_pid = le32_to_cpu(ms->m_pid);
  106. ms->m_lkid = le32_to_cpu(ms->m_lkid);
  107. ms->m_remid = le32_to_cpu(ms->m_remid);
  108. ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid);
  109. ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid);
  110. ms->m_exflags = le32_to_cpu(ms->m_exflags);
  111. ms->m_sbflags = le32_to_cpu(ms->m_sbflags);
  112. ms->m_flags = le32_to_cpu(ms->m_flags);
  113. ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq);
  114. ms->m_hash = le32_to_cpu(ms->m_hash);
  115. ms->m_status = le32_to_cpu(ms->m_status);
  116. ms->m_grmode = le32_to_cpu(ms->m_grmode);
  117. ms->m_rqmode = le32_to_cpu(ms->m_rqmode);
  118. ms->m_bastmode = le32_to_cpu(ms->m_bastmode);
  119. ms->m_asts = le32_to_cpu(ms->m_asts);
  120. ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result));
  121. }
  122. void dlm_rcom_out(struct dlm_rcom *rc)
  123. {
  124. header_out(&rc->rc_header);
  125. rc->rc_type = cpu_to_le32(rc->rc_type);
  126. rc->rc_result = cpu_to_le32(rc->rc_result);
  127. rc->rc_id = cpu_to_le64(rc->rc_id);
  128. rc->rc_seq = cpu_to_le64(rc->rc_seq);
  129. rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply);
  130. }
  131. void dlm_rcom_in(struct dlm_rcom *rc)
  132. {
  133. header_in(&rc->rc_header);
  134. rc->rc_type = le32_to_cpu(rc->rc_type);
  135. rc->rc_result = le32_to_cpu(rc->rc_result);
  136. rc->rc_id = le64_to_cpu(rc->rc_id);
  137. rc->rc_seq = le64_to_cpu(rc->rc_seq);
  138. rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply);
  139. }