openSUSE / libpathrs

C-friendly API to make path resolution safer on Linux.
GNU Lesser General Public License v3.0
66 stars 5 forks source link

cffi: add a configure option to opt-out of "nice" errors #39

Open cyphar opened 1 month ago

cyphar commented 1 month ago

While the new API makes error management much nicer, some users might just want to get raw errnos.

We can very easily switch to returning raw errnos from a type perspective, but it's a little unclear what we should do for errors that don't have an underlying errno. We can just copy the kernel and just use -EINVAL :sweat_smile:, or we could use an errno that the kernel rarely returns like -ENOANO, never returns like -ENOPARAM, or a large negative number that doesn't map to any errno (INT_MIN if we want to be safe, I guess?).

This requires us getting a nice config API first (#21).

(Suggested by @brauner.)

cyphar commented 1 month ago

ESERVERFAULT (errno 526, a kernel-internal errno from the NFSv3 protocol) semantically makes sense (the error description is An untranslatable error occurred) and is an errno userspace should never see returned from the kernel so we're safe remapping errors to it without causing confusion.

cyphar commented 3 weeks ago

We can also switch away from using Mutex<HashMap<...>> to one of these lockless alternatives:

  1. https://github.com/hawkw/sharded-slab (has the benefit of having generation numbers, which reduces the risk of a user double-getting the same ID and clearing another thread's error by accident.)
  2. https://github.com/loyd/idr-ebr is similar, but it isn't optimised for insert/remove (which is our usecase!) so sharded-slab is probably better.