1
The following changes since commit 136c67e07869227b21b3f627316e03679ce7b738:
1
The following changes since commit c6a5fc2ac76c5ab709896ee1b0edd33685a67ed1:
2
2
3
Merge remote-tracking branch 'remotes/bkoppelmann/tags/pull-tricore-2018-03-02' into staging (2018-03-02 16:56:20 +0000)
3
decodetree: Add --output-null for meson testing (2023-05-31 19:56:42 -0700)
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 23500c6a9409efc80d696aede0629bfbe7556a90:
9
for you to fetch changes up to 98b126f5e3228a346c774e569e26689943b401dd:
10
10
11
README: Document 'git-publish' workflow (2018-03-05 09:03:17 +0000)
11
qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa (2023-06-01 11:08:21 -0400)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Pull request
14
Pull request
15
15
16
Mostly patches that are only indirectly related to the block layer, but I've
16
- Stefano Garzarella's blkio block driver 'fd' parameter
17
reviewed them and there is no maintainer.
17
- My thread-local blk_io_plug() series
18
18
19
----------------------------------------------------------------
19
----------------------------------------------------------------
20
20
21
Fam Zheng (2):
21
Stefan Hajnoczi (6):
22
Add a git-publish configuration file
22
block: add blk_io_plug_call() API
23
README: Document 'git-publish' workflow
23
block/nvme: convert to blk_io_plug_call() API
24
block/blkio: convert to blk_io_plug_call() API
25
block/io_uring: convert to blk_io_plug_call() API
26
block/linux-aio: convert to blk_io_plug_call() API
27
block: remove bdrv_co_io_plug() API
24
28
25
Su Hang (3):
29
Stefano Garzarella (2):
26
util/uri.c: Coding style check, Only whitespace involved
30
block/blkio: use qemu_open() to support fd passing for virtio-blk
27
util/uri.c: remove brackets that wrap `return` statement's content.
31
qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa
28
util/uri.c: wrap single statement blocks with braces {}
29
32
30
Thomas Huth (1):
33
MAINTAINERS | 1 +
31
tests/libqos: Check for valid dev pointer when looking for PCI devices
34
qapi/block-core.json | 6 ++
32
35
meson.build | 4 +
33
tests/libqos/virtio-pci.c | 4 +-
36
include/block/block-io.h | 3 -
34
util/uri.c | 1733 ++++++++++++++++++++++++---------------------
37
include/block/block_int-common.h | 11 ---
35
.gitpublish | 51 ++
38
include/block/raw-aio.h | 14 ---
36
README | 31 +-
39
include/sysemu/block-backend-io.h | 13 +--
37
4 files changed, 1014 insertions(+), 805 deletions(-)
40
block/blkio.c | 96 ++++++++++++------
38
create mode 100644 .gitpublish
41
block/block-backend.c | 22 -----
42
block/file-posix.c | 38 -------
43
block/io.c | 37 -------
44
block/io_uring.c | 44 ++++-----
45
block/linux-aio.c | 41 +++-----
46
block/nvme.c | 44 +++------
47
block/plug.c | 159 ++++++++++++++++++++++++++++++
48
hw/block/dataplane/xen-block.c | 8 +-
49
hw/block/virtio-blk.c | 4 +-
50
hw/scsi/virtio-scsi.c | 6 +-
51
block/meson.build | 1 +
52
block/trace-events | 6 +-
53
20 files changed, 293 insertions(+), 265 deletions(-)
54
create mode 100644 block/plug.c
39
55
40
--
56
--
41
2.14.3
57
2.40.1
42
43
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Introduce a new API for thread-local blk_io_plug() that does not
2
2
traverse the block graph. The goal is to make blk_io_plug() multi-queue
3
git-publish [1] is a convenient tool to send patches and has been
3
friendly.
4
popular among QEMU developers. Recently it has been made available in
4
5
Fedora/Debian official repo.
5
Instead of having block drivers track whether or not we're in a plugged
6
6
section, provide an API that allows them to defer a function call until
7
One nice feature of the tool is a per-project configuration with
7
we're unplugged: blk_io_plug_call(fn, opaque). If blk_io_plug_call() is
8
profiles, especially in which the cccmd option is a handy method to
8
called multiple times with the same fn/opaque pair, then fn() is only
9
create the Cc list.
9
called once at the end of the function - resulting in batching.
10
10
11
[1]: https://github.com/stefanha/git-publish
11
This patch introduces the API and changes blk_io_plug()/blk_io_unplug().
12
12
blk_io_plug()/blk_io_unplug() no longer require a BlockBackend argument
13
Signed-off-by: Fam Zheng <famz@redhat.com>
13
because the plug state is now thread-local.
14
Message-id: 20180226030326.20219-2-famz@redhat.com
14
15
Later patches convert block drivers to blk_io_plug_call() and then we
16
can finally remove .bdrv_co_io_plug() once all block drivers have been
17
converted.
18
19
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
20
Reviewed-by: Eric Blake <eblake@redhat.com>
21
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
22
Acked-by: Kevin Wolf <kwolf@redhat.com>
23
Message-id: 20230530180959.1108766-2-stefanha@redhat.com
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
24
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
25
---
17
.gitpublish | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
26
MAINTAINERS | 1 +
18
1 file changed, 51 insertions(+)
27
include/sysemu/block-backend-io.h | 13 +--
19
create mode 100644 .gitpublish
28
block/block-backend.c | 22 -----
20
29
block/plug.c | 159 ++++++++++++++++++++++++++++++
21
diff --git a/.gitpublish b/.gitpublish
30
hw/block/dataplane/xen-block.c | 8 +-
31
hw/block/virtio-blk.c | 4 +-
32
hw/scsi/virtio-scsi.c | 6 +-
33
block/meson.build | 1 +
34
8 files changed, 173 insertions(+), 41 deletions(-)
35
create mode 100644 block/plug.c
36
37
diff --git a/MAINTAINERS b/MAINTAINERS
38
index XXXXXXX..XXXXXXX 100644
39
--- a/MAINTAINERS
40
+++ b/MAINTAINERS
41
@@ -XXX,XX +XXX,XX @@ F: util/aio-*.c
42
F: util/aio-*.h
43
F: util/fdmon-*.c
44
F: block/io.c
45
+F: block/plug.c
46
F: migration/block*
47
F: include/block/aio.h
48
F: include/block/aio-wait.h
49
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
50
index XXXXXXX..XXXXXXX 100644
51
--- a/include/sysemu/block-backend-io.h
52
+++ b/include/sysemu/block-backend-io.h
53
@@ -XXX,XX +XXX,XX @@ void blk_iostatus_set_err(BlockBackend *blk, int error);
54
int blk_get_max_iov(BlockBackend *blk);
55
int blk_get_max_hw_iov(BlockBackend *blk);
56
57
-/*
58
- * blk_io_plug/unplug are thread-local operations. This means that multiple
59
- * IOThreads can simultaneously call plug/unplug, but the caller must ensure
60
- * that each unplug() is called in the same IOThread of the matching plug().
61
- */
62
-void coroutine_fn blk_co_io_plug(BlockBackend *blk);
63
-void co_wrapper blk_io_plug(BlockBackend *blk);
64
-
65
-void coroutine_fn blk_co_io_unplug(BlockBackend *blk);
66
-void co_wrapper blk_io_unplug(BlockBackend *blk);
67
+void blk_io_plug(void);
68
+void blk_io_unplug(void);
69
+void blk_io_plug_call(void (*fn)(void *), void *opaque);
70
71
AioContext *blk_get_aio_context(BlockBackend *blk);
72
BlockAcctStats *blk_get_stats(BlockBackend *blk);
73
diff --git a/block/block-backend.c b/block/block-backend.c
74
index XXXXXXX..XXXXXXX 100644
75
--- a/block/block-backend.c
76
+++ b/block/block-backend.c
77
@@ -XXX,XX +XXX,XX @@ void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify)
78
notifier_list_add(&blk->insert_bs_notifiers, notify);
79
}
80
81
-void coroutine_fn blk_co_io_plug(BlockBackend *blk)
82
-{
83
- BlockDriverState *bs = blk_bs(blk);
84
- IO_CODE();
85
- GRAPH_RDLOCK_GUARD();
86
-
87
- if (bs) {
88
- bdrv_co_io_plug(bs);
89
- }
90
-}
91
-
92
-void coroutine_fn blk_co_io_unplug(BlockBackend *blk)
93
-{
94
- BlockDriverState *bs = blk_bs(blk);
95
- IO_CODE();
96
- GRAPH_RDLOCK_GUARD();
97
-
98
- if (bs) {
99
- bdrv_co_io_unplug(bs);
100
- }
101
-}
102
-
103
BlockAcctStats *blk_get_stats(BlockBackend *blk)
104
{
105
IO_CODE();
106
diff --git a/block/plug.c b/block/plug.c
22
new file mode 100644
107
new file mode 100644
23
index XXXXXXX..XXXXXXX
108
index XXXXXXX..XXXXXXX
24
--- /dev/null
109
--- /dev/null
25
+++ b/.gitpublish
110
+++ b/block/plug.c
26
@@ -XXX,XX +XXX,XX @@
111
@@ -XXX,XX +XXX,XX @@
27
+#
112
+/* SPDX-License-Identifier: GPL-2.0-or-later */
28
+# Common git-publish profiles that can be used to send patches to QEMU upstream.
113
+/*
29
+#
114
+ * Block I/O plugging
30
+# See https://github.com/stefanha/git-publish for more information
115
+ *
31
+#
116
+ * Copyright Red Hat.
32
+[gitpublishprofile "default"]
117
+ *
33
+base = master
118
+ * This API defers a function call within a blk_io_plug()/blk_io_unplug()
34
+to = qemu-devel@nongnu.org
119
+ * section, allowing multiple calls to batch up. This is a performance
35
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
120
+ * optimization that is used in the block layer to submit several I/O requests
36
+
121
+ * at once instead of individually:
37
+[gitpublishprofile "rfc"]
122
+ *
38
+base = master
123
+ * blk_io_plug(); <-- start of plugged region
39
+prefix = RFC PATCH
124
+ * ...
40
+to = qemu-devel@nongnu.org
125
+ * blk_io_plug_call(my_func, my_obj); <-- deferred my_func(my_obj) call
41
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
126
+ * blk_io_plug_call(my_func, my_obj); <-- another
42
+
127
+ * blk_io_plug_call(my_func, my_obj); <-- another
43
+[gitpublishprofile "stable"]
128
+ * ...
44
+base = master
129
+ * blk_io_unplug(); <-- end of plugged region, my_func(my_obj) is called once
45
+to = qemu-devel@nongnu.org
130
+ *
46
+cc = qemu-stable@nongnu.org
131
+ * This code is actually generic and not tied to the block layer. If another
47
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
132
+ * subsystem needs this functionality, it could be renamed.
48
+
133
+ */
49
+[gitpublishprofile "trivial"]
134
+
50
+base = master
135
+#include "qemu/osdep.h"
51
+to = qemu-devel@nongnu.org
136
+#include "qemu/coroutine-tls.h"
52
+cc = qemu-trivial@nongnu.org
137
+#include "qemu/notify.h"
53
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
138
+#include "qemu/thread.h"
54
+
139
+#include "sysemu/block-backend.h"
55
+[gitpublishprofile "block"]
140
+
56
+base = master
141
+/* A function call that has been deferred until unplug() */
57
+to = qemu-devel@nongnu.org
142
+typedef struct {
58
+cc = qemu-block@nongnu.org
143
+ void (*fn)(void *);
59
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
144
+ void *opaque;
60
+
145
+} UnplugFn;
61
+[gitpublishprofile "arm"]
146
+
62
+base = master
147
+/* Per-thread state */
63
+to = qemu-devel@nongnu.org
148
+typedef struct {
64
+cc = qemu-arm@nongnu.org
149
+ unsigned count; /* how many times has plug() been called? */
65
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
150
+ GArray *unplug_fns; /* functions to call at unplug time */
66
+
151
+} Plug;
67
+[gitpublishprofile "s390"]
152
+
68
+base = master
153
+/* Use get_ptr_plug() to fetch this thread-local value */
69
+to = qemu-devel@nongnu.org
154
+QEMU_DEFINE_STATIC_CO_TLS(Plug, plug);
70
+cc = qemu-s390@nongnu.org
155
+
71
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
156
+/* Called at thread cleanup time */
72
+
157
+static void blk_io_plug_atexit(Notifier *n, void *value)
73
+[gitpublishprofile "ppc"]
158
+{
74
+base = master
159
+ Plug *plug = get_ptr_plug();
75
+to = qemu-devel@nongnu.org
160
+ g_array_free(plug->unplug_fns, TRUE);
76
+cc = qemu-ppc@nongnu.org
161
+}
77
+cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
162
+
163
+/* This won't involve coroutines, so use __thread */
164
+static __thread Notifier blk_io_plug_atexit_notifier;
165
+
166
+/**
167
+ * blk_io_plug_call:
168
+ * @fn: a function pointer to be invoked
169
+ * @opaque: a user-defined argument to @fn()
170
+ *
171
+ * Call @fn(@opaque) immediately if not within a blk_io_plug()/blk_io_unplug()
172
+ * section.
173
+ *
174
+ * Otherwise defer the call until the end of the outermost
175
+ * blk_io_plug()/blk_io_unplug() section in this thread. If the same
176
+ * @fn/@opaque pair has already been deferred, it will only be called once upon
177
+ * blk_io_unplug() so that accumulated calls are batched into a single call.
178
+ *
179
+ * The caller must ensure that @opaque is not freed before @fn() is invoked.
180
+ */
181
+void blk_io_plug_call(void (*fn)(void *), void *opaque)
182
+{
183
+ Plug *plug = get_ptr_plug();
184
+
185
+ /* Call immediately if we're not plugged */
186
+ if (plug->count == 0) {
187
+ fn(opaque);
188
+ return;
189
+ }
190
+
191
+ GArray *array = plug->unplug_fns;
192
+ if (!array) {
193
+ array = g_array_new(FALSE, FALSE, sizeof(UnplugFn));
194
+ plug->unplug_fns = array;
195
+ blk_io_plug_atexit_notifier.notify = blk_io_plug_atexit;
196
+ qemu_thread_atexit_add(&blk_io_plug_atexit_notifier);
197
+ }
198
+
199
+ UnplugFn *fns = (UnplugFn *)array->data;
200
+ UnplugFn new_fn = {
201
+ .fn = fn,
202
+ .opaque = opaque,
203
+ };
204
+
205
+ /*
206
+ * There won't be many, so do a linear search. If this becomes a bottleneck
207
+ * then a binary search (glib 2.62+) or different data structure could be
208
+ * used.
209
+ */
210
+ for (guint i = 0; i < array->len; i++) {
211
+ if (memcmp(&fns[i], &new_fn, sizeof(new_fn)) == 0) {
212
+ return; /* already exists */
213
+ }
214
+ }
215
+
216
+ g_array_append_val(array, new_fn);
217
+}
218
+
219
+/**
220
+ * blk_io_plug: Defer blk_io_plug_call() functions until blk_io_unplug()
221
+ *
222
+ * blk_io_plug/unplug are thread-local operations. This means that multiple
223
+ * threads can simultaneously call plug/unplug, but the caller must ensure that
224
+ * each unplug() is called in the same thread of the matching plug().
225
+ *
226
+ * Nesting is supported. blk_io_plug_call() functions are only called at the
227
+ * outermost blk_io_unplug().
228
+ */
229
+void blk_io_plug(void)
230
+{
231
+ Plug *plug = get_ptr_plug();
232
+
233
+ assert(plug->count < UINT32_MAX);
234
+
235
+ plug->count++;
236
+}
237
+
238
+/**
239
+ * blk_io_unplug: Run any pending blk_io_plug_call() functions
240
+ *
241
+ * There must have been a matching blk_io_plug() call in the same thread prior
242
+ * to this blk_io_unplug() call.
243
+ */
244
+void blk_io_unplug(void)
245
+{
246
+ Plug *plug = get_ptr_plug();
247
+
248
+ assert(plug->count > 0);
249
+
250
+ if (--plug->count > 0) {
251
+ return;
252
+ }
253
+
254
+ GArray *array = plug->unplug_fns;
255
+ if (!array) {
256
+ return;
257
+ }
258
+
259
+ UnplugFn *fns = (UnplugFn *)array->data;
260
+
261
+ for (guint i = 0; i < array->len; i++) {
262
+ fns[i].fn(fns[i].opaque);
263
+ }
264
+
265
+ /*
266
+ * This resets the array without freeing memory so that appending is cheap
267
+ * in the future.
268
+ */
269
+ g_array_set_size(array, 0);
270
+}
271
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
272
index XXXXXXX..XXXXXXX 100644
273
--- a/hw/block/dataplane/xen-block.c
274
+++ b/hw/block/dataplane/xen-block.c
275
@@ -XXX,XX +XXX,XX @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
276
* is below us.
277
*/
278
if (inflight_atstart > IO_PLUG_THRESHOLD) {
279
- blk_io_plug(dataplane->blk);
280
+ blk_io_plug();
281
}
282
while (rc != rp) {
283
/* pull request from ring */
284
@@ -XXX,XX +XXX,XX @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
285
286
if (inflight_atstart > IO_PLUG_THRESHOLD &&
287
batched >= inflight_atstart) {
288
- blk_io_unplug(dataplane->blk);
289
+ blk_io_unplug();
290
}
291
xen_block_do_aio(request);
292
if (inflight_atstart > IO_PLUG_THRESHOLD) {
293
if (batched >= inflight_atstart) {
294
- blk_io_plug(dataplane->blk);
295
+ blk_io_plug();
296
batched = 0;
297
} else {
298
batched++;
299
@@ -XXX,XX +XXX,XX @@ static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
300
}
301
}
302
if (inflight_atstart > IO_PLUG_THRESHOLD) {
303
- blk_io_unplug(dataplane->blk);
304
+ blk_io_unplug();
305
}
306
307
return done_something;
308
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
309
index XXXXXXX..XXXXXXX 100644
310
--- a/hw/block/virtio-blk.c
311
+++ b/hw/block/virtio-blk.c
312
@@ -XXX,XX +XXX,XX @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
313
bool suppress_notifications = virtio_queue_get_notification(vq);
314
315
aio_context_acquire(blk_get_aio_context(s->blk));
316
- blk_io_plug(s->blk);
317
+ blk_io_plug();
318
319
do {
320
if (suppress_notifications) {
321
@@ -XXX,XX +XXX,XX @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
322
virtio_blk_submit_multireq(s, &mrb);
323
}
324
325
- blk_io_unplug(s->blk);
326
+ blk_io_unplug();
327
aio_context_release(blk_get_aio_context(s->blk));
328
}
329
330
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
331
index XXXXXXX..XXXXXXX 100644
332
--- a/hw/scsi/virtio-scsi.c
333
+++ b/hw/scsi/virtio-scsi.c
334
@@ -XXX,XX +XXX,XX @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
335
return -ENOBUFS;
336
}
337
scsi_req_ref(req->sreq);
338
- blk_io_plug(d->conf.blk);
339
+ blk_io_plug();
340
object_unref(OBJECT(d));
341
return 0;
342
}
343
@@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req)
344
if (scsi_req_enqueue(sreq)) {
345
scsi_req_continue(sreq);
346
}
347
- blk_io_unplug(sreq->dev->conf.blk);
348
+ blk_io_unplug();
349
scsi_req_unref(sreq);
350
}
351
352
@@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq)
353
while (!QTAILQ_EMPTY(&reqs)) {
354
req = QTAILQ_FIRST(&reqs);
355
QTAILQ_REMOVE(&reqs, req, next);
356
- blk_io_unplug(req->sreq->dev->conf.blk);
357
+ blk_io_unplug();
358
scsi_req_unref(req->sreq);
359
virtqueue_detach_element(req->vq, &req->elem, 0);
360
virtio_scsi_free_req(req);
361
diff --git a/block/meson.build b/block/meson.build
362
index XXXXXXX..XXXXXXX 100644
363
--- a/block/meson.build
364
+++ b/block/meson.build
365
@@ -XXX,XX +XXX,XX @@ block_ss.add(files(
366
'mirror.c',
367
'nbd.c',
368
'null.c',
369
+ 'plug.c',
370
'qapi.c',
371
'qcow2-bitmap.c',
372
'qcow2-cache.c',
78
--
373
--
79
2.14.3
374
2.40.1
80
81
diff view generated by jsdifflib
New patch
1
Stop using the .bdrv_co_io_plug() API because it is not multi-queue
2
block layer friendly. Use the new blk_io_plug_call() API to batch I/O
3
submission instead.
1
4
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
8
Acked-by: Kevin Wolf <kwolf@redhat.com>
9
Message-id: 20230530180959.1108766-3-stefanha@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
block/nvme.c | 44 ++++++++++++--------------------------------
13
block/trace-events | 1 -
14
2 files changed, 12 insertions(+), 33 deletions(-)
15
16
diff --git a/block/nvme.c b/block/nvme.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/nvme.c
19
+++ b/block/nvme.c
20
@@ -XXX,XX +XXX,XX @@
21
#include "qemu/vfio-helpers.h"
22
#include "block/block-io.h"
23
#include "block/block_int.h"
24
+#include "sysemu/block-backend.h"
25
#include "sysemu/replay.h"
26
#include "trace.h"
27
28
@@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState {
29
int blkshift;
30
31
uint64_t max_transfer;
32
- bool plugged;
33
34
bool supports_write_zeroes;
35
bool supports_discard;
36
@@ -XXX,XX +XXX,XX @@ static void nvme_kick(NVMeQueuePair *q)
37
{
38
BDRVNVMeState *s = q->s;
39
40
- if (s->plugged || !q->need_kick) {
41
+ if (!q->need_kick) {
42
return;
43
}
44
trace_nvme_kick(s, q->index);
45
@@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q)
46
NvmeCqe *c;
47
48
trace_nvme_process_completion(s, q->index, q->inflight);
49
- if (s->plugged) {
50
- trace_nvme_process_completion_queue_plugged(s, q->index);
51
- return false;
52
- }
53
54
/*
55
* Support re-entrancy when a request cb() function invokes aio_poll().
56
@@ -XXX,XX +XXX,XX @@ static void nvme_trace_command(const NvmeCmd *cmd)
57
}
58
}
59
60
+static void nvme_unplug_fn(void *opaque)
61
+{
62
+ NVMeQueuePair *q = opaque;
63
+
64
+ QEMU_LOCK_GUARD(&q->lock);
65
+ nvme_kick(q);
66
+ nvme_process_completion(q);
67
+}
68
+
69
static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req,
70
NvmeCmd *cmd, BlockCompletionFunc cb,
71
void *opaque)
72
@@ -XXX,XX +XXX,XX @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req,
73
q->sq.tail * NVME_SQ_ENTRY_BYTES, cmd, sizeof(*cmd));
74
q->sq.tail = (q->sq.tail + 1) % NVME_QUEUE_SIZE;
75
q->need_kick++;
76
- nvme_kick(q);
77
- nvme_process_completion(q);
78
+ blk_io_plug_call(nvme_unplug_fn, q);
79
qemu_mutex_unlock(&q->lock);
80
}
81
82
@@ -XXX,XX +XXX,XX @@ static void nvme_attach_aio_context(BlockDriverState *bs,
83
}
84
}
85
86
-static void coroutine_fn nvme_co_io_plug(BlockDriverState *bs)
87
-{
88
- BDRVNVMeState *s = bs->opaque;
89
- assert(!s->plugged);
90
- s->plugged = true;
91
-}
92
-
93
-static void coroutine_fn nvme_co_io_unplug(BlockDriverState *bs)
94
-{
95
- BDRVNVMeState *s = bs->opaque;
96
- assert(s->plugged);
97
- s->plugged = false;
98
- for (unsigned i = INDEX_IO(0); i < s->queue_count; i++) {
99
- NVMeQueuePair *q = s->queues[i];
100
- qemu_mutex_lock(&q->lock);
101
- nvme_kick(q);
102
- nvme_process_completion(q);
103
- qemu_mutex_unlock(&q->lock);
104
- }
105
-}
106
-
107
static bool nvme_register_buf(BlockDriverState *bs, void *host, size_t size,
108
Error **errp)
109
{
110
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nvme = {
111
.bdrv_detach_aio_context = nvme_detach_aio_context,
112
.bdrv_attach_aio_context = nvme_attach_aio_context,
113
114
- .bdrv_co_io_plug = nvme_co_io_plug,
115
- .bdrv_co_io_unplug = nvme_co_io_unplug,
116
-
117
.bdrv_register_buf = nvme_register_buf,
118
.bdrv_unregister_buf = nvme_unregister_buf,
119
};
120
diff --git a/block/trace-events b/block/trace-events
121
index XXXXXXX..XXXXXXX 100644
122
--- a/block/trace-events
123
+++ b/block/trace-events
124
@@ -XXX,XX +XXX,XX @@ nvme_kick(void *s, unsigned q_index) "s %p q #%u"
125
nvme_dma_flush_queue_wait(void *s) "s %p"
126
nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x"
127
nvme_process_completion(void *s, unsigned q_index, int inflight) "s %p q #%u inflight %d"
128
-nvme_process_completion_queue_plugged(void *s, unsigned q_index) "s %p q #%u"
129
nvme_complete_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d"
130
nvme_submit_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d"
131
nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x"
132
--
133
2.40.1
diff view generated by jsdifflib
New patch
1
Stop using the .bdrv_co_io_plug() API because it is not multi-queue
2
block layer friendly. Use the new blk_io_plug_call() API to batch I/O
3
submission instead.
1
4
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
8
Acked-by: Kevin Wolf <kwolf@redhat.com>
9
Message-id: 20230530180959.1108766-4-stefanha@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
block/blkio.c | 43 ++++++++++++++++++++++++-------------------
13
1 file changed, 24 insertions(+), 19 deletions(-)
14
15
diff --git a/block/blkio.c b/block/blkio.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/blkio.c
18
+++ b/block/blkio.c
19
@@ -XXX,XX +XXX,XX @@
20
#include "qemu/error-report.h"
21
#include "qapi/qmp/qdict.h"
22
#include "qemu/module.h"
23
+#include "sysemu/block-backend.h"
24
#include "exec/memory.h" /* for ram_block_discard_disable() */
25
26
#include "block/block-io.h"
27
@@ -XXX,XX +XXX,XX @@ static void blkio_detach_aio_context(BlockDriverState *bs)
28
NULL, NULL, NULL);
29
}
30
31
-/* Call with s->blkio_lock held to submit I/O after enqueuing a new request */
32
-static void blkio_submit_io(BlockDriverState *bs)
33
+/*
34
+ * Called by blk_io_unplug() or immediately if not plugged. Called without
35
+ * blkio_lock.
36
+ */
37
+static void blkio_unplug_fn(void *opaque)
38
{
39
- if (qatomic_read(&bs->io_plugged) == 0) {
40
- BDRVBlkioState *s = bs->opaque;
41
+ BDRVBlkioState *s = opaque;
42
43
+ WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
44
blkioq_do_io(s->blkioq, NULL, 0, 0, NULL);
45
}
46
}
47
48
+/*
49
+ * Schedule I/O submission after enqueuing a new request. Called without
50
+ * blkio_lock.
51
+ */
52
+static void blkio_submit_io(BlockDriverState *bs)
53
+{
54
+ BDRVBlkioState *s = bs->opaque;
55
+
56
+ blk_io_plug_call(blkio_unplug_fn, s);
57
+}
58
+
59
static int coroutine_fn
60
blkio_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
61
{
62
@@ -XXX,XX +XXX,XX @@ blkio_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
63
64
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
65
blkioq_discard(s->blkioq, offset, bytes, &cod, 0);
66
- blkio_submit_io(bs);
67
}
68
69
+ blkio_submit_io(bs);
70
qemu_coroutine_yield();
71
return cod.ret;
72
}
73
@@ -XXX,XX +XXX,XX @@ blkio_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
74
75
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
76
blkioq_readv(s->blkioq, offset, iov, iovcnt, &cod, 0);
77
- blkio_submit_io(bs);
78
}
79
80
+ blkio_submit_io(bs);
81
qemu_coroutine_yield();
82
83
if (use_bounce_buffer) {
84
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn blkio_co_pwritev(BlockDriverState *bs, int64_t offset,
85
86
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
87
blkioq_writev(s->blkioq, offset, iov, iovcnt, &cod, blkio_flags);
88
- blkio_submit_io(bs);
89
}
90
91
+ blkio_submit_io(bs);
92
qemu_coroutine_yield();
93
94
if (use_bounce_buffer) {
95
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn blkio_co_flush(BlockDriverState *bs)
96
97
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
98
blkioq_flush(s->blkioq, &cod, 0);
99
- blkio_submit_io(bs);
100
}
101
102
+ blkio_submit_io(bs);
103
qemu_coroutine_yield();
104
return cod.ret;
105
}
106
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn blkio_co_pwrite_zeroes(BlockDriverState *bs,
107
108
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
109
blkioq_write_zeroes(s->blkioq, offset, bytes, &cod, blkio_flags);
110
- blkio_submit_io(bs);
111
}
112
113
+ blkio_submit_io(bs);
114
qemu_coroutine_yield();
115
return cod.ret;
116
}
117
118
-static void coroutine_fn blkio_co_io_unplug(BlockDriverState *bs)
119
-{
120
- BDRVBlkioState *s = bs->opaque;
121
-
122
- WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
123
- blkio_submit_io(bs);
124
- }
125
-}
126
-
127
typedef enum {
128
BMRR_OK,
129
BMRR_SKIP,
130
@@ -XXX,XX +XXX,XX @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp)
131
.bdrv_co_pwritev = blkio_co_pwritev, \
132
.bdrv_co_flush_to_disk = blkio_co_flush, \
133
.bdrv_co_pwrite_zeroes = blkio_co_pwrite_zeroes, \
134
- .bdrv_co_io_unplug = blkio_co_io_unplug, \
135
.bdrv_refresh_limits = blkio_refresh_limits, \
136
.bdrv_register_buf = blkio_register_buf, \
137
.bdrv_unregister_buf = blkio_unregister_buf, \
138
--
139
2.40.1
diff view generated by jsdifflib
1
From: Su Hang <suhang16@mails.ucas.ac.cn>
1
Stop using the .bdrv_co_io_plug() API because it is not multi-queue
2
block layer friendly. Use the new blk_io_plug_call() API to batch I/O
3
submission instead.
2
4
3
only remove brackets that wrap `return` statements' content.
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4
6
Reviewed-by: Eric Blake <eblake@redhat.com>
5
use `perl -pi -e "s/return \((.*?)\);/return \1;/g" util/uri.c`
7
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
6
to remove pattern like this: "return (1);"
8
Acked-by: Kevin Wolf <kwolf@redhat.com>
7
9
Message-id: 20230530180959.1108766-5-stefanha@redhat.com
8
Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
9
Reviewed-by: Thomas Huth <thuth@redhat.com>
10
Message-id: 1519533358-13759-3-git-send-email-suhang16@mails.ucas.ac.cn
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
11
---
13
util/uri.c | 160 ++++++++++++++++++++++++++++++-------------------------------
12
include/block/raw-aio.h | 7 -------
14
1 file changed, 80 insertions(+), 80 deletions(-)
13
block/file-posix.c | 10 ----------
14
block/io_uring.c | 44 ++++++++++++++++-------------------------
15
block/trace-events | 5 ++---
16
4 files changed, 19 insertions(+), 47 deletions(-)
15
17
16
diff --git a/util/uri.c b/util/uri.c
18
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
17
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
18
--- a/util/uri.c
20
--- a/include/block/raw-aio.h
19
+++ b/util/uri.c
21
+++ b/include/block/raw-aio.h
20
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_scheme(URI *uri, const char **str)
22
@@ -XXX,XX +XXX,XX @@ int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset,
21
const char *cur;
23
QEMUIOVector *qiov, int type);
22
24
void luring_detach_aio_context(LuringState *s, AioContext *old_context);
23
if (str == NULL)
25
void luring_attach_aio_context(LuringState *s, AioContext *new_context);
24
- return (-1);
26
-
25
+ return -1;
27
-/*
26
28
- * luring_io_plug/unplug work in the thread's current AioContext, therefore the
27
cur = *str;
29
- * caller must ensure that they are paired in the same IOThread.
28
if (!ISA_ALPHA(cur))
30
- */
29
- return (2);
31
-void luring_io_plug(void);
30
+ return 2;
32
-void luring_io_unplug(void);
31
cur++;
33
#endif
32
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
34
33
(*cur == '.'))
35
#ifdef _WIN32
34
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_scheme(URI *uri, const char **str)
36
diff --git a/block/file-posix.c b/block/file-posix.c
35
uri->scheme = g_strndup(*str, cur - *str);
37
index XXXXXXX..XXXXXXX 100644
38
--- a/block/file-posix.c
39
+++ b/block/file-posix.c
40
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn raw_co_io_plug(BlockDriverState *bs)
41
laio_io_plug();
36
}
42
}
37
*str = cur;
43
#endif
38
- return (0);
44
-#ifdef CONFIG_LINUX_IO_URING
39
+ return 0;
45
- if (s->use_linux_io_uring) {
46
- luring_io_plug();
47
- }
48
-#endif
40
}
49
}
41
50
42
/**
51
static void coroutine_fn raw_co_io_unplug(BlockDriverState *bs)
43
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_fragment(URI *uri, const char **str)
52
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn raw_co_io_unplug(BlockDriverState *bs)
44
const char *cur;
53
laio_io_unplug(s->aio_max_batch);
45
46
if (str == NULL)
47
- return (-1);
48
+ return -1;
49
50
cur = *str;
51
52
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_fragment(URI *uri, const char **str)
53
uri->fragment = uri_string_unescape(*str, cur - *str, NULL);
54
}
54
}
55
*str = cur;
55
#endif
56
- return (0);
56
-#ifdef CONFIG_LINUX_IO_URING
57
+ return 0;
57
- if (s->use_linux_io_uring) {
58
- luring_io_unplug();
59
- }
60
-#endif
58
}
61
}
59
62
60
/**
63
static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs)
61
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_query(URI *uri, const char **str)
64
diff --git a/block/io_uring.c b/block/io_uring.c
62
const char *cur;
65
index XXXXXXX..XXXXXXX 100644
63
66
--- a/block/io_uring.c
64
if (str == NULL)
67
+++ b/block/io_uring.c
65
- return (-1);
68
@@ -XXX,XX +XXX,XX @@
66
+ return -1;
69
#include "block/raw-aio.h"
67
70
#include "qemu/coroutine.h"
68
cur = *str;
71
#include "qapi/error.h"
69
72
+#include "sysemu/block-backend.h"
70
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_query(URI *uri, const char **str)
73
#include "trace.h"
71
uri->query = g_strndup(*str, cur - *str);
74
75
/* Only used for assertions. */
76
@@ -XXX,XX +XXX,XX @@ typedef struct LuringAIOCB {
77
} LuringAIOCB;
78
79
typedef struct LuringQueue {
80
- int plugged;
81
unsigned int in_queue;
82
unsigned int in_flight;
83
bool blocked;
84
@@ -XXX,XX +XXX,XX @@ static void luring_process_completions_and_submit(LuringState *s)
85
{
86
luring_process_completions(s);
87
88
- if (!s->io_q.plugged && s->io_q.in_queue > 0) {
89
+ if (s->io_q.in_queue > 0) {
90
ioq_submit(s);
72
}
91
}
73
*str = cur;
74
- return (0);
75
+ return 0;
76
}
92
}
77
93
@@ -XXX,XX +XXX,XX @@ static void qemu_luring_poll_ready(void *opaque)
78
/**
94
static void ioq_init(LuringQueue *io_q)
79
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_user_info(URI *uri, const char **str)
95
{
80
uri->user = uri_string_unescape(*str, cur - *str, NULL);
96
QSIMPLEQ_INIT(&io_q->submit_queue);
81
}
97
- io_q->plugged = 0;
82
*str = cur;
98
io_q->in_queue = 0;
83
- return (0);
99
io_q->in_flight = 0;
84
+ return 0;
100
io_q->blocked = false;
101
}
102
103
-void luring_io_plug(void)
104
+static void luring_unplug_fn(void *opaque)
105
{
106
- AioContext *ctx = qemu_get_current_aio_context();
107
- LuringState *s = aio_get_linux_io_uring(ctx);
108
- trace_luring_io_plug(s);
109
- s->io_q.plugged++;
110
-}
111
-
112
-void luring_io_unplug(void)
113
-{
114
- AioContext *ctx = qemu_get_current_aio_context();
115
- LuringState *s = aio_get_linux_io_uring(ctx);
116
- assert(s->io_q.plugged);
117
- trace_luring_io_unplug(s, s->io_q.blocked, s->io_q.plugged,
118
- s->io_q.in_queue, s->io_q.in_flight);
119
- if (--s->io_q.plugged == 0 &&
120
- !s->io_q.blocked && s->io_q.in_queue > 0) {
121
+ LuringState *s = opaque;
122
+ trace_luring_unplug_fn(s, s->io_q.blocked, s->io_q.in_queue,
123
+ s->io_q.in_flight);
124
+ if (!s->io_q.blocked && s->io_q.in_queue > 0) {
125
ioq_submit(s);
85
}
126
}
86
- return (1);
87
+ return 1;
88
}
127
}
89
128
@@ -XXX,XX +XXX,XX @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s,
90
/**
129
91
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_dec_octet(const char **str)
130
QSIMPLEQ_INSERT_TAIL(&s->io_q.submit_queue, luringcb, next);
92
const char *cur = *str;
131
s->io_q.in_queue++;
93
132
- trace_luring_do_submit(s, s->io_q.blocked, s->io_q.plugged,
94
if (!(ISA_DIGIT(cur)))
133
- s->io_q.in_queue, s->io_q.in_flight);
95
- return (1);
134
- if (!s->io_q.blocked &&
96
+ return 1;
135
- (!s->io_q.plugged ||
97
if (!ISA_DIGIT(cur + 1))
136
- s->io_q.in_flight + s->io_q.in_queue >= MAX_ENTRIES)) {
98
cur++;
137
- ret = ioq_submit(s);
99
else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + 2)))
138
- trace_luring_do_submit_done(s, ret);
100
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_dec_octet(const char **str)
139
- return ret;
101
(*(cur + 1) <= '5'))
140
+ trace_luring_do_submit(s, s->io_q.blocked, s->io_q.in_queue,
102
cur += 3;
141
+ s->io_q.in_flight);
103
else
142
+ if (!s->io_q.blocked) {
104
- return (1);
143
+ if (s->io_q.in_flight + s->io_q.in_queue >= MAX_ENTRIES) {
105
+ return 1;
144
+ ret = ioq_submit(s);
106
*str = cur;
145
+ trace_luring_do_submit_done(s, ret);
107
- return (0);
146
+ return ret;
108
+ return 0;
147
+ }
148
+
149
+ blk_io_plug_call(luring_unplug_fn, s);
150
}
151
return 0;
109
}
152
}
110
/**
153
diff --git a/block/trace-events b/block/trace-events
111
* rfc3986_parse_host:
154
index XXXXXXX..XXXXXXX 100644
112
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_host(URI *uri, const char **str)
155
--- a/block/trace-events
113
while ((*cur != ']') && (*cur != 0))
156
+++ b/block/trace-events
114
cur++;
157
@@ -XXX,XX +XXX,XX @@ file_paio_submit(void *acb, void *opaque, int64_t offset, int count, int type) "
115
if (*cur != ']')
158
# io_uring.c
116
- return (1);
159
luring_init_state(void *s, size_t size) "s %p size %zu"
117
+ return 1;
160
luring_cleanup_state(void *s) "%p freed"
118
cur++;
161
-luring_io_plug(void *s) "LuringState %p plug"
119
goto found;
162
-luring_io_unplug(void *s, int blocked, int plugged, int queued, int inflight) "LuringState %p blocked %d plugged %d queued %d inflight %d"
120
}
163
-luring_do_submit(void *s, int blocked, int plugged, int queued, int inflight) "LuringState %p blocked %d plugged %d queued %d inflight %d"
121
@@ -XXX,XX +XXX,XX @@ found:
164
+luring_unplug_fn(void *s, int blocked, int queued, int inflight) "LuringState %p blocked %d queued %d inflight %d"
122
uri->server = NULL;
165
+luring_do_submit(void *s, int blocked, int queued, int inflight) "LuringState %p blocked %d queued %d inflight %d"
123
}
166
luring_do_submit_done(void *s, int ret) "LuringState %p submitted to kernel %d"
124
*str = cur;
167
luring_co_submit(void *bs, void *s, void *luringcb, int fd, uint64_t offset, size_t nbytes, int type) "bs %p s %p luringcb %p fd %d offset %" PRId64 " nbytes %zd type %d"
125
- return (0);
168
luring_process_completion(void *s, void *aiocb, int ret) "LuringState %p luringcb %p ret %d"
126
+ return 0;
127
}
128
129
/**
130
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_authority(URI *uri, const char **str)
131
cur++;
132
ret = rfc3986_parse_host(uri, &cur);
133
if (ret != 0)
134
- return (ret);
135
+ return ret;
136
if (*cur == ':') {
137
cur++;
138
ret = rfc3986_parse_port(uri, &cur);
139
if (ret != 0)
140
- return (ret);
141
+ return ret;
142
}
143
*str = cur;
144
- return (0);
145
+ return 0;
146
}
147
148
/**
149
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_segment(const char **str, char forbid, int empty)
150
cur = *str;
151
if (!ISA_PCHAR(cur)) {
152
if (empty)
153
- return (0);
154
- return (1);
155
+ return 0;
156
+ return 1;
157
}
158
while (ISA_PCHAR(cur) && (*cur != forbid))
159
NEXT(cur);
160
*str = cur;
161
- return (0);
162
+ return 0;
163
}
164
165
/**
166
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
167
cur++;
168
ret = rfc3986_parse_segment(&cur, 0, 1);
169
if (ret != 0)
170
- return (ret);
171
+ return ret;
172
}
173
if (uri != NULL) {
174
g_free(uri->path);
175
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
176
}
177
}
178
*str = cur;
179
- return (0);
180
+ return 0;
181
}
182
183
/**
184
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_absolute(URI *uri, const char **str)
185
cur = *str;
186
187
if (*cur != '/')
188
- return (1);
189
+ return 1;
190
cur++;
191
ret = rfc3986_parse_segment(&cur, 0, 0);
192
if (ret == 0) {
193
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_absolute(URI *uri, const char **str)
194
cur++;
195
ret = rfc3986_parse_segment(&cur, 0, 1);
196
if (ret != 0)
197
- return (ret);
198
+ return ret;
199
}
200
}
201
if (uri != NULL) {
202
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_absolute(URI *uri, const char **str)
203
}
204
}
205
*str = cur;
206
- return (0);
207
+ return 0;
208
}
209
210
/**
211
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_rootless(URI *uri, const char **str)
212
213
ret = rfc3986_parse_segment(&cur, 0, 0);
214
if (ret != 0)
215
- return (ret);
216
+ return ret;
217
while (*cur == '/') {
218
cur++;
219
ret = rfc3986_parse_segment(&cur, 0, 1);
220
if (ret != 0)
221
- return (ret);
222
+ return ret;
223
}
224
if (uri != NULL) {
225
g_free(uri->path);
226
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_rootless(URI *uri, const char **str)
227
}
228
}
229
*str = cur;
230
- return (0);
231
+ return 0;
232
}
233
234
/**
235
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
236
237
ret = rfc3986_parse_segment(&cur, ':', 0);
238
if (ret != 0)
239
- return (ret);
240
+ return ret;
241
while (*cur == '/') {
242
cur++;
243
ret = rfc3986_parse_segment(&cur, 0, 1);
244
if (ret != 0)
245
- return (ret);
246
+ return ret;
247
}
248
if (uri != NULL) {
249
g_free(uri->path);
250
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
251
}
252
}
253
*str = cur;
254
- return (0);
255
+ return 0;
256
}
257
258
/**
259
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_hier_part(URI *uri, const char **str)
260
cur += 2;
261
ret = rfc3986_parse_authority(uri, &cur);
262
if (ret != 0)
263
- return (ret);
264
+ return ret;
265
ret = rfc3986_parse_path_ab_empty(uri, &cur);
266
if (ret != 0)
267
- return (ret);
268
+ return ret;
269
*str = cur;
270
- return (0);
271
+ return 0;
272
} else if (*cur == '/') {
273
ret = rfc3986_parse_path_absolute(uri, &cur);
274
if (ret != 0)
275
- return (ret);
276
+ return ret;
277
} else if (ISA_PCHAR(cur)) {
278
ret = rfc3986_parse_path_rootless(uri, &cur);
279
if (ret != 0)
280
- return (ret);
281
+ return ret;
282
} else {
283
/* path-empty is effectively empty */
284
if (uri != NULL) {
285
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_hier_part(URI *uri, const char **str)
286
}
287
}
288
*str = cur;
289
- return (0);
290
+ return 0;
291
}
292
293
/**
294
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_relative_ref(URI *uri, const char *str)
295
str += 2;
296
ret = rfc3986_parse_authority(uri, &str);
297
if (ret != 0)
298
- return (ret);
299
+ return ret;
300
ret = rfc3986_parse_path_ab_empty(uri, &str);
301
if (ret != 0)
302
- return (ret);
303
+ return ret;
304
} else if (*str == '/') {
305
ret = rfc3986_parse_path_absolute(uri, &str);
306
if (ret != 0)
307
- return (ret);
308
+ return ret;
309
} else if (ISA_PCHAR(str)) {
310
ret = rfc3986_parse_path_no_scheme(uri, &str);
311
if (ret != 0)
312
- return (ret);
313
+ return ret;
314
} else {
315
/* path-empty is effectively empty */
316
if (uri != NULL) {
317
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_relative_ref(URI *uri, const char *str)
318
str++;
319
ret = rfc3986_parse_query(uri, &str);
320
if (ret != 0)
321
- return (ret);
322
+ return ret;
323
}
324
if (*str == '#') {
325
str++;
326
ret = rfc3986_parse_fragment(uri, &str);
327
if (ret != 0)
328
- return (ret);
329
+ return ret;
330
}
331
if (*str != 0) {
332
uri_clean(uri);
333
- return (1);
334
+ return 1;
335
}
336
- return (0);
337
+ return 0;
338
}
339
340
/**
341
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse(URI *uri, const char *str)
342
343
ret = rfc3986_parse_scheme(uri, &str);
344
if (ret != 0)
345
- return (ret);
346
+ return ret;
347
if (*str != ':') {
348
- return (1);
349
+ return 1;
350
}
351
str++;
352
ret = rfc3986_parse_hier_part(uri, &str);
353
if (ret != 0)
354
- return (ret);
355
+ return ret;
356
if (*str == '?') {
357
str++;
358
ret = rfc3986_parse_query(uri, &str);
359
if (ret != 0)
360
- return (ret);
361
+ return ret;
362
}
363
if (*str == '#') {
364
str++;
365
ret = rfc3986_parse_fragment(uri, &str);
366
if (ret != 0)
367
- return (ret);
368
+ return ret;
369
}
370
if (*str != 0) {
371
uri_clean(uri);
372
- return (1);
373
+ return 1;
374
}
375
- return (0);
376
+ return 0;
377
}
378
379
/**
380
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_uri_reference(URI *uri, const char *str)
381
int ret;
382
383
if (str == NULL)
384
- return (-1);
385
+ return -1;
386
uri_clean(uri);
387
388
/*
389
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_uri_reference(URI *uri, const char *str)
390
ret = rfc3986_parse_relative_ref(uri, str);
391
if (ret != 0) {
392
uri_clean(uri);
393
- return (ret);
394
+ return ret;
395
}
396
}
397
- return (0);
398
+ return 0;
399
}
400
401
/**
402
@@ -XXX,XX +XXX,XX @@ URI *uri_parse(const char *str)
403
int ret;
404
405
if (str == NULL)
406
- return (NULL);
407
+ return NULL;
408
uri = uri_new();
409
ret = rfc3986_parse_uri_reference(uri, str);
410
if (ret) {
411
uri_free(uri);
412
- return (NULL);
413
+ return NULL;
414
}
415
- return (uri);
416
+ return uri;
417
}
418
419
/**
420
@@ -XXX,XX +XXX,XX @@ URI *uri_parse(const char *str)
421
*/
422
int uri_parse_into(URI *uri, const char *str)
423
{
424
- return (rfc3986_parse_uri_reference(uri, str));
425
+ return rfc3986_parse_uri_reference(uri, str);
426
}
427
428
/**
429
@@ -XXX,XX +XXX,XX @@ URI *uri_parse_raw(const char *str, int raw)
430
int ret;
431
432
if (str == NULL)
433
- return (NULL);
434
+ return NULL;
435
uri = uri_new();
436
if (raw) {
437
uri->cleanup |= 2;
438
@@ -XXX,XX +XXX,XX @@ URI *uri_parse_raw(const char *str, int raw)
439
ret = uri_parse_into(uri, str);
440
if (ret) {
441
uri_free(uri);
442
- return (NULL);
443
+ return NULL;
444
}
445
- return (uri);
446
+ return uri;
447
}
448
449
/************************************************************************
450
@@ -XXX,XX +XXX,XX @@ URI *uri_new(void)
451
URI *ret;
452
453
ret = g_new0(URI, 1);
454
- return (ret);
455
+ return ret;
456
}
457
458
/**
459
@@ -XXX,XX +XXX,XX @@ static char *realloc2n(char *ret, int *max)
460
tmp = *max * 2;
461
temp = g_realloc(ret, (tmp + 1));
462
*max = tmp;
463
- return (temp);
464
+ return temp;
465
}
466
467
/**
468
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
469
int max;
470
471
if (uri == NULL)
472
- return (NULL);
473
+ return NULL;
474
475
max = 80;
476
ret = g_malloc(max + 1);
477
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
478
ret = temp;
479
}
480
ret[len] = 0;
481
- return (ret);
482
+ return ret;
483
}
484
485
/**
486
@@ -XXX,XX +XXX,XX @@ static int normalize_uri_path(char *path)
487
char *cur, *out;
488
489
if (path == NULL)
490
- return (-1);
491
+ return -1;
492
493
/* Skip all initial "/" chars. We want to get to the beginning of the
494
* first non-empty segment.
495
@@ -XXX,XX +XXX,XX @@ static int normalize_uri_path(char *path)
496
while (cur[0] == '/')
497
++cur;
498
if (cur[0] == '\0')
499
- return (0);
500
+ return 0;
501
502
/* Keep everything we've seen so far. */
503
out = cur;
504
@@ -XXX,XX +XXX,XX @@ done_cd:
505
while (cur[0] == '/')
506
++cur;
507
if (cur[0] == '\0')
508
- return (0);
509
+ return 0;
510
511
/*
512
* Analyze each segment in sequence for cases (e) and (f).
513
@@ -XXX,XX +XXX,XX @@ done_cd:
514
}
515
}
516
517
- return (0);
518
+ return 0;
519
}
520
521
static int is_hex(char c)
522
{
523
if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
524
((c >= 'A') && (c <= 'F')))
525
- return (1);
526
- return (0);
527
+ return 1;
528
+ return 0;
529
}
530
531
/**
532
@@ -XXX,XX +XXX,XX @@ char *uri_string_unescape(const char *str, int len, char *target)
533
const char *in;
534
535
if (str == NULL)
536
- return (NULL);
537
+ return NULL;
538
if (len <= 0)
539
len = strlen(str);
540
if (len < 0)
541
- return (NULL);
542
+ return NULL;
543
544
if (target == NULL) {
545
ret = g_malloc(len + 1);
546
@@ -XXX,XX +XXX,XX @@ char *uri_string_unescape(const char *str, int len, char *target)
547
}
548
}
549
*out = 0;
550
- return (ret);
551
+ return ret;
552
}
553
554
/**
555
@@ -XXX,XX +XXX,XX @@ char *uri_string_escape(const char *str, const char *list)
556
int len, out;
557
558
if (str == NULL)
559
- return (NULL);
560
+ return NULL;
561
if (str[0] == 0)
562
- return (g_strdup(str));
563
+ return g_strdup(str);
564
len = strlen(str);
565
if (!(len > 0))
566
- return (NULL);
567
+ return NULL;
568
569
len += 20;
570
ret = g_malloc(len);
571
@@ -XXX,XX +XXX,XX @@ char *uri_string_escape(const char *str, const char *list)
572
}
573
}
574
ret[out] = 0;
575
- return (ret);
576
+ return ret;
577
}
578
579
/************************************************************************
580
@@ -XXX,XX +XXX,XX @@ done:
581
uri_free(bas);
582
if (res != NULL)
583
uri_free(res);
584
- return (val);
585
+ return val;
586
}
587
588
/**
589
--
169
--
590
2.14.3
170
2.40.1
591
592
diff view generated by jsdifflib
1
From: Su Hang <suhang16@mails.ucas.ac.cn>
1
Stop using the .bdrv_co_io_plug() API because it is not multi-queue
2
2
block layer friendly. Use the new blk_io_plug_call() API to batch I/O
3
For this patch, using curly braces to wrap `if` `while` `else` statements,
3
submission instead.
4
which only hold single statement. For example:
4
5
'''
5
Note that a dev_max_batch check is dropped in laio_io_unplug() because
6
if (cond)
6
the semantics of unplug_fn() are different from .bdrv_co_unplug():
7
statement;
7
1. unplug_fn() is only called when the last blk_io_unplug() call occurs,
8
'''
8
not every time blk_io_unplug() is called.
9
to
9
2. unplug_fn() is per-thread, not per-BlockDriverState, so there is no
10
'''
10
way to get per-BlockDriverState fields like dev_max_batch.
11
if (cond) {
11
12
statement;
12
Therefore this condition cannot be moved to laio_unplug_fn(). It is not
13
}
13
obvious that this condition affects performance in practice, so I am
14
'''
14
removing it instead of trying to come up with a more complex mechanism
15
15
to preserve the condition.
16
And using tricks that compare the disassemblies before and after
16
17
code changes, to make sure code logic isn't changed:
17
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
'''
18
Reviewed-by: Eric Blake <eblake@redhat.com>
19
git checkout master
19
Acked-by: Kevin Wolf <kwolf@redhat.com>
20
make util/uri.o
20
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
21
strip util/uri.o
21
Message-id: 20230530180959.1108766-6-stefanha@redhat.com
22
objdump -Drx util/uri.o > /tmp/uri-master.txt
23
git checkout cleanupbranch
24
make util/uri.o
25
strip util/uri.o
26
objdump -Drx util/uri.o > /tmp/uri-cleanup.txt
27
28
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
22
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
29
---
23
---
30
util/uri.c | 463 +++++++++++++++++++++++++++++++++++++++----------------------
24
include/block/raw-aio.h | 7 -------
31
1 file changed, 294 insertions(+), 169 deletions(-)
25
block/file-posix.c | 28 ----------------------------
32
26
block/linux-aio.c | 41 +++++++++++------------------------------
33
diff --git a/util/uri.c b/util/uri.c
27
3 files changed, 11 insertions(+), 65 deletions(-)
28
29
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
34
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
35
--- a/util/uri.c
31
--- a/include/block/raw-aio.h
36
+++ b/util/uri.c
32
+++ b/include/block/raw-aio.h
37
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_scheme(URI *uri, const char **str)
33
@@ -XXX,XX +XXX,XX @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov,
38
{
34
39
const char *cur;
35
void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context);
40
36
void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context);
41
- if (str == NULL)
37
-
42
+ if (str == NULL) {
38
-/*
43
return -1;
39
- * laio_io_plug/unplug work in the thread's current AioContext, therefore the
44
+ }
40
- * caller must ensure that they are paired in the same IOThread.
45
41
- */
46
cur = *str;
42
-void laio_io_plug(void);
47
- if (!ISA_ALPHA(cur))
43
-void laio_io_unplug(uint64_t dev_max_batch);
48
+ if (!ISA_ALPHA(cur)) {
44
#endif
49
return 2;
45
/* io_uring.c - Linux io_uring implementation */
50
+ }
46
#ifdef CONFIG_LINUX_IO_URING
51
cur++;
47
diff --git a/block/file-posix.c b/block/file-posix.c
52
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
48
index XXXXXXX..XXXXXXX 100644
53
- (*cur == '.'))
49
--- a/block/file-posix.c
54
+ (*cur == '.')) {
50
+++ b/block/file-posix.c
55
cur++;
51
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offset,
56
+ }
52
return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_WRITE);
57
if (uri != NULL) {
53
}
58
g_free(uri->scheme);
54
59
uri->scheme = g_strndup(*str, cur - *str);
55
-static void coroutine_fn raw_co_io_plug(BlockDriverState *bs)
60
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_fragment(URI *uri, const char **str)
56
-{
61
{
57
- BDRVRawState __attribute__((unused)) *s = bs->opaque;
62
const char *cur;
58
-#ifdef CONFIG_LINUX_AIO
63
59
- if (s->use_linux_aio) {
64
- if (str == NULL)
60
- laio_io_plug();
65
+ if (str == NULL) {
61
- }
66
return -1;
62
-#endif
67
+ }
63
-}
68
64
-
69
cur = *str;
65
-static void coroutine_fn raw_co_io_unplug(BlockDriverState *bs)
70
66
-{
71
while ((ISA_PCHAR(cur)) || (*cur == '/') || (*cur == '?') ||
67
- BDRVRawState __attribute__((unused)) *s = bs->opaque;
72
(*cur == '[') || (*cur == ']') ||
68
-#ifdef CONFIG_LINUX_AIO
73
- ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))
69
- if (s->use_linux_aio) {
74
+ ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) {
70
- laio_io_unplug(s->aio_max_batch);
75
NEXT(cur);
71
- }
76
+ }
72
-#endif
77
if (uri != NULL) {
73
-}
78
g_free(uri->fragment);
74
-
79
- if (uri->cleanup & 2)
75
static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs)
80
+ if (uri->cleanup & 2) {
76
{
81
uri->fragment = g_strndup(*str, cur - *str);
77
BDRVRawState *s = bs->opaque;
82
- else
78
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
79
.bdrv_co_copy_range_from = raw_co_copy_range_from,
80
.bdrv_co_copy_range_to = raw_co_copy_range_to,
81
.bdrv_refresh_limits = raw_refresh_limits,
82
- .bdrv_co_io_plug = raw_co_io_plug,
83
- .bdrv_co_io_unplug = raw_co_io_unplug,
84
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
85
86
.bdrv_co_truncate = raw_co_truncate,
87
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_device = {
88
.bdrv_co_copy_range_from = raw_co_copy_range_from,
89
.bdrv_co_copy_range_to = raw_co_copy_range_to,
90
.bdrv_refresh_limits = raw_refresh_limits,
91
- .bdrv_co_io_plug = raw_co_io_plug,
92
- .bdrv_co_io_unplug = raw_co_io_unplug,
93
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
94
95
.bdrv_co_truncate = raw_co_truncate,
96
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_cdrom = {
97
.bdrv_co_pwritev = raw_co_pwritev,
98
.bdrv_co_flush_to_disk = raw_co_flush_to_disk,
99
.bdrv_refresh_limits = cdrom_refresh_limits,
100
- .bdrv_co_io_plug = raw_co_io_plug,
101
- .bdrv_co_io_unplug = raw_co_io_unplug,
102
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
103
104
.bdrv_co_truncate = raw_co_truncate,
105
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_cdrom = {
106
.bdrv_co_pwritev = raw_co_pwritev,
107
.bdrv_co_flush_to_disk = raw_co_flush_to_disk,
108
.bdrv_refresh_limits = cdrom_refresh_limits,
109
- .bdrv_co_io_plug = raw_co_io_plug,
110
- .bdrv_co_io_unplug = raw_co_io_unplug,
111
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
112
113
.bdrv_co_truncate = raw_co_truncate,
114
diff --git a/block/linux-aio.c b/block/linux-aio.c
115
index XXXXXXX..XXXXXXX 100644
116
--- a/block/linux-aio.c
117
+++ b/block/linux-aio.c
118
@@ -XXX,XX +XXX,XX @@
119
#include "qemu/event_notifier.h"
120
#include "qemu/coroutine.h"
121
#include "qapi/error.h"
122
+#include "sysemu/block-backend.h"
123
124
/* Only used for assertions. */
125
#include "qemu/coroutine_int.h"
126
@@ -XXX,XX +XXX,XX @@ struct qemu_laiocb {
127
};
128
129
typedef struct {
130
- int plugged;
131
unsigned int in_queue;
132
unsigned int in_flight;
133
bool blocked;
134
@@ -XXX,XX +XXX,XX @@ static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
135
{
136
qemu_laio_process_completions(s);
137
138
- if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
139
+ if (!QSIMPLEQ_EMPTY(&s->io_q.pending)) {
140
ioq_submit(s);
141
}
142
}
143
@@ -XXX,XX +XXX,XX @@ static void qemu_laio_poll_ready(EventNotifier *opaque)
144
static void ioq_init(LaioQueue *io_q)
145
{
146
QSIMPLEQ_INIT(&io_q->pending);
147
- io_q->plugged = 0;
148
io_q->in_queue = 0;
149
io_q->in_flight = 0;
150
io_q->blocked = false;
151
@@ -XXX,XX +XXX,XX @@ static uint64_t laio_max_batch(LinuxAioState *s, uint64_t dev_max_batch)
152
return max_batch;
153
}
154
155
-void laio_io_plug(void)
156
+static void laio_unplug_fn(void *opaque)
157
{
158
- AioContext *ctx = qemu_get_current_aio_context();
159
- LinuxAioState *s = aio_get_linux_aio(ctx);
160
+ LinuxAioState *s = opaque;
161
162
- s->io_q.plugged++;
163
-}
164
-
165
-void laio_io_unplug(uint64_t dev_max_batch)
166
-{
167
- AioContext *ctx = qemu_get_current_aio_context();
168
- LinuxAioState *s = aio_get_linux_aio(ctx);
169
-
170
- assert(s->io_q.plugged);
171
- s->io_q.plugged--;
172
-
173
- /*
174
- * Why max batch checking is performed here:
175
- * Another BDS may have queued requests with a higher dev_max_batch and
176
- * therefore in_queue could now exceed our dev_max_batch. Re-check the max
177
- * batch so we can honor our device's dev_max_batch.
178
- */
179
- if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch) ||
180
- (!s->io_q.plugged &&
181
- !s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending))) {
182
+ if (!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
183
ioq_submit(s);
184
}
185
}
186
@@ -XXX,XX +XXX,XX @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
187
188
QSIMPLEQ_INSERT_TAIL(&s->io_q.pending, laiocb, next);
189
s->io_q.in_queue++;
190
- if (!s->io_q.blocked &&
191
- (!s->io_q.plugged ||
192
- s->io_q.in_queue >= laio_max_batch(s, dev_max_batch))) {
193
- ioq_submit(s);
194
+ if (!s->io_q.blocked) {
195
+ if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch)) {
196
+ ioq_submit(s);
83
+ } else {
197
+ } else {
84
uri->fragment = uri_string_unescape(*str, cur - *str, NULL);
198
+ blk_io_plug_call(laio_unplug_fn, s);
85
+ }
199
+ }
86
}
200
}
87
*str = cur;
201
88
return 0;
202
return 0;
89
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_query(URI *uri, const char **str)
90
{
91
const char *cur;
92
93
- if (str == NULL)
94
+ if (str == NULL) {
95
return -1;
96
+ }
97
98
cur = *str;
99
100
while ((ISA_PCHAR(cur)) || (*cur == '/') || (*cur == '?') ||
101
- ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))
102
+ ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) {
103
NEXT(cur);
104
+ }
105
if (uri != NULL) {
106
g_free(uri->query);
107
uri->query = g_strndup(*str, cur - *str);
108
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_user_info(URI *uri, const char **str)
109
110
cur = *str;
111
while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur) ||
112
- (*cur == ':'))
113
+ (*cur == ':')) {
114
NEXT(cur);
115
+ }
116
if (*cur == '@') {
117
if (uri != NULL) {
118
g_free(uri->user);
119
- if (uri->cleanup & 2)
120
+ if (uri->cleanup & 2) {
121
uri->user = g_strndup(*str, cur - *str);
122
- else
123
+ } else {
124
uri->user = uri_string_unescape(*str, cur - *str, NULL);
125
+ }
126
}
127
*str = cur;
128
return 0;
129
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_dec_octet(const char **str)
130
{
131
const char *cur = *str;
132
133
- if (!(ISA_DIGIT(cur)))
134
+ if (!(ISA_DIGIT(cur))) {
135
return 1;
136
- if (!ISA_DIGIT(cur + 1))
137
+ }
138
+ if (!ISA_DIGIT(cur + 1)) {
139
cur++;
140
- else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + 2)))
141
+ } else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + 2))) {
142
cur += 2;
143
- else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2)))
144
+ } else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2))) {
145
cur += 3;
146
- else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') &&
147
- (ISA_DIGIT(cur + 2)))
148
+ } else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') &&
149
+ (ISA_DIGIT(cur + 2))) {
150
cur += 3;
151
- else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') &&
152
- (*(cur + 1) <= '5'))
153
+ } else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') &&
154
+ (*(cur + 1) <= '5')) {
155
cur += 3;
156
- else
157
+ } else {
158
return 1;
159
+ }
160
*str = cur;
161
return 0;
162
}
163
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_host(URI *uri, const char **str)
164
*/
165
if (*cur == '[') {
166
cur++;
167
- while ((*cur != ']') && (*cur != 0))
168
+ while ((*cur != ']') && (*cur != 0)) {
169
cur++;
170
- if (*cur != ']')
171
+ }
172
+ if (*cur != ']') {
173
return 1;
174
+ }
175
cur++;
176
goto found;
177
}
178
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_host(URI *uri, const char **str)
179
* try to parse an IPv4
180
*/
181
if (ISA_DIGIT(cur)) {
182
- if (rfc3986_parse_dec_octet(&cur) != 0)
183
+ if (rfc3986_parse_dec_octet(&cur) != 0) {
184
goto not_ipv4;
185
- if (*cur != '.')
186
+ }
187
+ if (*cur != '.') {
188
goto not_ipv4;
189
+ }
190
cur++;
191
- if (rfc3986_parse_dec_octet(&cur) != 0)
192
+ if (rfc3986_parse_dec_octet(&cur) != 0) {
193
goto not_ipv4;
194
- if (*cur != '.')
195
+ }
196
+ if (*cur != '.') {
197
goto not_ipv4;
198
- if (rfc3986_parse_dec_octet(&cur) != 0)
199
+ }
200
+ if (rfc3986_parse_dec_octet(&cur) != 0) {
201
goto not_ipv4;
202
- if (*cur != '.')
203
+ }
204
+ if (*cur != '.') {
205
goto not_ipv4;
206
- if (rfc3986_parse_dec_octet(&cur) != 0)
207
+ }
208
+ if (rfc3986_parse_dec_octet(&cur) != 0) {
209
goto not_ipv4;
210
+ }
211
goto found;
212
not_ipv4:
213
cur = *str;
214
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_host(URI *uri, const char **str)
215
/*
216
* then this should be a hostname which can be empty
217
*/
218
- while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur))
219
+ while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur)) {
220
NEXT(cur);
221
+ }
222
found:
223
if (uri != NULL) {
224
g_free(uri->authority);
225
uri->authority = NULL;
226
g_free(uri->server);
227
if (cur != host) {
228
- if (uri->cleanup & 2)
229
+ if (uri->cleanup & 2) {
230
uri->server = g_strndup(host, cur - host);
231
- else
232
+ } else {
233
uri->server = uri_string_unescape(host, cur - host, NULL);
234
- } else
235
+ }
236
+ } else {
237
uri->server = NULL;
238
+ }
239
}
240
*str = cur;
241
return 0;
242
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_authority(URI *uri, const char **str)
243
* try to parse a userinfo and check for the trailing @
244
*/
245
ret = rfc3986_parse_user_info(uri, &cur);
246
- if ((ret != 0) || (*cur != '@'))
247
+ if ((ret != 0) || (*cur != '@')) {
248
cur = *str;
249
- else
250
+ } else {
251
cur++;
252
+ }
253
ret = rfc3986_parse_host(uri, &cur);
254
- if (ret != 0)
255
+ if (ret != 0) {
256
return ret;
257
+ }
258
if (*cur == ':') {
259
cur++;
260
ret = rfc3986_parse_port(uri, &cur);
261
- if (ret != 0)
262
+ if (ret != 0) {
263
return ret;
264
+ }
265
}
266
*str = cur;
267
return 0;
268
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_segment(const char **str, char forbid, int empty)
269
270
cur = *str;
271
if (!ISA_PCHAR(cur)) {
272
- if (empty)
273
+ if (empty) {
274
return 0;
275
+ }
276
return 1;
277
}
278
- while (ISA_PCHAR(cur) && (*cur != forbid))
279
+ while (ISA_PCHAR(cur) && (*cur != forbid)) {
280
NEXT(cur);
281
+ }
282
*str = cur;
283
return 0;
284
}
285
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
286
while (*cur == '/') {
287
cur++;
288
ret = rfc3986_parse_segment(&cur, 0, 1);
289
- if (ret != 0)
290
+ if (ret != 0) {
291
return ret;
292
+ }
293
}
294
if (uri != NULL) {
295
g_free(uri->path);
296
if (*str != cur) {
297
- if (uri->cleanup & 2)
298
+ if (uri->cleanup & 2) {
299
uri->path = g_strndup(*str, cur - *str);
300
- else
301
+ } else {
302
uri->path = uri_string_unescape(*str, cur - *str, NULL);
303
+ }
304
} else {
305
uri->path = NULL;
306
}
307
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_absolute(URI *uri, const char **str)
308
309
cur = *str;
310
311
- if (*cur != '/')
312
+ if (*cur != '/') {
313
return 1;
314
+ }
315
cur++;
316
ret = rfc3986_parse_segment(&cur, 0, 0);
317
if (ret == 0) {
318
while (*cur == '/') {
319
cur++;
320
ret = rfc3986_parse_segment(&cur, 0, 1);
321
- if (ret != 0)
322
+ if (ret != 0) {
323
return ret;
324
+ }
325
}
326
}
327
if (uri != NULL) {
328
g_free(uri->path);
329
if (cur != *str) {
330
- if (uri->cleanup & 2)
331
+ if (uri->cleanup & 2) {
332
uri->path = g_strndup(*str, cur - *str);
333
- else
334
+ } else {
335
uri->path = uri_string_unescape(*str, cur - *str, NULL);
336
+ }
337
} else {
338
uri->path = NULL;
339
}
340
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_rootless(URI *uri, const char **str)
341
cur = *str;
342
343
ret = rfc3986_parse_segment(&cur, 0, 0);
344
- if (ret != 0)
345
+ if (ret != 0) {
346
return ret;
347
+ }
348
while (*cur == '/') {
349
cur++;
350
ret = rfc3986_parse_segment(&cur, 0, 1);
351
- if (ret != 0)
352
+ if (ret != 0) {
353
return ret;
354
+ }
355
}
356
if (uri != NULL) {
357
g_free(uri->path);
358
if (cur != *str) {
359
- if (uri->cleanup & 2)
360
+ if (uri->cleanup & 2) {
361
uri->path = g_strndup(*str, cur - *str);
362
- else
363
+ } else {
364
uri->path = uri_string_unescape(*str, cur - *str, NULL);
365
+ }
366
} else {
367
uri->path = NULL;
368
}
369
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
370
cur = *str;
371
372
ret = rfc3986_parse_segment(&cur, ':', 0);
373
- if (ret != 0)
374
+ if (ret != 0) {
375
return ret;
376
+ }
377
while (*cur == '/') {
378
cur++;
379
ret = rfc3986_parse_segment(&cur, 0, 1);
380
- if (ret != 0)
381
+ if (ret != 0) {
382
return ret;
383
+ }
384
}
385
if (uri != NULL) {
386
g_free(uri->path);
387
if (cur != *str) {
388
- if (uri->cleanup & 2)
389
+ if (uri->cleanup & 2) {
390
uri->path = g_strndup(*str, cur - *str);
391
- else
392
+ } else {
393
uri->path = uri_string_unescape(*str, cur - *str, NULL);
394
+ }
395
} else {
396
uri->path = NULL;
397
}
398
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_hier_part(URI *uri, const char **str)
399
if ((*cur == '/') && (*(cur + 1) == '/')) {
400
cur += 2;
401
ret = rfc3986_parse_authority(uri, &cur);
402
- if (ret != 0)
403
+ if (ret != 0) {
404
return ret;
405
+ }
406
ret = rfc3986_parse_path_ab_empty(uri, &cur);
407
- if (ret != 0)
408
+ if (ret != 0) {
409
return ret;
410
+ }
411
*str = cur;
412
return 0;
413
} else if (*cur == '/') {
414
ret = rfc3986_parse_path_absolute(uri, &cur);
415
- if (ret != 0)
416
+ if (ret != 0) {
417
return ret;
418
+ }
419
} else if (ISA_PCHAR(cur)) {
420
ret = rfc3986_parse_path_rootless(uri, &cur);
421
- if (ret != 0)
422
+ if (ret != 0) {
423
return ret;
424
+ }
425
} else {
426
/* path-empty is effectively empty */
427
if (uri != NULL) {
428
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_relative_ref(URI *uri, const char *str)
429
if ((*str == '/') && (*(str + 1) == '/')) {
430
str += 2;
431
ret = rfc3986_parse_authority(uri, &str);
432
- if (ret != 0)
433
+ if (ret != 0) {
434
return ret;
435
+ }
436
ret = rfc3986_parse_path_ab_empty(uri, &str);
437
- if (ret != 0)
438
+ if (ret != 0) {
439
return ret;
440
+ }
441
} else if (*str == '/') {
442
ret = rfc3986_parse_path_absolute(uri, &str);
443
- if (ret != 0)
444
+ if (ret != 0) {
445
return ret;
446
+ }
447
} else if (ISA_PCHAR(str)) {
448
ret = rfc3986_parse_path_no_scheme(uri, &str);
449
- if (ret != 0)
450
+ if (ret != 0) {
451
return ret;
452
+ }
453
} else {
454
/* path-empty is effectively empty */
455
if (uri != NULL) {
456
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_relative_ref(URI *uri, const char *str)
457
if (*str == '?') {
458
str++;
459
ret = rfc3986_parse_query(uri, &str);
460
- if (ret != 0)
461
+ if (ret != 0) {
462
return ret;
463
+ }
464
}
465
if (*str == '#') {
466
str++;
467
ret = rfc3986_parse_fragment(uri, &str);
468
- if (ret != 0)
469
+ if (ret != 0) {
470
return ret;
471
+ }
472
}
473
if (*str != 0) {
474
uri_clean(uri);
475
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse(URI *uri, const char *str)
476
int ret;
477
478
ret = rfc3986_parse_scheme(uri, &str);
479
- if (ret != 0)
480
+ if (ret != 0) {
481
return ret;
482
+ }
483
if (*str != ':') {
484
return 1;
485
}
486
str++;
487
ret = rfc3986_parse_hier_part(uri, &str);
488
- if (ret != 0)
489
+ if (ret != 0) {
490
return ret;
491
+ }
492
if (*str == '?') {
493
str++;
494
ret = rfc3986_parse_query(uri, &str);
495
- if (ret != 0)
496
+ if (ret != 0) {
497
return ret;
498
+ }
499
}
500
if (*str == '#') {
501
str++;
502
ret = rfc3986_parse_fragment(uri, &str);
503
- if (ret != 0)
504
+ if (ret != 0) {
505
return ret;
506
+ }
507
}
508
if (*str != 0) {
509
uri_clean(uri);
510
@@ -XXX,XX +XXX,XX @@ static int rfc3986_parse_uri_reference(URI *uri, const char *str)
511
{
512
int ret;
513
514
- if (str == NULL)
515
+ if (str == NULL) {
516
return -1;
517
+ }
518
uri_clean(uri);
519
520
/*
521
@@ -XXX,XX +XXX,XX @@ URI *uri_parse(const char *str)
522
URI *uri;
523
int ret;
524
525
- if (str == NULL)
526
+ if (str == NULL) {
527
return NULL;
528
+ }
529
uri = uri_new();
530
ret = rfc3986_parse_uri_reference(uri, str);
531
if (ret) {
532
@@ -XXX,XX +XXX,XX @@ URI *uri_parse_raw(const char *str, int raw)
533
URI *uri;
534
int ret;
535
536
- if (str == NULL)
537
+ if (str == NULL) {
538
return NULL;
539
+ }
540
uri = uri_new();
541
if (raw) {
542
uri->cleanup |= 2;
543
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
544
int len;
545
int max;
546
547
- if (uri == NULL)
548
+ if (uri == NULL) {
549
return NULL;
550
+ }
551
552
max = 80;
553
ret = g_malloc(max + 1);
554
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
555
temp = realloc2n(ret, &max);
556
ret = temp;
557
}
558
- if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
559
+ if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) {
560
ret[len++] = *p++;
561
- else {
562
+ } else {
563
int val = *(unsigned char *)p++;
564
int hi = val / 0x10, lo = val % 0x10;
565
ret[len++] = '%';
566
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
567
}
568
if ((IS_UNRESERVED(*(p))) || ((*(p) == ';')) ||
569
((*(p) == ':')) || ((*(p) == '&')) || ((*(p) == '=')) ||
570
- ((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ',')))
571
+ ((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ','))) {
572
ret[len++] = *p++;
573
- else {
574
+ } else {
575
int val = *(unsigned char *)p++;
576
int hi = val / 0x10, lo = val % 0x10;
577
ret[len++] = '%';
578
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
579
if ((IS_UNRESERVED(*(p))) || ((*(p) == '$')) ||
580
((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == ':')) ||
581
((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == '=')) ||
582
- ((*(p) == '+')))
583
+ ((*(p) == '+'))) {
584
ret[len++] = *p++;
585
- else {
586
+ } else {
587
int val = *(unsigned char *)p++;
588
int hi = val / 0x10, lo = val % 0x10;
589
ret[len++] = '%';
590
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
591
if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
592
((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
593
((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) ||
594
- ((*(p) == ',')))
595
+ ((*(p) == ','))) {
596
ret[len++] = *p++;
597
- else {
598
+ } else {
599
int val = *(unsigned char *)p++;
600
int hi = val / 0x10, lo = val % 0x10;
601
ret[len++] = '%';
602
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
603
temp = realloc2n(ret, &max);
604
ret = temp;
605
}
606
- if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
607
+ if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) {
608
ret[len++] = *p++;
609
- else {
610
+ } else {
611
int val = *(unsigned char *)p++;
612
int hi = val / 0x10, lo = val % 0x10;
613
ret[len++] = '%';
614
@@ -XXX,XX +XXX,XX @@ char *uri_to_string(URI *uri)
615
*/
616
static void uri_clean(URI *uri)
617
{
618
- if (uri == NULL)
619
+ if (uri == NULL) {
620
return;
621
+ }
622
623
g_free(uri->scheme);
624
uri->scheme = NULL;
625
@@ -XXX,XX +XXX,XX @@ static int normalize_uri_path(char *path)
626
{
627
char *cur, *out;
628
629
- if (path == NULL)
630
+ if (path == NULL) {
631
return -1;
632
+ }
633
634
/* Skip all initial "/" chars. We want to get to the beginning of the
635
* first non-empty segment.
636
*/
637
cur = path;
638
- while (cur[0] == '/')
639
+ while (cur[0] == '/') {
640
++cur;
641
- if (cur[0] == '\0')
642
+ }
643
+ if (cur[0] == '\0') {
644
return 0;
645
+ }
646
647
/* Keep everything we've seen so far. */
648
out = cur;
649
@@ -XXX,XX +XXX,XX @@ static int normalize_uri_path(char *path)
650
if ((cur[0] == '.') && (cur[1] == '/')) {
651
cur += 2;
652
/* '//' normalization should be done at this point too */
653
- while (cur[0] == '/')
654
+ while (cur[0] == '/') {
655
cur++;
656
+ }
657
continue;
658
}
659
660
@@ -XXX,XX +XXX,XX @@ static int normalize_uri_path(char *path)
661
* d) If the buffer string ends with "." as a complete path segment,
662
* that "." is removed.
663
*/
664
- if ((cur[0] == '.') && (cur[1] == '\0'))
665
+ if ((cur[0] == '.') && (cur[1] == '\0')) {
666
break;
667
+ }
668
669
/* Otherwise keep the segment. */
670
while (cur[0] != '/') {
671
- if (cur[0] == '\0')
672
+ if (cur[0] == '\0') {
673
goto done_cd;
674
+ }
675
(out++)[0] = (cur++)[0];
676
}
677
/* nomalize // */
678
- while ((cur[0] == '/') && (cur[1] == '/'))
679
+ while ((cur[0] == '/') && (cur[1] == '/')) {
680
cur++;
681
+ }
682
683
(out++)[0] = (cur++)[0];
684
}
685
@@ -XXX,XX +XXX,XX @@ done_cd:
686
687
/* Reset to the beginning of the first segment for the next sequence. */
688
cur = path;
689
- while (cur[0] == '/')
690
+ while (cur[0] == '/') {
691
++cur;
692
- if (cur[0] == '\0')
693
+ }
694
+ if (cur[0] == '\0') {
695
return 0;
696
+ }
697
698
/*
699
* Analyze each segment in sequence for cases (e) and (f).
700
@@ -XXX,XX +XXX,XX @@ done_cd:
701
702
/* Find the end of the current segment. */
703
segp = cur;
704
- while ((segp[0] != '/') && (segp[0] != '\0'))
705
+ while ((segp[0] != '/') && (segp[0] != '\0')) {
706
++segp;
707
+ }
708
709
/* If this is the last segment, we're done (we need at least two
710
* segments to meet the criteria for the (e) and (f) cases).
711
*/
712
- if (segp[0] == '\0')
713
+ if (segp[0] == '\0') {
714
break;
715
+ }
716
717
/* If the first segment is "..", or if the next segment _isn't_ "..",
718
* keep this segment and try the next one.
719
@@ -XXX,XX +XXX,XX @@ done_cd:
720
/* string will overlap, do not use strcpy */
721
tmp = cur;
722
segp += 3;
723
- while ((*tmp++ = *segp++) != 0)
724
- ;
725
+ while ((*tmp++ = *segp++) != 0) {
726
+ /* No further work */
727
+ }
728
729
/* If there are no previous segments, then keep going from here. */
730
segp = cur;
731
- while ((segp > path) && ((--segp)[0] == '/'))
732
- ;
733
- if (segp == path)
734
+ while ((segp > path) && ((--segp)[0] == '/')) {
735
+ /* No further work */
736
+ }
737
+ if (segp == path) {
738
continue;
739
+ }
740
741
/* "segp" is pointing to the end of a previous segment; find it's
742
* start. We need to back up to the previous segment and start
743
@@ -XXX,XX +XXX,XX @@ done_cd:
744
* remove the "foo/..".
745
*/
746
cur = segp;
747
- while ((cur > path) && (cur[-1] != '/'))
748
+ while ((cur > path) && (cur[-1] != '/')) {
749
--cur;
750
+ }
751
}
752
out[0] = '\0';
753
754
@@ -XXX,XX +XXX,XX @@ done_cd:
755
if (path[0] == '/') {
756
cur = path;
757
while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') &&
758
- ((cur[3] == '/') || (cur[3] == '\0')))
759
+ ((cur[3] == '/') || (cur[3] == '\0'))) {
760
cur += 3;
761
+ }
762
763
if (cur != path) {
764
out = path;
765
- while (cur[0] != '\0')
766
+ while (cur[0] != '\0') {
767
(out++)[0] = (cur++)[0];
768
+ }
769
out[0] = 0;
770
}
771
}
772
@@ -XXX,XX +XXX,XX @@ done_cd:
773
static int is_hex(char c)
774
{
775
if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
776
- ((c >= 'A') && (c <= 'F')))
777
+ ((c >= 'A') && (c <= 'F'))) {
778
return 1;
779
+ }
780
return 0;
781
}
782
783
@@ -XXX,XX +XXX,XX @@ char *uri_string_unescape(const char *str, int len, char *target)
784
char *ret, *out;
785
const char *in;
786
787
- if (str == NULL)
788
+ if (str == NULL) {
789
return NULL;
790
- if (len <= 0)
791
+ }
792
+ if (len <= 0) {
793
len = strlen(str);
794
- if (len < 0)
795
+ }
796
+ if (len < 0) {
797
return NULL;
798
+ }
799
800
if (target == NULL) {
801
ret = g_malloc(len + 1);
802
- } else
803
+ } else {
804
ret = target;
805
+ }
806
in = str;
807
out = ret;
808
while (len > 0) {
809
if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
810
in++;
811
- if ((*in >= '0') && (*in <= '9'))
812
+ if ((*in >= '0') && (*in <= '9')) {
813
*out = (*in - '0');
814
- else if ((*in >= 'a') && (*in <= 'f'))
815
+ } else if ((*in >= 'a') && (*in <= 'f')) {
816
*out = (*in - 'a') + 10;
817
- else if ((*in >= 'A') && (*in <= 'F'))
818
+ } else if ((*in >= 'A') && (*in <= 'F')) {
819
*out = (*in - 'A') + 10;
820
+ }
821
in++;
822
- if ((*in >= '0') && (*in <= '9'))
823
+ if ((*in >= '0') && (*in <= '9')) {
824
*out = *out * 16 + (*in - '0');
825
- else if ((*in >= 'a') && (*in <= 'f'))
826
+ } else if ((*in >= 'a') && (*in <= 'f')) {
827
*out = *out * 16 + (*in - 'a') + 10;
828
- else if ((*in >= 'A') && (*in <= 'F'))
829
+ } else if ((*in >= 'A') && (*in <= 'F')) {
830
*out = *out * 16 + (*in - 'A') + 10;
831
+ }
832
in++;
833
len -= 3;
834
out++;
835
@@ -XXX,XX +XXX,XX @@ char *uri_string_escape(const char *str, const char *list)
836
const char *in;
837
int len, out;
838
839
- if (str == NULL)
840
+ if (str == NULL) {
841
return NULL;
842
- if (str[0] == 0)
843
+ }
844
+ if (str[0] == 0) {
845
return g_strdup(str);
846
+ }
847
len = strlen(str);
848
- if (!(len > 0))
849
+ if (!(len > 0)) {
850
return NULL;
851
+ }
852
853
len += 20;
854
ret = g_malloc(len);
855
@@ -XXX,XX +XXX,XX @@ char *uri_string_escape(const char *str, const char *list)
856
unsigned char val;
857
ret[out++] = '%';
858
val = ch >> 4;
859
- if (val <= 9)
860
+ if (val <= 9) {
861
ret[out++] = '0' + val;
862
- else
863
+ } else {
864
ret[out++] = 'A' + val - 0xA;
865
+ }
866
val = ch & 0xF;
867
- if (val <= 9)
868
+ if (val <= 9) {
869
ret[out++] = '0' + val;
870
- else
871
+ } else {
872
ret[out++] = 'A' + val - 0xA;
873
+ }
874
in++;
875
} else {
876
ret[out++] = *in++;
877
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
878
* as a reference to "." rather than as a synonym for the current
879
* URI. Should we do that here?
880
*/
881
- if (uri == NULL)
882
+ if (uri == NULL) {
883
ret = -1;
884
- else {
885
+ } else {
886
if (*uri) {
887
ref = uri_new();
888
ret = uri_parse_into(ref, uri);
889
- } else
890
+ } else {
891
ret = 0;
892
+ }
893
}
894
- if (ret != 0)
895
+ if (ret != 0) {
896
goto done;
897
+ }
898
if ((ref != NULL) && (ref->scheme != NULL)) {
899
/*
900
* The URI is absolute don't modify.
901
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
902
val = g_strdup(uri);
903
goto done;
904
}
905
- if (base == NULL)
906
+ if (base == NULL) {
907
ret = -1;
908
- else {
909
+ } else {
910
bas = uri_new();
911
ret = uri_parse_into(bas, base);
912
}
913
if (ret != 0) {
914
- if (ref)
915
+ if (ref) {
916
val = uri_to_string(ref);
917
+ }
918
goto done;
919
}
920
if (ref == NULL) {
921
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
922
if ((ref->scheme == NULL) && (ref->path == NULL) &&
923
((ref->authority == NULL) && (ref->server == NULL))) {
924
res->scheme = g_strdup(bas->scheme);
925
- if (bas->authority != NULL)
926
+ if (bas->authority != NULL) {
927
res->authority = g_strdup(bas->authority);
928
- else if (bas->server != NULL) {
929
+ } else if (bas->server != NULL) {
930
res->server = g_strdup(bas->server);
931
res->user = g_strdup(bas->user);
932
res->port = bas->port;
933
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
934
* use an authority component.
935
*/
936
if ((ref->authority != NULL) || (ref->server != NULL)) {
937
- if (ref->authority != NULL)
938
+ if (ref->authority != NULL) {
939
res->authority = g_strdup(ref->authority);
940
- else {
941
+ } else {
942
res->server = g_strdup(ref->server);
943
res->user = g_strdup(ref->user);
944
res->port = ref->port;
945
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
946
res->path = g_strdup(ref->path);
947
goto step_7;
948
}
949
- if (bas->authority != NULL)
950
+ if (bas->authority != NULL) {
951
res->authority = g_strdup(bas->authority);
952
- else if (bas->server != NULL) {
953
+ } else if (bas->server != NULL) {
954
res->server = g_strdup(bas->server);
955
res->user = g_strdup(bas->user);
956
res->port = bas->port;
957
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
958
* Allocate a buffer large enough for the result string.
959
*/
960
len = 2; /* extra / and 0 */
961
- if (ref->path != NULL)
962
+ if (ref->path != NULL) {
963
len += strlen(ref->path);
964
- if (bas->path != NULL)
965
+ }
966
+ if (bas->path != NULL) {
967
len += strlen(bas->path);
968
+ }
969
res->path = g_malloc(len);
970
res->path[0] = 0;
971
972
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
973
out = 0;
974
if (bas->path != NULL) {
975
while (bas->path[cur] != 0) {
976
- while ((bas->path[cur] != 0) && (bas->path[cur] != '/'))
977
+ while ((bas->path[cur] != 0) && (bas->path[cur] != '/')) {
978
cur++;
979
- if (bas->path[cur] == 0)
980
+ }
981
+ if (bas->path[cur] == 0) {
982
break;
983
+ }
984
985
cur++;
986
while (out < cur) {
987
@@ -XXX,XX +XXX,XX @@ char *uri_resolve(const char *uri, const char *base)
988
/*
989
* Ensure the path includes a '/'
990
*/
991
- if ((out == 0) && (bas->server != NULL))
992
+ if ((out == 0) && (bas->server != NULL)) {
993
res->path[out++] = '/';
994
+ }
995
while (ref->path[indx] != 0) {
996
res->path[out++] = ref->path[indx++];
997
}
998
@@ -XXX,XX +XXX,XX @@ step_7:
999
val = uri_to_string(res);
1000
1001
done:
1002
- if (ref != NULL)
1003
+ if (ref != NULL) {
1004
uri_free(ref);
1005
- if (bas != NULL)
1006
+ }
1007
+ if (bas != NULL) {
1008
uri_free(bas);
1009
- if (res != NULL)
1010
+ }
1011
+ if (res != NULL) {
1012
uri_free(res);
1013
+ }
1014
return val;
1015
}
1016
1017
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1018
char *bptr, *uptr, *vptr;
1019
int remove_path = 0;
1020
1021
- if ((uri == NULL) || (*uri == 0))
1022
+ if ((uri == NULL) || (*uri == 0)) {
1023
return NULL;
1024
+ }
1025
1026
/*
1027
* First parse URI into a standard form
1028
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1029
/* If URI not already in "relative" form */
1030
if (uri[0] != '.') {
1031
ret = uri_parse_into(ref, uri);
1032
- if (ret != 0)
1033
+ if (ret != 0) {
1034
goto done; /* Error in URI, return NULL */
1035
- } else
1036
+ }
1037
+ } else {
1038
ref->path = g_strdup(uri);
1039
+ }
1040
1041
/*
1042
* Next parse base into the same standard form
1043
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1044
bas = uri_new();
1045
if (base[0] != '.') {
1046
ret = uri_parse_into(bas, base);
1047
- if (ret != 0)
1048
+ if (ret != 0) {
1049
goto done; /* Error in base, return NULL */
1050
- } else
1051
+ }
1052
+ } else {
1053
bas->path = g_strdup(base);
1054
+ }
1055
1056
/*
1057
* If the scheme / server on the URI differs from the base,
1058
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1059
if (bas->path == NULL) {
1060
if (ref->path != NULL) {
1061
uptr = ref->path;
1062
- if (*uptr == '/')
1063
+ if (*uptr == '/') {
1064
uptr++;
1065
+ }
1066
/* exception characters from uri_to_string */
1067
val = uri_string_escape(uptr, "/;&=+$,");
1068
}
1069
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1070
bptr = bas->path;
1071
if (ref->path == NULL) {
1072
for (ix = 0; bptr[ix] != 0; ix++) {
1073
- if (bptr[ix] == '/')
1074
+ if (bptr[ix] == '/') {
1075
nbslash++;
1076
+ }
1077
}
1078
uptr = NULL;
1079
len = 1; /* this is for a string terminator only */
1080
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1081
/*
1082
* Next we compare the two strings and find where they first differ
1083
*/
1084
- if ((ref->path[pos] == '.') && (ref->path[pos + 1] == '/'))
1085
+ if ((ref->path[pos] == '.') && (ref->path[pos + 1] == '/')) {
1086
pos += 2;
1087
- if ((*bptr == '.') && (bptr[1] == '/'))
1088
+ }
1089
+ if ((*bptr == '.') && (bptr[1] == '/')) {
1090
bptr += 2;
1091
- else if ((*bptr == '/') && (ref->path[pos] != '/'))
1092
+ } else if ((*bptr == '/') && (ref->path[pos] != '/')) {
1093
bptr++;
1094
- while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0))
1095
+ }
1096
+ while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) {
1097
pos++;
1098
+ }
1099
1100
if (bptr[pos] == ref->path[pos]) {
1101
val = g_strdup("");
1102
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1103
* beginning of the "unique" suffix of URI
1104
*/
1105
ix = pos;
1106
- if ((ref->path[ix] == '/') && (ix > 0))
1107
+ if ((ref->path[ix] == '/') && (ix > 0)) {
1108
ix--;
1109
- else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/'))
1110
+ } else if ((ref->path[ix] == 0) && (ix > 1)
1111
+ && (ref->path[ix - 1] == '/')) {
1112
ix -= 2;
1113
+ }
1114
for (; ix > 0; ix--) {
1115
- if (ref->path[ix] == '/')
1116
+ if (ref->path[ix] == '/') {
1117
break;
1118
+ }
1119
}
1120
if (ix == 0) {
1121
uptr = ref->path;
1122
@@ -XXX,XX +XXX,XX @@ char *uri_resolve_relative(const char *uri, const char *base)
1123
*/
1124
if (bptr[pos] != ref->path[pos]) { /* check for trivial URI == base */
1125
for (; bptr[ix] != 0; ix++) {
1126
- if (bptr[ix] == '/')
1127
+ if (bptr[ix] == '/') {
1128
nbslash++;
1129
+ }
1130
}
1131
}
1132
len = strlen(uptr) + 1;
1133
}
1134
1135
if (nbslash == 0) {
1136
- if (uptr != NULL)
1137
+ if (uptr != NULL) {
1138
/* exception characters from uri_to_string */
1139
val = uri_string_escape(uptr, "/;&=+$,");
1140
+ }
1141
goto done;
1142
}
1143
1144
@@ -XXX,XX +XXX,XX @@ done:
1145
/*
1146
* Free the working variables
1147
*/
1148
- if (remove_path != 0)
1149
+ if (remove_path != 0) {
1150
ref->path = NULL;
1151
- if (ref != NULL)
1152
+ }
1153
+ if (ref != NULL) {
1154
uri_free(ref);
1155
- if (bas != NULL)
1156
+ }
1157
+ if (bas != NULL) {
1158
uri_free(bas);
1159
+ }
1160
1161
return val;
1162
}
1163
@@ -XXX,XX +XXX,XX @@ struct QueryParams *query_params_new(int init_alloc)
1164
{
1165
struct QueryParams *ps;
1166
1167
- if (init_alloc <= 0)
1168
+ if (init_alloc <= 0) {
1169
init_alloc = 1;
1170
+ }
1171
1172
ps = g_new(QueryParams, 1);
1173
ps->n = 0;
1174
@@ -XXX,XX +XXX,XX @@ struct QueryParams *query_params_parse(const char *query)
1175
const char *end, *eq;
1176
1177
ps = query_params_new(0);
1178
- if (!query || query[0] == '\0')
1179
+ if (!query || query[0] == '\0') {
1180
return ps;
1181
+ }
1182
1183
while (*query) {
1184
char *name = NULL, *value = NULL;
1185
1186
/* Find the next separator, or end of the string. */
1187
end = strchr(query, '&');
1188
- if (!end)
1189
+ if (!end) {
1190
end = strchr(query, ';');
1191
- if (!end)
1192
+ }
1193
+ if (!end) {
1194
end = query + strlen(query);
1195
+ }
1196
1197
/* Find the first '=' character between here and end. */
1198
eq = strchr(query, '=');
1199
- if (eq && eq >= end)
1200
+ if (eq && eq >= end) {
1201
eq = NULL;
1202
+ }
1203
1204
/* Empty section (eg. "&&"). */
1205
- if (end == query)
1206
+ if (end == query) {
1207
goto next;
1208
+ }
1209
1210
/* If there is no '=' character, then we have just "name"
1211
* and consistent with CGI.pm we assume value is "".
1212
@@ -XXX,XX +XXX,XX @@ struct QueryParams *query_params_parse(const char *query)
1213
/* If the '=' character is at the beginning then we have
1214
* "=value" and consistent with CGI.pm we _ignore_ this.
1215
*/
1216
- else if (query == eq)
1217
+ else if (query == eq) {
1218
goto next;
1219
+ }
1220
1221
/* Otherwise it's "name=value". */
1222
else {
1223
@@ -XXX,XX +XXX,XX @@ struct QueryParams *query_params_parse(const char *query)
1224
1225
next:
1226
query = end;
1227
- if (*query)
1228
+ if (*query) {
1229
query++; /* skip '&' separator */
1230
+ }
1231
}
1232
1233
return ps;
1234
--
203
--
1235
2.14.3
204
2.40.1
1236
1237
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
No block driver implements .bdrv_co_io_plug() anymore. Get rid of the
2
function pointers.
2
3
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4
Message-id: 20180226030326.20219-3-famz@redhat.com
5
Reviewed-by: Eric Blake <eblake@redhat.com>
6
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
7
Acked-by: Kevin Wolf <kwolf@redhat.com>
8
Message-id: 20230530180959.1108766-7-stefanha@redhat.com
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
10
---
7
README | 31 ++++++++++++++++++++++++++++++-
11
include/block/block-io.h | 3 ---
8
1 file changed, 30 insertions(+), 1 deletion(-)
12
include/block/block_int-common.h | 11 ----------
13
block/io.c | 37 --------------------------------
14
3 files changed, 51 deletions(-)
9
15
10
diff --git a/README b/README
16
diff --git a/include/block/block-io.h b/include/block/block-io.h
11
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
12
--- a/README
18
--- a/include/block/block-io.h
13
+++ b/README
19
+++ b/include/block/block-io.h
14
@@ -XXX,XX +XXX,XX @@ The QEMU source code is maintained under the GIT version control system.
20
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, AioContext *old_ctx);
15
21
16
git clone git://git.qemu.org/qemu.git
22
AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c);
17
23
18
-When submitting patches, the preferred approach is to use 'git
24
-void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs);
19
+When submitting patches, one common approach is to use 'git
25
-void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs);
20
format-patch' and/or 'git send-email' to format & send the mail to the
26
-
21
qemu-devel@nongnu.org mailing list. All patches submitted must contain
27
bool coroutine_fn GRAPH_RDLOCK
22
a 'Signed-off-by' line from the author. Patches should follow the
28
bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
23
@@ -XXX,XX +XXX,XX @@ The QEMU website is also maintained under source control.
29
uint32_t granularity, Error **errp);
24
git clone git://git.qemu.org/qemu-web.git
30
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
25
https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/
31
index XXXXXXX..XXXXXXX 100644
26
32
--- a/include/block/block_int-common.h
27
+A 'git-profile' utility was created to make above process less
33
+++ b/include/block/block_int-common.h
28
+cumbersome, and is highly recommended for making regular contributions,
34
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
29
+or even just for sending consecutive patch series revisions. It also
35
void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_debug_event)(
30
+requires a working 'git send-email' setup, and by default doesn't
36
BlockDriverState *bs, BlkdebugEvent event);
31
+automate everything, so you may want to go through the above steps
37
32
+manually for once.
38
- /* io queue for linux-aio */
33
+
39
- void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_plug)(BlockDriverState *bs);
34
+For installation instructions, please go to
40
- void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_unplug)(
35
+
41
- BlockDriverState *bs);
36
+ https://github.com/stefanha/git-publish
42
-
37
+
43
bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs);
38
+The workflow with 'git-publish' is:
44
39
+
45
bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_can_store_new_dirty_bitmap)(
40
+ $ git checkout master -b my-feature
46
@@ -XXX,XX +XXX,XX @@ struct BlockDriverState {
41
+ $ # work on new commits, add your 'Signed-off-by' lines to each
47
unsigned int in_flight;
42
+ $ git publish
48
unsigned int serialising_in_flight;
43
+
49
44
+Your patch series will be sent and tagged as my-feature-v1 if you need to refer
50
- /*
45
+back to it in the future.
51
- * counter for nested bdrv_io_plug.
46
+
52
- * Accessed with atomic ops.
47
+Sending v2:
53
- */
48
+
54
- unsigned io_plugged;
49
+ $ git checkout my-feature # same topic branch
55
-
50
+ $ # making changes to the commits (using 'git rebase', for example)
56
/* do we need to tell the quest if we have a volatile write cache? */
51
+ $ git publish
57
int enable_write_cache;
52
+
58
53
+Your patch series will be sent with 'v2' tag in the subject and the git tip
59
diff --git a/block/io.c b/block/io.c
54
+will be tagged as my-feature-v2.
60
index XXXXXXX..XXXXXXX 100644
55
+
61
--- a/block/io.c
56
Bug reporting
62
+++ b/block/io.c
57
=============
63
@@ -XXX,XX +XXX,XX @@ void *qemu_try_blockalign0(BlockDriverState *bs, size_t size)
58
64
return mem;
65
}
66
67
-void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs)
68
-{
69
- BdrvChild *child;
70
- IO_CODE();
71
- assert_bdrv_graph_readable();
72
-
73
- QLIST_FOREACH(child, &bs->children, next) {
74
- bdrv_co_io_plug(child->bs);
75
- }
76
-
77
- if (qatomic_fetch_inc(&bs->io_plugged) == 0) {
78
- BlockDriver *drv = bs->drv;
79
- if (drv && drv->bdrv_co_io_plug) {
80
- drv->bdrv_co_io_plug(bs);
81
- }
82
- }
83
-}
84
-
85
-void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs)
86
-{
87
- BdrvChild *child;
88
- IO_CODE();
89
- assert_bdrv_graph_readable();
90
-
91
- assert(bs->io_plugged);
92
- if (qatomic_fetch_dec(&bs->io_plugged) == 1) {
93
- BlockDriver *drv = bs->drv;
94
- if (drv && drv->bdrv_co_io_unplug) {
95
- drv->bdrv_co_io_unplug(bs);
96
- }
97
- }
98
-
99
- QLIST_FOREACH(child, &bs->children, next) {
100
- bdrv_co_io_unplug(child->bs);
101
- }
102
-}
103
-
104
/* Helper that undoes bdrv_register_buf() when it fails partway through */
105
static void GRAPH_RDLOCK
106
bdrv_register_buf_rollback(BlockDriverState *bs, void *host, size_t size,
59
--
107
--
60
2.14.3
108
2.40.1
61
62
diff view generated by jsdifflib
1
From: Su Hang <suhang16@mails.ucas.ac.cn>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Using `clang-format -i util/uri.c` first, then change back few code
3
Some virtio-blk drivers (e.g. virtio-blk-vhost-vdpa) supports the fd
4
manually, to make sure only whitespace involved.
4
passing. Let's expose this to the user, so the management layer
5
can pass the file descriptor of an already opened path.
5
6
6
Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
7
If the libblkio virtio-blk driver supports fd passing, let's always
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
8
use qemu_open() to open the `path`, so we can handle fd passing
8
Message-id: 1519533358-13759-2-git-send-email-suhang16@mails.ucas.ac.cn
9
from the management layer through the "/dev/fdset/N" special path.
10
11
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
13
Message-id: 20230530071941.8954-2-sgarzare@redhat.com
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
15
---
11
util/uri.c | 1450 ++++++++++++++++++++++++++++++------------------------------
16
block/blkio.c | 53 ++++++++++++++++++++++++++++++++++++++++++---------
12
1 file changed, 726 insertions(+), 724 deletions(-)
17
1 file changed, 44 insertions(+), 9 deletions(-)
13
18
14
diff --git a/util/uri.c b/util/uri.c
19
diff --git a/block/blkio.c b/block/blkio.c
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/util/uri.c
21
--- a/block/blkio.c
17
+++ b/util/uri.c
22
+++ b/block/blkio.c
18
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
23
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
19
*/
24
{
20
#define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x))
25
const char *path = qdict_get_try_str(options, "path");
21
26
BDRVBlkioState *s = bs->opaque;
27
- int ret;
28
+ bool fd_supported = false;
29
+ int fd, ret;
30
31
if (!path) {
32
error_setg(errp, "missing 'path' option");
33
return -EINVAL;
34
}
35
36
- ret = blkio_set_str(s->blkio, "path", path);
37
- qdict_del(options, "path");
38
- if (ret < 0) {
39
- error_setg_errno(errp, -ret, "failed to set path: %s",
40
- blkio_get_error_msg());
41
- return ret;
42
- }
22
-
43
-
23
/*
44
if (!(flags & BDRV_O_NOCACHE)) {
24
* lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
45
error_setg(errp, "cache.direct=off is not supported");
25
* "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" |
46
return -EINVAL;
26
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
27
* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
28
*/
29
30
-#define IS_MARK(x) (((x) == '-') || ((x) == '_') || ((x) == '.') || \
31
- ((x) == '!') || ((x) == '~') || ((x) == '*') || ((x) == '\'') || \
32
+#define IS_MARK(x) (((x) == '-') || ((x) == '_') || ((x) == '.') || \
33
+ ((x) == '!') || ((x) == '~') || ((x) == '*') || ((x) == '\'') || \
34
((x) == '(') || ((x) == ')'))
35
36
/*
37
* unwise = "{" | "}" | "|" | "\" | "^" | "`"
38
*/
39
40
-#define IS_UNWISE(p) \
41
- (((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \
42
- ((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \
43
- ((*(p) == ']')) || ((*(p) == '`')))
44
+#define IS_UNWISE(p) \
45
+ (((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \
46
+ ((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \
47
+ ((*(p) == ']')) || ((*(p) == '`')))
48
/*
49
* reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," |
50
* "[" | "]"
51
*/
52
53
-#define IS_RESERVED(x) (((x) == ';') || ((x) == '/') || ((x) == '?') || \
54
- ((x) == ':') || ((x) == '@') || ((x) == '&') || ((x) == '=') || \
55
- ((x) == '+') || ((x) == '$') || ((x) == ',') || ((x) == '[') || \
56
- ((x) == ']'))
57
+#define IS_RESERVED(x) (((x) == ';') || ((x) == '/') || ((x) == '?') || \
58
+ ((x) == ':') || ((x) == '@') || ((x) == '&') || ((x) == '=') || \
59
+ ((x) == '+') || ((x) == '$') || ((x) == ',') || ((x) == '[') || \
60
+ ((x) == ']'))
61
62
/*
63
* unreserved = alphanum | mark
64
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
65
* Skip to next pointer char, handle escaped sequences
66
*/
67
68
-#define NEXT(p) ((*p == '%')? p += 3 : p++)
69
+#define NEXT(p) ((*p == '%') ? p += 3 : p++)
70
71
/*
72
* Productions from the spec.
73
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
74
* path = [ abs_path | opaque_part ]
75
*/
76
77
-
78
/************************************************************************
79
- *                                    *
80
- * RFC 3986 parser                *
81
- *                                    *
82
+ * *
83
+ * RFC 3986 parser *
84
+ * *
85
************************************************************************/
86
87
#define ISA_DIGIT(p) ((*(p) >= '0') && (*(p) <= '9'))
88
-#define ISA_ALPHA(p) (((*(p) >= 'a') && (*(p) <= 'z')) ||        \
89
+#define ISA_ALPHA(p) (((*(p) >= 'a') && (*(p) <= 'z')) || \
90
((*(p) >= 'A') && (*(p) <= 'Z')))
91
-#define ISA_HEXDIG(p)                            \
92
- (ISA_DIGIT(p) || ((*(p) >= 'a') && (*(p) <= 'f')) ||        \
93
- ((*(p) >= 'A') && (*(p) <= 'F')))
94
+#define ISA_HEXDIG(p) \
95
+ (ISA_DIGIT(p) || ((*(p) >= 'a') && (*(p) <= 'f')) || \
96
+ ((*(p) >= 'A') && (*(p) <= 'F')))
97
98
/*
99
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
100
* / "*" / "+" / "," / ";" / "="
101
*/
102
-#define ISA_SUB_DELIM(p)                        \
103
- (((*(p) == '!')) || ((*(p) == '$')) || ((*(p) == '&')) ||        \
104
- ((*(p) == '(')) || ((*(p) == ')')) || ((*(p) == '*')) ||        \
105
- ((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) ||        \
106
- ((*(p) == '=')) || ((*(p) == '\'')))
107
+#define ISA_SUB_DELIM(p) \
108
+ (((*(p) == '!')) || ((*(p) == '$')) || ((*(p) == '&')) || \
109
+ ((*(p) == '(')) || ((*(p) == ')')) || ((*(p) == '*')) || \
110
+ ((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) || \
111
+ ((*(p) == '=')) || ((*(p) == '\'')))
112
113
/*
114
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
115
*/
116
-#define ISA_GEN_DELIM(p)                        \
117
- (((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) || \
118
- ((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) || \
119
- ((*(p) == '@')))
120
+#define ISA_GEN_DELIM(p) \
121
+ (((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) || \
122
+ ((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) || \
123
+ ((*(p) == '@')))
124
125
/*
126
* reserved = gen-delims / sub-delims
127
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
128
/*
129
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
130
*/
131
-#define ISA_UNRESERVED(p)                        \
132
- ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) == '-')) ||        \
133
- ((*(p) == '.')) || ((*(p) == '_')) || ((*(p) == '~')))
134
+#define ISA_UNRESERVED(p) \
135
+ ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) == '-')) || \
136
+ ((*(p) == '.')) || ((*(p) == '_')) || ((*(p) == '~')))
137
138
/*
139
* pct-encoded = "%" HEXDIG HEXDIG
140
*/
141
-#define ISA_PCT_ENCODED(p)                        \
142
- ((*(p) == '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2)))
143
+#define ISA_PCT_ENCODED(p) \
144
+ ((*(p) == '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2)))
145
146
/*
147
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
148
*/
149
-#define ISA_PCHAR(p)                            \
150
- (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) ||    \
151
- ((*(p) == ':')) || ((*(p) == '@')))
152
+#define ISA_PCHAR(p) \
153
+ (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || \
154
+ ((*(p) == ':')) || ((*(p) == '@')))
155
156
/**
157
* rfc3986_parse_scheme:
158
@@ -XXX,XX +XXX,XX @@ static void uri_clean(URI *uri);
159
*
160
* Returns 0 or the error code
161
*/
162
-static int
163
-rfc3986_parse_scheme(URI *uri, const char **str) {
164
+static int rfc3986_parse_scheme(URI *uri, const char **str)
165
+{
166
const char *cur;
167
168
if (str == NULL)
169
-    return(-1);
170
+ return (-1);
171
172
cur = *str;
173
if (!ISA_ALPHA(cur))
174
-    return(2);
175
+ return (2);
176
cur++;
177
- while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
178
- (*cur == '+') || (*cur == '-') || (*cur == '.')) cur++;
179
+ while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
180
+ (*cur == '.'))
181
+ cur++;
182
if (uri != NULL) {
183
g_free(uri->scheme);
184
-    uri->scheme = g_strndup(*str, cur - *str);
185
+ uri->scheme = g_strndup(*str, cur - *str);
186
}
47
}
187
*str = cur;
48
+
188
- return(0);
49
+ if (blkio_get_int(s->blkio, "fd", &fd) == 0) {
189
+ return (0);
50
+ fd_supported = true;
190
}
51
+ }
191
52
+
192
/**
53
+ /*
193
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_scheme(URI *uri, const char **str) {
54
+ * If the libblkio driver supports fd passing, let's always use qemu_open()
194
*
55
+ * to open the `path`, so we can handle fd passing from the management
195
* Returns 0 or the error code
56
+ * layer through the "/dev/fdset/N" special path.
196
*/
57
+ */
197
-static int
58
+ if (fd_supported) {
198
-rfc3986_parse_fragment(URI *uri, const char **str)
59
+ int open_flags;
199
+static int rfc3986_parse_fragment(URI *uri, const char **str)
60
+
200
{
61
+ if (flags & BDRV_O_RDWR) {
201
const char *cur;
62
+ open_flags = O_RDWR;
202
63
+ } else {
203
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_fragment(URI *uri, const char **str)
64
+ open_flags = O_RDONLY;
204
NEXT(cur);
205
if (uri != NULL) {
206
g_free(uri->fragment);
207
-    if (uri->cleanup & 2)
208
-     uri->fragment = g_strndup(*str, cur - *str);
209
-    else
210
-     uri->fragment = uri_string_unescape(*str, cur - *str, NULL);
211
+ if (uri->cleanup & 2)
212
+ uri->fragment = g_strndup(*str, cur - *str);
213
+ else
214
+ uri->fragment = uri_string_unescape(*str, cur - *str, NULL);
215
}
216
*str = cur;
217
return (0);
218
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_fragment(URI *uri, const char **str)
219
*
220
* Returns 0 or the error code
221
*/
222
-static int
223
-rfc3986_parse_query(URI *uri, const char **str)
224
+static int rfc3986_parse_query(URI *uri, const char **str)
225
{
226
const char *cur;
227
228
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_query(URI *uri, const char **str)
229
NEXT(cur);
230
if (uri != NULL) {
231
g_free(uri->query);
232
-    uri->query = g_strndup (*str, cur - *str);
233
+ uri->query = g_strndup(*str, cur - *str);
234
}
235
*str = cur;
236
return (0);
237
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_query(URI *uri, const char **str)
238
*
239
* Returns 0 or the error code
240
*/
241
-static int
242
-rfc3986_parse_port(URI *uri, const char **str)
243
+static int rfc3986_parse_port(URI *uri, const char **str)
244
{
245
const char *cur = *str;
246
int port = 0;
247
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_port(URI *uri, const char **str)
248
*
249
* Returns 0 or the error code
250
*/
251
-static int
252
-rfc3986_parse_user_info(URI *uri, const char **str)
253
+static int rfc3986_parse_user_info(URI *uri, const char **str)
254
{
255
const char *cur;
256
257
cur = *str;
258
- while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) ||
259
- ISA_SUB_DELIM(cur) || (*cur == ':'))
260
-    NEXT(cur);
261
+ while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur) ||
262
+ (*cur == ':'))
263
+ NEXT(cur);
264
if (*cur == '@') {
265
-    if (uri != NULL) {
266
+ if (uri != NULL) {
267
g_free(uri->user);
268
-     if (uri->cleanup & 2)
269
-        uri->user = g_strndup(*str, cur - *str);
270
-     else
271
-        uri->user = uri_string_unescape(*str, cur - *str, NULL);
272
-    }
273
-    *str = cur;
274
-    return(0);
275
+ if (uri->cleanup & 2)
276
+ uri->user = g_strndup(*str, cur - *str);
277
+ else
278
+ uri->user = uri_string_unescape(*str, cur - *str, NULL);
279
+ }
65
+ }
280
+ *str = cur;
66
+
281
+ return (0);
67
+ fd = qemu_open(path, open_flags, errp);
282
}
68
+ if (fd < 0) {
283
- return(1);
69
+ return -EINVAL;
284
+ return (1);
285
}
286
287
/**
288
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_user_info(URI *uri, const char **str)
289
*
290
* Returns 0 if found and skipped, 1 otherwise
291
*/
292
-static int
293
-rfc3986_parse_dec_octet(const char **str) {
294
+static int rfc3986_parse_dec_octet(const char **str)
295
+{
296
const char *cur = *str;
297
298
if (!(ISA_DIGIT(cur)))
299
- return(1);
300
- if (!ISA_DIGIT(cur+1))
301
-    cur++;
302
- else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur+2)))
303
-    cur += 2;
304
+ return (1);
305
+ if (!ISA_DIGIT(cur + 1))
306
+ cur++;
307
+ else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + 2)))
308
+ cur += 2;
309
else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2)))
310
-    cur += 3;
311
- else if ((*cur == '2') && (*(cur + 1) >= '0') &&
312
-     (*(cur + 1) <= '4') && (ISA_DIGIT(cur + 2)))
313
-    cur += 3;
314
- else if ((*cur == '2') && (*(cur + 1) == '5') &&
315
-     (*(cur + 2) >= '0') && (*(cur + 1) <= '5'))
316
-    cur += 3;
317
+ cur += 3;
318
+ else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') &&
319
+ (ISA_DIGIT(cur + 2)))
320
+ cur += 3;
321
+ else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') &&
322
+ (*(cur + 1) <= '5'))
323
+ cur += 3;
324
else
325
- return(1);
326
+ return (1);
327
*str = cur;
328
- return(0);
329
+ return (0);
330
}
331
/**
332
* rfc3986_parse_host:
333
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_dec_octet(const char **str) {
334
*
335
* Returns 0 or the error code
336
*/
337
-static int
338
-rfc3986_parse_host(URI *uri, const char **str)
339
+static int rfc3986_parse_host(URI *uri, const char **str)
340
{
341
const char *cur = *str;
342
const char *host;
343
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_host(URI *uri, const char **str)
344
*/
345
if (*cur == '[') {
346
cur++;
347
-    while ((*cur != ']') && (*cur != 0))
348
-     cur++;
349
-    if (*cur != ']')
350
-     return(1);
351
-    cur++;
352
-    goto found;
353
+ while ((*cur != ']') && (*cur != 0))
354
+ cur++;
355
+ if (*cur != ']')
356
+ return (1);
357
+ cur++;
358
+ goto found;
359
}
360
/*
361
* try to parse an IPv4
362
*/
363
if (ISA_DIGIT(cur)) {
364
if (rfc3986_parse_dec_octet(&cur) != 0)
365
-     goto not_ipv4;
366
-    if (*cur != '.')
367
-     goto not_ipv4;
368
-    cur++;
369
+ goto not_ipv4;
370
+ if (*cur != '.')
371
+ goto not_ipv4;
372
+ cur++;
373
if (rfc3986_parse_dec_octet(&cur) != 0)
374
-     goto not_ipv4;
375
-    if (*cur != '.')
376
-     goto not_ipv4;
377
+ goto not_ipv4;
378
+ if (*cur != '.')
379
+ goto not_ipv4;
380
if (rfc3986_parse_dec_octet(&cur) != 0)
381
-     goto not_ipv4;
382
-    if (*cur != '.')
383
-     goto not_ipv4;
384
+ goto not_ipv4;
385
+ if (*cur != '.')
386
+ goto not_ipv4;
387
if (rfc3986_parse_dec_octet(&cur) != 0)
388
-     goto not_ipv4;
389
-    goto found;
390
-not_ipv4:
391
+ goto not_ipv4;
392
+ goto found;
393
+ not_ipv4:
394
cur = *str;
395
}
396
/*
397
@@ -XXX,XX +XXX,XX @@ not_ipv4:
398
found:
399
if (uri != NULL) {
400
g_free(uri->authority);
401
-    uri->authority = NULL;
402
+ uri->authority = NULL;
403
g_free(uri->server);
404
-    if (cur != host) {
405
-     if (uri->cleanup & 2)
406
-        uri->server = g_strndup(host, cur - host);
407
-     else
408
-        uri->server = uri_string_unescape(host, cur - host, NULL);
409
-    } else
410
-     uri->server = NULL;
411
+ if (cur != host) {
412
+ if (uri->cleanup & 2)
413
+ uri->server = g_strndup(host, cur - host);
414
+ else
415
+ uri->server = uri_string_unescape(host, cur - host, NULL);
416
+ } else
417
+ uri->server = NULL;
418
}
419
*str = cur;
420
- return(0);
421
+ return (0);
422
}
423
424
/**
425
@@ -XXX,XX +XXX,XX @@ found:
426
*
427
* Returns 0 or the error code
428
*/
429
-static int
430
-rfc3986_parse_authority(URI *uri, const char **str)
431
+static int rfc3986_parse_authority(URI *uri, const char **str)
432
{
433
const char *cur;
434
int ret;
435
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_authority(URI *uri, const char **str)
436
else
437
cur++;
438
ret = rfc3986_parse_host(uri, &cur);
439
- if (ret != 0) return(ret);
440
+ if (ret != 0)
441
+ return (ret);
442
if (*cur == ':') {
443
cur++;
444
ret = rfc3986_parse_port(uri, &cur);
445
-    if (ret != 0) return(ret);
446
+ if (ret != 0)
447
+ return (ret);
448
}
449
*str = cur;
450
- return(0);
451
+ return (0);
452
}
453
454
/**
455
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_authority(URI *uri, const char **str)
456
*
457
* Returns 0 or the error code
458
*/
459
-static int
460
-rfc3986_parse_segment(const char **str, char forbid, int empty)
461
+static int rfc3986_parse_segment(const char **str, char forbid, int empty)
462
{
463
const char *cur;
464
465
cur = *str;
466
if (!ISA_PCHAR(cur)) {
467
if (empty)
468
-     return(0);
469
-    return(1);
470
+ return (0);
471
+ return (1);
472
}
473
while (ISA_PCHAR(cur) && (*cur != forbid))
474
NEXT(cur);
475
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_segment(const char **str, char forbid, int empty)
476
*
477
* Returns 0 or the error code
478
*/
479
-static int
480
-rfc3986_parse_path_ab_empty(URI *uri, const char **str)
481
+static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
482
{
483
const char *cur;
484
int ret;
485
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
486
487
while (*cur == '/') {
488
cur++;
489
-    ret = rfc3986_parse_segment(&cur, 0, 1);
490
-    if (ret != 0) return(ret);
491
+ ret = rfc3986_parse_segment(&cur, 0, 1);
492
+ if (ret != 0)
493
+ return (ret);
494
}
495
if (uri != NULL) {
496
g_free(uri->path);
497
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
498
*
499
* Returns 0 or the error code
500
*/
501
-static int
502
-rfc3986_parse_path_absolute(URI *uri, const char **str)
503
+static int rfc3986_parse_path_absolute(URI *uri, const char **str)
504
{
505
const char *cur;
506
int ret;
507
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
508
cur = *str;
509
510
if (*cur != '/')
511
- return(1);
512
+ return (1);
513
cur++;
514
ret = rfc3986_parse_segment(&cur, 0, 0);
515
if (ret == 0) {
516
-    while (*cur == '/') {
517
-     cur++;
518
-     ret = rfc3986_parse_segment(&cur, 0, 1);
519
-     if (ret != 0) return(ret);
520
-    }
521
+ while (*cur == '/') {
522
+ cur++;
523
+ ret = rfc3986_parse_segment(&cur, 0, 1);
524
+ if (ret != 0)
525
+ return (ret);
526
+ }
70
+ }
527
}
71
+
528
if (uri != NULL) {
72
+ ret = blkio_set_int(s->blkio, "fd", fd);
529
g_free(uri->path);
73
+ if (ret < 0) {
530
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
74
+ error_setg_errno(errp, -ret, "failed to set fd: %s",
531
*
75
+ blkio_get_error_msg());
532
* Returns 0 or the error code
76
+ qemu_close(fd);
533
*/
77
+ return ret;
534
-static int
535
-rfc3986_parse_path_rootless(URI *uri, const char **str)
536
+static int rfc3986_parse_path_rootless(URI *uri, const char **str)
537
{
538
const char *cur;
539
int ret;
540
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
541
cur = *str;
542
543
ret = rfc3986_parse_segment(&cur, 0, 0);
544
- if (ret != 0) return(ret);
545
+ if (ret != 0)
546
+ return (ret);
547
while (*cur == '/') {
548
cur++;
549
-    ret = rfc3986_parse_segment(&cur, 0, 1);
550
-    if (ret != 0) return(ret);
551
+ ret = rfc3986_parse_segment(&cur, 0, 1);
552
+ if (ret != 0)
553
+ return (ret);
554
}
555
if (uri != NULL) {
556
g_free(uri->path);
557
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
558
*
559
* Returns 0 or the error code
560
*/
561
-static int
562
-rfc3986_parse_path_no_scheme(URI *uri, const char **str)
563
+static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
564
{
565
const char *cur;
566
int ret;
567
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
568
cur = *str;
569
570
ret = rfc3986_parse_segment(&cur, ':', 0);
571
- if (ret != 0) return(ret);
572
+ if (ret != 0)
573
+ return (ret);
574
while (*cur == '/') {
575
cur++;
576
-    ret = rfc3986_parse_segment(&cur, 0, 1);
577
-    if (ret != 0) return(ret);
578
+ ret = rfc3986_parse_segment(&cur, 0, 1);
579
+ if (ret != 0)
580
+ return (ret);
581
}
582
if (uri != NULL) {
583
g_free(uri->path);
584
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
585
*
586
* Returns 0 or the error code
587
*/
588
-static int
589
-rfc3986_parse_hier_part(URI *uri, const char **str)
590
+static int rfc3986_parse_hier_part(URI *uri, const char **str)
591
{
592
const char *cur;
593
int ret;
594
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_hier_part(URI *uri, const char **str)
595
596
if ((*cur == '/') && (*(cur + 1) == '/')) {
597
cur += 2;
598
-    ret = rfc3986_parse_authority(uri, &cur);
599
-    if (ret != 0) return(ret);
600
-    ret = rfc3986_parse_path_ab_empty(uri, &cur);
601
-    if (ret != 0) return(ret);
602
-    *str = cur;
603
-    return(0);
604
+ ret = rfc3986_parse_authority(uri, &cur);
605
+ if (ret != 0)
606
+ return (ret);
607
+ ret = rfc3986_parse_path_ab_empty(uri, &cur);
608
+ if (ret != 0)
609
+ return (ret);
610
+ *str = cur;
611
+ return (0);
612
} else if (*cur == '/') {
613
ret = rfc3986_parse_path_absolute(uri, &cur);
614
-    if (ret != 0) return(ret);
615
+ if (ret != 0)
616
+ return (ret);
617
} else if (ISA_PCHAR(cur)) {
618
ret = rfc3986_parse_path_rootless(uri, &cur);
619
-    if (ret != 0) return(ret);
620
+ if (ret != 0)
621
+ return (ret);
622
} else {
623
-    /* path-empty is effectively empty */
624
-    if (uri != NULL) {
625
+ /* path-empty is effectively empty */
626
+ if (uri != NULL) {
627
g_free(uri->path);
628
-     uri->path = NULL;
629
-    }
630
+ uri->path = NULL;
631
+ }
78
+ }
632
}
79
+ } else {
633
*str = cur;
80
+ ret = blkio_set_str(s->blkio, "path", path);
634
return (0);
81
+ if (ret < 0) {
635
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_hier_part(URI *uri, const char **str)
82
+ error_setg_errno(errp, -ret, "failed to set path: %s",
636
*
83
+ blkio_get_error_msg());
637
* Returns 0 or the error code
84
+ return ret;
638
*/
639
-static int
640
-rfc3986_parse_relative_ref(URI *uri, const char *str) {
641
+static int rfc3986_parse_relative_ref(URI *uri, const char *str)
642
+{
643
int ret;
644
645
if ((*str == '/') && (*(str + 1) == '/')) {
646
str += 2;
647
-    ret = rfc3986_parse_authority(uri, &str);
648
-    if (ret != 0) return(ret);
649
-    ret = rfc3986_parse_path_ab_empty(uri, &str);
650
-    if (ret != 0) return(ret);
651
+ ret = rfc3986_parse_authority(uri, &str);
652
+ if (ret != 0)
653
+ return (ret);
654
+ ret = rfc3986_parse_path_ab_empty(uri, &str);
655
+ if (ret != 0)
656
+ return (ret);
657
} else if (*str == '/') {
658
-    ret = rfc3986_parse_path_absolute(uri, &str);
659
-    if (ret != 0) return(ret);
660
+ ret = rfc3986_parse_path_absolute(uri, &str);
661
+ if (ret != 0)
662
+ return (ret);
663
} else if (ISA_PCHAR(str)) {
664
ret = rfc3986_parse_path_no_scheme(uri, &str);
665
-    if (ret != 0) return(ret);
666
+ if (ret != 0)
667
+ return (ret);
668
} else {
669
-    /* path-empty is effectively empty */
670
-    if (uri != NULL) {
671
+ /* path-empty is effectively empty */
672
+ if (uri != NULL) {
673
g_free(uri->path);
674
-     uri->path = NULL;
675
-    }
676
+ uri->path = NULL;
677
+ }
85
+ }
678
}
86
+ }
679
87
+
680
if (*str == '?') {
88
+ qdict_del(options, "path");
681
-    str++;
89
+
682
-    ret = rfc3986_parse_query(uri, &str);
683
-    if (ret != 0) return(ret);
684
+ str++;
685
+ ret = rfc3986_parse_query(uri, &str);
686
+ if (ret != 0)
687
+ return (ret);
688
}
689
if (*str == '#') {
690
-    str++;
691
-    ret = rfc3986_parse_fragment(uri, &str);
692
-    if (ret != 0) return(ret);
693
+ str++;
694
+ ret = rfc3986_parse_fragment(uri, &str);
695
+ if (ret != 0)
696
+ return (ret);
697
}
698
if (*str != 0) {
699
-    uri_clean(uri);
700
-    return(1);
701
+ uri_clean(uri);
702
+ return (1);
703
}
704
- return(0);
705
+ return (0);
706
}
707
708
-
709
/**
710
* rfc3986_parse:
711
* @uri: pointer to an URI structure
712
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
713
*
714
* Returns 0 or the error code
715
*/
716
-static int
717
-rfc3986_parse(URI *uri, const char *str) {
718
+static int rfc3986_parse(URI *uri, const char *str)
719
+{
720
int ret;
721
722
ret = rfc3986_parse_scheme(uri, &str);
723
- if (ret != 0) return(ret);
724
+ if (ret != 0)
725
+ return (ret);
726
if (*str != ':') {
727
-    return(1);
728
+ return (1);
729
}
730
str++;
731
ret = rfc3986_parse_hier_part(uri, &str);
732
- if (ret != 0) return(ret);
733
+ if (ret != 0)
734
+ return (ret);
735
if (*str == '?') {
736
-    str++;
737
-    ret = rfc3986_parse_query(uri, &str);
738
-    if (ret != 0) return(ret);
739
+ str++;
740
+ ret = rfc3986_parse_query(uri, &str);
741
+ if (ret != 0)
742
+ return (ret);
743
}
744
if (*str == '#') {
745
-    str++;
746
-    ret = rfc3986_parse_fragment(uri, &str);
747
-    if (ret != 0) return(ret);
748
+ str++;
749
+ ret = rfc3986_parse_fragment(uri, &str);
750
+ if (ret != 0)
751
+ return (ret);
752
}
753
if (*str != 0) {
754
-    uri_clean(uri);
755
-    return(1);
756
+ uri_clean(uri);
757
+ return (1);
758
}
759
- return(0);
760
+ return (0);
761
}
762
763
/**
764
@@ -XXX,XX +XXX,XX @@ rfc3986_parse(URI *uri, const char *str) {
765
*
766
* Returns 0 or the error code
767
*/
768
-static int
769
-rfc3986_parse_uri_reference(URI *uri, const char *str) {
770
+static int rfc3986_parse_uri_reference(URI *uri, const char *str)
771
+{
772
int ret;
773
774
if (str == NULL)
775
-    return(-1);
776
+ return (-1);
777
uri_clean(uri);
778
779
/*
780
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_uri_reference(URI *uri, const char *str) {
781
*/
782
ret = rfc3986_parse(uri, str);
783
if (ret != 0) {
784
-    uri_clean(uri);
785
+ uri_clean(uri);
786
ret = rfc3986_parse_relative_ref(uri, str);
787
-    if (ret != 0) {
788
-     uri_clean(uri);
789
-     return(ret);
790
-    }
791
+ if (ret != 0) {
792
+ uri_clean(uri);
793
+ return (ret);
794
+ }
795
}
796
- return(0);
797
+ return (0);
798
}
799
800
/**
801
@@ -XXX,XX +XXX,XX @@ rfc3986_parse_uri_reference(URI *uri, const char *str) {
802
*
803
* Returns a newly built URI or NULL in case of error
804
*/
805
-URI *
806
-uri_parse(const char *str) {
807
+URI *uri_parse(const char *str)
808
+{
809
URI *uri;
810
int ret;
811
812
if (str == NULL)
813
-    return(NULL);
814
+ return (NULL);
815
uri = uri_new();
816
ret = rfc3986_parse_uri_reference(uri, str);
817
if (ret) {
818
uri_free(uri);
819
- return(NULL);
820
+ return (NULL);
821
}
822
- return(uri);
823
+ return (uri);
824
}
825
826
/**
827
@@ -XXX,XX +XXX,XX @@ uri_parse(const char *str) {
828
*
829
* Returns 0 or the error code
830
*/
831
-int
832
-uri_parse_into(URI *uri, const char *str) {
833
- return(rfc3986_parse_uri_reference(uri, str));
834
+int uri_parse_into(URI *uri, const char *str)
835
+{
836
+ return (rfc3986_parse_uri_reference(uri, str));
837
}
838
839
/**
840
@@ -XXX,XX +XXX,XX @@ uri_parse_into(URI *uri, const char *str) {
841
*
842
* Returns a newly built URI or NULL in case of error
843
*/
844
-URI *
845
-uri_parse_raw(const char *str, int raw) {
846
+URI *uri_parse_raw(const char *str, int raw)
847
+{
848
URI *uri;
849
int ret;
850
851
if (str == NULL)
852
-    return(NULL);
853
+ return (NULL);
854
uri = uri_new();
855
if (raw) {
856
uri->cleanup |= 2;
857
@@ -XXX,XX +XXX,XX @@ uri_parse_raw(const char *str, int raw) {
858
ret = uri_parse_into(uri, str);
859
if (ret) {
860
uri_free(uri);
861
- return(NULL);
862
+ return (NULL);
863
}
864
- return(uri);
865
+ return (uri);
866
}
867
868
/************************************************************************
869
- *                                    *
870
- *            Generic URI structure functions            *
871
- *                                    *
872
+ * *
873
+ * Generic URI structure functions *
874
+ * *
875
************************************************************************/
876
877
/**
878
@@ -XXX,XX +XXX,XX @@ uri_parse_raw(const char *str, int raw) {
879
*
880
* Returns the new structure or NULL in case of error
881
*/
882
-URI *
883
-uri_new(void) {
884
+URI *uri_new(void)
885
+{
886
URI *ret;
887
888
ret = g_new0(URI, 1);
889
- return(ret);
890
+ return (ret);
891
}
892
893
/**
894
@@ -XXX,XX +XXX,XX @@ uri_new(void) {
895
* Function to handle properly a reallocation when saving an URI
896
* Also imposes some limit on the length of an URI string output
897
*/
898
-static char *
899
-realloc2n(char *ret, int *max) {
900
+static char *realloc2n(char *ret, int *max)
901
+{
902
char *temp;
903
int tmp;
904
905
tmp = *max * 2;
906
temp = g_realloc(ret, (tmp + 1));
907
*max = tmp;
908
- return(temp);
909
+ return (temp);
910
}
911
912
/**
913
@@ -XXX,XX +XXX,XX @@ realloc2n(char *ret, int *max) {
914
*
915
* Returns a new string (to be deallocated by caller)
916
*/
917
-char *
918
-uri_to_string(URI *uri) {
919
+char *uri_to_string(URI *uri)
920
+{
921
char *ret = NULL;
922
char *temp;
923
const char *p;
924
int len;
925
int max;
926
927
- if (uri == NULL) return(NULL);
928
-
929
+ if (uri == NULL)
930
+ return (NULL);
931
932
max = 80;
933
ret = g_malloc(max + 1);
934
len = 0;
935
936
if (uri->scheme != NULL) {
937
-    p = uri->scheme;
938
-    while (*p != 0) {
939
-     if (len >= max) {
940
+ p = uri->scheme;
941
+ while (*p != 0) {
942
+ if (len >= max) {
943
temp = realloc2n(ret, &max);
944
-        ret = temp;
945
-     }
946
-     ret[len++] = *p++;
947
-    }
948
-    if (len >= max) {
949
+ ret = temp;
950
+ }
951
+ ret[len++] = *p++;
952
+ }
953
+ if (len >= max) {
954
temp = realloc2n(ret, &max);
955
ret = temp;
956
-    }
957
-    ret[len++] = ':';
958
+ }
959
+ ret[len++] = ':';
960
}
961
if (uri->opaque != NULL) {
962
-    p = uri->opaque;
963
-    while (*p != 0) {
964
-     if (len + 3 >= max) {
965
+ p = uri->opaque;
966
+ while (*p != 0) {
967
+ if (len + 3 >= max) {
968
temp = realloc2n(ret, &max);
969
ret = temp;
970
-     }
971
-     if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
972
-        ret[len++] = *p++;
973
-     else {
974
-        int val = *(unsigned char *)p++;
975
-        int hi = val / 0x10, lo = val % 0x10;
976
-        ret[len++] = '%';
977
-        ret[len++] = hi + (hi > 9? 'A'-10 : '0');
978
-        ret[len++] = lo + (lo > 9? 'A'-10 : '0');
979
-     }
980
-    }
981
+ }
982
+ if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
983
+ ret[len++] = *p++;
984
+ else {
985
+ int val = *(unsigned char *)p++;
986
+ int hi = val / 0x10, lo = val % 0x10;
987
+ ret[len++] = '%';
988
+ ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0');
989
+ ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0');
990
+ }
991
+ }
992
} else {
993
-    if (uri->server != NULL) {
994
-     if (len + 3 >= max) {
995
+ if (uri->server != NULL) {
996
+ if (len + 3 >= max) {
997
temp = realloc2n(ret, &max);
998
ret = temp;
999
-     }
1000
-     ret[len++] = '/';
1001
-     ret[len++] = '/';
1002
-     if (uri->user != NULL) {
1003
-        p = uri->user;
1004
-        while (*p != 0) {
1005
-         if (len + 3 >= max) {
1006
+ }
1007
+ ret[len++] = '/';
1008
+ ret[len++] = '/';
1009
+ if (uri->user != NULL) {
1010
+ p = uri->user;
1011
+ while (*p != 0) {
1012
+ if (len + 3 >= max) {
1013
temp = realloc2n(ret, &max);
1014
ret = temp;
1015
-         }
1016
-         if ((IS_UNRESERVED(*(p))) ||
1017
-            ((*(p) == ';')) || ((*(p) == ':')) ||
1018
-            ((*(p) == '&')) || ((*(p) == '=')) ||
1019
-            ((*(p) == '+')) || ((*(p) == '$')) ||
1020
-            ((*(p) == ',')))
1021
-            ret[len++] = *p++;
1022
-         else {
1023
-            int val = *(unsigned char *)p++;
1024
-            int hi = val / 0x10, lo = val % 0x10;
1025
-            ret[len++] = '%';
1026
-            ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1027
-            ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1028
-         }
1029
-        }
1030
-        if (len + 3 >= max) {
1031
+ }
1032
+ if ((IS_UNRESERVED(*(p))) || ((*(p) == ';')) ||
1033
+ ((*(p) == ':')) || ((*(p) == '&')) || ((*(p) == '=')) ||
1034
+ ((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ',')))
1035
+ ret[len++] = *p++;
1036
+ else {
1037
+ int val = *(unsigned char *)p++;
1038
+ int hi = val / 0x10, lo = val % 0x10;
1039
+ ret[len++] = '%';
1040
+ ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0');
1041
+ ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0');
1042
+ }
1043
+ }
1044
+ if (len + 3 >= max) {
1045
temp = realloc2n(ret, &max);
1046
ret = temp;
1047
-        }
1048
-        ret[len++] = '@';
1049
-     }
1050
-     p = uri->server;
1051
-     while (*p != 0) {
1052
-        if (len >= max) {
1053
+ }
1054
+ ret[len++] = '@';
1055
+ }
1056
+ p = uri->server;
1057
+ while (*p != 0) {
1058
+ if (len >= max) {
1059
temp = realloc2n(ret, &max);
1060
ret = temp;
1061
-        }
1062
-        ret[len++] = *p++;
1063
-     }
1064
-     if (uri->port > 0) {
1065
-        if (len + 10 >= max) {
1066
+ }
1067
+ ret[len++] = *p++;
1068
+ }
1069
+ if (uri->port > 0) {
1070
+ if (len + 10 >= max) {
1071
temp = realloc2n(ret, &max);
1072
ret = temp;
1073
-        }
1074
-        len += snprintf(&ret[len], max - len, ":%d", uri->port);
1075
-     }
1076
-    } else if (uri->authority != NULL) {
1077
-     if (len + 3 >= max) {
1078
+ }
1079
+ len += snprintf(&ret[len], max - len, ":%d", uri->port);
1080
+ }
1081
+ } else if (uri->authority != NULL) {
1082
+ if (len + 3 >= max) {
1083
temp = realloc2n(ret, &max);
1084
ret = temp;
1085
-     }
1086
-     ret[len++] = '/';
1087
-     ret[len++] = '/';
1088
-     p = uri->authority;
1089
-     while (*p != 0) {
1090
-        if (len + 3 >= max) {
1091
+ }
1092
+ ret[len++] = '/';
1093
+ ret[len++] = '/';
1094
+ p = uri->authority;
1095
+ while (*p != 0) {
1096
+ if (len + 3 >= max) {
1097
temp = realloc2n(ret, &max);
1098
ret = temp;
1099
-        }
1100
-        if ((IS_UNRESERVED(*(p))) ||
1101
- ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
1102
- ((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1103
- ((*(p) == '=')) || ((*(p) == '+')))
1104
-         ret[len++] = *p++;
1105
-        else {
1106
-         int val = *(unsigned char *)p++;
1107
-         int hi = val / 0x10, lo = val % 0x10;
1108
-         ret[len++] = '%';
1109
-         ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1110
-         ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1111
-        }
1112
-     }
1113
-    } else if (uri->scheme != NULL) {
1114
-     if (len + 3 >= max) {
1115
+ }
1116
+ if ((IS_UNRESERVED(*(p))) || ((*(p) == '$')) ||
1117
+ ((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == ':')) ||
1118
+ ((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == '=')) ||
1119
+ ((*(p) == '+')))
1120
+ ret[len++] = *p++;
1121
+ else {
1122
+ int val = *(unsigned char *)p++;
1123
+ int hi = val / 0x10, lo = val % 0x10;
1124
+ ret[len++] = '%';
1125
+ ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0');
1126
+ ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0');
1127
+ }
1128
+ }
1129
+ } else if (uri->scheme != NULL) {
1130
+ if (len + 3 >= max) {
1131
temp = realloc2n(ret, &max);
1132
ret = temp;
1133
-     }
1134
-     ret[len++] = '/';
1135
-     ret[len++] = '/';
1136
-    }
1137
-    if (uri->path != NULL) {
1138
-     p = uri->path;
1139
-     /*
1140
-     * the colon in file:///d: should not be escaped or
1141
-     * Windows accesses fail later.
1142
-     */
1143
-     if ((uri->scheme != NULL) &&
1144
-        (p[0] == '/') &&
1145
-        (((p[1] >= 'a') && (p[1] <= 'z')) ||
1146
-         ((p[1] >= 'A') && (p[1] <= 'Z'))) &&
1147
-        (p[2] == ':') &&
1148
-     (!strcmp(uri->scheme, "file"))) {
1149
-        if (len + 3 >= max) {
1150
+ }
1151
+ ret[len++] = '/';
1152
+ ret[len++] = '/';
1153
+ }
1154
+ if (uri->path != NULL) {
1155
+ p = uri->path;
1156
+ /*
1157
+ * the colon in file:///d: should not be escaped or
1158
+ * Windows accesses fail later.
1159
+ */
1160
+ if ((uri->scheme != NULL) && (p[0] == '/') &&
1161
+ (((p[1] >= 'a') && (p[1] <= 'z')) ||
1162
+ ((p[1] >= 'A') && (p[1] <= 'Z'))) &&
1163
+ (p[2] == ':') && (!strcmp(uri->scheme, "file"))) {
1164
+ if (len + 3 >= max) {
1165
temp = realloc2n(ret, &max);
1166
ret = temp;
1167
-        }
1168
-        ret[len++] = *p++;
1169
-        ret[len++] = *p++;
1170
-        ret[len++] = *p++;
1171
-     }
1172
-     while (*p != 0) {
1173
-        if (len + 3 >= max) {
1174
+ }
1175
+ ret[len++] = *p++;
1176
+ ret[len++] = *p++;
1177
+ ret[len++] = *p++;
1178
+ }
1179
+ while (*p != 0) {
1180
+ if (len + 3 >= max) {
1181
temp = realloc2n(ret, &max);
1182
ret = temp;
1183
-        }
1184
-        if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
1185
+ }
1186
+ if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
1187
((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1188
-     ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) ||
1189
-     ((*(p) == ',')))
1190
-         ret[len++] = *p++;
1191
-        else {
1192
-         int val = *(unsigned char *)p++;
1193
-         int hi = val / 0x10, lo = val % 0x10;
1194
-         ret[len++] = '%';
1195
-         ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1196
-         ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1197
-        }
1198
-     }
1199
-    }
1200
-    if (uri->query != NULL) {
1201
-     if (len + 1 >= max) {
1202
+ ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) ||
1203
+ ((*(p) == ',')))
1204
+ ret[len++] = *p++;
1205
+ else {
1206
+ int val = *(unsigned char *)p++;
1207
+ int hi = val / 0x10, lo = val % 0x10;
1208
+ ret[len++] = '%';
1209
+ ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0');
1210
+ ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0');
1211
+ }
1212
+ }
1213
+ }
1214
+ if (uri->query != NULL) {
1215
+ if (len + 1 >= max) {
1216
temp = realloc2n(ret, &max);
1217
ret = temp;
1218
-     }
1219
-     ret[len++] = '?';
1220
-     p = uri->query;
1221
-     while (*p != 0) {
1222
-        if (len + 1 >= max) {
1223
+ }
1224
+ ret[len++] = '?';
1225
+ p = uri->query;
1226
+ while (*p != 0) {
1227
+ if (len + 1 >= max) {
1228
temp = realloc2n(ret, &max);
1229
ret = temp;
1230
-        }
1231
-        ret[len++] = *p++;
1232
-     }
1233
-    }
1234
+ }
1235
+ ret[len++] = *p++;
1236
+ }
1237
+ }
1238
}
1239
if (uri->fragment != NULL) {
1240
-    if (len + 3 >= max) {
1241
+ if (len + 3 >= max) {
1242
temp = realloc2n(ret, &max);
1243
ret = temp;
1244
-    }
1245
-    ret[len++] = '#';
1246
-    p = uri->fragment;
1247
-    while (*p != 0) {
1248
-     if (len + 3 >= max) {
1249
+ }
1250
+ ret[len++] = '#';
1251
+ p = uri->fragment;
1252
+ while (*p != 0) {
1253
+ if (len + 3 >= max) {
1254
temp = realloc2n(ret, &max);
1255
ret = temp;
1256
-     }
1257
-     if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1258
-        ret[len++] = *p++;
1259
-     else {
1260
-        int val = *(unsigned char *)p++;
1261
-        int hi = val / 0x10, lo = val % 0x10;
1262
-        ret[len++] = '%';
1263
-        ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1264
-        ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1265
-     }
1266
-    }
1267
+ }
1268
+ if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1269
+ ret[len++] = *p++;
1270
+ else {
1271
+ int val = *(unsigned char *)p++;
1272
+ int hi = val / 0x10, lo = val % 0x10;
1273
+ ret[len++] = '%';
1274
+ ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0');
1275
+ ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0');
1276
+ }
1277
+ }
1278
}
1279
if (len >= max) {
1280
temp = realloc2n(ret, &max);
1281
ret = temp;
1282
}
1283
ret[len] = 0;
1284
- return(ret);
1285
+ return (ret);
1286
}
1287
1288
/**
1289
@@ -XXX,XX +XXX,XX @@ uri_to_string(URI *uri) {
1290
*
1291
* Make sure the URI struct is free of content
1292
*/
1293
-static void
1294
-uri_clean(URI *uri) {
1295
- if (uri == NULL) return;
1296
+static void uri_clean(URI *uri)
1297
+{
1298
+ if (uri == NULL)
1299
+ return;
1300
1301
g_free(uri->scheme);
1302
uri->scheme = NULL;
1303
@@ -XXX,XX +XXX,XX @@ uri_clean(URI *uri) {
1304
*
1305
* Free up the URI struct
1306
*/
1307
-void
1308
-uri_free(URI *uri) {
1309
+void uri_free(URI *uri)
1310
+{
1311
uri_clean(uri);
1312
g_free(uri);
1313
}
1314
1315
/************************************************************************
1316
- *                                    *
1317
- *            Helper functions                *
1318
- *                                    *
1319
+ * *
1320
+ * Helper functions *
1321
+ * *
1322
************************************************************************/
1323
1324
/**
1325
@@ -XXX,XX +XXX,XX @@ uri_free(URI *uri) {
1326
*
1327
* Returns 0 or an error code
1328
*/
1329
-static int
1330
-normalize_uri_path(char *path) {
1331
+static int normalize_uri_path(char *path)
1332
+{
1333
char *cur, *out;
1334
1335
if (path == NULL)
1336
-    return(-1);
1337
+ return (-1);
1338
1339
/* Skip all initial "/" chars. We want to get to the beginning of the
1340
* first non-empty segment.
1341
*/
1342
cur = path;
1343
while (cur[0] == '/')
1344
- ++cur;
1345
+ ++cur;
1346
if (cur[0] == '\0')
1347
- return(0);
1348
+ return (0);
1349
1350
/* Keep everything we've seen so far. */
1351
out = cur;
1352
@@ -XXX,XX +XXX,XX @@ normalize_uri_path(char *path) {
1353
* Analyze each segment in sequence for cases (c) and (d).
1354
*/
1355
while (cur[0] != '\0') {
1356
-    /*
1357
-     * c) All occurrences of "./", where "." is a complete path segment,
1358
-     * are removed from the buffer string.
1359
-     */
1360
-    if ((cur[0] == '.') && (cur[1] == '/')) {
1361
-     cur += 2;
1362
-     /* '//' normalization should be done at this point too */
1363
-     while (cur[0] == '/')
1364
-        cur++;
1365
-     continue;
1366
-    }
1367
+ /*
1368
+ * c) All occurrences of "./", where "." is a complete path segment,
1369
+ * are removed from the buffer string.
1370
+ */
1371
+ if ((cur[0] == '.') && (cur[1] == '/')) {
1372
+ cur += 2;
1373
+ /* '//' normalization should be done at this point too */
1374
+ while (cur[0] == '/')
1375
+ cur++;
1376
+ continue;
1377
+ }
1378
1379
-    /*
1380
-     * d) If the buffer string ends with "." as a complete path segment,
1381
-     * that "." is removed.
1382
-     */
1383
-    if ((cur[0] == '.') && (cur[1] == '\0'))
1384
-     break;
1385
+ /*
1386
+ * d) If the buffer string ends with "." as a complete path segment,
1387
+ * that "." is removed.
1388
+ */
1389
+ if ((cur[0] == '.') && (cur[1] == '\0'))
1390
+ break;
1391
1392
-    /* Otherwise keep the segment. */
1393
-    while (cur[0] != '/') {
1394
+ /* Otherwise keep the segment. */
1395
+ while (cur[0] != '/') {
1396
if (cur[0] == '\0')
1397
- goto done_cd;
1398
-     (out++)[0] = (cur++)[0];
1399
-    }
1400
-    /* nomalize // */
1401
-    while ((cur[0] == '/') && (cur[1] == '/'))
1402
-     cur++;
1403
+ goto done_cd;
1404
+ (out++)[0] = (cur++)[0];
1405
+ }
1406
+ /* nomalize // */
1407
+ while ((cur[0] == '/') && (cur[1] == '/'))
1408
+ cur++;
1409
1410
(out++)[0] = (cur++)[0];
1411
}
1412
- done_cd:
1413
+done_cd:
1414
out[0] = '\0';
1415
1416
/* Reset to the beginning of the first segment for the next sequence. */
1417
cur = path;
1418
while (cur[0] == '/')
1419
- ++cur;
1420
+ ++cur;
1421
if (cur[0] == '\0')
1422
-    return(0);
1423
+ return (0);
1424
1425
/*
1426
* Analyze each segment in sequence for cases (e) and (f).
1427
@@ -XXX,XX +XXX,XX @@ normalize_uri_path(char *path) {
1428
/* Find the end of the current segment. */
1429
segp = cur;
1430
while ((segp[0] != '/') && (segp[0] != '\0'))
1431
- ++segp;
1432
+ ++segp;
1433
1434
/* If this is the last segment, we're done (we need at least two
1435
* segments to meet the criteria for the (e) and (f) cases).
1436
*/
1437
if (segp[0] == '\0')
1438
- break;
1439
+ break;
1440
1441
/* If the first segment is "..", or if the next segment _isn't_ "..",
1442
* keep this segment and try the next one.
1443
*/
1444
++segp;
1445
- if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur+3))
1446
- || ((segp[0] != '.') || (segp[1] != '.')
1447
- || ((segp[2] != '/') && (segp[2] != '\0')))) {
1448
- cur = segp;
1449
- continue;
1450
+ if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur + 3)) ||
1451
+ ((segp[0] != '.') || (segp[1] != '.') ||
1452
+ ((segp[2] != '/') && (segp[2] != '\0')))) {
1453
+ cur = segp;
1454
+ continue;
1455
}
1456
1457
/* If we get here, remove this segment and the next one and back up
1458
@@ -XXX,XX +XXX,XX @@ normalize_uri_path(char *path) {
1459
1460
/* If this is the end of the buffer, we're done. */
1461
if (segp[2] == '\0') {
1462
- cur[0] = '\0';
1463
- break;
1464
+ cur[0] = '\0';
1465
+ break;
1466
}
1467
/* Valgrind complained, strcpy(cur, segp + 3); */
1468
/* string will overlap, do not use strcpy */
1469
tmp = cur;
1470
segp += 3;
1471
while ((*tmp++ = *segp++) != 0)
1472
- ;
1473
+ ;
1474
1475
/* If there are no previous segments, then keep going from here. */
1476
segp = cur;
1477
while ((segp > path) && ((--segp)[0] == '/'))
1478
- ;
1479
+ ;
1480
if (segp == path)
1481
- continue;
1482
+ continue;
1483
1484
/* "segp" is pointing to the end of a previous segment; find it's
1485
* start. We need to back up to the previous segment and start
1486
@@ -XXX,XX +XXX,XX @@ normalize_uri_path(char *path) {
1487
*/
1488
cur = segp;
1489
while ((cur > path) && (cur[-1] != '/'))
1490
- --cur;
1491
+ --cur;
1492
}
1493
out[0] = '\0';
1494
1495
@@ -XXX,XX +XXX,XX @@ normalize_uri_path(char *path) {
1496
* We discard them from the final path.
1497
*/
1498
if (path[0] == '/') {
1499
- cur = path;
1500
- while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.')
1501
- && ((cur[3] == '/') || (cur[3] == '\0')))
1502
-    cur += 3;
1503
+ cur = path;
1504
+ while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') &&
1505
+ ((cur[3] == '/') || (cur[3] == '\0')))
1506
+ cur += 3;
1507
1508
- if (cur != path) {
1509
-    out = path;
1510
-    while (cur[0] != '\0')
1511
- (out++)[0] = (cur++)[0];
1512
-    out[0] = 0;
1513
- }
1514
+ if (cur != path) {
1515
+ out = path;
1516
+ while (cur[0] != '\0')
1517
+ (out++)[0] = (cur++)[0];
1518
+ out[0] = 0;
1519
+ }
1520
}
1521
1522
- return(0);
1523
+ return (0);
1524
}
1525
1526
-static int is_hex(char c) {
1527
- if (((c >= '0') && (c <= '9')) ||
1528
- ((c >= 'a') && (c <= 'f')) ||
1529
+static int is_hex(char c)
1530
+{
1531
+ if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
1532
((c >= 'A') && (c <= 'F')))
1533
-    return(1);
1534
- return(0);
1535
+ return (1);
1536
+ return (0);
1537
}
1538
1539
-
1540
/**
1541
* uri_string_unescape:
1542
* @str: the string to unescape
1543
@@ -XXX,XX +XXX,XX @@ static int is_hex(char c) {
1544
* Returns a copy of the string, but unescaped, will return NULL only in case
1545
* of error
1546
*/
1547
-char *
1548
-uri_string_unescape(const char *str, int len, char *target) {
1549
+char *uri_string_unescape(const char *str, int len, char *target)
1550
+{
1551
char *ret, *out;
1552
const char *in;
1553
1554
if (str == NULL)
1555
-    return(NULL);
1556
- if (len <= 0) len = strlen(str);
1557
- if (len < 0) return(NULL);
1558
+ return (NULL);
1559
+ if (len <= 0)
1560
+ len = strlen(str);
1561
+ if (len < 0)
1562
+ return (NULL);
1563
1564
if (target == NULL) {
1565
-    ret = g_malloc(len + 1);
1566
+ ret = g_malloc(len + 1);
1567
} else
1568
-    ret = target;
1569
+ ret = target;
1570
in = str;
1571
out = ret;
1572
- while(len > 0) {
1573
-    if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
1574
-     in++;
1575
-     if ((*in >= '0') && (*in <= '9'))
1576
-     *out = (*in - '0');
1577
-     else if ((*in >= 'a') && (*in <= 'f'))
1578
-     *out = (*in - 'a') + 10;
1579
-     else if ((*in >= 'A') && (*in <= 'F'))
1580
-     *out = (*in - 'A') + 10;
1581
-     in++;
1582
-     if ((*in >= '0') && (*in <= '9'))
1583
-     *out = *out * 16 + (*in - '0');
1584
-     else if ((*in >= 'a') && (*in <= 'f'))
1585
-     *out = *out * 16 + (*in - 'a') + 10;
1586
-     else if ((*in >= 'A') && (*in <= 'F'))
1587
-     *out = *out * 16 + (*in - 'A') + 10;
1588
-     in++;
1589
-     len -= 3;
1590
-     out++;
1591
-    } else {
1592
-     *out++ = *in++;
1593
-     len--;
1594
-    }
1595
+ while (len > 0) {
1596
+ if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
1597
+ in++;
1598
+ if ((*in >= '0') && (*in <= '9'))
1599
+ *out = (*in - '0');
1600
+ else if ((*in >= 'a') && (*in <= 'f'))
1601
+ *out = (*in - 'a') + 10;
1602
+ else if ((*in >= 'A') && (*in <= 'F'))
1603
+ *out = (*in - 'A') + 10;
1604
+ in++;
1605
+ if ((*in >= '0') && (*in <= '9'))
1606
+ *out = *out * 16 + (*in - '0');
1607
+ else if ((*in >= 'a') && (*in <= 'f'))
1608
+ *out = *out * 16 + (*in - 'a') + 10;
1609
+ else if ((*in >= 'A') && (*in <= 'F'))
1610
+ *out = *out * 16 + (*in - 'A') + 10;
1611
+ in++;
1612
+ len -= 3;
1613
+ out++;
1614
+ } else {
1615
+ *out++ = *in++;
1616
+ len--;
1617
+ }
1618
}
1619
*out = 0;
1620
- return(ret);
1621
+ return (ret);
1622
}
1623
1624
/**
1625
@@ -XXX,XX +XXX,XX @@ uri_string_unescape(const char *str, int len, char *target) {
1626
*
1627
* Returns a new escaped string or NULL in case of error.
1628
*/
1629
-char *
1630
-uri_string_escape(const char *str, const char *list) {
1631
+char *uri_string_escape(const char *str, const char *list)
1632
+{
1633
char *ret, ch;
1634
char *temp;
1635
const char *in;
1636
int len, out;
1637
1638
if (str == NULL)
1639
-    return(NULL);
1640
+ return (NULL);
1641
if (str[0] == 0)
1642
-    return(g_strdup(str));
1643
+ return (g_strdup(str));
1644
len = strlen(str);
1645
- if (!(len > 0)) return(NULL);
1646
+ if (!(len > 0))
1647
+ return (NULL);
1648
1649
len += 20;
1650
ret = g_malloc(len);
1651
in = str;
1652
out = 0;
1653
- while(*in != 0) {
1654
-    if (len - out <= 3) {
1655
+ while (*in != 0) {
1656
+ if (len - out <= 3) {
1657
temp = realloc2n(ret, &len);
1658
-     ret = temp;
1659
-    }
1660
+ ret = temp;
1661
+ }
1662
1663
-    ch = *in;
1664
-
1665
-    if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) {
1666
-     unsigned char val;
1667
-     ret[out++] = '%';
1668
-     val = ch >> 4;
1669
-     if (val <= 9)
1670
-        ret[out++] = '0' + val;
1671
-     else
1672
-        ret[out++] = 'A' + val - 0xA;
1673
-     val = ch & 0xF;
1674
-     if (val <= 9)
1675
-        ret[out++] = '0' + val;
1676
-     else
1677
-        ret[out++] = 'A' + val - 0xA;
1678
-     in++;
1679
-    } else {
1680
-     ret[out++] = *in++;
1681
-    }
1682
+ ch = *in;
1683
1684
+ if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) {
1685
+ unsigned char val;
1686
+ ret[out++] = '%';
1687
+ val = ch >> 4;
1688
+ if (val <= 9)
1689
+ ret[out++] = '0' + val;
1690
+ else
1691
+ ret[out++] = 'A' + val - 0xA;
1692
+ val = ch & 0xF;
1693
+ if (val <= 9)
1694
+ ret[out++] = '0' + val;
1695
+ else
1696
+ ret[out++] = 'A' + val - 0xA;
1697
+ in++;
1698
+ } else {
1699
+ ret[out++] = *in++;
1700
+ }
1701
}
1702
ret[out] = 0;
1703
- return(ret);
1704
+ return (ret);
1705
}
1706
1707
/************************************************************************
1708
- *                                    *
1709
- *            Public functions                *
1710
- *                                    *
1711
+ * *
1712
+ * Public functions *
1713
+ * *
1714
************************************************************************/
1715
1716
/**
1717
@@ -XXX,XX +XXX,XX @@ uri_string_escape(const char *str, const char *list) {
1718
* Returns a new URI string (to be freed by the caller) or NULL in case
1719
* of error.
1720
*/
1721
-char *
1722
-uri_resolve(const char *uri, const char *base) {
1723
+char *uri_resolve(const char *uri, const char *base)
1724
+{
1725
char *val = NULL;
1726
int ret, len, indx, cur, out;
1727
URI *ref = NULL;
1728
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1729
* URI. Should we do that here?
1730
*/
1731
if (uri == NULL)
1732
-    ret = -1;
1733
+ ret = -1;
1734
else {
1735
-    if (*uri) {
1736
-     ref = uri_new();
1737
-     ret = uri_parse_into(ref, uri);
1738
-    }
1739
-    else
1740
-     ret = 0;
1741
+ if (*uri) {
1742
+ ref = uri_new();
1743
+ ret = uri_parse_into(ref, uri);
1744
+ } else
1745
+ ret = 0;
1746
}
1747
if (ret != 0)
1748
-    goto done;
1749
+ goto done;
1750
if ((ref != NULL) && (ref->scheme != NULL)) {
1751
-    /*
1752
-     * The URI is absolute don't modify.
1753
-     */
1754
-    val = g_strdup(uri);
1755
-    goto done;
1756
+ /*
1757
+ * The URI is absolute don't modify.
1758
+ */
1759
+ val = g_strdup(uri);
1760
+ goto done;
1761
}
1762
if (base == NULL)
1763
-    ret = -1;
1764
+ ret = -1;
1765
else {
1766
-    bas = uri_new();
1767
-    ret = uri_parse_into(bas, base);
1768
+ bas = uri_new();
1769
+ ret = uri_parse_into(bas, base);
1770
}
1771
if (ret != 0) {
1772
-    if (ref)
1773
-     val = uri_to_string(ref);
1774
-    goto done;
1775
+ if (ref)
1776
+ val = uri_to_string(ref);
1777
+ goto done;
1778
}
1779
if (ref == NULL) {
1780
-    /*
1781
-     * the base fragment must be ignored
1782
-     */
1783
+ /*
1784
+ * the base fragment must be ignored
1785
+ */
1786
g_free(bas->fragment);
1787
bas->fragment = NULL;
1788
-    val = uri_to_string(bas);
1789
-    goto done;
1790
+ val = uri_to_string(bas);
1791
+ goto done;
1792
}
1793
1794
/*
1795
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1796
*/
1797
res = uri_new();
1798
if ((ref->scheme == NULL) && (ref->path == NULL) &&
1799
-    ((ref->authority == NULL) && (ref->server == NULL))) {
1800
+ ((ref->authority == NULL) && (ref->server == NULL))) {
1801
res->scheme = g_strdup(bas->scheme);
1802
-    if (bas->authority != NULL)
1803
-     res->authority = g_strdup(bas->authority);
1804
-    else if (bas->server != NULL) {
1805
+ if (bas->authority != NULL)
1806
+ res->authority = g_strdup(bas->authority);
1807
+ else if (bas->server != NULL) {
1808
res->server = g_strdup(bas->server);
1809
res->user = g_strdup(bas->user);
1810
res->port = bas->port;
1811
-    }
1812
+ }
1813
res->path = g_strdup(bas->path);
1814
if (ref->query != NULL) {
1815
-     res->query = g_strdup (ref->query);
1816
+ res->query = g_strdup(ref->query);
1817
} else {
1818
res->query = g_strdup(bas->query);
1819
}
1820
res->fragment = g_strdup(ref->fragment);
1821
-    goto step_7;
1822
+ goto step_7;
1823
}
1824
1825
/*
1826
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1827
* scheme is inherited from the base URI's scheme component.
1828
*/
1829
if (ref->scheme != NULL) {
1830
-    val = uri_to_string(ref);
1831
-    goto done;
1832
+ val = uri_to_string(ref);
1833
+ goto done;
1834
}
1835
res->scheme = g_strdup(bas->scheme);
1836
1837
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1838
* use an authority component.
1839
*/
1840
if ((ref->authority != NULL) || (ref->server != NULL)) {
1841
-    if (ref->authority != NULL)
1842
-     res->authority = g_strdup(ref->authority);
1843
-    else {
1844
-     res->server = g_strdup(ref->server);
1845
+ if (ref->authority != NULL)
1846
+ res->authority = g_strdup(ref->authority);
1847
+ else {
1848
+ res->server = g_strdup(ref->server);
1849
res->user = g_strdup(ref->user);
1850
res->port = ref->port;
1851
-    }
1852
+ }
1853
res->path = g_strdup(ref->path);
1854
-    goto step_7;
1855
+ goto step_7;
1856
}
1857
if (bas->authority != NULL)
1858
-    res->authority = g_strdup(bas->authority);
1859
+ res->authority = g_strdup(bas->authority);
1860
else if (bas->server != NULL) {
1861
res->server = g_strdup(bas->server);
1862
res->user = g_strdup(bas->user);
1863
-    res->port = bas->port;
1864
+ res->port = bas->port;
1865
}
1866
1867
/*
1868
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1869
* the reference is an absolute-path and we skip to step 7.
1870
*/
1871
if ((ref->path != NULL) && (ref->path[0] == '/')) {
1872
-    res->path = g_strdup(ref->path);
1873
-    goto step_7;
1874
+ res->path = g_strdup(ref->path);
1875
+ goto step_7;
1876
}
1877
1878
-
1879
/*
1880
* 6) If this step is reached, then we are resolving a relative-path
1881
* reference. The relative path needs to be merged with the base
1882
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1883
*/
1884
len = 2; /* extra / and 0 */
1885
if (ref->path != NULL)
1886
-    len += strlen(ref->path);
1887
+ len += strlen(ref->path);
1888
if (bas->path != NULL)
1889
-    len += strlen(bas->path);
1890
+ len += strlen(bas->path);
1891
res->path = g_malloc(len);
1892
res->path[0] = 0;
1893
1894
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1895
cur = 0;
1896
out = 0;
1897
if (bas->path != NULL) {
1898
-    while (bas->path[cur] != 0) {
1899
-     while ((bas->path[cur] != 0) && (bas->path[cur] != '/'))
1900
-        cur++;
1901
-     if (bas->path[cur] == 0)
1902
-        break;
1903
+ while (bas->path[cur] != 0) {
1904
+ while ((bas->path[cur] != 0) && (bas->path[cur] != '/'))
1905
+ cur++;
1906
+ if (bas->path[cur] == 0)
1907
+ break;
1908
1909
-     cur++;
1910
-     while (out < cur) {
1911
-        res->path[out] = bas->path[out];
1912
-        out++;
1913
-     }
1914
-    }
1915
+ cur++;
1916
+ while (out < cur) {
1917
+ res->path[out] = bas->path[out];
1918
+ out++;
1919
+ }
1920
+ }
1921
}
1922
res->path[out] = 0;
1923
1924
@@ -XXX,XX +XXX,XX @@ uri_resolve(const char *uri, const char *base) {
1925
* string.
1926
*/
1927
if (ref->path != NULL && ref->path[0] != 0) {
1928
-    indx = 0;
1929
-    /*
1930
-     * Ensure the path includes a '/'
1931
-     */
1932
-    if ((out == 0) && (bas->server != NULL))
1933
-     res->path[out++] = '/';
1934
-    while (ref->path[indx] != 0) {
1935
-     res->path[out++] = ref->path[indx++];
1936
-    }
1937
+ indx = 0;
1938
+ /*
1939
+ * Ensure the path includes a '/'
1940
+ */
1941
+ if ((out == 0) && (bas->server != NULL))
1942
+ res->path[out++] = '/';
1943
+ while (ref->path[indx] != 0) {
1944
+ res->path[out++] = ref->path[indx++];
1945
+ }
1946
}
1947
res->path[out] = 0;
1948
1949
@@ -XXX,XX +XXX,XX @@ step_7:
1950
1951
done:
1952
if (ref != NULL)
1953
-    uri_free(ref);
1954
+ uri_free(ref);
1955
if (bas != NULL)
1956
-    uri_free(bas);
1957
+ uri_free(bas);
1958
if (res != NULL)
1959
-    uri_free(res);
1960
- return(val);
1961
+ uri_free(res);
1962
+ return (val);
1963
}
1964
1965
/**
1966
@@ -XXX,XX +XXX,XX @@ done:
1967
* Returns a new URI string (to be freed by the caller) or NULL in case
1968
* error.
1969
*/
1970
-char *
1971
-uri_resolve_relative (const char *uri, const char * base)
1972
+char *uri_resolve_relative(const char *uri, const char *base)
1973
{
1974
char *val = NULL;
1975
int ret;
1976
@@ -XXX,XX +XXX,XX @@ uri_resolve_relative (const char *uri, const char * base)
1977
int remove_path = 0;
1978
1979
if ((uri == NULL) || (*uri == 0))
1980
-    return NULL;
1981
+ return NULL;
1982
1983
/*
1984
* First parse URI into a standard form
1985
*/
1986
- ref = uri_new ();
1987
+ ref = uri_new();
1988
/* If URI not already in "relative" form */
1989
if (uri[0] != '.') {
1990
-    ret = uri_parse_into (ref, uri);
1991
-    if (ret != 0)
1992
-     goto done;        /* Error in URI, return NULL */
1993
+ ret = uri_parse_into(ref, uri);
1994
+ if (ret != 0)
1995
+ goto done; /* Error in URI, return NULL */
1996
} else
1997
-    ref->path = g_strdup(uri);
1998
+ ref->path = g_strdup(uri);
1999
2000
/*
2001
* Next parse base into the same standard form
2002
*/
2003
if ((base == NULL) || (*base == 0)) {
2004
-    val = g_strdup (uri);
2005
-    goto done;
2006
+ val = g_strdup(uri);
2007
+ goto done;
2008
}
2009
- bas = uri_new ();
2010
+ bas = uri_new();
2011
if (base[0] != '.') {
2012
-    ret = uri_parse_into (bas, base);
2013
-    if (ret != 0)
2014
-     goto done;        /* Error in base, return NULL */
2015
+ ret = uri_parse_into(bas, base);
2016
+ if (ret != 0)
2017
+ goto done; /* Error in base, return NULL */
2018
} else
2019
-    bas->path = g_strdup(base);
2020
+ bas->path = g_strdup(base);
2021
2022
/*
2023
* If the scheme / server on the URI differs from the base,
2024
* just return the URI
2025
*/
2026
if ((ref->scheme != NULL) &&
2027
-    ((bas->scheme == NULL) ||
2028
-     (strcmp (bas->scheme, ref->scheme)) ||
2029
-     (strcmp (bas->server, ref->server)))) {
2030
-    val = g_strdup (uri);
2031
-    goto done;
2032
+ ((bas->scheme == NULL) || (strcmp(bas->scheme, ref->scheme)) ||
2033
+ (strcmp(bas->server, ref->server)))) {
2034
+ val = g_strdup(uri);
2035
+ goto done;
2036
}
2037
if (bas->path == ref->path ||
2038
(bas->path && ref->path && !strcmp(bas->path, ref->path))) {
2039
-    val = g_strdup("");
2040
-    goto done;
2041
+ val = g_strdup("");
2042
+ goto done;
2043
}
2044
if (bas->path == NULL) {
2045
-    val = g_strdup(ref->path);
2046
-    goto done;
2047
+ val = g_strdup(ref->path);
2048
+ goto done;
2049
}
2050
if (ref->path == NULL) {
2051
- ref->path = (char *) "/";
2052
-    remove_path = 1;
2053
+ ref->path = (char *)"/";
2054
+ remove_path = 1;
2055
}
2056
2057
/*
2058
@@ -XXX,XX +XXX,XX @@ uri_resolve_relative (const char *uri, const char * base)
2059
* two path components may be missing (bug 316224)
2060
*/
2061
if (bas->path == NULL) {
2062
-    if (ref->path != NULL) {
2063
-     uptr = ref->path;
2064
-     if (*uptr == '/')
2065
-        uptr++;
2066
-     /* exception characters from uri_to_string */
2067
-     val = uri_string_escape(uptr, "/;&=+$,");
2068
-    }
2069
-    goto done;
2070
+ if (ref->path != NULL) {
2071
+ uptr = ref->path;
2072
+ if (*uptr == '/')
2073
+ uptr++;
2074
+ /* exception characters from uri_to_string */
2075
+ val = uri_string_escape(uptr, "/;&=+$,");
2076
+ }
2077
+ goto done;
2078
}
2079
bptr = bas->path;
2080
if (ref->path == NULL) {
2081
-    for (ix = 0; bptr[ix] != 0; ix++) {
2082
-     if (bptr[ix] == '/')
2083
-        nbslash++;
2084
-    }
2085
-    uptr = NULL;
2086
-    len = 1;    /* this is for a string terminator only */
2087
+ for (ix = 0; bptr[ix] != 0; ix++) {
2088
+ if (bptr[ix] == '/')
2089
+ nbslash++;
2090
+ }
2091
+ uptr = NULL;
2092
+ len = 1; /* this is for a string terminator only */
2093
} else {
2094
- /*
2095
- * Next we compare the two strings and find where they first differ
2096
- */
2097
-    if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/'))
2098
+ /*
2099
+ * Next we compare the two strings and find where they first differ
2100
+ */
2101
+ if ((ref->path[pos] == '.') && (ref->path[pos + 1] == '/'))
2102
pos += 2;
2103
-    if ((*bptr == '.') && (bptr[1] == '/'))
2104
+ if ((*bptr == '.') && (bptr[1] == '/'))
2105
bptr += 2;
2106
-    else if ((*bptr == '/') && (ref->path[pos] != '/'))
2107
-     bptr++;
2108
-    while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0))
2109
-     pos++;
2110
+ else if ((*bptr == '/') && (ref->path[pos] != '/'))
2111
+ bptr++;
2112
+ while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0))
2113
+ pos++;
2114
2115
-    if (bptr[pos] == ref->path[pos]) {
2116
-     val = g_strdup("");
2117
-     goto done;        /* (I can't imagine why anyone would do this) */
2118
-    }
2119
+ if (bptr[pos] == ref->path[pos]) {
2120
+ val = g_strdup("");
2121
+ goto done; /* (I can't imagine why anyone would do this) */
2122
+ }
2123
2124
-    /*
2125
-     * In URI, "back up" to the last '/' encountered. This will be the
2126
-     * beginning of the "unique" suffix of URI
2127
-     */
2128
-    ix = pos;
2129
-    if ((ref->path[ix] == '/') && (ix > 0))
2130
-     ix--;
2131
-    else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/'))
2132
-     ix -= 2;
2133
-    for (; ix > 0; ix--) {
2134
-     if (ref->path[ix] == '/')
2135
-        break;
2136
-    }
2137
-    if (ix == 0) {
2138
-     uptr = ref->path;
2139
-    } else {
2140
-     ix++;
2141
-     uptr = &ref->path[ix];
2142
-    }
2143
+ /*
2144
+ * In URI, "back up" to the last '/' encountered. This will be the
2145
+ * beginning of the "unique" suffix of URI
2146
+ */
2147
+ ix = pos;
2148
+ if ((ref->path[ix] == '/') && (ix > 0))
2149
+ ix--;
2150
+ else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/'))
2151
+ ix -= 2;
2152
+ for (; ix > 0; ix--) {
2153
+ if (ref->path[ix] == '/')
2154
+ break;
2155
+ }
2156
+ if (ix == 0) {
2157
+ uptr = ref->path;
2158
+ } else {
2159
+ ix++;
2160
+ uptr = &ref->path[ix];
2161
+ }
2162
2163
-    /*
2164
-     * In base, count the number of '/' from the differing point
2165
-     */
2166
-    if (bptr[pos] != ref->path[pos]) {/* check for trivial URI == base */
2167
-     for (; bptr[ix] != 0; ix++) {
2168
-        if (bptr[ix] == '/')
2169
-         nbslash++;
2170
-     }
2171
-    }
2172
-    len = strlen (uptr) + 1;
2173
+ /*
2174
+ * In base, count the number of '/' from the differing point
2175
+ */
2176
+ if (bptr[pos] != ref->path[pos]) { /* check for trivial URI == base */
2177
+ for (; bptr[ix] != 0; ix++) {
2178
+ if (bptr[ix] == '/')
2179
+ nbslash++;
2180
+ }
2181
+ }
2182
+ len = strlen(uptr) + 1;
2183
}
2184
2185
if (nbslash == 0) {
2186
-    if (uptr != NULL)
2187
-     /* exception characters from uri_to_string */
2188
-     val = uri_string_escape(uptr, "/;&=+$,");
2189
-    goto done;
2190
+ if (uptr != NULL)
2191
+ /* exception characters from uri_to_string */
2192
+ val = uri_string_escape(uptr, "/;&=+$,");
2193
+ goto done;
2194
}
2195
2196
/*
2197
@@ -XXX,XX +XXX,XX @@ uri_resolve_relative (const char *uri, const char * base)
2198
* length of the remainder of the URI, plus enough space
2199
* for the "../" groups, plus one for the terminator
2200
*/
2201
- val = g_malloc (len + 3 * nbslash);
2202
+ val = g_malloc(len + 3 * nbslash);
2203
vptr = val;
2204
/*
2205
* Put in as many "../" as needed
2206
*/
2207
- for (; nbslash>0; nbslash--) {
2208
-    *vptr++ = '.';
2209
-    *vptr++ = '.';
2210
-    *vptr++ = '/';
2211
+ for (; nbslash > 0; nbslash--) {
2212
+ *vptr++ = '.';
2213
+ *vptr++ = '.';
2214
+ *vptr++ = '/';
2215
}
2216
/*
2217
* Finish up with the end of the URI
2218
*/
2219
if (uptr != NULL) {
2220
- if ((vptr > val) && (len > 0) &&
2221
-     (uptr[0] == '/') && (vptr[-1] == '/')) {
2222
-     memcpy (vptr, uptr + 1, len - 1);
2223
-     vptr[len - 2] = 0;
2224
-    } else {
2225
-     memcpy (vptr, uptr, len);
2226
-     vptr[len - 1] = 0;
2227
-    }
2228
+ if ((vptr > val) && (len > 0) && (uptr[0] == '/') &&
2229
+ (vptr[-1] == '/')) {
2230
+ memcpy(vptr, uptr + 1, len - 1);
2231
+ vptr[len - 2] = 0;
2232
+ } else {
2233
+ memcpy(vptr, uptr, len);
2234
+ vptr[len - 1] = 0;
2235
+ }
2236
} else {
2237
-    vptr[len - 1] = 0;
2238
+ vptr[len - 1] = 0;
2239
}
2240
2241
/* escape the freshly-built path */
2242
vptr = val;
2243
-    /* exception characters from uri_to_string */
2244
+ /* exception characters from uri_to_string */
2245
val = uri_string_escape(vptr, "/;&=+$,");
2246
g_free(vptr);
2247
2248
@@ -XXX,XX +XXX,XX @@ done:
2249
if (remove_path != 0)
2250
ref->path = NULL;
2251
if (ref != NULL)
2252
-    uri_free (ref);
2253
+ uri_free(ref);
2254
if (bas != NULL)
2255
-    uri_free (bas);
2256
+ uri_free(bas);
2257
2258
return val;
2259
}
2260
@@ -XXX,XX +XXX,XX @@ done:
2261
* Utility functions to help parse and assemble query strings.
2262
*/
2263
2264
-struct QueryParams *
2265
-query_params_new (int init_alloc)
2266
+struct QueryParams *query_params_new(int init_alloc)
2267
{
2268
struct QueryParams *ps;
2269
2270
- if (init_alloc <= 0) init_alloc = 1;
2271
+ if (init_alloc <= 0)
2272
+ init_alloc = 1;
2273
2274
ps = g_new(QueryParams, 1);
2275
ps->n = 0;
2276
@@ -XXX,XX +XXX,XX @@ query_params_new (int init_alloc)
2277
/* Ensure there is space to store at least one more parameter
2278
* at the end of the set.
2279
*/
2280
-static int
2281
-query_params_append (struct QueryParams *ps,
2282
- const char *name, const char *value)
2283
+static int query_params_append(struct QueryParams *ps, const char *name,
2284
+ const char *value)
2285
{
2286
if (ps->n >= ps->alloc) {
2287
ps->p = g_renew(QueryParam, ps->p, ps->alloc * 2);
2288
@@ -XXX,XX +XXX,XX @@ query_params_append (struct QueryParams *ps,
2289
return 0;
90
return 0;
2290
}
91
}
2291
92
2292
-void
2293
-query_params_free (struct QueryParams *ps)
2294
+void query_params_free(struct QueryParams *ps)
2295
{
2296
int i;
2297
2298
for (i = 0; i < ps->n; ++i) {
2299
- g_free (ps->p[i].name);
2300
- g_free (ps->p[i].value);
2301
+ g_free(ps->p[i].name);
2302
+ g_free(ps->p[i].value);
2303
}
2304
- g_free (ps->p);
2305
- g_free (ps);
2306
+ g_free(ps->p);
2307
+ g_free(ps);
2308
}
2309
2310
-struct QueryParams *
2311
-query_params_parse (const char *query)
2312
+struct QueryParams *query_params_parse(const char *query)
2313
{
2314
struct QueryParams *ps;
2315
const char *end, *eq;
2316
2317
- ps = query_params_new (0);
2318
- if (!query || query[0] == '\0') return ps;
2319
+ ps = query_params_new(0);
2320
+ if (!query || query[0] == '\0')
2321
+ return ps;
2322
2323
while (*query) {
2324
char *name = NULL, *value = NULL;
2325
2326
/* Find the next separator, or end of the string. */
2327
- end = strchr (query, '&');
2328
+ end = strchr(query, '&');
2329
if (!end)
2330
- end = strchr (query, ';');
2331
+ end = strchr(query, ';');
2332
if (!end)
2333
- end = query + strlen (query);
2334
+ end = query + strlen(query);
2335
2336
/* Find the first '=' character between here and end. */
2337
- eq = strchr (query, '=');
2338
- if (eq && eq >= end) eq = NULL;
2339
+ eq = strchr(query, '=');
2340
+ if (eq && eq >= end)
2341
+ eq = NULL;
2342
2343
/* Empty section (eg. "&&"). */
2344
if (end == query)
2345
@@ -XXX,XX +XXX,XX @@ query_params_parse (const char *query)
2346
* and consistent with CGI.pm we assume value is "".
2347
*/
2348
else if (!eq) {
2349
- name = uri_string_unescape (query, end - query, NULL);
2350
+ name = uri_string_unescape(query, end - query, NULL);
2351
value = NULL;
2352
}
2353
/* Or if we have "name=" here (works around annoying
2354
* problem when calling uri_string_unescape with len = 0).
2355
*/
2356
- else if (eq+1 == end) {
2357
- name = uri_string_unescape (query, eq - query, NULL);
2358
+ else if (eq + 1 == end) {
2359
+ name = uri_string_unescape(query, eq - query, NULL);
2360
value = g_new0(char, 1);
2361
}
2362
/* If the '=' character is at the beginning then we have
2363
@@ -XXX,XX +XXX,XX @@ query_params_parse (const char *query)
2364
2365
/* Otherwise it's "name=value". */
2366
else {
2367
- name = uri_string_unescape (query, eq - query, NULL);
2368
- value = uri_string_unescape (eq+1, end - (eq+1), NULL);
2369
+ name = uri_string_unescape(query, eq - query, NULL);
2370
+ value = uri_string_unescape(eq + 1, end - (eq + 1), NULL);
2371
}
2372
2373
/* Append to the parameter set. */
2374
- query_params_append (ps, name, value);
2375
+ query_params_append(ps, name, value);
2376
g_free(name);
2377
g_free(value);
2378
2379
next:
2380
query = end;
2381
- if (*query) query ++; /* skip '&' separator */
2382
+ if (*query)
2383
+ query++; /* skip '&' separator */
2384
}
2385
2386
return ps;
2387
--
93
--
2388
2.14.3
94
2.40.1
2389
2390
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
dev could be NULL if the PCI device can not be found due to some
3
The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the fd
4
reasons, so we must not dereference the pointer in this case.
4
passing through the new 'fd' property.
5
5
6
Signed-off-by: Thomas Huth <thuth@redhat.com>
6
Since now we are using qemu_open() on '@path' if the virtio-blk driver
7
Message-id: 1519713884-2346-1-git-send-email-thuth@redhat.com
7
supports the fd passing, let's announce it.
8
In this way, the management layer can pass the file descriptor of an
9
already opened vhost-vdpa character device. This is useful especially
10
when the device can only be accessed with certain privileges.
11
12
Add the '@fdset' feature only when the virtio-blk-vhost-vdpa driver
13
in libblkio supports it.
14
15
Suggested-by: Markus Armbruster <armbru@redhat.com>
16
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
17
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
18
Message-id: 20230530071941.8954-3-sgarzare@redhat.com
8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
19
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
20
---
10
tests/libqos/virtio-pci.c | 4 +++-
21
qapi/block-core.json | 6 ++++++
11
1 file changed, 3 insertions(+), 1 deletion(-)
22
meson.build | 4 ++++
23
2 files changed, 10 insertions(+)
12
24
13
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
25
diff --git a/qapi/block-core.json b/qapi/block-core.json
14
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/libqos/virtio-pci.c
27
--- a/qapi/block-core.json
16
+++ b/tests/libqos/virtio-pci.c
28
+++ b/qapi/block-core.json
17
@@ -XXX,XX +XXX,XX @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
29
@@ -XXX,XX +XXX,XX @@
18
qvirtio_pci_foreach(bus, device_type, false, 0,
30
#
19
qvirtio_pci_assign_device, &dev);
31
# @path: path to the vhost-vdpa character device.
20
32
#
21
- dev->vdev.bus = &qvirtio_pci;
33
+# Features:
22
+ if (dev) {
34
+# @fdset: Member @path supports the special "/dev/fdset/N" path
23
+ dev->vdev.bus = &qvirtio_pci;
35
+# (since 8.1)
24
+ }
36
+#
25
37
# Since: 7.2
26
return dev;
38
##
27
}
39
{ 'struct': 'BlockdevOptionsVirtioBlkVhostVdpa',
40
'data': { 'path': 'str' },
41
+ 'features': [ { 'name' :'fdset',
42
+ 'if': 'CONFIG_BLKIO_VHOST_VDPA_FD' } ],
43
'if': 'CONFIG_BLKIO' }
44
45
##
46
diff --git a/meson.build b/meson.build
47
index XXXXXXX..XXXXXXX 100644
48
--- a/meson.build
49
+++ b/meson.build
50
@@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_LZO', lzo.found())
51
config_host_data.set('CONFIG_MPATH', mpathpersist.found())
52
config_host_data.set('CONFIG_MPATH_NEW_API', mpathpersist_new_api)
53
config_host_data.set('CONFIG_BLKIO', blkio.found())
54
+if blkio.found()
55
+ config_host_data.set('CONFIG_BLKIO_VHOST_VDPA_FD',
56
+ blkio.version().version_compare('>=1.3.0'))
57
+endif
58
config_host_data.set('CONFIG_CURL', curl.found())
59
config_host_data.set('CONFIG_CURSES', curses.found())
60
config_host_data.set('CONFIG_GBM', gbm.found())
28
--
61
--
29
2.14.3
62
2.40.1
30
31
diff view generated by jsdifflib