rust: debugfs: Add support for scoped directories
authorMatthew Maurer <mmaurer@google.com>
Thu, 4 Sep 2025 21:13:57 +0000 (21:13 +0000)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 10 Sep 2025 16:58:29 +0000 (18:58 +0200)
commit5f0942581dd0218c4449dac0639cf362e943c302
tree46930ef00452ce6d0eb7f71d7a39e37764d7ad8f
parent6f227d21377c8b86bcacb266ee1f72bc937f4598
rust: debugfs: Add support for scoped directories

Introduces the concept of a `ScopedDir`, which allows for the creation
of debugfs directories and files that are tied to the lifetime of a
particular data structure. This ensures that debugfs entries do not
outlive the data they refer to.

The new `Dir::scope` method creates a new directory that is owned by a
`Scope` handle. All files and subdirectories created within this scope
are automatically cleaned up when the `Scope` is dropped.

Signed-off-by: Matthew Maurer <mmaurer@google.com>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250904-debugfs-rust-v11-6-7d12a165685a@google.com
[ Fix up Result<(), Error> -> Result; fix spurious backtick in
  doc-comment. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/debugfs.rs
rust/kernel/debugfs/entry.rs