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.
42 #include <sys/dmu_traverse.h>
43 #include <sys/dsl_dataset.h>
44 #include <sys/dsl_prop.h>
46 #include <sys/zfeature.h>
47 #include <sys/zil_impl.h>
48 #include <sys/dmu_tx.h>
50 #include <sys/zfs_rlock.h>
51 #include <sys/zfs_znode.h>
53 #include <linux/blkdev_compat.h>
55 unsigned int zvol_inhibit_dev = 0;
56 unsigned int zvol_major = ZVOL_MAJOR;
57 unsigned int zvol_prefetch_bytes = (128 * 1024);
58 unsigned long zvol_max_discard_blocks = 16384;
60 static kmutex_t zvol_state_lock;
61 static list_t zvol_state_list;
62 static char *zvol_tag = "zvol_tag";
65 * The in-core state of each volume.
67 typedef struct zvol_state {
68 char zv_name[MAXNAMELEN]; /* name */
69 uint64_t zv_volsize; /* advertised space */
70 uint64_t zv_volblocksize; /* volume block size */
71 objset_t *zv_objset; /* objset handle */
72 uint32_t zv_flags; /* ZVOL_* flags */
73 uint32_t zv_open_count; /* open counts */
74 uint32_t zv_changed; /* disk changed */
75 zilog_t *zv_zilog; /* ZIL handle */
76 znode_t zv_znode; /* for range locking */
77 dmu_buf_t *zv_dbuf; /* bonus handle */
78 dev_t zv_dev; /* device id */
79 struct gendisk *zv_disk; /* generic disk */
80 struct request_queue *zv_queue; /* request queue */
81 list_node_t zv_next; /* next zvol_state_t linkage */
84 #define ZVOL_RDONLY 0x1
87 * Find the next available range of ZVOL_MINORS minor numbers. The
88 * zvol_state_list is kept in ascending minor order so we simply need
89 * to scan the list for the first gap in the sequence. This allows us
90 * to recycle minor number as devices are created and removed.
93 zvol_find_minor(unsigned *minor)
98 ASSERT(MUTEX_HELD(&zvol_state_lock));
99 for (zv = list_head(&zvol_state_list); zv != NULL;
100 zv = list_next(&zvol_state_list, zv), *minor += ZVOL_MINORS) {
101 if (MINOR(zv->zv_dev) != MINOR(*minor))
105 /* All minors are in use */
106 if (*minor >= (1 << MINORBITS))
107 return (SET_ERROR(ENXIO));
113 * Find a zvol_state_t given the full major+minor dev_t.
115 static zvol_state_t *
116 zvol_find_by_dev(dev_t dev)
120 ASSERT(MUTEX_HELD(&zvol_state_lock));
121 for (zv = list_head(&zvol_state_list); zv != NULL;
122 zv = list_next(&zvol_state_list, zv)) {
123 if (zv->zv_dev == dev)
131 * Find a zvol_state_t given the name provided at zvol_alloc() time.
133 static zvol_state_t *
134 zvol_find_by_name(const char *name)
138 ASSERT(MUTEX_HELD(&zvol_state_lock));
139 for (zv = list_head(&zvol_state_list); zv != NULL;
140 zv = list_next(&zvol_state_list, zv)) {
141 if (strncmp(zv->zv_name, name, MAXNAMELEN) == 0)
150 * Given a path, return TRUE if path is a ZVOL.
153 zvol_is_zvol(const char *device)
155 struct block_device *bdev;
158 bdev = lookup_bdev(device);
162 major = MAJOR(bdev->bd_dev);
165 if (major == zvol_major)
172 * ZFS_IOC_CREATE callback handles dmu zvol and zap object creation.
175 zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
177 zfs_creat_t *zct = arg;
178 nvlist_t *nvprops = zct->zct_props;
180 uint64_t volblocksize, volsize;
182 VERIFY(nvlist_lookup_uint64(nvprops,
183 zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0);
184 if (nvlist_lookup_uint64(nvprops,
185 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0)
186 volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
189 * These properties must be removed from the list so the generic
190 * property setting step won't apply to them.
192 VERIFY(nvlist_remove_all(nvprops,
193 zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0);
194 (void) nvlist_remove_all(nvprops,
195 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE));
197 error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize,
201 error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP,
205 error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx);
210 * ZFS_IOC_OBJSET_STATS entry point.
213 zvol_get_stats(objset_t *os, nvlist_t *nv)
216 dmu_object_info_t *doi;
219 error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val);
221 return (SET_ERROR(error));
223 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val);
224 doi = kmem_alloc(sizeof (dmu_object_info_t), KM_SLEEP);
225 error = dmu_object_info(os, ZVOL_OBJ, doi);
228 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE,
229 doi->doi_data_block_size);
232 kmem_free(doi, sizeof (dmu_object_info_t));
234 return (SET_ERROR(error));
238 zvol_size_changed(zvol_state_t *zv, uint64_t volsize)
240 struct block_device *bdev;
242 bdev = bdget_disk(zv->zv_disk, 0);
245 set_capacity(zv->zv_disk, volsize >> 9);
246 zv->zv_volsize = volsize;
247 check_disk_size_change(zv->zv_disk, bdev);
253 * Sanity check volume size.
256 zvol_check_volsize(uint64_t volsize, uint64_t blocksize)
259 return (SET_ERROR(EINVAL));
261 if (volsize % blocksize != 0)
262 return (SET_ERROR(EINVAL));
265 if (volsize - 1 > MAXOFFSET_T)
266 return (SET_ERROR(EOVERFLOW));
272 * Ensure the zap is flushed then inform the VFS of the capacity change.
275 zvol_update_volsize(uint64_t volsize, objset_t *os)
280 ASSERT(MUTEX_HELD(&zvol_state_lock));
282 tx = dmu_tx_create(os);
283 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
284 dmu_tx_mark_netfree(tx);
285 error = dmu_tx_assign(tx, TXG_WAIT);
288 return (SET_ERROR(error));
291 error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1,
296 error = dmu_free_long_range(os,
297 ZVOL_OBJ, volsize, DMU_OBJECT_END);
303 zvol_update_live_volsize(zvol_state_t *zv, uint64_t volsize)
305 zvol_size_changed(zv, volsize);
308 * We should post a event here describing the expansion. However,
309 * the zfs_ereport_post() interface doesn't nicely support posting
310 * events for zvols, it assumes events relate to vdevs or zios.
317 * Set ZFS_PROP_VOLSIZE set entry point.
320 zvol_set_volsize(const char *name, uint64_t volsize)
322 zvol_state_t *zv = NULL;
325 dmu_object_info_t *doi;
327 boolean_t owned = B_FALSE;
329 error = dsl_prop_get_integer(name,
330 zfs_prop_to_name(ZFS_PROP_READONLY), &readonly, NULL);
332 return (SET_ERROR(error));
334 return (SET_ERROR(EROFS));
336 mutex_enter(&zvol_state_lock);
337 zv = zvol_find_by_name(name);
339 if (zv == NULL || zv->zv_objset == NULL) {
340 if ((error = dmu_objset_own(name, DMU_OST_ZVOL, B_FALSE,
342 mutex_exit(&zvol_state_lock);
343 return (SET_ERROR(error));
352 doi = kmem_alloc(sizeof (dmu_object_info_t), KM_SLEEP);
354 if ((error = dmu_object_info(os, ZVOL_OBJ, doi)) ||
355 (error = zvol_check_volsize(volsize, doi->doi_data_block_size)))
358 error = zvol_update_volsize(volsize, os);
359 kmem_free(doi, sizeof (dmu_object_info_t));
361 if (error == 0 && zv != NULL)
362 error = zvol_update_live_volsize(zv, volsize);
365 dmu_objset_disown(os, FTAG);
367 zv->zv_objset = NULL;
369 mutex_exit(&zvol_state_lock);
374 * Sanity check volume block size.
377 zvol_check_volblocksize(const char *name, uint64_t volblocksize)
379 /* Record sizes above 128k need the feature to be enabled */
380 if (volblocksize > SPA_OLD_MAXBLOCKSIZE) {
384 if ((error = spa_open(name, &spa, FTAG)) != 0)
387 if (!spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_BLOCKS)) {
388 spa_close(spa, FTAG);
389 return (SET_ERROR(ENOTSUP));
393 * We don't allow setting the property above 1MB,
394 * unless the tunable has been changed.
396 if (volblocksize > zfs_max_recordsize)
397 return (SET_ERROR(EDOM));
399 spa_close(spa, FTAG);
402 if (volblocksize < SPA_MINBLOCKSIZE ||
403 volblocksize > SPA_MAXBLOCKSIZE ||
405 return (SET_ERROR(EDOM));
411 * Set ZFS_PROP_VOLBLOCKSIZE set entry point.
414 zvol_set_volblocksize(const char *name, uint64_t volblocksize)
420 mutex_enter(&zvol_state_lock);
422 zv = zvol_find_by_name(name);
424 error = SET_ERROR(ENXIO);
428 if (zv->zv_flags & ZVOL_RDONLY) {
429 error = SET_ERROR(EROFS);
433 tx = dmu_tx_create(zv->zv_objset);
434 dmu_tx_hold_bonus(tx, ZVOL_OBJ);
435 error = dmu_tx_assign(tx, TXG_WAIT);
439 error = dmu_object_set_blocksize(zv->zv_objset, ZVOL_OBJ,
440 volblocksize, 0, tx);
441 if (error == ENOTSUP)
442 error = SET_ERROR(EBUSY);
445 zv->zv_volblocksize = volblocksize;
448 mutex_exit(&zvol_state_lock);
450 return (SET_ERROR(error));
454 * Replay a TX_TRUNCATE ZIL transaction if asked. TX_TRUNCATE is how we
455 * implement DKIOCFREE/free-long-range.
458 zvol_replay_truncate(zvol_state_t *zv, lr_truncate_t *lr, boolean_t byteswap)
460 uint64_t offset, length;
463 byteswap_uint64_array(lr, sizeof (*lr));
465 offset = lr->lr_offset;
466 length = lr->lr_length;
468 return (dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset, length));
472 * Replay a TX_WRITE ZIL transaction that didn't get committed
473 * after a system failure
476 zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap)
478 objset_t *os = zv->zv_objset;
479 char *data = (char *)(lr + 1); /* data follows lr_write_t */
480 uint64_t off = lr->lr_offset;
481 uint64_t len = lr->lr_length;
486 byteswap_uint64_array(lr, sizeof (*lr));
488 tx = dmu_tx_create(os);
489 dmu_tx_hold_write(tx, ZVOL_OBJ, off, len);
490 error = dmu_tx_assign(tx, TXG_WAIT);
494 dmu_write(os, ZVOL_OBJ, off, len, data, tx);
498 return (SET_ERROR(error));
502 zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap)
504 return (SET_ERROR(ENOTSUP));
508 * Callback vectors for replaying records.
509 * Only TX_WRITE and TX_TRUNCATE are needed for zvol.
511 zil_replay_func_t zvol_replay_vector[TX_MAX_TYPE] = {
512 (zil_replay_func_t)zvol_replay_err, /* no such transaction type */
513 (zil_replay_func_t)zvol_replay_err, /* TX_CREATE */
514 (zil_replay_func_t)zvol_replay_err, /* TX_MKDIR */
515 (zil_replay_func_t)zvol_replay_err, /* TX_MKXATTR */
516 (zil_replay_func_t)zvol_replay_err, /* TX_SYMLINK */
517 (zil_replay_func_t)zvol_replay_err, /* TX_REMOVE */
518 (zil_replay_func_t)zvol_replay_err, /* TX_RMDIR */
519 (zil_replay_func_t)zvol_replay_err, /* TX_LINK */
520 (zil_replay_func_t)zvol_replay_err, /* TX_RENAME */
521 (zil_replay_func_t)zvol_replay_write, /* TX_WRITE */
522 (zil_replay_func_t)zvol_replay_truncate, /* TX_TRUNCATE */
523 (zil_replay_func_t)zvol_replay_err, /* TX_SETATTR */
524 (zil_replay_func_t)zvol_replay_err, /* TX_ACL */
528 * zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions.
530 * We store data in the log buffers if it's small enough.
531 * Otherwise we will later flush the data out via dmu_sync().
533 ssize_t zvol_immediate_write_sz = 32768;
536 zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
537 uint64_t size, int sync)
539 uint32_t blocksize = zv->zv_volblocksize;
540 zilog_t *zilog = zv->zv_zilog;
542 ssize_t immediate_write_sz;
544 if (zil_replaying(zilog, tx))
547 immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
548 ? 0 : zvol_immediate_write_sz;
549 slogging = spa_has_slogs(zilog->zl_spa) &&
550 (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
556 itx_wr_state_t write_state;
559 * Unlike zfs_log_write() we can be called with
560 * up to DMU_MAX_ACCESS/2 (5MB) writes.
562 if (blocksize > immediate_write_sz && !slogging &&
563 size >= blocksize && offset % blocksize == 0) {
564 write_state = WR_INDIRECT; /* uses dmu_sync */
567 write_state = WR_COPIED;
568 len = MIN(ZIL_MAX_LOG_DATA, size);
570 write_state = WR_NEED_COPY;
571 len = MIN(ZIL_MAX_LOG_DATA, size);
574 itx = zil_itx_create(TX_WRITE, sizeof (*lr) +
575 (write_state == WR_COPIED ? len : 0));
576 lr = (lr_write_t *)&itx->itx_lr;
577 if (write_state == WR_COPIED && dmu_read(zv->zv_objset,
578 ZVOL_OBJ, offset, len, lr+1, DMU_READ_NO_PREFETCH) != 0) {
579 zil_itx_destroy(itx);
580 itx = zil_itx_create(TX_WRITE, sizeof (*lr));
581 lr = (lr_write_t *)&itx->itx_lr;
582 write_state = WR_NEED_COPY;
585 itx->itx_wr_state = write_state;
586 if (write_state == WR_NEED_COPY)
588 lr->lr_foid = ZVOL_OBJ;
589 lr->lr_offset = offset;
592 BP_ZERO(&lr->lr_blkptr);
594 itx->itx_private = zv;
595 itx->itx_sync = sync;
597 (void) zil_itx_assign(zilog, itx, tx);
605 zvol_write(zvol_state_t *zv, uio_t *uio, boolean_t sync)
607 uint64_t volsize = zv->zv_volsize;
611 ASSERT(zv && zv->zv_open_count > 0);
613 rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid,
616 while (uio->uio_resid > 0 && uio->uio_loffset < volsize) {
617 uint64_t bytes = MIN(uio->uio_resid, DMU_MAX_ACCESS >> 1);
618 uint64_t off = uio->uio_loffset;
619 dmu_tx_t *tx = dmu_tx_create(zv->zv_objset);
621 if (bytes > volsize - off) /* don't write past the end */
622 bytes = volsize - off;
624 dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes);
626 /* This will only fail for ENOSPC */
627 error = dmu_tx_assign(tx, TXG_WAIT);
632 error = dmu_write_uio_dbuf(zv->zv_dbuf, uio, bytes, tx);
634 zvol_log_write(zv, tx, off, bytes, sync);
640 zfs_range_unlock(rl);
642 zil_commit(zv->zv_zilog, ZVOL_OBJ);
647 * Log a DKIOCFREE/free-long-range to the ZIL with TX_TRUNCATE.
650 zvol_log_truncate(zvol_state_t *zv, dmu_tx_t *tx, uint64_t off, uint64_t len,
655 zilog_t *zilog = zv->zv_zilog;
657 if (zil_replaying(zilog, tx))
660 itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
661 lr = (lr_truncate_t *)&itx->itx_lr;
662 lr->lr_foid = ZVOL_OBJ;
666 itx->itx_sync = sync;
667 zil_itx_assign(zilog, itx, tx);
671 zvol_discard(struct bio *bio)
673 zvol_state_t *zv = bio->bi_bdev->bd_disk->private_data;
674 uint64_t start = BIO_BI_SECTOR(bio) << 9;
675 uint64_t size = BIO_BI_SIZE(bio);
676 uint64_t end = start + size;
681 ASSERT(zv && zv->zv_open_count > 0);
683 if (end > zv->zv_volsize)
684 return (SET_ERROR(EIO));
687 * Align the request to volume block boundaries when REQ_SECURE is
688 * available, but not requested. If we don't, then this will force
689 * dnode_free_range() to zero out the unaligned parts, which is slow
690 * (read-modify-write) and useless since we are not freeing any space
691 * by doing so. Kernels that do not support REQ_SECURE (2.6.32 through
692 * 2.6.35) will not receive this optimization.
695 if (!(bio->bi_rw & REQ_SECURE)) {
696 start = P2ROUNDUP(start, zv->zv_volblocksize);
697 end = P2ALIGN(end, zv->zv_volblocksize);
705 rl = zfs_range_lock(&zv->zv_znode, start, size, RL_WRITER);
706 tx = dmu_tx_create(zv->zv_objset);
707 dmu_tx_mark_netfree(tx);
708 error = dmu_tx_assign(tx, TXG_WAIT);
712 zvol_log_truncate(zv, tx, start, size, B_TRUE);
714 error = dmu_free_long_range(zv->zv_objset,
715 ZVOL_OBJ, start, size);
718 zfs_range_unlock(rl);
724 zvol_read(zvol_state_t *zv, uio_t *uio)
726 uint64_t volsize = zv->zv_volsize;
730 ASSERT(zv && zv->zv_open_count > 0);
732 rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid,
734 while (uio->uio_resid > 0 && uio->uio_loffset < volsize) {
735 uint64_t bytes = MIN(uio->uio_resid, DMU_MAX_ACCESS >> 1);
737 /* don't read past the end */
738 if (bytes > volsize - uio->uio_loffset)
739 bytes = volsize - uio->uio_loffset;
741 error = dmu_read_uio_dbuf(zv->zv_dbuf, uio, bytes);
743 /* convert checksum errors into IO errors */
745 error = SET_ERROR(EIO);
749 zfs_range_unlock(rl);
753 static MAKE_REQUEST_FN_RET
754 zvol_request(struct request_queue *q, struct bio *bio)
757 zvol_state_t *zv = q->queuedata;
758 fstrans_cookie_t cookie = spl_fstrans_mark();
759 int rw = bio_data_dir(bio);
760 #ifdef HAVE_GENERIC_IO_ACCT
761 unsigned long start = jiffies;
765 uio.uio_bvec = &bio->bi_io_vec[BIO_BI_IDX(bio)];
766 uio.uio_skip = BIO_BI_SKIP(bio);
767 uio.uio_resid = BIO_BI_SIZE(bio);
768 uio.uio_iovcnt = bio->bi_vcnt - BIO_BI_IDX(bio);
769 uio.uio_loffset = BIO_BI_SECTOR(bio) << 9;
770 uio.uio_limit = MAXOFFSET_T;
771 uio.uio_segflg = UIO_BVEC;
773 if (bio_has_data(bio) && uio.uio_loffset + uio.uio_resid >
776 "%s: bad access: offset=%llu, size=%lu\n",
777 zv->zv_disk->disk_name,
778 (long long unsigned)uio.uio_loffset,
779 (long unsigned)uio.uio_resid);
780 error = SET_ERROR(EIO);
784 generic_start_io_acct(rw, bio_sectors(bio), &zv->zv_disk->part0);
787 if (unlikely(zv->zv_flags & ZVOL_RDONLY)) {
788 error = SET_ERROR(EROFS);
792 if (bio->bi_rw & VDEV_REQ_DISCARD) {
793 error = zvol_discard(bio);
798 * Some requests are just for flush and nothing else.
800 if (uio.uio_resid == 0) {
801 if (bio->bi_rw & VDEV_REQ_FLUSH)
802 zil_commit(zv->zv_zilog, ZVOL_OBJ);
806 error = zvol_write(zv, &uio,
807 ((bio->bi_rw & (VDEV_REQ_FUA|VDEV_REQ_FLUSH)) ||
808 zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS));
810 error = zvol_read(zv, &uio);
813 generic_end_io_acct(rw, &zv->zv_disk->part0, start);
815 BIO_END_IO(bio, -error);
816 spl_fstrans_unmark(cookie);
817 #ifdef HAVE_MAKE_REQUEST_FN_RET_INT
819 #elif defined(HAVE_MAKE_REQUEST_FN_RET_QC)
820 return (BLK_QC_T_NONE);
825 zvol_get_done(zgd_t *zgd, int error)
828 dmu_buf_rele(zgd->zgd_db, zgd);
830 zfs_range_unlock(zgd->zgd_rl);
832 if (error == 0 && zgd->zgd_bp)
833 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
835 kmem_free(zgd, sizeof (zgd_t));
839 * Get data to generate a TX_WRITE intent log record.
842 zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
844 zvol_state_t *zv = arg;
845 objset_t *os = zv->zv_objset;
846 uint64_t object = ZVOL_OBJ;
847 uint64_t offset = lr->lr_offset;
848 uint64_t size = lr->lr_length;
849 blkptr_t *bp = &lr->lr_blkptr;
857 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
858 zgd->zgd_zilog = zv->zv_zilog;
859 zgd->zgd_rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_READER);
862 * Write records come in two flavors: immediate and indirect.
863 * For small writes it's cheaper to store the data with the
864 * log record (immediate); for large writes it's cheaper to
865 * sync the data and get a pointer to it (indirect) so that
866 * we don't have to write the data twice.
868 if (buf != NULL) { /* immediate write */
869 error = dmu_read(os, object, offset, size, buf,
870 DMU_READ_NO_PREFETCH);
872 size = zv->zv_volblocksize;
873 offset = P2ALIGN_TYPED(offset, size, uint64_t);
874 error = dmu_buf_hold(os, object, offset, zgd, &db,
875 DMU_READ_NO_PREFETCH);
877 blkptr_t *obp = dmu_buf_get_blkptr(db);
879 ASSERT(BP_IS_HOLE(bp));
884 zgd->zgd_bp = &lr->lr_blkptr;
887 ASSERT(db->db_offset == offset);
888 ASSERT(db->db_size == size);
890 error = dmu_sync(zio, lr->lr_common.lrc_txg,
898 zvol_get_done(zgd, error);
900 return (SET_ERROR(error));
904 * The zvol_state_t's are inserted in increasing MINOR(dev_t) order.
907 zvol_insert(zvol_state_t *zv_insert)
909 zvol_state_t *zv = NULL;
911 ASSERT(MUTEX_HELD(&zvol_state_lock));
912 ASSERT3U(MINOR(zv_insert->zv_dev) & ZVOL_MINOR_MASK, ==, 0);
913 for (zv = list_head(&zvol_state_list); zv != NULL;
914 zv = list_next(&zvol_state_list, zv)) {
915 if (MINOR(zv->zv_dev) > MINOR(zv_insert->zv_dev))
919 list_insert_before(&zvol_state_list, zv, zv_insert);
923 * Simply remove the zvol from to list of zvols.
926 zvol_remove(zvol_state_t *zv_remove)
928 ASSERT(MUTEX_HELD(&zvol_state_lock));
929 list_remove(&zvol_state_list, zv_remove);
933 zvol_first_open(zvol_state_t *zv)
942 * In all other cases the spa_namespace_lock is taken before the
943 * bdev->bd_mutex lock. But in this case the Linux __blkdev_get()
944 * function calls fops->open() with the bdev->bd_mutex lock held.
946 * To avoid a potential lock inversion deadlock we preemptively
947 * try to take the spa_namespace_lock(). Normally it will not
948 * be contended and this is safe because spa_open_common() handles
949 * the case where the caller already holds the spa_namespace_lock.
951 * When it is contended we risk a lock inversion if we were to
952 * block waiting for the lock. Luckily, the __blkdev_get()
953 * function allows us to return -ERESTARTSYS which will result in
954 * bdev->bd_mutex being dropped, reacquired, and fops->open() being
955 * called again. This process can be repeated safely until both
956 * locks are acquired.
958 if (!mutex_owned(&spa_namespace_lock)) {
959 locked = mutex_tryenter(&spa_namespace_lock);
961 return (-SET_ERROR(ERESTARTSYS));
964 error = dsl_prop_get_integer(zv->zv_name, "readonly", &ro, NULL);
968 /* lie and say we're read-only */
969 error = dmu_objset_own(zv->zv_name, DMU_OST_ZVOL, 1, zvol_tag, &os);
973 error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize);
975 dmu_objset_disown(os, zvol_tag);
980 error = dmu_bonus_hold(os, ZVOL_OBJ, zvol_tag, &zv->zv_dbuf);
982 dmu_objset_disown(os, zvol_tag);
986 set_capacity(zv->zv_disk, volsize >> 9);
987 zv->zv_volsize = volsize;
988 zv->zv_zilog = zil_open(os, zvol_get_data);
990 if (ro || dmu_objset_is_snapshot(os) ||
991 !spa_writeable(dmu_objset_spa(os))) {
992 set_disk_ro(zv->zv_disk, 1);
993 zv->zv_flags |= ZVOL_RDONLY;
995 set_disk_ro(zv->zv_disk, 0);
996 zv->zv_flags &= ~ZVOL_RDONLY;
1001 mutex_exit(&spa_namespace_lock);
1003 return (SET_ERROR(-error));
1007 zvol_last_close(zvol_state_t *zv)
1009 zil_close(zv->zv_zilog);
1010 zv->zv_zilog = NULL;
1012 dmu_buf_rele(zv->zv_dbuf, zvol_tag);
1018 if (dsl_dataset_is_dirty(dmu_objset_ds(zv->zv_objset)) &&
1019 !(zv->zv_flags & ZVOL_RDONLY))
1020 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0);
1021 (void) dmu_objset_evict_dbufs(zv->zv_objset);
1023 dmu_objset_disown(zv->zv_objset, zvol_tag);
1024 zv->zv_objset = NULL;
1028 zvol_open(struct block_device *bdev, fmode_t flag)
1031 int error = 0, drop_mutex = 0;
1034 * If the caller is already holding the mutex do not take it
1035 * again, this will happen as part of zvol_create_minor().
1036 * Once add_disk() is called the device is live and the kernel
1037 * will attempt to open it to read the partition information.
1039 if (!mutex_owned(&zvol_state_lock)) {
1040 mutex_enter(&zvol_state_lock);
1045 * Obtain a copy of private_data under the lock to make sure
1046 * that either the result of zvol_freeg() setting
1047 * bdev->bd_disk->private_data to NULL is observed, or zvol_free()
1048 * is not called on this zv because of the positive zv_open_count.
1050 zv = bdev->bd_disk->private_data;
1056 if (zv->zv_open_count == 0) {
1057 error = zvol_first_open(zv);
1062 if ((flag & FMODE_WRITE) && (zv->zv_flags & ZVOL_RDONLY)) {
1064 goto out_open_count;
1067 zv->zv_open_count++;
1069 check_disk_change(bdev);
1072 if (zv->zv_open_count == 0)
1073 zvol_last_close(zv);
1077 mutex_exit(&zvol_state_lock);
1079 return (SET_ERROR(error));
1082 #ifdef HAVE_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
1087 zvol_release(struct gendisk *disk, fmode_t mode)
1089 zvol_state_t *zv = disk->private_data;
1092 ASSERT(zv && zv->zv_open_count > 0);
1094 if (!mutex_owned(&zvol_state_lock)) {
1095 mutex_enter(&zvol_state_lock);
1099 zv->zv_open_count--;
1100 if (zv->zv_open_count == 0)
1101 zvol_last_close(zv);
1104 mutex_exit(&zvol_state_lock);
1106 #ifndef HAVE_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
1112 zvol_ioctl(struct block_device *bdev, fmode_t mode,
1113 unsigned int cmd, unsigned long arg)
1115 zvol_state_t *zv = bdev->bd_disk->private_data;
1118 ASSERT(zv && zv->zv_open_count > 0);
1122 zil_commit(zv->zv_zilog, ZVOL_OBJ);
1125 error = copy_to_user((void *)arg, zv->zv_name, MAXNAMELEN);
1134 return (SET_ERROR(error));
1137 #ifdef CONFIG_COMPAT
1139 zvol_compat_ioctl(struct block_device *bdev, fmode_t mode,
1140 unsigned cmd, unsigned long arg)
1142 return (zvol_ioctl(bdev, mode, cmd, arg));
1145 #define zvol_compat_ioctl NULL
1148 static int zvol_media_changed(struct gendisk *disk)
1150 zvol_state_t *zv = disk->private_data;
1152 ASSERT(zv && zv->zv_open_count > 0);
1154 return (zv->zv_changed);
1157 static int zvol_revalidate_disk(struct gendisk *disk)
1159 zvol_state_t *zv = disk->private_data;
1161 ASSERT(zv && zv->zv_open_count > 0);
1164 set_capacity(zv->zv_disk, zv->zv_volsize >> 9);
1170 * Provide a simple virtual geometry for legacy compatibility. For devices
1171 * smaller than 1 MiB a small head and sector count is used to allow very
1172 * tiny devices. For devices over 1 Mib a standard head and sector count
1173 * is used to keep the cylinders count reasonable.
1176 zvol_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1178 zvol_state_t *zv = bdev->bd_disk->private_data;
1181 ASSERT(zv && zv->zv_open_count > 0);
1183 sectors = get_capacity(zv->zv_disk);
1185 if (sectors > 2048) {
1194 geo->cylinders = sectors / (geo->heads * geo->sectors);
1199 static struct kobject *
1200 zvol_probe(dev_t dev, int *part, void *arg)
1203 struct kobject *kobj;
1205 mutex_enter(&zvol_state_lock);
1206 zv = zvol_find_by_dev(dev);
1207 kobj = zv ? get_disk(zv->zv_disk) : NULL;
1208 mutex_exit(&zvol_state_lock);
1213 #ifdef HAVE_BDEV_BLOCK_DEVICE_OPERATIONS
1214 static struct block_device_operations zvol_ops = {
1216 .release = zvol_release,
1217 .ioctl = zvol_ioctl,
1218 .compat_ioctl = zvol_compat_ioctl,
1219 .media_changed = zvol_media_changed,
1220 .revalidate_disk = zvol_revalidate_disk,
1221 .getgeo = zvol_getgeo,
1222 .owner = THIS_MODULE,
1225 #else /* HAVE_BDEV_BLOCK_DEVICE_OPERATIONS */
1228 zvol_open_by_inode(struct inode *inode, struct file *file)
1230 return (zvol_open(inode->i_bdev, file->f_mode));
1234 zvol_release_by_inode(struct inode *inode, struct file *file)
1236 return (zvol_release(inode->i_bdev->bd_disk, file->f_mode));
1240 zvol_ioctl_by_inode(struct inode *inode, struct file *file,
1241 unsigned int cmd, unsigned long arg)
1243 if (file == NULL || inode == NULL)
1244 return (SET_ERROR(-EINVAL));
1246 return (zvol_ioctl(inode->i_bdev, file->f_mode, cmd, arg));
1249 #ifdef CONFIG_COMPAT
1251 zvol_compat_ioctl_by_inode(struct file *file,
1252 unsigned int cmd, unsigned long arg)
1255 return (SET_ERROR(-EINVAL));
1257 return (zvol_compat_ioctl(file->f_dentry->d_inode->i_bdev,
1258 file->f_mode, cmd, arg));
1261 #define zvol_compat_ioctl_by_inode NULL
1264 static struct block_device_operations zvol_ops = {
1265 .open = zvol_open_by_inode,
1266 .release = zvol_release_by_inode,
1267 .ioctl = zvol_ioctl_by_inode,
1268 .compat_ioctl = zvol_compat_ioctl_by_inode,
1269 .media_changed = zvol_media_changed,
1270 .revalidate_disk = zvol_revalidate_disk,
1271 .getgeo = zvol_getgeo,
1272 .owner = THIS_MODULE,
1274 #endif /* HAVE_BDEV_BLOCK_DEVICE_OPERATIONS */
1277 * Allocate memory for a new zvol_state_t and setup the required
1278 * request queue and generic disk structures for the block device.
1280 static zvol_state_t *
1281 zvol_alloc(dev_t dev, const char *name)
1285 zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
1287 list_link_init(&zv->zv_next);
1289 zv->zv_queue = blk_alloc_queue(GFP_ATOMIC);
1290 if (zv->zv_queue == NULL)
1293 blk_queue_make_request(zv->zv_queue, zvol_request);
1295 #ifdef HAVE_BLK_QUEUE_FLUSH
1296 blk_queue_flush(zv->zv_queue, VDEV_REQ_FLUSH | VDEV_REQ_FUA);
1298 blk_queue_ordered(zv->zv_queue, QUEUE_ORDERED_DRAIN, NULL);
1299 #endif /* HAVE_BLK_QUEUE_FLUSH */
1301 zv->zv_disk = alloc_disk(ZVOL_MINORS);
1302 if (zv->zv_disk == NULL)
1305 zv->zv_queue->queuedata = zv;
1307 zv->zv_open_count = 0;
1308 strlcpy(zv->zv_name, name, MAXNAMELEN);
1310 mutex_init(&zv->zv_znode.z_range_lock, NULL, MUTEX_DEFAULT, NULL);
1311 avl_create(&zv->zv_znode.z_range_avl, zfs_range_compare,
1312 sizeof (rl_t), offsetof(rl_t, r_node));
1313 zv->zv_znode.z_is_zvol = TRUE;
1315 zv->zv_disk->major = zvol_major;
1316 zv->zv_disk->first_minor = (dev & MINORMASK);
1317 zv->zv_disk->fops = &zvol_ops;
1318 zv->zv_disk->private_data = zv;
1319 zv->zv_disk->queue = zv->zv_queue;
1320 snprintf(zv->zv_disk->disk_name, DISK_NAME_LEN, "%s%d",
1321 ZVOL_DEV_NAME, (dev & MINORMASK));
1326 blk_cleanup_queue(zv->zv_queue);
1328 kmem_free(zv, sizeof (zvol_state_t));
1334 * Cleanup then free a zvol_state_t which was created by zvol_alloc().
1337 zvol_free(zvol_state_t *zv)
1339 ASSERT(MUTEX_HELD(&zvol_state_lock));
1340 ASSERT(zv->zv_open_count == 0);
1342 avl_destroy(&zv->zv_znode.z_range_avl);
1343 mutex_destroy(&zv->zv_znode.z_range_lock);
1345 zv->zv_disk->private_data = NULL;
1347 del_gendisk(zv->zv_disk);
1348 blk_cleanup_queue(zv->zv_queue);
1349 put_disk(zv->zv_disk);
1351 kmem_free(zv, sizeof (zvol_state_t));
1355 __zvol_snapdev_hidden(const char *name)
1362 parent = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1363 (void) strlcpy(parent, name, MAXPATHLEN);
1365 if ((atp = strrchr(parent, '@')) != NULL) {
1367 error = dsl_prop_get_integer(parent, "snapdev", &snapdev, NULL);
1368 if ((error == 0) && (snapdev == ZFS_SNAPDEV_HIDDEN))
1369 error = SET_ERROR(ENODEV);
1372 kmem_free(parent, MAXPATHLEN);
1374 return (SET_ERROR(error));
1378 __zvol_create_minor(const char *name, boolean_t ignore_snapdev)
1382 dmu_object_info_t *doi;
1388 ASSERT(MUTEX_HELD(&zvol_state_lock));
1390 zv = zvol_find_by_name(name);
1392 error = SET_ERROR(EEXIST);
1396 if (ignore_snapdev == B_FALSE) {
1397 error = __zvol_snapdev_hidden(name);
1402 doi = kmem_alloc(sizeof (dmu_object_info_t), KM_SLEEP);
1404 error = dmu_objset_own(name, DMU_OST_ZVOL, B_TRUE, zvol_tag, &os);
1408 error = dmu_object_info(os, ZVOL_OBJ, doi);
1410 goto out_dmu_objset_disown;
1412 error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize);
1414 goto out_dmu_objset_disown;
1416 error = zvol_find_minor(&minor);
1418 goto out_dmu_objset_disown;
1420 zv = zvol_alloc(MKDEV(zvol_major, minor), name);
1422 error = SET_ERROR(EAGAIN);
1423 goto out_dmu_objset_disown;
1426 if (dmu_objset_is_snapshot(os))
1427 zv->zv_flags |= ZVOL_RDONLY;
1429 zv->zv_volblocksize = doi->doi_data_block_size;
1430 zv->zv_volsize = volsize;
1433 set_capacity(zv->zv_disk, zv->zv_volsize >> 9);
1435 blk_queue_max_hw_sectors(zv->zv_queue, (DMU_MAX_ACCESS / 4) >> 9);
1436 blk_queue_max_segments(zv->zv_queue, UINT16_MAX);
1437 blk_queue_max_segment_size(zv->zv_queue, UINT_MAX);
1438 blk_queue_physical_block_size(zv->zv_queue, zv->zv_volblocksize);
1439 blk_queue_io_opt(zv->zv_queue, zv->zv_volblocksize);
1440 blk_queue_max_discard_sectors(zv->zv_queue,
1441 (zvol_max_discard_blocks * zv->zv_volblocksize) >> 9);
1442 blk_queue_discard_granularity(zv->zv_queue, zv->zv_volblocksize);
1443 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, zv->zv_queue);
1444 #ifdef QUEUE_FLAG_NONROT
1445 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zv->zv_queue);
1447 #ifdef QUEUE_FLAG_ADD_RANDOM
1448 queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, zv->zv_queue);
1451 if (spa_writeable(dmu_objset_spa(os))) {
1452 if (zil_replay_disable)
1453 zil_destroy(dmu_objset_zil(os), B_FALSE);
1455 zil_replay(os, zv, zvol_replay_vector);
1459 * When udev detects the addition of the device it will immediately
1460 * invoke blkid(8) to determine the type of content on the device.
1461 * Prefetching the blocks commonly scanned by blkid(8) will speed
1464 len = MIN(MAX(zvol_prefetch_bytes, 0), SPA_MAXBLOCKSIZE);
1466 dmu_prefetch(os, ZVOL_OBJ, 0, 0, len, ZIO_PRIORITY_SYNC_READ);
1467 dmu_prefetch(os, ZVOL_OBJ, 0, volsize - len, len,
1468 ZIO_PRIORITY_SYNC_READ);
1471 zv->zv_objset = NULL;
1472 out_dmu_objset_disown:
1473 dmu_objset_disown(os, zvol_tag);
1475 kmem_free(doi, sizeof (dmu_object_info_t));
1481 * Drop the lock to prevent deadlock with sys_open() ->
1482 * zvol_open(), which first takes bd_disk->bd_mutex and then
1483 * takes zvol_state_lock, whereas this code path first takes
1484 * zvol_state_lock, and then takes bd_disk->bd_mutex.
1486 mutex_exit(&zvol_state_lock);
1487 add_disk(zv->zv_disk);
1488 mutex_enter(&zvol_state_lock);
1491 return (SET_ERROR(error));
1495 * Create a block device minor node and setup the linkage between it
1496 * and the specified volume. Once this function returns the block
1497 * device is live and ready for use.
1500 zvol_create_minor(const char *name)
1504 mutex_enter(&zvol_state_lock);
1505 error = __zvol_create_minor(name, B_FALSE);
1506 mutex_exit(&zvol_state_lock);
1508 return (SET_ERROR(error));
1512 __zvol_remove_minor(const char *name)
1516 ASSERT(MUTEX_HELD(&zvol_state_lock));
1518 zv = zvol_find_by_name(name);
1520 return (SET_ERROR(ENXIO));
1522 if (zv->zv_open_count > 0)
1523 return (SET_ERROR(EBUSY));
1532 * Remove a block device minor node for the specified volume.
1535 zvol_remove_minor(const char *name)
1539 mutex_enter(&zvol_state_lock);
1540 error = __zvol_remove_minor(name);
1541 mutex_exit(&zvol_state_lock);
1543 return (SET_ERROR(error));
1547 * Rename a block device minor mode for the specified volume.
1550 __zvol_rename_minor(zvol_state_t *zv, const char *newname)
1552 int readonly = get_disk_ro(zv->zv_disk);
1554 ASSERT(MUTEX_HELD(&zvol_state_lock));
1556 strlcpy(zv->zv_name, newname, sizeof (zv->zv_name));
1559 * The block device's read-only state is briefly changed causing
1560 * a KOBJ_CHANGE uevent to be issued. This ensures udev detects
1561 * the name change and fixes the symlinks. This does not change
1562 * ZVOL_RDONLY in zv->zv_flags so the actual read-only state never
1563 * changes. This would normally be done using kobject_uevent() but
1564 * that is a GPL-only symbol which is why we need this workaround.
1566 set_disk_ro(zv->zv_disk, !readonly);
1567 set_disk_ro(zv->zv_disk, readonly);
1571 zvol_create_minors_cb(const char *dsname, void *arg)
1573 (void) zvol_create_minor(dsname);
1579 * Create minors for specified dataset including children and snapshots.
1582 zvol_create_minors(const char *name)
1585 fstrans_cookie_t cookie;
1587 if (zvol_inhibit_dev)
1590 cookie = spl_fstrans_mark();
1591 error = dmu_objset_find((char *)name, zvol_create_minors_cb,
1592 NULL, DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS);
1593 spl_fstrans_unmark(cookie);
1595 return (SET_ERROR(error));
1599 * Remove minors for specified dataset including children and snapshots.
1602 zvol_remove_minors(const char *name)
1604 zvol_state_t *zv, *zv_next;
1605 int namelen = ((name) ? strlen(name) : 0);
1607 if (zvol_inhibit_dev)
1610 mutex_enter(&zvol_state_lock);
1612 for (zv = list_head(&zvol_state_list); zv != NULL; zv = zv_next) {
1613 zv_next = list_next(&zvol_state_list, zv);
1615 if (name == NULL || strcmp(zv->zv_name, name) == 0 ||
1616 (strncmp(zv->zv_name, name, namelen) == 0 &&
1617 (zv->zv_name[namelen] == '/' ||
1618 zv->zv_name[namelen] == '@'))) {
1620 /* If in use, leave alone */
1621 if (zv->zv_open_count > 0)
1629 mutex_exit(&zvol_state_lock);
1633 * Rename minors for specified dataset including children and snapshots.
1636 zvol_rename_minors(const char *oldname, const char *newname)
1638 zvol_state_t *zv, *zv_next;
1639 int oldnamelen, newnamelen;
1642 if (zvol_inhibit_dev)
1645 oldnamelen = strlen(oldname);
1646 newnamelen = strlen(newname);
1647 name = kmem_alloc(MAXNAMELEN, KM_SLEEP);
1649 mutex_enter(&zvol_state_lock);
1651 for (zv = list_head(&zvol_state_list); zv != NULL; zv = zv_next) {
1652 zv_next = list_next(&zvol_state_list, zv);
1654 /* If in use, leave alone */
1655 if (zv->zv_open_count > 0)
1658 if (strcmp(zv->zv_name, oldname) == 0) {
1659 __zvol_rename_minor(zv, newname);
1660 } else if (strncmp(zv->zv_name, oldname, oldnamelen) == 0 &&
1661 (zv->zv_name[oldnamelen] == '/' ||
1662 zv->zv_name[oldnamelen] == '@')) {
1663 snprintf(name, MAXNAMELEN, "%s%c%s", newname,
1664 zv->zv_name[oldnamelen],
1665 zv->zv_name + oldnamelen + 1);
1666 __zvol_rename_minor(zv, name);
1670 mutex_exit(&zvol_state_lock);
1672 kmem_free(name, MAXNAMELEN);
1676 snapdev_snapshot_changed_cb(const char *dsname, void *arg) {
1677 uint64_t snapdev = *(uint64_t *) arg;
1679 if (strchr(dsname, '@') == NULL)
1683 case ZFS_SNAPDEV_VISIBLE:
1684 mutex_enter(&zvol_state_lock);
1685 (void) __zvol_create_minor(dsname, B_TRUE);
1686 mutex_exit(&zvol_state_lock);
1688 case ZFS_SNAPDEV_HIDDEN:
1689 (void) zvol_remove_minor(dsname);
1697 zvol_set_snapdev(const char *dsname, uint64_t snapdev) {
1698 fstrans_cookie_t cookie;
1700 if (zvol_inhibit_dev)
1701 /* caller should continue to modify snapdev property */
1704 cookie = spl_fstrans_mark();
1705 (void) dmu_objset_find((char *) dsname, snapdev_snapshot_changed_cb,
1706 &snapdev, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
1707 spl_fstrans_unmark(cookie);
1709 /* caller should continue to modify snapdev property */
1718 list_create(&zvol_state_list, sizeof (zvol_state_t),
1719 offsetof(zvol_state_t, zv_next));
1721 mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL);
1723 error = register_blkdev(zvol_major, ZVOL_DRIVER);
1725 printk(KERN_INFO "ZFS: register_blkdev() failed %d\n", error);
1729 blk_register_region(MKDEV(zvol_major, 0), 1UL << MINORBITS,
1730 THIS_MODULE, zvol_probe, NULL, NULL);
1735 mutex_destroy(&zvol_state_lock);
1736 list_destroy(&zvol_state_list);
1738 return (SET_ERROR(error));
1744 zvol_remove_minors(NULL);
1745 blk_unregister_region(MKDEV(zvol_major, 0), 1UL << MINORBITS);
1746 unregister_blkdev(zvol_major, ZVOL_DRIVER);
1747 mutex_destroy(&zvol_state_lock);
1748 list_destroy(&zvol_state_list);
1751 module_param(zvol_inhibit_dev, uint, 0644);
1752 MODULE_PARM_DESC(zvol_inhibit_dev, "Do not create zvol device nodes");
1754 module_param(zvol_major, uint, 0444);
1755 MODULE_PARM_DESC(zvol_major, "Major number for zvol device");
1757 module_param(zvol_max_discard_blocks, ulong, 0444);
1758 MODULE_PARM_DESC(zvol_max_discard_blocks, "Max number of blocks to discard");
1760 module_param(zvol_prefetch_bytes, uint, 0644);
1761 MODULE_PARM_DESC(zvol_prefetch_bytes, "Prefetch N bytes at zvol start+end");