assert(bdrv_opt_mem_align(bs) != 0);
assert(bdrv_min_mem_align(bs) != 0);
- assert(is_power_of_2(bs->request_alignment) || bdrv_is_sg(bs));
+ assert(is_power_of_2(bs->bl.request_alignment));
qemu_opts_del(opts);
return 0;
BDRVBlkdebugState *s = bs->opaque;
if (s->align) {
- bs->request_alignment = s->align;
+ bs->bl.request_alignment = s->align;
}
}
static void bochs_refresh_limits(BlockDriverState *bs, Error **errp)
{
- bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */
+ bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
}
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
static void cloop_refresh_limits(BlockDriverState *bs, Error **errp)
{
- bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */
+ bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
}
static inline int cloop_read_block(BlockDriverState *bs, int block_num)
static void dmg_refresh_limits(BlockDriverState *bs, Error **errp)
{
- bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */
+ bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
}
static inline int is_sector_in_chunk(BDRVDMGState* s,
}
/* Default alignment based on whether driver has byte interface */
- bs->request_alignment = drv->bdrv_co_preadv ? 1 : 512;
+ bs->bl.request_alignment = drv->bdrv_co_preadv ? 1 : 512;
/* Take some limits from the children as a default */
if (bs->file) {
ret = bdrv_get_info(bs, &bdi);
if (ret < 0 || bdi.cluster_size == 0) {
- return bs->request_alignment;
+ return bs->bl.request_alignment;
} else {
return bdi.cluster_size;
}
BlockDriver *drv = bs->drv;
BdrvTrackedRequest req;
- uint64_t align = bs->request_alignment;
+ uint64_t align = bs->bl.request_alignment;
uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov;
int tail = 0;
int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT_MAX);
- int alignment = MAX(bs->bl.pwrite_zeroes_alignment ?: 1,
- bs->request_alignment);
+ int alignment = MAX(bs->bl.pwrite_zeroes_alignment,
+ bs->bl.request_alignment);
assert(is_power_of_2(alignment));
head = offset & (alignment - 1);
uint8_t *buf = NULL;
QEMUIOVector local_qiov;
struct iovec iov;
- uint64_t align = bs->request_alignment;
+ uint64_t align = bs->bl.request_alignment;
unsigned int head_padding_bytes, tail_padding_bytes;
int ret = 0;
BdrvRequestFlags flags)
{
BdrvTrackedRequest req;
- uint64_t align = bs->request_alignment;
+ uint64_t align = bs->bl.request_alignment;
uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov;
IscsiLun *iscsilun = bs->opaque;
uint64_t max_xfer_len = iscsilun->use_16_for_rw ? 0xffffffff : 0xffff;
- bs->request_alignment = iscsilun->block_size;
+ bs->bl.request_alignment = iscsilun->block_size;
if (iscsilun->bl.max_xfer_len) {
max_xfer_len = MIN(max_xfer_len, iscsilun->bl.max_xfer_len);
if (bs->encrypted) {
/* Encryption works on a sector granularity */
- bs->request_alignment = BDRV_SECTOR_SIZE;
+ bs->bl.request_alignment = BDRV_SECTOR_SIZE;
}
bs->bl.pwrite_zeroes_alignment = s->cluster_size;
}
/* For SCSI generic devices the alignment is not really used.
With buffered I/O, we don't have any restrictions. */
if (bdrv_is_sg(bs) || !s->needs_alignment) {
- bs->request_alignment = 1;
+ bs->bl.request_alignment = 1;
s->buf_align = 1;
return;
}
- bs->request_alignment = 0;
+ bs->bl.request_alignment = 0;
s->buf_align = 0;
/* Let's try to use the logical blocksize for the alignment. */
- if (probe_logical_blocksize(fd, &bs->request_alignment) < 0) {
- bs->request_alignment = 0;
+ if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) {
+ bs->bl.request_alignment = 0;
}
#ifdef CONFIG_XFS
if (s->is_xfs) {
struct dioattr da;
if (xfsctl(NULL, fd, XFS_IOC_DIOINFO, &da) >= 0) {
- bs->request_alignment = da.d_miniosz;
+ bs->bl.request_alignment = da.d_miniosz;
/* The kernel returns wrong information for d_mem */
/* s->buf_align = da.d_mem; */
}
qemu_vfree(buf);
}
- if (!bs->request_alignment) {
+ if (!bs->bl.request_alignment) {
size_t align;
buf = qemu_memalign(s->buf_align, max_align);
for (align = 512; align <= max_align; align <<= 1) {
if (raw_is_io_aligned(fd, buf, align)) {
- bs->request_alignment = align;
+ bs->bl.request_alignment = align;
break;
}
}
qemu_vfree(buf);
}
- if (!s->buf_align || !bs->request_alignment) {
+ if (!s->buf_align || !bs->bl.request_alignment) {
error_setg(errp, "Could not find working O_DIRECT alignment. "
"Try cache.direct=off.");
}
BOOL status;
if (s->type == FTYPE_CD) {
- bs->request_alignment = 2048;
+ bs->bl.request_alignment = 2048;
return;
}
if (s->type == FTYPE_HARDDISK) {
status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, &dg, sizeof(dg), &count, NULL);
if (status != 0) {
- bs->request_alignment = dg.Geometry.BytesPerSector;
+ bs->bl.request_alignment = dg.Geometry.BytesPerSector;
return;
}
/* try GetDiskFreeSpace too */
GetDiskFreeSpace(s->drive_path, §orsPerCluster,
&dg.Geometry.BytesPerSector,
&freeClusters, &totalClusters);
- bs->request_alignment = dg.Geometry.BytesPerSector;
+ bs->bl.request_alignment = dg.Geometry.BytesPerSector;
}
}
static void vvfat_refresh_limits(BlockDriverState *bs, Error **errp)
{
- bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */
+ bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
}
static inline void vvfat_close_current_file(BDRVVVFATState *s)
};
typedef struct BlockLimits {
+ /* Alignment requirement, in bytes, for offset/length of I/O
+ * requests. Must be a power of 2 less than INT_MAX; defaults to
+ * 1 for drivers with modern byte interfaces, and to 512
+ * otherwise. */
+ uint32_t request_alignment;
+
/* maximum number of bytes that can be discarded at once (since it
* 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
/* optimal alignment for discard requests in bytes, must be power
* 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 */
+ * bl.request_alignment. May be 0 if bl.request_alignment is good
+ * enough */
uint32_t pdiscard_alignment;
/* maximum number of bytes that can zeroized at once (since it is
/* optimal alignment for write zeroes requests in bytes, must be
* power of 2, less than max_pwrite_zeroes if that is set, and
- * multiple of bs->request_alignment. May be 0 if
- * bs->request_alignment is good enough */
+ * multiple of bl.request_alignment. May be 0 if
+ * bl.request_alignment is good enough */
uint32_t pwrite_zeroes_alignment;
/* optimal transfer length in bytes (must be power of 2, and
- * multiple of bs->request_alignment), or 0 if no preferred size */
+ * multiple of bl.request_alignment), or 0 if no preferred size */
uint32_t opt_transfer;
/* maximal transfer length in bytes (need not be power of 2, but
* For now, anything larger than INT_MAX is clamped down. */
uint32_t max_transfer;
- /* memory alignment so that no bounce buffer is needed */
+ /* memory alignment, in bytes so that no bounce buffer is needed */
size_t min_mem_alignment;
- /* memory alignment for bounce buffer */
+ /* memory alignment, in bytes, for bounce buffer */
size_t opt_mem_alignment;
/* maximum number of iovec elements */
/* I/O Limits */
BlockLimits bl;
- /* Alignment requirement for offset/length of I/O requests */
- unsigned int request_alignment;
/* Flags honored during pwrite (so far: BDRV_REQ_FUA) */
unsigned int supported_write_flags;
/* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA,