On Thu Jul 30, 2026 at 7:05 PM CEST, Alvin Sun wrote:
> +    /// Creates a [`ScopedDir`] wrapping an existing debugfs dentry.
> +    ///
> +    /// Files created under this directory are not automatically removed on 
> drop;
> +    /// their lifetime is tied to the dentry owner.
> +    ///
> +    /// # Safety
> +    ///
> +    /// The caller must ensure the dentry remains valid for the lifetime of 
> the
> +    /// returned `ScopedDir`.
> +    pub unsafe fn from_dentry(dentry: *mut bindings::dentry) -> Self {
> +        let _ = dentry;
> +        ScopedDir {
> +            #[cfg(CONFIG_DEBUG_FS)]
> +            // SAFETY: The caller guarantees the dentry is valid and 
> outlives this `ScopedDir`.
> +            entry: ManuallyDrop::new(unsafe { Entry::from_raw(dentry) }),
> +            _phantom: PhantomData,
> +        }
> +    }

I think what you actually want to express is that the DRM debugfs root dir
represents a view into an existing scope, where the data is T::RegistrationData.

Additionally, we want to be able to derive new debugfs::Scopes from this that
are shorter lived, so we can create new debugfs::Scopes e.g. in
drm::DriverFile<'a>, which I currently work on.

So, what I'm thinking of is a type like:

        pub struct ScopeRef<'a, T> {
            #[cfg(CONFIG_DEBUG_FS)]
            dentry: Option<NonNull<bindings::dentry>>,
            data: &'a T,
        }

which has a corresponding unsafe constructor and provides methods to e.g. create
a new directory, returning a new ScopeRef<'a, T>, which can be stored in
lifetime scoped data.

Additionally, but that's somewhat orthogonal, we want debugfs::Scope to support
lifetime data, so a scope can participate in the driver lifecycle; the
corresponding synchronization is already in place with full proxy fops.

Reply via email to