1
The following changes since commit 560009f2c8b57b7cdd31a5693ea86ab369382f49:
1
The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81:
2
2
3
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2019-10-07 15:40:53 +0100)
3
Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://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 4d804b5305ffb4d5fa414c38d4f1bdfb987c8d0b:
9
for you to fetch changes up to 9f460c64e13897117f35ffb61f6f5e0102cabc70:
10
10
11
iotests/262: Switch source/dest VM launch order (2019-10-08 14:28:25 +0100)
11
block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Pull request
14
Pull request
15
15
16
This pull request also contains the two commits from the previous pull request
17
that was dropped due to a mingw compilation error. The compilation should now
18
be fixed.
19
20
----------------------------------------------------------------
16
----------------------------------------------------------------
21
17
22
Max Reitz (2):
18
Akihiko Odaki (3):
23
block: Skip COR for inactive nodes
19
block/file-posix: Optimize for macOS
24
iotests/262: Switch source/dest VM launch order
20
block: Add backend_defaults property
21
block/io: Merge discard request alignments
25
22
26
Sergio Lopez (1):
23
Stefan Hajnoczi (2):
27
virtio-blk: schedule virtio_notify_config to run on main context
24
util/async: add a human-readable name to BHs for debugging
25
util/async: print leaked BH name when AioContext finalizes
28
26
29
Vladimir Sementsov-Ogievskiy (1):
27
include/block/aio.h | 31 ++++++++++++++++++++++---
30
util/ioc.c: try to reassure Coverity about qemu_iovec_init_extended
28
include/hw/block/block.h | 3 +++
31
29
include/qemu/main-loop.h | 4 +++-
32
block/io.c | 41 +++++++++++++++++++++++++-------------
30
block/file-posix.c | 27 ++++++++++++++++++++--
33
hw/block/virtio-blk.c | 16 ++++++++++++++-
31
block/io.c | 2 ++
34
util/iov.c | 5 +++--
32
hw/block/block.c | 42 ++++++++++++++++++++++++++++++----
35
tests/qemu-iotests/262 | 12 +++++------
33
tests/unit/ptimer-test-stubs.c | 2 +-
36
tests/qemu-iotests/262.out | 6 +++---
34
util/async.c | 25 ++++++++++++++++----
37
5 files changed, 54 insertions(+), 26 deletions(-)
35
util/main-loop.c | 4 ++--
36
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++
37
10 files changed, 161 insertions(+), 17 deletions(-)
38
38
39
--
39
--
40
2.21.0
40
2.31.1
41
41
42
diff view generated by jsdifflib
New patch
1
It can be difficult to debug issues with BHs in production environments.
2
Although BHs can usually be identified by looking up their ->cb()
3
function pointer, this requires debug information for the program. It is
4
also not possible to print human-readable diagnostics about BHs because
5
they have no identifier.
1
6
7
This patch adds a name to each BH. The name is not unique per instance
8
but differentiates between cb() functions, which is usually enough. It's
9
done by changing aio_bh_new() and friends to macros that stringify cb.
10
11
The next patch will use the name field when reporting leaked BHs.
12
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Message-Id: <20210414200247.917496-2-stefanha@redhat.com>
16
---
17
include/block/aio.h | 31 ++++++++++++++++++++++++++++---
18
include/qemu/main-loop.h | 4 +++-
19
tests/unit/ptimer-test-stubs.c | 2 +-
20
util/async.c | 9 +++++++--
21
util/main-loop.c | 4 ++--
22
5 files changed, 41 insertions(+), 9 deletions(-)
23
24
diff --git a/include/block/aio.h b/include/block/aio.h
25
index XXXXXXX..XXXXXXX 100644
26
--- a/include/block/aio.h
27
+++ b/include/block/aio.h
28
@@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx);
29
/* Relinquish ownership of the AioContext. */
30
void aio_context_release(AioContext *ctx);
31
32
+/**
33
+ * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will
34
+ * run only once and as soon as possible.
35
+ *
36
+ * @name: A human-readable identifier for debugging purposes.
37
+ */
38
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
39
+ const char *name);
40
+
41
/**
42
* aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run
43
* only once and as soon as possible.
44
+ *
45
+ * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the
46
+ * name string.
47
*/
48
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
49
+#define aio_bh_schedule_oneshot(ctx, cb, opaque) \
50
+ aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb)))
51
52
/**
53
- * aio_bh_new: Allocate a new bottom half structure.
54
+ * aio_bh_new_full: Allocate a new bottom half structure.
55
*
56
* Bottom halves are lightweight callbacks whose invocation is guaranteed
57
* to be wait-free, thread-safe and signal-safe. The #QEMUBH structure
58
* is opaque and must be allocated prior to its use.
59
+ *
60
+ * @name: A human-readable identifier for debugging purposes.
61
*/
62
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
63
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
64
+ const char *name);
65
+
66
+/**
67
+ * aio_bh_new: Allocate a new bottom half structure
68
+ *
69
+ * A convenience wrapper for aio_bh_new_full() that uses the cb as the name
70
+ * string.
71
+ */
72
+#define aio_bh_new(ctx, cb, opaque) \
73
+ aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)))
74
75
/**
76
* aio_notify: Force processing of pending events.
77
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
78
index XXXXXXX..XXXXXXX 100644
79
--- a/include/qemu/main-loop.h
80
+++ b/include/qemu/main-loop.h
81
@@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
82
83
void qemu_fd_register(int fd);
84
85
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
86
+#define qemu_bh_new(cb, opaque) \
87
+ qemu_bh_new_full((cb), (opaque), (stringify(cb)))
88
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name);
89
void qemu_bh_schedule_idle(QEMUBH *bh);
90
91
enum {
92
diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c
93
index XXXXXXX..XXXXXXX 100644
94
--- a/tests/unit/ptimer-test-stubs.c
95
+++ b/tests/unit/ptimer-test-stubs.c
96
@@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
97
return deadline;
98
}
99
100
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
101
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
102
{
103
QEMUBH *bh = g_new(QEMUBH, 1);
104
105
diff --git a/util/async.c b/util/async.c
106
index XXXXXXX..XXXXXXX 100644
107
--- a/util/async.c
108
+++ b/util/async.c
109
@@ -XXX,XX +XXX,XX @@ enum {
110
111
struct QEMUBH {
112
AioContext *ctx;
113
+ const char *name;
114
QEMUBHFunc *cb;
115
void *opaque;
116
QSLIST_ENTRY(QEMUBH) next;
117
@@ -XXX,XX +XXX,XX @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags)
118
return bh;
119
}
120
121
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
122
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb,
123
+ void *opaque, const char *name)
124
{
125
QEMUBH *bh;
126
bh = g_new(QEMUBH, 1);
127
@@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
128
.ctx = ctx,
129
.cb = cb,
130
.opaque = opaque,
131
+ .name = name,
132
};
133
aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT);
134
}
135
136
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
137
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
138
+ const char *name)
139
{
140
QEMUBH *bh;
141
bh = g_new(QEMUBH, 1);
142
@@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
143
.ctx = ctx,
144
.cb = cb,
145
.opaque = opaque,
146
+ .name = name,
147
};
148
return bh;
149
}
150
diff --git a/util/main-loop.c b/util/main-loop.c
151
index XXXXXXX..XXXXXXX 100644
152
--- a/util/main-loop.c
153
+++ b/util/main-loop.c
154
@@ -XXX,XX +XXX,XX @@ void main_loop_wait(int nonblocking)
155
156
/* Functions to operate on the main QEMU AioContext. */
157
158
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
159
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
160
{
161
- return aio_bh_new(qemu_aio_context, cb, opaque);
162
+ return aio_bh_new_full(qemu_aio_context, cb, opaque, name);
163
}
164
165
/*
166
--
167
2.31.1
168
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
BHs must be deleted before the AioContext is finalized. If not, it's a
2
bug and probably indicates that some part of the program still expects
3
the BH to run in the future. That can lead to memory leaks, inconsistent
4
state, or just hangs.
2
5
3
Make it more obvious, that filling qiov corresponds to qiov allocation,
6
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize()
4
which in turn corresponds to total_niov calculation, based on mid_niov
7
is difficult to debug because the assertion failure contains no
5
(not mid_len). Still add an assertion to show that there should be no
8
information about the BH!
6
difference.
7
9
8
[Added mingw "error: 'mid_iov' may be used uninitialized in this
10
Use the QEMUBH name field added in the previous patch to show a useful
9
function" compiler error fix suggested by Vladimir.
11
error when a leaked BH is detected.
10
--Stefan]
11
12
12
Reported-by: Coverity (CID 1405302)
13
Suggested-by: Eric Ernst <eric.g.ernst@gmail.com>
13
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
14
Message-id: 20190910090310.14032-1-vsementsov@virtuozzo.com
15
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
17
Message-Id: <20190910090310.14032-1-vsementsov@virtuozzo.com>
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Message-Id: <20210414200247.917496-3-stefanha@redhat.com>
16
---
17
util/async.c | 16 ++++++++++++++--
18
1 file changed, 14 insertions(+), 2 deletions(-)
19
19
20
fixup! util/ioc.c: try to reassure Coverity about qemu_iovec_init_extended
20
diff --git a/util/async.c b/util/async.c
21
---
21
index XXXXXXX..XXXXXXX 100644
22
util/iov.c | 5 +++--
22
--- a/util/async.c
23
1 file changed, 3 insertions(+), 2 deletions(-)
23
+++ b/util/async.c
24
@@ -XXX,XX +XXX,XX @@ aio_ctx_finalize(GSource *source)
25
assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list));
26
27
while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) {
28
- /* qemu_bh_delete() must have been called on BHs in this AioContext */
29
- assert(flags & BH_DELETED);
30
+ /*
31
+ * qemu_bh_delete() must have been called on BHs in this AioContext. In
32
+ * many cases memory leaks, hangs, or inconsistent state occur when a
33
+ * BH is leaked because something still expects it to run.
34
+ *
35
+ * If you hit this, fix the lifecycle of the BH so that
36
+ * qemu_bh_delete() and any associated cleanup is called before the
37
+ * AioContext is finalized.
38
+ */
39
+ if (unlikely(!(flags & BH_DELETED))) {
40
+ fprintf(stderr, "%s: BH '%s' leaked, aborting...\n",
41
+ __func__, bh->name);
42
+ abort();
43
+ }
44
45
g_free(bh);
46
}
47
--
48
2.31.1
24
49
25
diff --git a/util/iov.c b/util/iov.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/util/iov.c
28
+++ b/util/iov.c
29
@@ -XXX,XX +XXX,XX @@ void qemu_iovec_init_extended(
30
{
31
size_t mid_head, mid_tail;
32
int total_niov, mid_niov = 0;
33
- struct iovec *p, *mid_iov;
34
+ struct iovec *p, *mid_iov = NULL;
35
36
if (mid_len) {
37
mid_iov = qiov_slice(mid_qiov, mid_offset, mid_len,
38
@@ -XXX,XX +XXX,XX @@ void qemu_iovec_init_extended(
39
p++;
40
}
41
42
- if (mid_len) {
43
+ assert(!mid_niov == !mid_len);
44
+ if (mid_niov) {
45
memcpy(p, mid_iov, mid_niov * sizeof(*p));
46
p[0].iov_base = (uint8_t *)p[0].iov_base + mid_head;
47
p[0].iov_len -= mid_head;
48
--
49
2.21.0
50
51
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
Launching the destination VM before the source VM gives us a regression
3
This commit introduces "punch hole" operation and optimizes transfer
4
test for HEAD^:
4
block size for macOS.
5
5
6
The guest device causes a read from the disk image through
6
Thanks to Konstantin Nazarov for detailed analysis of a flaw in an
7
guess_disk_lchs(). This will not work if the first sector (containing
7
old version of this change:
8
the partition table) is yet unallocated, we use COR, and the node is
8
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667
9
inactive.
10
9
11
By launching the source VM before the destination, however, the COR
10
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
12
filter on the source will allocate that area in the image shared between
11
Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com
13
both VMs, thus the problem will not become apparent.
14
15
Switching the launch order causes the sector to still be unallocated
16
when guess_disk_lchs() runs on the inactive node in the destination VM,
17
and thus we get our test case.
18
19
Signed-off-by: Max Reitz <mreitz@redhat.com>
20
Reviewed-by: Eric Blake <eblake@redhat.com>
21
Message-id: 20191001174827.11081-3-mreitz@redhat.com
22
Message-Id: <20191001174827.11081-3-mreitz@redhat.com>
23
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
24
---
13
---
25
tests/qemu-iotests/262 | 12 ++++++------
14
block/file-posix.c | 27 +++++++++++++++++++++++++--
26
tests/qemu-iotests/262.out | 6 +++---
15
1 file changed, 25 insertions(+), 2 deletions(-)
27
2 files changed, 9 insertions(+), 9 deletions(-)
28
16
29
diff --git a/tests/qemu-iotests/262 b/tests/qemu-iotests/262
17
diff --git a/block/file-posix.c b/block/file-posix.c
30
index XXXXXXX..XXXXXXX 100755
18
index XXXXXXX..XXXXXXX 100644
31
--- a/tests/qemu-iotests/262
19
--- a/block/file-posix.c
32
+++ b/tests/qemu-iotests/262
20
+++ b/block/file-posix.c
33
@@ -XXX,XX +XXX,XX @@ with iotests.FilePath('img') as img_path, \
21
@@ -XXX,XX +XXX,XX @@
34
22
#if defined(HAVE_HOST_BLOCK_DEVICE)
35
os.mkfifo(fifo)
23
#include <paths.h>
36
24
#include <sys/param.h>
37
- iotests.log('Launching source VM...')
25
+#include <sys/mount.h>
38
- add_opts(vm_a)
26
#include <IOKit/IOKitLib.h>
39
- vm_a.launch()
27
#include <IOKit/IOBSD.h>
40
-
28
#include <IOKit/storage/IOMediaBSDClient.h>
41
- vm_a.enable_migration_events('A')
29
@@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
42
-
30
return;
43
iotests.log('Launching destination VM...')
31
}
44
add_opts(vm_b)
32
45
vm_b.add_incoming("exec: cat '%s'" % (fifo))
33
+#if defined(__APPLE__) && (__MACH__)
46
@@ -XXX,XX +XXX,XX @@ with iotests.FilePath('img') as img_path, \
34
+ struct statfs buf;
47
48
vm_b.enable_migration_events('B')
49
50
+ iotests.log('Launching source VM...')
51
+ add_opts(vm_a)
52
+ vm_a.launch()
53
+
35
+
54
+ vm_a.enable_migration_events('A')
36
+ if (!fstatfs(s->fd, &buf)) {
37
+ bs->bl.opt_transfer = buf.f_iosize;
38
+ bs->bl.pdiscard_alignment = buf.f_bsize;
39
+ }
40
+#endif
55
+
41
+
56
iotests.log('Starting migration to B...')
42
if (bs->sg || S_ISBLK(st.st_mode)) {
57
iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo)))
43
int ret = hdev_get_max_hw_transfer(s->fd, &st);
58
with iotests.Timeout(3, 'Migration does not complete'):
44
59
diff --git a/tests/qemu-iotests/262.out b/tests/qemu-iotests/262.out
45
@@ -XXX,XX +XXX,XX @@ out:
60
index XXXXXXX..XXXXXXX 100644
46
}
61
--- a/tests/qemu-iotests/262.out
47
}
62
+++ b/tests/qemu-iotests/262.out
48
63
@@ -XXX,XX +XXX,XX @@
49
+#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD)
64
-Launching source VM...
50
static int translate_err(int err)
65
-Enabling migration QMP events on A...
51
{
66
-{"return": {}}
52
if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP ||
67
Launching destination VM...
53
@@ -XXX,XX +XXX,XX @@ static int translate_err(int err)
68
Enabling migration QMP events on B...
54
}
69
{"return": {}}
55
return err;
70
+Launching source VM...
56
}
71
+Enabling migration QMP events on A...
57
+#endif
72
+{"return": {}}
58
73
Starting migration to B...
59
#ifdef CONFIG_FALLOCATE
74
{"return": {}}
60
static int do_fallocate(int fd, int mode, off_t offset, off_t len)
75
{"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
61
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
62
}
63
} while (errno == EINTR);
64
65
- ret = -errno;
66
+ ret = translate_err(-errno);
67
#endif
68
} else {
69
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
70
ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
71
aiocb->aio_offset, aiocb->aio_nbytes);
72
+ ret = translate_err(-errno);
73
+#elif defined(__APPLE__) && (__MACH__)
74
+ fpunchhole_t fpunchhole;
75
+ fpunchhole.fp_flags = 0;
76
+ fpunchhole.reserved = 0;
77
+ fpunchhole.fp_offset = aiocb->aio_offset;
78
+ fpunchhole.fp_length = aiocb->aio_nbytes;
79
+ if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) == -1) {
80
+ ret = errno == ENODEV ? -ENOTSUP : -errno;
81
+ } else {
82
+ ret = 0;
83
+ }
84
#endif
85
}
86
87
- ret = translate_err(ret);
88
if (ret == -ENOTSUP) {
89
s->has_discard = false;
90
}
76
--
91
--
77
2.21.0
92
2.31.1
78
93
79
diff view generated by jsdifflib
1
From: Sergio Lopez <slp@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
virtio_notify_config() needs to acquire the global mutex, which isn't
3
backend_defaults property allow users to control if default block
4
allowed from an iothread, and may lead to a deadlock like this:
4
properties should be decided with backend information.
5
5
6
- main thead
6
If it is off, any backend information will be discarded, which is
7
* Has acquired: qemu_global_mutex.
7
suitable if you plan to perform live migration to a different disk backend.
8
* Is trying the acquire: iothread AioContext lock via
8
9
AIO_WAIT_WHILE (after aio_poll).
9
If it is on, a block device may utilize backend information more
10
10
aggressively.
11
- iothread
11
12
* Has acquired: AioContext lock.
12
By default, it is auto, which uses backend information for block
13
* Is trying to acquire: qemu_global_mutex (via
13
sizes and ignores the others, which is consistent with the older
14
virtio_notify_config->prepare_mmio_access).
14
versions.
15
15
16
If virtio_blk_resize() is called from an iothread, schedule
16
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
17
virtio_notify_config() to be run in the main context BH.
17
Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com
18
19
[Removed unnecessary newline as suggested by Kevin Wolf
20
<kwolf@redhat.com>.
21
--Stefan]
22
23
Signed-off-by: Sergio Lopez <slp@redhat.com>
24
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
25
Message-id: 20190916112411.21636-1-slp@redhat.com
26
Message-Id: <20190916112411.21636-1-slp@redhat.com>
27
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
28
---
19
---
29
hw/block/virtio-blk.c | 16 +++++++++++++++-
20
include/hw/block/block.h | 3 +++
30
1 file changed, 15 insertions(+), 1 deletion(-)
21
hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++----
31
22
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++
32
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
23
3 files changed, 79 insertions(+), 4 deletions(-)
24
25
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
33
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/block/virtio-blk.c
27
--- a/include/hw/block/block.h
35
+++ b/hw/block/virtio-blk.c
28
+++ b/include/hw/block/block.h
36
@@ -XXX,XX +XXX,XX @@
29
@@ -XXX,XX +XXX,XX @@
37
#include "qemu/iov.h"
30
38
#include "qemu/module.h"
31
typedef struct BlockConf {
39
#include "qemu/error-report.h"
32
BlockBackend *blk;
40
+#include "qemu/main-loop.h"
33
+ OnOffAuto backend_defaults;
41
#include "trace.h"
34
uint32_t physical_block_size;
42
#include "hw/block/block.h"
35
uint32_t logical_block_size;
43
#include "hw/qdev-properties.h"
36
uint32_t min_io_size;
44
@@ -XXX,XX +XXX,XX @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
37
@@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
45
return 0;
46
}
38
}
47
39
48
+static void virtio_resize_cb(void *opaque)
40
#define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
49
+{
41
+ DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \
50
+ VirtIODevice *vdev = opaque;
42
+ _conf.backend_defaults, ON_OFF_AUTO_AUTO), \
43
DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
44
_conf.logical_block_size), \
45
DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
46
diff --git a/hw/block/block.c b/hw/block/block.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/hw/block/block.c
49
+++ b/hw/block/block.c
50
@@ -XXX,XX +XXX,XX @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp)
51
{
52
BlockBackend *blk = conf->blk;
53
BlockSizes blocksizes;
54
- int backend_ret;
55
+ BlockDriverState *bs;
56
+ bool use_blocksizes;
57
+ bool use_bs;
51
+
58
+
52
+ assert(qemu_get_current_aio_context() == qemu_get_aio_context());
59
+ switch (conf->backend_defaults) {
53
+ virtio_notify_config(vdev);
60
+ case ON_OFF_AUTO_AUTO:
54
+}
61
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
62
+ use_bs = false;
63
+ break;
55
+
64
+
56
static void virtio_blk_resize(void *opaque)
65
+ case ON_OFF_AUTO_ON:
57
{
66
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
58
VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
67
+ bs = blk_bs(blk);
59
68
+ use_bs = bs;
60
- virtio_notify_config(vdev);
69
+ break;
61
+ /*
70
+
62
+ * virtio_notify_config() needs to acquire the global mutex,
71
+ case ON_OFF_AUTO_OFF:
63
+ * so it can't be called from an iothread. Instead, schedule
72
+ use_blocksizes = false;
64
+ * it to be run in the main context BH.
73
+ use_bs = false;
65
+ */
74
+ break;
66
+ aio_bh_schedule_oneshot(qemu_get_aio_context(), virtio_resize_cb, vdev);
75
+
67
}
76
+ default:
68
77
+ abort();
69
static const BlockDevOps virtio_block_ops = {
78
+ }
79
80
- backend_ret = blk_probe_blocksizes(blk, &blocksizes);
81
/* fill in detected values if they are not defined via qemu command line */
82
if (!conf->physical_block_size) {
83
- if (!backend_ret) {
84
+ if (use_blocksizes) {
85
conf->physical_block_size = blocksizes.phys;
86
} else {
87
conf->physical_block_size = BDRV_SECTOR_SIZE;
88
}
89
}
90
if (!conf->logical_block_size) {
91
- if (!backend_ret) {
92
+ if (use_blocksizes) {
93
conf->logical_block_size = blocksizes.log;
94
} else {
95
conf->logical_block_size = BDRV_SECTOR_SIZE;
96
}
97
}
98
+ if (use_bs) {
99
+ if (!conf->opt_io_size) {
100
+ conf->opt_io_size = bs->bl.opt_transfer;
101
+ }
102
+ if (conf->discard_granularity == -1) {
103
+ if (bs->bl.pdiscard_alignment) {
104
+ conf->discard_granularity = bs->bl.pdiscard_alignment;
105
+ } else if (bs->bl.request_alignment != 1) {
106
+ conf->discard_granularity = bs->bl.request_alignment;
107
+ }
108
+ }
109
+ }
110
111
if (conf->logical_block_size > conf->physical_block_size) {
112
error_setg(errp,
113
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
114
index XXXXXXX..XXXXXXX 100644
115
--- a/tests/qemu-iotests/172.out
116
+++ b/tests/qemu-iotests/172.out
117
@@ -XXX,XX +XXX,XX @@ Testing:
118
dev: floppy, id ""
119
unit = 0 (0x0)
120
drive = "floppy0"
121
+ backend_defaults = "auto"
122
logical_block_size = 512 (512 B)
123
physical_block_size = 512 (512 B)
124
min_io_size = 0 (0 B)
125
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2
126
dev: floppy, id ""
127
unit = 0 (0x0)
128
drive = "floppy0"
129
+ backend_defaults = "auto"
130
logical_block_size = 512 (512 B)
131
physical_block_size = 512 (512 B)
132
min_io_size = 0 (0 B)
133
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
134
dev: floppy, id ""
135
unit = 1 (0x1)
136
drive = "floppy1"
137
+ backend_defaults = "auto"
138
logical_block_size = 512 (512 B)
139
physical_block_size = 512 (512 B)
140
min_io_size = 0 (0 B)
141
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
142
dev: floppy, id ""
143
unit = 0 (0x0)
144
drive = "floppy0"
145
+ backend_defaults = "auto"
146
logical_block_size = 512 (512 B)
147
physical_block_size = 512 (512 B)
148
min_io_size = 0 (0 B)
149
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
150
dev: floppy, id ""
151
unit = 1 (0x1)
152
drive = "floppy1"
153
+ backend_defaults = "auto"
154
logical_block_size = 512 (512 B)
155
physical_block_size = 512 (512 B)
156
min_io_size = 0 (0 B)
157
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
158
dev: floppy, id ""
159
unit = 0 (0x0)
160
drive = "floppy0"
161
+ backend_defaults = "auto"
162
logical_block_size = 512 (512 B)
163
physical_block_size = 512 (512 B)
164
min_io_size = 0 (0 B)
165
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
166
dev: floppy, id ""
167
unit = 1 (0x1)
168
drive = "floppy1"
169
+ backend_defaults = "auto"
170
logical_block_size = 512 (512 B)
171
physical_block_size = 512 (512 B)
172
min_io_size = 0 (0 B)
173
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
174
dev: floppy, id ""
175
unit = 0 (0x0)
176
drive = "floppy0"
177
+ backend_defaults = "auto"
178
logical_block_size = 512 (512 B)
179
physical_block_size = 512 (512 B)
180
min_io_size = 0 (0 B)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2
182
dev: floppy, id ""
183
unit = 0 (0x0)
184
drive = "floppy0"
185
+ backend_defaults = "auto"
186
logical_block_size = 512 (512 B)
187
physical_block_size = 512 (512 B)
188
min_io_size = 0 (0 B)
189
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
190
dev: floppy, id ""
191
unit = 1 (0x1)
192
drive = "floppy1"
193
+ backend_defaults = "auto"
194
logical_block_size = 512 (512 B)
195
physical_block_size = 512 (512 B)
196
min_io_size = 0 (0 B)
197
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
198
dev: floppy, id ""
199
unit = 0 (0x0)
200
drive = "floppy0"
201
+ backend_defaults = "auto"
202
logical_block_size = 512 (512 B)
203
physical_block_size = 512 (512 B)
204
min_io_size = 0 (0 B)
205
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
206
dev: floppy, id ""
207
unit = 1 (0x1)
208
drive = "floppy1"
209
+ backend_defaults = "auto"
210
logical_block_size = 512 (512 B)
211
physical_block_size = 512 (512 B)
212
min_io_size = 0 (0 B)
213
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
214
dev: floppy, id ""
215
unit = 0 (0x0)
216
drive = "floppy0"
217
+ backend_defaults = "auto"
218
logical_block_size = 512 (512 B)
219
physical_block_size = 512 (512 B)
220
min_io_size = 0 (0 B)
221
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
222
dev: floppy, id ""
223
unit = 0 (0x0)
224
drive = "none0"
225
+ backend_defaults = "auto"
226
logical_block_size = 512 (512 B)
227
physical_block_size = 512 (512 B)
228
min_io_size = 0 (0 B)
229
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
230
dev: floppy, id ""
231
unit = 1 (0x1)
232
drive = "none0"
233
+ backend_defaults = "auto"
234
logical_block_size = 512 (512 B)
235
physical_block_size = 512 (512 B)
236
min_io_size = 0 (0 B)
237
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
238
dev: floppy, id ""
239
unit = 1 (0x1)
240
drive = "none1"
241
+ backend_defaults = "auto"
242
logical_block_size = 512 (512 B)
243
physical_block_size = 512 (512 B)
244
min_io_size = 0 (0 B)
245
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
246
dev: floppy, id ""
247
unit = 0 (0x0)
248
drive = "none0"
249
+ backend_defaults = "auto"
250
logical_block_size = 512 (512 B)
251
physical_block_size = 512 (512 B)
252
min_io_size = 0 (0 B)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
254
dev: floppy, id ""
255
unit = 1 (0x1)
256
drive = "none0"
257
+ backend_defaults = "auto"
258
logical_block_size = 512 (512 B)
259
physical_block_size = 512 (512 B)
260
min_io_size = 0 (0 B)
261
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
262
dev: floppy, id ""
263
unit = 0 (0x0)
264
drive = "floppy0"
265
+ backend_defaults = "auto"
266
logical_block_size = 512 (512 B)
267
physical_block_size = 512 (512 B)
268
min_io_size = 0 (0 B)
269
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
270
dev: floppy, id ""
271
unit = 1 (0x1)
272
drive = "none0"
273
+ backend_defaults = "auto"
274
logical_block_size = 512 (512 B)
275
physical_block_size = 512 (512 B)
276
min_io_size = 0 (0 B)
277
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
278
dev: floppy, id ""
279
unit = 0 (0x0)
280
drive = "floppy0"
281
+ backend_defaults = "auto"
282
logical_block_size = 512 (512 B)
283
physical_block_size = 512 (512 B)
284
min_io_size = 0 (0 B)
285
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
286
dev: floppy, id ""
287
unit = 0 (0x0)
288
drive = "none0"
289
+ backend_defaults = "auto"
290
logical_block_size = 512 (512 B)
291
physical_block_size = 512 (512 B)
292
min_io_size = 0 (0 B)
293
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
294
dev: floppy, id ""
295
unit = 1 (0x1)
296
drive = "floppy1"
297
+ backend_defaults = "auto"
298
logical_block_size = 512 (512 B)
299
physical_block_size = 512 (512 B)
300
min_io_size = 0 (0 B)
301
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
302
dev: floppy, id ""
303
unit = 0 (0x0)
304
drive = "none0"
305
+ backend_defaults = "auto"
306
logical_block_size = 512 (512 B)
307
physical_block_size = 512 (512 B)
308
min_io_size = 0 (0 B)
309
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
310
dev: floppy, id ""
311
unit = 1 (0x1)
312
drive = "floppy1"
313
+ backend_defaults = "auto"
314
logical_block_size = 512 (512 B)
315
physical_block_size = 512 (512 B)
316
min_io_size = 0 (0 B)
317
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
318
dev: floppy, id ""
319
unit = 1 (0x1)
320
drive = "none0"
321
+ backend_defaults = "auto"
322
logical_block_size = 512 (512 B)
323
physical_block_size = 512 (512 B)
324
min_io_size = 0 (0 B)
325
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
326
dev: floppy, id ""
327
unit = 0 (0x0)
328
drive = "floppy0"
329
+ backend_defaults = "auto"
330
logical_block_size = 512 (512 B)
331
physical_block_size = 512 (512 B)
332
min_io_size = 0 (0 B)
333
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
334
dev: floppy, id ""
335
unit = 1 (0x1)
336
drive = "none0"
337
+ backend_defaults = "auto"
338
logical_block_size = 512 (512 B)
339
physical_block_size = 512 (512 B)
340
min_io_size = 0 (0 B)
341
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
342
dev: floppy, id ""
343
unit = 0 (0x0)
344
drive = "floppy0"
345
+ backend_defaults = "auto"
346
logical_block_size = 512 (512 B)
347
physical_block_size = 512 (512 B)
348
min_io_size = 0 (0 B)
349
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device
350
dev: floppy, id ""
351
unit = 0 (0x0)
352
drive = "none0"
353
+ backend_defaults = "auto"
354
logical_block_size = 512 (512 B)
355
physical_block_size = 512 (512 B)
356
min_io_size = 0 (0 B)
357
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy
358
dev: floppy, id ""
359
unit = 0 (0x0)
360
drive = ""
361
+ backend_defaults = "auto"
362
logical_block_size = 512 (512 B)
363
physical_block_size = 512 (512 B)
364
min_io_size = 0 (0 B)
365
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=120
366
dev: floppy, id ""
367
unit = 0 (0x0)
368
drive = ""
369
+ backend_defaults = "auto"
370
logical_block_size = 512 (512 B)
371
physical_block_size = 512 (512 B)
372
min_io_size = 0 (0 B)
373
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=144
374
dev: floppy, id ""
375
unit = 0 (0x0)
376
drive = ""
377
+ backend_defaults = "auto"
378
logical_block_size = 512 (512 B)
379
physical_block_size = 512 (512 B)
380
min_io_size = 0 (0 B)
381
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=288
382
dev: floppy, id ""
383
unit = 0 (0x0)
384
drive = ""
385
+ backend_defaults = "auto"
386
logical_block_size = 512 (512 B)
387
physical_block_size = 512 (512 B)
388
min_io_size = 0 (0 B)
389
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
390
dev: floppy, id ""
391
unit = 0 (0x0)
392
drive = "none0"
393
+ backend_defaults = "auto"
394
logical_block_size = 512 (512 B)
395
physical_block_size = 512 (512 B)
396
min_io_size = 0 (0 B)
397
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
398
dev: floppy, id ""
399
unit = 0 (0x0)
400
drive = "none0"
401
+ backend_defaults = "auto"
402
logical_block_size = 512 (512 B)
403
physical_block_size = 512 (512 B)
404
min_io_size = 0 (0 B)
405
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical
406
dev: floppy, id ""
407
unit = 0 (0x0)
408
drive = "none0"
409
+ backend_defaults = "auto"
410
logical_block_size = 512 (512 B)
411
physical_block_size = 512 (512 B)
412
min_io_size = 0 (0 B)
413
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica
414
dev: floppy, id ""
415
unit = 0 (0x0)
416
drive = "none0"
417
+ backend_defaults = "auto"
418
logical_block_size = 512 (512 B)
419
physical_block_size = 512 (512 B)
420
min_io_size = 0 (0 B)
70
--
421
--
71
2.21.0
422
2.31.1
72
423
73
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
We must not write data to inactive nodes, and a COR is certainly
3
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
4
something we can simply not do without upsetting anyone. So skip COR
4
Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com
5
operations on inactive nodes.
6
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
Message-id: 20191001174827.11081-2-mreitz@redhat.com
10
Message-Id: <20191001174827.11081-2-mreitz@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
6
---
13
block/io.c | 41 +++++++++++++++++++++++++++--------------
7
block/io.c | 2 ++
14
1 file changed, 27 insertions(+), 14 deletions(-)
8
1 file changed, 2 insertions(+)
15
9
16
diff --git a/block/io.c b/block/io.c
10
diff --git a/block/io.c b/block/io.c
17
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
18
--- a/block/io.c
12
--- a/block/io.c
19
+++ b/block/io.c
13
+++ b/block/io.c
20
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
14
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
21
int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer,
15
22
BDRV_REQUEST_MAX_BYTES);
16
static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
23
unsigned int progress = 0;
17
{
24
+ bool skip_write;
18
+ dst->pdiscard_alignment = MAX(dst->pdiscard_alignment,
25
19
+ src->pdiscard_alignment);
26
if (!drv) {
20
dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer);
27
return -ENOMEDIUM;
21
dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer);
28
}
22
dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer,
29
30
+ /*
31
+ * Do not write anything when the BDS is inactive. That is not
32
+ * allowed, and it would not help.
33
+ */
34
+ skip_write = (bs->open_flags & BDRV_O_INACTIVE);
35
+
36
/* FIXME We cannot require callers to have write permissions when all they
37
* are doing is a read request. If we did things right, write permissions
38
* would be obtained anyway, but internally by the copy-on-read code. As
39
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
40
while (cluster_bytes) {
41
int64_t pnum;
42
43
- ret = bdrv_is_allocated(bs, cluster_offset,
44
- MIN(cluster_bytes, max_transfer), &pnum);
45
- if (ret < 0) {
46
- /* Safe to treat errors in querying allocation as if
47
- * unallocated; we'll probably fail again soon on the
48
- * read, but at least that will set a decent errno.
49
- */
50
+ if (skip_write) {
51
+ ret = 1; /* "already allocated", so nothing will be copied */
52
pnum = MIN(cluster_bytes, max_transfer);
53
- }
54
+ } else {
55
+ ret = bdrv_is_allocated(bs, cluster_offset,
56
+ MIN(cluster_bytes, max_transfer), &pnum);
57
+ if (ret < 0) {
58
+ /*
59
+ * Safe to treat errors in querying allocation as if
60
+ * unallocated; we'll probably fail again soon on the
61
+ * read, but at least that will set a decent errno.
62
+ */
63
+ pnum = MIN(cluster_bytes, max_transfer);
64
+ }
65
66
- /* Stop at EOF if the image ends in the middle of the cluster */
67
- if (ret == 0 && pnum == 0) {
68
- assert(progress >= bytes);
69
- break;
70
- }
71
+ /* Stop at EOF if the image ends in the middle of the cluster */
72
+ if (ret == 0 && pnum == 0) {
73
+ assert(progress >= bytes);
74
+ break;
75
+ }
76
77
- assert(skip_bytes < pnum);
78
+ assert(skip_bytes < pnum);
79
+ }
80
81
if (ret <= 0) {
82
QEMUIOVector local_qiov;
83
--
23
--
84
2.21.0
24
2.31.1
85
25
86
diff view generated by jsdifflib