Print this page
5981 Deadlock in dmu_objset_find_dp


1729         dsl_dataset_rele(ds, FTAG);
1730 
1731 out:
1732         if (err != 0) {
1733                 mutex_enter(dcp->dc_error_lock);
1734                 /* only keep first error */
1735                 if (*dcp->dc_error == 0)
1736                         *dcp->dc_error = err;
1737                 mutex_exit(dcp->dc_error_lock);
1738         }
1739 
1740         kmem_free(dcp, sizeof(*dcp));
1741 }
1742 
1743 static void
1744 dmu_objset_find_dp_cb(void *arg)
1745 {
1746         dmu_objset_find_ctx_t *dcp = arg;
1747         dsl_pool_t *dp = dcp->dc_dp;
1748 
1749         dsl_pool_config_enter(dp, FTAG);












1750 
1751         dmu_objset_find_dp_impl(dcp);
1752 
1753         dsl_pool_config_exit(dp, FTAG);
1754 }
1755 
1756 /*
1757  * Find objsets under and including ddobj, call func(ds) on each.
1758  * The order for the enumeration is completely undefined.
1759  * func is called with dsl_pool_config held.
1760  */
1761 int
1762 dmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj,
1763     int func(dsl_pool_t *, dsl_dataset_t *, void *), void *arg, int flags)
1764 {
1765         int error = 0;
1766         taskq_t *tq = NULL;
1767         int ntasks;
1768         dmu_objset_find_ctx_t *dcp;
1769         kmutex_t err_lock;




1729         dsl_dataset_rele(ds, FTAG);
1730 
1731 out:
1732         if (err != 0) {
1733                 mutex_enter(dcp->dc_error_lock);
1734                 /* only keep first error */
1735                 if (*dcp->dc_error == 0)
1736                         *dcp->dc_error = err;
1737                 mutex_exit(dcp->dc_error_lock);
1738         }
1739 
1740         kmem_free(dcp, sizeof(*dcp));
1741 }
1742 
1743 static void
1744 dmu_objset_find_dp_cb(void *arg)
1745 {
1746         dmu_objset_find_ctx_t *dcp = arg;
1747         dsl_pool_t *dp = dcp->dc_dp;
1748 
1749         /*
1750          * We need to get a pool_config_lock here, as there are several
1751          * asssert(pool_config_held) down the stack. Getting a lock via
1752          * dsl_pool_config_enter is risky, as it might be stalled by a
1753          * pending writer. This would deadlock, as the write lock can
1754          * only be granted when our parent thread gives up the lock.
1755          * The _prio interface gives us priority over a pending writer.
1756          * On the other hand, we don't risk to stall any pending writers,
1757          * as the parent thread already holds a config lock. We give up
1758          * our lock before the parent does, so in effect we do not prolong
1759          * the waiting time for the writer.
1760          */
1761         dsl_pool_config_enter_prio(dp, FTAG);
1762 
1763         dmu_objset_find_dp_impl(dcp);
1764 
1765         dsl_pool_config_exit(dp, FTAG);
1766 }
1767 
1768 /*
1769  * Find objsets under and including ddobj, call func(ds) on each.
1770  * The order for the enumeration is completely undefined.
1771  * func is called with dsl_pool_config held.
1772  */
1773 int
1774 dmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj,
1775     int func(dsl_pool_t *, dsl_dataset_t *, void *), void *arg, int flags)
1776 {
1777         int error = 0;
1778         taskq_t *tq = NULL;
1779         int ntasks;
1780         dmu_objset_find_ctx_t *dcp;
1781         kmutex_t err_lock;