Page MenuHomeFreeBSD

stand: shuffle dv_open/dv_init bits around
Needs ReviewPublic

Authored by kevans on Jun 26 2019, 6:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 10 2024, 3:37 AM
Unknown Object (File)
Jul 15 2023, 10:14 PM
Unknown Object (File)
Jun 26 2023, 11:12 PM
Unknown Object (File)
Jun 3 2023, 7:46 AM
Unknown Object (File)
May 3 2023, 7:24 PM
Unknown Object (File)
Dec 27 2022, 1:49 AM
Unknown Object (File)
Nov 26 2022, 1:18 PM
Subscribers

Details

Reviewers
imp
bcran
tsoome
Group Reviewers
bhyve
Summary

This is an attempt to only allow opening on devices that have actually successfully init (or have no dv_init?) -- wrap devsw->dv_open so we can kick back ENXIO consistently if we haven't been initialized successfully.

dv_open previously used varargs, but always took exactly one devdesc-esque pointer. Formalize the prototype as taking a struct devdesc *, we'll just use type-punning as needed and is safe in individual dv_open.

Some redundancy of walking through global devsw and initializing has been removed in favor of providing a common method for this in libsa. U-Boot uses it, though it did something slightly different: dv_init == NULL implied an unusable device, but this is now fine (and likely sufficiently edge-casey that it doesn't really matter).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 25074

Event Timeline

stand/common/dev_net.c
117–118

delete this line

stand/efi/libefi/efihttp.c
243

picking one at random... why this test?

stand/libsa/conf.c
45 ↗(On Diff #59070)

I'd do (dev->dv_init() == 0) here.

58 ↗(On Diff #59070)

Maybe add:

if (dev == NULL)
return (EINVAL);

stand/powerpc/kboot/hostdisk.c
90

Can we put the desc check only in the dv_open() function call you've added, then we know for sure it's != NULL, then we can remove the checks in all the functions.

stand/powerpc/ofw/main.c
127

I like this, but this change feels like a separate commit, if you're ok with splitting this a little...

stand/libsa/conf.c
58 ↗(On Diff #59070)

+1

kevans marked 5 inline comments as done.
kevans edited the summary of this revision. (Show Details)

Address review comments:

  • Delete stale comment
  • Push dev == null check into dv_open wrapper

Many of these were casting it to a disk_devdesc but only really needed the devdesc bits, so I killed off the local disk_devdesc and casted it as appropriate when passing elsewhere...

I'll commit it in these two pieces (in order):
https://github.com/kevans91/freebsd/commit/f2be8295bbb803b1c00bfa1cb78454a176ed7eef
https://github.com/kevans91/freebsd/commit/fcafa5bbaca2bac2749c577355c0418d16f96062

The review wasn't shaped like that since the dv_open wrapper started only being useful because of the dv_inited bits, but no qualms with splitting it now.

stand/libsa/Makefile
148

the conf.c does sound a bit confusing. maybe devsw.c or devsw_utils.c or like?

stand/libsa/stand.h
159

I think, either use bool, or if to keep int, then name it like dv_flags or dv_state and add constant values like above for dv_type.

stand/i386/libfirewire/firewire.c
180–181

while you're here and changing it anyway... just delete this whole #if 0.

stand/libsa/Makefile
148

Good suggestion! I'd prefer devsw.c because we may need/want other wrappers.

stand/libsa/stand.h
159

It would be more in keeping with the rest of the system to call it dv_flags and a DV_FLAG_INIT_DONE or similar.
But dv_inited should be a bool.

kevans marked 3 inline comments as done.

conf.c -> devsw.c
dv_inited -> dv_flags (I liked DV_FLAG_INIT_DONE)