struct dlm_ls *ls = lkb->lkb_resource->res_ls;
        int rv;
 
-       if (lkb->lkb_dflags & DLM_DFL_USER) {
+       if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
                dlm_user_add_ast(lkb, flags, mode, status, sbflags);
                return;
        }
 
        u64 xid = 0;
        u64 us;
 
-       if (lkb->lkb_dflags & DLM_DFL_USER) {
+       if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
                if (lkb->lkb_ua)
                        xid = lkb->lkb_ua->xid;
        }
 {
        u64 xid = 0;
 
-       if (lkb->lkb_dflags & DLM_DFL_USER) {
+       if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
                if (lkb->lkb_ua)
                        xid = lkb->lkb_ua->xid;
        }
 
 
 /* lkb_dflags */
 
-#define DLM_DFL_USER           0x00000001
-#define DLM_DFL_ORPHAN         0x00000002
+#define DLM_DFL_USER_BIT       0
+#define __DLM_DFL_MIN_BIT      DLM_DFL_USER_BIT
+#define DLM_DFL_ORPHAN_BIT     1
+#define __DLM_DFL_MAX_BIT      DLM_DFL_ORPHAN_BIT
 
 #define DLM_CB_CAST            0x00000001
 #define DLM_CB_BAST            0x00000002
        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_dflags;     /* distributed flags */
        unsigned long           lkb_iflags;     /* internal flags */
        uint32_t                lkb_lvbseq;     /* lvb sequence number */
 
        return test_bit(LSFL_NODIR, &ls->ls_flags);
 }
 
+/* takes a snapshot from dlm atomic flags */
+static inline uint32_t dlm_flags_val(const unsigned long *addr,
+                                    uint32_t min, uint32_t max)
+{
+       uint32_t bit = min, val = 0;
+
+       for_each_set_bit_from(bit, addr, max + 1) {
+               val |= BIT(bit);
+       }
+
+       return val;
+}
+
+static inline uint32_t dlm_dflags_val(const struct dlm_lkb *lkb)
+{
+       return dlm_flags_val(&lkb->lkb_dflags, __DLM_DFL_MIN_BIT,
+                            __DLM_DFL_MAX_BIT);
+}
+
+static inline void dlm_set_flags_val(unsigned long *addr, uint32_t val,
+                                    uint32_t min, uint32_t max)
+{
+       uint32_t bit;
+
+       for (bit = min; bit < (max + 1); bit++) {
+               if (val & BIT(bit))
+                       set_bit(bit, addr);
+               else
+                       clear_bit(bit, addr);
+       }
+}
+
+static inline void dlm_set_dflags_val(struct dlm_lkb *lkb, uint32_t val)
+{
+       dlm_set_flags_val(&lkb->lkb_dflags, val, __DLM_DFL_MIN_BIT,
+                         __DLM_DFL_MAX_BIT);
+}
+
 int dlm_plock_init(void);
 void dlm_plock_exit(void);
 
 
        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_flags    = cpu_to_le32(lkb->lkb_flags);
+       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);
        ms->m_grmode   = cpu_to_le32(lkb->lkb_grmode);
 {
        lkb->lkb_exflags = le32_to_cpu(ms->m_exflags);
        lkb->lkb_sbflags = le32_to_cpu(ms->m_sbflags);
-       lkb->lkb_dflags = le32_to_cpu(ms->m_flags);
+       dlm_set_dflags_val(lkb, le32_to_cpu(ms->m_flags));
 }
 
 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_dflags = le32_to_cpu(ms->m_flags);
+       dlm_set_dflags_val(lkb, le32_to_cpu(ms->m_flags));
 }
 
 static int receive_extralen(struct dlm_message *ms)
        int error = 0;
 
        /* currently mixing of user/kernel locks are not supported */
-       if (ms->m_flags & cpu_to_le32(DLM_DFL_USER) &&
-           ~lkb->lkb_dflags & DLM_DFL_USER) {
+       if (ms->m_flags & cpu_to_le32(BIT(DLM_DFL_USER_BIT)) &&
+           !test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
                log_error(lkb->lkb_resource->res_ls,
                          "got user dlm message for a kernel lock");
                error = -EINVAL;
        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_dflags = le32_to_cpu(rl->rl_flags);
+       dlm_set_dflags_val(lkb, 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;
        }
 
        /* After ua is attached to lkb it will be freed by dlm_free_lkb().
-          When DLM_DFL_USER is set, the dlm knows that this is a userspace
+          When DLM_DFL_USER_BIT is set, the dlm knows that this is a userspace
           lock and that lkb_astparam is the dlm_user_args structure. */
-       lkb->lkb_dflags |= DLM_DFL_USER;
+       set_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags);
        error = request_lock(ls, lkb, name, namelen, &args);
 
        switch (error) {
 
                lkb = iter;
                list_del_init(&iter->lkb_ownqueue);
-               iter->lkb_dflags &= ~DLM_DFL_ORPHAN;
+               clear_bit(DLM_DFL_ORPHAN_BIT, &iter->lkb_dflags);
                *lkid = iter->lkb_id;
                break;
        }
        list_del_init(&lkb->lkb_ownqueue);
 
        if (lkb->lkb_exflags & DLM_LKF_PERSISTENT)
-               lkb->lkb_dflags |= DLM_DFL_ORPHAN;
+               set_bit(DLM_DFL_ORPHAN_BIT, &lkb->lkb_dflags);
        else
                lkb->lkb_flags |= DLM_IFL_DEAD;
  out:
        int error;
 
        /* we currently can't set a valid user lock */
-       if (lkb_dflags & DLM_DFL_USER)
+       if (lkb_dflags & BIT(DLM_DFL_USER_BIT))
                return -EOPNOTSUPP;
 
        lksb = kzalloc(sizeof(*lksb), GFP_NOFS);
                return error;
        }
 
-       lkb->lkb_dflags = lkb_dflags;
+       dlm_set_dflags_val(lkb, 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_dflags & DLM_DFL_USER)
+       if (~lkb_dflags & BIT(DLM_DFL_USER_BIT))
                lkb->lkb_astparam = (void *)0xDEADBEEF;
 
        error = find_rsb(ls, name, len, 0, R_REQUEST, &r);
 
 
 void dlm_free_lkb(struct dlm_lkb *lkb)
 {
-       if (lkb->lkb_dflags & DLM_DFL_USER) {
+       if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
                struct dlm_user_args *ua;
                ua = lkb->lkb_ua;
                if (ua) {
 
        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_dflags);
+       rl->rl_flags = cpu_to_le32(dlm_dflags_val(lkb));
        rl->rl_lvbseq = cpu_to_le32(lkb->lkb_lvbseq);
        rl->rl_rqmode = lkb->lkb_rqmode;
        rl->rl_grmode = lkb->lkb_grmode;
 
        struct dlm_user_proc *proc;
        int rv;
 
-       if (lkb->lkb_dflags & DLM_DFL_ORPHAN ||
+       if (test_bit(DLM_DFL_ORPHAN_BIT, &lkb->lkb_dflags) ||
            lkb->lkb_flags & DLM_IFL_DEAD)
                return;
 
           for cases where a completion ast is received for an operation that
           began before clear_proc_locks did its cancel/unlock. */
 
-       if (lkb->lkb_dflags & DLM_DFL_ORPHAN ||
+       if (test_bit(DLM_DFL_ORPHAN_BIT, &lkb->lkb_dflags) ||
            lkb->lkb_flags & DLM_IFL_DEAD)
                goto out;
 
 
        { DLM_SBF_ALTMODE,      "ALTMODE" })
 
 #define show_lkb_flags(flags) __print_flags(flags, "|",                \
-       { DLM_DFL_USER,         "USER" },                       \
-       { DLM_DFL_ORPHAN,       "ORPHAN" })
+       { BIT(DLM_DFL_USER_BIT), "USER" },                      \
+       { BIT(DLM_DFL_ORPHAN_BIT), "ORPHAN" })
 
 #define show_header_cmd(cmd) __print_symbolic(cmd,             \
        { DLM_MSG,              "MSG"},                         \