339 }
340
341 int
342 dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, void *tag,
343 dsl_dataset_t **dsp)
344 {
345 objset_t *mos = dp->dp_meta_objset;
346 dmu_buf_t *dbuf;
347 dsl_dataset_t *ds;
348 int err;
349 dmu_object_info_t doi;
350
351 ASSERT(dsl_pool_config_held(dp));
352
353 err = dmu_bonus_hold(mos, dsobj, tag, &dbuf);
354 if (err != 0)
355 return (err);
356
357 /* Make sure dsobj has the correct object type. */
358 dmu_object_info_from_db(dbuf, &doi);
359 if (doi.doi_type != DMU_OT_DSL_DATASET)
360 return (SET_ERROR(EINVAL));
361
362 ds = dmu_buf_get_user(dbuf);
363 if (ds == NULL) {
364 dsl_dataset_t *winner = NULL;
365
366 ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_SLEEP);
367 ds->ds_dbuf = dbuf;
368 ds->ds_object = dsobj;
369 ds->ds_phys = dbuf->db_data;
370
371 mutex_init(&ds->ds_lock, NULL, MUTEX_DEFAULT, NULL);
372 mutex_init(&ds->ds_opening_lock, NULL, MUTEX_DEFAULT, NULL);
373 mutex_init(&ds->ds_sendstream_lock, NULL, MUTEX_DEFAULT, NULL);
374 refcount_create(&ds->ds_longholds);
375
376 bplist_create(&ds->ds_pending_deadlist);
377 dsl_deadlist_open(&ds->ds_deadlist,
378 mos, ds->ds_phys->ds_deadlist_obj);
379
380 list_create(&ds->ds_sendstreams, sizeof (dmu_sendarg_t),
|
339 }
340
341 int
342 dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, void *tag,
343 dsl_dataset_t **dsp)
344 {
345 objset_t *mos = dp->dp_meta_objset;
346 dmu_buf_t *dbuf;
347 dsl_dataset_t *ds;
348 int err;
349 dmu_object_info_t doi;
350
351 ASSERT(dsl_pool_config_held(dp));
352
353 err = dmu_bonus_hold(mos, dsobj, tag, &dbuf);
354 if (err != 0)
355 return (err);
356
357 /* Make sure dsobj has the correct object type. */
358 dmu_object_info_from_db(dbuf, &doi);
359 if (doi.doi_type != DMU_OT_DSL_DATASET) {
360 dmu_buf_rele(dbuf, tag);
361 return (SET_ERROR(EINVAL));
362 }
363
364 ds = dmu_buf_get_user(dbuf);
365 if (ds == NULL) {
366 dsl_dataset_t *winner = NULL;
367
368 ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_SLEEP);
369 ds->ds_dbuf = dbuf;
370 ds->ds_object = dsobj;
371 ds->ds_phys = dbuf->db_data;
372
373 mutex_init(&ds->ds_lock, NULL, MUTEX_DEFAULT, NULL);
374 mutex_init(&ds->ds_opening_lock, NULL, MUTEX_DEFAULT, NULL);
375 mutex_init(&ds->ds_sendstream_lock, NULL, MUTEX_DEFAULT, NULL);
376 refcount_create(&ds->ds_longholds);
377
378 bplist_create(&ds->ds_pending_deadlist);
379 dsl_deadlist_open(&ds->ds_deadlist,
380 mos, ds->ds_phys->ds_deadlist_obj);
381
382 list_create(&ds->ds_sendstreams, sizeof (dmu_sendarg_t),
|