Skip to content

Commit

Permalink
fs: dlm: switch lkb_sbflags to atomic ops
Browse files Browse the repository at this point in the history
This patch moves lkb_sbflags handling to atomic bits ops. This should
prepare for a possible manipulating of lkb_sbflags flags at the same
time by concurrent execution.

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 46d6e72 commit 1361737
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
28 changes: 27 additions & 1 deletion fs/dlm/dlm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct dlm_lkb {
uint32_t lkb_id; /* our lock ID */
uint32_t lkb_remid; /* lock ID on remote partner */
uint32_t lkb_exflags; /* external flags from caller */
uint32_t lkb_sbflags; /* lksb flags */
unsigned long lkb_sbflags; /* lksb flags */
unsigned long lkb_dflags; /* distributed flags */
unsigned long lkb_iflags; /* internal flags */
uint32_t lkb_lvbseq; /* lvb sequence number */
Expand Down Expand Up @@ -760,6 +760,26 @@ static inline uint32_t dlm_dflags_val(const struct dlm_lkb *lkb)
__DLM_DFL_MAX_BIT);
}

/* coming from UAPI header
*
* TODO:
* Move this to UAPI header and let other values point to them and use BIT()
*/
#define DLM_SBF_DEMOTED_BIT 0
#define __DLM_SBF_MIN_BIT DLM_SBF_DEMOTED_BIT
#define DLM_SBF_VALNOTVALID_BIT 1
#define DLM_SBF_ALTMODE_BIT 2
#define __DLM_SBF_MAX_BIT DLM_SBF_ALTMODE_BIT

static inline uint32_t dlm_sbflags_val(const struct dlm_lkb *lkb)
{
/* be sure the next person updates this */
BUILD_BUG_ON(BIT(__DLM_SBF_MAX_BIT) != DLM_SBF_ALTMODE);

return dlm_flags_val(&lkb->lkb_sbflags, __DLM_SBF_MIN_BIT,
__DLM_SBF_MAX_BIT);
}

static inline void dlm_set_flags_val(unsigned long *addr, uint32_t val,
uint32_t min, uint32_t max)
{
Expand All @@ -779,6 +799,12 @@ static inline void dlm_set_dflags_val(struct dlm_lkb *lkb, uint32_t val)
__DLM_DFL_MAX_BIT);
}

static inline void dlm_set_sbflags_val(struct dlm_lkb *lkb, uint32_t val)
{
dlm_set_flags_val(&lkb->lkb_sbflags, val, __DLM_SBF_MIN_BIT,
__DLM_SBF_MAX_BIT);
}

int dlm_plock_init(void);
void dlm_plock_exit(void);

Expand Down
22 changes: 11 additions & 11 deletions fs/dlm/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ static inline int force_blocking_asts(struct dlm_lkb *lkb)

static inline int is_demoted(struct dlm_lkb *lkb)
{
return (lkb->lkb_sbflags & DLM_SBF_DEMOTED);
return test_bit(DLM_SBF_DEMOTED_BIT, &lkb->lkb_sbflags);
}

static inline int is_altmode(struct dlm_lkb *lkb)
{
return (lkb->lkb_sbflags & DLM_SBF_ALTMODE);
return test_bit(DLM_SBF_ALTMODE_BIT, &lkb->lkb_sbflags);
}

static inline int is_granted(struct dlm_lkb *lkb)
Expand Down Expand Up @@ -298,7 +298,7 @@ static void queue_cast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv)
test_and_clear_bit(DLM_IFL_DEADLOCK_CANCEL_BIT, &lkb->lkb_iflags))
rv = -EDEADLK;

dlm_add_cb(lkb, DLM_CB_CAST, lkb->lkb_grmode, rv, lkb->lkb_sbflags);
dlm_add_cb(lkb, DLM_CB_CAST, lkb->lkb_grmode, rv, dlm_sbflags_val(lkb));
}

static inline void queue_cast_overlap(struct dlm_rsb *r, struct dlm_lkb *lkb)
Expand Down Expand Up @@ -1770,7 +1770,7 @@ static void set_lvb_lock(struct dlm_rsb *r, struct dlm_lkb *lkb)
}

if (rsb_flag(r, RSB_VALNOTVALID))
lkb->lkb_sbflags |= DLM_SBF_VALNOTVALID;
set_bit(DLM_SBF_VALNOTVALID_BIT, &lkb->lkb_sbflags);
}

static void set_lvb_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb)
Expand Down Expand Up @@ -2242,7 +2242,7 @@ static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now,
conversion_deadlock_detect(r, lkb)) {
if (lkb->lkb_exflags & DLM_LKF_CONVDEADLK) {
lkb->lkb_grmode = DLM_LOCK_NL;
lkb->lkb_sbflags |= DLM_SBF_DEMOTED;
set_bit(DLM_SBF_DEMOTED_BIT, &lkb->lkb_sbflags);
} else if (err) {
*err = -EDEADLK;
} else {
Expand All @@ -2269,7 +2269,7 @@ static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now,
lkb->lkb_rqmode = alt;
rv = _can_be_granted(r, lkb, now, 0);
if (rv)
lkb->lkb_sbflags |= DLM_SBF_ALTMODE;
set_bit(DLM_SBF_ALTMODE_BIT, &lkb->lkb_sbflags);
else
lkb->lkb_rqmode = rqmode;
}
Expand Down Expand Up @@ -2685,7 +2685,7 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
}

lkb->lkb_exflags = args->flags;
lkb->lkb_sbflags = 0;
dlm_set_sbflags_val(lkb, 0);
lkb->lkb_astfn = args->astfn;
lkb->lkb_astparam = args->astparam;
lkb->lkb_bastfn = args->bastfn;
Expand Down Expand Up @@ -2836,7 +2836,7 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)
out_ok:
/* an overlapping op shouldn't blow away exflags from other op */
lkb->lkb_exflags |= args->flags;
lkb->lkb_sbflags = 0;
dlm_set_sbflags_val(lkb, 0);
lkb->lkb_astparam = args->astparam;
rv = 0;
out:
Expand Down Expand Up @@ -3408,7 +3408,7 @@ static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb,
ms->m_lkid = cpu_to_le32(lkb->lkb_id);
ms->m_remid = cpu_to_le32(lkb->lkb_remid);
ms->m_exflags = cpu_to_le32(lkb->lkb_exflags);
ms->m_sbflags = cpu_to_le32(lkb->lkb_sbflags);
ms->m_sbflags = cpu_to_le32(dlm_sbflags_val(lkb));
ms->m_flags = cpu_to_le32(dlm_dflags_val(lkb));
ms->m_lvbseq = cpu_to_le32(lkb->lkb_lvbseq);
ms->m_status = cpu_to_le32(lkb->lkb_status);
Expand Down Expand Up @@ -3673,7 +3673,7 @@ static int send_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms_in,
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);
dlm_set_sbflags_val(lkb, le32_to_cpu(ms->m_sbflags));
dlm_set_dflags_val(lkb, le32_to_cpu(ms->m_flags));
}

Expand All @@ -3683,7 +3683,7 @@ static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms,
if (local)
return;

lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags);
dlm_set_sbflags_val(lkb, le32_to_cpu(ms->m_sbflags));
dlm_set_dflags_val(lkb, le32_to_cpu(ms->m_flags));
}

Expand Down

0 comments on commit 1361737

Please sign in to comment.