mirror of
https://github.com/qemu/qemu.git
synced 2024-12-18 09:43:38 +08:00
block: Switch discard 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_discard and
discard_alignment. Rename them, using 'pdiscard' as an aid to
track which remaining discard interfaces need conversion, and so
that the compiler will help us catch the change in semantics
across any rebased code. The BlockLimits type is now completely
byte-based; and in iscsi.c, sector_limits_lun2qemu() is no
longer needed.
pdiscard_alignment is made unsigned (we use power-of-2 alignments
as bitmasks, where unsigned is easier to think about) while
leaving max_pdiscard signed (since we still have an 'int'
interface); this is comparable to what commit cf081fc
did for
write zeroes limits. We may later want to make everything an
unsigned 64-bit limit - but that requires a bigger code audit.
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:
parent
29cc6a6834
commit
b9f7855a50
16
block/io.c
16
block/io.c
@ -2368,19 +2368,21 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
max_discard = MIN_NON_ZERO(bs->bl.max_discard, BDRV_REQUEST_MAX_SECTORS);
|
max_discard = MIN_NON_ZERO(bs->bl.max_pdiscard >> BDRV_SECTOR_BITS,
|
||||||
|
BDRV_REQUEST_MAX_SECTORS);
|
||||||
while (nb_sectors > 0) {
|
while (nb_sectors > 0) {
|
||||||
int ret;
|
int ret;
|
||||||
int num = nb_sectors;
|
int num = nb_sectors;
|
||||||
|
int discard_alignment = bs->bl.pdiscard_alignment >> BDRV_SECTOR_BITS;
|
||||||
|
|
||||||
/* align request */
|
/* align request */
|
||||||
if (bs->bl.discard_alignment &&
|
if (discard_alignment &&
|
||||||
num >= bs->bl.discard_alignment &&
|
num >= discard_alignment &&
|
||||||
sector_num % bs->bl.discard_alignment) {
|
sector_num % discard_alignment) {
|
||||||
if (num > bs->bl.discard_alignment) {
|
if (num > discard_alignment) {
|
||||||
num = bs->bl.discard_alignment;
|
num = discard_alignment;
|
||||||
}
|
}
|
||||||
num -= sector_num % bs->bl.discard_alignment;
|
num -= sector_num % discard_alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* limit request size */
|
/* limit request size */
|
||||||
|
@ -1697,13 +1697,6 @@ static void iscsi_close(BlockDriverState *bs)
|
|||||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
memset(iscsilun, 0, sizeof(IscsiLun));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sector_limits_lun2qemu(int64_t sector, IscsiLun *iscsilun)
|
|
||||||
{
|
|
||||||
int limit = MIN(sector_lun2qemu(sector, iscsilun), INT_MAX / 2 + 1);
|
|
||||||
|
|
||||||
return limit < BDRV_REQUEST_MAX_SECTORS ? limit : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
|
static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||||
{
|
{
|
||||||
/* We don't actually refresh here, but just return data queried in
|
/* We don't actually refresh here, but just return data queried in
|
||||||
@ -1723,14 +1716,14 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iscsilun->lbp.lbpu) {
|
if (iscsilun->lbp.lbpu) {
|
||||||
if (iscsilun->bl.max_unmap < 0xffffffff) {
|
if (iscsilun->bl.max_unmap < 0xffffffff / iscsilun->block_size) {
|
||||||
bs->bl.max_discard =
|
bs->bl.max_pdiscard =
|
||||||
sector_limits_lun2qemu(iscsilun->bl.max_unmap, iscsilun);
|
iscsilun->bl.max_unmap * iscsilun->block_size;
|
||||||
}
|
}
|
||||||
bs->bl.discard_alignment =
|
bs->bl.pdiscard_alignment =
|
||||||
sector_limits_lun2qemu(iscsilun->bl.opt_unmap_gran, iscsilun);
|
iscsilun->bl.opt_unmap_gran * iscsilun->block_size;
|
||||||
} else {
|
} else {
|
||||||
bs->bl.discard_alignment = iscsilun->block_size >> BDRV_SECTOR_BITS;
|
bs->bl.pdiscard_alignment = iscsilun->block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscsilun->bl.max_ws_len < 0xffffffff / iscsilun->block_size) {
|
if (iscsilun->bl.max_ws_len < 0xffffffff / iscsilun->block_size) {
|
||||||
|
@ -362,7 +362,7 @@ static int nbd_co_flush(BlockDriverState *bs)
|
|||||||
|
|
||||||
static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)
|
static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||||
{
|
{
|
||||||
bs->bl.max_discard = NBD_MAX_SECTORS;
|
bs->bl.max_pdiscard = NBD_MAX_BUFFER_SIZE;
|
||||||
bs->bl.max_transfer = NBD_MAX_BUFFER_SIZE;
|
bs->bl.max_transfer = NBD_MAX_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,11 +324,17 @@ struct BlockDriver {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef struct BlockLimits {
|
typedef struct BlockLimits {
|
||||||
/* maximum number of sectors that can be discarded at once */
|
/* maximum number of bytes that can be discarded at once (since it
|
||||||
int max_discard;
|
* is signed, it must be < 2G, if set), should be multiple of
|
||||||
|
* pdiscard_alignment, but need not be power of 2. May be 0 if no
|
||||||
|
* inherent 32-bit limit */
|
||||||
|
int32_t max_pdiscard;
|
||||||
|
|
||||||
/* optimal alignment for discard requests in sectors */
|
/* optimal alignment for discard requests in bytes, must be power
|
||||||
int64_t discard_alignment;
|
* of 2, less than max_pdiscard if that is set, and multiple of
|
||||||
|
* bs->request_alignment. May be 0 if bs->request_alignment is
|
||||||
|
* good enough */
|
||||||
|
uint32_t pdiscard_alignment;
|
||||||
|
|
||||||
/* maximum number of bytes that can zeroized at once (since it is
|
/* maximum number of bytes that can zeroized at once (since it is
|
||||||
* signed, it must be < 2G, if set), should be multiple of
|
* signed, it must be < 2G, if set), should be multiple of
|
||||||
|
@ -2091,7 +2091,8 @@ static int img_convert(int argc, char **argv)
|
|||||||
bufsectors = MIN(32768,
|
bufsectors = MIN(32768,
|
||||||
MAX(bufsectors,
|
MAX(bufsectors,
|
||||||
MAX(out_bs->bl.opt_transfer >> BDRV_SECTOR_BITS,
|
MAX(out_bs->bl.opt_transfer >> BDRV_SECTOR_BITS,
|
||||||
out_bs->bl.discard_alignment)));
|
out_bs->bl.pdiscard_alignment >>
|
||||||
|
BDRV_SECTOR_BITS)));
|
||||||
|
|
||||||
if (skip_create) {
|
if (skip_create) {
|
||||||
int64_t output_sectors = blk_nb_sectors(out_blk);
|
int64_t output_sectors = blk_nb_sectors(out_blk);
|
||||||
|
Loading…
Reference in New Issue
Block a user