Skip to contentSkip to conversation

configfs: rust: add an API for adding default groups from C

PATCH Superseded Andreas Hindborg 1 participant 1 message Nov 11

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Andreas Hindborg

author maintainer
#0 lore raw

PATCH v3 1/1 configfs: rust: add an API for adding default groups from C

Some C subsystems provide a feature to add configfs default groups to the configfs hierarchy of other drivers or subsystems. Rust abstractions for these subsystems will want a way to add these default groups via the configfs Rust API. So add infrastructure to make this possible.

---
Changes in v3:
- Acquire a reference on each default group before adding it to its parent group. configfs_add_default_group does not acquire one, but configfs_remove_default_groups releases one, so a default group reached
a zero reference count when its parent was dropped, while the caller
still owned it.
- Make CDefaultGroup an unsafe trait and document the requirements on implementers.
- Add UnattachedGroup, a token that grants permission to attach a group
as a default group exactly once, and take that in Group::new instead of
an Arc. A struct config_group is linked into its parent through a
single group_entry field, so attaching one group to two parents would corrupt both lists. The token cannot be cloned and Group::new consumes
it, so this is now rejected at compile time rather than left to the
caller.
- Allocate the group in UnattachedGroup::new, so that uniqueness follows
from construction. Obtain a handle to the group with clone_arc or into_arc, named after the ListArc accessors.
- Initialize data before group in Group::new, so that no fallible
step runs after the default groups have been attached.
- Drop default groups from the list of unsupported features in the module documentation.
- Link to v2: https://msgid.link/[email protected]

Changes in v2:
- Drop the spurious __ prefix on the symbol name of the configfs_remove_default_groups Rust helper (Alice).
- Wrap the body of Group::new in pin_init::pin_init_scope so that
allocation failure from KVec::push is propagated with ? instead
of panicking via unwrap (Danilo).
- Only build configfs rust helpers when configfs is enabled.
- Link to v1: https://msgid.link/[email protected]

---
 drivers/block/rnull/configfs.rs |   1 +
 rust/helpers/configfs.c         |  20 +++++
 rust/helpers/helpers.c          |   1 +
 rust/kernel/configfs.rs         | 184 +++++++++++++++++++++++++++++++++++++---
 samples/rust/rust_configfs.rs   |   8 +-
 5 files changed, 200 insertions(+), 14 deletions(-)
drivers/block/rnull/configfs.rs +1 -0
index 34ef96fa125f0..2f5b722927e0d 100644
@@ -88,6 +88,7 @@ fn make_group(
                     name: name.try_into()?,
                 }),
             }),
+            core::iter::empty(),
         ))
     }
 }
rust/helpers/configfs.c new file +20 -0
new file mode 100644
index 0000000000000..4c71c33211bf7
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/configfs.h>
+
+#ifdef CONFIG_CONFIGFS_FS
+
+__rust_helper void
+rust_helper_configfs_add_default_group(struct config_group *new_group,
+				       struct config_group *group)
+{
+	configfs_add_default_group(new_group, group);
+}
+
+__rust_helper void
+rust_helper_configfs_remove_default_groups(struct config_group *group)
+{
+	configfs_remove_default_groups(group);
+}
+
+#endif
rust/helpers/helpers.c +1 -0
index d62c7be1ca7bd..ab8d38b431176 100644
@@ -51,6 +51,7 @@
 #include "build_bug.c"
 #include "clk.c"
 #include "completion.c"
+#include "configfs.c"
 #include "cpu.c"
 #include "cpufreq.c"
 #include "cpumask.c"
rust/kernel/configfs.rs +171 -13

222 lines not on this page · raw message

samples/rust/rust_configfs.rs +7 -1
index a1bd9db6010da..ada378bc331b1 100644
@@ -83,7 +83,12 @@ fn make_group(&self, name: &CStr) -> Result<impl PinInit<configfs::Group<Child>,
             ],
         };
 
-        Ok(configfs::Group::new(name.try_into()?, tpe, Child::new()))
+        Ok(configfs::Group::new(
+            name.try_into()?,
+            tpe,
+            Child::new(),
+            core::iter::empty(),
+        ))
     }
 }
 
@@ -152,6 +157,7 @@ fn make_group(&self, name: &CStr) -> Result<impl PinInit<configfs::Group<GrandCh
             name.try_into()?,
             tpe,
             GrandChild::new(),
+            core::iter::empty(),
         ))
     }
 }

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260215-configfs-c-default-groups-bdb0a44633a6

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>