From 649f2684701423b800f3053c7eb21ad03be7dbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 7 Apr 2022 04:32:27 +0200 Subject: [PATCH] libzfs: import: zpool_clear_label: actually fail if clearing l2arc header fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found with -Wunused-but-set-variable on Clang trunk Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #13304 --- lib/libzfs/libzfs_import.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c index 7aed626b21bf..aeb131d5db91 100644 --- a/lib/libzfs/libzfs_import.c +++ b/lib/libzfs/libzfs_import.c @@ -137,10 +137,10 @@ zpool_clear_label(int fd) struct stat64 statbuf; int l; vdev_label_t *label; - l2arc_dev_hdr_phys_t *l2dhdr; + l2arc_dev_hdr_phys_t *l2dhdr = NULL; uint64_t size; - int labels_cleared = 0, header_cleared = 0; - boolean_t clear_l2arc_header = B_FALSE; + int labels_cleared = 0; + boolean_t clear_l2arc_header = B_FALSE, header_cleared = B_FALSE; if (fstat64_blk(fd, &statbuf) == -1) return (0); @@ -210,13 +210,10 @@ zpool_clear_label(int fd) } /* Clear the L2ARC header. */ - if (clear_l2arc_header) { - memset(l2dhdr, 0, sizeof (l2arc_dev_hdr_phys_t)); - if (pwrite64(fd, l2dhdr, sizeof (l2arc_dev_hdr_phys_t), - VDEV_LABEL_START_SIZE) == sizeof (l2arc_dev_hdr_phys_t)) { - header_cleared++; - } - } + if (clear_l2arc_header && + pwrite64(fd, l2dhdr, sizeof (l2arc_dev_hdr_phys_t), + VDEV_LABEL_START_SIZE) == sizeof (l2arc_dev_hdr_phys_t)) + header_cleared = B_TRUE; free(label); free(l2dhdr); @@ -224,6 +221,9 @@ zpool_clear_label(int fd) if (labels_cleared == 0) return (-1); + if (clear_l2arc_header && !header_cleared) + return (-1); + return (0); }