From: Maxim Levitsky <mlevitsk@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Ronnie Sahlberg <ronniesahlberg@gmail.com>,
qemu-block@nongnu.org, Peter Lieven <pl@kamp.de>,
Tom Yan <tom.ty89@gmail.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [PATCH v3 3/5] block: add max_ioctl_transfer to BlockLimits
Date: Thu, 17 Dec 2020 18:56:10 +0200 [thread overview]
Message-ID: <20201217165612.942849-4-mlevitsk@redhat.com> (raw)
In-Reply-To: <20201217165612.942849-1-mlevitsk@redhat.com>
Maximum transfer size when accessing a kernel block device is only relevant
when using SCSI passthrough (SG_IO ioctl) since only in this case the requests
are passed directly to underlying hardware with no pre-processing.
Same is true when using /dev/sg* character devices (which only support SG_IO)
Therefore split the block driver's advertized max transfer size by
the regular max transfer size, and the max transfer size for SCSI passthrough
(the new max_ioctl_transfer field)
In the next patch, the qemu block drivers that support SCSI passthrough
will set the max_ioctl_transfer field, and simultaneously, the block devices
that implement scsi passthrough will switch to 'blk_get_max_ioctl_transfer' to
query and to pass it to the guest.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
block/block-backend.c | 12 ++++++++++++
block/io.c | 2 ++
include/block/block_int.h | 4 ++++
include/sysemu/block-backend.h | 1 +
4 files changed, 19 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index ce78d30794..c1d149a755 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1938,6 +1938,18 @@ uint32_t blk_get_max_transfer(BlockBackend *blk)
return MIN_NON_ZERO(max, INT_MAX);
}
+/* Returns the maximum transfer length, for SCSI passthrough */
+uint32_t blk_get_max_ioctl_transfer(BlockBackend *blk)
+{
+ BlockDriverState *bs = blk_bs(blk);
+ uint32_t max = 0;
+
+ if (bs) {
+ max = bs->bl.max_ioctl_transfer;
+ }
+ return MIN_NON_ZERO(max, INT_MAX);
+}
+
int blk_get_max_iov(BlockBackend *blk)
{
return blk->root->bs->bl.max_iov;
diff --git a/block/io.c b/block/io.c
index 24205f5168..ac5aea435e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -126,6 +126,8 @@ static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
{
dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer);
dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer);
+ dst->max_ioctl_transfer = MIN_NON_ZERO(dst->max_ioctl_transfer,
+ src->max_ioctl_transfer);
dst->opt_mem_alignment = MAX(dst->opt_mem_alignment,
src->opt_mem_alignment);
dst->min_mem_alignment = MAX(dst->min_mem_alignment,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1eeafc118c..c59b0aefc4 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -686,6 +686,10 @@ typedef struct BlockLimits {
* clamped down. */
uint32_t max_transfer;
+ /* Maximal transfer length for SCSI passthrough (ioctl interface) */
+ uint32_t max_ioctl_transfer;
+
+
/* memory alignment, in bytes so that no bounce buffer is needed */
size_t min_mem_alignment;
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 8203d7f6f9..b019a37b7a 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -203,6 +203,7 @@ void blk_eject(BlockBackend *blk, bool eject_flag);
int blk_get_flags(BlockBackend *blk);
uint32_t blk_get_request_alignment(BlockBackend *blk);
uint32_t blk_get_max_transfer(BlockBackend *blk);
+uint32_t blk_get_max_ioctl_transfer(BlockBackend *blk);
int blk_get_max_iov(BlockBackend *blk);
void blk_set_guest_block_size(BlockBackend *blk, int align);
void *blk_try_blockalign(BlockBackend *blk, size_t size);
--
2.26.2
next prev parent reply other threads:[~2020-12-17 16:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 16:56 [PATCH v3 0/5] SCSI: fix transfer limits for SCSI passthrough Maxim Levitsky
2020-12-17 16:56 ` [PATCH v3 1/5] file-posix: split hdev_refresh_limits from raw_refresh_limits Maxim Levitsky
2021-01-07 12:24 ` Max Reitz
2020-12-17 16:56 ` [PATCH v3 2/5] file-posix: add sg_get_max_segments that actually works with sg Maxim Levitsky
2021-01-07 12:42 ` Max Reitz
2020-12-17 16:56 ` Maxim Levitsky [this message]
2021-01-07 13:09 ` [PATCH v3 3/5] block: add max_ioctl_transfer to BlockLimits Max Reitz
2020-12-17 16:56 ` [PATCH v3 4/5] block: use blk_get_max_ioctl_transfer for SCSI passthrough Maxim Levitsky
2021-01-07 13:19 ` Max Reitz
2020-12-17 16:56 ` [PATCH v3 5/5] block/scsi: correctly emulate the VPD block limits page Maxim Levitsky
2021-01-07 13:44 ` Max Reitz
2021-01-07 10:23 ` [PATCH v3 0/5] SCSI: fix transfer limits for SCSI passthrough Maxim Levitsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201217165612.942849-4-mlevitsk@redhat.com \
--to=mlevitsk@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
--cc=stefanha@redhat.com \
--cc=tom.ty89@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).