[Midnightbsd-cvs] src [8214] trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c: zfs: allow a zvol to be used as a pool vdev, again
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Sep 17 16:21:30 EDT 2016
Revision: 8214
http://svnweb.midnightbsd.org/src/?rev=8214
Author: laffer1
Date: 2016-09-17 16:21:30 -0400 (Sat, 17 Sep 2016)
Log Message:
-----------
zfs: allow a zvol to be used as a pool vdev, again
Modified Paths:
--------------
trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
Modified: trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
===================================================================
--- trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c 2016-09-17 20:21:07 UTC (rev 8213)
+++ trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c 2016-09-17 20:21:30 UTC (rev 8214)
@@ -875,20 +875,28 @@
{
zvol_state_t *zv;
int err = 0;
+ boolean_t locked = B_FALSE;
- if (MUTEX_HELD(&spa_namespace_lock)) {
- /*
- * If the spa_namespace_lock is being held, it means that ZFS
- * is trying to open ZVOL as its VDEV. This is not supported.
- */
- return (EOPNOTSUPP);
+ /*
+ * Protect against recursively entering spa_namespace_lock
+ * when spa_open() is used for a pool on a (local) ZVOL(s).
+ * This is needed since we replaced upstream zfsdev_state_lock
+ * with spa_namespace_lock in the ZVOL code.
+ * We are using the same trick as spa_open().
+ * Note that calls in zvol_first_open which need to resolve
+ * pool name to a spa object will enter spa_open()
+ * recursively, but that function already has all the
+ * necessary protection.
+ */
+ if (!MUTEX_HELD(&spa_namespace_lock)) {
+ mutex_enter(&spa_namespace_lock);
+ locked = B_TRUE;
}
- mutex_enter(&spa_namespace_lock);
-
zv = pp->private;
if (zv == NULL) {
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (ENXIO);
}
@@ -895,7 +903,8 @@
if (zv->zv_total_opens == 0)
err = zvol_first_open(zv);
if (err) {
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (err);
}
if ((flag & FWRITE) && (zv->zv_flags & ZVOL_RDONLY)) {
@@ -917,13 +926,15 @@
#endif
zv->zv_total_opens += count;
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (err);
out:
if (zv->zv_total_opens == 0)
zvol_last_close(zv);
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (err);
}
@@ -933,12 +944,18 @@
{
zvol_state_t *zv;
int error = 0;
+ boolean_t locked = B_FALSE;
- mutex_enter(&spa_namespace_lock);
+ /* See comment in zvol_open(). */
+ if (!MUTEX_HELD(&spa_namespace_lock)) {
+ mutex_enter(&spa_namespace_lock);
+ locked = B_TRUE;
+ }
zv = pp->private;
if (zv == NULL) {
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (ENXIO);
}
@@ -961,7 +978,8 @@
if (zv->zv_total_opens == 0)
zvol_last_close(zv);
- mutex_exit(&spa_namespace_lock);
+ if (locked)
+ mutex_exit(&spa_namespace_lock);
return (error);
}
More information about the Midnightbsd-cvs
mailing list