From patchwork Fri Jan 8 13:50:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7986251 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A01FBBEEE5 for ; Fri, 8 Jan 2016 14:06:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B462201CE for ; Fri, 8 Jan 2016 14:06:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 740F22017E for ; Fri, 8 Jan 2016 14:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755310AbcAHOGJ (ORCPT ); Fri, 8 Jan 2016 09:06:09 -0500 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36368 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754228AbcAHOGH (ORCPT ); Fri, 8 Jan 2016 09:06:07 -0500 Received: by mail-qk0-f194.google.com with SMTP id e124so5705390qkc.3 for ; Fri, 08 Jan 2016 06:06:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poochiereds-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zziBiVsgxe/rj2GYUYOqWoK7u7xkCTDhoupMstopXVA=; b=pS5VE3gTXZIcRUHdFnZzErd6tVdX1cuSax522Wqk0AHhsn1BxFgEJ9xa2BHAYvDuCE tOxGiDilv4EGFy0EQBx9HhFDq4xEnR2Q8nWrxf97K31JK20ny2tRXHZCNGLo5AiJjkqA wDt8qsUIHuEPUnxxECF8lDtL1YVbh1qN0F29Te2e5Vx5X/LlDEoJOyDwEAZkE9U9l+Hu w3PnvtgXD8PlhwnuSkMdEy2WpnC3sBAQifE3No05II6FzX0qY6AZ3Qqnt06KrqMfD4lL ovlvPs0p6cL0p6RyYxubzkl0qGbetLeSAt0Wc4jusFq4Q4cQplFxVMB7KpnfHuIjIjc+ 36dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zziBiVsgxe/rj2GYUYOqWoK7u7xkCTDhoupMstopXVA=; b=l+O2XZ6pqI8Uv9t8TZXF/MuhyLGRiN6ozg7mrR0Ez+VaDAS1S676XlbQvLcU9icfJB jo7iX8Wiy9RO4SdNRHLQgRysNkyZnlVjg1WWAUwYRIVlfL9lsYdnRcNjFll6pugZoyPc iyTCXgMfVfpW1/y/jqZ8fQyDPoz59kGwYTGHUkPadYD3IgN6Zc1axUFq4s/71UxgxUK0 KCI55JE9+D7TCqxJyCbrTQJHHvV5O61L795/hvzScsxh9JO2HkR2QZu1C4DtQHALECLS QTQXFOL8Ttuyipx9juklTcAuF6TLc1/g0gX0zQfKj1sjv3Kh8ldCOxFQzDd8n7Y/UHaw xHHg== X-Gm-Message-State: ALoCoQkpT2q4xTBYOzyKK3rAfb+5ceUcIKifYHsZI14FptgSfDRgJqMjv4MLhhaZDhK9we1DxxO6XSst/6+1GKqkreMQleoYaQ== X-Received: by 10.55.77.148 with SMTP id a142mr142776564qkb.44.1452261026529; Fri, 08 Jan 2016 05:50:26 -0800 (PST) Received: from tlielax.poochiereds.net ([2606:a000:1125:4075::d5a]) by smtp.googlemail.com with ESMTPSA id d188sm45848800qkb.9.2016.01.08.05.50.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jan 2016 05:50:25 -0800 (PST) From: Jeff Layton X-Google-Original-From: Jeff Layton To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , "J. Bruce Fields" , Alexander Viro , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin , Eric Dumazet Subject: [PATCH v2 3/6] locks: sprinkle some tracepoints around the file locking code Date: Fri, 8 Jan 2016 08:50:11 -0500 Message-Id: <1452261014-1682-4-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452261014-1682-1-git-send-email-jeff.layton@primarydata.com> References: <1452219742-18507-1-git-send-email-jeff.layton@primarydata.com> <1452261014-1682-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add some tracepoints around the POSIX locking code. These were useful when tracking down problems when handling the race between setlk and close. Signed-off-by: Jeff Layton --- fs/locks.c | 12 +++++-- include/trace/events/filelock.h | 77 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index e72077d5a664..0af2387bd91e 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -229,6 +229,7 @@ locks_get_lock_context(struct inode *inode, int type) ctx = smp_load_acquire(&inode->i_flctx); } out: + trace_locks_get_lock_context(inode, type, ctx); return ctx; } @@ -1141,6 +1142,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str if (new_fl2) locks_free_lock(new_fl2); locks_dispose_list(&dispose); + trace_posix_lock_inode(inode, request, error); + return error; } @@ -2164,6 +2167,8 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, if (file_lock == NULL) return -ENOLCK; + inode = file_inode(filp); + /* * This might block, so we do it before checking the inode. */ @@ -2171,8 +2176,6 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, if (copy_from_user(&flock, l, sizeof(flock))) goto out; - inode = file_inode(filp); - /* Don't allow mandatory locks on files that may be memory mapped * and shared. */ @@ -2241,6 +2244,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, } } out: + trace_fcntl_setlk(inode, file_lock, error); locks_free_lock(file_lock); return error; } @@ -2397,6 +2401,7 @@ out: */ void locks_remove_posix(struct file *filp, fl_owner_t owner) { + int error; struct file_lock lock; struct file_lock_context *ctx; @@ -2419,10 +2424,11 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) lock.fl_ops = NULL; lock.fl_lmops = NULL; - vfs_lock_file(filp, F_SETLK, &lock, NULL); + error = vfs_lock_file(filp, F_SETLK, &lock, NULL); if (lock.fl_ops && lock.fl_ops->fl_release_private) lock.fl_ops->fl_release_private(&lock); + trace_locks_remove_posix(file_inode(filp), &lock, error); } EXPORT_SYMBOL(locks_remove_posix); diff --git a/include/trace/events/filelock.h b/include/trace/events/filelock.h index c72f2dc01d0b..63a7680347cb 100644 --- a/include/trace/events/filelock.h +++ b/include/trace/events/filelock.h @@ -34,6 +34,83 @@ { F_WRLCK, "F_WRLCK" }, \ { F_UNLCK, "F_UNLCK" }) +TRACE_EVENT(locks_get_lock_context, + TP_PROTO(struct inode *inode, int type, struct file_lock_context *ctx), + + TP_ARGS(inode, type, ctx), + + TP_STRUCT__entry( + __field(unsigned long, i_ino) + __field(dev_t, s_dev) + __field(unsigned char, type) + __field(struct file_lock_context *, ctx) + ), + + TP_fast_assign( + __entry->s_dev = inode->i_sb->s_dev; + __entry->i_ino = inode->i_ino; + __entry->type = type; + __entry->ctx = ctx; + ), + + TP_printk("dev=0x%x:0x%x ino=0x%lx type=%s ctx=%p", + MAJOR(__entry->s_dev), MINOR(__entry->s_dev), + __entry->i_ino, show_fl_type(__entry->type), __entry->ctx) +); + +DECLARE_EVENT_CLASS(filelock_lock, + TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), + + TP_ARGS(inode, fl, ret), + + TP_STRUCT__entry( + __field(struct file_lock *, fl) + __field(unsigned long, i_ino) + __field(dev_t, s_dev) + __field(struct file_lock *, fl_next) + __field(fl_owner_t, fl_owner) + __field(unsigned int, fl_pid) + __field(unsigned int, fl_flags) + __field(unsigned char, fl_type) + __field(loff_t, fl_start) + __field(loff_t, fl_end) + __field(int, ret) + ), + + TP_fast_assign( + __entry->fl = fl ? fl : NULL; + __entry->s_dev = inode->i_sb->s_dev; + __entry->i_ino = inode->i_ino; + __entry->fl_next = fl ? fl->fl_next : NULL; + __entry->fl_owner = fl ? fl->fl_owner : NULL; + __entry->fl_pid = fl ? fl->fl_pid : 0; + __entry->fl_flags = fl ? fl->fl_flags : 0; + __entry->fl_type = fl ? fl->fl_type : 0; + __entry->fl_start = fl ? fl->fl_start : 0; + __entry->fl_end = fl ? fl->fl_end : 0; + __entry->ret = ret; + ), + + TP_printk("fl=0x%p dev=0x%x:0x%x ino=0x%lx fl_next=0x%p fl_owner=0x%p fl_pid=%u fl_flags=%s fl_type=%s fl_start=%lld fl_end=%lld ret=%d", + __entry->fl, MAJOR(__entry->s_dev), MINOR(__entry->s_dev), + __entry->i_ino, __entry->fl_next, __entry->fl_owner, + __entry->fl_pid, show_fl_flags(__entry->fl_flags), + show_fl_type(__entry->fl_type), + __entry->fl_start, __entry->fl_end, __entry->ret) +); + +DEFINE_EVENT(filelock_lock, posix_lock_inode, + TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), + TP_ARGS(inode, fl, ret)); + +DEFINE_EVENT(filelock_lock, fcntl_setlk, + TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), + TP_ARGS(inode, fl, ret)); + +DEFINE_EVENT(filelock_lock, locks_remove_posix, + TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), + TP_ARGS(inode, fl, ret)); + DECLARE_EVENT_CLASS(filelock_lease, TP_PROTO(struct inode *inode, struct file_lock *fl),