Page MenuHomeFreeBSD

pseudofs: return errors from pfs_create_*()
ClosedPublic

Authored by kevans on Aug 25 2025, 9:11 PM.
Tags
None
Referenced Files
F132385231: D52157.id160963.diff
Thu, Oct 16, 11:07 AM
Unknown Object (File)
Mon, Oct 13, 1:00 AM
Unknown Object (File)
Sat, Oct 11, 6:35 AM
Unknown Object (File)
Sat, Oct 11, 6:34 AM
Unknown Object (File)
Sat, Oct 11, 6:34 AM
Unknown Object (File)
Sat, Oct 11, 6:34 AM
Unknown Object (File)
Sat, Oct 11, 1:10 AM
Unknown Object (File)
Fri, Oct 10, 11:17 PM
Subscribers

Details

Summary

In D52038, we kind of guess at the reason that pfs_create_dir() failed,
which isn't great: it could be EEXISTS, or it could even be ENOMEM.

Change the pfs_create_*() interfaces to return an error and use a double
pointer to return the new node as requested. Outside of the changes
in sys/fs/pseudofs, this diff is the result of running the added
coccinelle script against in-tree pseudofs and fixing all of the
style(9) violations that spatch added. One comment was added to
linsysfs to note where we need the actual return value, but nothing is
done there yet.

We set *opn to NULL in the failure cases to avoid breaking callers that
did actually error-check their results, since the cocci patch does not
attempt to handle that in any way.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des added inline comments.
sys/fs/pseudofs/pseudofs.c
259

Perhaps it would be better to move those two lines to the beginning of the function (and the same for pfs_create_file() and pfs_create_link())

sys/fs/pseudofs/pseudofs.h
263

I would prefer to have opn as the second argument, but that's purely a matter of taste.

This revision is now accepted and ready to land.Aug 25 2025, 9:33 PM
sys/fs/pseudofs/pseudofs.h
263

Hmm. I had added it to the end just to ease transition (since pattern matching pfs_create.+); and replacing the end-of-line is trivial), but given that I'm providing a coccinelle patch to do it anyways I don't think I care[0].

[0] Other than the fact that spatch will bork a bunch of formatting that I have to fix when I re-roll all of those bits, but looking at the options, increasing --max-width or using --smpl-spacing might make life a lot easier there so that I just have to wrap some long lines.

sys/fs/pseudofs/pseudofs.c
567–568

The inverted condition here is fixed in the version that moves it back into the previous patch.

Move the out-node parameter to the second and update the spatch accordingly, and
set *opn up front.

Note that pfs_dir will preserve the original parent, because at least one
consumer (linsysfs) has just re-used the same pointer for both the parent and
the new directory. It seems better to be safe and accommodate others that could
have adopted the same convention.

This revision now requires review to proceed.Aug 30 2025, 3:37 PM
This revision is now accepted and ready to land.Aug 30 2025, 4:50 PM
This revision was automatically updated to reflect the committed changes.