--- old/usr/src/lib/libzpool/common/kernel.c	2012-07-30 16:07:06.939607123 +0400
+++ new/usr/src/lib/libzpool/common/kernel.c	2012-07-30 16:07:06.403607110 +0400
@@ -256,14 +256,21 @@
 	VERIFY(cond_destroy(cv) == 0);
 }
 
-void
-cv_wait(kcondvar_t *cv, kmutex_t *mp)
+int
+cv_wait_sig(kcondvar_t *cv, kmutex_t *mp)
 {
 	ASSERT(mutex_owner(mp) == curthread);
 	mp->m_owner = NULL;
 	int ret = cond_wait(cv, &mp->m_lock);
 	VERIFY(ret == 0 || ret == EINTR);
 	mp->m_owner = curthread;
+	return (ret == EINTR ? 0 : 1);
+}
+
+void
+cv_wait(kcondvar_t *cv, kmutex_t *mp)
+{
+	(void) cv_wait_sig(cv, mp);
 }
 
 clock_t
--- old/usr/src/lib/libzpool/common/sys/zfs_context.h	2012-07-30 16:07:07.919607149 +0400
+++ new/usr/src/lib/libzpool/common/sys/zfs_context.h	2012-07-30 16:07:07.351607134 +0400
@@ -300,6 +300,7 @@
 extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
 extern void cv_destroy(kcondvar_t *cv);
 extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
+extern int  cv_wait_sig(kcondvar_t *cv, kmutex_t *mp);
 extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
 extern void cv_signal(kcondvar_t *cv);
 extern void cv_broadcast(kcondvar_t *cv);
--- old/usr/src/uts/common/fs/zfs/dmu_send.c	2012-07-30 16:07:08.855607172 +0400
+++ new/usr/src/uts/common/fs/zfs/dmu_send.c	2012-07-30 16:07:08.291607158 +0400
@@ -850,12 +850,6 @@
 			return (EINVAL);
 		}
 
-		/* must not have an incremental recv already in progress */
-		if (!mutex_tryenter(&ds->ds_recvlock)) {
-			dsl_dataset_rele(ds, dmu_recv_tag);
-			return (EBUSY);
-		}
-
 		/* tmp clone name is: tofs/%tosnap" */
 		(void) snprintf(rbsa.clonelastname, sizeof (rbsa.clonelastname),
 		    "%%%s", tosnap);
@@ -863,12 +857,12 @@
 		err = dsl_sync_task_do(ds->ds_dir->dd_pool,
 		    recv_existing_check, recv_existing_sync, ds, &rbsa, 5);
 		if (err) {
-			mutex_exit(&ds->ds_recvlock);
 			dsl_dataset_rele(ds, dmu_recv_tag);
 			return (err);
 		}
-		drc->drc_logical_ds = ds;
+		drc->drc_logical_dsobj = ds->ds_object;
 		drc->drc_real_ds = rbsa.ds;
+		dsl_dataset_rele(ds, dmu_recv_tag);
 	} else if (err == ENOENT) {
 		/* target fs does not exist; must be a full backup or clone */
 		char *cp;
@@ -898,7 +892,7 @@
 		dsl_dataset_rele(ds, FTAG);
 		if (err)
 			return (err);
-		drc->drc_logical_ds = drc->drc_real_ds = rbsa.ds;
+		drc->drc_real_ds = rbsa.ds;
 		drc->drc_newfs = B_TRUE;
 	}
 
@@ -1528,10 +1522,6 @@
 
 		(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag,
 		    B_FALSE);
-		if (drc->drc_real_ds != drc->drc_logical_ds) {
-			mutex_exit(&drc->drc_logical_ds->ds_recvlock);
-			dsl_dataset_rele(drc->drc_logical_ds, dmu_recv_tag);
-		}
 	}
 
 	kmem_free(ra.buf, ra.bufsize);
@@ -1600,8 +1590,20 @@
 dmu_recv_existing_end(dmu_recv_cookie_t *drc)
 {
 	struct recvendsyncarg resa;
-	dsl_dataset_t *ds = drc->drc_logical_ds;
+	dsl_dataset_t *ds;
 	int err, myerr;
+	dsl_pool_t *dp = drc->drc_real_ds->ds_dir->dd_pool;
+
+	rw_enter(&dp->dp_config_rwlock, RW_READER);
+	err = dsl_dataset_own_obj(dp, drc->drc_logical_dsobj, FALSE,
+	    dmu_recv_tag, &ds);
+	rw_exit(&dp->dp_config_rwlock);
+
+	if (err) {
+		(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag,
+		    B_FALSE);
+		return (EBUSY);
+	}
 
 	/*
 	 * XXX hack; seems the ds is still dirty and dsl_pool_zil_clean()
@@ -1610,18 +1612,9 @@
 	 */
 	txg_wait_synced(ds->ds_dir->dd_pool, 0);
 
-	if (dsl_dataset_tryown(ds, FALSE, dmu_recv_tag)) {
-		err = dsl_dataset_clone_swap(drc->drc_real_ds, ds,
-		    drc->drc_force);
-		if (err)
-			goto out;
-	} else {
-		mutex_exit(&ds->ds_recvlock);
-		dsl_dataset_rele(ds, dmu_recv_tag);
-		(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag,
-		    B_FALSE);
-		return (EBUSY);
-	}
+	err = dsl_dataset_clone_swap(drc->drc_real_ds, ds, drc->drc_force);
+	if (err)
+		goto out;
 
 	resa.creation_time = drc->drc_drrb->drr_creation_time;
 	resa.toguid = drc->drc_drrb->drr_toguid;
@@ -1635,7 +1628,6 @@
 	}
 
 out:
-	mutex_exit(&ds->ds_recvlock);
 	if (err == 0 && drc->drc_guid_to_ds_map != NULL)
 		(void) add_ds_to_guidmap(drc->drc_guid_to_ds_map, ds);
 	dsl_dataset_disown(ds, dmu_recv_tag);
@@ -1648,7 +1640,7 @@
 dmu_recv_new_end(dmu_recv_cookie_t *drc)
 {
 	struct recvendsyncarg resa;
-	dsl_dataset_t *ds = drc->drc_logical_ds;
+	dsl_dataset_t *ds = drc->drc_real_ds;
 	int err;
 
 	/*
@@ -1679,7 +1671,7 @@
 int
 dmu_recv_end(dmu_recv_cookie_t *drc)
 {
-	if (drc->drc_logical_ds != drc->drc_real_ds)
+	if (!drc->drc_newfs)
 		return (dmu_recv_existing_end(drc));
 	else
 		return (dmu_recv_new_end(drc));
--- old/usr/src/uts/common/fs/zfs/dsl_dataset.c	2012-07-30 16:07:09.827607197 +0400
+++ new/usr/src/uts/common/fs/zfs/dsl_dataset.c	2012-07-30 16:07:09.291607184 +0400
@@ -289,7 +289,6 @@
 	ASSERT(!list_link_active(&ds->ds_synced_link));
 
 	mutex_destroy(&ds->ds_lock);
-	mutex_destroy(&ds->ds_recvlock);
 	mutex_destroy(&ds->ds_opening_lock);
 	rw_destroy(&ds->ds_rwlock);
 	cv_destroy(&ds->ds_exclusive_cv);
@@ -395,7 +394,6 @@
 		ds->ds_phys = dbuf->db_data;
 
 		mutex_init(&ds->ds_lock, NULL, MUTEX_DEFAULT, NULL);
-		mutex_init(&ds->ds_recvlock, NULL, MUTEX_DEFAULT, NULL);
 		mutex_init(&ds->ds_opening_lock, NULL, MUTEX_DEFAULT, NULL);
 		mutex_init(&ds->ds_sendstream_lock, NULL, MUTEX_DEFAULT, NULL);
 
@@ -415,7 +413,6 @@
 		}
 		if (err) {
 			mutex_destroy(&ds->ds_lock);
-			mutex_destroy(&ds->ds_recvlock);
 			mutex_destroy(&ds->ds_opening_lock);
 			rw_destroy(&ds->ds_rwlock);
 			cv_destroy(&ds->ds_exclusive_cv);
@@ -483,7 +480,6 @@
 				dsl_dataset_drop_ref(ds->ds_prev, ds);
 			dsl_dir_close(ds->ds_dir, ds);
 			mutex_destroy(&ds->ds_lock);
-			mutex_destroy(&ds->ds_recvlock);
 			mutex_destroy(&ds->ds_opening_lock);
 			rw_destroy(&ds->ds_rwlock);
 			cv_destroy(&ds->ds_exclusive_cv);
@@ -546,13 +542,15 @@
 	ASSERT(!RW_WRITE_HELD(&dp->dp_config_rwlock));
 	mutex_enter(&ds->ds_lock);
 	while (!rw_tryenter(&ds->ds_rwlock, RW_READER)) {
+		int rc;
+
 		rw_exit(&dp->dp_config_rwlock);
-		cv_wait(&ds->ds_exclusive_cv, &ds->ds_lock);
-		if (DSL_DATASET_IS_DESTROYED(ds)) {
+		rc = cv_wait_sig(&ds->ds_exclusive_cv, &ds->ds_lock);
+		if (!rc || DSL_DATASET_IS_DESTROYED(ds)) {
 			mutex_exit(&ds->ds_lock);
 			dsl_dataset_drop_ref(ds, tag);
 			rw_enter(&dp->dp_config_rwlock, RW_READER);
-			return (ENOENT);
+			return (rc ? ENOENT : EINTR);
 		}
 		/*
 		 * The dp_config_rwlock lives above the ds_lock. And
--- old/usr/src/uts/common/fs/zfs/sys/dmu.h	2012-07-30 16:07:10.935607225 +0400
+++ new/usr/src/uts/common/fs/zfs/sys/dmu.h	2012-07-30 16:07:10.395607212 +0400
@@ -802,7 +802,7 @@
 	 * into the "real" temporary clone, and then switching it with
 	 * the "logical" target.
 	 */
-	struct dsl_dataset *drc_logical_ds;
+	uint64_t drc_logical_dsobj;
 	struct dsl_dataset *drc_real_ds;
 	struct drr_begin *drc_drrb;
 	char *drc_tosnap;
--- old/usr/src/uts/common/fs/zfs/sys/dsl_dataset.h	2012-07-30 16:07:11.851607249 +0400
+++ new/usr/src/uts/common/fs/zfs/sys/dsl_dataset.h	2012-07-30 16:07:11.307607235 +0400
@@ -125,9 +125,6 @@
 	dsl_deadlist_t ds_deadlist;
 	bplist_t ds_pending_deadlist;
 
-	/* to protect against multiple concurrent incremental recv */
-	kmutex_t ds_recvlock;
-
 	/* protected by lock on pool's dp_dirty_datasets list */
 	txg_node_t ds_dirty_link;
 	list_node_t ds_synced_link;
--- old/usr/src/uts/common/fs/zfs/zfs_ioctl.c	2012-07-30 16:07:12.759607272 +0400
+++ new/usr/src/uts/common/fs/zfs/zfs_ioctl.c	2012-07-30 16:07:12.219607259 +0400
@@ -3227,21 +3227,32 @@
 	int error;
 	zfsvfs_t *zfsvfs;
 	char *clone_name;
+	boolean_t umounted = B_FALSE;
+
+	if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
+		error = zfs_suspend_fs(zfsvfs);
+		if (error) {
+			VFS_RELE(zfsvfs->z_vfs);
+			return (error);
+		}
+
+		umounted = B_TRUE;
+	}
 
 	error = dsl_dataset_hold(zc->zc_name, FTAG, &ds);
 	if (error)
-		return (error);
+		goto out_vfs;
 
 	/* must not be a snapshot */
 	if (dsl_dataset_is_snapshot(ds)) {
-		dsl_dataset_rele(ds, FTAG);
-		return (EINVAL);
+		error = EINVAL;
+		goto out_ds;
 	}
 
 	/* must have a most recent snapshot */
 	if (ds->ds_phys->ds_prev_snap_txg < TXG_INITIAL) {
-		dsl_dataset_rele(ds, FTAG);
-		return (EINVAL);
+		error = EINVAL;
+		goto out_ds;
 	}
 
 	/*
@@ -3259,23 +3270,15 @@
 	/*
 	 * Do clone swap.
 	 */
-	if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
-		error = zfs_suspend_fs(zfsvfs);
-		if (error == 0) {
-			int resume_err;
-
-			if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
-				error = dsl_dataset_clone_swap(clone, ds,
-				    B_TRUE);
-				dsl_dataset_disown(ds, FTAG);
-				ds = NULL;
-			} else {
-				error = EBUSY;
-			}
-			resume_err = zfs_resume_fs(zfsvfs, zc->zc_name);
-			error = error ? error : resume_err;
+	if (umounted) {
+		if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
+			error = dsl_dataset_clone_swap(clone, ds,
+			    B_TRUE);
+			dsl_dataset_disown(ds, FTAG);
+			ds = NULL;
+		} else {
+			error = EBUSY;
 		}
-		VFS_RELE(zfsvfs->z_vfs);
 	} else {
 		if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
 			error = dsl_dataset_clone_swap(clone, ds, B_TRUE);
@@ -3293,8 +3296,18 @@
 
 out:
 	strfree(clone_name);
+out_ds:
 	if (ds)
 		dsl_dataset_rele(ds, FTAG);
+out_vfs:
+	if (umounted) {
+		int resume_err;
+
+		resume_err = zfs_resume_fs(zfsvfs, zc->zc_name);
+		error = error ? error : resume_err;
+		VFS_RELE(zfsvfs->z_vfs);
+	}
+
 	return (error);
 }
 
@@ -3701,7 +3714,12 @@
 	if (props) {
 		nvlist_t *errlist;
 
-		if (dmu_objset_from_ds(drc.drc_logical_ds, &os) == 0) {
+		if (drc.drc_newfs)
+			error = dmu_objset_from_ds(drc.drc_real_ds, &os);
+		else
+			error = dmu_objset_hold(tofs, FTAG, &os);
+
+		if (error == 0) {
 			if (drc.drc_newfs) {
 				if (spa_version(os->os_spa) >=
 				    SPA_VERSION_RECVD_PROPS)
@@ -3714,6 +3732,9 @@
 				zc->zc_obj |= ZPROP_ERR_NOCLEAR;
 			}
 			dsl_prop_set_hasrecvd(os);
+
+			if (!drc.drc_newfs)
+				dmu_objset_rele(os, FTAG);
 		} else if (!drc.drc_newfs) {
 			zc->zc_obj |= ZPROP_ERR_NOCLEAR;
 		}
