git: 1ad22bbc04c7 - stable/14 - loader: return errors from writing ZFS labels

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 16 Apr 2024 20:13:09 UTC
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=1ad22bbc04c7094644135b2e22386e20b899b3ff

commit 1ad22bbc04c7094644135b2e22386e20b899b3ff
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-22 15:17:56 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 19:54:26 +0000

    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)
---
 stand/libsa/zfs/zfsimpl.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/stand/libsa/zfs/zfsimpl.c b/stand/libsa/zfs/zfsimpl.c
index ed9c3753dd19..1b29c57a2ed1 100644
--- a/stand/libsa/zfs/zfsimpl.c
+++ b/stand/libsa/zfs/zfsimpl.c
@@ -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);