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>.
26 * Copyright (c) 2012, 2019 by Delphix. All rights reserved.
29 #include <sys/zfs_context.h>
30 #include <sys/spa_impl.h>
31 #include <sys/vdev_disk.h>
32 #include <sys/vdev_impl.h>
33 #include <sys/vdev_trim.h>
35 #include <sys/fs/zfs.h>
37 #include <linux/blkpg.h>
38 #include <linux/msdos_fs.h>
39 #include <linux/vfs_compat.h>
40 #ifdef HAVE_LINUX_BLK_CGROUP_HEADER
41 #include <linux/blk-cgroup.h>
44 typedef struct vdev_disk
{
45 struct block_device
*vd_bdev
;
50 * Unique identifier for the exclusive vdev holder.
52 static void *zfs_vdev_holder
= VDEV_HOLDER
;
55 * Wait up to zfs_vdev_open_timeout_ms milliseconds before determining the
56 * device is missing. The missing path may be transient since the links
57 * can be briefly removed and recreated in response to udev events.
59 static unsigned zfs_vdev_open_timeout_ms
= 1000;
62 * Size of the "reserved" partition, in blocks.
64 #define EFI_MIN_RESV_SIZE (16 * 1024)
67 * Virtual device vector for disks.
69 typedef struct dio_request
{
70 zio_t
*dr_zio
; /* Parent ZIO */
71 atomic_t dr_ref
; /* References */
72 int dr_error
; /* Bio error */
73 int dr_bio_count
; /* Count of bio's */
74 struct bio
*dr_bio
[0]; /* Attached bio's */
78 vdev_bdev_mode(spa_mode_t spa_mode
)
82 if (spa_mode
& SPA_MODE_READ
)
85 if (spa_mode
& SPA_MODE_WRITE
)
92 * Returns the usable capacity (in bytes) for the partition or disk.
95 bdev_capacity(struct block_device
*bdev
)
97 return (i_size_read(bdev
->bd_inode
));
100 #if !defined(HAVE_BDEV_WHOLE)
101 static inline struct block_device
*
102 bdev_whole(struct block_device
*bdev
)
104 return (bdev
->bd_contains
);
109 * Returns the maximum expansion capacity of the block device (in bytes).
111 * It is possible to expand a vdev when it has been created as a wholedisk
112 * and the containing block device has increased in capacity. Or when the
113 * partition containing the pool has been manually increased in size.
115 * This function is only responsible for calculating the potential expansion
116 * size so it can be reported by 'zpool list'. The efi_use_whole_disk() is
117 * responsible for verifying the expected partition layout in the wholedisk
118 * case, and updating the partition table if appropriate. Once the partition
119 * size has been increased the additional capacity will be visible using
122 * The returned maximum expansion capacity is always expected to be larger, or
123 * at the very least equal, to its usable capacity to prevent overestimating
124 * the pool expandsize.
127 bdev_max_capacity(struct block_device
*bdev
, uint64_t wholedisk
)
132 if (wholedisk
&& bdev
!= bdev_whole(bdev
)) {
134 * When reporting maximum expansion capacity for a wholedisk
135 * deduct any capacity which is expected to be lost due to
136 * alignment restrictions. Over reporting this value isn't
137 * harmful and would only result in slightly less capacity
138 * than expected post expansion.
139 * The estimated available space may be slightly smaller than
140 * bdev_capacity() for devices where the number of sectors is
141 * not a multiple of the alignment size and the partition layout
142 * is keeping less than PARTITION_END_ALIGNMENT bytes after the
143 * "reserved" EFI partition: in such cases return the device
146 available
= i_size_read(bdev_whole(bdev
)->bd_inode
) -
147 ((EFI_MIN_RESV_SIZE
+ NEW_START_BLOCK
+
148 PARTITION_END_ALIGNMENT
) << SECTOR_BITS
);
149 psize
= MAX(available
, bdev_capacity(bdev
));
151 psize
= bdev_capacity(bdev
);
158 vdev_disk_error(zio_t
*zio
)
161 * This function can be called in interrupt context, for instance while
162 * handling IRQs coming from a misbehaving disk device; use printk()
163 * which is safe from any context.
165 printk(KERN_WARNING
"zio pool=%s vdev=%s error=%d type=%d "
166 "offset=%llu size=%llu flags=%x\n", spa_name(zio
->io_spa
),
167 zio
->io_vd
->vdev_path
, zio
->io_error
, zio
->io_type
,
168 (u_longlong_t
)zio
->io_offset
, (u_longlong_t
)zio
->io_size
,
173 vdev_disk_open(vdev_t
*v
, uint64_t *psize
, uint64_t *max_psize
,
174 uint64_t *logical_ashift
, uint64_t *physical_ashift
)
176 struct block_device
*bdev
;
177 fmode_t mode
= vdev_bdev_mode(spa_mode(v
->vdev_spa
));
178 hrtime_t timeout
= MSEC2NSEC(zfs_vdev_open_timeout_ms
);
181 /* Must have a pathname and it must be absolute. */
182 if (v
->vdev_path
== NULL
|| v
->vdev_path
[0] != '/') {
183 v
->vdev_stat
.vs_aux
= VDEV_AUX_BAD_LABEL
;
184 vdev_dbgmsg(v
, "invalid vdev_path");
185 return (SET_ERROR(EINVAL
));
189 * Reopen the device if it is currently open. When expanding a
190 * partition force re-scanning the partition table if userland
191 * did not take care of this already. We need to do this while closed
192 * in order to get an accurate updated block device size. Then
193 * since udev may need to recreate the device links increase the
194 * open retry timeout before reporting the device as unavailable.
198 char disk_name
[BDEVNAME_SIZE
+ 6] = "/dev/";
199 boolean_t reread_part
= B_FALSE
;
201 rw_enter(&vd
->vd_lock
, RW_WRITER
);
206 if (v
->vdev_expanding
&& bdev
!= bdev_whole(bdev
)) {
207 bdevname(bdev_whole(bdev
), disk_name
+ 5);
209 * If userland has BLKPG_RESIZE_PARTITION,
210 * then it should have updated the partition
211 * table already. We can detect this by
212 * comparing our current physical size
213 * with that of the device. If they are
214 * the same, then we must not have
215 * BLKPG_RESIZE_PARTITION or it failed to
216 * update the partition table online. We
217 * fallback to rescanning the partition
218 * table from the kernel below. However,
219 * if the capacity already reflects the
220 * updated partition, then we skip
221 * rescanning the partition table here.
223 if (v
->vdev_psize
== bdev_capacity(bdev
))
224 reread_part
= B_TRUE
;
227 blkdev_put(bdev
, mode
| FMODE_EXCL
);
231 bdev
= blkdev_get_by_path(disk_name
, mode
| FMODE_EXCL
,
234 int error
= vdev_bdev_reread_part(bdev
);
235 blkdev_put(bdev
, mode
| FMODE_EXCL
);
238 zfs_vdev_open_timeout_ms
* 2);
243 vd
= kmem_zalloc(sizeof (vdev_disk_t
), KM_SLEEP
);
245 rw_init(&vd
->vd_lock
, NULL
, RW_DEFAULT
, NULL
);
246 rw_enter(&vd
->vd_lock
, RW_WRITER
);
250 * Devices are always opened by the path provided at configuration
251 * time. This means that if the provided path is a udev by-id path
252 * then drives may be re-cabled without an issue. If the provided
253 * path is a udev by-path path, then the physical location information
254 * will be preserved. This can be critical for more complicated
255 * configurations where drives are located in specific physical
256 * locations to maximize the systems tolerance to component failure.
258 * Alternatively, you can provide your own udev rule to flexibly map
259 * the drives as you see fit. It is not advised that you use the
260 * /dev/[hd]d devices which may be reordered due to probing order.
261 * Devices in the wrong locations will be detected by the higher
262 * level vdev validation.
264 * The specified paths may be briefly removed and recreated in
265 * response to udev events. This should be exceptionally unlikely
266 * because the zpool command makes every effort to verify these paths
267 * have already settled prior to reaching this point. Therefore,
268 * a ENOENT failure at this point is highly likely to be transient
269 * and it is reasonable to sleep and retry before giving up. In
270 * practice delays have been observed to be on the order of 100ms.
272 * When ERESTARTSYS is returned it indicates the block device is
273 * a zvol which could not be opened due to the deadlock detection
274 * logic in zvol_open(). Extend the timeout and retry the open
275 * subsequent attempts are expected to eventually succeed.
277 hrtime_t start
= gethrtime();
278 bdev
= ERR_PTR(-ENXIO
);
279 while (IS_ERR(bdev
) && ((gethrtime() - start
) < timeout
)) {
280 bdev
= blkdev_get_by_path(v
->vdev_path
, mode
| FMODE_EXCL
,
282 if (unlikely(PTR_ERR(bdev
) == -ENOENT
)) {
283 schedule_timeout(MSEC_TO_TICK(10));
284 } else if (unlikely(PTR_ERR(bdev
) == -ERESTARTSYS
)) {
285 timeout
= MSEC2NSEC(zfs_vdev_open_timeout_ms
* 10);
287 } else if (IS_ERR(bdev
)) {
293 int error
= -PTR_ERR(bdev
);
294 vdev_dbgmsg(v
, "open error=%d timeout=%llu/%llu", error
,
295 (u_longlong_t
)(gethrtime() - start
),
296 (u_longlong_t
)timeout
);
299 rw_exit(&vd
->vd_lock
);
300 return (SET_ERROR(error
));
304 rw_exit(&vd
->vd_lock
);
307 struct request_queue
*q
= bdev_get_queue(vd
->vd_bdev
);
309 /* Determine the physical block size */
310 int physical_block_size
= bdev_physical_block_size(vd
->vd_bdev
);
312 /* Determine the logical block size */
313 int logical_block_size
= bdev_logical_block_size(vd
->vd_bdev
);
315 /* Clear the nowritecache bit, causes vdev_reopen() to try again. */
316 v
->vdev_nowritecache
= B_FALSE
;
318 /* Set when device reports it supports TRIM. */
319 v
->vdev_has_trim
= !!blk_queue_discard(q
);
321 /* Set when device reports it supports secure TRIM. */
322 v
->vdev_has_securetrim
= !!blk_queue_discard_secure(q
);
324 /* Inform the ZIO pipeline that we are non-rotational */
325 v
->vdev_nonrot
= blk_queue_nonrot(q
);
327 /* Physical volume size in bytes for the partition */
328 *psize
= bdev_capacity(vd
->vd_bdev
);
330 /* Physical volume size in bytes including possible expansion space */
331 *max_psize
= bdev_max_capacity(vd
->vd_bdev
, v
->vdev_wholedisk
);
333 /* Based on the minimum sector size set the block size */
334 *physical_ashift
= highbit64(MAX(physical_block_size
,
335 SPA_MINBLOCKSIZE
)) - 1;
337 *logical_ashift
= highbit64(MAX(logical_block_size
,
338 SPA_MINBLOCKSIZE
)) - 1;
344 vdev_disk_close(vdev_t
*v
)
346 vdev_disk_t
*vd
= v
->vdev_tsd
;
348 if (v
->vdev_reopening
|| vd
== NULL
)
351 if (vd
->vd_bdev
!= NULL
) {
352 blkdev_put(vd
->vd_bdev
,
353 vdev_bdev_mode(spa_mode(v
->vdev_spa
)) | FMODE_EXCL
);
356 rw_destroy(&vd
->vd_lock
);
357 kmem_free(vd
, sizeof (vdev_disk_t
));
361 static dio_request_t
*
362 vdev_disk_dio_alloc(int bio_count
)
364 dio_request_t
*dr
= kmem_zalloc(sizeof (dio_request_t
) +
365 sizeof (struct bio
*) * bio_count
, KM_SLEEP
);
366 atomic_set(&dr
->dr_ref
, 0);
367 dr
->dr_bio_count
= bio_count
;
370 for (int i
= 0; i
< dr
->dr_bio_count
; i
++)
371 dr
->dr_bio
[i
] = NULL
;
377 vdev_disk_dio_free(dio_request_t
*dr
)
381 for (i
= 0; i
< dr
->dr_bio_count
; i
++)
383 bio_put(dr
->dr_bio
[i
]);
385 kmem_free(dr
, sizeof (dio_request_t
) +
386 sizeof (struct bio
*) * dr
->dr_bio_count
);
390 vdev_disk_dio_get(dio_request_t
*dr
)
392 atomic_inc(&dr
->dr_ref
);
396 vdev_disk_dio_put(dio_request_t
*dr
)
398 int rc
= atomic_dec_return(&dr
->dr_ref
);
401 * Free the dio_request when the last reference is dropped and
402 * ensure zio_interpret is called only once with the correct zio
405 zio_t
*zio
= dr
->dr_zio
;
406 int error
= dr
->dr_error
;
408 vdev_disk_dio_free(dr
);
411 zio
->io_error
= error
;
412 ASSERT3S(zio
->io_error
, >=, 0);
414 vdev_disk_error(zio
);
416 zio_delay_interrupt(zio
);
423 BIO_END_IO_PROTO(vdev_disk_physio_completion
, bio
, error
)
425 dio_request_t
*dr
= bio
->bi_private
;
428 if (dr
->dr_error
== 0) {
429 #ifdef HAVE_1ARG_BIO_END_IO_T
430 dr
->dr_error
= BIO_END_IO_ERROR(bio
);
433 dr
->dr_error
= -(error
);
434 else if (!test_bit(BIO_UPTODATE
, &bio
->bi_flags
))
439 /* Drop reference acquired by __vdev_disk_physio */
440 rc
= vdev_disk_dio_put(dr
);
444 vdev_submit_bio_impl(struct bio
*bio
)
446 #ifdef HAVE_1ARG_SUBMIT_BIO
447 (void) submit_bio(bio
);
449 (void) submit_bio(0, bio
);
454 * preempt_schedule_notrace is GPL-only which breaks the ZFS build, so
455 * replace it with preempt_schedule under the following condition:
457 #if defined(CONFIG_ARM64) && \
458 defined(CONFIG_PREEMPTION) && \
459 defined(CONFIG_BLK_CGROUP)
460 #define preempt_schedule_notrace(x) preempt_schedule(x)
463 #ifdef HAVE_BIO_SET_DEV
464 #if defined(CONFIG_BLK_CGROUP) && defined(HAVE_BIO_SET_DEV_GPL_ONLY)
466 * The Linux 5.5 kernel updated percpu_ref_tryget() which is inlined by
467 * blkg_tryget() to use rcu_read_lock() instead of rcu_read_lock_sched().
468 * As a side effect the function was converted to GPL-only. Define our
469 * own version when needed which uses rcu_read_lock_sched().
471 #if defined(HAVE_BLKG_TRYGET_GPL_ONLY)
473 vdev_blkg_tryget(struct blkcg_gq
*blkg
)
475 struct percpu_ref
*ref
= &blkg
->refcnt
;
476 unsigned long __percpu
*count
;
479 rcu_read_lock_sched();
481 if (__ref_is_percpu(ref
, &count
)) {
482 this_cpu_inc(*count
);
485 #ifdef ZFS_PERCPU_REF_COUNT_IN_DATA
486 rc
= atomic_long_inc_not_zero(&ref
->data
->count
);
488 rc
= atomic_long_inc_not_zero(&ref
->count
);
492 rcu_read_unlock_sched();
496 #elif defined(HAVE_BLKG_TRYGET)
497 #define vdev_blkg_tryget(bg) blkg_tryget(bg)
499 #ifdef HAVE_BIO_SET_DEV_MACRO
501 * The Linux 5.0 kernel updated the bio_set_dev() macro so it calls the
502 * GPL-only bio_associate_blkg() symbol thus inadvertently converting
503 * the entire macro. Provide a minimal version which always assigns the
504 * request queue's root_blkg to the bio.
507 vdev_bio_associate_blkg(struct bio
*bio
)
509 #if defined(HAVE_BIO_BDEV_DISK)
510 struct request_queue
*q
= bio
->bi_bdev
->bd_disk
->queue
;
512 struct request_queue
*q
= bio
->bi_disk
->queue
;
515 ASSERT3P(q
, !=, NULL
);
516 ASSERT3P(bio
->bi_blkg
, ==, NULL
);
518 if (q
->root_blkg
&& vdev_blkg_tryget(q
->root_blkg
))
519 bio
->bi_blkg
= q
->root_blkg
;
522 #define bio_associate_blkg vdev_bio_associate_blkg
525 vdev_bio_set_dev(struct bio
*bio
, struct block_device
*bdev
)
527 #if defined(HAVE_BIO_BDEV_DISK)
528 struct request_queue
*q
= bdev
->bd_disk
->queue
;
530 struct request_queue
*q
= bio
->bi_disk
->queue
;
532 bio_clear_flag(bio
, BIO_REMAPPED
);
533 if (bio
->bi_bdev
!= bdev
)
534 bio_clear_flag(bio
, BIO_THROTTLED
);
537 ASSERT3P(q
, !=, NULL
);
538 ASSERT3P(bio
->bi_blkg
, ==, NULL
);
540 if (q
->root_blkg
&& vdev_blkg_tryget(q
->root_blkg
))
541 bio
->bi_blkg
= q
->root_blkg
;
543 #define bio_set_dev vdev_bio_set_dev
548 * Provide a bio_set_dev() helper macro for pre-Linux 4.14 kernels.
551 bio_set_dev(struct bio
*bio
, struct block_device
*bdev
)
555 #endif /* HAVE_BIO_SET_DEV */
558 vdev_submit_bio(struct bio
*bio
)
560 struct bio_list
*bio_list
= current
->bio_list
;
561 current
->bio_list
= NULL
;
562 vdev_submit_bio_impl(bio
);
563 current
->bio_list
= bio_list
;
567 __vdev_disk_physio(struct block_device
*bdev
, zio_t
*zio
,
568 size_t io_size
, uint64_t io_offset
, int rw
, int flags
)
576 struct blk_plug plug
;
579 * Accessing outside the block device is never allowed.
581 if (io_offset
+ io_size
> bdev
->bd_inode
->i_size
) {
582 vdev_dbgmsg(zio
->io_vd
,
583 "Illegal access %llu size %llu, device size %llu",
584 (u_longlong_t
)io_offset
,
585 (u_longlong_t
)io_size
,
586 (u_longlong_t
)i_size_read(bdev
->bd_inode
));
587 return (SET_ERROR(EIO
));
591 dr
= vdev_disk_dio_alloc(bio_count
);
593 if (zio
&& !(zio
->io_flags
& (ZIO_FLAG_IO_RETRY
| ZIO_FLAG_TRYHARD
)))
594 bio_set_flags_failfast(bdev
, &flags
);
599 * Since bio's can have up to BIO_MAX_PAGES=256 iovec's, each of which
600 * is at least 512 bytes and at most PAGESIZE (typically 4K), one bio
601 * can cover at least 128KB and at most 1MB. When the required number
602 * of iovec's exceeds this, we are forced to break the IO in multiple
603 * bio's and wait for them all to complete. This is likely if the
604 * recordsize property is increased beyond 1MB. The default
605 * bio_count=16 should typically accommodate the maximum-size zio of
610 bio_offset
= io_offset
;
612 for (int i
= 0; i
<= dr
->dr_bio_count
; i
++) {
614 /* Finished constructing bio's for given buffer */
619 * If additional bio's are required, we have to retry, but
620 * this should be rare - see the comment above.
622 if (dr
->dr_bio_count
== i
) {
623 vdev_disk_dio_free(dr
);
628 /* bio_alloc() with __GFP_WAIT never returns NULL */
629 #ifdef HAVE_BIO_MAX_SEGS
630 dr
->dr_bio
[i
] = bio_alloc(GFP_NOIO
, bio_max_segs(
631 abd_nr_pages_off(zio
->io_abd
, bio_size
, abd_offset
)));
633 dr
->dr_bio
[i
] = bio_alloc(GFP_NOIO
,
634 MIN(abd_nr_pages_off(zio
->io_abd
, bio_size
, abd_offset
),
637 if (unlikely(dr
->dr_bio
[i
] == NULL
)) {
638 vdev_disk_dio_free(dr
);
639 return (SET_ERROR(ENOMEM
));
642 /* Matching put called by vdev_disk_physio_completion */
643 vdev_disk_dio_get(dr
);
645 bio_set_dev(dr
->dr_bio
[i
], bdev
);
646 BIO_BI_SECTOR(dr
->dr_bio
[i
]) = bio_offset
>> 9;
647 dr
->dr_bio
[i
]->bi_end_io
= vdev_disk_physio_completion
;
648 dr
->dr_bio
[i
]->bi_private
= dr
;
649 bio_set_op_attrs(dr
->dr_bio
[i
], rw
, flags
);
651 /* Remaining size is returned to become the new size */
652 bio_size
= abd_bio_map_off(dr
->dr_bio
[i
], zio
->io_abd
,
653 bio_size
, abd_offset
);
655 /* Advance in buffer and construct another bio if needed */
656 abd_offset
+= BIO_BI_SIZE(dr
->dr_bio
[i
]);
657 bio_offset
+= BIO_BI_SIZE(dr
->dr_bio
[i
]);
660 /* Extra reference to protect dio_request during vdev_submit_bio */
661 vdev_disk_dio_get(dr
);
663 if (dr
->dr_bio_count
> 1)
664 blk_start_plug(&plug
);
666 /* Submit all bio's associated with this dio */
667 for (int i
= 0; i
< dr
->dr_bio_count
; i
++) {
669 vdev_submit_bio(dr
->dr_bio
[i
]);
672 if (dr
->dr_bio_count
> 1)
673 blk_finish_plug(&plug
);
675 (void) vdev_disk_dio_put(dr
);
680 BIO_END_IO_PROTO(vdev_disk_io_flush_completion
, bio
, error
)
682 zio_t
*zio
= bio
->bi_private
;
683 #ifdef HAVE_1ARG_BIO_END_IO_T
684 zio
->io_error
= BIO_END_IO_ERROR(bio
);
686 zio
->io_error
= -error
;
689 if (zio
->io_error
&& (zio
->io_error
== EOPNOTSUPP
))
690 zio
->io_vd
->vdev_nowritecache
= B_TRUE
;
693 ASSERT3S(zio
->io_error
, >=, 0);
695 vdev_disk_error(zio
);
700 vdev_disk_io_flush(struct block_device
*bdev
, zio_t
*zio
)
702 struct request_queue
*q
;
705 q
= bdev_get_queue(bdev
);
707 return (SET_ERROR(ENXIO
));
709 bio
= bio_alloc(GFP_NOIO
, 0);
710 /* bio_alloc() with __GFP_WAIT never returns NULL */
711 if (unlikely(bio
== NULL
))
712 return (SET_ERROR(ENOMEM
));
714 bio
->bi_end_io
= vdev_disk_io_flush_completion
;
715 bio
->bi_private
= zio
;
716 bio_set_dev(bio
, bdev
);
718 vdev_submit_bio(bio
);
719 invalidate_bdev(bdev
);
725 vdev_disk_io_start(zio_t
*zio
)
727 vdev_t
*v
= zio
->io_vd
;
728 vdev_disk_t
*vd
= v
->vdev_tsd
;
729 unsigned long trim_flags
= 0;
733 * If the vdev is closed, it's likely in the REMOVED or FAULTED state.
734 * Nothing to be done here but return failure.
737 zio
->io_error
= ENXIO
;
742 rw_enter(&vd
->vd_lock
, RW_READER
);
745 * If the vdev is closed, it's likely due to a failed reopen and is
746 * in the UNAVAIL state. Nothing to be done here but return failure.
748 if (vd
->vd_bdev
== NULL
) {
749 rw_exit(&vd
->vd_lock
);
750 zio
->io_error
= ENXIO
;
755 switch (zio
->io_type
) {
758 if (!vdev_readable(v
)) {
759 rw_exit(&vd
->vd_lock
);
760 zio
->io_error
= SET_ERROR(ENXIO
);
765 switch (zio
->io_cmd
) {
766 case DKIOCFLUSHWRITECACHE
:
768 if (zfs_nocacheflush
)
771 if (v
->vdev_nowritecache
) {
772 zio
->io_error
= SET_ERROR(ENOTSUP
);
776 error
= vdev_disk_io_flush(vd
->vd_bdev
, zio
);
778 rw_exit(&vd
->vd_lock
);
782 zio
->io_error
= error
;
787 zio
->io_error
= SET_ERROR(ENOTSUP
);
790 rw_exit(&vd
->vd_lock
);
802 #if defined(BLKDEV_DISCARD_SECURE)
803 if (zio
->io_trim_flags
& ZIO_TRIM_SECURE
)
804 trim_flags
|= BLKDEV_DISCARD_SECURE
;
806 zio
->io_error
= -blkdev_issue_discard(vd
->vd_bdev
,
807 zio
->io_offset
>> 9, zio
->io_size
>> 9, GFP_NOFS
,
810 rw_exit(&vd
->vd_lock
);
815 rw_exit(&vd
->vd_lock
);
816 zio
->io_error
= SET_ERROR(ENOTSUP
);
821 zio
->io_target_timestamp
= zio_handle_io_delay(zio
);
822 error
= __vdev_disk_physio(vd
->vd_bdev
, zio
,
823 zio
->io_size
, zio
->io_offset
, rw
, 0);
824 rw_exit(&vd
->vd_lock
);
827 zio
->io_error
= error
;
834 vdev_disk_io_done(zio_t
*zio
)
837 * If the device returned EIO, we revalidate the media. If it is
838 * determined the media has changed this triggers the asynchronous
839 * removal of the device from the configuration.
841 if (zio
->io_error
== EIO
) {
842 vdev_t
*v
= zio
->io_vd
;
843 vdev_disk_t
*vd
= v
->vdev_tsd
;
845 if (zfs_check_media_change(vd
->vd_bdev
)) {
846 invalidate_bdev(vd
->vd_bdev
);
847 v
->vdev_remove_wanted
= B_TRUE
;
848 spa_async_request(zio
->io_spa
, SPA_ASYNC_REMOVE
);
854 vdev_disk_hold(vdev_t
*vd
)
856 ASSERT(spa_config_held(vd
->vdev_spa
, SCL_STATE
, RW_WRITER
));
858 /* We must have a pathname, and it must be absolute. */
859 if (vd
->vdev_path
== NULL
|| vd
->vdev_path
[0] != '/')
863 * Only prefetch path and devid info if the device has
866 if (vd
->vdev_tsd
!= NULL
)
872 vdev_disk_rele(vdev_t
*vd
)
874 ASSERT(spa_config_held(vd
->vdev_spa
, SCL_STATE
, RW_WRITER
));
876 /* XXX: Implement me as a vnode rele for the device */
879 vdev_ops_t vdev_disk_ops
= {
880 .vdev_op_init
= NULL
,
881 .vdev_op_fini
= NULL
,
882 .vdev_op_open
= vdev_disk_open
,
883 .vdev_op_close
= vdev_disk_close
,
884 .vdev_op_asize
= vdev_default_asize
,
885 .vdev_op_min_asize
= vdev_default_min_asize
,
886 .vdev_op_min_alloc
= NULL
,
887 .vdev_op_io_start
= vdev_disk_io_start
,
888 .vdev_op_io_done
= vdev_disk_io_done
,
889 .vdev_op_state_change
= NULL
,
890 .vdev_op_need_resilver
= NULL
,
891 .vdev_op_hold
= vdev_disk_hold
,
892 .vdev_op_rele
= vdev_disk_rele
,
893 .vdev_op_remap
= NULL
,
894 .vdev_op_xlate
= vdev_default_xlate
,
895 .vdev_op_rebuild_asize
= NULL
,
896 .vdev_op_metaslab_init
= NULL
,
897 .vdev_op_config_generate
= NULL
,
898 .vdev_op_nparity
= NULL
,
899 .vdev_op_ndisks
= NULL
,
900 .vdev_op_type
= VDEV_TYPE_DISK
, /* name of this vdev type */
901 .vdev_op_leaf
= B_TRUE
/* leaf vdev */
905 * The zfs_vdev_scheduler module option has been deprecated. Setting this
906 * value no longer has any effect. It has not yet been entirely removed
907 * to allow the module to be loaded if this option is specified in the
908 * /etc/modprobe.d/zfs.conf file. The following warning will be logged.
911 param_set_vdev_scheduler(const char *val
, zfs_kernel_param_t
*kp
)
913 int error
= param_set_charp(val
, kp
);
915 printk(KERN_INFO
"The 'zfs_vdev_scheduler' module option "
916 "is not supported.\n");
922 static const char *zfs_vdev_scheduler
= "unused";
923 module_param_call(zfs_vdev_scheduler
, param_set_vdev_scheduler
,
924 param_get_charp
, &zfs_vdev_scheduler
, 0644);
925 MODULE_PARM_DESC(zfs_vdev_scheduler
, "I/O scheduler");
928 param_set_min_auto_ashift(const char *buf
, zfs_kernel_param_t
*kp
)
933 error
= kstrtoull(buf
, 0, &val
);
935 return (SET_ERROR(error
));
937 if (val
< ASHIFT_MIN
|| val
> zfs_vdev_max_auto_ashift
)
938 return (SET_ERROR(-EINVAL
));
940 error
= param_set_ulong(buf
, kp
);
942 return (SET_ERROR(error
));
948 param_set_max_auto_ashift(const char *buf
, zfs_kernel_param_t
*kp
)
953 error
= kstrtoull(buf
, 0, &val
);
955 return (SET_ERROR(error
));
957 if (val
> ASHIFT_MAX
|| val
< zfs_vdev_min_auto_ashift
)
958 return (SET_ERROR(-EINVAL
));
960 error
= param_set_ulong(buf
, kp
);
962 return (SET_ERROR(error
));