aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-04-07 04:37:16 +0200
committerBrian Behlendorf <[email protected]>2022-04-13 11:37:10 -0700
commit74e4bfbcff3636182b76a18d6d08efd3ad0ad165 (patch)
treec2dba94cc1c4b6553d5a3d6f34c1e41a7f60d007
parenta4e0cee1780cbd8f2cb9a263a0ed8d91dbe68b4a (diff)
libzfs: import: zpool_clear_label: don't allocate another time for L2ARC header
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13304
-rw-r--r--lib/libzfs/libzfs_import.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c
index aeb131d5d..806ab4e23 100644
--- a/lib/libzfs/libzfs_import.c
+++ b/lib/libzfs/libzfs_import.c
@@ -137,7 +137,6 @@ zpool_clear_label(int fd)
struct stat64 statbuf;
int l;
vdev_label_t *label;
- l2arc_dev_hdr_phys_t *l2dhdr = NULL;
uint64_t size;
int labels_cleared = 0;
boolean_t clear_l2arc_header = B_FALSE, header_cleared = B_FALSE;
@@ -150,11 +149,6 @@ zpool_clear_label(int fd)
if ((label = calloc(1, sizeof (vdev_label_t))) == NULL)
return (-1);
- if ((l2dhdr = calloc(1, sizeof (l2arc_dev_hdr_phys_t))) == NULL) {
- free(label);
- return (-1);
- }
-
for (l = 0; l < VDEV_LABELS; l++) {
uint64_t state, guid, l2cache;
nvlist_t *config;
@@ -209,14 +203,16 @@ zpool_clear_label(int fd)
}
}
- /* Clear the L2ARC header. */
- if (clear_l2arc_header &&
- pwrite64(fd, l2dhdr, sizeof (l2arc_dev_hdr_phys_t),
- VDEV_LABEL_START_SIZE) == sizeof (l2arc_dev_hdr_phys_t))
+ if (clear_l2arc_header) {
+ _Static_assert(sizeof (*label) >= sizeof (l2arc_dev_hdr_phys_t),
+ "label < l2arc_dev_hdr_phys_t");
+ memset(label, 0, sizeof (l2arc_dev_hdr_phys_t));
+ if (pwrite64(fd, label, sizeof (l2arc_dev_hdr_phys_t),
+ VDEV_LABEL_START_SIZE) == sizeof (l2arc_dev_hdr_phys_t))
header_cleared = B_TRUE;
+ }
free(label);
- free(l2dhdr);
if (labels_cleared == 0)
return (-1);