From 62a9d372f83249619694a141d59c8e88500126e6 Mon Sep 17 00:00:00 2001 From: Tony Hutter Date: Wed, 12 Mar 2025 06:52:36 -0700 Subject: [PATCH] zed: Print return code on failed zpool_prepare_disk We had a case where we were autoreplacing a disk and zpool_prepare_disk failed for some reason, and ZED didn't log the return code. This commit logs the code. Reviewed-by: Alexander Motin Signed-off-by: Tony Hutter Closes #17124 --- cmd/zed/agents/zfs_mod.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/zed/agents/zfs_mod.c b/cmd/zed/agents/zfs_mod.c index d0372608c..56da87fa9 100644 --- a/cmd/zed/agents/zfs_mod.c +++ b/cmd/zed/agents/zfs_mod.c @@ -214,6 +214,7 @@ zfs_process_add(zpool_handle_t *zhp, nvlist_t *vdev, boolean_t labeled) vdev_stat_t *vs; char **lines = NULL; int lines_cnt = 0; + int rc; /* * Get the persistent path, typically under the '/dev/disk/by-id' or @@ -405,17 +406,17 @@ zfs_process_add(zpool_handle_t *zhp, nvlist_t *vdev, boolean_t labeled) } nvlist_lookup_string(vdev, "new_devid", &new_devid); - if (is_mpath_wholedisk) { /* Don't label device mapper or multipath disks. */ zed_log_msg(LOG_INFO, " it's a multipath wholedisk, don't label"); - if (zpool_prepare_disk(zhp, vdev, "autoreplace", &lines, - &lines_cnt) != 0) { + rc = zpool_prepare_disk(zhp, vdev, "autoreplace", &lines, + &lines_cnt); + if (rc != 0) { zed_log_msg(LOG_INFO, " zpool_prepare_disk: could not " - "prepare '%s' (%s)", fullpath, - libzfs_error_description(g_zfshdl)); + "prepare '%s' (%s), path '%s', rc = %d", fullpath, + libzfs_error_description(g_zfshdl), path, rc); if (lines_cnt > 0) { zed_log_msg(LOG_INFO, " zfs_prepare_disk output:"); @@ -446,12 +447,13 @@ zfs_process_add(zpool_handle_t *zhp, nvlist_t *vdev, boolean_t labeled) * If this is a request to label a whole disk, then attempt to * write out the label. */ - if (zpool_prepare_and_label_disk(g_zfshdl, zhp, leafname, - vdev, "autoreplace", &lines, &lines_cnt) != 0) { + rc = zpool_prepare_and_label_disk(g_zfshdl, zhp, leafname, + vdev, "autoreplace", &lines, &lines_cnt); + if (rc != 0) { zed_log_msg(LOG_WARNING, " zpool_prepare_and_label_disk: could not " - "label '%s' (%s)", leafname, - libzfs_error_description(g_zfshdl)); + "label '%s' (%s), rc = %d", leafname, + libzfs_error_description(g_zfshdl), rc); if (lines_cnt > 0) { zed_log_msg(LOG_INFO, " zfs_prepare_disk output:");