svn commit: r323791 - in head/cddl/contrib/opensolaris: cmd/zpool lib/libzfs/common

Andriy Gapon avg at FreeBSD.org
Wed Sep 20 07:23:51 UTC 2017


Author: avg
Date: Wed Sep 20 07:23:50 2017
New Revision: 323791
URL: https://svnweb.freebsd.org/changeset/base/323791

Log:
  MFV r323790: 8567 Inconsistent return value in zpool_read_label
  
  illumos/illumos-gate at c861bfbd77c4ae780a0341e9cb6926d8b74341cf
  https://github.com/illumos/illumos-gate/commit/c861bfbd77c4ae780a0341e9cb6926d8b74341cf
  
  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 at delphix.com>
  Reviewed by: Matthew Ahrens <mahrens at delphix.com>
  Approved by: Robert Mustacchi <rm at joyent.com>
  Author: Alan Somers <asomers at gmail.com>
  
  MFC after:	2 weeks

Modified:
  head/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
  head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
Directory Properties:
  head/cddl/contrib/opensolaris/   (props changed)
  head/cddl/contrib/opensolaris/lib/libzfs/   (props changed)

Modified: head/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
==============================================================================
--- head/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c	Wed Sep 20 07:18:09 2017	(r323790)
+++ head/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c	Wed Sep 20 07:23:50 2017	(r323791)
@@ -705,7 +705,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);

Modified: head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
==============================================================================
--- head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c	Wed Sep 20 07:18:09 2017	(r323790)
+++ head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c	Wed Sep 20 07:23:50 2017	(r323791)
@@ -865,6 +865,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)
@@ -877,7 +878,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)
@@ -911,7 +912,7 @@ zpool_read_label(int fd, nvlist_t **config)
 
 	free(label);
 	*config = NULL;
-	return (0);
+	return (-1);
 }
 
 /*
@@ -1148,7 +1149,7 @@ zpool_open_func(void *arg)
 	}
 #endif	/* illumos */
 
-	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;
@@ -1649,7 +1650,7 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_
 
 	*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);
 	}


More information about the svn-src-all mailing list