stand: create common set_currdev

Pull together the nearly identical copies of set_currdev in i386,
userboot and efi. Other boot loaders have variances that might be fine
to use the common routine, or not. Since they are harder to test for me,
and ofw and uboot do handle these setting differently, leave them be for
now.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38005
This commit is contained in:
Warner Losh 2023-01-11 15:14:28 -07:00
parent bf020787d5
commit ad70f2e22e
5 changed files with 19 additions and 28 deletions

View file

@ -415,6 +415,7 @@ int nvstore_unset_var(void *, const char *);
/* common code to set currdev variable. */
int gen_setcurrdev(struct env_var *ev, int flags, const void *value);
int mount_currdev(struct env_var *, int, const void *);
void set_currdev(const char *devname);
#ifndef CTASSERT
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")

View file

@ -206,3 +206,20 @@ gen_setcurrdev(struct env_var *ev, int flags, const void *value)
return (mount_currdev(ev, flags, value));
}
/*
* Wrapper to set currdev and loaddev at the same time.
*/
void
set_currdev(const char *devname)
{
env_setenv("currdev", EV_VOLATILE, devname, gen_setcurrdev,
env_nounset);
/*
* Don't execute hook here; the loaddev hook makes it immutable
* once we've determined what the proper currdev is.
*/
env_setenv("loaddev", EV_VOLATILE | EV_NOHOOK, devname, env_noset,
env_nounset);
}

View file

@ -185,20 +185,6 @@ has_keyboard(void)
return retval;
}
static void
set_currdev(const char *devname)
{
env_setenv("currdev", EV_VOLATILE, devname, gen_setcurrdev,
env_nounset);
/*
* Don't execute hook here; the loaddev hook makes it immutable
* once we've determined what the proper currdev is.
*/
env_setenv("loaddev", EV_VOLATILE | EV_NOHOOK, devname, env_noset,
env_nounset);
}
static void
set_currdev_devdesc(struct devdesc *currdev)
{

View file

@ -383,10 +383,7 @@ extract_currdev(void)
init_zfs_boot_options(devformat(&new_currdev.dd));
#endif
env_setenv("currdev", EV_VOLATILE, devformat(&new_currdev.dd),
gen_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, devformat(&new_currdev.dd),
env_noset, env_nounset);
set_currdev(devformat(&new_currdev.dd));
}
COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);

View file

@ -224,16 +224,6 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
exit(0);
}
static void
set_currdev(const char *devname)
{
env_setenv("currdev", EV_VOLATILE, devname,
gen_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, devname,
env_noset, env_nounset);
}
/*
* Set the 'current device' by (if possible) recovering the boot device as
* supplied by the initial bootstrap.