From nobody Sun Apr 19 17:03:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 865F4C43334 for ; Tue, 28 Jun 2022 20:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbiF1Uq2 (ORCPT ); Tue, 28 Jun 2022 16:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbiF1UqV (ORCPT ); Tue, 28 Jun 2022 16:46:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D79CE2A275 for ; Tue, 28 Jun 2022 13:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656449179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UnwOLd+3RtI858ogHbbAwRvYSEQdRCv3KJ1ACMKljA=; b=Bd7KEVq7dBHToUrVcIJKRhjf1WDj3RT0pjyEz0neSfPRzswxap5UKtZyiY/2ADxbmST0He ZWSMcVS4O++D2MK3LgNzrQvLyCde2UPPsYtOggMEIYvC0QF0z+HDUva+Vchg6mykTluAz1 2iUAEllWBPELNceeP3kddvSApghiTlk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-KDy9fWrnP-m8W5GnpFIHkQ-1; Tue, 28 Jun 2022 16:46:14 -0400 X-MC-Unique: KDy9fWrnP-m8W5GnpFIHkQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EABC85A581; Tue, 28 Jun 2022 20:46:14 +0000 (UTC) Received: from max.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EC9540D282F; Tue, 28 Jun 2022 20:46:13 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 1/5] gfs2: Add glockfd debugfs file Date: Tue, 28 Jun 2022 22:46:07 +0200 Message-Id: <20220628204611.651126-2-agruenba@redhat.com> In-Reply-To: <20220628204611.651126-1-agruenba@redhat.com> References: <20220628204611.651126-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a process has a gfs2 file open, the file is keeping a reference on the underlying gfs2 inode, and the inode is keeping the inode's iopen glock hel= d in shared mode. In other words, the process depends on the iopen glock of each open gfs2 file. Expose those dependencies in a new "glockfd" debugfs file. The new debugfs file contains one line for each gfs2 file descriptor, specifying the tgid, file descriptor number, and glock name, e.g., 1601 6 5/816d This list is compiled by iterating all tasks on the system using find_ge_pi= d(), and all file descriptors of each task using task_lookup_next_fd_rcu(). To = make that work from gfs2, export those two functions. Signed-off-by: Andreas Gruenbacher Cc: Eric W. Biederman Cc: cluster-devel@redhat.com Cc: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org --- fs/file.c | 1 + fs/gfs2/glock.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ kernel/pid.c | 1 + 3 files changed, 149 insertions(+) diff --git a/fs/file.c b/fs/file.c index 3bcc1ecc314a..5f9c802a5d8d 100644 --- a/fs/file.c +++ b/fs/file.c @@ -980,6 +980,7 @@ struct file *task_lookup_next_fd_rcu(struct task_struct= *task, unsigned int *ret *ret_fd =3D fd; return file; } +EXPORT_SYMBOL(task_lookup_next_fd_rcu); =20 /* * Lightweight file lookup - no refcnt increment if fd table isn't shared. diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index c992d53013d3..63dbab6fa242 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -33,6 +33,7 @@ #include #include #include +#include =20 #include "gfs2.h" #include "incore.h" @@ -2745,6 +2746,149 @@ static const struct file_operations gfs2_glstats_fo= ps =3D { .release =3D gfs2_glocks_release, }; =20 +struct gfs2_glockfd_iter { + struct super_block *sb; + unsigned int tgid; + struct task_struct *task; + unsigned int fd; + struct file *file; +}; + +static struct task_struct *gfs2_glockfd_next_task(struct gfs2_glockfd_iter= *i) +{ + struct pid_namespace *ns =3D task_active_pid_ns(current); + struct pid *pid; + + if (i->task) + put_task_struct(i->task); + + rcu_read_lock(); +retry: + i->task =3D NULL; + pid =3D find_ge_pid(i->tgid, ns); + if (pid) { + i->tgid =3D pid_nr_ns(pid, ns); + i->task =3D pid_task(pid, PIDTYPE_TGID); + if (!i->task) { + i->tgid++; + goto retry; + } + get_task_struct(i->task); + } + rcu_read_unlock(); + return i->task; +} + +static struct file *gfs2_glockfd_next_file(struct gfs2_glockfd_iter *i) +{ + if (i->file) { + fput(i->file); + i->file =3D NULL; + } + + rcu_read_lock(); + for(;; i->fd++) { + struct inode *inode; + + i->file =3D task_lookup_next_fd_rcu(i->task, &i->fd); + if (!i->file) { + i->fd =3D 0; + break; + } + inode =3D file_inode(i->file); + if (inode->i_sb !=3D i->sb) + continue; + if (get_file_rcu(i->file)) + break; + } + rcu_read_unlock(); + return i->file; +} + +static void *gfs2_glockfd_seq_start(struct seq_file *seq, loff_t *pos) +{ + struct gfs2_glockfd_iter *i =3D seq->private; + + if (*pos) + return NULL; + while (gfs2_glockfd_next_task(i)) { + if (gfs2_glockfd_next_file(i)) + return i; + i->tgid++; + } + return NULL; +} + +static void *gfs2_glockfd_seq_next(struct seq_file *seq, void *iter_ptr, + loff_t *pos) +{ + struct gfs2_glockfd_iter *i =3D seq->private; + + (*pos)++; + i->fd++; + do { + if (gfs2_glockfd_next_file(i)) + return i; + i->tgid++; + } while (gfs2_glockfd_next_task(i)); + return NULL; +} + +static void gfs2_glockfd_seq_stop(struct seq_file *seq, void *iter_ptr) +{ + struct gfs2_glockfd_iter *i =3D seq->private; + + if (i->file) + fput(i->file); + if (i->task) + put_task_struct(i->task); +} + +static int gfs2_glockfd_seq_show(struct seq_file *seq, void *iter_ptr) +{ + struct gfs2_glockfd_iter *i =3D seq->private; + struct inode *inode =3D file_inode(i->file); + struct gfs2_glock *gl; + + inode_lock_shared(inode); + gl =3D GFS2_I(inode)->i_iopen_gh.gh_gl; + if (gl) { + seq_printf(seq, "%d %u %u/%llx\n", + i->tgid, i->fd, gl->gl_name.ln_type, + (unsigned long long)gl->gl_name.ln_number); + } + inode_unlock_shared(inode); + return 0; +} + +static const struct seq_operations gfs2_glockfd_seq_ops =3D { + .start =3D gfs2_glockfd_seq_start, + .next =3D gfs2_glockfd_seq_next, + .stop =3D gfs2_glockfd_seq_stop, + .show =3D gfs2_glockfd_seq_show, +}; + +static int gfs2_glockfd_open(struct inode *inode, struct file *file) +{ + struct gfs2_glockfd_iter *i; + struct gfs2_sbd *sdp =3D inode->i_private; + + i =3D __seq_open_private(file, &gfs2_glockfd_seq_ops, + sizeof(struct gfs2_glockfd_iter)); + if (!i) + return -ENOMEM; + i->sb =3D sdp->sd_vfs; + return 0; +} + +static const struct file_operations gfs2_glockfd_fops =3D { + .owner =3D THIS_MODULE, + .open =3D gfs2_glockfd_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D seq_release_private, +}; + DEFINE_SEQ_ATTRIBUTE(gfs2_sbstats); =20 void gfs2_create_debugfs_file(struct gfs2_sbd *sdp) @@ -2754,6 +2898,9 @@ void gfs2_create_debugfs_file(struct gfs2_sbd *sdp) debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, &gfs2_glocks_fops); =20 + debugfs_create_file("glockfd", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, + &gfs2_glockfd_fops); + debugfs_create_file("glstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, &gfs2_glstats_fops); =20 diff --git a/kernel/pid.c b/kernel/pid.c index 2fc0a16ec77b..3fbc5e46b721 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -519,6 +519,7 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *n= s) { return idr_get_next(&ns->idr, &nr); } +EXPORT_SYMBOL_GPL(find_ge_pid); =20 struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) { --=20 2.35.1 From nobody Sun Apr 19 17:03:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1311C43334 for ; Tue, 28 Jun 2022 20:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbiF1UqZ (ORCPT ); Tue, 28 Jun 2022 16:46:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbiF1UqT (ORCPT ); Tue, 28 Jun 2022 16:46:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4FACC2A279 for ; Tue, 28 Jun 2022 13:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656449177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UJ28lpHMxANwjsFwVo8SWCUkkqxHqZ8kRWKJwGe1CCM=; b=ZlE1+ELDm6RNcVtguvltC3Ngg6Sc9GOLwi+d5KzMihzGgIzbLo0haTKNtJwbo3HpatQxNF lWCoTZUgRV2ZSBi11nupiB/JXKrsh4QUWJTIeetDBJkK6b5SUFa+ydfzOM+zzNOTQpNgu5 W1dlYb+nyL2hHQayvE6R8UP4YcFDKX8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-xDX8Q9XTOxSiFDluEQg8EA-1; Tue, 28 Jun 2022 16:46:16 -0400 X-MC-Unique: xDX8Q9XTOxSiFDluEQg8EA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACC54398CA67; Tue, 28 Jun 2022 20:46:15 +0000 (UTC) Received: from max.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE9B440C1240; Tue, 28 Jun 2022 20:46:14 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 2/5] gfs2: Add flocks to glockfd debugfs file Date: Tue, 28 Jun 2022 22:46:08 +0200 Message-Id: <20220628204611.651126-3-agruenba@redhat.com> In-Reply-To: <20220628204611.651126-1-agruenba@redhat.com> References: <20220628204611.651126-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Include flock glocks in the "glockfd" debugfs file. Those are similar to t= he iopen glocks; while an open file is holding an flock, it is holding the fil= e's flock glock. We cannot take f_fl_mutex in gfs2_glockfd_seq_show_flock() or else dumping = the "glockfd" file would block on flock operations. Instead, use the file->f_l= ock spin lock to protect the f_fl_gh.gh_gl glock pointer. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/file.c | 22 ++++++++++++++++++++-- fs/gfs2/glock.c | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 2cceb193dcd8..25f4080bc973 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1444,6 +1444,22 @@ static int gfs2_lock(struct file *file, int cmd, str= uct file_lock *fl) return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl); } =20 +static void __flock_holder_uninit(struct file *file, struct gfs2_holder *f= l_gh) +{ + struct gfs2_glock *gl =3D fl_gh->gh_gl; + + /* + * Make sure gfs2_glock_put() won't sleep under the file->f_lock + * spinlock. + */ + + gfs2_glock_hold(gl); + spin_lock(&file->f_lock); + gfs2_holder_uninit(fl_gh); + spin_unlock(&file->f_lock); + gfs2_glock_put(gl); +} + static int do_flock(struct file *file, int cmd, struct file_lock *fl) { struct gfs2_file *fp =3D file->private_data; @@ -1475,7 +1491,9 @@ static int do_flock(struct file *file, int cmd, struc= t file_lock *fl) &gfs2_flock_glops, CREATE, &gl); if (error) goto out; + spin_lock(&file->f_lock); gfs2_holder_init(gl, state, flags, fl_gh); + spin_unlock(&file->f_lock); gfs2_glock_put(gl); } for (sleeptime =3D 1; sleeptime <=3D 4; sleeptime <<=3D 1) { @@ -1486,7 +1504,7 @@ static int do_flock(struct file *file, int cmd, struc= t file_lock *fl) msleep(sleeptime); } if (error) { - gfs2_holder_uninit(fl_gh); + __flock_holder_uninit(file, fl_gh); if (error =3D=3D GLR_TRYFAILED) error =3D -EAGAIN; } else { @@ -1508,7 +1526,7 @@ static void do_unflock(struct file *file, struct file= _lock *fl) locks_lock_file_wait(file, fl); if (gfs2_holder_initialized(fl_gh)) { gfs2_glock_dq(fl_gh); - gfs2_holder_uninit(fl_gh); + __flock_holder_uninit(file, fl_gh); } mutex_unlock(&fp->f_fl_mutex); } diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 63dbab6fa242..aa35f5d4eb54 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2844,6 +2844,28 @@ static void gfs2_glockfd_seq_stop(struct seq_file *s= eq, void *iter_ptr) put_task_struct(i->task); } =20 +static void gfs2_glockfd_seq_show_flock(struct seq_file *seq, + struct gfs2_glockfd_iter *i) +{ + struct gfs2_file *fp =3D i->file->private_data; + struct gfs2_holder *fl_gh =3D &fp->f_fl_gh; + struct lm_lockname gl_name =3D { .ln_type =3D LM_TYPE_RESERVED }; + + if (!READ_ONCE(fl_gh->gh_gl)) + return; + + spin_lock(&i->file->f_lock); + if (gfs2_holder_initialized(fl_gh)) + gl_name =3D fl_gh->gh_gl->gl_name; + spin_unlock(&i->file->f_lock); + + if (gl_name.ln_type !=3D LM_TYPE_RESERVED) { + seq_printf(seq, "%d %u %u/%llx\n", + i->tgid, i->fd, gl_name.ln_type, + (unsigned long long)gl_name.ln_number); + } +} + static int gfs2_glockfd_seq_show(struct seq_file *seq, void *iter_ptr) { struct gfs2_glockfd_iter *i =3D seq->private; @@ -2857,6 +2879,7 @@ static int gfs2_glockfd_seq_show(struct seq_file *seq= , void *iter_ptr) i->tgid, i->fd, gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); } + gfs2_glockfd_seq_show_flock(seq, i); inode_unlock_shared(inode); return 0; } --=20 2.35.1 From nobody Sun Apr 19 17:03:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CBB6C433EF for ; Tue, 28 Jun 2022 20:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbiF1Uqc (ORCPT ); Tue, 28 Jun 2022 16:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbiF1UqW (ORCPT ); Tue, 28 Jun 2022 16:46:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4D4942A423 for ; Tue, 28 Jun 2022 13:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656449180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=etd/HiWPRFylPp9B1UP6EMuDHvBVBKKMEBDyPqA1sCk=; b=aLACLbjOYVIwb1WKD/PZKpEyzi1F1vsW4B3wBinAs6PCmj21O/CFMmG9sugHfg+V4ibx6W tcatHRTVLxEV3JCCi957Hw6+g/UGd9iksGVoiR4bvLr/Mxm8Pt1e2Tk8rhXZ+gfaznkolj dhWCkKquJn9EZlMZbYxQoXlTuomzC8o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-448-6--e8s4GMk2NY6qk63AJOQ-1; Tue, 28 Jun 2022 16:46:17 -0400 X-MC-Unique: 6--e8s4GMk2NY6qk63AJOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB886294EDD1; Tue, 28 Jun 2022 20:46:16 +0000 (UTC) Received: from max.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDB88404E4C8; Tue, 28 Jun 2022 20:46:15 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 3/5] gfs2: Add GL_NOPID flag for process-independent glock holders Date: Tue, 28 Jun 2022 22:46:09 +0200 Message-Id: <20220628204611.651126-4-agruenba@redhat.com> In-Reply-To: <20220628204611.651126-1-agruenba@redhat.com> References: <20220628204611.651126-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a GL_NOPID flag to indicate that once a glock holder has been acquired,= it won't be associated with the current process anymore. This is useful for i= open and flock glocks which are associated with open files, as well as journal g= lock holders and similar which are associated with the filesystem. Once GL_NOPID is used for all applicable glocks (see the next patches), processes will no longer be falsely reported as holding glocks which they a= re not actually holding in the glocks dump file. Unlike before, when a proces= s is reported as having "(ended)", this will indicate an actual bug. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/glock.c | 41 +++++++++++++++++++++++++++++++---------- fs/gfs2/glock.h | 1 + 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index aa35f5d4eb54..480b3d2b00e8 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1465,6 +1465,15 @@ void gfs2_print_dbg(struct seq_file *seq, const char= *fmt, ...) va_end(args); } =20 +static inline bool pid_is_meaningful(const struct gfs2_holder *gh) +{ + if (!(gh->gh_flags & GL_NOPID)) + return true; + if (gh->gh_state =3D=3D LM_ST_UNLOCKED) + return true; + return false; +} + /** * add_to_queue - Add a holder to the wait queue (but look for recursion) * @gh: the holder structure to add @@ -1501,10 +1510,17 @@ __acquires(&gl->gl_lockref.lock) } =20 list_for_each_entry(gh2, &gl->gl_holders, gh_list) { - if (unlikely(gh2->gh_owner_pid =3D=3D gh->gh_owner_pid && - (gh->gh_gl->gl_ops->go_type !=3D LM_TYPE_FLOCK) && - !test_bit(HIF_MAY_DEMOTE, &gh2->gh_iflags))) - goto trap_recursive; + if (likely(gh2->gh_owner_pid !=3D gh->gh_owner_pid)) + continue; + if (gh->gh_gl->gl_ops->go_type =3D=3D LM_TYPE_FLOCK) + continue; + if (test_bit(HIF_MAY_DEMOTE, &gh2->gh_iflags)) + continue; + if (!pid_is_meaningful(gh2)) + continue; + goto trap_recursive; + } + list_for_each_entry(gh2, &gl->gl_holders, gh_list) { if (try_futile && !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { fail: @@ -2319,19 +2335,24 @@ static const char *hflags2str(char *buf, u16 flags,= unsigned long iflags) static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh, const char *fs_id_buf) { - struct task_struct *gh_owner =3D NULL; + const char *comm =3D "(none)"; + pid_t owner_pid =3D 0; char flags_buf[32]; =20 rcu_read_lock(); - if (gh->gh_owner_pid) + if (pid_is_meaningful(gh)) { + struct task_struct *gh_owner; + + comm =3D "(ended)"; + owner_pid =3D pid_nr(gh->gh_owner_pid); gh_owner =3D pid_task(gh->gh_owner_pid, PIDTYPE_PID); + if (gh_owner) + comm =3D gh_owner->comm; + } gfs2_print_dbg(seq, "%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n", fs_id_buf, state2str(gh->gh_state), hflags2str(flags_buf, gh->gh_flags, gh->gh_iflags), - gh->gh_error, - gh->gh_owner_pid ? (long)pid_nr(gh->gh_owner_pid) : -1, - gh_owner ? gh_owner->comm : "(ended)", - (void *)gh->gh_ip); + gh->gh_error, (long)owner_pid, comm, (void *)gh->gh_ip); rcu_read_unlock(); } =20 diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index c0ae9100a0bc..e764ebeba54c 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -91,6 +91,7 @@ enum { #define GL_ASYNC 0x0040 #define GL_EXACT 0x0080 #define GL_SKIP 0x0100 +#define GL_NOPID 0x0200 #define GL_NOCACHE 0x0400 =20 /* --=20 2.35.1 From nobody Sun Apr 19 17:03:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AEA1C43334 for ; Tue, 28 Jun 2022 20:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbiF1Uqg (ORCPT ); Tue, 28 Jun 2022 16:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbiF1UqY (ORCPT ); Tue, 28 Jun 2022 16:46:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 339B82A407 for ; Tue, 28 Jun 2022 13:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656449182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BcsVY1OPkKZ0bSTMBzDtRfeW2FEqJiWVDTUaBARc3oQ=; b=WkStoH8KHN6GhFKNbHxgqiKdOq5QVrzp0EvXiToqvU7ViaNjFrNppf+zLeIjPYXkyFLvr1 QPgMRci2jShir5mDM9nDdCAnLFvgzG4PfqJ2flC+d85b2KBq+PZjkNPvg9Qk3i6O99eBZs J0hYF8hC8MsNDTJ+/+HpXn8LwCaxOt4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-if9X01vlPC-sowPfu-fSog-1; Tue, 28 Jun 2022 16:46:18 -0400 X-MC-Unique: if9X01vlPC-sowPfu-fSog-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17AAD1C0896B; Tue, 28 Jun 2022 20:46:18 +0000 (UTC) Received: from max.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2721D4050C4A; Tue, 28 Jun 2022 20:46:17 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 4/5] gfs2: Mark flock glock holders as GL_NOPID Date: Tue, 28 Jun 2022 22:46:10 +0200 Message-Id: <20220628204611.651126-5-agruenba@redhat.com> In-Reply-To: <20220628204611.651126-1-agruenba@redhat.com> References: <20220628204611.651126-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add the GL_NOPID flag for flock glock holders. Clean up the flag setting code in do_flock. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 25f4080bc973..1383f9598011 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1472,7 +1472,9 @@ static int do_flock(struct file *file, int cmd, struc= t file_lock *fl) int sleeptime; =20 state =3D (fl->fl_type =3D=3D F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; - flags =3D (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY_1CB) | GL_EXACT; + flags =3D GL_EXACT | GL_NOPID; + if (!IS_SETLKW(cmd)) + flags |=3D LM_FLAG_TRY_1CB; =20 mutex_lock(&fp->f_fl_mutex); =20 @@ -1500,7 +1502,8 @@ static int do_flock(struct file *file, int cmd, struc= t file_lock *fl) error =3D gfs2_glock_nq(fl_gh); if (error !=3D GLR_TRYFAILED) break; - fl_gh->gh_flags =3D LM_FLAG_TRY | GL_EXACT; + fl_gh->gh_flags &=3D ~LM_FLAG_TRY_1CB; + fl_gh->gh_flags |=3D LM_FLAG_TRY; msleep(sleeptime); } if (error) { --=20 2.35.1 From nobody Sun Apr 19 17:03:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5586DC433EF for ; Tue, 28 Jun 2022 20:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231448AbiF1Uqi (ORCPT ); Tue, 28 Jun 2022 16:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbiF1UqZ (ORCPT ); Tue, 28 Jun 2022 16:46:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE2BA26540 for ; Tue, 28 Jun 2022 13:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656449183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AxAXLtt/qHvFpa3MozdupVmWHjm0h9gbo/SJ35DEqEU=; b=AkvC6jv+M37tgpOP65vZH4/4cdLNg3KsGNIqLJpZKcQovLqmu6XRqAL/E+xQzzBvPA/mZ4 WkULmqeik0ZydXo40p3c0Rymj/7SuMfvC45W7gNwaXVWxaSQ2emh8NXYpuwYLNujyBovb7 VXso10Bg1jB0eHpYgmo+Jb51vbLycgs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-Jj1d7vLEMh2BLGWcJF-AOw-1; Tue, 28 Jun 2022 16:46:20 -0400 X-MC-Unique: Jj1d7vLEMh2BLGWcJF-AOw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E737818A6584; Tue, 28 Jun 2022 20:46:19 +0000 (UTC) Received: from max.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0026C40D282F; Tue, 28 Jun 2022 20:46:18 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com Cc: Andreas Gruenbacher , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 5/5] gfs2: Mark the remaining process-independent glock holders as GL_NOPID Date: Tue, 28 Jun 2022 22:46:11 +0200 Message-Id: <20220628204611.651126-6-agruenba@redhat.com> In-Reply-To: <20220628204611.651126-1-agruenba@redhat.com> References: <20220628204611.651126-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add the GL_NOPID flag for the remaining glock holders which are not associated with the current process. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/inode.c | 6 ++++-- fs/gfs2/ops_fstype.c | 14 ++++++++------ fs/gfs2/super.c | 3 ++- fs/gfs2/util.c | 6 ++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index c8ec876f33ea..e211ed8636b5 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -143,7 +143,8 @@ struct inode *gfs2_inode_lookup(struct super_block *sb,= unsigned int type, =20 if (blktype !=3D GFS2_BLKST_UNLINKED) gfs2_cancel_delete_work(io_gl); - error =3D gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, + error =3D gfs2_glock_nq_init(io_gl, LM_ST_SHARED, + GL_EXACT | GL_NOPID, &ip->i_iopen_gh); gfs2_glock_put(io_gl); if (unlikely(error)) @@ -720,7 +721,8 @@ static int gfs2_create_inode(struct inode *dir, struct = dentry *dentry, error =3D insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no= _addr); BUG_ON(error); =20 - error =3D gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_= gh); + error =3D gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT | GL_NOPID, + &ip->i_iopen_gh); if (error) goto fail_gunlock2; =20 diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c9b423c874a3..904a2d47c4b3 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -403,7 +403,8 @@ static int init_locking(struct gfs2_sbd *sdp, struct gf= s2_holder *mount_gh, =20 error =3D gfs2_glock_nq_num(sdp, GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, - LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, + LM_ST_EXCLUSIVE, + LM_FLAG_NOEXP | GL_NOCACHE | GL_NOPID, mount_gh); if (error) { fs_err(sdp, "can't acquire mount glock: %d\n", error); @@ -413,7 +414,7 @@ static int init_locking(struct gfs2_sbd *sdp, struct gf= s2_holder *mount_gh, error =3D gfs2_glock_nq_num(sdp, GFS2_LIVE_LOCK, &gfs2_nondisk_glops, LM_ST_SHARED, - LM_FLAG_NOEXP | GL_EXACT, + LM_FLAG_NOEXP | GL_EXACT | GL_NOPID, &sdp->sd_live_gh); if (error) { fs_err(sdp, "can't acquire live glock: %d\n", error); @@ -689,7 +690,7 @@ static int init_statfs(struct gfs2_sbd *sdp) iput(pn); pn =3D NULL; ip =3D GFS2_I(sdp->sd_sc_inode); - error =3D gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, + error =3D gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NOPID, &sdp->sd_sc_gh); if (error) { fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); @@ -778,7 +779,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) error =3D gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, &gfs2_journal_glops, LM_ST_EXCLUSIVE, - LM_FLAG_NOEXP | GL_NOCACHE, + LM_FLAG_NOEXP | GL_NOCACHE | GL_NOPID, &sdp->sd_journal_gh); if (error) { fs_err(sdp, "can't acquire journal glock: %d\n", error); @@ -788,7 +789,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) ip =3D GFS2_I(sdp->sd_jdesc->jd_inode); sdp->sd_jinode_gl =3D ip->i_gl; error =3D gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, - LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, + LM_FLAG_NOEXP | GL_EXACT | + GL_NOCACHE | GL_NOPID, &sdp->sd_jinode_gh); if (error) { fs_err(sdp, "can't acquire journal inode glock: %d\n", @@ -959,7 +961,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) pn =3D NULL; =20 ip =3D GFS2_I(sdp->sd_qc_inode); - error =3D gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, + error =3D gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NOPID, &sdp->sd_qc_gh); if (error) { fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index bdb773e5c88f..90db4a289269 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -346,7 +346,8 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sd= p) } =20 error =3D gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_EXCLUSIVE, - LM_FLAG_NOEXP, &sdp->sd_freeze_gh); + LM_FLAG_NOEXP | GL_NOPID, + &sdp->sd_freeze_gh); if (error) goto out; =20 diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 8241029a2a5d..95d733dd3c25 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -226,7 +226,8 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp) */ fs_warn(sdp, "Requesting recovery of jid %d.\n", sdp->sd_lockstruct.ls_jid); - gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | LM_FLAG_NOEXP, + gfs2_holder_reinit(LM_ST_EXCLUSIVE, + LM_FLAG_TRY_1CB | LM_FLAG_NOEXP | GL_NOPID, &sdp->sd_live_gh); msleep(GL_GLOCK_MAX_HOLD); /* @@ -251,7 +252,8 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp) fs_warn(sdp, "Unable to recover our journal jid %d.\n", sdp->sd_lockstruct.ls_jid); gfs2_glock_dq_wait(&sdp->sd_live_gh); - gfs2_holder_reinit(LM_ST_SHARED, LM_FLAG_NOEXP | GL_EXACT, + gfs2_holder_reinit(LM_ST_SHARED, + LM_FLAG_NOEXP | GL_EXACT | GL_NOPID, &sdp->sd_live_gh); gfs2_glock_nq(&sdp->sd_live_gh); } --=20 2.35.1