@@ -337,16 +337,14 @@ zvol_discard(zv_request_t *zvr)
337337 }
338338
339339 /*
340- * Align the request to volume block boundaries when a secure erase is
341- * not required. This will prevent dnode_free_range() from zeroing out
342- * the unaligned parts which is slow (read-modify-write) and useless
343- * since we are not freeing any space by doing so.
340+ * Align the request to volume block boundaries. This will prevent
341+ * dnode_free_range() from zeroing out the unaligned parts which is
342+ * slow (read-modify-write) and useless since we are not freeing any
343+ * space by doing so.
344344 */
345- if (!io_is_secure_erase (bio , rq )) {
346- start = P2ROUNDUP (start , zv -> zv_volblocksize );
347- end = P2ALIGN_TYPED (end , zv -> zv_volblocksize , uint64_t );
348- size = end - start ;
349- }
345+ start = P2ROUNDUP (start , zv -> zv_volblocksize );
346+ end = P2ALIGN_TYPED (end , zv -> zv_volblocksize , uint64_t );
347+ size = end - start ;
350348
351349 if (start >= end )
352350 goto unlock ;
@@ -467,6 +465,24 @@ zvol_read_task(void *arg)
467465 zv_request_task_free (task );
468466}
469467
468+ /*
469+ * Note:
470+ *
471+ * The kernel uses different enum names for the IO opcode, depending on the
472+ * kernel version ('req_opf', 'req_op'). To sidestep this, use macros rather
473+ * than inline functions for these checks.
474+ */
475+ /* Should this IO go down the zvol write path? */
476+ #define ZVOL_OP_IS_WRITE (op ) \
477+ (op == REQ_OP_WRITE || \
478+ op == REQ_OP_FLUSH || \
479+ op == REQ_OP_DISCARD)
480+
481+ /* Is this IO type supported by zvols? */
482+ #define ZVOL_OP_IS_SUPPORTED (op ) (op == REQ_OP_READ || ZVOL_OP_IS_WRITE(op))
483+
484+ /* Get the IO opcode */
485+ #define ZVOL_OP (bio , rq ) (bio != NULL ? bio_op(bio) : req_op(rq))
470486
471487/*
472488 * Process a BIO or request
@@ -486,27 +502,32 @@ zvol_request_impl(zvol_state_t *zv, struct bio *bio, struct request *rq,
486502 uint64_t size = io_size (bio , rq );
487503 int rw ;
488504
489- if (rq != NULL ) {
490- /*
491- * Flush & trim requests go down the zvol_write codepath. Or
492- * more specifically:
493- *
494- * If request is a write, or if it's op_is_sync() and not a
495- * read, or if it's a flush, or if it's a discard, then send the
496- * request down the write path.
497- */
498- if (op_is_write (rq -> cmd_flags ) ||
499- (op_is_sync (rq -> cmd_flags ) && req_op (rq ) != REQ_OP_READ ) ||
500- req_op (rq ) == REQ_OP_FLUSH ||
501- op_is_discard (rq -> cmd_flags )) {
502- rw = WRITE ;
503- } else {
504- rw = READ ;
505- }
505+ if (unlikely (!ZVOL_OP_IS_SUPPORTED (ZVOL_OP (bio , rq )))) {
506+ zfs_dbgmsg ("Unsupported zvol %s, op=%d, flags=0x%x" ,
507+ rq != NULL ? "request" : "BIO" ,
508+ ZVOL_OP (bio , rq ),
509+ rq != NULL ? rq -> cmd_flags : bio -> bi_opf );
510+ ASSERT (ZVOL_OP_IS_SUPPORTED (ZVOL_OP (bio , rq )));
511+ zvol_end_io (bio , rq , SET_ERROR (ENOTSUPP ));
512+ goto out ;
513+ }
514+
515+ if (ZVOL_OP_IS_WRITE (ZVOL_OP (bio , rq ))) {
516+ rw = WRITE ;
506517 } else {
507- rw = bio_data_dir ( bio ) ;
518+ rw = READ ;
508519 }
509520
521+ /*
522+ * Sanity check
523+ *
524+ * If we're a BIO, check our rw matches the kernel's
525+ * bio_data_dir(bio) rw. We need to check because we support fewer
526+ * IO operations, and want to verify that what we think are reads and
527+ * writes from those operations match what the kernel thinks.
528+ */
529+ ASSERT (rq != NULL || rw == bio_data_dir (bio ));
530+
510531 if (unlikely (zv -> zv_flags & ZVOL_REMOVING )) {
511532 zvol_end_io (bio , rq , SET_ERROR (ENXIO ));
512533 goto out ;
@@ -610,7 +631,7 @@ zvol_request_impl(zvol_state_t *zv, struct bio *bio, struct request *rq,
610631 * interfaces lack this functionality (they block waiting for
611632 * the i/o to complete).
612633 */
613- if (io_is_discard (bio , rq ) || io_is_secure_erase ( bio , rq ) ) {
634+ if (io_is_discard (bio , rq )) {
614635 if (force_sync ) {
615636 zvol_discard (& zvr );
616637 } else {
0 commit comments