[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <053cb4c3-aab1-23b3-56e3-4f1741e69404@ryhl.io>
Date: Fri, 16 Jun 2023 21:23:28 +0200
From: Alice Ryhl <alice@...l.io>
To: Jakub Kicinski <kuba@...nel.org>
Cc: FUJITA Tomonori <fujita.tomonori@...il.com>, andrew@...n.ch,
netdev@...r.kernel.org, rust-for-linux@...r.kernel.org,
aliceryhl@...gle.com, miguel.ojeda.sandonis@...il.com
Subject: Re: [PATCH 0/5] Rust abstractions for network device drivers
On 6/16/23 21:10, Jakub Kicinski wrote:
> On Fri, 16 Jun 2023 21:00:36 +0200 Alice Ryhl wrote:
>> A Rust method can be defined to take the struct "by value", which
>> consumes the struct and prevents you from using it again. This can let
>> you provide many different cleanup methods that each clean it up in
>> different ways.
>>
>> However, you cannot force the user to use one of those methods. They
>> always have the option of letting the value go out of scope, which calls
>> the destructor. And they can do this at any time.
>>
>> That said, the destructor of the value does not necessarily *have* to
>> translate to immediately freeing the value. If the value if refcounted,
>> the destructor could just drop the refcount. It would also be possible
>> for a destructor to schedule the cleanup operation to a workqueue. Or
>> you could do something more clever.
>
> Can we put a WARN_ON() in the destructor and expect object to never be
> implicitly freed? skbs represent packets (most of the time) and for
> tracking which part of the stack is dropping packets we try to provide
> a drop reason along the freed skb. It'd be great if for Rust we could
> from the get-go direct everyone towards the APIs with an explicit reason
> code.
Yes, you can certainly put a WARN_ON in the destructor.
Another possibility is to use a scope to clean up. I don't know anything
about these skb objects are used, but you could have the user define a
"process this socket" function that you pass a pointer to the skb, then
make the return value be something that explains what should be done
with the packet. Since you must return a value of the right type, this
forces you to choose.
Of course, this requires that the processing of packets can be expressed
as a function call, where it only inspects the packet for the duration
of that function call. (Lifetimes can ensure that the skb pointer does
not escape the function.)
Would something like that work?
Alice
Powered by blists - more mailing lists