-int
-zvol_remove_minor(const char *name)
-{
- zvol_state_t *zv;
- char namebuf[30];
-
- mutex_enter(&zvol_state_lock);
-
- if ((zv = zvol_minor_lookup(name)) == NULL) {
- mutex_exit(&zvol_state_lock);
- return (ENXIO);
- }
-
- if (zv->zv_total_opens != 0) {
- mutex_exit(&zvol_state_lock);
- return (EBUSY);
- }
-
- (void) sprintf(namebuf, "%uc,raw", zv->zv_minor);
- ddi_remove_minor_node(zfs_dip, namebuf);
-
- (void) sprintf(namebuf, "%uc", zv->zv_minor);
- ddi_remove_minor_node(zfs_dip, namebuf);
-
- VERIFY(dsl_prop_unregister(dmu_objset_ds(zv->zv_objset),
- "readonly", zvol_readonly_changed_cb, zv) == 0);
-
- zil_close(zv->zv_zilog);
- zv->zv_zilog = NULL;
- dmu_objset_close(zv->zv_objset);
- zv->zv_objset = NULL;
- avl_destroy(&zv->zv_znode.z_range_avl);
- mutex_destroy(&zv->zv_znode.z_range_lock);
-
- ddi_soft_state_free(zvol_state, zv->zv_minor);
-
- zvol_minors--;
-
- mutex_exit(&zvol_state_lock);
-
- return (0);
-}
-
-int
-zvol_prealloc(zvol_state_t *zv)
-{
- objset_t *os = zv->zv_objset;
- dmu_tx_t *tx;
- uint64_t refd, avail, usedobjs, availobjs;
- uint64_t resid = zv->zv_volsize;
- uint64_t off = 0;
-
- /* Check the space usage before attempting to allocate the space */
- dmu_objset_space(os, &refd, &avail, &usedobjs, &availobjs);
- if (avail < zv->zv_volsize)
- return (ENOSPC);
-
- /* Free old extents if they exist */
- zvol_free_extents(zv);
-
- while (resid != 0) {
- int error;
- uint64_t bytes = MIN(resid, SPA_MAXBLOCKSIZE);
-
- tx = dmu_tx_create(os);
- dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes);
- error = dmu_tx_assign(tx, TXG_WAIT);
- if (error) {
- dmu_tx_abort(tx);
- (void) dmu_free_long_range(os, ZVOL_OBJ, 0, off);
- return (error);
- }
- dmu_prealloc(os, ZVOL_OBJ, off, bytes, tx);
- dmu_tx_commit(tx);
- off += bytes;
- resid -= bytes;
- }
- txg_wait_synced(dmu_objset_pool(os), 0);
-
- return (0);
-}
-
-int
-zvol_update_volsize(zvol_state_t *zv, major_t maj, uint64_t volsize)