Author: asomers
Date: Wed Dec  9 20:06:37 2020
New Revision: 368491
URL: https://svnweb.freebsd.org/changeset/base/368491

Log:
  ZFS: fix spurious EBUSY after zfs receive to an existing dataset
  
  If you do a "zfs send -p <src> | zfs receive -F <dst>" to an existing but
  empty dataset, the receive will complete successfully but spuriously fail
  with exit status 1 and the message "cannot mount 'pool/dataset': mountpoint
  or dataset is busy".
  
  The root cause is a merge error made in r344569 and MFCed in r345578, which
  merged changes a10d50f999 and e63ac16d25 from ZoL.  The merge:
  * failed to flip a == to an != like the upstream change did, and
  * Left out one chunk
  
  Direct commit to stable/12 because head has moved on to OpenZFS.
  
  PR:           251694
  Reviewed by:  bapt
  Sponsored by: Axcient

Modified:
  stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c

Modified: stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c
==============================================================================
--- stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c       
Wed Dec  9 18:43:58 2020        (r368490)
+++ stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c       
Wed Dec  9 20:06:37 2020        (r368491)
@@ -895,13 +895,25 @@ libzfs_mnttab_add(libzfs_handle_t *hdl, const char *sp
        mnttab_node_t *mtn;
 
        pthread_mutex_lock(&hdl->libzfs_mnttab_cache_lock);
-       if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0) {
+       if (avl_numnodes(&hdl->libzfs_mnttab_cache) != 0) {
                mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
                mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
                mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
                mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
                mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
-               avl_add(&hdl->libzfs_mnttab_cache, mtn);
+               /*
+                * Another thread may have already added this entry
+                * via libzfs_mnttab_update. If so we should skip it.
+                */
+               if (avl_find(&hdl->libzfs_mnttab_cache, mtn, NULL) != NULL) {
+                       free(mtn->mtn_mt.mnt_special);
+                       free(mtn->mtn_mt.mnt_mountp);
+                       free(mtn->mtn_mt.mnt_fstype);
+                       free(mtn->mtn_mt.mnt_mntopts);
+                       free(mtn);
+               } else {
+                       avl_add(&hdl->libzfs_mnttab_cache, mtn);
+               }
        }
        pthread_mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 }              
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to