diff options
author | Yuri Pankov <[email protected]> | 2017-01-13 09:25:15 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-04-11 09:54:39 -0700 |
commit | dbb38f660509073f43284c6c745a4449ffd46385 (patch) | |
tree | a980a446a446b1e1d1291010653719f5b21fbf9c /cmd/zdb/zdb.c | |
parent | 047187c1bd4a893e7a89e8795fa8f4ecc3eb0732 (diff) |
OpenZFS 6865 - want zfs-tests cases for zpool labelclear command
Authored by: Yuri Pankov <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: John Kennedy <[email protected]>
Approved by: Robert Mustacchi <[email protected]>
Reviewed-by: loli10K <[email protected]>
Ported-by: Brian Behlendorf <[email protected]>
Porting Notes:
- Updated 'zpool labelclear' and 'zdb -l' such that they attempt
to find a vdev given solely its short name. This behavior is
consistent with the upstream OpenZFS code and the test cases
depend on it. The actual implementation differs slightly due
to device naming conventions on Linux.
- auto_online_001_pos, auto_replace_001_pos and add-o_ashift
test cases updated to expect failure when no label exists.
- read_efi_label() and zpool_label_disk_check() are read-only
operations and should use O_RDONLY at open time to enforce this.
- zpool_label_disk() and zpool_relabel_disk() write the partition
information using O_DIRECT an fsync() and page cache invalidation
to ensure a consistent view of the device.
- dump_label() in zdb should invalidate the page cache in order
to get the authoritative label from disk.
OpenZFS-issue: https://www.illumos.org/issues/6865
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/c95076c
Closes #5981
Diffstat (limited to 'cmd/zdb/zdb.c')
-rw-r--r-- | cmd/zdb/zdb.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index d5b8a7745..b58b709e7 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -2515,13 +2515,37 @@ dump_label(const char *dev) bzero(labels, sizeof (labels)); + /* + * Check if we were given absolute path and use it as is. + * Otherwise if the provided vdev name doesn't point to a file, + * try prepending expected disk paths and partition numbers. + */ (void) strlcpy(path, dev, sizeof (path)); + if (dev[0] != '/' && stat64(path, &statbuf) != 0) { + int error; + + error = zfs_resolve_shortname(dev, path, MAXPATHLEN); + if (error == 0 && zfs_dev_is_whole_disk(path)) { + if (zfs_append_partition(path, MAXPATHLEN) == -1) + error = ENOENT; + } + + if (error || (stat64(path, &statbuf) != 0)) { + (void) printf("failed to find device %s, try " + "specifying absolute path instead\n", dev); + return (1); + } + } if ((fd = open64(path, O_RDONLY)) < 0) { (void) printf("cannot open '%s': %s\n", path, strerror(errno)); exit(1); } + if (ioctl(fd, BLKFLSBUF) != 0) + (void) printf("failed to invalidate cache '%s' : %s\n", path, + strerror(errno)); + if (fstat64_blk(fd, &statbuf) != 0) { (void) printf("failed to stat '%s': %s\n", path, strerror(errno)); |