aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2019-03-21 10:13:01 -0700
committerGitHub <[email protected]>2019-03-21 10:13:01 -0700
commit066da71e7fe32f569736b53454b034937d0d3813 (patch)
tree2b4723e49c2e4720cb600da78cc5b60f618742ba /cmd
parent304d469dcdcb47a6c4e993a62007a8b7c81a212a (diff)
Improve `zpool labelclear`
1) As implemented the `zpool labelclear` command overwrites the calculated offsets of all four vdev labels even when only a single valid label is found. If the device as been re-purposed but still contains a valid label this can result in space no longer owned by ZFS being zeroed. Prevent this by verifying every label removed is intact before it's overwritten. 2) Address a small bug in zpool_do_labelclear() which prevented labelclear from working on file vdevs. Only block devices support BLKFLSBUF, try the ioctl() but when it's reported as unsupported this should not be fatal. 3) Fix `zpool labelclear` so it can be run on vdevs which were removed from the pool with `zpool remove`. Additionally, allow intact but partial labels to be cleared as in the case of a failed `zpool attach` or `zpool replace`. 4) Remove LABELCLEAR and LABELREAD variables for test cases. Reviewed-by: Matt Ahrens <[email protected]> Reviewed-by: Tim Chase <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #8500 Closes #8373 Closes #6261
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 61403a173..3607656e0 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -1113,13 +1113,18 @@ zpool_do_labelclear(int argc, char **argv)
return (1);
}
- if (ioctl(fd, BLKFLSBUF) != 0)
+ /*
+ * Flush all dirty pages for the block device. This should not be
+ * fatal when the device does not support BLKFLSBUF as would be the
+ * case for a file vdev.
+ */
+ if ((ioctl(fd, BLKFLSBUF) != 0) && (errno != ENOTTY))
(void) fprintf(stderr, gettext("failed to invalidate "
"cache for %s: %s\n"), vdev, strerror(errno));
- if (zpool_read_label(fd, &config, NULL) != 0 || config == NULL) {
+ if (zpool_read_label(fd, &config, NULL) != 0) {
(void) fprintf(stderr,
- gettext("failed to check state for %s\n"), vdev);
+ gettext("failed to read label from %s\n"), vdev);
ret = 1;
goto errout;
}