Pull request
Please include these bug fixes in QEMU 8.1. Thanks! -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmTCzPUACgkQnKSrs4Gr c8g1DAf/fPUQ4zRsCn079pHIyK9TFo4COm23p4kiusxj8otfjt8LH1Zsc9pGWC2+ bl2RlnPID8JlyJFDRN7b/RCEhj45a83GtCmhDDmqVgy1eO5vwOKm2XyyWeD+pq/U Hf2QLPLZZ7tCD8Njpty+gB3Ux4zqthKGXSg8FpJ3w0tl4me2efLvjMa6jHMwtnHT aAbyQ3WMpT9w4XHLqRQDHzBqrTSY4od3nl9SrM/DQ2klLIcz8ECTEZVBY9B3pq6m QvAg24tfb0QvS14YnZv/PMCfOaVuE87M9G4f93pCynnMxMYze+XczL0sGhIAS9wp 03NgGlhGumOix6r2kHjlG6p3xywV8A== =jMf8 -----END PGP SIGNATURE----- Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging Pull request Please include these bug fixes in QEMU 8.1. Thanks! # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmTCzPUACgkQnKSrs4Gr # c8g1DAf/fPUQ4zRsCn079pHIyK9TFo4COm23p4kiusxj8otfjt8LH1Zsc9pGWC2+ # bl2RlnPID8JlyJFDRN7b/RCEhj45a83GtCmhDDmqVgy1eO5vwOKm2XyyWeD+pq/U # Hf2QLPLZZ7tCD8Njpty+gB3Ux4zqthKGXSg8FpJ3w0tl4me2efLvjMa6jHMwtnHT # aAbyQ3WMpT9w4XHLqRQDHzBqrTSY4od3nl9SrM/DQ2klLIcz8ECTEZVBY9B3pq6m # QvAg24tfb0QvS14YnZv/PMCfOaVuE87M9G4f93pCynnMxMYze+XczL0sGhIAS9wp # 03NgGlhGumOix6r2kHjlG6p3xywV8A== # =jMf8 # -----END PGP SIGNATURE----- # gpg: Signature made Thu 27 Jul 2023 01:00:53 PM PDT # gpg: using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full] # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" [full] * tag 'block-pull-request' of https://gitlab.com/stefanha/qemu: block/blkio: use blkio_set_int("fd") to check fd support block/blkio: fall back on using `path` when `fd` setting fails block/blkio: retry blkio_connect() if it fails using `fd` block/blkio: move blkio_connect() in the drivers functions block: Fix pad_request's request restriction block/file-posix: fix g_file_get_contents return path block/blkio: do not use open flags in qemu_open() block/blkio: enable the completion eventfd Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
f33c745764
138
block/blkio.c
138
block/blkio.c
@ -603,8 +603,8 @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
|
static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options,
|
||||||
Error **errp)
|
int flags, Error **errp)
|
||||||
{
|
{
|
||||||
const char *filename = qdict_get_str(options, "filename");
|
const char *filename = qdict_get_str(options, "filename");
|
||||||
BDRVBlkioState *s = bs->opaque;
|
BDRVBlkioState *s = bs->opaque;
|
||||||
@ -627,11 +627,18 @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = blkio_connect(s->blkio);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "blkio_connect failed: %s",
|
||||||
|
blkio_get_error_msg());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,
|
static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options,
|
||||||
Error **errp)
|
int flags, Error **errp)
|
||||||
{
|
{
|
||||||
const char *path = qdict_get_try_str(options, "path");
|
const char *path = qdict_get_try_str(options, "path");
|
||||||
BDRVBlkioState *s = bs->opaque;
|
BDRVBlkioState *s = bs->opaque;
|
||||||
@ -655,11 +662,18 @@ static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = blkio_connect(s->blkio);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "blkio_connect failed: %s",
|
||||||
|
blkio_get_error_msg());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blkio_virtio_blk_common_open(BlockDriverState *bs,
|
static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
|
||||||
QDict *options, int flags, Error **errp)
|
int flags, Error **errp)
|
||||||
{
|
{
|
||||||
const char *path = qdict_get_try_str(options, "path");
|
const char *path = qdict_get_try_str(options, "path");
|
||||||
BDRVBlkioState *s = bs->opaque;
|
BDRVBlkioState *s = bs->opaque;
|
||||||
@ -676,7 +690,7 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blkio_get_int(s->blkio, "fd", &fd) == 0) {
|
if (blkio_set_int(s->blkio, "fd", -1) == 0) {
|
||||||
fd_supported = true;
|
fd_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,27 +700,30 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
|
|||||||
* layer through the "/dev/fdset/N" special path.
|
* layer through the "/dev/fdset/N" special path.
|
||||||
*/
|
*/
|
||||||
if (fd_supported) {
|
if (fd_supported) {
|
||||||
int open_flags;
|
/*
|
||||||
|
* `path` can contain the path of a character device
|
||||||
if (flags & BDRV_O_RDWR) {
|
* (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or a unix socket.
|
||||||
open_flags = O_RDWR;
|
*
|
||||||
} else {
|
* So, we should always open it with O_RDWR flag, also if BDRV_O_RDWR
|
||||||
open_flags = O_RDONLY;
|
* is not set in the open flags, because the exchange of IOCTL commands
|
||||||
}
|
* for example will fail.
|
||||||
|
*
|
||||||
fd = qemu_open(path, open_flags, errp);
|
* In order to open the device read-only, we are using the `read-only`
|
||||||
|
* property of the libblkio driver in blkio_file_open().
|
||||||
|
*/
|
||||||
|
fd = qemu_open(path, O_RDWR, NULL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return -EINVAL;
|
fd_supported = false;
|
||||||
|
} else {
|
||||||
|
ret = blkio_set_int(s->blkio, "fd", fd);
|
||||||
|
if (ret < 0) {
|
||||||
|
fd_supported = false;
|
||||||
|
qemu_close(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = blkio_set_int(s->blkio, "fd", fd);
|
if (!fd_supported) {
|
||||||
if (ret < 0) {
|
|
||||||
error_setg_errno(errp, -ret, "failed to set fd: %s",
|
|
||||||
blkio_get_error_msg());
|
|
||||||
qemu_close(fd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = blkio_set_str(s->blkio, "path", path);
|
ret = blkio_set_str(s->blkio, "path", path);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, -ret, "failed to set path: %s",
|
error_setg_errno(errp, -ret, "failed to set path: %s",
|
||||||
@ -715,6 +732,42 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = blkio_connect(s->blkio);
|
||||||
|
/*
|
||||||
|
* If the libblkio driver doesn't support the `fd` property, blkio_connect()
|
||||||
|
* will fail with -EINVAL. So let's try calling blkio_connect() again by
|
||||||
|
* directly setting `path`.
|
||||||
|
*/
|
||||||
|
if (fd_supported && ret == -EINVAL) {
|
||||||
|
qemu_close(fd);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to clear the `fd` property we set previously by setting
|
||||||
|
* it to -1.
|
||||||
|
*/
|
||||||
|
ret = blkio_set_int(s->blkio, "fd", -1);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "failed to set fd: %s",
|
||||||
|
blkio_get_error_msg());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = blkio_set_str(s->blkio, "path", path);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "failed to set path: %s",
|
||||||
|
blkio_get_error_msg());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = blkio_connect(s->blkio);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "blkio_connect failed: %s",
|
||||||
|
blkio_get_error_msg());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
qdict_del(options, "path");
|
qdict_del(options, "path");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -734,24 +787,6 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(blkio_driver, "io_uring") == 0) {
|
|
||||||
ret = blkio_io_uring_open(bs, options, flags, errp);
|
|
||||||
} else if (strcmp(blkio_driver, "nvme-io_uring") == 0) {
|
|
||||||
ret = blkio_nvme_io_uring(bs, options, flags, errp);
|
|
||||||
} else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) {
|
|
||||||
ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
|
|
||||||
} else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) {
|
|
||||||
ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
|
|
||||||
} else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) {
|
|
||||||
ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
if (ret < 0) {
|
|
||||||
blkio_destroy(&s->blkio);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(flags & BDRV_O_RDWR)) {
|
if (!(flags & BDRV_O_RDWR)) {
|
||||||
ret = blkio_set_bool(s->blkio, "read-only", true);
|
ret = blkio_set_bool(s->blkio, "read-only", true);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -762,10 +797,20 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blkio_connect(s->blkio);
|
if (strcmp(blkio_driver, "io_uring") == 0) {
|
||||||
|
ret = blkio_io_uring_connect(bs, options, flags, errp);
|
||||||
|
} else if (strcmp(blkio_driver, "nvme-io_uring") == 0) {
|
||||||
|
ret = blkio_nvme_io_uring_connect(bs, options, flags, errp);
|
||||||
|
} else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) {
|
||||||
|
ret = blkio_virtio_blk_connect(bs, options, flags, errp);
|
||||||
|
} else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) {
|
||||||
|
ret = blkio_virtio_blk_connect(bs, options, flags, errp);
|
||||||
|
} else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) {
|
||||||
|
ret = blkio_virtio_blk_connect(bs, options, flags, errp);
|
||||||
|
} else {
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, -ret, "blkio_connect failed: %s",
|
|
||||||
blkio_get_error_msg());
|
|
||||||
blkio_destroy(&s->blkio);
|
blkio_destroy(&s->blkio);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -845,6 +890,7 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
QLIST_INIT(&s->bounce_bufs);
|
QLIST_INIT(&s->bounce_bufs);
|
||||||
s->blkioq = blkio_get_queue(s->blkio, 0);
|
s->blkioq = blkio_get_queue(s->blkio, 0);
|
||||||
s->completion_fd = blkioq_get_completion_fd(s->blkioq);
|
s->completion_fd = blkioq_get_completion_fd(s->blkioq);
|
||||||
|
blkioq_set_completion_fd_enabled(s->blkioq, true);
|
||||||
|
|
||||||
blkio_attach_aio_context(bs, bdrv_get_aio_context(bs));
|
blkio_attach_aio_context(bs, bdrv_get_aio_context(bs));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1232,7 +1232,6 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)
|
|||||||
static int get_sysfs_str_val(struct stat *st, const char *attribute,
|
static int get_sysfs_str_val(struct stat *st, const char *attribute,
|
||||||
char **val) {
|
char **val) {
|
||||||
g_autofree char *sysfspath = NULL;
|
g_autofree char *sysfspath = NULL;
|
||||||
int ret;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (!S_ISBLK(st->st_mode)) {
|
if (!S_ISBLK(st->st_mode)) {
|
||||||
@ -1242,8 +1241,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
|
|||||||
sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s",
|
sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s",
|
||||||
major(st->st_rdev), minor(st->st_rdev),
|
major(st->st_rdev), minor(st->st_rdev),
|
||||||
attribute);
|
attribute);
|
||||||
ret = g_file_get_contents(sysfspath, val, &len, NULL);
|
if (!g_file_get_contents(sysfspath, val, &len, NULL)) {
|
||||||
if (ret == -1) {
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,7 +1251,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
|
|||||||
if (*(p + len - 1) == '\n') {
|
if (*(p + len - 1) == '\n') {
|
||||||
*(p + len - 1) = '\0';
|
*(p + len - 1) = '\0';
|
||||||
}
|
}
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1710,7 +1710,11 @@ static int bdrv_pad_request(BlockDriverState *bs,
|
|||||||
int sliced_niov;
|
int sliced_niov;
|
||||||
size_t sliced_head, sliced_tail;
|
size_t sliced_head, sliced_tail;
|
||||||
|
|
||||||
bdrv_check_qiov_request(*offset, *bytes, *qiov, *qiov_offset, &error_abort);
|
/* Should have been checked by the caller already */
|
||||||
|
ret = bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) {
|
if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) {
|
||||||
if (padded) {
|
if (padded) {
|
||||||
@ -1723,7 +1727,7 @@ static int bdrv_pad_request(BlockDriverState *bs,
|
|||||||
&sliced_head, &sliced_tail,
|
&sliced_head, &sliced_tail,
|
||||||
&sliced_niov);
|
&sliced_niov);
|
||||||
|
|
||||||
/* Guaranteed by bdrv_check_qiov_request() */
|
/* Guaranteed by bdrv_check_request32() */
|
||||||
assert(*bytes <= SIZE_MAX);
|
assert(*bytes <= SIZE_MAX);
|
||||||
ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov,
|
ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov,
|
||||||
sliced_head, *bytes);
|
sliced_head, *bytes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user