Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Mar 2018 20:28:49 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r330522 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
Message-ID:  <201803052028.w25KSn1g079618@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Mon Mar  5 20:28:49 2018
New Revision: 330522
URL: https://svnweb.freebsd.org/changeset/base/330522

Log:
  MFC r326401:
  
  Fix assertion when ZFS fails to open certain devices
  
  "panic: vdev_geom_close_locked: cp->private is NULL"
  This panic will result if ZFS fails to open a device due to either of the
  following reasons:
  
  1) The device's sector size is greater than 8KB.
  2) ZFS wants to open the device RW, but it can't be opened for writing.
  
  The solution is to change the initialization order to ensure that the
  assertion will be satisfied.
  
  PR:		221066
  Reported by:	David NewHamlet <wheelcomplex@gmail.com>
  Reviewed by:	avg
  Sponsored by:	Spectra Logic Corp
  Differential Revision:	https://reviews.freebsd.org/D13278

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c	Mon Mar  5 20:03:45 2018	(r330521)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c	Mon Mar  5 20:28:49 2018	(r330522)
@@ -851,35 +851,10 @@ vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *
 	if (cp == NULL) {
 		ZFS_LOG(1, "Vdev %s not found.", vd->vdev_path);
 		error = ENOENT;
-	} else if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
-	    !ISP2(cp->provider->sectorsize)) {
-		ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
-		    cp->provider->name);
-
-		vdev_geom_close_locked(vd);
-		error = EINVAL;
-		cp = NULL;
-	} else if (cp->acw == 0 && (spa_mode(vd->vdev_spa) & FWRITE) != 0) {
-		int i;
-
-		for (i = 0; i < 5; i++) {
-			error = g_access(cp, 0, 1, 0);
-			if (error == 0)
-				break;
-			g_topology_unlock();
-			tsleep(vd, 0, "vdev", hz / 2);
-			g_topology_lock();
-		}
-		if (error != 0) {
-			printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
-			    cp->provider->name, error);
-			vdev_geom_close_locked(vd);
-			cp = NULL;
-		}
-	}
-	if (cp != NULL) {
+	} else {
 		struct consumer_priv_t *priv;
 		struct consumer_vdev_elem *elem;
+		int spamode;
 
 		priv = (struct consumer_priv_t*)&cp->private;
 		if (cp->private == NULL)
@@ -887,6 +862,34 @@ vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *
 		elem = g_malloc(sizeof(*elem), M_WAITOK|M_ZERO);
 		elem->vd = vd;
 		SLIST_INSERT_HEAD(priv, elem, elems);
+
+		spamode = spa_mode(vd->vdev_spa);
+		if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
+		    !ISP2(cp->provider->sectorsize)) {
+			ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
+			    cp->provider->name);
+
+			vdev_geom_close_locked(vd);
+			error = EINVAL;
+			cp = NULL;
+		} else if (cp->acw == 0 && (spamode & FWRITE) != 0) {
+			int i;
+
+			for (i = 0; i < 5; i++) {
+				error = g_access(cp, 0, 1, 0);
+				if (error == 0)
+					break;
+				g_topology_unlock();
+				tsleep(vd, 0, "vdev", hz / 2);
+				g_topology_lock();
+			}
+			if (error != 0) {
+				printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
+				    cp->provider->name, error);
+				vdev_geom_close_locked(vd);
+				cp = NULL;
+			}
+		}
 	}
 
 	/* Fetch initial physical path information for this device. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803052028.w25KSn1g079618>