loader: return errors from writing ZFS labels

vdev_write_bootenv_impl can only return success. Instead, return the
last error.  This will make any write errors more visible. The old code
masked kboot's inability to write bootenv.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44018

and

loader/zfs: Fix to actually return the last error

The last fix, to try to return the last error, really returns the first
return code after the last error, which could be zero. Instead, return
the last error. Also, change rc to err to make it visually distinct from
rv, which is the cause of my error in e54bb0ad8058.

Reported by:            Bill Sommerfeld <sommerfeld@hamachi.org>
Fixes:                  e54bb0ad8058
Sponsored by:           Netflix

(cherry picked from commit e54bb0ad8058c0f84ceb08b49bb1d22af829a9e8)
(cherry picked from commit 525e6d6c890f6aee898ac70347e5bb49da6638a1)
This commit is contained in:
Warner Losh 2024-02-22 08:17:56 -07:00
parent 7209dd3eba
commit 1ad22bbc04

View file

@ -1682,14 +1682,14 @@ static int
vdev_write_bootenv_impl(vdev_t *vdev, vdev_boot_envblock_t *be)
{
vdev_t *kid;
int rv = 0, rc;
int rv = 0, err;
STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
if (kid->v_state != VDEV_STATE_HEALTHY)
continue;
rc = vdev_write_bootenv_impl(kid, be);
if (rv == 0)
rv = rc;
err = vdev_write_bootenv_impl(kid, be);
if (err != 0)
rv = err;
}
/*
@ -1699,12 +1699,12 @@ vdev_write_bootenv_impl(vdev_t *vdev, vdev_boot_envblock_t *be)
return (rv);
for (int l = 0; l < VDEV_LABELS; l++) {
rc = vdev_label_write(vdev, l, be,
err = vdev_label_write(vdev, l, be,
offsetof(vdev_label_t, vl_be));
if (rc != 0) {
if (err != 0) {
printf("failed to write bootenv to %s label %d: %d\n",
vdev->v_name ? vdev->v_name : "unknown", l, rc);
rv = rc;
vdev->v_name ? vdev->v_name : "unknown", l, err);
rv = err;
}
}
return (rv);