1
The following changes since commit fe8ee082db5038a05dbd8872e946049e9a9c550e:
1
The following changes since commit 6c769690ac845fa62642a5f93b4e4bd906adab95:
2
2
3
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-02-22' into staging (2017-02-24 15:00:51 +0000)
3
Merge remote-tracking branch 'remotes/vsementsov/tags/pull-simplebench-2021-05-04' into staging (2021-05-21 12:02:34 +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/codyprime/qemu-kvm-jtc.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 1d393bdeae22fde2cb83c1ea719675747c85c40e:
9
for you to fetch changes up to 0a6f0c76a030710780ce10d6347a70f098024d21:
10
10
11
RBD: Add support readv,writev for rbd (2017-02-24 12:43:01 -0500)
11
coroutine-sleep: introduce qemu_co_sleep (2021-05-21 18:22:33 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches for 2.9
14
Pull request
15
16
(Resent due to an email preparation mistake.)
17
15
----------------------------------------------------------------
18
----------------------------------------------------------------
16
19
17
Peter Lieven (2):
20
Paolo Bonzini (6):
18
block/nfs: convert to preadv / pwritev
21
coroutine-sleep: use a stack-allocated timer
19
block/nfs: try to avoid the bounce buffer in pwritev
22
coroutine-sleep: disallow NULL QemuCoSleepState** argument
23
coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing
24
coroutine-sleep: move timer out of QemuCoSleepState
25
coroutine-sleep: replace QemuCoSleepState pointer with struct in the
26
API
27
coroutine-sleep: introduce qemu_co_sleep
20
28
21
tianqing (1):
29
Philippe Mathieu-Daudé (1):
22
RBD: Add support readv,writev for rbd
30
bitops.h: Improve find_xxx_bit() documentation
23
31
24
block/nfs.c | 62 +++++++++++++++++++++++++----------------------
32
Zenghui Yu (1):
25
block/rbd.c | 80 ++++++++++++++++++++++++++++++++++++++++++-------------------
33
multi-process: Initialize variables declared with g_auto*
26
2 files changed, 90 insertions(+), 52 deletions(-)
34
35
include/qemu/bitops.h | 15 ++++++--
36
include/qemu/coroutine.h | 27 ++++++++-----
37
block/block-copy.c | 10 ++---
38
block/nbd.c | 14 +++----
39
hw/remote/memory.c | 5 +--
40
hw/remote/proxy.c | 3 +-
41
util/qemu-coroutine-sleep.c | 75 +++++++++++++++++++------------------
42
7 files changed, 79 insertions(+), 70 deletions(-)
27
43
28
--
44
--
29
2.9.3
45
2.31.1
30
46
31
diff view generated by jsdifflib
New patch
1
From: Zenghui Yu <yuzenghui@huawei.com>
1
2
3
Quote docs/devel/style.rst (section "Automatic memory deallocation"):
4
5
* Variables declared with g_auto* MUST always be initialized,
6
otherwise the cleanup function will use uninitialized stack memory
7
8
Initialize @name properly to get rid of the compilation error (using
9
gcc-7.3.0 on CentOS):
10
11
../hw/remote/proxy.c: In function 'pci_proxy_dev_realize':
12
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized]
13
g_free (*pp);
14
^~~~~~~~~~~~
15
../hw/remote/proxy.c:350:30: note: 'name' was declared here
16
g_autofree char *name;
17
^~~~
18
19
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
20
Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>
21
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22
Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>
23
Message-id: 20210312112143.1369-1-yuzenghui@huawei.com
24
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
25
---
26
hw/remote/memory.c | 5 ++---
27
hw/remote/proxy.c | 3 +--
28
2 files changed, 3 insertions(+), 5 deletions(-)
29
30
diff --git a/hw/remote/memory.c b/hw/remote/memory.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/remote/memory.c
33
+++ b/hw/remote/memory.c
34
@@ -XXX,XX +XXX,XX @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
35
36
remote_sysmem_reset();
37
38
- for (region = 0; region < msg->num_fds; region++) {
39
- g_autofree char *name;
40
+ for (region = 0; region < msg->num_fds; region++, suffix++) {
41
+ g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
42
subregion = g_new(MemoryRegion, 1);
43
- name = g_strdup_printf("remote-mem-%u", suffix++);
44
memory_region_init_ram_from_fd(subregion, NULL,
45
name, sysmem_info->sizes[region],
46
true, msg->fds[region],
47
diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/remote/proxy.c
50
+++ b/hw/remote/proxy.c
51
@@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp)
52
PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY;
53
54
if (size) {
55
- g_autofree char *name;
56
+ g_autofree char *name = g_strdup_printf("bar-region-%d", i);
57
pdev->region[i].dev = pdev;
58
pdev->region[i].present = true;
59
if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) {
60
pdev->region[i].memory = true;
61
}
62
- name = g_strdup_printf("bar-region-%d", i);
63
memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev),
64
&proxy_mr_ops, &pdev->region[i],
65
name, size);
66
--
67
2.31.1
68
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
Document the following functions return the bitmap size
4
if no matching bit is found:
5
6
- find_first_bit
7
- find_next_bit
8
- find_last_bit
9
- find_first_zero_bit
10
- find_next_zero_bit
11
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Message-id: 20210510200758.2623154-2-philmd@redhat.com
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17
---
18
include/qemu/bitops.h | 15 ++++++++++++---
19
1 file changed, 12 insertions(+), 3 deletions(-)
20
21
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/include/qemu/bitops.h
24
+++ b/include/qemu/bitops.h
25
@@ -XXX,XX +XXX,XX @@ static inline int test_bit(long nr, const unsigned long *addr)
26
* @addr: The address to start the search at
27
* @size: The maximum size to search
28
*
29
- * Returns the bit number of the first set bit, or size.
30
+ * Returns the bit number of the last set bit,
31
+ * or @size if there is no set bit in the bitmap.
32
*/
33
unsigned long find_last_bit(const unsigned long *addr,
34
unsigned long size);
35
@@ -XXX,XX +XXX,XX @@ unsigned long find_last_bit(const unsigned long *addr,
36
* @addr: The address to base the search on
37
* @offset: The bitnumber to start searching at
38
* @size: The bitmap size in bits
39
+ *
40
+ * Returns the bit number of the next set bit,
41
+ * or @size if there are no further set bits in the bitmap.
42
*/
43
unsigned long find_next_bit(const unsigned long *addr,
44
unsigned long size,
45
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_bit(const unsigned long *addr,
46
* @addr: The address to base the search on
47
* @offset: The bitnumber to start searching at
48
* @size: The bitmap size in bits
49
+ *
50
+ * Returns the bit number of the next cleared bit,
51
+ * or @size if there are no further clear bits in the bitmap.
52
*/
53
54
unsigned long find_next_zero_bit(const unsigned long *addr,
55
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_zero_bit(const unsigned long *addr,
56
* @addr: The address to start the search at
57
* @size: The maximum size to search
58
*
59
- * Returns the bit number of the first set bit.
60
+ * Returns the bit number of the first set bit,
61
+ * or @size if there is no set bit in the bitmap.
62
*/
63
static inline unsigned long find_first_bit(const unsigned long *addr,
64
unsigned long size)
65
@@ -XXX,XX +XXX,XX @@ static inline unsigned long find_first_bit(const unsigned long *addr,
66
* @addr: The address to start the search at
67
* @size: The maximum size to search
68
*
69
- * Returns the bit number of the first cleared bit.
70
+ * Returns the bit number of the first cleared bit,
71
+ * or @size if there is no clear bit in the bitmap.
72
*/
73
static inline unsigned long find_first_zero_bit(const unsigned long *addr,
74
unsigned long size)
75
--
76
2.31.1
77
diff view generated by jsdifflib
1
From: tianqing <tianqing@unitedstack.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Rbd can do readv and writev directly, so wo do not need to transform
3
The lifetime of the timer is well-known (it cannot outlive
4
iov to buf or vice versa any more.
4
qemu_co_sleep_ns_wakeable, because it's deleted by the time the
5
coroutine resumes), so it is not necessary to place it on the heap.
5
6
6
Signed-off-by: tianqing <tianqing@unitedstack.com>
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Reviewed-by: Jeff Cody <jcody@redhat.com>
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9
Message-id: 20210517100548.28806-2-pbonzini@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
11
---
10
block/rbd.c | 80 ++++++++++++++++++++++++++++++++++++++++++-------------------
12
util/qemu-coroutine-sleep.c | 9 ++++-----
11
1 file changed, 56 insertions(+), 24 deletions(-)
13
1 file changed, 4 insertions(+), 5 deletions(-)
12
14
13
diff --git a/block/rbd.c b/block/rbd.c
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/block/rbd.c
17
--- a/util/qemu-coroutine-sleep.c
16
+++ b/block/rbd.c
18
+++ b/util/qemu-coroutine-sleep.c
17
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
18
#define RBD_MAX_SNAP_NAME_SIZE 128
20
19
#define RBD_MAX_SNAPS 100
21
struct QemuCoSleepState {
20
22
Coroutine *co;
21
+/* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */
23
- QEMUTimer *ts;
22
+#ifdef LIBRBD_SUPPORTS_IOVEC
24
+ QEMUTimer ts;
23
+#define LIBRBD_USE_IOVEC 1
25
QemuCoSleepState **user_state_pointer;
24
+#else
26
};
25
+#define LIBRBD_USE_IOVEC 0
27
26
+#endif
28
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
27
+
29
if (sleep_state->user_state_pointer) {
28
typedef enum {
30
*sleep_state->user_state_pointer = NULL;
29
RBD_AIO_READ,
31
}
30
RBD_AIO_WRITE,
32
- timer_del(sleep_state->ts);
31
@@ -XXX,XX +XXX,XX @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf,
33
+ timer_del(&sleep_state->ts);
32
return ret;
34
aio_co_wake(sleep_state->co);
33
}
35
}
34
36
35
+static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs)
37
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
36
+{
38
AioContext *ctx = qemu_get_current_aio_context();
37
+ if (LIBRBD_USE_IOVEC) {
39
QemuCoSleepState state = {
38
+ RBDAIOCB *acb = rcb->acb;
40
.co = qemu_coroutine_self(),
39
+ iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0,
41
- .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state),
40
+ acb->qiov->size - offs);
42
.user_state_pointer = sleep_state,
41
+ } else {
43
};
42
+ memset(rcb->buf + offs, 0, rcb->size - offs);
44
43
+ }
45
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
44
+}
46
abort();
45
+
46
static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
47
{
48
Error *local_err = NULL;
49
@@ -XXX,XX +XXX,XX @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
50
}
51
} else {
52
if (r < 0) {
53
- memset(rcb->buf, 0, rcb->size);
54
+ qemu_rbd_memset(rcb, 0);
55
acb->ret = r;
56
acb->error = 1;
57
} else if (r < rcb->size) {
58
- memset(rcb->buf + r, 0, rcb->size - r);
59
+ qemu_rbd_memset(rcb, r);
60
if (!acb->error) {
61
acb->ret = rcb->size;
62
}
63
@@ -XXX,XX +XXX,XX @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
64
65
g_free(rcb);
66
67
- if (acb->cmd == RBD_AIO_READ) {
68
- qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size);
69
+ if (!LIBRBD_USE_IOVEC) {
70
+ if (acb->cmd == RBD_AIO_READ) {
71
+ qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size);
72
+ }
73
+ qemu_vfree(acb->bounce);
74
}
47
}
75
- qemu_vfree(acb->bounce);
48
76
+
49
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
77
acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret));
50
if (sleep_state) {
78
51
*sleep_state = &state;
79
qemu_aio_unref(acb);
80
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
81
RBDAIOCB *acb;
82
RADOSCB *rcb = NULL;
83
rbd_completion_t c;
84
- char *buf;
85
int r;
86
87
BDRVRBDState *s = bs->opaque;
88
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
89
acb->cmd = cmd;
90
acb->qiov = qiov;
91
assert(!qiov || qiov->size == size);
92
- if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) {
93
- acb->bounce = NULL;
94
- } else {
95
- acb->bounce = qemu_try_blockalign(bs, qiov->size);
96
- if (acb->bounce == NULL) {
97
- goto failed;
98
+
99
+ rcb = g_new(RADOSCB, 1);
100
+
101
+ if (!LIBRBD_USE_IOVEC) {
102
+ if (cmd == RBD_AIO_DISCARD || cmd == RBD_AIO_FLUSH) {
103
+ acb->bounce = NULL;
104
+ } else {
105
+ acb->bounce = qemu_try_blockalign(bs, qiov->size);
106
+ if (acb->bounce == NULL) {
107
+ goto failed;
108
+ }
109
}
110
+ if (cmd == RBD_AIO_WRITE) {
111
+ qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size);
112
+ }
113
+ rcb->buf = acb->bounce;
114
}
52
}
115
+
53
- timer_mod(state.ts, qemu_clock_get_ns(type) + ns);
116
acb->ret = 0;
54
+ timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
117
acb->error = 0;
55
qemu_coroutine_yield();
118
acb->s = s;
56
if (sleep_state) {
119
57
/*
120
- if (cmd == RBD_AIO_WRITE) {
58
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
121
- qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size);
59
*/
122
- }
60
assert(*sleep_state == NULL);
123
-
124
- buf = acb->bounce;
125
-
126
- rcb = g_new(RADOSCB, 1);
127
rcb->acb = acb;
128
- rcb->buf = buf;
129
rcb->s = acb->s;
130
rcb->size = size;
131
r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c);
132
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
133
134
switch (cmd) {
135
case RBD_AIO_WRITE:
136
- r = rbd_aio_write(s->image, off, size, buf, c);
137
+#ifdef LIBRBD_SUPPORTS_IOVEC
138
+ r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c);
139
+#else
140
+ r = rbd_aio_write(s->image, off, size, rcb->buf, c);
141
+#endif
142
break;
143
case RBD_AIO_READ:
144
- r = rbd_aio_read(s->image, off, size, buf, c);
145
+#ifdef LIBRBD_SUPPORTS_IOVEC
146
+ r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c);
147
+#else
148
+ r = rbd_aio_read(s->image, off, size, rcb->buf, c);
149
+#endif
150
break;
151
case RBD_AIO_DISCARD:
152
r = rbd_aio_discard_wrapper(s->image, off, size, c);
153
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
154
if (r < 0) {
155
goto failed_completion;
156
}
61
}
157
-
62
- timer_free(state.ts);
158
return &acb->common;
159
160
failed_completion:
161
rbd_aio_release(c);
162
failed:
163
g_free(rcb);
164
- qemu_vfree(acb->bounce);
165
+ if (!LIBRBD_USE_IOVEC) {
166
+ qemu_vfree(acb->bounce);
167
+ }
168
+
169
qemu_aio_unref(acb);
170
return NULL;
171
}
63
}
172
--
64
--
173
2.9.3
65
2.31.1
174
66
175
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Simplify the code by removing conditionals. qemu_co_sleep_ns
4
can simply point the argument to an on-stack temporary.
5
6
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-id: 20210517100548.28806-3-pbonzini@redhat.com
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
11
include/qemu/coroutine.h | 5 +++--
12
util/qemu-coroutine-sleep.c | 18 +++++-------------
13
2 files changed, 8 insertions(+), 15 deletions(-)
14
15
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/qemu/coroutine.h
18
+++ b/include/qemu/coroutine.h
19
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleepState QemuCoSleepState;
20
21
/**
22
* Yield the coroutine for a given duration. During this yield, @sleep_state
23
- * (if not NULL) is set to an opaque pointer, which may be used for
24
+ * is set to an opaque pointer, which may be used for
25
* qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
26
* timer fires. Don't save the obtained value to other variables and don't call
27
* qemu_co_sleep_wake from another aio context.
28
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
29
QemuCoSleepState **sleep_state);
30
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
31
{
32
- qemu_co_sleep_ns_wakeable(type, ns, NULL);
33
+ QemuCoSleepState *unused = NULL;
34
+ qemu_co_sleep_ns_wakeable(type, ns, &unused);
35
}
36
37
/**
38
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/util/qemu-coroutine-sleep.c
41
+++ b/util/qemu-coroutine-sleep.c
42
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
43
qemu_co_sleep_ns__scheduled, NULL);
44
45
assert(scheduled == qemu_co_sleep_ns__scheduled);
46
- if (sleep_state->user_state_pointer) {
47
- *sleep_state->user_state_pointer = NULL;
48
- }
49
+ *sleep_state->user_state_pointer = NULL;
50
timer_del(&sleep_state->ts);
51
aio_co_wake(sleep_state->co);
52
}
53
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
54
}
55
56
aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
57
- if (sleep_state) {
58
- *sleep_state = &state;
59
- }
60
+ *sleep_state = &state;
61
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
62
qemu_coroutine_yield();
63
- if (sleep_state) {
64
- /*
65
- * Note that *sleep_state is cleared during qemu_co_sleep_wake
66
- * before resuming this coroutine.
67
- */
68
- assert(*sleep_state == NULL);
69
- }
70
+
71
+ /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
72
+ assert(*sleep_state == NULL);
73
}
74
--
75
2.31.1
76
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
All callers of qemu_co_sleep_wake are checking whether they are passing
4
a NULL argument inside the pointer-to-pointer: do the check in
5
qemu_co_sleep_wake itself.
6
7
As a side effect, qemu_co_sleep_wake can be called more than once and
8
it will only wake the coroutine once; after the first time, the argument
9
will be set to NULL via *sleep_state->user_state_pointer. However, this
10
would not be safe unless co_sleep_cb keeps using the QemuCoSleepState*
11
directly, so make it go through the pointer-to-pointer instead.
12
13
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
14
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
15
Message-id: 20210517100548.28806-4-pbonzini@redhat.com
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17
---
18
block/block-copy.c | 4 +---
19
block/nbd.c | 8 ++------
20
util/qemu-coroutine-sleep.c | 21 ++++++++++++---------
21
3 files changed, 15 insertions(+), 18 deletions(-)
22
23
diff --git a/block/block-copy.c b/block/block-copy.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/block/block-copy.c
26
+++ b/block/block-copy.c
27
@@ -XXX,XX +XXX,XX @@ out:
28
29
void block_copy_kick(BlockCopyCallState *call_state)
30
{
31
- if (call_state->sleep_state) {
32
- qemu_co_sleep_wake(call_state->sleep_state);
33
- }
34
+ qemu_co_sleep_wake(call_state->sleep_state);
35
}
36
37
/*
38
diff --git a/block/nbd.c b/block/nbd.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/block/nbd.c
41
+++ b/block/nbd.c
42
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
43
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
44
45
s->drained = true;
46
- if (s->connection_co_sleep_ns_state) {
47
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
48
- }
49
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
50
51
nbd_co_establish_connection_cancel(bs, false);
52
53
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
54
55
s->state = NBD_CLIENT_QUIT;
56
if (s->connection_co) {
57
- if (s->connection_co_sleep_ns_state) {
58
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
59
- }
60
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
61
nbd_co_establish_connection_cancel(bs, true);
62
}
63
if (qemu_in_coroutine()) {
64
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/util/qemu-coroutine-sleep.c
67
+++ b/util/qemu-coroutine-sleep.c
68
@@ -XXX,XX +XXX,XX @@ struct QemuCoSleepState {
69
70
void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
71
{
72
- /* Write of schedule protected by barrier write in aio_co_schedule */
73
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
74
- qemu_co_sleep_ns__scheduled, NULL);
75
+ if (sleep_state) {
76
+ /* Write of schedule protected by barrier write in aio_co_schedule */
77
+ const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
78
+ qemu_co_sleep_ns__scheduled, NULL);
79
80
- assert(scheduled == qemu_co_sleep_ns__scheduled);
81
- *sleep_state->user_state_pointer = NULL;
82
- timer_del(&sleep_state->ts);
83
- aio_co_wake(sleep_state->co);
84
+ assert(scheduled == qemu_co_sleep_ns__scheduled);
85
+ *sleep_state->user_state_pointer = NULL;
86
+ timer_del(&sleep_state->ts);
87
+ aio_co_wake(sleep_state->co);
88
+ }
89
}
90
91
static void co_sleep_cb(void *opaque)
92
{
93
- qemu_co_sleep_wake(opaque);
94
+ QemuCoSleepState **sleep_state = opaque;
95
+ qemu_co_sleep_wake(*sleep_state);
96
}
97
98
void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
99
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
100
abort();
101
}
102
103
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
104
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
105
*sleep_state = &state;
106
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
107
qemu_coroutine_yield();
108
--
109
2.31.1
110
diff view generated by jsdifflib
1
From: Peter Lieven <pl@kamp.de>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
if the passed qiov contains exactly one iov we can
3
This simplification is enabled by the previous patch. Now aio_co_wake
4
pass the buffer directly.
4
will only be called once, therefore we do not care about a spurious
5
firing of the timer after a qemu_co_sleep_wake.
5
6
6
Signed-off-by: Peter Lieven <pl@kamp.de>
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Reviewed-by: Jeff Cody <jcody@redhat.com>
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-id: 1487349541-10201-3-git-send-email-pl@kamp.de
9
Message-id: 20210517100548.28806-5-pbonzini@redhat.com
9
Signed-off-by: Jeff Cody <jcody@redhat.com>
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
11
---
11
block/nfs.c | 35 ++++++++++++++++++++++-------------
12
util/qemu-coroutine-sleep.c | 8 ++++----
12
1 file changed, 22 insertions(+), 13 deletions(-)
13
1 file changed, 4 insertions(+), 4 deletions(-)
13
14
14
diff --git a/block/nfs.c b/block/nfs.c
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/block/nfs.c
17
--- a/util/qemu-coroutine-sleep.c
17
+++ b/block/nfs.c
18
+++ b/util/qemu-coroutine-sleep.c
18
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset,
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
19
NFSClient *client = bs->opaque;
20
20
NFSRPC task;
21
struct QemuCoSleepState {
21
char *buf = NULL;
22
Coroutine *co;
22
+ bool my_buffer = false;
23
- QEMUTimer ts;
23
24
QemuCoSleepState **user_state_pointer;
24
nfs_co_init_task(bs, &task);
25
};
25
26
26
- buf = g_try_malloc(bytes);
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
27
- if (bytes && buf == NULL) {
28
28
- return -ENOMEM;
29
assert(scheduled == qemu_co_sleep_ns__scheduled);
29
+ if (iov->niov != 1) {
30
*sleep_state->user_state_pointer = NULL;
30
+ buf = g_try_malloc(bytes);
31
- timer_del(&sleep_state->ts);
31
+ if (bytes && buf == NULL) {
32
aio_co_wake(sleep_state->co);
32
+ return -ENOMEM;
33
+ }
34
+ qemu_iovec_to_buf(iov, 0, buf, bytes);
35
+ my_buffer = true;
36
+ } else {
37
+ buf = iov->iov[0].iov_base;
38
}
33
}
39
34
}
40
- qemu_iovec_to_buf(iov, 0, buf, bytes);
35
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
41
-
36
QemuCoSleepState **sleep_state)
42
if (nfs_pwrite_async(client->context, client->fh,
37
{
43
offset, bytes, buf,
38
AioContext *ctx = qemu_get_current_aio_context();
44
nfs_co_generic_cb, &task) != 0) {
39
+ QEMUTimer ts;
45
+ if (my_buffer) {
40
QemuCoSleepState state = {
46
+ g_free(buf);
41
.co = qemu_coroutine_self(),
47
+ }
42
.user_state_pointer = sleep_state,
48
+ return -ENOMEM;
43
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
49
+ }
44
abort();
50
+
51
+ nfs_set_events(client);
52
+ while (!task.complete) {
53
+ qemu_coroutine_yield();
54
+ }
55
+
56
+ if (my_buffer) {
57
g_free(buf);
58
- return -ENOMEM;
59
}
45
}
60
46
61
- nfs_set_events(client);
47
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
62
- while (!task.complete) {
48
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
63
- qemu_coroutine_yield();
49
*sleep_state = &state;
64
- }
50
- timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
65
-
51
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
66
- g_free(buf);
52
qemu_coroutine_yield();
67
-
53
+ timer_del(&ts);
68
if (task.ret != bytes) {
54
69
return task.ret < 0 ? task.ret : -EIO;
55
/* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
70
}
56
assert(*sleep_state == NULL);
71
--
57
--
72
2.9.3
58
2.31.1
73
59
74
diff view generated by jsdifflib
New patch
1
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
3
Right now, users of qemu_co_sleep_ns_wakeable are simply passing
4
a pointer to QemuCoSleepState by reference to the function. But
5
QemuCoSleepState really is just a Coroutine*; making the
6
content of the struct public is just as efficient and lets us
7
skip the user_state_pointer indirection.
8
9
Since the usage is changed, take the occasion to rename the
10
struct to QemuCoSleep.
11
12
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
14
Message-id: 20210517100548.28806-6-pbonzini@redhat.com
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
17
include/qemu/coroutine.h | 23 +++++++++++----------
18
block/block-copy.c | 8 ++++----
19
block/nbd.c | 10 ++++-----
20
util/qemu-coroutine-sleep.c | 41 ++++++++++++++++---------------------
21
4 files changed, 39 insertions(+), 43 deletions(-)
22
23
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
24
index XXXXXXX..XXXXXXX 100644
25
--- a/include/qemu/coroutine.h
26
+++ b/include/qemu/coroutine.h
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_wrlock(CoRwlock *lock);
28
*/
29
void qemu_co_rwlock_unlock(CoRwlock *lock);
30
31
-typedef struct QemuCoSleepState QemuCoSleepState;
32
+typedef struct QemuCoSleep {
33
+ Coroutine *to_wake;
34
+} QemuCoSleep;
35
36
/**
37
- * Yield the coroutine for a given duration. During this yield, @sleep_state
38
- * is set to an opaque pointer, which may be used for
39
- * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
40
- * timer fires. Don't save the obtained value to other variables and don't call
41
- * qemu_co_sleep_wake from another aio context.
42
+ * Yield the coroutine for a given duration. Initializes @w so that,
43
+ * during this yield, it can be passed to qemu_co_sleep_wake() to
44
+ * terminate the sleep.
45
*/
46
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
47
- QemuCoSleepState **sleep_state);
48
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
49
+ QEMUClockType type, int64_t ns);
50
+
51
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
52
{
53
- QemuCoSleepState *unused = NULL;
54
- qemu_co_sleep_ns_wakeable(type, ns, &unused);
55
+ QemuCoSleep w = { 0 };
56
+ qemu_co_sleep_ns_wakeable(&w, type, ns);
57
}
58
59
/**
60
@@ -XXX,XX +XXX,XX @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
61
* qemu_co_sleep_ns() and should be checked to be non-NULL before calling
62
* qemu_co_sleep_wake().
63
*/
64
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state);
65
+void qemu_co_sleep_wake(QemuCoSleep *w);
66
67
/**
68
* Yield until a file descriptor becomes readable
69
diff --git a/block/block-copy.c b/block/block-copy.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/block/block-copy.c
72
+++ b/block/block-copy.c
73
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyCallState {
74
/* State */
75
int ret;
76
bool finished;
77
- QemuCoSleepState *sleep_state;
78
+ QemuCoSleep sleep;
79
bool cancelled;
80
81
/* OUT parameters */
82
@@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
83
if (ns > 0) {
84
block_copy_task_end(task, -EAGAIN);
85
g_free(task);
86
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns,
87
- &call_state->sleep_state);
88
+ qemu_co_sleep_ns_wakeable(&call_state->sleep,
89
+ QEMU_CLOCK_REALTIME, ns);
90
continue;
91
}
92
}
93
@@ -XXX,XX +XXX,XX @@ out:
94
95
void block_copy_kick(BlockCopyCallState *call_state)
96
{
97
- qemu_co_sleep_wake(call_state->sleep_state);
98
+ qemu_co_sleep_wake(&call_state->sleep);
99
}
100
101
/*
102
diff --git a/block/nbd.c b/block/nbd.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/block/nbd.c
105
+++ b/block/nbd.c
106
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVNBDState {
107
CoQueue free_sema;
108
Coroutine *connection_co;
109
Coroutine *teardown_co;
110
- QemuCoSleepState *connection_co_sleep_ns_state;
111
+ QemuCoSleep reconnect_sleep;
112
bool drained;
113
bool wait_drained_end;
114
int in_flight;
115
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
116
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
117
118
s->drained = true;
119
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
120
+ qemu_co_sleep_wake(&s->reconnect_sleep);
121
122
nbd_co_establish_connection_cancel(bs, false);
123
124
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
125
126
s->state = NBD_CLIENT_QUIT;
127
if (s->connection_co) {
128
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
129
+ qemu_co_sleep_wake(&s->reconnect_sleep);
130
nbd_co_establish_connection_cancel(bs, true);
131
}
132
if (qemu_in_coroutine()) {
133
@@ -XXX,XX +XXX,XX @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s)
134
}
135
bdrv_inc_in_flight(s->bs);
136
} else {
137
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout,
138
- &s->connection_co_sleep_ns_state);
139
+ qemu_co_sleep_ns_wakeable(&s->reconnect_sleep,
140
+ QEMU_CLOCK_REALTIME, timeout);
141
if (s->drained) {
142
continue;
143
}
144
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
145
index XXXXXXX..XXXXXXX 100644
146
--- a/util/qemu-coroutine-sleep.c
147
+++ b/util/qemu-coroutine-sleep.c
148
@@ -XXX,XX +XXX,XX @@
149
150
static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
151
152
-struct QemuCoSleepState {
153
+void qemu_co_sleep_wake(QemuCoSleep *w)
154
+{
155
Coroutine *co;
156
- QemuCoSleepState **user_state_pointer;
157
-};
158
159
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
160
-{
161
- if (sleep_state) {
162
+ co = w->to_wake;
163
+ w->to_wake = NULL;
164
+ if (co) {
165
/* Write of schedule protected by barrier write in aio_co_schedule */
166
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
167
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled,
168
qemu_co_sleep_ns__scheduled, NULL);
169
170
assert(scheduled == qemu_co_sleep_ns__scheduled);
171
- *sleep_state->user_state_pointer = NULL;
172
- aio_co_wake(sleep_state->co);
173
+ aio_co_wake(co);
174
}
175
}
176
177
static void co_sleep_cb(void *opaque)
178
{
179
- QemuCoSleepState **sleep_state = opaque;
180
- qemu_co_sleep_wake(*sleep_state);
181
+ QemuCoSleep *w = opaque;
182
+ qemu_co_sleep_wake(w);
183
}
184
185
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
186
- QemuCoSleepState **sleep_state)
187
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
188
+ QEMUClockType type, int64_t ns)
189
{
190
+ Coroutine *co = qemu_coroutine_self();
191
AioContext *ctx = qemu_get_current_aio_context();
192
QEMUTimer ts;
193
- QemuCoSleepState state = {
194
- .co = qemu_coroutine_self(),
195
- .user_state_pointer = sleep_state,
196
- };
197
198
- const char *scheduled = qatomic_cmpxchg(&state.co->scheduled, NULL,
199
- qemu_co_sleep_ns__scheduled);
200
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
201
+ qemu_co_sleep_ns__scheduled);
202
if (scheduled) {
203
fprintf(stderr,
204
"%s: Co-routine was already scheduled in '%s'\n",
205
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
206
abort();
207
}
208
209
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
210
- *sleep_state = &state;
211
+ w->to_wake = co;
212
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
213
timer_mod(&ts, qemu_clock_get_ns(type) + ns);
214
qemu_coroutine_yield();
215
timer_del(&ts);
216
217
- /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
218
- assert(*sleep_state == NULL);
219
+ /* w->to_wake is cleared before resuming this coroutine. */
220
+ assert(w->to_wake == NULL);
221
}
222
--
223
2.31.1
224
diff view generated by jsdifflib
1
From: Peter Lieven <pl@kamp.de>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Signed-off-by: Peter Lieven <pl@kamp.de>
3
Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake.
4
Reviewed-by: Jeff Cody <jcody@redhat.com>
4
This makes the logic of qemu_co_sleep_ns_wakeable easy to understand.
5
Message-id: 1487349541-10201-2-git-send-email-pl@kamp.de
5
6
Signed-off-by: Jeff Cody <jcody@redhat.com>
6
In the future we will introduce an API that can work even if the
7
sleep and wake happen from different threads. For now, initializing
8
w->to_wake after timer_mod is fine because the timer can only fire in
9
the same AioContext.
10
11
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
13
Message-id: 20210517100548.28806-7-pbonzini@redhat.com
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7
---
15
---
8
block/nfs.c | 33 +++++++++++++++------------------
16
include/qemu/coroutine.h | 5 +++++
9
1 file changed, 15 insertions(+), 18 deletions(-)
17
util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++-------
18
2 files changed, 24 insertions(+), 7 deletions(-)
10
19
11
diff --git a/block/nfs.c b/block/nfs.c
20
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
12
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
13
--- a/block/nfs.c
22
--- a/include/qemu/coroutine.h
14
+++ b/block/nfs.c
23
+++ b/include/qemu/coroutine.h
15
@@ -XXX,XX +XXX,XX @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data,
24
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleep {
16
nfs_co_generic_bh_cb, task);
25
void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
26
QEMUClockType type, int64_t ns);
27
28
+/**
29
+ * Yield the coroutine until the next call to qemu_co_sleep_wake.
30
+ */
31
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w);
32
+
33
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
34
{
35
QemuCoSleep w = { 0 };
36
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/util/qemu-coroutine-sleep.c
39
+++ b/util/qemu-coroutine-sleep.c
40
@@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque)
41
qemu_co_sleep_wake(w);
17
}
42
}
18
43
19
-static int coroutine_fn nfs_co_readv(BlockDriverState *bs,
44
-void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
20
- int64_t sector_num, int nb_sectors,
45
- QEMUClockType type, int64_t ns)
21
- QEMUIOVector *iov)
46
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w)
22
+static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset,
23
+ uint64_t bytes, QEMUIOVector *iov,
24
+ int flags)
25
{
47
{
26
NFSClient *client = bs->opaque;
48
Coroutine *co = qemu_coroutine_self();
27
NFSRPC task;
49
- AioContext *ctx = qemu_get_current_aio_context();
28
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_readv(BlockDriverState *bs,
50
- QEMUTimer ts;
29
task.iov = iov;
51
30
52
const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
31
if (nfs_pread_async(client->context, client->fh,
53
qemu_co_sleep_ns__scheduled);
32
- sector_num * BDRV_SECTOR_SIZE,
54
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
33
- nb_sectors * BDRV_SECTOR_SIZE,
34
- nfs_co_generic_cb, &task) != 0) {
35
+ offset, bytes, nfs_co_generic_cb, &task) != 0) {
36
return -ENOMEM;
37
}
55
}
38
56
39
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_readv(BlockDriverState *bs,
57
w->to_wake = co;
40
return 0;
58
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
59
- timer_mod(&ts, qemu_clock_get_ns(type) + ns);
60
qemu_coroutine_yield();
61
- timer_del(&ts);
62
63
/* w->to_wake is cleared before resuming this coroutine. */
64
assert(w->to_wake == NULL);
41
}
65
}
42
66
+
43
-static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
67
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
44
- int64_t sector_num, int nb_sectors,
68
+ QEMUClockType type, int64_t ns)
45
- QEMUIOVector *iov)
69
+{
46
+static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset,
70
+ AioContext *ctx = qemu_get_current_aio_context();
47
+ uint64_t bytes, QEMUIOVector *iov,
71
+ QEMUTimer ts;
48
+ int flags)
72
+
49
{
73
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w);
50
NFSClient *client = bs->opaque;
74
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
51
NFSRPC task;
75
+
52
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
76
+ /*
53
77
+ * The timer will fire in the current AiOContext, so the callback
54
nfs_co_init_task(bs, &task);
78
+ * must happen after qemu_co_sleep yields and there is no race
55
79
+ * between timer_mod and qemu_co_sleep.
56
- buf = g_try_malloc(nb_sectors * BDRV_SECTOR_SIZE);
80
+ */
57
- if (nb_sectors && buf == NULL) {
81
+ qemu_co_sleep(w);
58
+ buf = g_try_malloc(bytes);
82
+ timer_del(&ts);
59
+ if (bytes && buf == NULL) {
83
+}
60
return -ENOMEM;
61
}
62
63
- qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE);
64
+ qemu_iovec_to_buf(iov, 0, buf, bytes);
65
66
if (nfs_pwrite_async(client->context, client->fh,
67
- sector_num * BDRV_SECTOR_SIZE,
68
- nb_sectors * BDRV_SECTOR_SIZE,
69
- buf, nfs_co_generic_cb, &task) != 0) {
70
+ offset, bytes, buf,
71
+ nfs_co_generic_cb, &task) != 0) {
72
g_free(buf);
73
return -ENOMEM;
74
}
75
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
76
77
g_free(buf);
78
79
- if (task.ret != nb_sectors * BDRV_SECTOR_SIZE) {
80
+ if (task.ret != bytes) {
81
return task.ret < 0 ? task.ret : -EIO;
82
}
83
84
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nfs = {
85
.bdrv_create = nfs_file_create,
86
.bdrv_reopen_prepare = nfs_reopen_prepare,
87
88
- .bdrv_co_readv = nfs_co_readv,
89
- .bdrv_co_writev = nfs_co_writev,
90
+ .bdrv_co_preadv = nfs_co_preadv,
91
+ .bdrv_co_pwritev = nfs_co_pwritev,
92
.bdrv_co_flush_to_disk = nfs_co_flush,
93
94
.bdrv_detach_aio_context = nfs_detach_aio_context,
95
--
84
--
96
2.9.3
85
2.31.1
97
86
98
diff view generated by jsdifflib