block: Switch transfer length bounds to byte-based

Sector-based limits are awkward to think about; in our on-going
quest to move to byte-based interfaces, convert max_transfer_length
and opt_transfer_length.  Rename them (dropping the _length suffix)
so that the compiler will help us catch the change in semantics
across any rebased code, and improve the documentation.  Use unsigned
values, so that we don't have to worry about negative values and
so that bit-twiddling is easier; however, we are still constrained
by 2^31 of signed int in most APIs.

When a value comes from an external source (iscsi and raw-posix),
sanitize the results to ensure that opt_transfer is a power of 2.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Eric Blake 2016-06-23 16:37:19 -06:00 committed by Kevin Wolf
parent 79ba8c986a
commit 5def6b80e1
10 changed files with 57 additions and 47 deletions

View file

@ -338,11 +338,14 @@ typedef struct BlockLimits {
* power of 2, and less than max_pwrite_zeroes if that is set */
uint32_t pwrite_zeroes_alignment;
/* optimal transfer length in sectors */
int opt_transfer_length;
/* optimal transfer length in bytes (must be power of 2, and
* multiple of bs->request_alignment), or 0 if no preferred size */
uint32_t opt_transfer;
/* maximal transfer length in sectors */
int max_transfer_length;
/* maximal transfer length in bytes (need not be power of 2, but
* should be multiple of opt_transfer), or 0 for no 32-bit limit.
* For now, anything larger than INT_MAX is clamped down. */
uint32_t max_transfer;
/* memory alignment so that no bounce buffer is needed */
size_t min_mem_alignment;