1 | The following changes since commit 508ba0f7e2092d3ca56e3f75e894d52d8b94818e: | 1 | The following changes since commit 7208429223963c405c62fa2611398f1aa8033593: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20171109' into staging (2017-11-13 11:41:47 +0000) | 3 | Merge tag 'mem-2022-10-28' of https://github.com/davidhildenbrand/qemu into staging (2022-10-30 18:31:59 -0400) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 0761562687e0d8135310a94b1d3e08376387c027: | 9 | for you to fetch changes up to 6c32fc0df9cd901add75618c831fb26a9eb742cb: |
10 | 10 | ||
11 | qemu-iotests: Test I/O limits with removable media (2017-11-13 15:46:26 +0000) | 11 | block/blkio: Make driver nvme-io_uring take a "path" instead of a "filename" (2022-10-31 14:35:14 -0400) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | The following disk I/O throttling fixes solve recent bugs. | 16 | Note that we're still discussing "block/blkio: Make driver nvme-io_uring take a |
17 | "path" instead of a "filename"". I have sent the pull request now so everything | ||
18 | is ready for the soft freeze tomorrow if we decide to go ahead with the patch. | ||
17 | 19 | ||
18 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
19 | 21 | ||
20 | Alberto Garcia (3): | 22 | Alberto Faria (3): |
21 | block: Check for inserted BlockDriverState in blk_io_limits_disable() | 23 | block/blkio: Add virtio-blk-vfio-pci BlockDriver |
22 | block: Leave valid throttle timers when removing a BDS from a backend | 24 | block/blkio: Tolerate device size changes |
23 | qemu-iotests: Test I/O limits with removable media | 25 | block/blkio: Make driver nvme-io_uring take a "path" instead of a |
26 | "filename" | ||
24 | 27 | ||
25 | Stefan Hajnoczi (1): | 28 | qapi/block-core.json | 22 +++++++++++++++++++-- |
26 | throttle-groups: drain before detaching ThrottleState | 29 | block/blkio.c | 47 ++++++++++++++++++++++++++++++++++++++++---- |
27 | 30 | 2 files changed, 63 insertions(+), 6 deletions(-) | |
28 | Zhengui (1): | ||
29 | block: all I/O should be completed before removing throttle timers. | ||
30 | |||
31 | block/block-backend.c | 36 ++++++++++++++++++--------- | ||
32 | block/throttle-groups.c | 6 +++++ | ||
33 | tests/qemu-iotests/093 | 62 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
34 | tests/qemu-iotests/093.out | 4 +-- | ||
35 | 4 files changed, 94 insertions(+), 14 deletions(-) | ||
36 | 31 | ||
37 | -- | 32 | -- |
38 | 2.13.6 | 33 | 2.38.1 |
39 | |||
40 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhengui <lizhengui@huawei.com> | ||
2 | 1 | ||
3 | In blk_remove_bs, all I/O should be completed before removing throttle | ||
4 | timers. If there has inflight I/O, removing throttle timers here will | ||
5 | cause the inflight I/O never return. | ||
6 | This patch add bdrv_drained_begin before throttle_timers_detach_aio_context | ||
7 | to let all I/O completed before removing throttle timers. | ||
8 | |||
9 | [Moved declaration of bs as suggested by Alberto Garcia | ||
10 | <berto@igalia.com>. | ||
11 | --Stefan] | ||
12 | |||
13 | Signed-off-by: Zhengui <lizhengui@huawei.com> | ||
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
16 | Message-id: 1508564040-120700-1-git-send-email-lizhengui@huawei.com | ||
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
18 | --- | ||
19 | block/block-backend.c | 4 ++++ | ||
20 | 1 file changed, 4 insertions(+) | ||
21 | |||
22 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block/block-backend.c | ||
25 | +++ b/block/block-backend.c | ||
26 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_by_public(BlockBackendPublic *public) | ||
27 | */ | ||
28 | void blk_remove_bs(BlockBackend *blk) | ||
29 | { | ||
30 | + BlockDriverState *bs; | ||
31 | ThrottleTimers *tt; | ||
32 | |||
33 | notifier_list_notify(&blk->remove_bs_notifiers, blk); | ||
34 | if (blk->public.throttle_group_member.throttle_state) { | ||
35 | tt = &blk->public.throttle_group_member.throttle_timers; | ||
36 | + bs = blk_bs(blk); | ||
37 | + bdrv_drained_begin(bs); | ||
38 | throttle_timers_detach_aio_context(tt); | ||
39 | + bdrv_drained_end(bs); | ||
40 | } | ||
41 | |||
42 | blk_update_root_state(blk); | ||
43 | -- | ||
44 | 2.13.6 | ||
45 | |||
46 | diff view generated by jsdifflib |
1 | I/O requests hang after stop/cont commands at least since QEMU 2.10.0 | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | with -drive iops=100: | ||
3 | 2 | ||
4 | (guest)$ dd if=/dev/zero of=/dev/vdb oflag=direct count=1000 | 3 | libblkio 1.1.0 [1] introduces a virtio-blk-vfio-pci driver, which |
5 | (qemu) stop | 4 | accesses a virtio-blk PCI device using VFIO. Add a corresponding |
6 | (qemu) cont | 5 | BlockDriver. |
7 | ...I/O is stuck... | ||
8 | 6 | ||
9 | This happens because blk_set_aio_context() detaches the ThrottleState | 7 | [1] https://gitlab.com/libblkio/libblkio/-/tree/v1.1.0 |
10 | while requests may still be in flight: | ||
11 | 8 | ||
12 | if (tgm->throttle_state) { | 9 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
13 | throttle_group_detach_aio_context(tgm); | 10 | Message-id: 20221028131635.710267-1-afaria@redhat.com |
14 | throttle_group_attach_aio_context(tgm, new_context); | ||
15 | } | ||
16 | |||
17 | This patch encloses the detach/attach calls in a drained region so no | ||
18 | I/O request is left hanging. Also add assertions so we don't make the | ||
19 | same mistake again in the future. | ||
20 | |||
21 | Reported-by: Yongxue Hong <yhong@redhat.com> | ||
22 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
23 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
24 | Message-id: 20171110151934.16883-1-stefanha@redhat.com | ||
25 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
26 | --- | 12 | --- |
27 | block/block-backend.c | 2 ++ | 13 | qapi/block-core.json | 18 ++++++++++++++++++ |
28 | block/throttle-groups.c | 6 ++++++ | 14 | block/blkio.c | 8 ++++++++ |
29 | 2 files changed, 8 insertions(+) | 15 | 2 files changed, 26 insertions(+) |
30 | 16 | ||
31 | diff --git a/block/block-backend.c b/block/block-backend.c | 17 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
32 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/block/block-backend.c | 19 | --- a/qapi/block-core.json |
34 | +++ b/block/block-backend.c | 20 | +++ b/qapi/block-core.json |
35 | @@ -XXX,XX +XXX,XX @@ void blk_set_aio_context(BlockBackend *blk, AioContext *new_context) | 21 | @@ -XXX,XX +XXX,XX @@ |
36 | 22 | 'raw', 'rbd', | |
37 | if (bs) { | 23 | { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, |
38 | if (tgm->throttle_state) { | 24 | 'ssh', 'throttle', 'vdi', 'vhdx', |
39 | + bdrv_drained_begin(bs); | 25 | + { 'name': 'virtio-blk-vfio-pci', 'if': 'CONFIG_BLKIO' }, |
40 | throttle_group_detach_aio_context(tgm); | 26 | { 'name': 'virtio-blk-vhost-user', 'if': 'CONFIG_BLKIO' }, |
41 | throttle_group_attach_aio_context(tgm, new_context); | 27 | { 'name': 'virtio-blk-vhost-vdpa', 'if': 'CONFIG_BLKIO' }, |
42 | + bdrv_drained_end(bs); | 28 | 'vmdk', 'vpc', 'vvfat' ] } |
43 | } | 29 | @@ -XXX,XX +XXX,XX @@ |
44 | bdrv_set_aio_context(bs, new_context); | 30 | 'data': { 'filename': 'str' }, |
45 | } | 31 | 'if': 'CONFIG_BLKIO' } |
46 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | 32 | |
33 | +## | ||
34 | +# @BlockdevOptionsVirtioBlkVfioPci: | ||
35 | +# | ||
36 | +# Driver specific block device options for the virtio-blk-vfio-pci backend. | ||
37 | +# | ||
38 | +# @path: path to the PCI device's sysfs directory (e.g. | ||
39 | +# /sys/bus/pci/devices/0000:00:01.0). | ||
40 | +# | ||
41 | +# Since: 7.2 | ||
42 | +## | ||
43 | +{ 'struct': 'BlockdevOptionsVirtioBlkVfioPci', | ||
44 | + 'data': { 'path': 'str' }, | ||
45 | + 'if': 'CONFIG_BLKIO' } | ||
46 | + | ||
47 | ## | ||
48 | # @BlockdevOptionsVirtioBlkVhostUser: | ||
49 | # | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | 'throttle': 'BlockdevOptionsThrottle', | ||
52 | 'vdi': 'BlockdevOptionsGenericFormat', | ||
53 | 'vhdx': 'BlockdevOptionsGenericFormat', | ||
54 | + 'virtio-blk-vfio-pci': | ||
55 | + { 'type': 'BlockdevOptionsVirtioBlkVfioPci', | ||
56 | + 'if': 'CONFIG_BLKIO' }, | ||
57 | 'virtio-blk-vhost-user': | ||
58 | { 'type': 'BlockdevOptionsVirtioBlkVhostUser', | ||
59 | 'if': 'CONFIG_BLKIO' }, | ||
60 | diff --git a/block/blkio.c b/block/blkio.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | 61 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/block/throttle-groups.c | 62 | --- a/block/blkio.c |
49 | +++ b/block/throttle-groups.c | 63 | +++ b/block/blkio.c |
50 | @@ -XXX,XX +XXX,XX @@ void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, | 64 | @@ -XXX,XX +XXX,XX @@ |
51 | void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) | 65 | */ |
66 | #define DRIVER_IO_URING "io_uring" | ||
67 | #define DRIVER_NVME_IO_URING "nvme-io_uring" | ||
68 | +#define DRIVER_VIRTIO_BLK_VFIO_PCI "virtio-blk-vfio-pci" | ||
69 | #define DRIVER_VIRTIO_BLK_VHOST_USER "virtio-blk-vhost-user" | ||
70 | #define DRIVER_VIRTIO_BLK_VHOST_VDPA "virtio-blk-vhost-vdpa" | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
73 | ret = blkio_io_uring_open(bs, options, flags, errp); | ||
74 | } else if (strcmp(blkio_driver, DRIVER_NVME_IO_URING) == 0) { | ||
75 | ret = blkio_nvme_io_uring(bs, options, flags, errp); | ||
76 | + } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VFIO_PCI) == 0) { | ||
77 | + ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
78 | } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_USER) == 0) { | ||
79 | ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
80 | } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_VDPA) == 0) { | ||
81 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nvme_io_uring = BLKIO_DRIVER( | ||
82 | .bdrv_needs_filename = true, | ||
83 | ); | ||
84 | |||
85 | +static BlockDriver bdrv_virtio_blk_vfio_pci = BLKIO_DRIVER( | ||
86 | + DRIVER_VIRTIO_BLK_VFIO_PCI | ||
87 | +); | ||
88 | + | ||
89 | static BlockDriver bdrv_virtio_blk_vhost_user = BLKIO_DRIVER( | ||
90 | DRIVER_VIRTIO_BLK_VHOST_USER | ||
91 | ); | ||
92 | @@ -XXX,XX +XXX,XX @@ static void bdrv_blkio_init(void) | ||
52 | { | 93 | { |
53 | ThrottleTimers *tt = &tgm->throttle_timers; | 94 | bdrv_register(&bdrv_io_uring); |
54 | + | 95 | bdrv_register(&bdrv_nvme_io_uring); |
55 | + /* Requests must have been drained */ | 96 | + bdrv_register(&bdrv_virtio_blk_vfio_pci); |
56 | + assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0); | 97 | bdrv_register(&bdrv_virtio_blk_vhost_user); |
57 | + assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); | 98 | bdrv_register(&bdrv_virtio_blk_vhost_vdpa); |
58 | + assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); | ||
59 | + | ||
60 | throttle_timers_detach_aio_context(tt); | ||
61 | tgm->aio_context = NULL; | ||
62 | } | 99 | } |
63 | -- | 100 | -- |
64 | 2.13.6 | 101 | 2.38.1 |
65 | |||
66 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Alberto Garcia <berto@igalia.com> | ||
2 | 1 | ||
3 | When you set I/O limits using block_set_io_throttle or the command | ||
4 | line throttling.* options they are kept in the BlockBackend regardless | ||
5 | of whether a BlockDriverState is attached to the backend or not. | ||
6 | |||
7 | Therefore when removing the limits using blk_io_limits_disable() we | ||
8 | need to check if there's a BDS before attempting to drain it, else it | ||
9 | will crash QEMU. This can be reproduced very easily using HMP: | ||
10 | |||
11 | (qemu) drive_add 0 if=none,throttling.iops-total=5000 | ||
12 | (qemu) drive_del none0 | ||
13 | |||
14 | Reported-by: sochin jiang <sochin.jiang@huawei.com> | ||
15 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
16 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
17 | Message-id: 0d3a67ce8d948bb33e08672564714dcfb76a3d8c.1510339534.git.berto@igalia.com | ||
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | --- | ||
20 | block/block-backend.c | 14 ++++++++++---- | ||
21 | 1 file changed, 10 insertions(+), 4 deletions(-) | ||
22 | |||
23 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/block/block-backend.c | ||
26 | +++ b/block/block-backend.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg) | ||
28 | |||
29 | void blk_io_limits_disable(BlockBackend *blk) | ||
30 | { | ||
31 | - assert(blk->public.throttle_group_member.throttle_state); | ||
32 | - bdrv_drained_begin(blk_bs(blk)); | ||
33 | - throttle_group_unregister_tgm(&blk->public.throttle_group_member); | ||
34 | - bdrv_drained_end(blk_bs(blk)); | ||
35 | + BlockDriverState *bs = blk_bs(blk); | ||
36 | + ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | ||
37 | + assert(tgm->throttle_state); | ||
38 | + if (bs) { | ||
39 | + bdrv_drained_begin(bs); | ||
40 | + } | ||
41 | + throttle_group_unregister_tgm(tgm); | ||
42 | + if (bs) { | ||
43 | + bdrv_drained_end(bs); | ||
44 | + } | ||
45 | } | ||
46 | |||
47 | /* should be called before blk_set_io_limits if a limit is set */ | ||
48 | -- | ||
49 | 2.13.6 | ||
50 | |||
51 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This test hotplugs a CD drive to a VM and checks that I/O limits can | 3 | Some libblkio drivers may be able to work with regular files (e.g., |
4 | be set only when the drive has media inserted and that they are kept | 4 | io_uring) or otherwise resizable devices. Conservatively set |
5 | when the media is replaced. | 5 | BlockDriver::has_variable_length to true to ensure bdrv_nb_sectors() |
6 | always gives up-to-date results. | ||
6 | 7 | ||
7 | This also tests the removal of a device with valid I/O limits set but | 8 | Also implement BlockDriver::bdrv_co_truncate for the case where no |
8 | no media inserted. This involves deleting and disabling the limits | 9 | preallocation is needed and the device already has a size compatible |
9 | of a BlockBackend without BlockDriverState, a scenario that has been | 10 | with what was requested. |
10 | crashing until the fixes from the last couple of patches. | ||
11 | 11 | ||
12 | [Python PEP8 fixup: "Don't use spaces are the = sign when used to | 12 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
13 | indicate a keyword argument or a default parameter value" | 13 | Message-id: 20221029122031.975273-1-afaria@redhat.com |
14 | --Stefan] | ||
15 | |||
16 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
17 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
18 | Message-id: 071eb397118ed207c5a7f01d58766e415ee18d6a.1510339534.git.berto@igalia.com | ||
19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
20 | --- | 15 | --- |
21 | tests/qemu-iotests/093 | 62 ++++++++++++++++++++++++++++++++++++++++++++++ | 16 | block/blkio.c | 27 +++++++++++++++++++++++++++ |
22 | tests/qemu-iotests/093.out | 4 +-- | 17 | 1 file changed, 27 insertions(+) |
23 | 2 files changed, 64 insertions(+), 2 deletions(-) | ||
24 | 18 | ||
25 | diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093 | 19 | diff --git a/block/blkio.c b/block/blkio.c |
26 | index XXXXXXX..XXXXXXX 100755 | 20 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/tests/qemu-iotests/093 | 21 | --- a/block/blkio.c |
28 | +++ b/tests/qemu-iotests/093 | 22 | +++ b/block/blkio.c |
29 | @@ -XXX,XX +XXX,XX @@ class ThrottleTestGroupNames(iotests.QMPTestCase): | 23 | @@ -XXX,XX +XXX,XX @@ static int64_t blkio_getlength(BlockDriverState *bs) |
30 | groupname = "group%d" % i | 24 | return capacity; |
31 | self.verify_name(devname, groupname) | 25 | } |
32 | 26 | ||
33 | +class ThrottleTestRemovableMedia(iotests.QMPTestCase): | 27 | +static int coroutine_fn blkio_truncate(BlockDriverState *bs, int64_t offset, |
34 | + def setUp(self): | 28 | + bool exact, PreallocMode prealloc, |
35 | + self.vm = iotests.VM() | 29 | + BdrvRequestFlags flags, Error **errp) |
36 | + if iotests.qemu_default_machine == 's390-ccw-virtio': | 30 | +{ |
37 | + self.vm.add_device("virtio-scsi-ccw,id=virtio-scsi") | 31 | + int64_t current_length; |
38 | + else: | ||
39 | + self.vm.add_device("virtio-scsi-pci,id=virtio-scsi") | ||
40 | + self.vm.launch() | ||
41 | + | 32 | + |
42 | + def tearDown(self): | 33 | + if (prealloc != PREALLOC_MODE_OFF) { |
43 | + self.vm.shutdown() | 34 | + error_setg(errp, "Unsupported preallocation mode '%s'", |
35 | + PreallocMode_str(prealloc)); | ||
36 | + return -ENOTSUP; | ||
37 | + } | ||
44 | + | 38 | + |
45 | + def test_removable_media(self): | 39 | + current_length = blkio_getlength(bs); |
46 | + # Add a couple of dummy nodes named cd0 and cd1 | ||
47 | + result = self.vm.qmp("blockdev-add", driver="null-aio", | ||
48 | + node_name="cd0") | ||
49 | + self.assert_qmp(result, 'return', {}) | ||
50 | + result = self.vm.qmp("blockdev-add", driver="null-aio", | ||
51 | + node_name="cd1") | ||
52 | + self.assert_qmp(result, 'return', {}) | ||
53 | + | 40 | + |
54 | + # Attach a CD drive with cd0 inserted | 41 | + if (offset > current_length) { |
55 | + result = self.vm.qmp("device_add", driver="scsi-cd", | 42 | + error_setg(errp, "Cannot grow device"); |
56 | + id="dev0", drive="cd0") | 43 | + return -EINVAL; |
57 | + self.assert_qmp(result, 'return', {}) | 44 | + } else if (exact && offset != current_length) { |
45 | + error_setg(errp, "Cannot resize device"); | ||
46 | + return -ENOTSUP; | ||
47 | + } | ||
58 | + | 48 | + |
59 | + # Set I/O limits | 49 | + return 0; |
60 | + args = { "id": "dev0", "iops": 100, "iops_rd": 0, "iops_wr": 0, | 50 | +} |
61 | + "bps": 50, "bps_rd": 0, "bps_wr": 0 } | ||
62 | + result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **args) | ||
63 | + self.assert_qmp(result, 'return', {}) | ||
64 | + | 51 | + |
65 | + # Check that the I/O limits have been set | 52 | static int blkio_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) |
66 | + result = self.vm.qmp("query-block") | 53 | { |
67 | + self.assert_qmp(result, 'return[0]/inserted/iops', 100) | 54 | return 0; |
68 | + self.assert_qmp(result, 'return[0]/inserted/bps', 50) | 55 | @@ -XXX,XX +XXX,XX @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp) |
69 | + | 56 | { \ |
70 | + # Now eject cd0 and insert cd1 | 57 | .format_name = name, \ |
71 | + result = self.vm.qmp("blockdev-open-tray", id='dev0') | 58 | .protocol_name = name, \ |
72 | + self.assert_qmp(result, 'return', {}) | 59 | + .has_variable_length = true, \ |
73 | + result = self.vm.qmp("x-blockdev-remove-medium", id='dev0') | 60 | .instance_size = sizeof(BDRVBlkioState), \ |
74 | + self.assert_qmp(result, 'return', {}) | 61 | .bdrv_file_open = blkio_file_open, \ |
75 | + result = self.vm.qmp("x-blockdev-insert-medium", id='dev0', node_name='cd1') | 62 | .bdrv_close = blkio_close, \ |
76 | + self.assert_qmp(result, 'return', {}) | 63 | .bdrv_getlength = blkio_getlength, \ |
77 | + | 64 | + .bdrv_co_truncate = blkio_truncate, \ |
78 | + # Check that the I/O limits are still the same | 65 | .bdrv_get_info = blkio_get_info, \ |
79 | + result = self.vm.qmp("query-block") | 66 | .bdrv_attach_aio_context = blkio_attach_aio_context, \ |
80 | + self.assert_qmp(result, 'return[0]/inserted/iops', 100) | 67 | .bdrv_detach_aio_context = blkio_detach_aio_context, \ |
81 | + self.assert_qmp(result, 'return[0]/inserted/bps', 50) | ||
82 | + | ||
83 | + # Eject cd1 | ||
84 | + result = self.vm.qmp("x-blockdev-remove-medium", id='dev0') | ||
85 | + self.assert_qmp(result, 'return', {}) | ||
86 | + | ||
87 | + # Check that we can't set limits if the device has no medium | ||
88 | + result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **args) | ||
89 | + self.assert_qmp(result, 'error/class', 'GenericError') | ||
90 | + | ||
91 | + # Remove the CD drive | ||
92 | + result = self.vm.qmp("device_del", id='dev0') | ||
93 | + self.assert_qmp(result, 'return', {}) | ||
94 | + | ||
95 | |||
96 | if __name__ == '__main__': | ||
97 | iotests.main(supported_fmts=["raw"]) | ||
98 | diff --git a/tests/qemu-iotests/093.out b/tests/qemu-iotests/093.out | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/tests/qemu-iotests/093.out | ||
101 | +++ b/tests/qemu-iotests/093.out | ||
102 | @@ -XXX,XX +XXX,XX @@ | ||
103 | -....... | ||
104 | +........ | ||
105 | ---------------------------------------------------------------------- | ||
106 | -Ran 7 tests | ||
107 | +Ran 8 tests | ||
108 | |||
109 | OK | ||
110 | -- | 68 | -- |
111 | 2.13.6 | 69 | 2.38.1 |
112 | |||
113 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | If a BlockBackend has I/O limits set then its ThrottleGroupMember | 3 | The nvme-io_uring driver expects a character special file such as |
4 | structure uses the AioContext from its attached BlockDriverState. | 4 | /dev/ng0n1. Follow the convention of having a "filename" option when a |
5 | Those two contexts must be kept in sync manually. This is not | 5 | regular file is expected, and a "path" option otherwise. |
6 | ideal and will be fixed in the future by removing the throttling | ||
7 | configuration from the BlockBackend and storing it in an implicit | ||
8 | filter node instead, but for now we have to live with this. | ||
9 | 6 | ||
10 | When you remove the BlockDriverState from the backend then the | 7 | This makes io_uring the only libblkio-based driver with a "filename" |
11 | throttle timers are destroyed. If a new BlockDriverState is later | 8 | option, as it accepts a regular file (even though it can also take a |
12 | inserted then they are created again using the new AioContext. | 9 | block special file). |
13 | 10 | ||
14 | There are a couple of problems with this: | 11 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
15 | 12 | Message-id: 20221028233854.839933-1-afaria@redhat.com | |
16 | a) The code manipulates the timers directly, leaving the | ||
17 | ThrottleGroupMember.aio_context field in an inconsisent state. | ||
18 | |||
19 | b) If you remove the I/O limits (e.g by destroying the backend) | ||
20 | when the timers are gone then throttle_group_unregister_tgm() | ||
21 | will attempt to destroy them again, crashing QEMU. | ||
22 | |||
23 | While b) could be fixed easily by allowing the timers to be freed | ||
24 | twice, this would result in a situation in which we can no longer | ||
25 | guarantee that a valid ThrottleState has a valid AioContext and | ||
26 | timers. | ||
27 | |||
28 | This patch ensures that the timers and AioContext are always valid | ||
29 | when I/O limits are set, regardless of whether the BlockBackend has a | ||
30 | BlockDriverState inserted or not. | ||
31 | |||
32 | [Fixed "There'a" typo as suggested by Max Reitz <mreitz@redhat.com> | ||
33 | --Stefan] | ||
34 | |||
35 | Reported-by: sochin jiang <sochin.jiang@huawei.com> | ||
36 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
37 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
38 | Message-id: e089c66e7c20289b046d782cea4373b765c5bc1d.1510339534.git.berto@igalia.com | ||
39 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
40 | --- | 14 | --- |
41 | block/block-backend.c | 16 ++++++++-------- | 15 | qapi/block-core.json | 4 ++-- |
42 | 1 file changed, 8 insertions(+), 8 deletions(-) | 16 | block/blkio.c | 12 ++++++++---- |
17 | 2 files changed, 10 insertions(+), 6 deletions(-) | ||
43 | 18 | ||
44 | diff --git a/block/block-backend.c b/block/block-backend.c | 19 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
45 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/block/block-backend.c | 21 | --- a/qapi/block-core.json |
47 | +++ b/block/block-backend.c | 22 | +++ b/qapi/block-core.json |
48 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_by_public(BlockBackendPublic *public) | 23 | @@ -XXX,XX +XXX,XX @@ |
49 | */ | 24 | # |
50 | void blk_remove_bs(BlockBackend *blk) | 25 | # Driver specific block device options for the nvme-io_uring backend. |
26 | # | ||
27 | -# @filename: path to the image file | ||
28 | +# @path: path to the image file | ||
29 | # | ||
30 | # Since: 7.2 | ||
31 | ## | ||
32 | { 'struct': 'BlockdevOptionsNvmeIoUring', | ||
33 | - 'data': { 'filename': 'str' }, | ||
34 | + 'data': { 'path': 'str' }, | ||
35 | 'if': 'CONFIG_BLKIO' } | ||
36 | |||
37 | ## | ||
38 | diff --git a/block/blkio.c b/block/blkio.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/block/blkio.c | ||
41 | +++ b/block/blkio.c | ||
42 | @@ -XXX,XX +XXX,XX @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, | ||
43 | static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, | ||
44 | Error **errp) | ||
51 | { | 45 | { |
52 | + ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | 46 | - const char *filename = qdict_get_str(options, "filename"); |
53 | BlockDriverState *bs; | 47 | + const char *path = qdict_get_try_str(options, "path"); |
54 | - ThrottleTimers *tt; | 48 | BDRVBlkioState *s = bs->opaque; |
55 | 49 | int ret; | |
56 | notifier_list_notify(&blk->remove_bs_notifiers, blk); | 50 | |
57 | - if (blk->public.throttle_group_member.throttle_state) { | 51 | - ret = blkio_set_str(s->blkio, "path", filename); |
58 | - tt = &blk->public.throttle_group_member.throttle_timers; | 52 | - qdict_del(options, "filename"); |
59 | + if (tgm->throttle_state) { | 53 | + if (!path) { |
60 | bs = blk_bs(blk); | 54 | + error_setg(errp, "missing 'path' option"); |
61 | bdrv_drained_begin(bs); | 55 | + return -EINVAL; |
62 | - throttle_timers_detach_aio_context(tt); | 56 | + } |
63 | + throttle_group_detach_aio_context(tgm); | 57 | + |
64 | + throttle_group_attach_aio_context(tgm, qemu_get_aio_context()); | 58 | + ret = blkio_set_str(s->blkio, "path", path); |
65 | bdrv_drained_end(bs); | 59 | + qdict_del(options, "path"); |
66 | } | 60 | if (ret < 0) { |
67 | 61 | error_setg_errno(errp, -ret, "failed to set path: %s", | |
68 | @@ -XXX,XX +XXX,XX @@ void blk_remove_bs(BlockBackend *blk) | 62 | blkio_get_error_msg()); |
69 | */ | 63 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_io_uring = BLKIO_DRIVER( |
70 | int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) | 64 | |
71 | { | 65 | static BlockDriver bdrv_nvme_io_uring = BLKIO_DRIVER( |
72 | + ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | 66 | DRIVER_NVME_IO_URING, |
73 | blk->root = bdrv_root_attach_child(bs, "root", &child_root, | 67 | - .bdrv_needs_filename = true, |
74 | blk->perm, blk->shared_perm, blk, errp); | 68 | ); |
75 | if (blk->root == NULL) { | 69 | |
76 | @@ -XXX,XX +XXX,XX @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) | 70 | static BlockDriver bdrv_virtio_blk_vfio_pci = BLKIO_DRIVER( |
77 | bdrv_ref(bs); | ||
78 | |||
79 | notifier_list_notify(&blk->insert_bs_notifiers, blk); | ||
80 | - if (blk->public.throttle_group_member.throttle_state) { | ||
81 | - throttle_timers_attach_aio_context( | ||
82 | - &blk->public.throttle_group_member.throttle_timers, | ||
83 | - bdrv_get_aio_context(bs)); | ||
84 | + if (tgm->throttle_state) { | ||
85 | + throttle_group_detach_aio_context(tgm); | ||
86 | + throttle_group_attach_aio_context(tgm, bdrv_get_aio_context(bs)); | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | -- | 71 | -- |
91 | 2.13.6 | 72 | 2.38.1 |
92 | |||
93 | diff view generated by jsdifflib |