From 096d22d43da2758693a6df66ce7d9ab54c9d464c Mon Sep 17 00:00:00 2001 From: Eric Schrock Date: Wed, 21 Oct 2009 16:03:06 -0700 Subject: 6893087 removing and inserting a faulted vdev clears faulted state 6893088 new ereports need to be generated when clearing a vdev 6893090 clearing a vdev should automatically detach spare 6893099 zpool_clear_label() would be useful --- usr/src/lib/libzfs/common/libzfs_import.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'usr/src/lib/libzfs/common/libzfs_import.c') diff --git a/usr/src/lib/libzfs/common/libzfs_import.c b/usr/src/lib/libzfs/common/libzfs_import.c index f5793390ea..8705361b6c 100644 --- a/usr/src/lib/libzfs/common/libzfs_import.c +++ b/usr/src/lib/libzfs/common/libzfs_import.c @@ -897,6 +897,36 @@ zpool_read_label(int fd, nvlist_t **config) return (0); } +/* + * Given a file descriptor, clear (zero) the label information. This function + * is currently only used in the appliance stack as part of the ZFS sysevent + * module. + */ +int +zpool_clear_label(int fd) +{ + struct stat64 statbuf; + int l; + vdev_label_t *label; + uint64_t size; + + if (fstat64(fd, &statbuf) == -1) + return (0); + size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t); + + if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL) + return (-1); + + for (l = 0; l < VDEV_LABELS; l++) { + if (pwrite64(fd, label, sizeof (vdev_label_t), + label_offset(size, l)) != sizeof (vdev_label_t)) + return (-1); + } + + free(label); + return (0); +} + /* * Given a list of directories to search, find all pools stored on disk. This * includes partial pools which are not available to import. If no args are -- cgit v1.2.3