From: David Reaver <me@davidreaver.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Tejun Heo <tj@kernel.org>
Cc: David Reaver <me@davidreaver.com>,
Steven Rostedt <rostedt@goodmis.org>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Jonathan Corbet <corbet@lwn.net>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Krister Johansen <kjlx@templeofstupid.com>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 0/5] samples/kernfs: Add a pseudo-filesystem to demonstrate kernfs usage
Date: Tue, 21 Jan 2025 07:36:34 -0800 [thread overview]
Message-ID: <20250121153646.37895-1-me@davidreaver.com> (raw)
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
next reply other threads:[~2025-01-21 15:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 15:36 David Reaver [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250121153646.37895-1-me@davidreaver.com \
--to=me@davidreaver.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=kjlx@templeofstupid.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox