From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Joel Becker" <jlbec@evilplan.org>,
"Christoph Hellwig" <hch@lst.de>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Fiona Behrens" <me@kloenk.dev>,
"Charalampos Mitrodimas" <charmitro@posteo.net>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/4] rust: configfs: add a sample demonstrating configfs usage
Date: Tue, 25 Feb 2025 11:23:30 +0100 [thread overview]
Message-ID: <87jz9ewcf1.fsf@kernel.org> (raw)
In-Reply-To: <CB975A56-A8D5-4615-8755-04D7B0BBBCA5@collabora.com> (Daniel Almeida's message of "Tue, 25 Feb 2025 06:37:33 -0300")
"Daniel Almeida" <daniel.almeida@collabora.com> writes:
> Hi Andreas,
>
>> On 24 Feb 2025, at 10:21, Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>> Add a sample to the samples folder, demonstrating the intended use of the
>> rust configfs API.
>
> nit: this is not the first time I see Rust not capitalized in this series.
Will fix 👍
[...]
>> +impl kernel::InPlaceModule for RustConfigfs {
>> + fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
>> + pr_info!("Rust configfs sample (init)\n");
>> +
>> + let item_type = configfs_attrs! {
>> + container: configfs::Subsystem<Configuration>,
>> + data: Configuration,
>> + child: Child,
>> + attributes: [
>> + message: 0,
>> + bar: 1,
>> + ],
>> + };
>
> As I said in the previous patch, this macro is a bit complex. Is there anything more you can do with it?
>
> If so, it better be in this driver, because I hardly think anybody will go through the source code itself
> to figure out. My 2c.
I can add some inline comments on the usage here. Is that what you are
thinking of?
>
>
>> +
>> + try_pin_init!(Self {
>> + config <- configfs::Subsystem::new(
>> + c_str!("rust_configfs"), item_type, Configuration::new()
>> + ),
>> + })
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::GroupOperations for Configuration {
>> + type Child = Child;
>> +
>> + fn make_group(&self, name: &CStr) -> Result<impl PinInit<configfs::Group<Child>, Error>> {
>> + let tpe = configfs_attrs! {
>> + container: configfs::Group<Child>,
>> + data: Child,
>> + child: GrandChild,
>> + attributes: [
>> + baz: 0,
>> + ],
>> + };
>> +
>> + Ok(configfs::Group::new(name.try_into()?, tpe, Child::new()))
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::AttributeOperations<0> for Configuration {
>> + type Data = Configuration;
>> +
>> + fn show(container: &Configuration, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
>> + pr_info!("Show message\n");
>> + let data = container.message;
>> + page[0..data.len()].copy_from_slice(data);
>> + Ok(data.len())
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::AttributeOperations<1> for Configuration {
>> + type Data = Configuration;
>> +
>> + fn show(container: &Configuration, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
>> + pr_info!("Show bar\n");
>> + let guard = container.bar.lock();
>> + let data = guard.0.as_slice();
>> + let len = guard.1;
>> + page[0..len].copy_from_slice(&data[0..len]);
>> + Ok(len)
>> + }
>> +
>> + fn store(container: &Configuration, page: &[u8]) -> Result {
>> + pr_info!("Store bar\n");
>> + let mut guard = container.bar.lock();
>> + guard.0[0..page.len()].copy_from_slice(page);
>> + guard.1 = page.len();
>> + Ok(())
>> + }
>> +}
>> +
>> +#[pin_data]
>> +struct Child {}
>
> nit: you don’t need the braces here
Can't do that. The `pin_data` macro won't eat it. I'll add a comment.
>
>> +
>> +impl Child {
>> + fn new() -> impl PinInit<Self, Error> {
>> + try_pin_init!(Self {})
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::GroupOperations for Child {
>> + type Child = GrandChild;
>> +
>> + fn make_group(&self, name: &CStr) -> Result<impl PinInit<configfs::Group<GrandChild>, Error>> {
>> + let tpe = configfs_attrs! {
>> + container: configfs::Group<GrandChild>,
>> + data: GrandChild,
>> + attributes: [
>> + gc: 0,
>> + ],
>> + };
>> +
>> + Ok(configfs::Group::new(
>> + name.try_into()?,
>> + tpe,
>> + GrandChild::new(),
>> + ))
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::AttributeOperations<0> for Child {
>> + type Data = Child;
>> +
>> + fn show(_container: &Child, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
>> + pr_info!("Show baz\n");
>> + let data = c"Hello Baz\n".to_bytes();
>> + page[0..data.len()].copy_from_slice(data);
>> + Ok(data.len())
>> + }
>> +}
>> +
>> +#[pin_data]
>> +struct GrandChild {}
>
> …nor here
>
>> +
>> +impl GrandChild {
>> + fn new() -> impl PinInit<Self, Error> {
>> + try_pin_init!(Self {})
>> + }
>> +}
>> +
>> +#[vtable]
>> +impl configfs::AttributeOperations<0> for GrandChild {
>> + type Data = GrandChild;
>> +
>> + fn show(_container: &GrandChild, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
>> + pr_info!("Show baz\n");
>
> As I said in the cover letter, perhaps this one slip through :)
Yes, thank you.
>
>> + let data = c"Hello GC\n".to_bytes();
>> + page[0..data.len()].copy_from_slice(data);
>> + Ok(data.len())
>> + }
>> +}
>>
>> --
>> 2.47.0
>>
>>
>
> I’m OK with this patch. It works, and it does what it’s supposed to do, i.e.: showcase the API.
>
> With the “Show baz” nit fixed:
>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Thanks!
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-02-25 10:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 13:21 [PATCH v4 0/4] rust: configfs abstractions Andreas Hindborg
2025-02-24 13:21 ` [PATCH v4 1/4] rust: sync: change `<Arc<T> as ForeignOwnable>::PointedTo` to `T` Andreas Hindborg
2025-02-24 21:22 ` Daniel Almeida
2025-02-24 13:21 ` [PATCH v4 2/4] rust: configfs: introduce rust support for configfs Andreas Hindborg
2025-02-24 22:30 ` Daniel Almeida
2025-02-25 10:11 ` Andreas Hindborg
2025-02-25 10:53 ` Daniel Almeida
2025-02-25 12:29 ` Andreas Hindborg
2025-02-25 13:01 ` Daniel Almeida
2025-02-24 13:21 ` [PATCH v4 3/4] rust: configfs: add a sample demonstrating configfs usage Andreas Hindborg
2025-02-25 9:37 ` Daniel Almeida
2025-02-25 10:23 ` Andreas Hindborg [this message]
2025-02-25 10:58 ` Daniel Almeida
2025-02-24 13:21 ` [PATCH v4 4/4] MAINTAINERS: add entry for configfs Rust abstractions Andreas Hindborg
2025-02-25 9:38 ` Daniel Almeida
2025-02-24 16:55 ` [PATCH v4 0/4] rust: configfs abstractions Daniel Almeida
2025-02-24 19:12 ` Andreas Hindborg
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=87jz9ewcf1.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=charmitro@posteo.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=hch@lst.de \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=me@kloenk.dev \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).