|
@@ -167,6 +167,7 @@ typedef struct BDRVRawState {
|
|
int page_cache_inconsistent; /* errno from fdatasync failure */
|
|
int page_cache_inconsistent; /* errno from fdatasync failure */
|
|
bool has_fallocate;
|
|
bool has_fallocate;
|
|
bool needs_alignment;
|
|
bool needs_alignment;
|
|
|
|
+ bool force_alignment;
|
|
bool drop_cache;
|
|
bool drop_cache;
|
|
bool check_cache_dropped;
|
|
bool check_cache_dropped;
|
|
struct {
|
|
struct {
|
|
@@ -351,6 +352,17 @@ static bool dio_byte_aligned(int fd)
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static bool raw_needs_alignment(BlockDriverState *bs)
|
|
|
|
+{
|
|
|
|
+ BDRVRawState *s = bs->opaque;
|
|
|
|
+
|
|
|
|
+ if ((bs->open_flags & BDRV_O_NOCACHE) != 0 && !dio_byte_aligned(s->fd)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return s->force_alignment;
|
|
|
|
+}
|
|
|
|
+
|
|
/* Check if read is allowed with given memory buffer and length.
|
|
/* Check if read is allowed with given memory buffer and length.
|
|
*
|
|
*
|
|
* This function is used to check O_DIRECT memory buffer and request alignment.
|
|
* This function is used to check O_DIRECT memory buffer and request alignment.
|
|
@@ -728,9 +740,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
|
|
|
|
|
s->has_discard = true;
|
|
s->has_discard = true;
|
|
s->has_write_zeroes = true;
|
|
s->has_write_zeroes = true;
|
|
- if ((bs->open_flags & BDRV_O_NOCACHE) != 0 && !dio_byte_aligned(s->fd)) {
|
|
|
|
- s->needs_alignment = true;
|
|
|
|
- }
|
|
|
|
|
|
|
|
if (fstat(s->fd, &st) < 0) {
|
|
if (fstat(s->fd, &st) < 0) {
|
|
ret = -errno;
|
|
ret = -errno;
|
|
@@ -784,9 +793,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
|
* so QEMU makes sure all IO operations on the device are aligned
|
|
* so QEMU makes sure all IO operations on the device are aligned
|
|
* to sector size, or else FreeBSD will reject them with EINVAL.
|
|
* to sector size, or else FreeBSD will reject them with EINVAL.
|
|
*/
|
|
*/
|
|
- s->needs_alignment = true;
|
|
|
|
|
|
+ s->force_alignment = true;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
+ s->needs_alignment = raw_needs_alignment(bs);
|
|
|
|
|
|
#ifdef CONFIG_XFS
|
|
#ifdef CONFIG_XFS
|
|
if (platform_test_xfs_fd(s->fd)) {
|
|
if (platform_test_xfs_fd(s->fd)) {
|
|
@@ -1251,7 +1261,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
|
|
BDRVRawState *s = bs->opaque;
|
|
BDRVRawState *s = bs->opaque;
|
|
struct stat st;
|
|
struct stat st;
|
|
|
|
|
|
|
|
+ s->needs_alignment = raw_needs_alignment(bs);
|
|
raw_probe_alignment(bs, s->fd, errp);
|
|
raw_probe_alignment(bs, s->fd, errp);
|
|
|
|
+
|
|
bs->bl.min_mem_alignment = s->buf_align;
|
|
bs->bl.min_mem_alignment = s->buf_align;
|
|
bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
|
|
bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
|
|
|
|
|