[1/3] seq_file: document how per-entry resources are managed.
diff mbox series

Message ID 161248539020.21478.3147971477400875336.stgit@noble1
State In Next
Commit 0ff271bed7c099964d86ea8def092b9745f16593
Headers show
  • Fix some seq_file users that were recently broken
Related show

Commit Message

NeilBrown Feb. 5, 2021, 12:36 a.m. UTC
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
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 <lucien.xin@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
 Documentation/filesystems/seq_file.rst |    6 ++++++
 1 file changed, 6 insertions(+)


Matthew Wilcox Feb. 5, 2021, 2:20 a.m. UTC | #1
On Fri, Feb 05, 2021 at 11:36:30AM +1100, NeilBrown wrote:
> +passed to a subsequenct next() or stop() call.  This allows resources


diff mbox series

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