1e7fd4179SDavid Teigland /****************************************************************************** 2e7fd4179SDavid Teigland ******************************************************************************* 3e7fd4179SDavid Teigland ** 4*dbcfc347SDavid Teigland ** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved. 5e7fd4179SDavid Teigland ** 6e7fd4179SDavid Teigland ** This copyrighted material is made available to anyone wishing to use, 7e7fd4179SDavid Teigland ** modify, copy, or redistribute it subject to the terms and conditions 8e7fd4179SDavid Teigland ** of the GNU General Public License v.2. 9e7fd4179SDavid Teigland ** 10e7fd4179SDavid Teigland ******************************************************************************* 11e7fd4179SDavid Teigland ******************************************************************************/ 12e7fd4179SDavid Teigland 13e7fd4179SDavid Teigland #include "dlm_internal.h" 14e7fd4179SDavid Teigland #include "rcom.h" 15e7fd4179SDavid Teigland #include "util.h" 16e7fd4179SDavid Teigland 17861e2369SDavid Teigland #define DLM_ERRNO_EDEADLK 35 18861e2369SDavid Teigland #define DLM_ERRNO_EBADR 53 19861e2369SDavid Teigland #define DLM_ERRNO_EBADSLT 57 20861e2369SDavid Teigland #define DLM_ERRNO_EPROTO 71 21861e2369SDavid Teigland #define DLM_ERRNO_EOPNOTSUPP 95 22861e2369SDavid Teigland #define DLM_ERRNO_ETIMEDOUT 110 23861e2369SDavid Teigland #define DLM_ERRNO_EINPROGRESS 115 24861e2369SDavid Teigland 25e7fd4179SDavid Teigland static void header_out(struct dlm_header *hd) 26e7fd4179SDavid Teigland { 27e7fd4179SDavid Teigland hd->h_version = cpu_to_le32(hd->h_version); 28e7fd4179SDavid Teigland hd->h_lockspace = cpu_to_le32(hd->h_lockspace); 29e7fd4179SDavid Teigland hd->h_nodeid = cpu_to_le32(hd->h_nodeid); 30e7fd4179SDavid Teigland hd->h_length = cpu_to_le16(hd->h_length); 31e7fd4179SDavid Teigland } 32e7fd4179SDavid Teigland 33e7fd4179SDavid Teigland static void header_in(struct dlm_header *hd) 34e7fd4179SDavid Teigland { 35e7fd4179SDavid Teigland hd->h_version = le32_to_cpu(hd->h_version); 36e7fd4179SDavid Teigland hd->h_lockspace = le32_to_cpu(hd->h_lockspace); 37e7fd4179SDavid Teigland hd->h_nodeid = le32_to_cpu(hd->h_nodeid); 38e7fd4179SDavid Teigland hd->h_length = le16_to_cpu(hd->h_length); 39e7fd4179SDavid Teigland } 40e7fd4179SDavid Teigland 41861e2369SDavid Teigland /* higher errno values are inconsistent across architectures, so select 42861e2369SDavid Teigland one set of values for on the wire */ 43861e2369SDavid Teigland 44861e2369SDavid Teigland static int to_dlm_errno(int err) 45861e2369SDavid Teigland { 46861e2369SDavid Teigland switch (err) { 47861e2369SDavid Teigland case -EDEADLK: 48861e2369SDavid Teigland return -DLM_ERRNO_EDEADLK; 49861e2369SDavid Teigland case -EBADR: 50861e2369SDavid Teigland return -DLM_ERRNO_EBADR; 51861e2369SDavid Teigland case -EBADSLT: 52861e2369SDavid Teigland return -DLM_ERRNO_EBADSLT; 53861e2369SDavid Teigland case -EPROTO: 54861e2369SDavid Teigland return -DLM_ERRNO_EPROTO; 55861e2369SDavid Teigland case -EOPNOTSUPP: 56861e2369SDavid Teigland return -DLM_ERRNO_EOPNOTSUPP; 57861e2369SDavid Teigland case -ETIMEDOUT: 58861e2369SDavid Teigland return -DLM_ERRNO_ETIMEDOUT; 59861e2369SDavid Teigland case -EINPROGRESS: 60861e2369SDavid Teigland return -DLM_ERRNO_EINPROGRESS; 61861e2369SDavid Teigland } 62861e2369SDavid Teigland return err; 63861e2369SDavid Teigland } 64861e2369SDavid Teigland 65861e2369SDavid Teigland static int from_dlm_errno(int err) 66861e2369SDavid Teigland { 67861e2369SDavid Teigland switch (err) { 68861e2369SDavid Teigland case -DLM_ERRNO_EDEADLK: 69861e2369SDavid Teigland return -EDEADLK; 70861e2369SDavid Teigland case -DLM_ERRNO_EBADR: 71861e2369SDavid Teigland return -EBADR; 72861e2369SDavid Teigland case -DLM_ERRNO_EBADSLT: 73861e2369SDavid Teigland return -EBADSLT; 74861e2369SDavid Teigland case -DLM_ERRNO_EPROTO: 75861e2369SDavid Teigland return -EPROTO; 76861e2369SDavid Teigland case -DLM_ERRNO_EOPNOTSUPP: 77861e2369SDavid Teigland return -EOPNOTSUPP; 78861e2369SDavid Teigland case -DLM_ERRNO_ETIMEDOUT: 79861e2369SDavid Teigland return -ETIMEDOUT; 80861e2369SDavid Teigland case -DLM_ERRNO_EINPROGRESS: 81861e2369SDavid Teigland return -EINPROGRESS; 82861e2369SDavid Teigland } 83861e2369SDavid Teigland return err; 84861e2369SDavid Teigland } 85861e2369SDavid Teigland 86e7fd4179SDavid Teigland void dlm_message_out(struct dlm_message *ms) 87e7fd4179SDavid Teigland { 88*dbcfc347SDavid Teigland header_out(&ms->m_header); 89e7fd4179SDavid Teigland 90e7fd4179SDavid Teigland ms->m_type = cpu_to_le32(ms->m_type); 91e7fd4179SDavid Teigland ms->m_nodeid = cpu_to_le32(ms->m_nodeid); 92e7fd4179SDavid Teigland ms->m_pid = cpu_to_le32(ms->m_pid); 93e7fd4179SDavid Teigland ms->m_lkid = cpu_to_le32(ms->m_lkid); 94e7fd4179SDavid Teigland ms->m_remid = cpu_to_le32(ms->m_remid); 95e7fd4179SDavid Teigland ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid); 96e7fd4179SDavid Teigland ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid); 97e7fd4179SDavid Teigland ms->m_exflags = cpu_to_le32(ms->m_exflags); 98e7fd4179SDavid Teigland ms->m_sbflags = cpu_to_le32(ms->m_sbflags); 99e7fd4179SDavid Teigland ms->m_flags = cpu_to_le32(ms->m_flags); 100e7fd4179SDavid Teigland ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq); 101e7fd4179SDavid Teigland ms->m_hash = cpu_to_le32(ms->m_hash); 102e7fd4179SDavid Teigland ms->m_status = cpu_to_le32(ms->m_status); 103e7fd4179SDavid Teigland ms->m_grmode = cpu_to_le32(ms->m_grmode); 104e7fd4179SDavid Teigland ms->m_rqmode = cpu_to_le32(ms->m_rqmode); 105e7fd4179SDavid Teigland ms->m_bastmode = cpu_to_le32(ms->m_bastmode); 106e7fd4179SDavid Teigland ms->m_asts = cpu_to_le32(ms->m_asts); 107861e2369SDavid Teigland ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result)); 108e7fd4179SDavid Teigland } 109e7fd4179SDavid Teigland 110e7fd4179SDavid Teigland void dlm_message_in(struct dlm_message *ms) 111e7fd4179SDavid Teigland { 112*dbcfc347SDavid Teigland header_in(&ms->m_header); 113e7fd4179SDavid Teigland 114e7fd4179SDavid Teigland ms->m_type = le32_to_cpu(ms->m_type); 115e7fd4179SDavid Teigland ms->m_nodeid = le32_to_cpu(ms->m_nodeid); 116e7fd4179SDavid Teigland ms->m_pid = le32_to_cpu(ms->m_pid); 117e7fd4179SDavid Teigland ms->m_lkid = le32_to_cpu(ms->m_lkid); 118e7fd4179SDavid Teigland ms->m_remid = le32_to_cpu(ms->m_remid); 119e7fd4179SDavid Teigland ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid); 120e7fd4179SDavid Teigland ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid); 121e7fd4179SDavid Teigland ms->m_exflags = le32_to_cpu(ms->m_exflags); 122e7fd4179SDavid Teigland ms->m_sbflags = le32_to_cpu(ms->m_sbflags); 123e7fd4179SDavid Teigland ms->m_flags = le32_to_cpu(ms->m_flags); 124e7fd4179SDavid Teigland ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq); 125e7fd4179SDavid Teigland ms->m_hash = le32_to_cpu(ms->m_hash); 126e7fd4179SDavid Teigland ms->m_status = le32_to_cpu(ms->m_status); 127e7fd4179SDavid Teigland ms->m_grmode = le32_to_cpu(ms->m_grmode); 128e7fd4179SDavid Teigland ms->m_rqmode = le32_to_cpu(ms->m_rqmode); 129e7fd4179SDavid Teigland ms->m_bastmode = le32_to_cpu(ms->m_bastmode); 130e7fd4179SDavid Teigland ms->m_asts = le32_to_cpu(ms->m_asts); 131861e2369SDavid Teigland ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result)); 132e7fd4179SDavid Teigland } 133e7fd4179SDavid Teigland 134e7fd4179SDavid Teigland static void rcom_lock_out(struct rcom_lock *rl) 135e7fd4179SDavid Teigland { 136e7fd4179SDavid Teigland rl->rl_ownpid = cpu_to_le32(rl->rl_ownpid); 137e7fd4179SDavid Teigland rl->rl_lkid = cpu_to_le32(rl->rl_lkid); 138e7fd4179SDavid Teigland rl->rl_remid = cpu_to_le32(rl->rl_remid); 139e7fd4179SDavid Teigland rl->rl_parent_lkid = cpu_to_le32(rl->rl_parent_lkid); 140e7fd4179SDavid Teigland rl->rl_parent_remid = cpu_to_le32(rl->rl_parent_remid); 141e7fd4179SDavid Teigland rl->rl_exflags = cpu_to_le32(rl->rl_exflags); 142e7fd4179SDavid Teigland rl->rl_flags = cpu_to_le32(rl->rl_flags); 143e7fd4179SDavid Teigland rl->rl_lvbseq = cpu_to_le32(rl->rl_lvbseq); 144e7fd4179SDavid Teigland rl->rl_result = cpu_to_le32(rl->rl_result); 145e7fd4179SDavid Teigland rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type); 146e7fd4179SDavid Teigland rl->rl_namelen = cpu_to_le16(rl->rl_namelen); 147e7fd4179SDavid Teigland } 148e7fd4179SDavid Teigland 149e7fd4179SDavid Teigland static void rcom_lock_in(struct rcom_lock *rl) 150e7fd4179SDavid Teigland { 151e7fd4179SDavid Teigland rl->rl_ownpid = le32_to_cpu(rl->rl_ownpid); 152e7fd4179SDavid Teigland rl->rl_lkid = le32_to_cpu(rl->rl_lkid); 153e7fd4179SDavid Teigland rl->rl_remid = le32_to_cpu(rl->rl_remid); 154e7fd4179SDavid Teigland rl->rl_parent_lkid = le32_to_cpu(rl->rl_parent_lkid); 155e7fd4179SDavid Teigland rl->rl_parent_remid = le32_to_cpu(rl->rl_parent_remid); 156e7fd4179SDavid Teigland rl->rl_exflags = le32_to_cpu(rl->rl_exflags); 157e7fd4179SDavid Teigland rl->rl_flags = le32_to_cpu(rl->rl_flags); 158e7fd4179SDavid Teigland rl->rl_lvbseq = le32_to_cpu(rl->rl_lvbseq); 159e7fd4179SDavid Teigland rl->rl_result = le32_to_cpu(rl->rl_result); 160e7fd4179SDavid Teigland rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type); 161e7fd4179SDavid Teigland rl->rl_namelen = le16_to_cpu(rl->rl_namelen); 162e7fd4179SDavid Teigland } 163e7fd4179SDavid Teigland 164e7fd4179SDavid Teigland static void rcom_config_out(struct rcom_config *rf) 165e7fd4179SDavid Teigland { 166e7fd4179SDavid Teigland rf->rf_lvblen = cpu_to_le32(rf->rf_lvblen); 167e7fd4179SDavid Teigland rf->rf_lsflags = cpu_to_le32(rf->rf_lsflags); 168e7fd4179SDavid Teigland } 169e7fd4179SDavid Teigland 170e7fd4179SDavid Teigland static void rcom_config_in(struct rcom_config *rf) 171e7fd4179SDavid Teigland { 172e7fd4179SDavid Teigland rf->rf_lvblen = le32_to_cpu(rf->rf_lvblen); 173e7fd4179SDavid Teigland rf->rf_lsflags = le32_to_cpu(rf->rf_lsflags); 174e7fd4179SDavid Teigland } 175e7fd4179SDavid Teigland 176e7fd4179SDavid Teigland void dlm_rcom_out(struct dlm_rcom *rc) 177e7fd4179SDavid Teigland { 178e7fd4179SDavid Teigland int type = rc->rc_type; 179e7fd4179SDavid Teigland 180*dbcfc347SDavid Teigland header_out(&rc->rc_header); 181e7fd4179SDavid Teigland 182e7fd4179SDavid Teigland rc->rc_type = cpu_to_le32(rc->rc_type); 183e7fd4179SDavid Teigland rc->rc_result = cpu_to_le32(rc->rc_result); 184e7fd4179SDavid Teigland rc->rc_id = cpu_to_le64(rc->rc_id); 18538aa8b0cSDavid Teigland rc->rc_seq = cpu_to_le64(rc->rc_seq); 18638aa8b0cSDavid Teigland rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply); 187e7fd4179SDavid Teigland 188550283e3SFabio M. Di Nitto if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY)) 189e7fd4179SDavid Teigland rcom_lock_out((struct rcom_lock *) rc->rc_buf); 190e7fd4179SDavid Teigland 191e7fd4179SDavid Teigland else if (type == DLM_RCOM_STATUS_REPLY) 192e7fd4179SDavid Teigland rcom_config_out((struct rcom_config *) rc->rc_buf); 193e7fd4179SDavid Teigland } 194e7fd4179SDavid Teigland 195e7fd4179SDavid Teigland void dlm_rcom_in(struct dlm_rcom *rc) 196e7fd4179SDavid Teigland { 197550283e3SFabio M. Di Nitto int type; 198e7fd4179SDavid Teigland 199*dbcfc347SDavid Teigland header_in(&rc->rc_header); 200e7fd4179SDavid Teigland 201e7fd4179SDavid Teigland rc->rc_type = le32_to_cpu(rc->rc_type); 202e7fd4179SDavid Teigland rc->rc_result = le32_to_cpu(rc->rc_result); 203e7fd4179SDavid Teigland rc->rc_id = le64_to_cpu(rc->rc_id); 20438aa8b0cSDavid Teigland rc->rc_seq = le64_to_cpu(rc->rc_seq); 20538aa8b0cSDavid Teigland rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply); 206e7fd4179SDavid Teigland 207550283e3SFabio M. Di Nitto type = rc->rc_type; 208550283e3SFabio M. Di Nitto 209550283e3SFabio M. Di Nitto if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY)) 210e7fd4179SDavid Teigland rcom_lock_in((struct rcom_lock *) rc->rc_buf); 211e7fd4179SDavid Teigland 212550283e3SFabio M. Di Nitto else if (type == DLM_RCOM_STATUS_REPLY) 213e7fd4179SDavid Teigland rcom_config_in((struct rcom_config *) rc->rc_buf); 214e7fd4179SDavid Teigland } 215e7fd4179SDavid Teigland 216