[PATCH v4 0/4] rust: configfs abstractions

Andreas Hindborg posted 4 patches 1 year, 1 month ago
There is a newer version of this series
MAINTAINERS                     |   7 +
rust/bindings/bindings_helper.h |   1 +
rust/helpers/mutex.c            |   5 +
rust/kernel/configfs.rs         | 938 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs              |   2 +
rust/kernel/sync/arc.rs         |  21 +-
samples/rust/Kconfig            |  11 +
samples/rust/Makefile           |   1 +
samples/rust/rust_configfs.rs   | 179 ++++++++
9 files changed, 1160 insertions(+), 5 deletions(-)
[PATCH v4 0/4] rust: configfs abstractions
Posted by Andreas Hindborg 1 year, 1 month ago
This series adds a safe Rust API that allows Rust modules to interface
the `configfs` machinery.

The series contains an example for the samples folder to demonstrate
usage of the API. As such, there is no inline example in the
documentation.

The last patch adds a maintainer entry for the Rust configfs
abstractions, to make it absolutely clear that I will commit to maintain
these abstractions, if required. Feel free to drop this patch if this is
not required.

The series is a dependency of `rnull`, the Rust null block driver.
Please see [1] for initial `configfs` support in `rnull`.

[1] https://github.com/metaspace/linux/tree/9ac53130f5fb05b9b3074fa261b445b8fde547dd/drivers/block/rnull

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Changes in v4:
- Fix a build issue by depending on v18 of "rust: types: add `ForeignOwnable::PointedTo`"
- Link to v3: https://lore.kernel.org/r/20250218-configfs-v3-0-0e40c0778187@kernel.org

Changes in v3:
- Allow trailing commas in invocation of `configfs_attrs!`.
- Use a more suitable C initialization function when initializing `Subsystem`.
- Split sample into separate patch.
- Add an inline example.

The remaining changes in this version are style fixes, documentation
improvements and typo fixes. They are enumerated below:
- Consolidate `paste` macro calls.
- Do not hard code page size in example.
- Remove prefix of `c_str!` in sample.
- Use a more descriptive variable name in `into_foreign`.
- Improve code formatting in macros invocations.
- Add comment related to null terminator in `configfs_attrs!`
- Move attributes below docstrings.
- Remove a rogue todo.
- Remove trait bound from struct definition `GroupOperationsVTable`.
- Remove `as _` casts.
- Remove `GroupOprations::Parent` associated type.
- General documentation improvements.
- Explicitly use `ArcBorrow` for `drop_item` parameter type.
- Add a comment describing expansion to a call to `Attribute::add`.
- Add a comment explaining bound check in `Attribute::add`.
- Link to v2: https://lore.kernel.org/r/20250207-configfs-v2-0-f7a60b24d38e@kernel.org

Changes in v2:
- Remove generalization over pointer type and enforce use of `Arc`.
- Use type system to enforce connection between `ItemType` and
  `Subsystem` or `Group`. Differentiate construction of vtables on this
  type difference.
- Move drop logic of child nodes from parent to child.
- Pick `ForeignOwnable::PointedTo` patch as dependency instead of
  including it here.
- Fix some rustdoc warnings.
- Use CamelCase for generic type parameter declaration.
- Destroy mutex in `Subsystem::drop`.
- Move `GroupOperationsVTable` struct definition next to implementation.
- Rebase on v6.14-rc1.
- Link to v1: https://lore.kernel.org/r/20250131-configfs-v1-0-87947611401c@kernel.org

---
Andreas Hindborg (4):
      rust: sync: change `<Arc<T> as ForeignOwnable>::PointedTo` to `T`
      rust: configfs: introduce rust support for configfs
      rust: configfs: add a sample demonstrating configfs usage
      MAINTAINERS: add entry for configfs Rust abstractions

 MAINTAINERS                     |   7 +
 rust/bindings/bindings_helper.h |   1 +
 rust/helpers/mutex.c            |   5 +
 rust/kernel/configfs.rs         | 938 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   2 +
 rust/kernel/sync/arc.rs         |  21 +-
 samples/rust/Kconfig            |  11 +
 samples/rust/Makefile           |   1 +
 samples/rust/rust_configfs.rs   | 179 ++++++++
 9 files changed, 1160 insertions(+), 5 deletions(-)
---
base-commit: 379487e17ca406b47392e7ab6cf35d1c3bacb371
change-id: 20250131-configfs-b888cd82d84a
prerequisite-patch-id: 03c1bff48fd24e83d1383e98f8668300e665ebae

Best regards,
-- 
Andreas Hindborg <a.hindborg@kernel.org>
Re: [PATCH v4 0/4] rust: configfs abstractions
Posted by Daniel Almeida 1 year, 1 month ago
Hi Andreas, FYI:

Tested-by: Daniel Almeida <daniel.almeida@collabora.com>

i.e.:

```
sudo cat /mnt/rust_configfs/message 
[  234.971000] rust_configfs: Show message
Hello World

sudo cat /mnt/rust_configfs/bar
[  335.542585] rust_configfs: Show bar

sudo sh -c "echo new_bar > /mnt/rust_configfs/bar"
[  382.114901] rust_configfs: Store bar

sudo cat /mnt/rust_configfs/bar
[  401.348487] rust_configfs: Show bar
new_bar

sudo mkdir /mnt/rust_configfs/child

sudo ls /mnt/rust_configfs/
bar      child/   message

sudo ls /mnt/rust_configfs/child/
baz

sudo cat /mnt/rust_configfs/child/baz 
[  600.651618] rust_configfs: Show baz
Hello Baz

sudo mkdir /mnt/rust_configfs/child/grandchild

sudo ls /mnt/rust_configfs/child/grandchild/
gc

sudo cat /mnt/rust_configfs/child/grandchild/gc
[  670.093647] rust_configfs: Show baz
Hello GC
```

Is that last one (for the grandchild) really supposed to print “Show baz” ?

Please let me know if there’s anything else needed to test this fully. A review will soon follow.

— Daniel
Re: [PATCH v4 0/4] rust: configfs abstractions
Posted by Andreas Hindborg 1 year, 1 month ago
"Daniel Almeida" <daniel.almeida@collabora.com> writes:

> Hi Andreas, FYI:
>
> Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
>
> i.e.:
>
> ```
> sudo cat /mnt/rust_configfs/message
> [  234.971000] rust_configfs: Show message
> Hello World
>
> sudo cat /mnt/rust_configfs/bar
> [  335.542585] rust_configfs: Show bar
>
> sudo sh -c "echo new_bar > /mnt/rust_configfs/bar"
> [  382.114901] rust_configfs: Store bar
>
> sudo cat /mnt/rust_configfs/bar
> [  401.348487] rust_configfs: Show bar
> new_bar
>
> sudo mkdir /mnt/rust_configfs/child
>
> sudo ls /mnt/rust_configfs/
> bar      child/   message
>
> sudo ls /mnt/rust_configfs/child/
> baz
>
> sudo cat /mnt/rust_configfs/child/baz
> [  600.651618] rust_configfs: Show baz
> Hello Baz
>
> sudo mkdir /mnt/rust_configfs/child/grandchild
>
> sudo ls /mnt/rust_configfs/child/grandchild/
> gc
>
> sudo cat /mnt/rust_configfs/child/grandchild/gc
> [  670.093647] rust_configfs: Show baz
> Hello GC
> ```
>
> Is that last one (for the grandchild) really supposed to print “Show baz” ?

Thanks for testing! Good catch of copy pasta on the last one - I will
fix that.


Best regards,
Andreas Hindborg