Skip to content

Commit

Permalink
fs: dlm: trace user space callbacks
Browse files Browse the repository at this point in the history
This patch adds trace callbacks for user locks. Unfortenately user locks
are handled in a different way than kernel locks in some cases. User
locks never call the dlm_lock()/dlm_unlock() kernel API and use the next
step internal API of dlm. Adding those traces from user API callers
should make it possible for dlm trace system to see lock handling for
user locks as well.

Signed-off-by: Alexander Aring <[email protected]>
Signed-off-by: David Teigland <[email protected]>
  • Loading branch information
Alexander Aring authored and teigland committed Aug 23, 2022
1 parent 296d9d1 commit 7a3de73
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
24 changes: 20 additions & 4 deletions fs/dlm/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3466,7 +3466,7 @@ int dlm_lock(dlm_lockspace_t *lockspace,
if (error == -EINPROGRESS)
error = 0;
out_put:
trace_dlm_lock_end(ls, lkb, name, namelen, mode, flags, error);
trace_dlm_lock_end(ls, lkb, name, namelen, mode, flags, error, true);

if (convert || error)
__put_lkb(ls, lkb);
Expand Down Expand Up @@ -5842,13 +5842,15 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
goto out;
}

trace_dlm_lock_start(ls, lkb, name, namelen, mode, flags);

if (flags & DLM_LKF_VALBLK) {
ua->lksb.sb_lvbptr = kzalloc(DLM_USER_LVB_LEN, GFP_NOFS);
if (!ua->lksb.sb_lvbptr) {
kfree(ua);
__put_lkb(ls, lkb);
error = -ENOMEM;
goto out;
goto out_trace_end;
}
}
#ifdef CONFIG_DLM_DEPRECATED_API
Expand All @@ -5863,7 +5865,7 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
ua->lksb.sb_lvbptr = NULL;
kfree(ua);
__put_lkb(ls, lkb);
goto out;
goto out_trace_end;
}

/* After ua is attached to lkb it will be freed by dlm_free_lkb().
Expand All @@ -5883,14 +5885,16 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
fallthrough;
default:
__put_lkb(ls, lkb);
goto out;
goto out_trace_end;
}

/* add this new lkb to the per-process list of locks */
spin_lock(&ua->proc->locks_spin);
hold_lkb(lkb);
list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks);
spin_unlock(&ua->proc->locks_spin);
out_trace_end:
trace_dlm_lock_end(ls, lkb, name, namelen, mode, flags, error, false);
out:
dlm_unlock_recovery(ls);
return error;
Expand All @@ -5916,6 +5920,8 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
if (error)
goto out;

trace_dlm_lock_start(ls, lkb, NULL, 0, mode, flags);

/* user can change the params on its lock when it converts it, or
add an lvb that didn't exist before */

Expand Down Expand Up @@ -5953,6 +5959,7 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
if (error == -EINPROGRESS || error == -EAGAIN || error == -EDEADLK)
error = 0;
out_put:
trace_dlm_lock_end(ls, lkb, NULL, 0, mode, flags, error, false);
dlm_put_lkb(lkb);
out:
dlm_unlock_recovery(ls);
Expand Down Expand Up @@ -6045,6 +6052,8 @@ int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
if (error)
goto out;

trace_dlm_unlock_start(ls, lkb, flags);

ua = lkb->lkb_ua;

if (lvb_in && ua->lksb.sb_lvbptr)
Expand Down Expand Up @@ -6073,6 +6082,7 @@ int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
list_move(&lkb->lkb_ownqueue, &ua->proc->unlocking);
spin_unlock(&ua->proc->locks_spin);
out_put:
trace_dlm_unlock_end(ls, lkb, flags, error);
dlm_put_lkb(lkb);
out:
dlm_unlock_recovery(ls);
Expand All @@ -6094,6 +6104,8 @@ int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
if (error)
goto out;

trace_dlm_unlock_start(ls, lkb, flags);

ua = lkb->lkb_ua;
if (ua_tmp->castparam)
ua->castparam = ua_tmp->castparam;
Expand All @@ -6111,6 +6123,7 @@ int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
if (error == -EBUSY)
error = 0;
out_put:
trace_dlm_unlock_end(ls, lkb, flags, error);
dlm_put_lkb(lkb);
out:
dlm_unlock_recovery(ls);
Expand All @@ -6132,6 +6145,8 @@ int dlm_user_deadlock(struct dlm_ls *ls, uint32_t flags, uint32_t lkid)
if (error)
goto out;

trace_dlm_unlock_start(ls, lkb, flags);

ua = lkb->lkb_ua;

error = set_unlock_args(flags, ua, &args);
Expand Down Expand Up @@ -6160,6 +6175,7 @@ int dlm_user_deadlock(struct dlm_ls *ls, uint32_t flags, uint32_t lkid)
if (error == -EBUSY)
error = 0;
out_put:
trace_dlm_unlock_end(ls, lkb, flags, error);
dlm_put_lkb(lkb);
out:
dlm_unlock_recovery(ls);
Expand Down
7 changes: 6 additions & 1 deletion fs/dlm/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <linux/slab.h>
#include <linux/sched/signal.h>

#include <trace/events/dlm.h>

#include "dlm_internal.h"
#include "lockspace.h"
#include "lock.h"
Expand Down Expand Up @@ -882,7 +884,9 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,
goto try_another;
}

if (cb.flags & DLM_CB_CAST) {
if (cb.flags & DLM_CB_BAST) {
trace_dlm_bast(lkb->lkb_resource->res_ls, lkb, cb.mode);
} else if (cb.flags & DLM_CB_CAST) {
new_mode = cb.mode;

if (!cb.sb_status && lkb->lkb_lksb->sb_lvbptr &&
Expand All @@ -891,6 +895,7 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,

lkb->lkb_lksb->sb_status = cb.sb_status;
lkb->lkb_lksb->sb_flags = cb.sb_flags;
trace_dlm_ast(lkb->lkb_resource->res_ls, lkb);
}

rv = copy_result_to_user(lkb->lkb_ua,
Expand Down
22 changes: 12 additions & 10 deletions include/trace/events/dlm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ TRACE_EVENT(dlm_lock_start,
TRACE_EVENT(dlm_lock_end,

TP_PROTO(struct dlm_ls *ls, struct dlm_lkb *lkb, void *name,
unsigned int namelen, int mode, __u32 flags, int error),
unsigned int namelen, int mode, __u32 flags, int error,
bool kernel_lock),

TP_ARGS(ls, lkb, name, namelen, mode, flags, error),
TP_ARGS(ls, lkb, name, namelen, mode, flags, error, kernel_lock),

TP_STRUCT__entry(
__field(__u32, ls_id)
Expand All @@ -113,6 +114,7 @@ TRACE_EVENT(dlm_lock_end,
__entry->lkb_id = lkb->lkb_id;
__entry->mode = mode;
__entry->flags = flags;
__entry->error = error;

r = lkb->lkb_resource;
if (r)
Expand All @@ -122,14 +124,14 @@ TRACE_EVENT(dlm_lock_end,
memcpy(__get_dynamic_array(res_name), name,
__get_dynamic_array_len(res_name));

/* return value will be zeroed in those cases by dlm_lock()
* we do it here again to not introduce more overhead if
* trace isn't running and error reflects the return value.
*/
if (error == -EAGAIN || error == -EDEADLK)
__entry->error = 0;
else
__entry->error = error;
if (kernel_lock) {
/* return value will be zeroed in those cases by dlm_lock()
* we do it here again to not introduce more overhead if
* trace isn't running and error reflects the return value.
*/
if (error == -EAGAIN || error == -EDEADLK)
__entry->error = 0;
}

),

Expand Down

0 comments on commit 7a3de73

Please sign in to comment.