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