Rust for Linux List
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@kernel.org>
To: Matthew Maurer <mmaurer@google.com>
Cc: "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>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 1/4] rust: debugfs: Bind DebugFS directory creation
Date: Thu, 1 May 2025 18:35:20 +0200	[thread overview]
Message-ID: <aBOiyB5fG_F60BNv@pollux> (raw)
In-Reply-To: <CAGSQo01O8DFe1+APM2cYYFT_4ROKrbTQpNmozYk3NQwYc3Zv2Q@mail.gmail.com>

On Thu, May 01, 2025 at 09:02:58AM -0700, Matthew Maurer wrote:
> On Thu, May 1, 2025 at 3:16 AM Danilo Krummrich <dakr@kernel.org> wrote:
> >
> > On Wed, Apr 30, 2025 at 11:31:56PM +0000, Matthew Maurer wrote:
> > >
> > > +    /// Create a DebugFS subdirectory.
> > > +    ///
> > > +    /// # Examples
> > > +    ///
> > > +    /// ```
> > > +    /// # use kernel::c_str;
> > > +    /// # use kernel::debugfs::Dir;
> > > +    /// {
> > > +    ///    let parent = Dir::new(c_str!("parent"));
> > > +    ///    // parent exists in DebugFS here.
> > > +    ///    let child = parent.subdir(c_str!("child"));
> > > +    ///    // parent/child exists in DebugFS here.
> > > +    /// }
> > > +    /// // Neither exist here.
> > > +    /// ```
> > > +    pub fn subdir(&self, name: &CStr) -> Self {
> > > +        Self::create(name, Some(self))
> > > +    }
> >
> > I think this should return a new type (SubDir), which is a transparent wrapper
> > of Dir and dereferences to Dir.
> >
> > Subsequently, we can remove Dir::keep() implement SubDir::keep() instead. This
> > ensures that we can never call keep() on the root directory, which would always
> > be a bug.
> 1. If the code in question is builtin rather than a module, discarding
> this without tearing it down may not be a bug.

True, if builtin *and* never intended to remove, it's indeed not a bug, but
arguably not very useful either.

> 2. Users could always write `core::mem::forget()`, so this will always
> be reachable (even if we decide to remove `::keep` to make it harder
> to choose).

Yet I wouldn't encourage users to create bugs by offering them a convenient way
to do so, without any benefit. :)

> > As an alternative to the Deref impl, you can also implement
> > `From<SubDir> for Dir`, such that a SubDir can either be "kept" or converted to
> > a Dir. Probably, that's even better.
> 
> Yes, this was the "extra type complexity" I referenced in the cover
> letter that I was considering doing. I think that probably what I'll
> do for v3 is to have both the `Deref` *and* `From` implementation, so
> that `SubDir` still automatically gets all of `Dir`s stuff, since your
> later `File` comment convinces me we can't just have everything be
> `Dir`.

Sounds good to me, thanks!

  reply	other threads:[~2025-05-01 16:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 23:31 [PATCH v2 0/4] rust: DebugFS Bindings Matthew Maurer
2025-04-30 23:31 ` [PATCH v2 1/4] rust: debugfs: Bind DebugFS directory creation Matthew Maurer
2025-05-01 10:00   ` Miguel Ojeda
2025-05-01 10:16   ` Danilo Krummrich
2025-05-01 16:02     ` Matthew Maurer
2025-05-01 16:35       ` Danilo Krummrich [this message]
2025-04-30 23:31 ` [PATCH v2 2/4] rust: debugfs: Bind file creation for long-lived Display Matthew Maurer
2025-05-01 10:37   ` Danilo Krummrich
2025-05-01 16:09     ` Matthew Maurer
2025-05-01 17:32       ` Danilo Krummrich
2025-04-30 23:31 ` [PATCH v2 3/4] rust: debugfs: Support format hooks Matthew Maurer
2025-05-01 10:00   ` Miguel Ojeda
2025-04-30 23:31 ` [PATCH v2 4/4] rust: samples: Add debugfs sample Matthew Maurer
2025-05-01  7:40   ` Greg Kroah-Hartman
2025-05-01 16:44     ` Timur Tabi

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=aBOiyB5fG_F60BNv@pollux \
    --to=dakr@kernel.org \
    --cc=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=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmaurer@google.com \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    /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