summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2017-08-07 14:17:22 -0600
committerPrakash Surya <prakash.surya@delphix.com>2017-09-15 09:32:54 -0700
commitc861bfbd77c4ae780a0341e9cb6926d8b74341cf (patch)
tree32b49873d45867654af081ac0a5d308adcf968d4
parenta141dbd6230b88bf7da3b673ca0f9b46918d5684 (diff)
downloadillumos-joyent-c861bfbd77c4ae780a0341e9cb6926d8b74341cf.tar.gz
8567 Inconsistent return value in zpool_read_label
Reviewed by: Prakash Surya <prakash.surya@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r--usr/src/cmd/fs.d/zfs/fstyp/fstyp.c3
-rw-r--r--usr/src/cmd/zpool/zpool_main.c2
-rw-r--r--usr/src/lib/libzfs/common/libzfs_import.c9
3 files changed, 7 insertions, 7 deletions
diff --git a/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c b/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
index 53bfda70c5..30f86375e7 100644
--- a/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
+++ b/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
@@ -89,8 +89,7 @@ fstyp_mod_ident(fstyp_mod_handle_t handle)
uint64_t u64;
char buf[64];
- if (zpool_read_label(h->fd, &h->config) != 0 ||
- h->config == NULL) {
+ if (zpool_read_label(h->fd, &h->config) != 0) {
return (FSTYP_ERR_NO_MATCH);
}
diff --git a/usr/src/cmd/zpool/zpool_main.c b/usr/src/cmd/zpool/zpool_main.c
index 2ccc609629..d3af687dc4 100644
--- a/usr/src/cmd/zpool/zpool_main.c
+++ b/usr/src/cmd/zpool/zpool_main.c
@@ -708,7 +708,7 @@ zpool_do_labelclear(int argc, char **argv)
return (1);
}
- if (zpool_read_label(fd, &config) != 0 || config == NULL) {
+ if (zpool_read_label(fd, &config) != 0) {
(void) fprintf(stderr,
gettext("failed to read label from %s\n"), vdev);
return (1);
diff --git a/usr/src/lib/libzfs/common/libzfs_import.c b/usr/src/lib/libzfs/common/libzfs_import.c
index 496ba2c321..7fbd9faf0b 100644
--- a/usr/src/lib/libzfs/common/libzfs_import.c
+++ b/usr/src/lib/libzfs/common/libzfs_import.c
@@ -841,6 +841,7 @@ label_offset(uint64_t size, int l)
/*
* Given a file descriptor, read the label information and return an nvlist
* describing the configuration, if there is one.
+ * Return 0 on success, or -1 on failure
*/
int
zpool_read_label(int fd, nvlist_t **config)
@@ -853,7 +854,7 @@ zpool_read_label(int fd, nvlist_t **config)
*config = NULL;
if (fstat64(fd, &statbuf) == -1)
- return (0);
+ return (-1);
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
if ((label = malloc(sizeof (vdev_label_t))) == NULL)
@@ -887,7 +888,7 @@ zpool_read_label(int fd, nvlist_t **config)
free(label);
*config = NULL;
- return (0);
+ return (-1);
}
typedef struct rdsk_node {
@@ -1052,7 +1053,7 @@ zpool_open_func(void *arg)
check_slices(rn->rn_avl, fd, rn->rn_name);
}
- if ((zpool_read_label(fd, &config)) != 0) {
+ if ((zpool_read_label(fd, &config)) != 0 && errno == ENOMEM) {
(void) close(fd);
(void) no_memory(rn->rn_hdl);
return;
@@ -1517,7 +1518,7 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
*inuse = B_FALSE;
- if (zpool_read_label(fd, &config) != 0) {
+ if (zpool_read_label(fd, &config) != 0 && errno == ENOMEM) {
(void) no_memory(hdl);
return (-1);
}