Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1595108pxb; Thu, 4 Feb 2021 18:01:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwH0zVt+UtQ/id5+AL6UAuM2zh5nJ6N4NFMgctACX3aC9kK8ELy2d9pp8zro+k9/pAQN3Ca X-Received: by 2002:a05:6402:151:: with SMTP id s17mr1318821edu.107.1612490468796; Thu, 04 Feb 2021 18:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612490468; cv=none; d=google.com; s=arc-20160816; b=SyIN45yEsepAh39wbqk0L4m9H1CoX1LbvmGRu7HnRQGoy+FTVzB3PIGQmVLzKFZwpO Mvo71jcZDmth0jvYdHVgXgIupBPtHDyxY9N3Osxq9rLD7VWjM19Ns9+DfzFGr6baPdYz 7sXZaNIqC84QeZjNX/v1bmap+FR5kvSTNly2VeJD1mJImFkGgMUFuQtcfpOFQ1gozPmO yFEm2vcUJ91vtQLXDXzWMV94XHV2HbJYTPuaZHudT/zyxkoKID2tKiMbaDyuqnPPVhdk we7Ej5GF5+ewnCw6t8bWecDk3ffdo9iEQWh4xQlHWJCYQNgqEVgbsZaFsDEb4tDectLF AVIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=PRK36DoJ0xN8rkKv1yCTB7W9o5TYlFRBr6GLrAJJgek=; b=YkLm722nta90t4xkc2zkn8OlJxmf+nYcRuUJZGGi9LBRsnOUkfinvrYLSv39aHiQSZ fC8yvvRKcYgSlrMgBg7YPlcPvfafn1gJ+A06rCx8d9PLpXC/LK5qD8TJYlwr/TvlBeMF IW75lx+ILtIv/i4NLapZAnKIprdxmVegczjHNjz1kmYVMf6oZs23fMG1novXGCUgpNNn L6iUA4KdjdRDUJwEAvWCBZVRM2K0XMopAu93kX3/cCK5Csmx16AugIq+syE4CHagsS3G /kyI5nFw0Ha0pNpOlp4YkpItd9Sbxof05ArhhvumwvbE31ubqtcZk0x7Lrv0eCytBlEB 2xzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r23si5122798edy.113.2021.02.04.18.00.44; Thu, 04 Feb 2021 18:01:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232133AbhBEArb (ORCPT + 99 others); Thu, 4 Feb 2021 19:47:31 -0500 Received: from mx2.suse.de ([195.135.220.15]:38022 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbhBEAr3 (ORCPT ); Thu, 4 Feb 2021 19:47:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 17C23B039; Fri, 5 Feb 2021 00:46:48 +0000 (UTC) From: NeilBrown To: Andrew Morton , Alexander Viro , Jonathan Corbet Date: Fri, 05 Feb 2021 11:36:30 +1100 Subject: [PATCH 1/3] seq_file: document how per-entry resources are managed. Cc: Xin Long , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Message-ID: <161248539020.21478.3147971477400875336.stgit@noble1> In-Reply-To: <161248518659.21478.2484341937387294998.stgit@noble1> References: <161248518659.21478.2484341937387294998.stgit@noble1> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Users of seq_file will sometimes find it convenient to take a resource, such as a lock or memory allocation, in the ->start or ->next operations. These are per-entry resources, distinct from per-session resources which are taken in ->start and released in ->stop. The preferred management of these is release the resource on the subsequent call to ->next or ->stop. However prior to Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") it happened that ->show would always be called after ->start or ->next, and a few users chose to release the resource in ->show. This is no longer reliable. Since the mentioned commit, ->next will always come after a successful ->show (to ensure m->index is updated correctly), so the original ordering cannot be maintained. This patch updates the documentation to clearly state the required behaviour. Other patches will fix the few problematic users. Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Cc: Xin Long Signed-off-by: NeilBrown --- Documentation/filesystems/seq_file.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/filesystems/seq_file.rst b/Documentation/filesystems/seq_file.rst index 56856481dc8d..0e40e1532e7f 100644 --- a/Documentation/filesystems/seq_file.rst +++ b/Documentation/filesystems/seq_file.rst @@ -217,6 +217,12 @@ between the calls to start() and stop(), so holding a lock during that time is a reasonable thing to do. The seq_file code will also avoid taking any other locks while the iterator is active. +The iterater value returned by start() or next() is guaranteed to be +passed to a subsequenct next() or stop() call. This allows resources +such as locks that were taken to be reliably released. There is *no* +guarantee that the iterator will be passed to show(), though in practice +it often will be. + Formatted output ================