8567 Inconsistent return value in zpool_read_label
illumos/illumos-gate@c861bfbd77
c861bfbd77
https://www.illumos.org/issues/8567
If fstat64 fails, pread64 fails, or the label is unintelligible,
zpool_read_label will return 0. But if malloc fails, it will return -1. For
consistency, it should always return -1 on failure or 0 on success.
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Alan Somers <asomers@gmail.com>
This commit is contained in:
parent
c014f2f95b
commit
035e679e27
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user