Re: [PATCH v4 7/9] rust: file: add `Kuid` wrapper

From: Greg Kroah-Hartman
Date: Fri Feb 02 2024 - 10:36:35 EST


On Fri, Feb 02, 2024 at 10:55:41AM +0000, Alice Ryhl wrote:
> + /// Returns the given task's pid in the current pid namespace.
> + pub fn pid_in_current_ns(&self) -> Pid {
> + let current = Task::current_raw();
> + // SAFETY: Calling `task_active_pid_ns` with the current task is always safe.
> + let namespace = unsafe { bindings::task_active_pid_ns(current) };
> + // SAFETY: We know that `self.0.get()` is valid by the type invariant, and the namespace
> + // pointer is not dangling since it points at this task's namespace.
> + unsafe { bindings::task_tgid_nr_ns(self.0.get(), namespace) }
> + }

pids are reference counted in the kernel, how does this deal with that?
Are they just ignored somehow? Where is the reference count given back?

thanks,

greg k-h