summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Khasanov <[email protected]>2013-07-05 17:44:53 +0700
committerBrian Behlendorf <[email protected]>2013-07-09 15:42:27 -0700
commit51a3ae72d23d89d35a4a67059b39e870d66a2495 (patch)
treedc5c87715c7c6af02d3a68dba9af520ebbfbf047
parent50210587563bb37c48d2624d11e158ab3ad30715 (diff)
Readd zpool_clear_label() from OpenSolaris
This patch restores the zpool_clear_label() function from OpenSolaris. This was removed by commit d603ed6 because it wasn't clear we had a use for it in ZoL. However, this functionality is a prerequisite for adding the 'zpool labelclear' command from FreeBSD. As part of bringing this change in the zpool_clear_label() function was changed to use fstat64_blk(2) for compatibility with Linux. Signed-off-by: Brian Behlendorf <[email protected]> Issue #1126
-rw-r--r--lib/libzfs/libzfs_import.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c
index 791aaad53..58b6043be 100644
--- a/lib/libzfs/libzfs_import.c
+++ b/lib/libzfs/libzfs_import.c
@@ -900,6 +900,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_blk(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);
+}
+
#ifdef HAVE_LIBBLKID
/*
* Use libblkid to quickly search for zfs devices