4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (C) 2008-2010 Lawrence Livermore National Security, LLC.
23 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
24 * Rewritten for Linux by Brian Behlendorf <behlendorf1@llnl.gov>.
27 * ZFS volume emulation driver.
29 * Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes.
30 * Volumes are accessed through the symbolic links named:
32 * /dev/<pool_name>/<dataset_name>
34 * Volumes are persistent through reboot and module load. No user command
35 * needs to be run before opening and using a device.
37 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
38 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
39 * Copyright (c) 2012, 2019 by Delphix. All rights reserved.
43 * Note on locking of zvol state structures.
45 * These structures are used to maintain internal state used to emulate block
46 * devices on top of zvols. In particular, management of device minor number
47 * operations - create, remove, rename, and set_snapdev - involves access to
48 * these structures. The zvol_state_lock is primarily used to protect the
49 * zvol_state_list. The zv->zv_state_lock is used to protect the contents
50 * of the zvol_state_t structures, as well as to make sure that when the
51 * time comes to remove the structure from the list, it is not in use, and
52 * therefore, it can be taken off zvol_state_list and freed.
54 * The zv_suspend_lock was introduced to allow for suspending I/O to a zvol,
55 * e.g. for the duration of receive and rollback operations. This lock can be
56 * held for significant periods of time. Given that it is undesirable to hold
57 * mutexes for long periods of time, the following lock ordering applies:
58 * - take zvol_state_lock if necessary, to protect zvol_state_list
59 * - take zv_suspend_lock if necessary, by the code path in question
60 * - take zv_state_lock to protect zvol_state_t
62 * The minor operations are issued to spa->spa_zvol_taskq queues, that are
63 * single-threaded (to preserve order of minor operations), and are executed
64 * through the zvol_task_cb that dispatches the specific operations. Therefore,
65 * these operations are serialized per pool. Consequently, we can be certain
66 * that for a given zvol, there is only one operation at a time in progress.
67 * That is why one can be sure that first, zvol_state_t for a given zvol is
68 * allocated and placed on zvol_state_list, and then other minor operations
69 * for this zvol are going to proceed in the order of issue.
73 #include <sys/dataset_kstats.h>
75 #include <sys/dmu_traverse.h>
76 #include <sys/dsl_dataset.h>
77 #include <sys/dsl_prop.h>
78 #include <sys/dsl_dir.h>
80 #include <sys/zfeature.h>
81 #include <sys/zil_impl.h>
82 #include <sys/dmu_tx.h>
84 #include <sys/zfs_rlock.h>
85 #include <sys/spa_impl.h>
88 #include <sys/zvol_impl.h>
91 unsigned int zvol_inhibit_dev = 0;
92 unsigned int zvol_volmode = ZFS_VOLMODE_GEOM;
94 struct hlist_head *zvol_htable;
95 list_t zvol_state_list;
96 krwlock_t zvol_state_lock;
97 const zvol_platform_ops_t *ops;
100 ZVOL_ASYNC_REMOVE_MINORS,
101 ZVOL_ASYNC_RENAME_MINORS,
102 ZVOL_ASYNC_SET_SNAPDEV,
103 ZVOL_ASYNC_SET_VOLMODE,
109 char pool[MAXNAMELEN];
110 char name1[MAXNAMELEN];
111 char name2[MAXNAMELEN];
112 zprop_source_t source;
117 zvol_name_hash(const char *name)
120 uint64_t crc = -1ULL;
121 const uint8_t *p = (const uint8_t *)name;
122 ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
123 for (i = 0; i < MAXNAMELEN - 1 && *p; i++, p++) {
124 crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (*p)) & 0xFF];
130 * Find a zvol_state_t given the name and hash generated by zvol_name_hash.
131 * If found, return with zv_suspend_lock and zv_state_lock taken, otherwise,
132 * return (NULL) without the taking locks. The zv_suspend_lock is always taken
133 * before zv_state_lock. The mode argument indicates the mode (including none)
134 * for zv_suspend_lock to be taken.
137 zvol_find_by_name_hash(const char *name, uint64_t hash, int mode)
140 struct hlist_node *p = NULL;
142 rw_enter(&zvol_state_lock, RW_READER);
143 hlist_for_each(p, ZVOL_HT_HEAD(hash)) {
144 zv = hlist_entry(p, zvol_state_t, zv_hlink);
145 mutex_enter(&zv->zv_state_lock);
146 if (zv->zv_hash == hash &&
147 strncmp(zv->zv_name, name, MAXNAMELEN) == 0) {
149 * this is the right zvol, take the locks in the
152 if (mode != RW_NONE &&
153 !rw_tryenter(&zv->zv_suspend_lock, mode)) {
154 mutex_exit(&zv->zv_state_lock);
155 rw_enter(&zv->zv_suspend_lock, mode);
156 mutex_enter(&zv->zv_state_lock);
158 * zvol cannot be renamed as we continue
159 * to hold zvol_state_lock
161 ASSERT(zv->zv_hash == hash &&
162 strncmp(zv->zv_name, name, MAXNAMELEN)
165 rw_exit(&zvol_state_lock);
168 mutex_exit(&zv->zv_state_lock);
170 rw_exit(&zvol_state_lock);
176 * Find a zvol_state_t given the name.
177 * If found, return with zv_suspend_lock and zv_state_lock taken, otherwise,
178 * return (NULL) without the taking locks. The zv_suspend_lock is always taken
179 * before zv_state_lock. The mode argument indicates the mode (including none)
180 * for zv_suspend_lock to be taken.
182 static zvol_state_t *
183 zvol_find_by_name(const char *name, int mode)
185 return (zvol_find_by_name_hash(name, zvol_name_hash(name), mode));
189 * ZFS_IOC_CREATE callback handles dmu zvol and zap object creation.
192 zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
194 zfs_creat_t *zct = arg;
195 nvlist_t *nvprops = zct->zct_props;
197 uint64_t volblocksize, volsize;
199 VERIFY(nvlist_lookup_uint64(nvprops,
200 zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0);
201 if (nvlist_lookup_uint64(nvprops,
202 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0)
203 volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
206 * These properties must be removed from the list so the generic
207 * property setting step won't apply to them.
209 VERIFY(nvlist_remove_all(nvprops,
210 zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0);
211 (void) nvlist_remove_all(nvprops,
212 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE));
214 error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize,
218 error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP,
222 error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx);
227 * ZFS_IOC_OBJSET_STATS entry point.
230 zvol_get_stats(objset_t *os, nvlist_t *nv)
233 dmu_object_info_t *doi;
236 error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val);
238 return (SET_ERROR(error));
240 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val);
241 doi = kmem_alloc(sizeof (dmu_object_info_t), KM_SLEEP);
242 error = dmu_object_info(os, ZVOL_OBJ, doi);
245 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE,
246 doi->doi_data_block_size);
249 kmem_free(doi, sizeof (dmu_object_info_t));
251 return (SET_ERROR(error));
255 * Sanity check volume size.
258 zvol_check_volsize(uint64_t volsize, uint64_t blocksize)
261 return (SET_ERROR(EINVAL));
263 if (volsize % blocksize != 0)
264 return (SET_ERROR(EINVAL));
267 if (volsize - 1 > SPEC_MAXOFFSET_T)
268 return (SET_ERROR(EOVERFLOW));
274 * Ensure the zap is flushed then inform the VFS of the capacity change.
277 zvol_update_volsize(uint64_t volsize, objset_t *os)
283 tx = dmu_tx_create(os);
284 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
285 dmu_tx_mark_netfree(tx);
286 error = dmu_tx_assign(tx, TXG_WAIT);
289 return (SET_ERROR(error));
291 txg = dmu_tx_get_txg(tx);
293 error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1,
297 txg_wait_synced(dmu_objset_pool(os), txg);
300 error = dmu_free_long_range(os,
301 ZVOL_OBJ, volsize, DMU_OBJECT_END);
307 * Set ZFS_PROP_VOLSIZE set entry point. Note that modifying the volume
308 * size will result in a udev "change" event being generated.
311 zvol_set_volsize(const char *name, uint64_t volsize)
316 boolean_t owned = B_FALSE;
318 error = dsl_prop_get_integer(name,
319 zfs_prop_to_name(ZFS_PROP_READONLY), &readonly, NULL);
321 return (SET_ERROR(error));
323 return (SET_ERROR(EROFS));
325 zvol_state_t *zv = zvol_find_by_name(name, RW_READER);
327 ASSERT(zv == NULL || (MUTEX_HELD(&zv->zv_state_lock) &&
328 RW_READ_HELD(&zv->zv_suspend_lock)));
330 if (zv == NULL || zv->zv_objset == NULL) {
332 rw_exit(&zv->zv_suspend_lock);
333 if ((error = dmu_objset_own(name, DMU_OST_ZVOL, B_FALSE, B_TRUE,
336 mutex_exit(&zv->zv_state_lock);
337 return (SET_ERROR(error));
346 dmu_object_info_t *doi = kmem_alloc(sizeof (*doi), KM_SLEEP);
348 if ((error = dmu_object_info(os, ZVOL_OBJ, doi)) ||
349 (error = zvol_check_volsize(volsize, doi->doi_data_block_size)))
352 error = zvol_update_volsize(volsize, os);
353 if (error == 0 && zv != NULL) {
354 zv->zv_volsize = volsize;
358 kmem_free(doi, sizeof (dmu_object_info_t));
361 dmu_objset_disown(os, B_TRUE, FTAG);
363 zv->zv_objset = NULL;
365 rw_exit(&zv->zv_suspend_lock);
369 mutex_exit(&zv->zv_state_lock);
371 if (error == 0 && zv != NULL)
372 ops->zv_update_volsize(zv, volsize);
374 return (SET_ERROR(error));
378 * Sanity check volume block size.
381 zvol_check_volblocksize(const char *name, uint64_t volblocksize)
383 /* Record sizes above 128k need the feature to be enabled */
384 if (volblocksize > SPA_OLD_MAXBLOCKSIZE) {
388 if ((error = spa_open(name, &spa, FTAG)) != 0)
391 if (!spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_BLOCKS)) {
392 spa_close(spa, FTAG);
393 return (SET_ERROR(ENOTSUP));
397 * We don't allow setting the property above 1MB,
398 * unless the tunable has been changed.
400 if (volblocksize > zfs_max_recordsize)
401 return (SET_ERROR(EDOM));
403 spa_close(spa, FTAG);
406 if (volblocksize < SPA_MINBLOCKSIZE ||
407 volblocksize > SPA_MAXBLOCKSIZE ||
409 return (SET_ERROR(EDOM));
415 * Set ZFS_PROP_VOLBLOCKSIZE set entry point.
418 zvol_set_volblocksize(const char *name, uint64_t volblocksize)
424 zv = zvol_find_by_name(name, RW_READER);
427 return (SET_ERROR(ENXIO));
429 ASSERT(MUTEX_HELD(&zv->zv_state_lock));
430 ASSERT(RW_READ_HELD(&zv->zv_suspend_lock));
432 if (zv->zv_flags & ZVOL_RDONLY) {
433 mutex_exit(&zv->zv_state_lock);
434 rw_exit(&zv->zv_suspend_lock);
435 return (SET_ERROR(EROFS));
438 tx = dmu_tx_create(zv->zv_objset);
439 dmu_tx_hold_bonus(tx, ZVOL_OBJ);
440 error = dmu_tx_assign(tx, TXG_WAIT);
444 error = dmu_object_set_blocksize(zv->zv_objset, ZVOL_OBJ,
445 volblocksize, 0, tx);
446 if (error == ENOTSUP)
447 error = SET_ERROR(EBUSY);
450 zv->zv_volblocksize = volblocksize;
453 mutex_exit(&zv->zv_state_lock);
454 rw_exit(&zv->zv_suspend_lock);
456 return (SET_ERROR(error));
460 * Replay a TX_TRUNCATE ZIL transaction if asked. TX_TRUNCATE is how we
461 * implement DKIOCFREE/free-long-range.
464 zvol_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
466 zvol_state_t *zv = arg1;
467 lr_truncate_t *lr = arg2;
468 uint64_t offset, length;
471 byteswap_uint64_array(lr, sizeof (*lr));
473 offset = lr->lr_offset;
474 length = lr->lr_length;
476 return (dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset, length));
480 * Replay a TX_WRITE ZIL transaction that didn't get committed
481 * after a system failure
484 zvol_replay_write(void *arg1, void *arg2, boolean_t byteswap)
486 zvol_state_t *zv = arg1;
487 lr_write_t *lr = arg2;
488 objset_t *os = zv->zv_objset;
489 char *data = (char *)(lr + 1); /* data follows lr_write_t */
490 uint64_t offset, length;
495 byteswap_uint64_array(lr, sizeof (*lr));
497 offset = lr->lr_offset;
498 length = lr->lr_length;
500 /* If it's a dmu_sync() block, write the whole block */
501 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
502 uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
503 if (length < blocksize) {
504 offset -= offset % blocksize;
509 tx = dmu_tx_create(os);
510 dmu_tx_hold_write(tx, ZVOL_OBJ, offset, length);
511 error = dmu_tx_assign(tx, TXG_WAIT);
515 dmu_write(os, ZVOL_OBJ, offset, length, data, tx);
523 zvol_replay_err(void *arg1, void *arg2, boolean_t byteswap)
525 return (SET_ERROR(ENOTSUP));
529 * Callback vectors for replaying records.
530 * Only TX_WRITE and TX_TRUNCATE are needed for zvol.
532 zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE] = {
533 zvol_replay_err, /* no such transaction type */
534 zvol_replay_err, /* TX_CREATE */
535 zvol_replay_err, /* TX_MKDIR */
536 zvol_replay_err, /* TX_MKXATTR */
537 zvol_replay_err, /* TX_SYMLINK */
538 zvol_replay_err, /* TX_REMOVE */
539 zvol_replay_err, /* TX_RMDIR */
540 zvol_replay_err, /* TX_LINK */
541 zvol_replay_err, /* TX_RENAME */
542 zvol_replay_write, /* TX_WRITE */
543 zvol_replay_truncate, /* TX_TRUNCATE */
544 zvol_replay_err, /* TX_SETATTR */
545 zvol_replay_err, /* TX_ACL */
546 zvol_replay_err, /* TX_CREATE_ATTR */
547 zvol_replay_err, /* TX_CREATE_ACL_ATTR */
548 zvol_replay_err, /* TX_MKDIR_ACL */
549 zvol_replay_err, /* TX_MKDIR_ATTR */
550 zvol_replay_err, /* TX_MKDIR_ACL_ATTR */
551 zvol_replay_err, /* TX_WRITE2 */
555 * zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions.
557 * We store data in the log buffers if it's small enough.
558 * Otherwise we will later flush the data out via dmu_sync().
560 ssize_t zvol_immediate_write_sz = 32768;
563 zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
564 uint64_t size, int sync)
566 uint32_t blocksize = zv->zv_volblocksize;
567 zilog_t *zilog = zv->zv_zilog;
568 itx_wr_state_t write_state;
570 if (zil_replaying(zilog, tx))
573 if (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
574 write_state = WR_INDIRECT;
575 else if (!spa_has_slogs(zilog->zl_spa) &&
576 size >= blocksize && blocksize > zvol_immediate_write_sz)
577 write_state = WR_INDIRECT;
579 write_state = WR_COPIED;
581 write_state = WR_NEED_COPY;
586 itx_wr_state_t wr_state = write_state;
589 if (wr_state == WR_COPIED && size > zil_max_copied_data(zilog))
590 wr_state = WR_NEED_COPY;
591 else if (wr_state == WR_INDIRECT)
592 len = MIN(blocksize - P2PHASE(offset, blocksize), size);
594 itx = zil_itx_create(TX_WRITE, sizeof (*lr) +
595 (wr_state == WR_COPIED ? len : 0));
596 lr = (lr_write_t *)&itx->itx_lr;
597 if (wr_state == WR_COPIED && dmu_read_by_dnode(zv->zv_dn,
598 offset, len, lr+1, DMU_READ_NO_PREFETCH) != 0) {
599 zil_itx_destroy(itx);
600 itx = zil_itx_create(TX_WRITE, sizeof (*lr));
601 lr = (lr_write_t *)&itx->itx_lr;
602 wr_state = WR_NEED_COPY;
605 itx->itx_wr_state = wr_state;
606 lr->lr_foid = ZVOL_OBJ;
607 lr->lr_offset = offset;
610 BP_ZERO(&lr->lr_blkptr);
612 itx->itx_private = zv;
613 itx->itx_sync = sync;
615 (void) zil_itx_assign(zilog, itx, tx);
623 * Log a DKIOCFREE/free-long-range to the ZIL with TX_TRUNCATE.
626 zvol_log_truncate(zvol_state_t *zv, dmu_tx_t *tx, uint64_t off, uint64_t len,
631 zilog_t *zilog = zv->zv_zilog;
633 if (zil_replaying(zilog, tx))
636 itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
637 lr = (lr_truncate_t *)&itx->itx_lr;
638 lr->lr_foid = ZVOL_OBJ;
642 itx->itx_sync = sync;
643 zil_itx_assign(zilog, itx, tx);
649 zvol_get_done(zgd_t *zgd, int error)
652 dmu_buf_rele(zgd->zgd_db, zgd);
654 zfs_rangelock_exit(zgd->zgd_lr);
656 kmem_free(zgd, sizeof (zgd_t));
660 * Get data to generate a TX_WRITE intent log record.
663 zvol_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb, zio_t *zio)
665 zvol_state_t *zv = arg;
666 uint64_t offset = lr->lr_offset;
667 uint64_t size = lr->lr_length;
672 ASSERT3P(lwb, !=, NULL);
673 ASSERT3P(zio, !=, NULL);
674 ASSERT3U(size, !=, 0);
676 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
680 * Write records come in two flavors: immediate and indirect.
681 * For small writes it's cheaper to store the data with the
682 * log record (immediate); for large writes it's cheaper to
683 * sync the data and get a pointer to it (indirect) so that
684 * we don't have to write the data twice.
686 if (buf != NULL) { /* immediate write */
687 zgd->zgd_lr = zfs_rangelock_enter(&zv->zv_rangelock, offset,
689 error = dmu_read_by_dnode(zv->zv_dn, offset, size, buf,
690 DMU_READ_NO_PREFETCH);
691 } else { /* indirect write */
693 * Have to lock the whole block to ensure when it's written out
694 * and its checksum is being calculated that no one can change
695 * the data. Contrarily to zfs_get_data we need not re-check
696 * blocksize after we get the lock because it cannot be changed.
698 size = zv->zv_volblocksize;
699 offset = P2ALIGN_TYPED(offset, size, uint64_t);
700 zgd->zgd_lr = zfs_rangelock_enter(&zv->zv_rangelock, offset,
702 error = dmu_buf_hold_by_dnode(zv->zv_dn, offset, zgd, &db,
703 DMU_READ_NO_PREFETCH);
705 blkptr_t *bp = &lr->lr_blkptr;
711 ASSERT(db->db_offset == offset);
712 ASSERT(db->db_size == size);
714 error = dmu_sync(zio, lr->lr_common.lrc_txg,
722 zvol_get_done(zgd, error);
724 return (SET_ERROR(error));
728 * The zvol_state_t's are inserted into zvol_state_list and zvol_htable.
732 zvol_insert(zvol_state_t *zv)
734 ASSERT(RW_WRITE_HELD(&zvol_state_lock));
735 list_insert_head(&zvol_state_list, zv);
736 hlist_add_head(&zv->zv_hlink, ZVOL_HT_HEAD(zv->zv_hash));
740 * Simply remove the zvol from to list of zvols.
743 zvol_remove(zvol_state_t *zv)
745 ASSERT(RW_WRITE_HELD(&zvol_state_lock));
746 list_remove(&zvol_state_list, zv);
747 hlist_del(&zv->zv_hlink);
751 * Setup zv after we just own the zv->objset
754 zvol_setup_zv(zvol_state_t *zv)
759 objset_t *os = zv->zv_objset;
761 ASSERT(MUTEX_HELD(&zv->zv_state_lock));
762 ASSERT(RW_LOCK_HELD(&zv->zv_suspend_lock));
765 zv->zv_flags &= ~ZVOL_WRITTEN_TO;
767 error = dsl_prop_get_integer(zv->zv_name, "readonly", &ro, NULL);
769 return (SET_ERROR(error));
771 error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize);
773 return (SET_ERROR(error));
775 error = dnode_hold(os, ZVOL_OBJ, FTAG, &zv->zv_dn);
777 return (SET_ERROR(error));
779 ops->zv_set_capacity(zv, volsize >> 9);
780 zv->zv_volsize = volsize;
782 if (ro || dmu_objset_is_snapshot(os) ||
783 !spa_writeable(dmu_objset_spa(os))) {
784 ops->zv_set_disk_ro(zv, 1);
785 zv->zv_flags |= ZVOL_RDONLY;
787 ops->zv_set_disk_ro(zv, 0);
788 zv->zv_flags &= ~ZVOL_RDONLY;
794 * Shutdown every zv_objset related stuff except zv_objset itself.
795 * The is the reverse of zvol_setup_zv.
798 zvol_shutdown_zv(zvol_state_t *zv)
800 ASSERT(MUTEX_HELD(&zv->zv_state_lock) &&
801 RW_LOCK_HELD(&zv->zv_suspend_lock));
803 if (zv->zv_flags & ZVOL_WRITTEN_TO) {
804 ASSERT(zv->zv_zilog != NULL);
805 zil_close(zv->zv_zilog);
810 dnode_rele(zv->zv_dn, FTAG);
814 * Evict cached data. We must write out any dirty data before
815 * disowning the dataset.
817 if (zv->zv_flags & ZVOL_WRITTEN_TO)
818 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0);
819 (void) dmu_objset_evict_dbufs(zv->zv_objset);
823 * return the proper tag for rollback and recv
826 zvol_tag(zvol_state_t *zv)
828 ASSERT(RW_WRITE_HELD(&zv->zv_suspend_lock));
829 return (zv->zv_open_count > 0 ? zv : NULL);
833 * Suspend the zvol for recv and rollback.
836 zvol_suspend(const char *name)
840 zv = zvol_find_by_name(name, RW_WRITER);
845 /* block all I/O, release in zvol_resume. */
846 ASSERT(MUTEX_HELD(&zv->zv_state_lock));
847 ASSERT(RW_WRITE_HELD(&zv->zv_suspend_lock));
849 atomic_inc(&zv->zv_suspend_ref);
851 if (zv->zv_open_count > 0)
852 zvol_shutdown_zv(zv);
855 * do not hold zv_state_lock across suspend/resume to
856 * avoid locking up zvol lookups
858 mutex_exit(&zv->zv_state_lock);
860 /* zv_suspend_lock is released in zvol_resume() */
865 zvol_resume(zvol_state_t *zv)
869 ASSERT(RW_WRITE_HELD(&zv->zv_suspend_lock));
871 mutex_enter(&zv->zv_state_lock);
873 if (zv->zv_open_count > 0) {
874 VERIFY0(dmu_objset_hold(zv->zv_name, zv, &zv->zv_objset));
875 VERIFY3P(zv->zv_objset->os_dsl_dataset->ds_owner, ==, zv);
876 VERIFY(dsl_dataset_long_held(zv->zv_objset->os_dsl_dataset));
877 dmu_objset_rele(zv->zv_objset, zv);
879 error = zvol_setup_zv(zv);
882 mutex_exit(&zv->zv_state_lock);
884 rw_exit(&zv->zv_suspend_lock);
886 * We need this because we don't hold zvol_state_lock while releasing
887 * zv_suspend_lock. zvol_remove_minors_impl thus cannot check
888 * zv_suspend_lock to determine it is safe to free because rwlock is
889 * not inherent atomic.
891 atomic_dec(&zv->zv_suspend_ref);
893 return (SET_ERROR(error));
897 zvol_first_open(zvol_state_t *zv, boolean_t readonly)
900 int error, locked = 0;
903 ASSERT(RW_READ_HELD(&zv->zv_suspend_lock));
904 ASSERT(MUTEX_HELD(&zv->zv_state_lock));
907 * In all other cases the spa_namespace_lock is taken before the
908 * bdev->bd_mutex lock. But in this case the Linux __blkdev_get()
909 * function calls fops->open() with the bdev->bd_mutex lock held.
910 * This deadlock can be easily observed with zvols used as vdevs.
912 * To avoid a potential lock inversion deadlock we preemptively
913 * try to take the spa_namespace_lock(). Normally it will not
914 * be contended and this is safe because spa_open_common() handles
915 * the case where the caller already holds the spa_namespace_lock.
917 * When it is contended we risk a lock inversion if we were to
918 * block waiting for the lock. Luckily, the __blkdev_get()
919 * function allows us to return -ERESTARTSYS which will result in
920 * bdev->bd_mutex being dropped, reacquired, and fops->open() being
921 * called again. This process can be repeated safely until both
922 * locks are acquired.
924 if (!mutex_owned(&spa_namespace_lock)) {
925 locked = mutex_tryenter(&spa_namespace_lock);
927 return (SET_ERROR(EINTR));
930 ro = (readonly || (strchr(zv->zv_name, '@') != NULL));
931 error = dmu_objset_own(zv->zv_name, DMU_OST_ZVOL, ro, B_TRUE, zv, &os);
937 error = zvol_setup_zv(zv);
940 dmu_objset_disown(os, 1, zv);
941 zv->zv_objset = NULL;
946 mutex_exit(&spa_namespace_lock);
947 return (SET_ERROR(error));
951 zvol_last_close(zvol_state_t *zv)
953 ASSERT(RW_READ_HELD(&zv->zv_suspend_lock));
954 ASSERT(MUTEX_HELD(&zv->zv_state_lock));
956 zvol_shutdown_zv(zv);
958 dmu_objset_disown(zv->zv_objset, 1, zv);
959 zv->zv_objset = NULL;
962 typedef struct minors_job {
972 * Prefetch zvol dnodes for the minors_job
975 zvol_prefetch_minors_impl(void *arg)
977 minors_job_t *job = arg;
978 char *dsname = job->name;
981 job->error = dmu_objset_own(dsname, DMU_OST_ZVOL, B_TRUE, B_TRUE,
983 if (job->error == 0) {
984 dmu_prefetch(os, ZVOL_OBJ, 0, 0, 0, ZIO_PRIORITY_SYNC_READ);
985 dmu_objset_disown(os, B_TRUE, FTAG);
990 * Mask errors to continue dmu_objset_find() traversal
993 zvol_create_snap_minor_cb(const char *dsname, void *arg)
995 minors_job_t *j = arg;
996 list_t *minors_list = j->list;
997 const char *name = j->name;
999 ASSERT0(MUTEX_HELD(&spa_namespace_lock));
1001 /* skip the designated dataset */
1002 if (name && strcmp(dsname, name) == 0)
1005 /* at this point, the dsname should name a snapshot */
1006 if (strchr(dsname, '@') == 0) {
1007 dprintf("zvol_create_snap_minor_cb(): "
1008 "%s is not a snapshot name\n", dsname);
1011 char *n = kmem_strdup(dsname);
1015 job = kmem_alloc(sizeof (minors_job_t), KM_SLEEP);
1017 job->list = minors_list;
1019 list_insert_tail(minors_list, job);
1020 /* don't care if dispatch fails, because job->error is 0 */
1021 taskq_dispatch(system_taskq, zvol_prefetch_minors_impl, job,
1029 * Mask errors to continue dmu_objset_find() traversal
1032 zvol_create_minors_cb(const char *dsname, void *arg)
1036 list_t *minors_list = arg;
1038 ASSERT0(MUTEX_HELD(&spa_namespace_lock));
1040 error = dsl_prop_get_integer(dsname, "snapdev", &snapdev, NULL);
1045 * Given the name and the 'snapdev' property, create device minor nodes
1046 * with the linkages to zvols/snapshots as needed.
1047 * If the name represents a zvol, create a minor node for the zvol, then
1048 * check if its snapshots are 'visible', and if so, iterate over the
1049 * snapshots and create device minor nodes for those.
1051 if (strchr(dsname, '@') == 0) {
1053 char *n = kmem_strdup(dsname);
1057 job = kmem_alloc(sizeof (minors_job_t), KM_SLEEP);
1059 job->list = minors_list;
1061 list_insert_tail(minors_list, job);
1062 /* don't care if dispatch fails, because job->error is 0 */
1063 taskq_dispatch(system_taskq, zvol_prefetch_minors_impl, job,
1066 if (snapdev == ZFS_SNAPDEV_VISIBLE) {
1068 * traverse snapshots only, do not traverse children,
1069 * and skip the 'dsname'
1071 error = dmu_objset_find(dsname,
1072 zvol_create_snap_minor_cb, (void *)job,
1076 dprintf("zvol_create_minors_cb(): %s is not a zvol name\n",
1084 * Create minors for the specified dataset, including children and snapshots.
1085 * Pay attention to the 'snapdev' property and iterate over the snapshots
1086 * only if they are 'visible'. This approach allows one to assure that the
1087 * snapshot metadata is read from disk only if it is needed.
1089 * The name can represent a dataset to be recursively scanned for zvols and
1090 * their snapshots, or a single zvol snapshot. If the name represents a
1091 * dataset, the scan is performed in two nested stages:
1092 * - scan the dataset for zvols, and
1093 * - for each zvol, create a minor node, then check if the zvol's snapshots
1094 * are 'visible', and only then iterate over the snapshots if needed
1096 * If the name represents a snapshot, a check is performed if the snapshot is
1097 * 'visible' (which also verifies that the parent is a zvol), and if so,
1098 * a minor node for that snapshot is created.
1101 zvol_create_minors_recursive(const char *name)
1106 if (zvol_inhibit_dev)
1110 * This is the list for prefetch jobs. Whenever we found a match
1111 * during dmu_objset_find, we insert a minors_job to the list and do
1112 * taskq_dispatch to parallel prefetch zvol dnodes. Note we don't need
1113 * any lock because all list operation is done on the current thread.
1115 * We will use this list to do zvol_create_minor_impl after prefetch
1116 * so we don't have to traverse using dmu_objset_find again.
1118 list_create(&minors_list, sizeof (minors_job_t),
1119 offsetof(minors_job_t, link));
1122 if (strchr(name, '@') != NULL) {
1125 int error = dsl_prop_get_integer(name, "snapdev",
1128 if (error == 0 && snapdev == ZFS_SNAPDEV_VISIBLE)
1129 (void) ops->zv_create_minor(name);
1131 fstrans_cookie_t cookie = spl_fstrans_mark();
1132 (void) dmu_objset_find(name, zvol_create_minors_cb,
1133 &minors_list, DS_FIND_CHILDREN);
1134 spl_fstrans_unmark(cookie);
1137 taskq_wait_outstanding(system_taskq, 0);
1140 * Prefetch is completed, we can do zvol_create_minor_impl
1143 while ((job = list_head(&minors_list)) != NULL) {
1144 list_remove(&minors_list, job);
1146 (void) ops->zv_create_minor(job->name);
1147 kmem_strfree(job->name);
1148 kmem_free(job, sizeof (minors_job_t));
1151 list_destroy(&minors_list);
1155 zvol_create_minor(const char *name)
1158 * Note: the dsl_pool_config_lock must not be held.
1159 * Minor node creation needs to obtain the zvol_state_lock.
1160 * zvol_open() obtains the zvol_state_lock and then the dsl pool
1161 * config lock. Therefore, we can't have the config lock now if
1162 * we are going to wait for the zvol_state_lock, because it
1163 * would be a lock order inversion which could lead to deadlock.
1166 if (zvol_inhibit_dev)
1169 if (strchr(name, '@') != NULL) {
1172 int error = dsl_prop_get_integer(name,
1173 "snapdev", &snapdev, NULL);
1175 if (error == 0 && snapdev == ZFS_SNAPDEV_VISIBLE)
1176 (void) ops->zv_create_minor(name);
1178 (void) ops->zv_create_minor(name);
1183 * Remove minors for specified dataset including children and snapshots.
1187 zvol_remove_minors_impl(const char *name)
1189 zvol_state_t *zv, *zv_next;
1190 int namelen = ((name) ? strlen(name) : 0);
1194 if (zvol_inhibit_dev)
1197 list_create(&free_list, sizeof (zvol_state_t),
1198 offsetof(zvol_state_t, zv_next));
1200 rw_enter(&zvol_state_lock, RW_WRITER);
1202 for (zv = list_head(&zvol_state_list); zv != NULL; zv = zv_next) {
1203 zv_next = list_next(&zvol_state_list, zv);
1205 mutex_enter(&zv->zv_state_lock);
1206 if (name == NULL || strcmp(zv->zv_name, name) == 0 ||
1207 (strncmp(zv->zv_name, name, namelen) == 0 &&
1208 (zv->zv_name[namelen] == '/' ||
1209 zv->zv_name[namelen] == '@'))) {
1211 * By holding zv_state_lock here, we guarantee that no
1212 * one is currently using this zv
1215 /* If in use, leave alone */
1216 if (zv->zv_open_count > 0 ||
1217 atomic_read(&zv->zv_suspend_ref)) {
1218 mutex_exit(&zv->zv_state_lock);
1225 * Cleared while holding zvol_state_lock as a writer
1226 * which will prevent zvol_open() from opening it.
1228 ops->zv_clear_private(zv);
1230 /* Drop zv_state_lock before zvol_free() */
1231 mutex_exit(&zv->zv_state_lock);
1233 /* Try parallel zv_free, if failed do it in place */
1234 t = taskq_dispatch(system_taskq,
1235 (task_func_t *)ops->zv_free, zv, TQ_SLEEP);
1236 if (t == TASKQID_INVALID)
1237 list_insert_head(&free_list, zv);
1239 mutex_exit(&zv->zv_state_lock);
1242 rw_exit(&zvol_state_lock);
1244 /* Drop zvol_state_lock before calling zvol_free() */
1245 while ((zv = list_head(&free_list)) != NULL) {
1246 list_remove(&free_list, zv);
1251 /* Remove minor for this specific volume only */
1253 zvol_remove_minor_impl(const char *name)
1255 zvol_state_t *zv = NULL, *zv_next;
1257 if (zvol_inhibit_dev)
1260 rw_enter(&zvol_state_lock, RW_WRITER);
1262 for (zv = list_head(&zvol_state_list); zv != NULL; zv = zv_next) {
1263 zv_next = list_next(&zvol_state_list, zv);
1265 mutex_enter(&zv->zv_state_lock);
1266 if (strcmp(zv->zv_name, name) == 0) {
1268 * By holding zv_state_lock here, we guarantee that no
1269 * one is currently using this zv
1272 /* If in use, leave alone */
1273 if (zv->zv_open_count > 0 ||
1274 atomic_read(&zv->zv_suspend_ref)) {
1275 mutex_exit(&zv->zv_state_lock);
1280 ops->zv_clear_private(zv);
1281 mutex_exit(&zv->zv_state_lock);
1284 mutex_exit(&zv->zv_state_lock);
1288 /* Drop zvol_state_lock before calling zvol_free() */
1289 rw_exit(&zvol_state_lock);
1296 * Rename minors for specified dataset including children and snapshots.
1299 zvol_rename_minors_impl(const char *oldname, const char *newname)
1301 zvol_state_t *zv, *zv_next;
1302 int oldnamelen, newnamelen;
1304 if (zvol_inhibit_dev)
1307 oldnamelen = strlen(oldname);
1308 newnamelen = strlen(newname);
1310 rw_enter(&zvol_state_lock, RW_READER);
1312 for (zv = list_head(&zvol_state_list); zv != NULL; zv = zv_next) {
1313 zv_next = list_next(&zvol_state_list, zv);
1315 mutex_enter(&zv->zv_state_lock);
1317 if (strcmp(zv->zv_name, oldname) == 0) {
1318 ops->zv_rename_minor(zv, newname);
1319 } else if (strncmp(zv->zv_name, oldname, oldnamelen) == 0 &&
1320 (zv->zv_name[oldnamelen] == '/' ||
1321 zv->zv_name[oldnamelen] == '@')) {
1322 char *name = kmem_asprintf("%s%c%s", newname,
1323 zv->zv_name[oldnamelen],
1324 zv->zv_name + oldnamelen + 1);
1325 ops->zv_rename_minor(zv, name);
1329 mutex_exit(&zv->zv_state_lock);
1332 rw_exit(&zvol_state_lock);
1335 typedef struct zvol_snapdev_cb_arg {
1337 } zvol_snapdev_cb_arg_t;
1340 zvol_set_snapdev_cb(const char *dsname, void *param)
1342 zvol_snapdev_cb_arg_t *arg = param;
1344 if (strchr(dsname, '@') == NULL)
1347 switch (arg->snapdev) {
1348 case ZFS_SNAPDEV_VISIBLE:
1349 (void) ops->zv_create_minor(dsname);
1351 case ZFS_SNAPDEV_HIDDEN:
1352 (void) zvol_remove_minor_impl(dsname);
1360 zvol_set_snapdev_impl(char *name, uint64_t snapdev)
1362 zvol_snapdev_cb_arg_t arg = {snapdev};
1363 fstrans_cookie_t cookie = spl_fstrans_mark();
1365 * The zvol_set_snapdev_sync() sets snapdev appropriately
1366 * in the dataset hierarchy. Here, we only scan snapshots.
1368 dmu_objset_find(name, zvol_set_snapdev_cb, &arg, DS_FIND_SNAPSHOTS);
1369 spl_fstrans_unmark(cookie);
1372 typedef struct zvol_volmode_cb_arg {
1374 } zvol_volmode_cb_arg_t;
1377 zvol_set_volmode_impl(char *name, uint64_t volmode)
1379 fstrans_cookie_t cookie = spl_fstrans_mark();
1381 if (strchr(name, '@') != NULL)
1385 * It's unfortunate we need to remove minors before we create new ones:
1386 * this is necessary because our backing gendisk (zvol_state->zv_disk)
1387 * could be different when we set, for instance, volmode from "geom"
1388 * to "dev" (or vice versa).
1389 * A possible optimization is to modify our consumers so we don't get
1390 * called when "volmode" does not change.
1393 case ZFS_VOLMODE_NONE:
1394 (void) zvol_remove_minor_impl(name);
1396 case ZFS_VOLMODE_GEOM:
1397 case ZFS_VOLMODE_DEV:
1398 (void) zvol_remove_minor_impl(name);
1399 (void) ops->zv_create_minor(name);
1401 case ZFS_VOLMODE_DEFAULT:
1402 (void) zvol_remove_minor_impl(name);
1403 if (zvol_volmode == ZFS_VOLMODE_NONE)
1405 else /* if zvol_volmode is invalid defaults to "geom" */
1406 (void) ops->zv_create_minor(name);
1410 spl_fstrans_unmark(cookie);
1413 static zvol_task_t *
1414 zvol_task_alloc(zvol_async_op_t op, const char *name1, const char *name2,
1420 /* Never allow tasks on hidden names. */
1421 if (name1[0] == '$')
1424 task = kmem_zalloc(sizeof (zvol_task_t), KM_SLEEP);
1426 task->value = value;
1427 delim = strchr(name1, '/');
1428 strlcpy(task->pool, name1, delim ? (delim - name1 + 1) : MAXNAMELEN);
1430 strlcpy(task->name1, name1, MAXNAMELEN);
1432 strlcpy(task->name2, name2, MAXNAMELEN);
1438 zvol_task_free(zvol_task_t *task)
1440 kmem_free(task, sizeof (zvol_task_t));
1444 * The worker thread function performed asynchronously.
1447 zvol_task_cb(void *arg)
1449 zvol_task_t *task = arg;
1452 case ZVOL_ASYNC_REMOVE_MINORS:
1453 zvol_remove_minors_impl(task->name1);
1455 case ZVOL_ASYNC_RENAME_MINORS:
1456 zvol_rename_minors_impl(task->name1, task->name2);
1458 case ZVOL_ASYNC_SET_SNAPDEV:
1459 zvol_set_snapdev_impl(task->name1, task->value);
1461 case ZVOL_ASYNC_SET_VOLMODE:
1462 zvol_set_volmode_impl(task->name1, task->value);
1469 zvol_task_free(task);
1472 typedef struct zvol_set_prop_int_arg {
1473 const char *zsda_name;
1474 uint64_t zsda_value;
1475 zprop_source_t zsda_source;
1477 } zvol_set_prop_int_arg_t;
1480 * Sanity check the dataset for safe use by the sync task. No additional
1481 * conditions are imposed.
1484 zvol_set_snapdev_check(void *arg, dmu_tx_t *tx)
1486 zvol_set_prop_int_arg_t *zsda = arg;
1487 dsl_pool_t *dp = dmu_tx_pool(tx);
1491 error = dsl_dir_hold(dp, zsda->zsda_name, FTAG, &dd, NULL);
1495 dsl_dir_rele(dd, FTAG);
1502 zvol_set_snapdev_sync_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
1504 char dsname[MAXNAMELEN];
1508 dsl_dataset_name(ds, dsname);
1509 if (dsl_prop_get_int_ds(ds, "snapdev", &snapdev) != 0)
1511 task = zvol_task_alloc(ZVOL_ASYNC_SET_SNAPDEV, dsname, NULL, snapdev);
1515 (void) taskq_dispatch(dp->dp_spa->spa_zvol_taskq, zvol_task_cb,
1521 * Traverse all child datasets and apply snapdev appropriately.
1522 * We call dsl_prop_set_sync_impl() here to set the value only on the toplevel
1523 * dataset and read the effective "snapdev" on every child in the callback
1524 * function: this is because the value is not guaranteed to be the same in the
1525 * whole dataset hierarchy.
1528 zvol_set_snapdev_sync(void *arg, dmu_tx_t *tx)
1530 zvol_set_prop_int_arg_t *zsda = arg;
1531 dsl_pool_t *dp = dmu_tx_pool(tx);
1536 VERIFY0(dsl_dir_hold(dp, zsda->zsda_name, FTAG, &dd, NULL));
1539 error = dsl_dataset_hold(dp, zsda->zsda_name, FTAG, &ds);
1541 dsl_prop_set_sync_impl(ds, zfs_prop_to_name(ZFS_PROP_SNAPDEV),
1542 zsda->zsda_source, sizeof (zsda->zsda_value), 1,
1543 &zsda->zsda_value, zsda->zsda_tx);
1544 dsl_dataset_rele(ds, FTAG);
1546 dmu_objset_find_dp(dp, dd->dd_object, zvol_set_snapdev_sync_cb,
1547 zsda, DS_FIND_CHILDREN);
1549 dsl_dir_rele(dd, FTAG);
1553 zvol_set_snapdev(const char *ddname, zprop_source_t source, uint64_t snapdev)
1555 zvol_set_prop_int_arg_t zsda;
1557 zsda.zsda_name = ddname;
1558 zsda.zsda_source = source;
1559 zsda.zsda_value = snapdev;
1561 return (dsl_sync_task(ddname, zvol_set_snapdev_check,
1562 zvol_set_snapdev_sync, &zsda, 0, ZFS_SPACE_CHECK_NONE));
1566 * Sanity check the dataset for safe use by the sync task. No additional
1567 * conditions are imposed.
1570 zvol_set_volmode_check(void *arg, dmu_tx_t *tx)
1572 zvol_set_prop_int_arg_t *zsda = arg;
1573 dsl_pool_t *dp = dmu_tx_pool(tx);
1577 error = dsl_dir_hold(dp, zsda->zsda_name, FTAG, &dd, NULL);
1581 dsl_dir_rele(dd, FTAG);
1588 zvol_set_volmode_sync_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
1590 char dsname[MAXNAMELEN];
1594 dsl_dataset_name(ds, dsname);
1595 if (dsl_prop_get_int_ds(ds, "volmode", &volmode) != 0)
1597 task = zvol_task_alloc(ZVOL_ASYNC_SET_VOLMODE, dsname, NULL, volmode);
1601 (void) taskq_dispatch(dp->dp_spa->spa_zvol_taskq, zvol_task_cb,
1607 * Traverse all child datasets and apply volmode appropriately.
1608 * We call dsl_prop_set_sync_impl() here to set the value only on the toplevel
1609 * dataset and read the effective "volmode" on every child in the callback
1610 * function: this is because the value is not guaranteed to be the same in the
1611 * whole dataset hierarchy.
1614 zvol_set_volmode_sync(void *arg, dmu_tx_t *tx)
1616 zvol_set_prop_int_arg_t *zsda = arg;
1617 dsl_pool_t *dp = dmu_tx_pool(tx);
1622 VERIFY0(dsl_dir_hold(dp, zsda->zsda_name, FTAG, &dd, NULL));
1625 error = dsl_dataset_hold(dp, zsda->zsda_name, FTAG, &ds);
1627 dsl_prop_set_sync_impl(ds, zfs_prop_to_name(ZFS_PROP_VOLMODE),
1628 zsda->zsda_source, sizeof (zsda->zsda_value), 1,
1629 &zsda->zsda_value, zsda->zsda_tx);
1630 dsl_dataset_rele(ds, FTAG);
1633 dmu_objset_find_dp(dp, dd->dd_object, zvol_set_volmode_sync_cb,
1634 zsda, DS_FIND_CHILDREN);
1636 dsl_dir_rele(dd, FTAG);
1640 zvol_set_volmode(const char *ddname, zprop_source_t source, uint64_t volmode)
1642 zvol_set_prop_int_arg_t zsda;
1644 zsda.zsda_name = ddname;
1645 zsda.zsda_source = source;
1646 zsda.zsda_value = volmode;
1648 return (dsl_sync_task(ddname, zvol_set_volmode_check,
1649 zvol_set_volmode_sync, &zsda, 0, ZFS_SPACE_CHECK_NONE));
1653 zvol_remove_minors(spa_t *spa, const char *name, boolean_t async)
1658 task = zvol_task_alloc(ZVOL_ASYNC_REMOVE_MINORS, name, NULL, ~0ULL);
1662 id = taskq_dispatch(spa->spa_zvol_taskq, zvol_task_cb, task, TQ_SLEEP);
1663 if ((async == B_FALSE) && (id != TASKQID_INVALID))
1664 taskq_wait_id(spa->spa_zvol_taskq, id);
1668 zvol_rename_minors(spa_t *spa, const char *name1, const char *name2,
1674 task = zvol_task_alloc(ZVOL_ASYNC_RENAME_MINORS, name1, name2, ~0ULL);
1678 id = taskq_dispatch(spa->spa_zvol_taskq, zvol_task_cb, task, TQ_SLEEP);
1679 if ((async == B_FALSE) && (id != TASKQID_INVALID))
1680 taskq_wait_id(spa->spa_zvol_taskq, id);
1684 zvol_is_zvol(const char *name)
1687 return (ops->zv_is_zvol(name));
1691 zvol_register_ops(const zvol_platform_ops_t *zvol_ops)
1697 zvol_init_impl(void)
1701 list_create(&zvol_state_list, sizeof (zvol_state_t),
1702 offsetof(zvol_state_t, zv_next));
1703 rw_init(&zvol_state_lock, NULL, RW_DEFAULT, NULL);
1705 zvol_htable = kmem_alloc(ZVOL_HT_SIZE * sizeof (struct hlist_head),
1707 for (i = 0; i < ZVOL_HT_SIZE; i++)
1708 INIT_HLIST_HEAD(&zvol_htable[i]);
1714 zvol_fini_impl(void)
1716 zvol_remove_minors_impl(NULL);
1719 * The call to "zvol_remove_minors_impl" may dispatch entries to
1720 * the system_taskq, but it doesn't wait for those entries to
1721 * complete before it returns. Thus, we must wait for all of the
1722 * removals to finish, before we can continue.
1724 taskq_wait_outstanding(system_taskq, 0);
1726 kmem_free(zvol_htable, ZVOL_HT_SIZE * sizeof (struct hlist_head));
1727 list_destroy(&zvol_state_list);
1728 rw_destroy(&zvol_state_lock);