From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46B6CC433DB for ; Sun, 21 Feb 2021 20:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ED086024A for ; Sun, 21 Feb 2021 20:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbhBUULM (ORCPT ); Sun, 21 Feb 2021 15:11:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbhBUULF (ORCPT ); Sun, 21 Feb 2021 15:11:05 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64EFEC06178B; Sun, 21 Feb 2021 12:10:25 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id 07C0028E5; Sun, 21 Feb 2021 15:10:24 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 07C0028E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1613938224; bh=7ZYHvlz2PyOH+1LBos+UH4lABWNPQ4hE/eJx23H2AVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kdABrIaGwL/eI3jBD++XWajauPoawwiH8JbrZft3T7k7FePF3rPxit/zoYPW4uf2h YuMiE/3N0vVZ8FPaSCS8oeetn9bXRnhBEMjIXkzteBypIY/tCbsG6nT9guQeyZ1/08 m987d5kdmNjfkDNQmrWTE6pBJmPrPkZP+RGSrQpQ= Date: Sun, 21 Feb 2021 15:10:24 -0500 From: "J. Bruce Fields" To: Jeff Layton Cc: Al Viro , Luo Longjun , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, sangyan@huawei.com, luchunhua@huawei.com Subject: Re: [PATCH] fs/locks: print full locks information Message-ID: <20210221201024.GB15975@fieldses.org> References: <20210220063250.742164-1-luolongjun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 21, 2021 at 01:43:03PM -0500, Jeff Layton wrote: > On Sun, 2021-02-21 at 16:52 +0000, Al Viro wrote: > > On Sat, Feb 20, 2021 at 01:32:50AM -0500, Luo Longjun wrote: > > > + list_for_each_entry(bfl, &fl->fl_blocked_requests, fl_blocked_member) > > > + __locks_show(f, bfl, level + 1); > > > > Er... What's the maximal depth, again? Kernel stack is very much finite... > > Ooof, good point. I don't think there is a maximal depth on the tree > itself. If you do want to do something like this, then you'd need to > impose a hard limit on the recursion somehow. I think all you need to do is something like: follow the first entry of fl_blocked_requests, printing as you go, until you get down to lock with empty fl_blocked_requests (a leaf of the tree). When you get to a leaf, print, then follow fl_blocker back up and look for your parent's next sibling on its fl_blocked_requests list. If there are no more siblings, continue up to your grandparent, etc. It's the traverse-a-maze-by-always-turning-left algorithm applied to a tree. I think we do it elsewhere in the VFS. You also need an integer that keeps track of your current indent depth. But you don't need a stack. ? --b.