1
The following changes since commit 00928a421d47f49691cace1207481b7aad31b1f1:
1
The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81:
2
2
3
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20180626' into staging (2018-06-26 18:23:49 +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
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 ed6e2161715c527330f936d44af4c547f25f687e:
9
for you to fetch changes up to 9f460c64e13897117f35ffb61f6f5e0102cabc70:
10
10
11
linux-aio: properly bubble up errors from initialization (2018-06-27 13:06:34 +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
* Gracefully handle Linux AIO init failure
17
18
----------------------------------------------------------------
16
----------------------------------------------------------------
19
17
20
Nishanth Aravamudan (1):
18
Akihiko Odaki (3):
21
linux-aio: properly bubble up errors from initialization
19
block/file-posix: Optimize for macOS
20
block: Add backend_defaults property
21
block/io: Merge discard request alignments
22
22
23
Stefan Hajnoczi (1):
23
Stefan Hajnoczi (2):
24
compiler: add a sizeof_field() macro
24
util/async: add a human-readable name to BHs for debugging
25
util/async: print leaked BH name when AioContext finalizes
25
26
26
include/block/aio.h | 3 +++
27
include/block/aio.h | 31 ++++++++++++++++++++++---
27
include/block/raw-aio.h | 2 +-
28
include/hw/block/block.h | 3 +++
28
include/hw/xen/io/ring.h | 2 +-
29
include/qemu/main-loop.h | 4 +++-
29
include/qemu/compiler.h | 2 ++
30
block/file-posix.c | 27 ++++++++++++++++++++--
30
accel/tcg/translate-all.c | 2 +-
31
block/io.c | 2 ++
31
block/file-posix.c | 33 ++++++++++++++++++++++++++++-----
32
hw/block/block.c | 42 ++++++++++++++++++++++++++++++----
32
block/linux-aio.c | 12 +++++++++---
33
tests/unit/ptimer-test-stubs.c | 2 +-
33
hw/display/xenfb.c | 4 ++--
34
util/async.c | 25 ++++++++++++++++----
34
hw/net/rocker/rocker_of_dpa.c | 2 +-
35
util/main-loop.c | 4 ++--
35
hw/net/virtio-net.c | 2 +-
36
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++
36
stubs/linux-aio.c | 2 +-
37
10 files changed, 161 insertions(+), 17 deletions(-)
37
target/i386/kvm.c | 2 +-
38
target/ppc/arch_dump.c | 10 +++++-----
39
target/s390x/arch_dump.c | 20 ++++++++++----------
40
util/async.c | 14 +++++++++++---
41
15 files changed, 77 insertions(+), 35 deletions(-)
42
38
43
--
39
--
44
2.17.1
40
2.31.1
45
41
46
diff view generated by jsdifflib
1
From: Nishanth Aravamudan <naravamudan@digitalocean.com>
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.
2
6
3
laio_init() can fail for a couple of reasons, which will lead to a NULL
7
This patch adds a name to each BH. The name is not unique per instance
4
pointer dereference in laio_attach_aio_context().
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.
5
10
6
To solve this, add a aio_setup_linux_aio() function which is called
11
The next patch will use the name field when reporting leaked BHs.
7
early in raw_open_common. If this fails, propagate the error up. The
8
signature of aio_get_linux_aio() was not modified, because it seems
9
preferable to return the actual errno from the possible failing
10
initialization calls.
11
12
12
Additionally, when the AioContext changes, we need to associate a
13
LinuxAioState with the new AioContext. Use the bdrv_attach_aio_context
14
callback and call the new aio_setup_linux_aio(), which will allocate a
15
new AioContext if needed, and return errors on failures. If it fails for
16
any reason, fallback to threaded AIO with an error message, as the
17
device is already in-use by the guest.
18
19
Add an assert that aio_get_linux_aio() cannot return NULL.
20
21
Signed-off-by: Nishanth Aravamudan <naravamudan@digitalocean.com>
22
Message-id: 20180622193700.6523-1-naravamudan@digitalocean.com
23
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
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>
24
---
16
---
25
include/block/aio.h | 3 +++
17
include/block/aio.h | 31 ++++++++++++++++++++++++++++---
26
include/block/raw-aio.h | 2 +-
18
include/qemu/main-loop.h | 4 +++-
27
block/file-posix.c | 33 ++++++++++++++++++++++++++++-----
19
tests/unit/ptimer-test-stubs.c | 2 +-
28
block/linux-aio.c | 12 +++++++++---
20
util/async.c | 9 +++++++--
29
stubs/linux-aio.c | 2 +-
21
util/main-loop.c | 4 ++--
30
util/async.c | 14 +++++++++++---
22
5 files changed, 41 insertions(+), 9 deletions(-)
31
6 files changed, 53 insertions(+), 13 deletions(-)
32
23
33
diff --git a/include/block/aio.h b/include/block/aio.h
24
diff --git a/include/block/aio.h b/include/block/aio.h
34
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
35
--- a/include/block/aio.h
26
--- a/include/block/aio.h
36
+++ b/include/block/aio.h
27
+++ b/include/block/aio.h
37
@@ -XXX,XX +XXX,XX @@ GSource *aio_get_g_source(AioContext *ctx);
28
@@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx);
38
/* Return the ThreadPool bound to this AioContext */
29
/* Relinquish ownership of the AioContext. */
39
struct ThreadPool *aio_get_thread_pool(AioContext *ctx);
30
void aio_context_release(AioContext *ctx);
40
31
41
+/* Setup the LinuxAioState bound to this AioContext */
32
+/**
42
+struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp);
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);
43
+
40
+
44
/* Return the LinuxAioState bound to this AioContext */
41
/**
45
struct LinuxAioState *aio_get_linux_aio(AioContext *ctx);
42
* aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run
46
43
* only once and as soon as possible.
47
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
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
48
index XXXXXXX..XXXXXXX 100644
78
index XXXXXXX..XXXXXXX 100644
49
--- a/include/block/raw-aio.h
79
--- a/include/qemu/main-loop.h
50
+++ b/include/block/raw-aio.h
80
+++ b/include/qemu/main-loop.h
51
@@ -XXX,XX +XXX,XX @@
81
@@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
52
/* linux-aio.c - Linux native implementation */
82
53
#ifdef CONFIG_LINUX_AIO
83
void qemu_fd_register(int fd);
54
typedef struct LinuxAioState LinuxAioState;
84
55
-LinuxAioState *laio_init(void);
85
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
56
+LinuxAioState *laio_init(Error **errp);
86
+#define qemu_bh_new(cb, opaque) \
57
void laio_cleanup(LinuxAioState *s);
87
+ qemu_bh_new_full((cb), (opaque), (stringify(cb)))
58
int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, int fd,
88
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name);
59
uint64_t offset, QEMUIOVector *qiov, int type);
89
void qemu_bh_schedule_idle(QEMUBH *bh);
60
diff --git a/block/file-posix.c b/block/file-posix.c
90
91
enum {
92
diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c
61
index XXXXXXX..XXXXXXX 100644
93
index XXXXXXX..XXXXXXX 100644
62
--- a/block/file-posix.c
94
--- a/tests/unit/ptimer-test-stubs.c
63
+++ b/block/file-posix.c
95
+++ b/tests/unit/ptimer-test-stubs.c
64
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
96
@@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
65
97
return deadline;
66
#ifdef CONFIG_LINUX_AIO
67
/* Currently Linux does AIO only for files opened with O_DIRECT */
68
- if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) {
69
- error_setg(errp, "aio=native was specified, but it requires "
70
- "cache.direct=on, which was not specified.");
71
- ret = -EINVAL;
72
- goto fail;
73
+ if (s->use_linux_aio) {
74
+ if (!(s->open_flags & O_DIRECT)) {
75
+ error_setg(errp, "aio=native was specified, but it requires "
76
+ "cache.direct=on, which was not specified.");
77
+ ret = -EINVAL;
78
+ goto fail;
79
+ }
80
+ if (!aio_setup_linux_aio(bdrv_get_aio_context(bs), errp)) {
81
+ error_prepend(errp, "Unable to use native AIO: ");
82
+ goto fail;
83
+ }
84
}
85
#else
86
if (s->use_linux_aio) {
87
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *raw_aio_flush(BlockDriverState *bs,
88
return paio_submit(bs, s->fd, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH);
89
}
98
}
90
99
91
+static void raw_aio_attach_aio_context(BlockDriverState *bs,
100
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
92
+ AioContext *new_context)
101
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
93
+{
94
+#ifdef CONFIG_LINUX_AIO
95
+ BDRVRawState *s = bs->opaque;
96
+ if (s->use_linux_aio) {
97
+ Error *local_err;
98
+ if (!aio_setup_linux_aio(new_context, &local_err)) {
99
+ error_reportf_err(local_err, "Unable to use native AIO, "
100
+ "falling back to thread pool: ");
101
+ s->use_linux_aio = false;
102
+ }
103
+ }
104
+#endif
105
+}
106
+
107
static void raw_close(BlockDriverState *bs)
108
{
102
{
109
BDRVRawState *s = bs->opaque;
103
QEMUBH *bh = g_new(QEMUBH, 1);
110
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
104
111
.bdrv_refresh_limits = raw_refresh_limits,
112
.bdrv_io_plug = raw_aio_plug,
113
.bdrv_io_unplug = raw_aio_unplug,
114
+ .bdrv_attach_aio_context = raw_aio_attach_aio_context,
115
116
.bdrv_truncate = raw_truncate,
117
.bdrv_getlength = raw_getlength,
118
diff --git a/block/linux-aio.c b/block/linux-aio.c
119
index XXXXXXX..XXXXXXX 100644
120
--- a/block/linux-aio.c
121
+++ b/block/linux-aio.c
122
@@ -XXX,XX +XXX,XX @@
123
#include "block/raw-aio.h"
124
#include "qemu/event_notifier.h"
125
#include "qemu/coroutine.h"
126
+#include "qapi/error.h"
127
128
#include <libaio.h>
129
130
@@ -XXX,XX +XXX,XX @@ void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
131
qemu_laio_poll_cb);
132
}
133
134
-LinuxAioState *laio_init(void)
135
+LinuxAioState *laio_init(Error **errp)
136
{
137
+ int rc;
138
LinuxAioState *s;
139
140
s = g_malloc0(sizeof(*s));
141
- if (event_notifier_init(&s->e, false) < 0) {
142
+ rc = event_notifier_init(&s->e, false);
143
+ if (rc < 0) {
144
+ error_setg_errno(errp, -rc, "failed to to initialize event notifier");
145
goto out_free_state;
146
}
147
148
- if (io_setup(MAX_EVENTS, &s->ctx) != 0) {
149
+ rc = io_setup(MAX_EVENTS, &s->ctx);
150
+ if (rc < 0) {
151
+ error_setg_errno(errp, -rc, "failed to create linux AIO context");
152
goto out_close_efd;
153
}
154
155
diff --git a/stubs/linux-aio.c b/stubs/linux-aio.c
156
index XXXXXXX..XXXXXXX 100644
157
--- a/stubs/linux-aio.c
158
+++ b/stubs/linux-aio.c
159
@@ -XXX,XX +XXX,XX @@ void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
160
abort();
161
}
162
163
-LinuxAioState *laio_init(void)
164
+LinuxAioState *laio_init(Error **errp)
165
{
166
abort();
167
}
168
diff --git a/util/async.c b/util/async.c
105
diff --git a/util/async.c b/util/async.c
169
index XXXXXXX..XXXXXXX 100644
106
index XXXXXXX..XXXXXXX 100644
170
--- a/util/async.c
107
--- a/util/async.c
171
+++ b/util/async.c
108
+++ b/util/async.c
172
@@ -XXX,XX +XXX,XX @@ ThreadPool *aio_get_thread_pool(AioContext *ctx)
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;
173
}
119
}
174
120
175
#ifdef CONFIG_LINUX_AIO
121
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
176
-LinuxAioState *aio_get_linux_aio(AioContext *ctx)
122
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb,
177
+LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp)
123
+ void *opaque, const char *name)
178
{
124
{
179
if (!ctx->linux_aio) {
125
QEMUBH *bh;
180
- ctx->linux_aio = laio_init();
126
bh = g_new(QEMUBH, 1);
181
- laio_attach_aio_context(ctx->linux_aio, ctx);
127
@@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
182
+ ctx->linux_aio = laio_init(errp);
128
.ctx = ctx,
183
+ if (ctx->linux_aio) {
129
.cb = cb,
184
+ laio_attach_aio_context(ctx->linux_aio, ctx);
130
.opaque = opaque,
185
+ }
131
+ .name = name,
186
}
132
};
187
return ctx->linux_aio;
133
aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT);
188
}
134
}
189
+
135
190
+LinuxAioState *aio_get_linux_aio(AioContext *ctx)
136
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
191
+{
137
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
192
+ assert(ctx->linux_aio);
138
+ const char *name)
193
+ return ctx->linux_aio;
139
{
194
+}
140
QEMUBH *bh;
195
#endif
141
bh = g_new(QEMUBH, 1);
196
142
@@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
197
void aio_notify(AioContext *ctx)
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
/*
198
--
166
--
199
2.17.1
167
2.31.1
200
168
201
diff view generated by jsdifflib
New patch
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.
1
5
6
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize()
7
is difficult to debug because the assertion failure contains no
8
information about the BH!
9
10
Use the QEMUBH name field added in the previous patch to show a useful
11
error when a leaked BH is detected.
12
13
Suggested-by: Eric Ernst <eric.g.ernst@gmail.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
20
diff --git a/util/async.c b/util/async.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/util/async.c
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
49
diff view generated by jsdifflib
New patch
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
1
2
3
This commit introduces "punch hole" operation and optimizes transfer
4
block size for macOS.
5
6
Thanks to Konstantin Nazarov for detailed analysis of a flaw in an
7
old version of this change:
8
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667
9
10
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
11
Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
14
block/file-posix.c | 27 +++++++++++++++++++++++++--
15
1 file changed, 25 insertions(+), 2 deletions(-)
16
17
diff --git a/block/file-posix.c b/block/file-posix.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/file-posix.c
20
+++ b/block/file-posix.c
21
@@ -XXX,XX +XXX,XX @@
22
#if defined(HAVE_HOST_BLOCK_DEVICE)
23
#include <paths.h>
24
#include <sys/param.h>
25
+#include <sys/mount.h>
26
#include <IOKit/IOKitLib.h>
27
#include <IOKit/IOBSD.h>
28
#include <IOKit/storage/IOMediaBSDClient.h>
29
@@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
30
return;
31
}
32
33
+#if defined(__APPLE__) && (__MACH__)
34
+ struct statfs buf;
35
+
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
41
+
42
if (bs->sg || S_ISBLK(st.st_mode)) {
43
int ret = hdev_get_max_hw_transfer(s->fd, &st);
44
45
@@ -XXX,XX +XXX,XX @@ out:
46
}
47
}
48
49
+#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD)
50
static int translate_err(int err)
51
{
52
if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP ||
53
@@ -XXX,XX +XXX,XX @@ static int translate_err(int err)
54
}
55
return err;
56
}
57
+#endif
58
59
#ifdef CONFIG_FALLOCATE
60
static int do_fallocate(int fd, int mode, off_t offset, off_t len)
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
}
91
--
92
2.31.1
93
diff view generated by jsdifflib
New patch
1
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
3
backend_defaults property allow users to control if default block
4
properties should be decided with backend information.
5
6
If it is off, any backend information will be discarded, which is
7
suitable if you plan to perform live migration to a different disk backend.
8
9
If it is on, a block device may utilize backend information more
10
aggressively.
11
12
By default, it is auto, which uses backend information for block
13
sizes and ignores the others, which is consistent with the older
14
versions.
15
16
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
17
Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
19
---
20
include/hw/block/block.h | 3 +++
21
hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++----
22
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++
23
3 files changed, 79 insertions(+), 4 deletions(-)
24
25
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
26
index XXXXXXX..XXXXXXX 100644
27
--- a/include/hw/block/block.h
28
+++ b/include/hw/block/block.h
29
@@ -XXX,XX +XXX,XX @@
30
31
typedef struct BlockConf {
32
BlockBackend *blk;
33
+ OnOffAuto backend_defaults;
34
uint32_t physical_block_size;
35
uint32_t logical_block_size;
36
uint32_t min_io_size;
37
@@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
38
}
39
40
#define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
41
+ DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \
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;
58
+
59
+ switch (conf->backend_defaults) {
60
+ case ON_OFF_AUTO_AUTO:
61
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
62
+ use_bs = false;
63
+ break;
64
+
65
+ case ON_OFF_AUTO_ON:
66
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
67
+ bs = blk_bs(blk);
68
+ use_bs = bs;
69
+ break;
70
+
71
+ case ON_OFF_AUTO_OFF:
72
+ use_blocksizes = false;
73
+ use_bs = false;
74
+ break;
75
+
76
+ default:
77
+ abort();
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)
421
--
422
2.31.1
423
diff view generated by jsdifflib
1
Determining the size of a field is useful when you don't have a struct
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
variable handy. Open-coding this is ugly.
3
2
4
This patch adds the sizeof_field() macro, which is similar to
3
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
5
typeof_field(). Existing instances are updated to use the macro.
4
Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com
6
7
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
Message-id: 20180614164431.29305-1-stefanha@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
6
---
12
include/hw/xen/io/ring.h | 2 +-
7
block/io.c | 2 ++
13
include/qemu/compiler.h | 2 ++
8
1 file changed, 2 insertions(+)
14
accel/tcg/translate-all.c | 2 +-
15
hw/display/xenfb.c | 4 ++--
16
hw/net/rocker/rocker_of_dpa.c | 2 +-
17
hw/net/virtio-net.c | 2 +-
18
target/i386/kvm.c | 2 +-
19
target/ppc/arch_dump.c | 10 +++++-----
20
target/s390x/arch_dump.c | 20 ++++++++++----------
21
9 files changed, 24 insertions(+), 22 deletions(-)
22
9
23
diff --git a/include/hw/xen/io/ring.h b/include/hw/xen/io/ring.h
10
diff --git a/block/io.c b/block/io.c
24
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/xen/io/ring.h
12
--- a/block/io.c
26
+++ b/include/hw/xen/io/ring.h
13
+++ b/block/io.c
27
@@ -XXX,XX +XXX,XX @@ typedef unsigned int RING_IDX;
14
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
28
*/
15
29
#define __CONST_RING_SIZE(_s, _sz) \
16
static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
30
(__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
31
-     sizeof(((struct _s##_sring *)0)->ring[0])))
32
+ sizeof_field(struct _s##_sring, ring[0])))
33
/*
34
* The same for passing in an actual pointer instead of a name tag.
35
*/
36
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/qemu/compiler.h
39
+++ b/include/qemu/compiler.h
40
@@ -XXX,XX +XXX,XX @@
41
(type *) ((char *) __mptr - offsetof(type, member));})
42
#endif
43
44
+#define sizeof_field(type, field) sizeof(((type *)0)->field)
45
+
46
/* Convert from a base type to a parent type, with compile time checking. */
47
#ifdef __GNUC__
48
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
49
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/accel/tcg/translate-all.c
52
+++ b/accel/tcg/translate-all.c
53
@@ -XXX,XX +XXX,XX @@ struct page_collection {
54
55
/* Make sure all possible CPU event bits fit in tb->trace_vcpu_dstate */
56
QEMU_BUILD_BUG_ON(CPU_TRACE_DSTATE_MAX_EVENTS >
57
- sizeof(((TranslationBlock *)0)->trace_vcpu_dstate)
58
+ sizeof_field(TranslationBlock, trace_vcpu_dstate)
59
* BITS_PER_BYTE);
60
61
/*
62
diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/hw/display/xenfb.c
65
+++ b/hw/display/xenfb.c
66
@@ -XXX,XX +XXX,XX @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim,
67
int width, int height, int depth,
68
size_t fb_len, int offset, int row_stride)
69
{
17
{
70
- size_t mfn_sz = sizeof(*((struct xenfb_page *)0)->pd);
18
+ dst->pdiscard_alignment = MAX(dst->pdiscard_alignment,
71
- size_t pd_len = sizeof(((struct xenfb_page *)0)->pd) / mfn_sz;
19
+ src->pdiscard_alignment);
72
+ size_t mfn_sz = sizeof_field(struct xenfb_page, pd[0]);
20
dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer);
73
+ size_t pd_len = sizeof_field(struct xenfb_page, pd) / mfn_sz;
21
dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer);
74
size_t fb_pages = pd_len * XC_PAGE_SIZE / mfn_sz;
22
dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer,
75
size_t fb_len_max = fb_pages * XC_PAGE_SIZE;
76
int max_width, max_height;
77
diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/hw/net/rocker/rocker_of_dpa.c
80
+++ b/hw/net/rocker/rocker_of_dpa.c
81
@@ -XXX,XX +XXX,XX @@ typedef struct of_dpa_flow_key {
82
83
/* Width of key which includes field 'f' in u64s, rounded up */
84
#define FLOW_KEY_WIDTH(f) \
85
- DIV_ROUND_UP(offsetof(OfDpaFlowKey, f) + sizeof(((OfDpaFlowKey *)0)->f), \
86
+ DIV_ROUND_UP(offsetof(OfDpaFlowKey, f) + sizeof_field(OfDpaFlowKey, f), \
87
sizeof(uint64_t))
88
89
typedef struct of_dpa_flow_action {
90
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
91
index XXXXXXX..XXXXXXX 100644
92
--- a/hw/net/virtio-net.c
93
+++ b/hw/net/virtio-net.c
94
@@ -XXX,XX +XXX,XX @@
95
* 'container'.
96
*/
97
#define endof(container, field) \
98
- (offsetof(container, field) + sizeof(((container *)0)->field))
99
+ (offsetof(container, field) + sizeof_field(container, field))
100
101
typedef struct VirtIOFeature {
102
uint64_t flags;
103
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
104
index XXXXXXX..XXXXXXX 100644
105
--- a/target/i386/kvm.c
106
+++ b/target/i386/kvm.c
107
@@ -XXX,XX +XXX,XX @@ static int kvm_put_fpu(X86CPU *cpu)
108
#define XSAVE_PKRU 672
109
110
#define XSAVE_BYTE_OFFSET(word_offset) \
111
- ((word_offset) * sizeof(((struct kvm_xsave *)0)->region[0]))
112
+ ((word_offset) * sizeof_field(struct kvm_xsave, region[0]))
113
114
#define ASSERT_OFFSET(word_offset, field) \
115
QEMU_BUILD_BUG_ON(XSAVE_BYTE_OFFSET(word_offset) != \
116
diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c
117
index XXXXXXX..XXXXXXX 100644
118
--- a/target/ppc/arch_dump.c
119
+++ b/target/ppc/arch_dump.c
120
@@ -XXX,XX +XXX,XX @@ static const struct NoteFuncDescStruct {
121
int contents_size;
122
void (*note_contents_func)(NoteFuncArg *arg, PowerPCCPU *cpu);
123
} note_func[] = {
124
- {sizeof(((Note *)0)->contents.prstatus), ppc_write_elf_prstatus},
125
- {sizeof(((Note *)0)->contents.fpregset), ppc_write_elf_fpregset},
126
- {sizeof(((Note *)0)->contents.vmxregset), ppc_write_elf_vmxregset},
127
- {sizeof(((Note *)0)->contents.vsxregset), ppc_write_elf_vsxregset},
128
- {sizeof(((Note *)0)->contents.speregset), ppc_write_elf_speregset},
129
+ {sizeof_field(Note, contents.prstatus), ppc_write_elf_prstatus},
130
+ {sizeof_field(Note, contents.fpregset), ppc_write_elf_fpregset},
131
+ {sizeof_field(Note, contents.vmxregset), ppc_write_elf_vmxregset},
132
+ {sizeof_field(Note, contents.vsxregset), ppc_write_elf_vsxregset},
133
+ {sizeof_field(Note, contents.speregset), ppc_write_elf_speregset},
134
{ 0, NULL}
135
};
136
137
diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c
138
index XXXXXXX..XXXXXXX 100644
139
--- a/target/s390x/arch_dump.c
140
+++ b/target/s390x/arch_dump.c
141
@@ -XXX,XX +XXX,XX @@ typedef struct NoteFuncDescStruct {
142
} NoteFuncDesc;
143
144
static const NoteFuncDesc note_core[] = {
145
- {sizeof(((Note *)0)->contents.prstatus), s390x_write_elf64_prstatus},
146
- {sizeof(((Note *)0)->contents.fpregset), s390x_write_elf64_fpregset},
147
+ {sizeof_field(Note, contents.prstatus), s390x_write_elf64_prstatus},
148
+ {sizeof_field(Note, contents.fpregset), s390x_write_elf64_fpregset},
149
{ 0, NULL}
150
};
151
152
static const NoteFuncDesc note_linux[] = {
153
- {sizeof(((Note *)0)->contents.prefix), s390x_write_elf64_prefix},
154
- {sizeof(((Note *)0)->contents.ctrs), s390x_write_elf64_ctrs},
155
- {sizeof(((Note *)0)->contents.timer), s390x_write_elf64_timer},
156
- {sizeof(((Note *)0)->contents.todcmp), s390x_write_elf64_todcmp},
157
- {sizeof(((Note *)0)->contents.todpreg), s390x_write_elf64_todpreg},
158
- {sizeof(((Note *)0)->contents.vregslo), s390x_write_elf64_vregslo},
159
- {sizeof(((Note *)0)->contents.vregshi), s390x_write_elf64_vregshi},
160
- {sizeof(((Note *)0)->contents.gscb), s390x_write_elf64_gscb},
161
+ {sizeof_field(Note, contents.prefix), s390x_write_elf64_prefix},
162
+ {sizeof_field(Note, contents.ctrs), s390x_write_elf64_ctrs},
163
+ {sizeof_field(Note, contents.timer), s390x_write_elf64_timer},
164
+ {sizeof_field(Note, contents.todcmp), s390x_write_elf64_todcmp},
165
+ {sizeof_field(Note, contents.todpreg), s390x_write_elf64_todpreg},
166
+ {sizeof_field(Note, contents.vregslo), s390x_write_elf64_vregslo},
167
+ {sizeof_field(Note, contents.vregshi), s390x_write_elf64_vregshi},
168
+ {sizeof_field(Note, contents.gscb), s390x_write_elf64_gscb},
169
{ 0, NULL}
170
};
171
172
--
23
--
173
2.17.1
24
2.31.1
174
25
175
diff view generated by jsdifflib