[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBOiyB5fG_F60BNv@pollux>
Date: Thu, 1 May 2025 18:35:20 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Matthew Maurer <mmaurer@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Timur Tabi <ttabi@...dia.com>, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v2 1/4] rust: debugfs: Bind DebugFS directory creation
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@...nel.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!
Powered by blists - more mailing lists