util.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) 2005 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. static void header_out(struct dlm_header *hd)
  16. {
  17. hd->h_version = cpu_to_le32(hd->h_version);
  18. hd->h_lockspace = cpu_to_le32(hd->h_lockspace);
  19. hd->h_nodeid = cpu_to_le32(hd->h_nodeid);
  20. hd->h_length = cpu_to_le16(hd->h_length);
  21. }
  22. static void header_in(struct dlm_header *hd)
  23. {
  24. hd->h_version = le32_to_cpu(hd->h_version);
  25. hd->h_lockspace = le32_to_cpu(hd->h_lockspace);
  26. hd->h_nodeid = le32_to_cpu(hd->h_nodeid);
  27. hd->h_length = le16_to_cpu(hd->h_length);
  28. }
  29. void dlm_message_out(struct dlm_message *ms)
  30. {
  31. struct dlm_header *hd = (struct dlm_header *) ms;
  32. header_out(hd);
  33. ms->m_type = cpu_to_le32(ms->m_type);
  34. ms->m_nodeid = cpu_to_le32(ms->m_nodeid);
  35. ms->m_pid = cpu_to_le32(ms->m_pid);
  36. ms->m_lkid = cpu_to_le32(ms->m_lkid);
  37. ms->m_remid = cpu_to_le32(ms->m_remid);
  38. ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid);
  39. ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid);
  40. ms->m_exflags = cpu_to_le32(ms->m_exflags);
  41. ms->m_sbflags = cpu_to_le32(ms->m_sbflags);
  42. ms->m_flags = cpu_to_le32(ms->m_flags);
  43. ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq);
  44. ms->m_hash = cpu_to_le32(ms->m_hash);
  45. ms->m_status = cpu_to_le32(ms->m_status);
  46. ms->m_grmode = cpu_to_le32(ms->m_grmode);
  47. ms->m_rqmode = cpu_to_le32(ms->m_rqmode);
  48. ms->m_bastmode = cpu_to_le32(ms->m_bastmode);
  49. ms->m_asts = cpu_to_le32(ms->m_asts);
  50. ms->m_result = cpu_to_le32(ms->m_result);
  51. }
  52. void dlm_message_in(struct dlm_message *ms)
  53. {
  54. struct dlm_header *hd = (struct dlm_header *) ms;
  55. header_in(hd);
  56. ms->m_type = le32_to_cpu(ms->m_type);
  57. ms->m_nodeid = le32_to_cpu(ms->m_nodeid);
  58. ms->m_pid = le32_to_cpu(ms->m_pid);
  59. ms->m_lkid = le32_to_cpu(ms->m_lkid);
  60. ms->m_remid = le32_to_cpu(ms->m_remid);
  61. ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid);
  62. ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid);
  63. ms->m_exflags = le32_to_cpu(ms->m_exflags);
  64. ms->m_sbflags = le32_to_cpu(ms->m_sbflags);
  65. ms->m_flags = le32_to_cpu(ms->m_flags);
  66. ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq);
  67. ms->m_hash = le32_to_cpu(ms->m_hash);
  68. ms->m_status = le32_to_cpu(ms->m_status);
  69. ms->m_grmode = le32_to_cpu(ms->m_grmode);
  70. ms->m_rqmode = le32_to_cpu(ms->m_rqmode);
  71. ms->m_bastmode = le32_to_cpu(ms->m_bastmode);
  72. ms->m_asts = le32_to_cpu(ms->m_asts);
  73. ms->m_result = le32_to_cpu(ms->m_result);
  74. }
  75. static void rcom_lock_out(struct rcom_lock *rl)
  76. {
  77. rl->rl_ownpid = cpu_to_le32(rl->rl_ownpid);
  78. rl->rl_lkid = cpu_to_le32(rl->rl_lkid);
  79. rl->rl_remid = cpu_to_le32(rl->rl_remid);
  80. rl->rl_parent_lkid = cpu_to_le32(rl->rl_parent_lkid);
  81. rl->rl_parent_remid = cpu_to_le32(rl->rl_parent_remid);
  82. rl->rl_exflags = cpu_to_le32(rl->rl_exflags);
  83. rl->rl_flags = cpu_to_le32(rl->rl_flags);
  84. rl->rl_lvbseq = cpu_to_le32(rl->rl_lvbseq);
  85. rl->rl_result = cpu_to_le32(rl->rl_result);
  86. rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type);
  87. rl->rl_namelen = cpu_to_le16(rl->rl_namelen);
  88. }
  89. static void rcom_lock_in(struct rcom_lock *rl)
  90. {
  91. rl->rl_ownpid = le32_to_cpu(rl->rl_ownpid);
  92. rl->rl_lkid = le32_to_cpu(rl->rl_lkid);
  93. rl->rl_remid = le32_to_cpu(rl->rl_remid);
  94. rl->rl_parent_lkid = le32_to_cpu(rl->rl_parent_lkid);
  95. rl->rl_parent_remid = le32_to_cpu(rl->rl_parent_remid);
  96. rl->rl_exflags = le32_to_cpu(rl->rl_exflags);
  97. rl->rl_flags = le32_to_cpu(rl->rl_flags);
  98. rl->rl_lvbseq = le32_to_cpu(rl->rl_lvbseq);
  99. rl->rl_result = le32_to_cpu(rl->rl_result);
  100. rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type);
  101. rl->rl_namelen = le16_to_cpu(rl->rl_namelen);
  102. }
  103. static void rcom_config_out(struct rcom_config *rf)
  104. {
  105. rf->rf_lvblen = cpu_to_le32(rf->rf_lvblen);
  106. rf->rf_lsflags = cpu_to_le32(rf->rf_lsflags);
  107. }
  108. static void rcom_config_in(struct rcom_config *rf)
  109. {
  110. rf->rf_lvblen = le32_to_cpu(rf->rf_lvblen);
  111. rf->rf_lsflags = le32_to_cpu(rf->rf_lsflags);
  112. }
  113. void dlm_rcom_out(struct dlm_rcom *rc)
  114. {
  115. struct dlm_header *hd = (struct dlm_header *) rc;
  116. int type = rc->rc_type;
  117. header_out(hd);
  118. rc->rc_type = cpu_to_le32(rc->rc_type);
  119. rc->rc_result = cpu_to_le32(rc->rc_result);
  120. rc->rc_id = cpu_to_le64(rc->rc_id);
  121. rc->rc_seq = cpu_to_le64(rc->rc_seq);
  122. rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply);
  123. if (type == DLM_RCOM_LOCK)
  124. rcom_lock_out((struct rcom_lock *) rc->rc_buf);
  125. else if (type == DLM_RCOM_STATUS_REPLY)
  126. rcom_config_out((struct rcom_config *) rc->rc_buf);
  127. }
  128. void dlm_rcom_in(struct dlm_rcom *rc)
  129. {
  130. struct dlm_header *hd = (struct dlm_header *) rc;
  131. header_in(hd);
  132. rc->rc_type = le32_to_cpu(rc->rc_type);
  133. rc->rc_result = le32_to_cpu(rc->rc_result);
  134. rc->rc_id = le64_to_cpu(rc->rc_id);
  135. rc->rc_seq = le64_to_cpu(rc->rc_seq);
  136. rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply);
  137. if (rc->rc_type == DLM_RCOM_LOCK)
  138. rcom_lock_in((struct rcom_lock *) rc->rc_buf);
  139. else if (rc->rc_type == DLM_RCOM_STATUS_REPLY)
  140. rcom_config_in((struct rcom_config *) rc->rc_buf);
  141. }