2019-05-29 00:57:20 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-01-18 17:30:29 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
**
|
2008-01-30 04:52:10 +08:00
|
|
|
** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
|
2006-01-18 17:30:29 +08:00
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "dlm_internal.h"
|
|
|
|
#include "rcom.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2008-01-16 05:43:24 +08:00
|
|
|
#define DLM_ERRNO_EDEADLK 35
|
|
|
|
#define DLM_ERRNO_EBADR 53
|
|
|
|
#define DLM_ERRNO_EBADSLT 57
|
|
|
|
#define DLM_ERRNO_EPROTO 71
|
|
|
|
#define DLM_ERRNO_EOPNOTSUPP 95
|
|
|
|
#define DLM_ERRNO_ETIMEDOUT 110
|
|
|
|
#define DLM_ERRNO_EINPROGRESS 115
|
|
|
|
|
2006-01-18 17:30:29 +08:00
|
|
|
static void header_out(struct dlm_header *hd)
|
|
|
|
{
|
|
|
|
hd->h_version = cpu_to_le32(hd->h_version);
|
|
|
|
hd->h_lockspace = cpu_to_le32(hd->h_lockspace);
|
|
|
|
hd->h_nodeid = cpu_to_le32(hd->h_nodeid);
|
|
|
|
hd->h_length = cpu_to_le16(hd->h_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void header_in(struct dlm_header *hd)
|
|
|
|
{
|
|
|
|
hd->h_version = le32_to_cpu(hd->h_version);
|
|
|
|
hd->h_lockspace = le32_to_cpu(hd->h_lockspace);
|
|
|
|
hd->h_nodeid = le32_to_cpu(hd->h_nodeid);
|
|
|
|
hd->h_length = le16_to_cpu(hd->h_length);
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:43:24 +08:00
|
|
|
/* higher errno values are inconsistent across architectures, so select
|
|
|
|
one set of values for on the wire */
|
|
|
|
|
|
|
|
static int to_dlm_errno(int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case -EDEADLK:
|
|
|
|
return -DLM_ERRNO_EDEADLK;
|
|
|
|
case -EBADR:
|
|
|
|
return -DLM_ERRNO_EBADR;
|
|
|
|
case -EBADSLT:
|
|
|
|
return -DLM_ERRNO_EBADSLT;
|
|
|
|
case -EPROTO:
|
|
|
|
return -DLM_ERRNO_EPROTO;
|
|
|
|
case -EOPNOTSUPP:
|
|
|
|
return -DLM_ERRNO_EOPNOTSUPP;
|
|
|
|
case -ETIMEDOUT:
|
|
|
|
return -DLM_ERRNO_ETIMEDOUT;
|
|
|
|
case -EINPROGRESS:
|
|
|
|
return -DLM_ERRNO_EINPROGRESS;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int from_dlm_errno(int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case -DLM_ERRNO_EDEADLK:
|
|
|
|
return -EDEADLK;
|
|
|
|
case -DLM_ERRNO_EBADR:
|
|
|
|
return -EBADR;
|
|
|
|
case -DLM_ERRNO_EBADSLT:
|
|
|
|
return -EBADSLT;
|
|
|
|
case -DLM_ERRNO_EPROTO:
|
|
|
|
return -EPROTO;
|
|
|
|
case -DLM_ERRNO_EOPNOTSUPP:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
case -DLM_ERRNO_ETIMEDOUT:
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
case -DLM_ERRNO_EINPROGRESS:
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-01-18 17:30:29 +08:00
|
|
|
void dlm_message_out(struct dlm_message *ms)
|
|
|
|
{
|
2008-01-30 04:52:10 +08:00
|
|
|
header_out(&ms->m_header);
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
ms->m_type = cpu_to_le32(ms->m_type);
|
|
|
|
ms->m_nodeid = cpu_to_le32(ms->m_nodeid);
|
|
|
|
ms->m_pid = cpu_to_le32(ms->m_pid);
|
|
|
|
ms->m_lkid = cpu_to_le32(ms->m_lkid);
|
|
|
|
ms->m_remid = cpu_to_le32(ms->m_remid);
|
|
|
|
ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid);
|
|
|
|
ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid);
|
|
|
|
ms->m_exflags = cpu_to_le32(ms->m_exflags);
|
|
|
|
ms->m_sbflags = cpu_to_le32(ms->m_sbflags);
|
|
|
|
ms->m_flags = cpu_to_le32(ms->m_flags);
|
|
|
|
ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq);
|
|
|
|
ms->m_hash = cpu_to_le32(ms->m_hash);
|
|
|
|
ms->m_status = cpu_to_le32(ms->m_status);
|
|
|
|
ms->m_grmode = cpu_to_le32(ms->m_grmode);
|
|
|
|
ms->m_rqmode = cpu_to_le32(ms->m_rqmode);
|
|
|
|
ms->m_bastmode = cpu_to_le32(ms->m_bastmode);
|
|
|
|
ms->m_asts = cpu_to_le32(ms->m_asts);
|
2008-01-16 05:43:24 +08:00
|
|
|
ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result));
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_message_in(struct dlm_message *ms)
|
|
|
|
{
|
2008-01-30 04:52:10 +08:00
|
|
|
header_in(&ms->m_header);
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
ms->m_type = le32_to_cpu(ms->m_type);
|
|
|
|
ms->m_nodeid = le32_to_cpu(ms->m_nodeid);
|
|
|
|
ms->m_pid = le32_to_cpu(ms->m_pid);
|
|
|
|
ms->m_lkid = le32_to_cpu(ms->m_lkid);
|
|
|
|
ms->m_remid = le32_to_cpu(ms->m_remid);
|
|
|
|
ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid);
|
|
|
|
ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid);
|
|
|
|
ms->m_exflags = le32_to_cpu(ms->m_exflags);
|
|
|
|
ms->m_sbflags = le32_to_cpu(ms->m_sbflags);
|
|
|
|
ms->m_flags = le32_to_cpu(ms->m_flags);
|
|
|
|
ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq);
|
|
|
|
ms->m_hash = le32_to_cpu(ms->m_hash);
|
|
|
|
ms->m_status = le32_to_cpu(ms->m_status);
|
|
|
|
ms->m_grmode = le32_to_cpu(ms->m_grmode);
|
|
|
|
ms->m_rqmode = le32_to_cpu(ms->m_rqmode);
|
|
|
|
ms->m_bastmode = le32_to_cpu(ms->m_bastmode);
|
|
|
|
ms->m_asts = le32_to_cpu(ms->m_asts);
|
2008-01-16 05:43:24 +08:00
|
|
|
ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result));
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_rcom_out(struct dlm_rcom *rc)
|
|
|
|
{
|
2008-01-30 04:52:10 +08:00
|
|
|
header_out(&rc->rc_header);
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
rc->rc_type = cpu_to_le32(rc->rc_type);
|
|
|
|
rc->rc_result = cpu_to_le32(rc->rc_result);
|
|
|
|
rc->rc_id = cpu_to_le64(rc->rc_id);
|
2006-12-14 00:37:16 +08:00
|
|
|
rc->rc_seq = cpu_to_le64(rc->rc_seq);
|
|
|
|
rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply);
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_rcom_in(struct dlm_rcom *rc)
|
|
|
|
{
|
2008-01-30 04:52:10 +08:00
|
|
|
header_in(&rc->rc_header);
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
rc->rc_type = le32_to_cpu(rc->rc_type);
|
|
|
|
rc->rc_result = le32_to_cpu(rc->rc_result);
|
|
|
|
rc->rc_id = le64_to_cpu(rc->rc_id);
|
2006-12-14 00:37:16 +08:00
|
|
|
rc->rc_seq = le64_to_cpu(rc->rc_seq);
|
|
|
|
rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply);
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|