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>
45 #include <sys/dsl_dir.h>
47 #include <sys/zfeature.h>
48 #include <sys/zil_impl.h>
49 #include <sys/dmu_tx.h>
51 #include <sys/zfs_rlock.h>
52 #include <sys/zfs_znode.h>
53 #include <sys/spa_impl.h>
55 #include <linux/blkdev_compat.h>
57 unsigned int zvol_inhibit_dev
= 0;
58 unsigned int zvol_major
= ZVOL_MAJOR
;
59 unsigned int zvol_threads
= 32;
60 unsigned int zvol_request_sync
= 0;
61 unsigned int zvol_prefetch_bytes
= (128 * 1024);
62 unsigned long zvol_max_discard_blocks
= 16384;
64 static taskq_t
*zvol_taskq
;
65 static kmutex_t zvol_state_lock
;
66 static list_t zvol_state_list
;
68 #define ZVOL_HT_SIZE 1024
69 static struct hlist_head
*zvol_htable
;
70 #define ZVOL_HT_HEAD(hash) (&zvol_htable[(hash) & (ZVOL_HT_SIZE-1)])
72 static struct ida zvol_ida
;
75 * The in-core state of each volume.
78 char zv_name
[MAXNAMELEN
]; /* name */
79 uint64_t zv_volsize
; /* advertised space */
80 uint64_t zv_volblocksize
; /* volume block size */
81 objset_t
*zv_objset
; /* objset handle */
82 uint32_t zv_flags
; /* ZVOL_* flags */
83 uint32_t zv_open_count
; /* open counts */
84 uint32_t zv_changed
; /* disk changed */
85 zilog_t
*zv_zilog
; /* ZIL handle */
86 zfs_rlock_t zv_range_lock
; /* range lock */
87 dmu_buf_t
*zv_dbuf
; /* bonus handle */
88 dev_t zv_dev
; /* device id */
89 struct gendisk
*zv_disk
; /* generic disk */
90 struct request_queue
*zv_queue
; /* request queue */
91 list_node_t zv_next
; /* next zvol_state_t linkage */
92 uint64_t zv_hash
; /* name hash */
93 struct hlist_node zv_hlink
; /* hash link */
94 atomic_t zv_suspend_ref
; /* refcount for suspend */
95 krwlock_t zv_suspend_lock
; /* suspend lock */
99 ZVOL_ASYNC_CREATE_MINORS
,
100 ZVOL_ASYNC_REMOVE_MINORS
,
101 ZVOL_ASYNC_RENAME_MINORS
,
102 ZVOL_ASYNC_SET_SNAPDEV
,
108 char pool
[MAXNAMELEN
];
109 char name1
[MAXNAMELEN
];
110 char name2
[MAXNAMELEN
];
111 zprop_source_t source
;
115 #define ZVOL_RDONLY 0x1
118 zvol_name_hash(const char *name
)
121 uint64_t crc
= -1ULL;
122 uint8_t *p
= (uint8_t *)name
;
123 ASSERT(zfs_crc64_table
[128] == ZFS_CRC64_POLY
);
124 for (i
= 0; i
< MAXNAMELEN
- 1 && *p
; i
++, p
++) {
125 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (*p
)) & 0xFF];
131 * Find a zvol_state_t given the full major+minor dev_t.
133 static zvol_state_t
*
134 zvol_find_by_dev(dev_t dev
)
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 (zv
->zv_dev
== dev
)
149 * Find a zvol_state_t given the name and hash generated by zvol_name_hash.
151 static zvol_state_t
*
152 zvol_find_by_name_hash(const char *name
, uint64_t hash
)
155 struct hlist_node
*p
;
157 ASSERT(MUTEX_HELD(&zvol_state_lock
));
158 hlist_for_each(p
, ZVOL_HT_HEAD(hash
)) {
159 zv
= hlist_entry(p
, zvol_state_t
, zv_hlink
);
160 if (zv
->zv_hash
== hash
&&
161 strncmp(zv
->zv_name
, name
, MAXNAMELEN
) == 0)
168 * Find a zvol_state_t given the name provided at zvol_alloc() time.
170 static zvol_state_t
*
171 zvol_find_by_name(const char *name
)
173 return (zvol_find_by_name_hash(name
, zvol_name_hash(name
)));
178 * Given a path, return TRUE if path is a ZVOL.
181 zvol_is_zvol(const char *device
)
183 struct block_device
*bdev
;
186 bdev
= vdev_lookup_bdev(device
);
190 major
= MAJOR(bdev
->bd_dev
);
193 if (major
== zvol_major
)
200 * ZFS_IOC_CREATE callback handles dmu zvol and zap object creation.
203 zvol_create_cb(objset_t
*os
, void *arg
, cred_t
*cr
, dmu_tx_t
*tx
)
205 zfs_creat_t
*zct
= arg
;
206 nvlist_t
*nvprops
= zct
->zct_props
;
208 uint64_t volblocksize
, volsize
;
210 VERIFY(nvlist_lookup_uint64(nvprops
,
211 zfs_prop_to_name(ZFS_PROP_VOLSIZE
), &volsize
) == 0);
212 if (nvlist_lookup_uint64(nvprops
,
213 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
), &volblocksize
) != 0)
214 volblocksize
= zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE
);
217 * These properties must be removed from the list so the generic
218 * property setting step won't apply to them.
220 VERIFY(nvlist_remove_all(nvprops
,
221 zfs_prop_to_name(ZFS_PROP_VOLSIZE
)) == 0);
222 (void) nvlist_remove_all(nvprops
,
223 zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE
));
225 error
= dmu_object_claim(os
, ZVOL_OBJ
, DMU_OT_ZVOL
, volblocksize
,
229 error
= zap_create_claim(os
, ZVOL_ZAP_OBJ
, DMU_OT_ZVOL_PROP
,
233 error
= zap_update(os
, ZVOL_ZAP_OBJ
, "size", 8, 1, &volsize
, tx
);
238 * ZFS_IOC_OBJSET_STATS entry point.
241 zvol_get_stats(objset_t
*os
, nvlist_t
*nv
)
244 dmu_object_info_t
*doi
;
247 error
= zap_lookup(os
, ZVOL_ZAP_OBJ
, "size", 8, 1, &val
);
249 return (SET_ERROR(error
));
251 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_VOLSIZE
, val
);
252 doi
= kmem_alloc(sizeof (dmu_object_info_t
), KM_SLEEP
);
253 error
= dmu_object_info(os
, ZVOL_OBJ
, doi
);
256 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_VOLBLOCKSIZE
,
257 doi
->doi_data_block_size
);
260 kmem_free(doi
, sizeof (dmu_object_info_t
));
262 return (SET_ERROR(error
));
266 zvol_size_changed(zvol_state_t
*zv
, uint64_t volsize
)
268 struct block_device
*bdev
;
270 bdev
= bdget_disk(zv
->zv_disk
, 0);
273 set_capacity(zv
->zv_disk
, volsize
>> 9);
274 zv
->zv_volsize
= volsize
;
275 check_disk_size_change(zv
->zv_disk
, bdev
);
281 * Sanity check volume size.
284 zvol_check_volsize(uint64_t volsize
, uint64_t blocksize
)
287 return (SET_ERROR(EINVAL
));
289 if (volsize
% blocksize
!= 0)
290 return (SET_ERROR(EINVAL
));
293 if (volsize
- 1 > SPEC_MAXOFFSET_T
)
294 return (SET_ERROR(EOVERFLOW
));
300 * Ensure the zap is flushed then inform the VFS of the capacity change.
303 zvol_update_volsize(uint64_t volsize
, objset_t
*os
)
309 ASSERT(MUTEX_HELD(&zvol_state_lock
));
311 tx
= dmu_tx_create(os
);
312 dmu_tx_hold_zap(tx
, ZVOL_ZAP_OBJ
, TRUE
, NULL
);
313 dmu_tx_mark_netfree(tx
);
314 error
= dmu_tx_assign(tx
, TXG_WAIT
);
317 return (SET_ERROR(error
));
319 txg
= dmu_tx_get_txg(tx
);
321 error
= zap_update(os
, ZVOL_ZAP_OBJ
, "size", 8, 1,
325 txg_wait_synced(dmu_objset_pool(os
), txg
);
328 error
= dmu_free_long_range(os
,
329 ZVOL_OBJ
, volsize
, DMU_OBJECT_END
);
335 zvol_update_live_volsize(zvol_state_t
*zv
, uint64_t volsize
)
337 zvol_size_changed(zv
, volsize
);
340 * We should post a event here describing the expansion. However,
341 * the zfs_ereport_post() interface doesn't nicely support posting
342 * events for zvols, it assumes events relate to vdevs or zios.
349 * Set ZFS_PROP_VOLSIZE set entry point.
352 zvol_set_volsize(const char *name
, uint64_t volsize
)
354 zvol_state_t
*zv
= NULL
;
357 dmu_object_info_t
*doi
;
359 boolean_t owned
= B_FALSE
;
361 error
= dsl_prop_get_integer(name
,
362 zfs_prop_to_name(ZFS_PROP_READONLY
), &readonly
, NULL
);
364 return (SET_ERROR(error
));
366 return (SET_ERROR(EROFS
));
368 mutex_enter(&zvol_state_lock
);
369 zv
= zvol_find_by_name(name
);
371 if (zv
== NULL
|| zv
->zv_objset
== NULL
) {
372 if ((error
= dmu_objset_own(name
, DMU_OST_ZVOL
, B_FALSE
,
374 mutex_exit(&zvol_state_lock
);
375 return (SET_ERROR(error
));
381 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
385 doi
= kmem_alloc(sizeof (dmu_object_info_t
), KM_SLEEP
);
387 if ((error
= dmu_object_info(os
, ZVOL_OBJ
, doi
)) ||
388 (error
= zvol_check_volsize(volsize
, doi
->doi_data_block_size
)))
391 error
= zvol_update_volsize(volsize
, os
);
392 kmem_free(doi
, sizeof (dmu_object_info_t
));
394 if (error
== 0 && zv
!= NULL
)
395 error
= zvol_update_live_volsize(zv
, volsize
);
398 dmu_objset_disown(os
, FTAG
);
400 zv
->zv_objset
= NULL
;
402 rw_exit(&zv
->zv_suspend_lock
);
404 mutex_exit(&zvol_state_lock
);
409 * Sanity check volume block size.
412 zvol_check_volblocksize(const char *name
, uint64_t volblocksize
)
414 /* Record sizes above 128k need the feature to be enabled */
415 if (volblocksize
> SPA_OLD_MAXBLOCKSIZE
) {
419 if ((error
= spa_open(name
, &spa
, FTAG
)) != 0)
422 if (!spa_feature_is_enabled(spa
, SPA_FEATURE_LARGE_BLOCKS
)) {
423 spa_close(spa
, FTAG
);
424 return (SET_ERROR(ENOTSUP
));
428 * We don't allow setting the property above 1MB,
429 * unless the tunable has been changed.
431 if (volblocksize
> zfs_max_recordsize
)
432 return (SET_ERROR(EDOM
));
434 spa_close(spa
, FTAG
);
437 if (volblocksize
< SPA_MINBLOCKSIZE
||
438 volblocksize
> SPA_MAXBLOCKSIZE
||
440 return (SET_ERROR(EDOM
));
446 * Set ZFS_PROP_VOLBLOCKSIZE set entry point.
449 zvol_set_volblocksize(const char *name
, uint64_t volblocksize
)
455 mutex_enter(&zvol_state_lock
);
457 zv
= zvol_find_by_name(name
);
459 error
= SET_ERROR(ENXIO
);
463 if (zv
->zv_flags
& ZVOL_RDONLY
) {
464 error
= SET_ERROR(EROFS
);
468 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
470 tx
= dmu_tx_create(zv
->zv_objset
);
471 dmu_tx_hold_bonus(tx
, ZVOL_OBJ
);
472 error
= dmu_tx_assign(tx
, TXG_WAIT
);
476 error
= dmu_object_set_blocksize(zv
->zv_objset
, ZVOL_OBJ
,
477 volblocksize
, 0, tx
);
478 if (error
== ENOTSUP
)
479 error
= SET_ERROR(EBUSY
);
482 zv
->zv_volblocksize
= volblocksize
;
484 rw_exit(&zv
->zv_suspend_lock
);
486 mutex_exit(&zvol_state_lock
);
488 return (SET_ERROR(error
));
492 * Replay a TX_TRUNCATE ZIL transaction if asked. TX_TRUNCATE is how we
493 * implement DKIOCFREE/free-long-range.
496 zvol_replay_truncate(zvol_state_t
*zv
, lr_truncate_t
*lr
, boolean_t byteswap
)
498 uint64_t offset
, length
;
501 byteswap_uint64_array(lr
, sizeof (*lr
));
503 offset
= lr
->lr_offset
;
504 length
= lr
->lr_length
;
506 return (dmu_free_long_range(zv
->zv_objset
, ZVOL_OBJ
, offset
, length
));
510 * Replay a TX_WRITE ZIL transaction that didn't get committed
511 * after a system failure
514 zvol_replay_write(zvol_state_t
*zv
, lr_write_t
*lr
, boolean_t byteswap
)
516 objset_t
*os
= zv
->zv_objset
;
517 char *data
= (char *)(lr
+ 1); /* data follows lr_write_t */
518 uint64_t off
= lr
->lr_offset
;
519 uint64_t len
= lr
->lr_length
;
524 byteswap_uint64_array(lr
, sizeof (*lr
));
526 tx
= dmu_tx_create(os
);
527 dmu_tx_hold_write(tx
, ZVOL_OBJ
, off
, len
);
528 error
= dmu_tx_assign(tx
, TXG_WAIT
);
532 dmu_write(os
, ZVOL_OBJ
, off
, len
, data
, tx
);
536 return (SET_ERROR(error
));
540 zvol_replay_err(zvol_state_t
*zv
, lr_t
*lr
, boolean_t byteswap
)
542 return (SET_ERROR(ENOTSUP
));
546 * Callback vectors for replaying records.
547 * Only TX_WRITE and TX_TRUNCATE are needed for zvol.
549 zil_replay_func_t zvol_replay_vector
[TX_MAX_TYPE
] = {
550 (zil_replay_func_t
)zvol_replay_err
, /* no such transaction type */
551 (zil_replay_func_t
)zvol_replay_err
, /* TX_CREATE */
552 (zil_replay_func_t
)zvol_replay_err
, /* TX_MKDIR */
553 (zil_replay_func_t
)zvol_replay_err
, /* TX_MKXATTR */
554 (zil_replay_func_t
)zvol_replay_err
, /* TX_SYMLINK */
555 (zil_replay_func_t
)zvol_replay_err
, /* TX_REMOVE */
556 (zil_replay_func_t
)zvol_replay_err
, /* TX_RMDIR */
557 (zil_replay_func_t
)zvol_replay_err
, /* TX_LINK */
558 (zil_replay_func_t
)zvol_replay_err
, /* TX_RENAME */
559 (zil_replay_func_t
)zvol_replay_write
, /* TX_WRITE */
560 (zil_replay_func_t
)zvol_replay_truncate
, /* TX_TRUNCATE */
561 (zil_replay_func_t
)zvol_replay_err
, /* TX_SETATTR */
562 (zil_replay_func_t
)zvol_replay_err
, /* TX_ACL */
566 * zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions.
568 * We store data in the log buffers if it's small enough.
569 * Otherwise we will later flush the data out via dmu_sync().
571 ssize_t zvol_immediate_write_sz
= 32768;
574 zvol_log_write(zvol_state_t
*zv
, dmu_tx_t
*tx
, uint64_t offset
,
575 uint64_t size
, int sync
)
577 uint32_t blocksize
= zv
->zv_volblocksize
;
578 zilog_t
*zilog
= zv
->zv_zilog
;
580 ssize_t immediate_write_sz
;
582 if (zil_replaying(zilog
, tx
))
585 immediate_write_sz
= (zilog
->zl_logbias
== ZFS_LOGBIAS_THROUGHPUT
)
586 ? 0 : zvol_immediate_write_sz
;
587 slogging
= spa_has_slogs(zilog
->zl_spa
) &&
588 (zilog
->zl_logbias
== ZFS_LOGBIAS_LATENCY
);
594 itx_wr_state_t write_state
;
597 * Unlike zfs_log_write() we can be called with
598 * up to DMU_MAX_ACCESS/2 (5MB) writes.
600 if (blocksize
> immediate_write_sz
&& !slogging
&&
601 size
>= blocksize
&& offset
% blocksize
== 0) {
602 write_state
= WR_INDIRECT
; /* uses dmu_sync */
605 write_state
= WR_COPIED
;
606 len
= MIN(ZIL_MAX_LOG_DATA
, size
);
608 write_state
= WR_NEED_COPY
;
609 len
= MIN(ZIL_MAX_LOG_DATA
, size
);
612 itx
= zil_itx_create(TX_WRITE
, sizeof (*lr
) +
613 (write_state
== WR_COPIED
? len
: 0));
614 lr
= (lr_write_t
*)&itx
->itx_lr
;
615 if (write_state
== WR_COPIED
&& dmu_read(zv
->zv_objset
,
616 ZVOL_OBJ
, offset
, len
, lr
+1, DMU_READ_NO_PREFETCH
) != 0) {
617 zil_itx_destroy(itx
);
618 itx
= zil_itx_create(TX_WRITE
, sizeof (*lr
));
619 lr
= (lr_write_t
*)&itx
->itx_lr
;
620 write_state
= WR_NEED_COPY
;
623 itx
->itx_wr_state
= write_state
;
624 if (write_state
== WR_NEED_COPY
)
626 lr
->lr_foid
= ZVOL_OBJ
;
627 lr
->lr_offset
= offset
;
630 BP_ZERO(&lr
->lr_blkptr
);
632 itx
->itx_private
= zv
;
633 itx
->itx_sync
= sync
;
635 (void) zil_itx_assign(zilog
, itx
, tx
);
642 typedef struct zv_request
{
649 uio_from_bio(uio_t
*uio
, struct bio
*bio
)
651 uio
->uio_bvec
= &bio
->bi_io_vec
[BIO_BI_IDX(bio
)];
652 uio
->uio_skip
= BIO_BI_SKIP(bio
);
653 uio
->uio_resid
= BIO_BI_SIZE(bio
);
654 uio
->uio_iovcnt
= bio
->bi_vcnt
- BIO_BI_IDX(bio
);
655 uio
->uio_loffset
= BIO_BI_SECTOR(bio
) << 9;
656 uio
->uio_limit
= MAXOFFSET_T
;
657 uio
->uio_segflg
= UIO_BVEC
;
661 zvol_write(void *arg
)
663 zv_request_t
*zvr
= arg
;
664 struct bio
*bio
= zvr
->bio
;
666 zvol_state_t
*zv
= zvr
->zv
;
667 uint64_t volsize
= zv
->zv_volsize
;
670 unsigned long start_jif
;
672 uio_from_bio(&uio
, bio
);
674 ASSERT(zv
&& zv
->zv_open_count
> 0);
677 generic_start_io_acct(WRITE
, bio_sectors(bio
), &zv
->zv_disk
->part0
);
679 sync
= bio_is_fua(bio
) || zv
->zv_objset
->os_sync
== ZFS_SYNC_ALWAYS
;
681 while (uio
.uio_resid
> 0 && uio
.uio_loffset
< volsize
) {
682 uint64_t bytes
= MIN(uio
.uio_resid
, DMU_MAX_ACCESS
>> 1);
683 uint64_t off
= uio
.uio_loffset
;
684 dmu_tx_t
*tx
= dmu_tx_create(zv
->zv_objset
);
686 if (bytes
> volsize
- off
) /* don't write past the end */
687 bytes
= volsize
- off
;
689 dmu_tx_hold_write(tx
, ZVOL_OBJ
, off
, bytes
);
691 /* This will only fail for ENOSPC */
692 error
= dmu_tx_assign(tx
, TXG_WAIT
);
697 error
= dmu_write_uio_dbuf(zv
->zv_dbuf
, &uio
, bytes
, tx
);
699 zvol_log_write(zv
, tx
, off
, bytes
, sync
);
705 zfs_range_unlock(zvr
->rl
);
707 zil_commit(zv
->zv_zilog
, ZVOL_OBJ
);
709 rw_exit(&zv
->zv_suspend_lock
);
710 generic_end_io_acct(WRITE
, &zv
->zv_disk
->part0
, start_jif
);
711 BIO_END_IO(bio
, -error
);
712 kmem_free(zvr
, sizeof (zv_request_t
));
716 * Log a DKIOCFREE/free-long-range to the ZIL with TX_TRUNCATE.
719 zvol_log_truncate(zvol_state_t
*zv
, dmu_tx_t
*tx
, uint64_t off
, uint64_t len
,
724 zilog_t
*zilog
= zv
->zv_zilog
;
726 if (zil_replaying(zilog
, tx
))
729 itx
= zil_itx_create(TX_TRUNCATE
, sizeof (*lr
));
730 lr
= (lr_truncate_t
*)&itx
->itx_lr
;
731 lr
->lr_foid
= ZVOL_OBJ
;
735 itx
->itx_sync
= sync
;
736 zil_itx_assign(zilog
, itx
, tx
);
740 zvol_discard(void *arg
)
742 zv_request_t
*zvr
= arg
;
743 struct bio
*bio
= zvr
->bio
;
744 zvol_state_t
*zv
= zvr
->zv
;
745 uint64_t start
= BIO_BI_SECTOR(bio
) << 9;
746 uint64_t size
= BIO_BI_SIZE(bio
);
747 uint64_t end
= start
+ size
;
750 unsigned long start_jif
;
752 ASSERT(zv
&& zv
->zv_open_count
> 0);
755 generic_start_io_acct(WRITE
, bio_sectors(bio
), &zv
->zv_disk
->part0
);
757 if (end
> zv
->zv_volsize
) {
758 error
= SET_ERROR(EIO
);
763 * Align the request to volume block boundaries when a secure erase is
764 * not required. This will prevent dnode_free_range() from zeroing out
765 * the unaligned parts which is slow (read-modify-write) and useless
766 * since we are not freeing any space by doing so.
768 if (!bio_is_secure_erase(bio
)) {
769 start
= P2ROUNDUP(start
, zv
->zv_volblocksize
);
770 end
= P2ALIGN(end
, zv
->zv_volblocksize
);
777 tx
= dmu_tx_create(zv
->zv_objset
);
778 dmu_tx_mark_netfree(tx
);
779 error
= dmu_tx_assign(tx
, TXG_WAIT
);
783 zvol_log_truncate(zv
, tx
, start
, size
, B_TRUE
);
785 error
= dmu_free_long_range(zv
->zv_objset
,
786 ZVOL_OBJ
, start
, size
);
790 zfs_range_unlock(zvr
->rl
);
791 rw_exit(&zv
->zv_suspend_lock
);
792 generic_end_io_acct(WRITE
, &zv
->zv_disk
->part0
, start_jif
);
793 BIO_END_IO(bio
, -error
);
794 kmem_free(zvr
, sizeof (zv_request_t
));
800 zv_request_t
*zvr
= arg
;
801 struct bio
*bio
= zvr
->bio
;
803 zvol_state_t
*zv
= zvr
->zv
;
804 uint64_t volsize
= zv
->zv_volsize
;
806 unsigned long start_jif
;
808 uio_from_bio(&uio
, bio
);
810 ASSERT(zv
&& zv
->zv_open_count
> 0);
813 generic_start_io_acct(READ
, bio_sectors(bio
), &zv
->zv_disk
->part0
);
815 while (uio
.uio_resid
> 0 && uio
.uio_loffset
< volsize
) {
816 uint64_t bytes
= MIN(uio
.uio_resid
, DMU_MAX_ACCESS
>> 1);
818 /* don't read past the end */
819 if (bytes
> volsize
- uio
.uio_loffset
)
820 bytes
= volsize
- uio
.uio_loffset
;
822 error
= dmu_read_uio_dbuf(zv
->zv_dbuf
, &uio
, bytes
);
824 /* convert checksum errors into IO errors */
826 error
= SET_ERROR(EIO
);
830 zfs_range_unlock(zvr
->rl
);
832 rw_exit(&zv
->zv_suspend_lock
);
833 generic_end_io_acct(READ
, &zv
->zv_disk
->part0
, start_jif
);
834 BIO_END_IO(bio
, -error
);
835 kmem_free(zvr
, sizeof (zv_request_t
));
838 static MAKE_REQUEST_FN_RET
839 zvol_request(struct request_queue
*q
, struct bio
*bio
)
841 zvol_state_t
*zv
= q
->queuedata
;
842 fstrans_cookie_t cookie
= spl_fstrans_mark();
843 uint64_t offset
= BIO_BI_SECTOR(bio
) << 9;
844 uint64_t size
= BIO_BI_SIZE(bio
);
845 int rw
= bio_data_dir(bio
);
848 if (bio_has_data(bio
) && offset
+ size
> zv
->zv_volsize
) {
850 "%s: bad access: offset=%llu, size=%lu\n",
851 zv
->zv_disk
->disk_name
,
852 (long long unsigned)offset
,
853 (long unsigned)size
);
855 BIO_END_IO(bio
, -SET_ERROR(EIO
));
860 if (unlikely(zv
->zv_flags
& ZVOL_RDONLY
)) {
861 BIO_END_IO(bio
, -SET_ERROR(EROFS
));
866 * To be released in the I/O function. See the comment on
867 * zfs_range_lock below.
869 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
871 /* bio marked as FLUSH need to flush before write */
872 if (bio_is_flush(bio
))
873 zil_commit(zv
->zv_zilog
, ZVOL_OBJ
);
875 /* Some requests are just for flush and nothing else. */
877 rw_exit(&zv
->zv_suspend_lock
);
882 zvr
= kmem_alloc(sizeof (zv_request_t
), KM_SLEEP
);
887 * To be released in the I/O function. Since the I/O functions
888 * are asynchronous, we take it here synchronously to make
889 * sure overlapped I/Os are properly ordered.
891 zvr
->rl
= zfs_range_lock(&zv
->zv_range_lock
, offset
, size
,
893 if (bio_is_discard(bio
) || bio_is_secure_erase(bio
)) {
894 if (zvol_request_sync
|| taskq_dispatch(zvol_taskq
,
895 zvol_discard
, zvr
, TQ_SLEEP
) == TASKQID_INVALID
)
898 if (zvol_request_sync
|| taskq_dispatch(zvol_taskq
,
899 zvol_write
, zvr
, TQ_SLEEP
) == TASKQID_INVALID
)
903 zvr
= kmem_alloc(sizeof (zv_request_t
), KM_SLEEP
);
907 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
909 zvr
->rl
= zfs_range_lock(&zv
->zv_range_lock
, offset
, size
,
911 if (zvol_request_sync
|| taskq_dispatch(zvol_taskq
,
912 zvol_read
, zvr
, TQ_SLEEP
) == TASKQID_INVALID
)
917 spl_fstrans_unmark(cookie
);
918 #ifdef HAVE_MAKE_REQUEST_FN_RET_INT
920 #elif defined(HAVE_MAKE_REQUEST_FN_RET_QC)
921 return (BLK_QC_T_NONE
);
926 zvol_get_done(zgd_t
*zgd
, int error
)
929 dmu_buf_rele(zgd
->zgd_db
, zgd
);
931 zfs_range_unlock(zgd
->zgd_rl
);
933 if (error
== 0 && zgd
->zgd_bp
)
934 zil_add_block(zgd
->zgd_zilog
, zgd
->zgd_bp
);
936 kmem_free(zgd
, sizeof (zgd_t
));
940 * Get data to generate a TX_WRITE intent log record.
943 zvol_get_data(void *arg
, lr_write_t
*lr
, char *buf
, zio_t
*zio
)
945 zvol_state_t
*zv
= arg
;
946 objset_t
*os
= zv
->zv_objset
;
947 uint64_t object
= ZVOL_OBJ
;
948 uint64_t offset
= lr
->lr_offset
;
949 uint64_t size
= lr
->lr_length
;
950 blkptr_t
*bp
= &lr
->lr_blkptr
;
958 zgd
= (zgd_t
*)kmem_zalloc(sizeof (zgd_t
), KM_SLEEP
);
959 zgd
->zgd_zilog
= zv
->zv_zilog
;
960 zgd
->zgd_rl
= zfs_range_lock(&zv
->zv_range_lock
, offset
, size
,
964 * Write records come in two flavors: immediate and indirect.
965 * For small writes it's cheaper to store the data with the
966 * log record (immediate); for large writes it's cheaper to
967 * sync the data and get a pointer to it (indirect) so that
968 * we don't have to write the data twice.
970 if (buf
!= NULL
) { /* immediate write */
971 error
= dmu_read(os
, object
, offset
, size
, buf
,
972 DMU_READ_NO_PREFETCH
);
974 size
= zv
->zv_volblocksize
;
975 offset
= P2ALIGN_TYPED(offset
, size
, uint64_t);
976 error
= dmu_buf_hold(os
, object
, offset
, zgd
, &db
,
977 DMU_READ_NO_PREFETCH
);
979 blkptr_t
*obp
= dmu_buf_get_blkptr(db
);
981 ASSERT(BP_IS_HOLE(bp
));
986 zgd
->zgd_bp
= &lr
->lr_blkptr
;
989 ASSERT(db
->db_offset
== offset
);
990 ASSERT(db
->db_size
== size
);
992 error
= dmu_sync(zio
, lr
->lr_common
.lrc_txg
,
1000 zvol_get_done(zgd
, error
);
1002 return (SET_ERROR(error
));
1006 * The zvol_state_t's are inserted into zvol_state_list and zvol_htable.
1009 zvol_insert(zvol_state_t
*zv
)
1011 ASSERT(MUTEX_HELD(&zvol_state_lock
));
1012 ASSERT3U(MINOR(zv
->zv_dev
) & ZVOL_MINOR_MASK
, ==, 0);
1013 list_insert_head(&zvol_state_list
, zv
);
1014 hlist_add_head(&zv
->zv_hlink
, ZVOL_HT_HEAD(zv
->zv_hash
));
1018 * Simply remove the zvol from to list of zvols.
1021 zvol_remove(zvol_state_t
*zv
)
1023 ASSERT(MUTEX_HELD(&zvol_state_lock
));
1024 list_remove(&zvol_state_list
, zv
);
1025 hlist_del(&zv
->zv_hlink
);
1029 * Setup zv after we just own the zv->objset
1032 zvol_setup_zv(zvol_state_t
*zv
)
1037 objset_t
*os
= zv
->zv_objset
;
1039 error
= dsl_prop_get_integer(zv
->zv_name
, "readonly", &ro
, NULL
);
1041 return (SET_ERROR(error
));
1043 error
= zap_lookup(os
, ZVOL_ZAP_OBJ
, "size", 8, 1, &volsize
);
1045 return (SET_ERROR(error
));
1047 error
= dmu_bonus_hold(os
, ZVOL_OBJ
, zv
, &zv
->zv_dbuf
);
1049 return (SET_ERROR(error
));
1051 set_capacity(zv
->zv_disk
, volsize
>> 9);
1052 zv
->zv_volsize
= volsize
;
1053 zv
->zv_zilog
= zil_open(os
, zvol_get_data
);
1055 if (ro
|| dmu_objset_is_snapshot(os
) ||
1056 !spa_writeable(dmu_objset_spa(os
))) {
1057 set_disk_ro(zv
->zv_disk
, 1);
1058 zv
->zv_flags
|= ZVOL_RDONLY
;
1060 set_disk_ro(zv
->zv_disk
, 0);
1061 zv
->zv_flags
&= ~ZVOL_RDONLY
;
1067 * Shutdown every zv_objset related stuff except zv_objset itself.
1068 * The is the reverse of zvol_setup_zv.
1071 zvol_shutdown_zv(zvol_state_t
*zv
)
1073 zil_close(zv
->zv_zilog
);
1074 zv
->zv_zilog
= NULL
;
1076 dmu_buf_rele(zv
->zv_dbuf
, zv
);
1082 if (dsl_dataset_is_dirty(dmu_objset_ds(zv
->zv_objset
)) &&
1083 !(zv
->zv_flags
& ZVOL_RDONLY
))
1084 txg_wait_synced(dmu_objset_pool(zv
->zv_objset
), 0);
1085 (void) dmu_objset_evict_dbufs(zv
->zv_objset
);
1089 * return the proper tag for rollback and recv
1092 zvol_tag(zvol_state_t
*zv
)
1094 ASSERT(RW_WRITE_HELD(&zv
->zv_suspend_lock
));
1095 return (zv
->zv_open_count
> 0 ? zv
: NULL
);
1099 * Suspend the zvol for recv and rollback.
1102 zvol_suspend(const char *name
)
1106 mutex_enter(&zvol_state_lock
);
1107 zv
= zvol_find_by_name(name
);
1111 /* block all I/O, release in zvol_resume. */
1112 rw_enter(&zv
->zv_suspend_lock
, RW_WRITER
);
1114 atomic_inc(&zv
->zv_suspend_ref
);
1116 if (zv
->zv_open_count
> 0)
1117 zvol_shutdown_zv(zv
);
1119 mutex_exit(&zvol_state_lock
);
1124 zvol_resume(zvol_state_t
*zv
)
1128 ASSERT(RW_WRITE_HELD(&zv
->zv_suspend_lock
));
1129 if (zv
->zv_open_count
> 0) {
1130 VERIFY0(dmu_objset_hold(zv
->zv_name
, zv
, &zv
->zv_objset
));
1131 VERIFY3P(zv
->zv_objset
->os_dsl_dataset
->ds_owner
, ==, zv
);
1132 VERIFY(dsl_dataset_long_held(zv
->zv_objset
->os_dsl_dataset
));
1133 dmu_objset_rele(zv
->zv_objset
, zv
);
1135 error
= zvol_setup_zv(zv
);
1137 rw_exit(&zv
->zv_suspend_lock
);
1139 * We need this because we don't hold zvol_state_lock while releasing
1140 * zv_suspend_lock. zvol_remove_minors_impl thus cannot check
1141 * zv_suspend_lock to determine it is safe to free because rwlock is
1142 * not inherent atomic.
1144 atomic_dec(&zv
->zv_suspend_ref
);
1146 return (SET_ERROR(error
));
1150 zvol_first_open(zvol_state_t
*zv
)
1153 int error
, locked
= 0;
1156 * In all other cases the spa_namespace_lock is taken before the
1157 * bdev->bd_mutex lock. But in this case the Linux __blkdev_get()
1158 * function calls fops->open() with the bdev->bd_mutex lock held.
1159 * This deadlock can be easily observed with zvols used as vdevs.
1161 * To avoid a potential lock inversion deadlock we preemptively
1162 * try to take the spa_namespace_lock(). Normally it will not
1163 * be contended and this is safe because spa_open_common() handles
1164 * the case where the caller already holds the spa_namespace_lock.
1166 * When it is contended we risk a lock inversion if we were to
1167 * block waiting for the lock. Luckily, the __blkdev_get()
1168 * function allows us to return -ERESTARTSYS which will result in
1169 * bdev->bd_mutex being dropped, reacquired, and fops->open() being
1170 * called again. This process can be repeated safely until both
1171 * locks are acquired.
1173 if (!mutex_owned(&spa_namespace_lock
)) {
1174 locked
= mutex_tryenter(&spa_namespace_lock
);
1176 return (-SET_ERROR(ERESTARTSYS
));
1179 /* lie and say we're read-only */
1180 error
= dmu_objset_own(zv
->zv_name
, DMU_OST_ZVOL
, 1, zv
, &os
);
1186 error
= zvol_setup_zv(zv
);
1189 dmu_objset_disown(os
, zv
);
1190 zv
->zv_objset
= NULL
;
1195 mutex_exit(&spa_namespace_lock
);
1196 return (SET_ERROR(-error
));
1200 zvol_last_close(zvol_state_t
*zv
)
1202 zvol_shutdown_zv(zv
);
1204 dmu_objset_disown(zv
->zv_objset
, zv
);
1205 zv
->zv_objset
= NULL
;
1209 zvol_open(struct block_device
*bdev
, fmode_t flag
)
1212 int error
= 0, drop_mutex
= 0, drop_suspend
= 0;
1215 * If the caller is already holding the mutex do not take it
1216 * again, this will happen as part of zvol_create_minor_impl().
1217 * Once add_disk() is called the device is live and the kernel
1218 * will attempt to open it to read the partition information.
1220 if (!mutex_owned(&zvol_state_lock
)) {
1221 mutex_enter(&zvol_state_lock
);
1226 * Obtain a copy of private_data under the lock to make sure
1227 * that either the result of zvol_free() setting
1228 * bdev->bd_disk->private_data to NULL is observed, or zvol_free()
1229 * is not called on this zv because of the positive zv_open_count.
1231 zv
= bdev
->bd_disk
->private_data
;
1237 if (zv
->zv_open_count
== 0) {
1238 /* make sure zvol is not suspended when first open */
1239 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
1242 error
= zvol_first_open(zv
);
1247 if ((flag
& FMODE_WRITE
) && (zv
->zv_flags
& ZVOL_RDONLY
)) {
1249 goto out_open_count
;
1252 zv
->zv_open_count
++;
1254 check_disk_change(bdev
);
1257 if (zv
->zv_open_count
== 0)
1258 zvol_last_close(zv
);
1261 rw_exit(&zv
->zv_suspend_lock
);
1263 mutex_exit(&zvol_state_lock
);
1265 return (SET_ERROR(error
));
1268 #ifdef HAVE_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
1273 zvol_release(struct gendisk
*disk
, fmode_t mode
)
1275 zvol_state_t
*zv
= disk
->private_data
;
1278 ASSERT(zv
&& zv
->zv_open_count
> 0);
1280 if (!mutex_owned(&zvol_state_lock
)) {
1281 mutex_enter(&zvol_state_lock
);
1285 /* make sure zvol is not suspended when last close */
1286 if (zv
->zv_open_count
== 1)
1287 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
1289 zv
->zv_open_count
--;
1290 if (zv
->zv_open_count
== 0) {
1291 zvol_last_close(zv
);
1292 rw_exit(&zv
->zv_suspend_lock
);
1296 mutex_exit(&zvol_state_lock
);
1298 #ifndef HAVE_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
1304 zvol_ioctl(struct block_device
*bdev
, fmode_t mode
,
1305 unsigned int cmd
, unsigned long arg
)
1307 zvol_state_t
*zv
= bdev
->bd_disk
->private_data
;
1310 ASSERT(zv
&& zv
->zv_open_count
> 0);
1315 invalidate_bdev(bdev
);
1316 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
1318 if (dsl_dataset_is_dirty(dmu_objset_ds(zv
->zv_objset
)) &&
1319 !(zv
->zv_flags
& ZVOL_RDONLY
))
1320 txg_wait_synced(dmu_objset_pool(zv
->zv_objset
), 0);
1322 rw_exit(&zv
->zv_suspend_lock
);
1326 mutex_enter(&zvol_state_lock
);
1327 error
= copy_to_user((void *)arg
, zv
->zv_name
, MAXNAMELEN
);
1328 mutex_exit(&zvol_state_lock
);
1336 return (SET_ERROR(error
));
1339 #ifdef CONFIG_COMPAT
1341 zvol_compat_ioctl(struct block_device
*bdev
, fmode_t mode
,
1342 unsigned cmd
, unsigned long arg
)
1344 return (zvol_ioctl(bdev
, mode
, cmd
, arg
));
1347 #define zvol_compat_ioctl NULL
1350 static int zvol_media_changed(struct gendisk
*disk
)
1352 zvol_state_t
*zv
= disk
->private_data
;
1354 ASSERT(zv
&& zv
->zv_open_count
> 0);
1356 return (zv
->zv_changed
);
1359 static int zvol_revalidate_disk(struct gendisk
*disk
)
1361 zvol_state_t
*zv
= disk
->private_data
;
1363 ASSERT(zv
&& zv
->zv_open_count
> 0);
1366 set_capacity(zv
->zv_disk
, zv
->zv_volsize
>> 9);
1372 * Provide a simple virtual geometry for legacy compatibility. For devices
1373 * smaller than 1 MiB a small head and sector count is used to allow very
1374 * tiny devices. For devices over 1 Mib a standard head and sector count
1375 * is used to keep the cylinders count reasonable.
1378 zvol_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1380 zvol_state_t
*zv
= bdev
->bd_disk
->private_data
;
1383 ASSERT(zv
&& zv
->zv_open_count
> 0);
1385 sectors
= get_capacity(zv
->zv_disk
);
1387 if (sectors
> 2048) {
1396 geo
->cylinders
= sectors
/ (geo
->heads
* geo
->sectors
);
1401 static struct kobject
*
1402 zvol_probe(dev_t dev
, int *part
, void *arg
)
1405 struct kobject
*kobj
;
1407 mutex_enter(&zvol_state_lock
);
1408 zv
= zvol_find_by_dev(dev
);
1409 kobj
= zv
? get_disk(zv
->zv_disk
) : NULL
;
1410 mutex_exit(&zvol_state_lock
);
1415 #ifdef HAVE_BDEV_BLOCK_DEVICE_OPERATIONS
1416 static struct block_device_operations zvol_ops
= {
1418 .release
= zvol_release
,
1419 .ioctl
= zvol_ioctl
,
1420 .compat_ioctl
= zvol_compat_ioctl
,
1421 .media_changed
= zvol_media_changed
,
1422 .revalidate_disk
= zvol_revalidate_disk
,
1423 .getgeo
= zvol_getgeo
,
1424 .owner
= THIS_MODULE
,
1427 #else /* HAVE_BDEV_BLOCK_DEVICE_OPERATIONS */
1430 zvol_open_by_inode(struct inode
*inode
, struct file
*file
)
1432 return (zvol_open(inode
->i_bdev
, file
->f_mode
));
1436 zvol_release_by_inode(struct inode
*inode
, struct file
*file
)
1438 return (zvol_release(inode
->i_bdev
->bd_disk
, file
->f_mode
));
1442 zvol_ioctl_by_inode(struct inode
*inode
, struct file
*file
,
1443 unsigned int cmd
, unsigned long arg
)
1445 if (file
== NULL
|| inode
== NULL
)
1446 return (SET_ERROR(-EINVAL
));
1448 return (zvol_ioctl(inode
->i_bdev
, file
->f_mode
, cmd
, arg
));
1451 #ifdef CONFIG_COMPAT
1453 zvol_compat_ioctl_by_inode(struct file
*file
,
1454 unsigned int cmd
, unsigned long arg
)
1457 return (SET_ERROR(-EINVAL
));
1459 return (zvol_compat_ioctl(file
->f_dentry
->d_inode
->i_bdev
,
1460 file
->f_mode
, cmd
, arg
));
1463 #define zvol_compat_ioctl_by_inode NULL
1466 static struct block_device_operations zvol_ops
= {
1467 .open
= zvol_open_by_inode
,
1468 .release
= zvol_release_by_inode
,
1469 .ioctl
= zvol_ioctl_by_inode
,
1470 .compat_ioctl
= zvol_compat_ioctl_by_inode
,
1471 .media_changed
= zvol_media_changed
,
1472 .revalidate_disk
= zvol_revalidate_disk
,
1473 .getgeo
= zvol_getgeo
,
1474 .owner
= THIS_MODULE
,
1476 #endif /* HAVE_BDEV_BLOCK_DEVICE_OPERATIONS */
1479 * Allocate memory for a new zvol_state_t and setup the required
1480 * request queue and generic disk structures for the block device.
1482 static zvol_state_t
*
1483 zvol_alloc(dev_t dev
, const char *name
)
1487 zv
= kmem_zalloc(sizeof (zvol_state_t
), KM_SLEEP
);
1489 list_link_init(&zv
->zv_next
);
1491 zv
->zv_queue
= blk_alloc_queue(GFP_ATOMIC
);
1492 if (zv
->zv_queue
== NULL
)
1495 blk_queue_make_request(zv
->zv_queue
, zvol_request
);
1496 blk_queue_set_write_cache(zv
->zv_queue
, B_TRUE
, B_TRUE
);
1498 /* Limit read-ahead to a single page to prevent over-prefetching. */
1499 blk_queue_set_read_ahead(zv
->zv_queue
, 1);
1501 /* Disable write merging in favor of the ZIO pipeline. */
1502 queue_flag_set(QUEUE_FLAG_NOMERGES
, zv
->zv_queue
);
1504 zv
->zv_disk
= alloc_disk(ZVOL_MINORS
);
1505 if (zv
->zv_disk
== NULL
)
1508 zv
->zv_queue
->queuedata
= zv
;
1510 zv
->zv_open_count
= 0;
1511 strlcpy(zv
->zv_name
, name
, MAXNAMELEN
);
1513 zfs_rlock_init(&zv
->zv_range_lock
);
1514 rw_init(&zv
->zv_suspend_lock
, NULL
, RW_DEFAULT
, NULL
);
1516 zv
->zv_disk
->major
= zvol_major
;
1517 zv
->zv_disk
->first_minor
= (dev
& MINORMASK
);
1518 zv
->zv_disk
->fops
= &zvol_ops
;
1519 zv
->zv_disk
->private_data
= zv
;
1520 zv
->zv_disk
->queue
= zv
->zv_queue
;
1521 snprintf(zv
->zv_disk
->disk_name
, DISK_NAME_LEN
, "%s%d",
1522 ZVOL_DEV_NAME
, (dev
& MINORMASK
));
1527 blk_cleanup_queue(zv
->zv_queue
);
1529 kmem_free(zv
, sizeof (zvol_state_t
));
1535 * Used for taskq, if used out side zvol_state_lock, you need to clear
1536 * zv_disk->private_data inside lock first.
1539 zvol_free_impl(void *arg
)
1541 zvol_state_t
*zv
= arg
;
1542 ASSERT(zv
->zv_open_count
== 0);
1544 rw_destroy(&zv
->zv_suspend_lock
);
1545 zfs_rlock_destroy(&zv
->zv_range_lock
);
1547 zv
->zv_disk
->private_data
= NULL
;
1549 del_gendisk(zv
->zv_disk
);
1550 blk_cleanup_queue(zv
->zv_queue
);
1551 put_disk(zv
->zv_disk
);
1553 ida_simple_remove(&zvol_ida
, MINOR(zv
->zv_dev
) >> ZVOL_MINOR_BITS
);
1554 kmem_free(zv
, sizeof (zvol_state_t
));
1558 * Cleanup then free a zvol_state_t which was created by zvol_alloc().
1561 zvol_free(zvol_state_t
*zv
)
1563 ASSERT(MUTEX_HELD(&zvol_state_lock
));
1568 * Create a block device minor node and setup the linkage between it
1569 * and the specified volume. Once this function returns the block
1570 * device is live and ready for use.
1573 zvol_create_minor_impl(const char *name
)
1577 dmu_object_info_t
*doi
;
1583 uint64_t hash
= zvol_name_hash(name
);
1585 idx
= ida_simple_get(&zvol_ida
, 0, 0, kmem_flags_convert(KM_SLEEP
));
1587 return (SET_ERROR(-idx
));
1588 minor
= idx
<< ZVOL_MINOR_BITS
;
1590 mutex_enter(&zvol_state_lock
);
1592 zv
= zvol_find_by_name_hash(name
, hash
);
1594 error
= SET_ERROR(EEXIST
);
1598 doi
= kmem_alloc(sizeof (dmu_object_info_t
), KM_SLEEP
);
1600 error
= dmu_objset_own(name
, DMU_OST_ZVOL
, B_TRUE
, FTAG
, &os
);
1604 error
= dmu_object_info(os
, ZVOL_OBJ
, doi
);
1606 goto out_dmu_objset_disown
;
1608 error
= zap_lookup(os
, ZVOL_ZAP_OBJ
, "size", 8, 1, &volsize
);
1610 goto out_dmu_objset_disown
;
1612 zv
= zvol_alloc(MKDEV(zvol_major
, minor
), name
);
1614 error
= SET_ERROR(EAGAIN
);
1615 goto out_dmu_objset_disown
;
1619 if (dmu_objset_is_snapshot(os
))
1620 zv
->zv_flags
|= ZVOL_RDONLY
;
1622 zv
->zv_volblocksize
= doi
->doi_data_block_size
;
1623 zv
->zv_volsize
= volsize
;
1626 set_capacity(zv
->zv_disk
, zv
->zv_volsize
>> 9);
1628 blk_queue_max_hw_sectors(zv
->zv_queue
, (DMU_MAX_ACCESS
/ 4) >> 9);
1629 blk_queue_max_segments(zv
->zv_queue
, UINT16_MAX
);
1630 blk_queue_max_segment_size(zv
->zv_queue
, UINT_MAX
);
1631 blk_queue_physical_block_size(zv
->zv_queue
, zv
->zv_volblocksize
);
1632 blk_queue_io_opt(zv
->zv_queue
, zv
->zv_volblocksize
);
1633 blk_queue_max_discard_sectors(zv
->zv_queue
,
1634 (zvol_max_discard_blocks
* zv
->zv_volblocksize
) >> 9);
1635 blk_queue_discard_granularity(zv
->zv_queue
, zv
->zv_volblocksize
);
1636 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD
, zv
->zv_queue
);
1637 #ifdef QUEUE_FLAG_NONROT
1638 queue_flag_set_unlocked(QUEUE_FLAG_NONROT
, zv
->zv_queue
);
1640 #ifdef QUEUE_FLAG_ADD_RANDOM
1641 queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM
, zv
->zv_queue
);
1644 if (spa_writeable(dmu_objset_spa(os
))) {
1645 if (zil_replay_disable
)
1646 zil_destroy(dmu_objset_zil(os
), B_FALSE
);
1648 zil_replay(os
, zv
, zvol_replay_vector
);
1652 * When udev detects the addition of the device it will immediately
1653 * invoke blkid(8) to determine the type of content on the device.
1654 * Prefetching the blocks commonly scanned by blkid(8) will speed
1657 len
= MIN(MAX(zvol_prefetch_bytes
, 0), SPA_MAXBLOCKSIZE
);
1659 dmu_prefetch(os
, ZVOL_OBJ
, 0, 0, len
, ZIO_PRIORITY_SYNC_READ
);
1660 dmu_prefetch(os
, ZVOL_OBJ
, 0, volsize
- len
, len
,
1661 ZIO_PRIORITY_SYNC_READ
);
1664 zv
->zv_objset
= NULL
;
1665 out_dmu_objset_disown
:
1666 dmu_objset_disown(os
, FTAG
);
1668 kmem_free(doi
, sizeof (dmu_object_info_t
));
1674 * Drop the lock to prevent deadlock with sys_open() ->
1675 * zvol_open(), which first takes bd_disk->bd_mutex and then
1676 * takes zvol_state_lock, whereas this code path first takes
1677 * zvol_state_lock, and then takes bd_disk->bd_mutex.
1679 mutex_exit(&zvol_state_lock
);
1680 add_disk(zv
->zv_disk
);
1682 mutex_exit(&zvol_state_lock
);
1683 ida_simple_remove(&zvol_ida
, idx
);
1686 return (SET_ERROR(error
));
1690 * Rename a block device minor mode for the specified volume.
1693 zvol_rename_minor(zvol_state_t
*zv
, const char *newname
)
1695 int readonly
= get_disk_ro(zv
->zv_disk
);
1697 ASSERT(MUTEX_HELD(&zvol_state_lock
));
1699 rw_enter(&zv
->zv_suspend_lock
, RW_READER
);
1700 strlcpy(zv
->zv_name
, newname
, sizeof (zv
->zv_name
));
1701 rw_exit(&zv
->zv_suspend_lock
);
1703 /* move to new hashtable entry */
1704 zv
->zv_hash
= zvol_name_hash(zv
->zv_name
);
1705 hlist_del(&zv
->zv_hlink
);
1706 hlist_add_head(&zv
->zv_hlink
, ZVOL_HT_HEAD(zv
->zv_hash
));
1709 * The block device's read-only state is briefly changed causing
1710 * a KOBJ_CHANGE uevent to be issued. This ensures udev detects
1711 * the name change and fixes the symlinks. This does not change
1712 * ZVOL_RDONLY in zv->zv_flags so the actual read-only state never
1713 * changes. This would normally be done using kobject_uevent() but
1714 * that is a GPL-only symbol which is why we need this workaround.
1716 set_disk_ro(zv
->zv_disk
, !readonly
);
1717 set_disk_ro(zv
->zv_disk
, readonly
);
1720 typedef struct minors_job
{
1730 * Prefetch zvol dnodes for the minors_job
1733 zvol_prefetch_minors_impl(void *arg
)
1735 minors_job_t
*job
= arg
;
1736 char *dsname
= job
->name
;
1737 objset_t
*os
= NULL
;
1739 job
->error
= dmu_objset_own(dsname
, DMU_OST_ZVOL
, B_TRUE
, FTAG
,
1741 if (job
->error
== 0) {
1742 dmu_prefetch(os
, ZVOL_OBJ
, 0, 0, 0, ZIO_PRIORITY_SYNC_READ
);
1743 dmu_objset_disown(os
, FTAG
);
1748 * Mask errors to continue dmu_objset_find() traversal
1751 zvol_create_snap_minor_cb(const char *dsname
, void *arg
)
1753 minors_job_t
*j
= arg
;
1754 list_t
*minors_list
= j
->list
;
1755 const char *name
= j
->name
;
1757 ASSERT0(MUTEX_HELD(&spa_namespace_lock
));
1759 /* skip the designated dataset */
1760 if (name
&& strcmp(dsname
, name
) == 0)
1763 /* at this point, the dsname should name a snapshot */
1764 if (strchr(dsname
, '@') == 0) {
1765 dprintf("zvol_create_snap_minor_cb(): "
1766 "%s is not a shapshot name\n", dsname
);
1769 char *n
= strdup(dsname
);
1773 job
= kmem_alloc(sizeof (minors_job_t
), KM_SLEEP
);
1775 job
->list
= minors_list
;
1777 list_insert_tail(minors_list
, job
);
1778 /* don't care if dispatch fails, because job->error is 0 */
1779 taskq_dispatch(system_taskq
, zvol_prefetch_minors_impl
, job
,
1787 * Mask errors to continue dmu_objset_find() traversal
1790 zvol_create_minors_cb(const char *dsname
, void *arg
)
1794 list_t
*minors_list
= arg
;
1796 ASSERT0(MUTEX_HELD(&spa_namespace_lock
));
1798 error
= dsl_prop_get_integer(dsname
, "snapdev", &snapdev
, NULL
);
1803 * Given the name and the 'snapdev' property, create device minor nodes
1804 * with the linkages to zvols/snapshots as needed.
1805 * If the name represents a zvol, create a minor node for the zvol, then
1806 * check if its snapshots are 'visible', and if so, iterate over the
1807 * snapshots and create device minor nodes for those.
1809 if (strchr(dsname
, '@') == 0) {
1811 char *n
= strdup(dsname
);
1815 job
= kmem_alloc(sizeof (minors_job_t
), KM_SLEEP
);
1817 job
->list
= minors_list
;
1819 list_insert_tail(minors_list
, job
);
1820 /* don't care if dispatch fails, because job->error is 0 */
1821 taskq_dispatch(system_taskq
, zvol_prefetch_minors_impl
, job
,
1824 if (snapdev
== ZFS_SNAPDEV_VISIBLE
) {
1826 * traverse snapshots only, do not traverse children,
1827 * and skip the 'dsname'
1829 error
= dmu_objset_find((char *)dsname
,
1830 zvol_create_snap_minor_cb
, (void *)job
,
1834 dprintf("zvol_create_minors_cb(): %s is not a zvol name\n",
1842 * Create minors for the specified dataset, including children and snapshots.
1843 * Pay attention to the 'snapdev' property and iterate over the snapshots
1844 * only if they are 'visible'. This approach allows one to assure that the
1845 * snapshot metadata is read from disk only if it is needed.
1847 * The name can represent a dataset to be recursively scanned for zvols and
1848 * their snapshots, or a single zvol snapshot. If the name represents a
1849 * dataset, the scan is performed in two nested stages:
1850 * - scan the dataset for zvols, and
1851 * - for each zvol, create a minor node, then check if the zvol's snapshots
1852 * are 'visible', and only then iterate over the snapshots if needed
1854 * If the name represents a snapshot, a check is performed if the snapshot is
1855 * 'visible' (which also verifies that the parent is a zvol), and if so,
1856 * a minor node for that snapshot is created.
1859 zvol_create_minors_impl(const char *name
)
1862 fstrans_cookie_t cookie
;
1867 if (zvol_inhibit_dev
)
1871 * This is the list for prefetch jobs. Whenever we found a match
1872 * during dmu_objset_find, we insert a minors_job to the list and do
1873 * taskq_dispatch to parallel prefetch zvol dnodes. Note we don't need
1874 * any lock because all list operation is done on the current thread.
1876 * We will use this list to do zvol_create_minor_impl after prefetch
1877 * so we don't have to traverse using dmu_objset_find again.
1879 list_create(&minors_list
, sizeof (minors_job_t
),
1880 offsetof(minors_job_t
, link
));
1882 parent
= kmem_alloc(MAXPATHLEN
, KM_SLEEP
);
1883 (void) strlcpy(parent
, name
, MAXPATHLEN
);
1885 if ((atp
= strrchr(parent
, '@')) != NULL
) {
1889 error
= dsl_prop_get_integer(parent
, "snapdev",
1892 if (error
== 0 && snapdev
== ZFS_SNAPDEV_VISIBLE
)
1893 error
= zvol_create_minor_impl(name
);
1895 cookie
= spl_fstrans_mark();
1896 error
= dmu_objset_find(parent
, zvol_create_minors_cb
,
1897 &minors_list
, DS_FIND_CHILDREN
);
1898 spl_fstrans_unmark(cookie
);
1901 kmem_free(parent
, MAXPATHLEN
);
1902 taskq_wait_outstanding(system_taskq
, 0);
1905 * Prefetch is completed, we can do zvol_create_minor_impl
1908 while ((job
= list_head(&minors_list
)) != NULL
) {
1909 list_remove(&minors_list
, job
);
1911 zvol_create_minor_impl(job
->name
);
1913 kmem_free(job
, sizeof (minors_job_t
));
1916 list_destroy(&minors_list
);
1918 return (SET_ERROR(error
));
1922 * Remove minors for specified dataset including children and snapshots.
1925 zvol_remove_minors_impl(const char *name
)
1927 zvol_state_t
*zv
, *zv_next
;
1928 int namelen
= ((name
) ? strlen(name
) : 0);
1929 taskqid_t t
, tid
= TASKQID_INVALID
;
1931 if (zvol_inhibit_dev
)
1934 mutex_enter(&zvol_state_lock
);
1936 for (zv
= list_head(&zvol_state_list
); zv
!= NULL
; zv
= zv_next
) {
1937 zv_next
= list_next(&zvol_state_list
, zv
);
1939 if (name
== NULL
|| strcmp(zv
->zv_name
, name
) == 0 ||
1940 (strncmp(zv
->zv_name
, name
, namelen
) == 0 &&
1941 (zv
->zv_name
[namelen
] == '/' ||
1942 zv
->zv_name
[namelen
] == '@'))) {
1944 /* If in use, leave alone */
1945 if (zv
->zv_open_count
> 0 ||
1946 atomic_read(&zv
->zv_suspend_ref
))
1951 /* clear this so zvol_open won't open it */
1952 zv
->zv_disk
->private_data
= NULL
;
1954 /* try parallel zv_free, if failed do it in place */
1955 t
= taskq_dispatch(system_taskq
, zvol_free_impl
, zv
,
1957 if (t
== TASKQID_INVALID
)
1963 mutex_exit(&zvol_state_lock
);
1964 if (tid
!= TASKQID_INVALID
)
1965 taskq_wait_outstanding(system_taskq
, tid
);
1968 /* Remove minor for this specific snapshot only */
1970 zvol_remove_minor_impl(const char *name
)
1972 zvol_state_t
*zv
, *zv_next
;
1974 if (zvol_inhibit_dev
)
1977 if (strchr(name
, '@') == NULL
)
1980 mutex_enter(&zvol_state_lock
);
1982 for (zv
= list_head(&zvol_state_list
); zv
!= NULL
; zv
= zv_next
) {
1983 zv_next
= list_next(&zvol_state_list
, zv
);
1985 if (strcmp(zv
->zv_name
, name
) == 0) {
1986 /* If in use, leave alone */
1987 if (zv
->zv_open_count
> 0 ||
1988 atomic_read(&zv
->zv_suspend_ref
))
1996 mutex_exit(&zvol_state_lock
);
2000 * Rename minors for specified dataset including children and snapshots.
2003 zvol_rename_minors_impl(const char *oldname
, const char *newname
)
2005 zvol_state_t
*zv
, *zv_next
;
2006 int oldnamelen
, newnamelen
;
2009 if (zvol_inhibit_dev
)
2012 oldnamelen
= strlen(oldname
);
2013 newnamelen
= strlen(newname
);
2014 name
= kmem_alloc(MAXNAMELEN
, KM_SLEEP
);
2016 mutex_enter(&zvol_state_lock
);
2018 for (zv
= list_head(&zvol_state_list
); zv
!= NULL
; zv
= zv_next
) {
2019 zv_next
= list_next(&zvol_state_list
, zv
);
2021 /* If in use, leave alone */
2022 if (zv
->zv_open_count
> 0)
2025 if (strcmp(zv
->zv_name
, oldname
) == 0) {
2026 zvol_rename_minor(zv
, newname
);
2027 } else if (strncmp(zv
->zv_name
, oldname
, oldnamelen
) == 0 &&
2028 (zv
->zv_name
[oldnamelen
] == '/' ||
2029 zv
->zv_name
[oldnamelen
] == '@')) {
2030 snprintf(name
, MAXNAMELEN
, "%s%c%s", newname
,
2031 zv
->zv_name
[oldnamelen
],
2032 zv
->zv_name
+ oldnamelen
+ 1);
2033 zvol_rename_minor(zv
, name
);
2037 mutex_exit(&zvol_state_lock
);
2039 kmem_free(name
, MAXNAMELEN
);
2042 typedef struct zvol_snapdev_cb_arg
{
2044 } zvol_snapdev_cb_arg_t
;
2047 zvol_set_snapdev_cb(const char *dsname
, void *param
)
2049 zvol_snapdev_cb_arg_t
*arg
= param
;
2051 if (strchr(dsname
, '@') == NULL
)
2054 switch (arg
->snapdev
) {
2055 case ZFS_SNAPDEV_VISIBLE
:
2056 (void) zvol_create_minor_impl(dsname
);
2058 case ZFS_SNAPDEV_HIDDEN
:
2059 (void) zvol_remove_minor_impl(dsname
);
2067 zvol_set_snapdev_impl(char *name
, uint64_t snapdev
)
2069 zvol_snapdev_cb_arg_t arg
= {snapdev
};
2070 fstrans_cookie_t cookie
= spl_fstrans_mark();
2072 * The zvol_set_snapdev_sync() sets snapdev appropriately
2073 * in the dataset hierarchy. Here, we only scan snapshots.
2075 dmu_objset_find(name
, zvol_set_snapdev_cb
, &arg
, DS_FIND_SNAPSHOTS
);
2076 spl_fstrans_unmark(cookie
);
2079 static zvol_task_t
*
2080 zvol_task_alloc(zvol_async_op_t op
, const char *name1
, const char *name2
,
2086 /* Never allow tasks on hidden names. */
2087 if (name1
[0] == '$')
2090 task
= kmem_zalloc(sizeof (zvol_task_t
), KM_SLEEP
);
2092 task
->snapdev
= snapdev
;
2093 delim
= strchr(name1
, '/');
2094 strlcpy(task
->pool
, name1
, delim
? (delim
- name1
+ 1) : MAXNAMELEN
);
2096 strlcpy(task
->name1
, name1
, MAXNAMELEN
);
2098 strlcpy(task
->name2
, name2
, MAXNAMELEN
);
2104 zvol_task_free(zvol_task_t
*task
)
2106 kmem_free(task
, sizeof (zvol_task_t
));
2110 * The worker thread function performed asynchronously.
2113 zvol_task_cb(void *param
)
2115 zvol_task_t
*task
= (zvol_task_t
*)param
;
2118 case ZVOL_ASYNC_CREATE_MINORS
:
2119 (void) zvol_create_minors_impl(task
->name1
);
2121 case ZVOL_ASYNC_REMOVE_MINORS
:
2122 zvol_remove_minors_impl(task
->name1
);
2124 case ZVOL_ASYNC_RENAME_MINORS
:
2125 zvol_rename_minors_impl(task
->name1
, task
->name2
);
2127 case ZVOL_ASYNC_SET_SNAPDEV
:
2128 zvol_set_snapdev_impl(task
->name1
, task
->snapdev
);
2135 zvol_task_free(task
);
2138 typedef struct zvol_set_snapdev_arg
{
2139 const char *zsda_name
;
2140 uint64_t zsda_value
;
2141 zprop_source_t zsda_source
;
2143 } zvol_set_snapdev_arg_t
;
2146 * Sanity check the dataset for safe use by the sync task. No additional
2147 * conditions are imposed.
2150 zvol_set_snapdev_check(void *arg
, dmu_tx_t
*tx
)
2152 zvol_set_snapdev_arg_t
*zsda
= arg
;
2153 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2157 error
= dsl_dir_hold(dp
, zsda
->zsda_name
, FTAG
, &dd
, NULL
);
2161 dsl_dir_rele(dd
, FTAG
);
2167 zvol_set_snapdev_sync_cb(dsl_pool_t
*dp
, dsl_dataset_t
*ds
, void *arg
)
2169 zvol_set_snapdev_arg_t
*zsda
= arg
;
2170 char dsname
[MAXNAMELEN
];
2173 dsl_dataset_name(ds
, dsname
);
2174 dsl_prop_set_sync_impl(ds
, zfs_prop_to_name(ZFS_PROP_SNAPDEV
),
2175 zsda
->zsda_source
, sizeof (zsda
->zsda_value
), 1,
2176 &zsda
->zsda_value
, zsda
->zsda_tx
);
2178 task
= zvol_task_alloc(ZVOL_ASYNC_SET_SNAPDEV
, dsname
,
2179 NULL
, zsda
->zsda_value
);
2183 (void) taskq_dispatch(dp
->dp_spa
->spa_zvol_taskq
, zvol_task_cb
,
2189 * Traverse all child snapshot datasets and apply snapdev appropriately.
2192 zvol_set_snapdev_sync(void *arg
, dmu_tx_t
*tx
)
2194 zvol_set_snapdev_arg_t
*zsda
= arg
;
2195 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2198 VERIFY0(dsl_dir_hold(dp
, zsda
->zsda_name
, FTAG
, &dd
, NULL
));
2201 dmu_objset_find_dp(dp
, dd
->dd_object
, zvol_set_snapdev_sync_cb
,
2202 zsda
, DS_FIND_CHILDREN
);
2204 dsl_dir_rele(dd
, FTAG
);
2208 zvol_set_snapdev(const char *ddname
, zprop_source_t source
, uint64_t snapdev
)
2210 zvol_set_snapdev_arg_t zsda
;
2212 zsda
.zsda_name
= ddname
;
2213 zsda
.zsda_source
= source
;
2214 zsda
.zsda_value
= snapdev
;
2216 return (dsl_sync_task(ddname
, zvol_set_snapdev_check
,
2217 zvol_set_snapdev_sync
, &zsda
, 0, ZFS_SPACE_CHECK_NONE
));
2221 zvol_create_minors(spa_t
*spa
, const char *name
, boolean_t async
)
2226 task
= zvol_task_alloc(ZVOL_ASYNC_CREATE_MINORS
, name
, NULL
, ~0ULL);
2230 id
= taskq_dispatch(spa
->spa_zvol_taskq
, zvol_task_cb
, task
, TQ_SLEEP
);
2231 if ((async
== B_FALSE
) && (id
!= TASKQID_INVALID
))
2232 taskq_wait_id(spa
->spa_zvol_taskq
, id
);
2236 zvol_remove_minors(spa_t
*spa
, const char *name
, boolean_t async
)
2241 task
= zvol_task_alloc(ZVOL_ASYNC_REMOVE_MINORS
, name
, NULL
, ~0ULL);
2245 id
= taskq_dispatch(spa
->spa_zvol_taskq
, zvol_task_cb
, task
, TQ_SLEEP
);
2246 if ((async
== B_FALSE
) && (id
!= TASKQID_INVALID
))
2247 taskq_wait_id(spa
->spa_zvol_taskq
, id
);
2251 zvol_rename_minors(spa_t
*spa
, const char *name1
, const char *name2
,
2257 task
= zvol_task_alloc(ZVOL_ASYNC_RENAME_MINORS
, name1
, name2
, ~0ULL);
2261 id
= taskq_dispatch(spa
->spa_zvol_taskq
, zvol_task_cb
, task
, TQ_SLEEP
);
2262 if ((async
== B_FALSE
) && (id
!= TASKQID_INVALID
))
2263 taskq_wait_id(spa
->spa_zvol_taskq
, id
);
2269 int threads
= MIN(MAX(zvol_threads
, 1), 1024);
2272 list_create(&zvol_state_list
, sizeof (zvol_state_t
),
2273 offsetof(zvol_state_t
, zv_next
));
2274 mutex_init(&zvol_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2275 ida_init(&zvol_ida
);
2277 zvol_taskq
= taskq_create(ZVOL_DRIVER
, threads
, maxclsyspri
,
2278 threads
* 2, INT_MAX
, TASKQ_PREPOPULATE
| TASKQ_DYNAMIC
);
2279 if (zvol_taskq
== NULL
) {
2280 printk(KERN_INFO
"ZFS: taskq_create() failed\n");
2285 zvol_htable
= kmem_alloc(ZVOL_HT_SIZE
* sizeof (struct hlist_head
),
2291 for (i
= 0; i
< ZVOL_HT_SIZE
; i
++)
2292 INIT_HLIST_HEAD(&zvol_htable
[i
]);
2294 error
= register_blkdev(zvol_major
, ZVOL_DRIVER
);
2296 printk(KERN_INFO
"ZFS: register_blkdev() failed %d\n", error
);
2300 blk_register_region(MKDEV(zvol_major
, 0), 1UL << MINORBITS
,
2301 THIS_MODULE
, zvol_probe
, NULL
, NULL
);
2306 kmem_free(zvol_htable
, ZVOL_HT_SIZE
* sizeof (struct hlist_head
));
2308 taskq_destroy(zvol_taskq
);
2310 mutex_destroy(&zvol_state_lock
);
2311 list_destroy(&zvol_state_list
);
2313 return (SET_ERROR(error
));
2319 zvol_remove_minors_impl(NULL
);
2321 blk_unregister_region(MKDEV(zvol_major
, 0), 1UL << MINORBITS
);
2322 unregister_blkdev(zvol_major
, ZVOL_DRIVER
);
2323 kmem_free(zvol_htable
, ZVOL_HT_SIZE
* sizeof (struct hlist_head
));
2325 taskq_destroy(zvol_taskq
);
2326 list_destroy(&zvol_state_list
);
2327 mutex_destroy(&zvol_state_lock
);
2329 ida_destroy(&zvol_ida
);
2333 module_param(zvol_inhibit_dev
, uint
, 0644);
2334 MODULE_PARM_DESC(zvol_inhibit_dev
, "Do not create zvol device nodes");
2336 module_param(zvol_major
, uint
, 0444);
2337 MODULE_PARM_DESC(zvol_major
, "Major number for zvol device");
2339 module_param(zvol_threads
, uint
, 0444);
2340 MODULE_PARM_DESC(zvol_threads
, "Max number of threads to handle I/O requests");
2342 module_param(zvol_request_sync
, uint
, 0644);
2343 MODULE_PARM_DESC(zvol_request_sync
, "Synchronously handle bio requests");
2345 module_param(zvol_max_discard_blocks
, ulong
, 0444);
2346 MODULE_PARM_DESC(zvol_max_discard_blocks
, "Max number of blocks to discard");
2348 module_param(zvol_prefetch_bytes
, uint
, 0644);
2349 MODULE_PARM_DESC(zvol_prefetch_bytes
, "Prefetch N bytes at zvol start+end");