public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] samples/kernfs: Add a pseudo-filesystem to demonstrate kernfs usage
@ 2025-01-21 15:36 David Reaver
  2025-01-21 15:46 ` [PATCH 1/5] samples/kernfs: Adds boilerplate/README for sample_kernfs David Reaver
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: David Reaver @ 2025-01-21 15:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Tejun Heo
  Cc: David Reaver, Steven Rostedt, Christian Brauner, Al Viro,
	Jonathan Corbet, James Bottomley, Krister Johansen, linux-fsdevel

This patch series creates a toy pseudo-filesystem built on top of kernfs in
samples/kernfs/.

kernfs underpins the sysfs and cgroup filesystems. Many kernel developers have
considered kernfs for other pseudo-filesystems [1][2] and a draft patch was
proposed to investigate moving tracefs to kernfs [3]. One reason kernfs isn't
used more is it is almost entirely undocumented; I certainly had to read almost
all of the kernfs code to implement this toy filesystem. This sample aims to
improve kernfs documentation by way of an example.

The README.rst file in the first patch describes how sample_kernfs works from a
user's perspective. Summary: the filesystem automatically populates directories
with counter files that increment every time they are read. Users can adjust the
increment via inc files. Counter files can be reset by writing a new value to
them.

Subsequent patches build the rest of the filesystem. The commits are structured
to guide readers in learning kernfs components and adapting them to build their
own filesystems. If reviewers would prefer this all to be in one commit, I'm
happy to do that too. Initially, I included a more complex example where you
could read the sum of all child directory counters in a parent directory, but I
didn't want to complicate the sample too much and distract from kernfs. I’m
happy to remove the inc file if reviewers feel it's unnecessary. It is funny how
even a toy can suffer from feature creep :)

This is my first substantial kernel patch, so I welcome feedback on any trivial
errors. I tested this filesystem with all of the CONFIG_DEBUG_* and similar
options I could find and I ensured none of them report any issues. They were
particularly useful when debugging a deadlock that required replacing
kernfs_remove() with kernfs_remove_self(), and discovering a memory leak fixed
with kernfs_put().

In the future, I hope to contribute further by writing documentation for kernfs
and exploring the possibility of porting debugfs and/or tracefs to kernfs (like
completing the draft in [3]). I'm curious if the reviewers feel any of those
ideas are worth doing right now.

Link: https://lwn.net/Articles/960088/ [1]
Link: https://lwn.net/Articles/981155/ [2]
Link: https://lore.kernel.org/all/20240131-tracefs-kernfs-v1-0-f20e2e9a8d61@kernel.org/ [3]

David Reaver (5):
  samples/kernfs: Adds boilerplate/README for sample_kernfs
  samples/kernfs: Make filesystem mountable
  samples/kernfs: Add counter file to each directory
  samples/kernfs: Allow creating and removing directories
  samples/kernfs: Add inc file to allow changing counter increment

 MAINTAINERS                    |   1 +
 samples/Kconfig                |   6 +
 samples/Makefile               |   1 +
 samples/kernfs/Makefile        |   3 +
 samples/kernfs/README.rst      |  55 ++++++
 samples/kernfs/sample_kernfs.c | 321 +++++++++++++++++++++++++++++++++
 6 files changed, 387 insertions(+)
 create mode 100644 samples/kernfs/Makefile
 create mode 100644 samples/kernfs/README.rst
 create mode 100644 samples/kernfs/sample_kernfs.c


base-commit: fda5e3f284002ea55dac1c98c1498d6dd684046e

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-02-03 16:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-21 15:36 [PATCH 0/5] samples/kernfs: Add a pseudo-filesystem to demonstrate kernfs usage David Reaver
2025-01-21 15:46 ` [PATCH 1/5] samples/kernfs: Adds boilerplate/README for sample_kernfs David Reaver
2025-01-21 15:46 ` [PATCH 2/5] samples/kernfs: Make filesystem mountable David Reaver
2025-01-21 15:46 ` [PATCH 3/5] samples/kernfs: Add counter file to each directory David Reaver
2025-01-21 15:47 ` [PATCH 4/5] samples/kernfs: Allow creating and removing directories David Reaver
2025-01-21 15:47 ` [PATCH 5/5] samples/kernfs: Add inc file to allow changing counter increment David Reaver
2025-01-28  6:08 ` [PATCH 0/5] samples/kernfs: Add a pseudo-filesystem to demonstrate kernfs usage Christoph Hellwig
2025-01-28 15:27   ` Steven Rostedt
2025-01-28 22:05     ` Linus Torvalds
2025-01-28 22:42       ` Steven Rostedt
2025-01-28 22:51         ` Tejun Heo
2025-01-28 23:29           ` Steven Rostedt
2025-01-28 23:38             ` Tejun Heo
2025-01-29  0:02               ` Steven Rostedt
2025-02-03 15:05                 ` Greg Kroah-Hartman
2025-02-03 16:12                   ` David Reaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox