Skip to content

Commit

Permalink
fs: dlm: store lkb distributed flags into own value
Browse files Browse the repository at this point in the history
This patch stores lkb distributed flags value in an separate value
instead of sharing internal and distributed flags in lkb->lkb_flags value.
This has the advantage to not mask/write back flag values in
receive_flags() functionality. The dlm debug_fs does not provide the
distributed flags anymore, those can be added in future.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
  • Loading branch information
Alexander Aring authored and David Teigland committed Mar 6, 2023
1 parent 9f48eea commit 8c11ba6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 41 deletions.
2 changes: 1 addition & 1 deletion fs/dlm/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,
struct dlm_ls *ls = lkb->lkb_resource->res_ls;
int rv;

if (lkb->lkb_flags & DLM_IFL_USER) {
if (lkb->lkb_dflags & DLM_DFL_USER) {
dlm_user_add_ast(lkb, flags, mode, status, sbflags);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/dlm/debug_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
u64 xid = 0;
u64 us;

if (lkb->lkb_flags & DLM_IFL_USER) {
if (lkb->lkb_dflags & DLM_DFL_USER) {
if (lkb->lkb_ua)
xid = lkb->lkb_ua->xid;
}
Expand Down Expand Up @@ -230,7 +230,7 @@ static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
{
u64 xid = 0;

if (lkb->lkb_flags & DLM_IFL_USER) {
if (lkb->lkb_dflags & DLM_DFL_USER) {
if (lkb->lkb_ua)
xid = lkb->lkb_ua->xid;
}
Expand Down
15 changes: 5 additions & 10 deletions fs/dlm/dlm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,10 @@ struct dlm_args {

#define DLM_IFL_CB_PENDING_BIT 0

/* least significant 2 bytes are message changed, they are full transmitted
* but at receive side only the 2 bytes LSB will be set.
*
* Even wireshark dlm dissector does only evaluate the lower bytes and note
* that they may not be used on transceiver side, we assume the higher bytes
* are for internal use or reserved so long they are not parsed on receiver
* side.
*/
#define DLM_IFL_USER 0x00000001
#define DLM_IFL_ORPHAN 0x00000002
/* lkb_dflags */

#define DLM_DFL_USER 0x00000001
#define DLM_DFL_ORPHAN 0x00000002

#define DLM_CB_CAST 0x00000001
#define DLM_CB_BAST 0x00000002
Expand All @@ -240,6 +234,7 @@ struct dlm_lkb {
uint32_t lkb_exflags; /* external flags from caller */
uint32_t lkb_sbflags; /* lksb flags */
uint32_t lkb_flags; /* internal flags */
uint32_t lkb_dflags; /* distributed flags */
unsigned long lkb_iflags; /* internal flags */
uint32_t lkb_lvbseq; /* lvb sequence number */

Expand Down
28 changes: 13 additions & 15 deletions fs/dlm/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3675,8 +3675,7 @@ static void receive_flags(struct dlm_lkb *lkb, struct dlm_message *ms)
{
lkb->lkb_exflags = le32_to_cpu(ms->m_exflags);
lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags);
lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) |
(le32_to_cpu(ms->m_flags) & 0x0000FFFF);
lkb->lkb_dflags = le32_to_cpu(ms->m_flags);
}

static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms,
Expand All @@ -3686,8 +3685,7 @@ static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms,
return;

lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags);
lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) |
(le32_to_cpu(ms->m_flags) & 0x0000FFFF);
lkb->lkb_dflags = le32_to_cpu(ms->m_flags);
}

static int receive_extralen(struct dlm_message *ms)
Expand Down Expand Up @@ -3788,8 +3786,8 @@ static int validate_message(struct dlm_lkb *lkb, struct dlm_message *ms)
int error = 0;

/* currently mixing of user/kernel locks are not supported */
if (ms->m_flags & cpu_to_le32(DLM_IFL_USER) &&
~lkb->lkb_flags & DLM_IFL_USER) {
if (ms->m_flags & cpu_to_le32(DLM_DFL_USER) &&
~lkb->lkb_dflags & DLM_DFL_USER) {
log_error(lkb->lkb_resource->res_ls,
"got user dlm message for a kernel lock");
error = -EINVAL;
Expand Down Expand Up @@ -5347,7 +5345,7 @@ static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
lkb->lkb_ownpid = le32_to_cpu(rl->rl_ownpid);
lkb->lkb_remid = le32_to_cpu(rl->rl_lkid);
lkb->lkb_exflags = le32_to_cpu(rl->rl_exflags);
lkb->lkb_flags = le32_to_cpu(rl->rl_flags) & 0x0000FFFF;
lkb->lkb_dflags = le32_to_cpu(rl->rl_flags);
lkb->lkb_flags |= DLM_IFL_MSTCPY;
lkb->lkb_lvbseq = le32_to_cpu(rl->rl_lvbseq);
lkb->lkb_rqmode = rl->rl_rqmode;
Expand Down Expand Up @@ -5573,9 +5571,9 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
}

/* After ua is attached to lkb it will be freed by dlm_free_lkb().
When DLM_IFL_USER is set, the dlm knows that this is a userspace
When DLM_DFL_USER is set, the dlm knows that this is a userspace
lock and that lkb_astparam is the dlm_user_args structure. */
lkb->lkb_flags |= DLM_IFL_USER;
lkb->lkb_dflags |= DLM_DFL_USER;
error = request_lock(ls, lkb, name, namelen, &args);

switch (error) {
Expand Down Expand Up @@ -5690,7 +5688,7 @@ int dlm_user_adopt_orphan(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,

lkb = iter;
list_del_init(&iter->lkb_ownqueue);
iter->lkb_flags &= ~DLM_IFL_ORPHAN;
iter->lkb_dflags &= ~DLM_DFL_ORPHAN;
*lkid = iter->lkb_id;
break;
}
Expand Down Expand Up @@ -5934,7 +5932,7 @@ static struct dlm_lkb *del_proc_lock(struct dlm_ls *ls,
list_del_init(&lkb->lkb_ownqueue);

if (lkb->lkb_exflags & DLM_LKF_PERSISTENT)
lkb->lkb_flags |= DLM_IFL_ORPHAN;
lkb->lkb_dflags |= DLM_DFL_ORPHAN;
else
lkb->lkb_flags |= DLM_IFL_DEAD;
out:
Expand Down Expand Up @@ -6085,15 +6083,15 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,

/* debug functionality */
int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
int lkb_nodeid, unsigned int lkb_flags, int lkb_status)
int lkb_nodeid, unsigned int lkb_dflags, int lkb_status)
{
struct dlm_lksb *lksb;
struct dlm_lkb *lkb;
struct dlm_rsb *r;
int error;

/* we currently can't set a valid user lock */
if (lkb_flags & DLM_IFL_USER)
if (lkb_dflags & DLM_DFL_USER)
return -EOPNOTSUPP;

lksb = kzalloc(sizeof(*lksb), GFP_NOFS);
Expand All @@ -6106,11 +6104,11 @@ int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
return error;
}

lkb->lkb_flags = lkb_flags;
lkb->lkb_dflags = lkb_dflags;
lkb->lkb_nodeid = lkb_nodeid;
lkb->lkb_lksb = lksb;
/* user specific pointer, just don't have it NULL for kernel locks */
if (~lkb_flags & DLM_IFL_USER)
if (~lkb_dflags & DLM_DFL_USER)
lkb->lkb_astparam = (void *)0xDEADBEEF;

error = find_rsb(ls, name, len, 0, R_REQUEST, &r);
Expand Down
2 changes: 1 addition & 1 deletion fs/dlm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)

void dlm_free_lkb(struct dlm_lkb *lkb)
{
if (lkb->lkb_flags & DLM_IFL_USER) {
if (lkb->lkb_dflags & DLM_DFL_USER) {
struct dlm_user_args *ua;
ua = lkb->lkb_ua;
if (ua) {
Expand Down
2 changes: 1 addition & 1 deletion fs/dlm/rcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb,
rl->rl_ownpid = cpu_to_le32(lkb->lkb_ownpid);
rl->rl_lkid = cpu_to_le32(lkb->lkb_id);
rl->rl_exflags = cpu_to_le32(lkb->lkb_exflags);
rl->rl_flags = cpu_to_le32(lkb->lkb_flags);
rl->rl_flags = cpu_to_le32(lkb->lkb_dflags);
rl->rl_lvbseq = cpu_to_le32(lkb->lkb_lvbseq);
rl->rl_rqmode = lkb->lkb_rqmode;
rl->rl_grmode = lkb->lkb_grmode;
Expand Down
6 changes: 4 additions & 2 deletions fs/dlm/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode,
struct dlm_user_proc *proc;
int rv;

if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD))
if (lkb->lkb_dflags & DLM_DFL_ORPHAN ||
lkb->lkb_flags & DLM_IFL_DEAD)
return;

ls = lkb->lkb_resource->res_ls;
Expand All @@ -195,7 +196,8 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode,
for cases where a completion ast is received for an operation that
began before clear_proc_locks did its cancel/unlock. */

if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD))
if (lkb->lkb_dflags & DLM_DFL_ORPHAN ||
lkb->lkb_flags & DLM_IFL_DEAD)
goto out;

DLM_ASSERT(lkb->lkb_ua, dlm_print_lkb(lkb););
Expand Down
11 changes: 2 additions & 9 deletions include/trace/events/dlm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@
{ DLM_SBF_ALTMODE, "ALTMODE" })

#define show_lkb_flags(flags) __print_flags(flags, "|", \
{ DLM_IFL_MSTCPY, "MSTCPY" }, \
{ DLM_IFL_RESEND, "RESEND" }, \
{ DLM_IFL_DEAD, "DEAD" }, \
{ DLM_IFL_OVERLAP_UNLOCK, "OVERLAP_UNLOCK" }, \
{ DLM_IFL_OVERLAP_CANCEL, "OVERLAP_CANCEL" }, \
{ DLM_IFL_ENDOFLIFE, "ENDOFLIFE" }, \
{ DLM_IFL_DEADLOCK_CANCEL, "DEADLOCK_CANCEL" }, \
{ DLM_IFL_USER, "USER" }, \
{ DLM_IFL_ORPHAN, "ORPHAN" })
{ DLM_DFL_USER, "USER" }, \
{ DLM_DFL_ORPHAN, "ORPHAN" })

#define show_header_cmd(cmd) __print_symbolic(cmd, \
{ DLM_MSG, "MSG"}, \
Expand Down

0 comments on commit 8c11ba6

Please sign in to comment.