Neil Perrin wrote: > > Chris Kirby wrote: >>But doesn't the rw_enter code block if there's a waiting >>writer? In other words, can't we cause a deadlock >>if we already hold the read lock, there's a waiting writer, >>and we try to grab the read lock again? >> >>-Chris > > > I agree. As a thread, there's no way to determine if I already hold > the read lock and regrabbing it can deadlock as you describe. > The only options I see are for the callers to grab it or pass > down an indication that they have it.
It looks like there are currently 30 callers of dsl_dataset_open_obj. The only callers from open context that don't grab the lock are dsl_dataset_create_root and dsl_dataset_snapshot_rename_check. In sync context, we either have no lock or we have the write lock. So if we fix up dsl_dataset_create_root to grab the lock; and change dsl_dataset_snapshot_rename_check not to do any work unless we're syncing, I think we can say this: need_lock = !RW_WRITE_HELD && dsl_pool_sync_context(dp); Does that make sense? It has to be less painful than adding an indication that the caller already holds the lock. -Chris