Created
July 15, 2023 12:17
-
-
Save stbuehler/b5ebba1b92a95b1bd324e22e4e241b56 to your computer and use it in GitHub Desktop.
debug fcntl F_SETLK[W] with bpftrace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fcntl.h> | |
/* Usage example: bpftrace fcntl_setlk.bt podman */ | |
kretfunc:vmlinux:fcntl_setlk / $# == 0 || comm == str($1) / { | |
if (args->flock->l_type == F_UNLCK) { | |
delete(@pending_locks[pid, args->filp]) | |
} else if (retval == 0) { | |
@pending_locks[pid, args->filp] = 1 | |
} | |
printf( | |
"[%d]* comm=%s l_type=%s fd=%-3d file=016x%lx dev=%u:%u ino=%lu [%u:%ld, len=%ld] -> %d: %s\n", | |
pid, | |
comm, | |
args->flock->l_type == F_WRLCK ? "F_WRLCK" : args->flock->l_type == F_UNLCK ? "F_UNLCK" : "F_RDLCK", | |
args->fd, | |
args->filp, | |
args->filp->f_inode->i_sb->s_dev >> 20, ((uint32) (args->filp->f_inode->i_sb->s_dev << 12)) >> 12, | |
args->filp->f_inode->i_ino, | |
args->flock->l_whence, args->flock->l_start, args->flock->l_len, | |
retval, | |
str(args->filp->f_path.dentry->d_name.name) | |
/* path(args->filp->f_path) - not allowed? */ | |
); | |
} | |
kfunc:vmlinux:locks_remove_posix / args->filp->f_inode->i_flctx != 0 && ($# == 0 || comm == str($1)) / { | |
if (@pending_locks[pid, args->filp] == 1) { | |
delete(@pending_locks[pid, args->filp]); | |
printf( | |
"[%d]* comm=%s locks_remove_posix file=016x%lx dev=%u:%u ino=%lu: %s\n", | |
pid, | |
comm, | |
args->filp, | |
args->filp->f_inode->i_sb->s_dev >> 20, ((uint32) (args->filp->f_inode->i_sb->s_dev << 12)) >> 12, | |
args->filp->f_inode->i_ino, | |
str(args->filp->f_path.dentry->d_name.name) | |
); | |
} | |
} | |
END { | |
clear(@pending_locks); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment