1
The following changes since commit a1cf5fac2b929ffa2abd1285401f2535ff8c6fea:
1
The following changes since commit 6c769690ac845fa62642a5f93b4e4bd906adab95:
2
2
3
Merge remote-tracking branch 'remotes/armbru/tags/pull-block-2017-02-21' into staging (2017-02-21 13:58:50 +0000)
3
Merge remote-tracking branch 'remotes/vsementsov/tags/pull-simplebench-2021-05-04' into staging (2021-05-21 12:02:34 +0100)
4
4
5
are available in the git repository at:
5
are available in the Git repository at:
6
6
7
git@github.com:codyprime/qemu-kvm-jtc.git tags/block-pull-request
7
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
8
8
9
for you to fetch changes up to 6135c5e12606b8413708384e3e7d43f6010c5941:
9
for you to fetch changes up to 0a6f0c76a030710780ce10d6347a70f098024d21:
10
10
11
qemu-options: Fix broken sheepdog URL (2017-02-21 10:38:09 -0500)
11
coroutine-sleep: introduce qemu_co_sleep (2021-05-21 18:22:33 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches
14
Pull request
15
16
(Resent due to an email preparation mistake.)
17
15
----------------------------------------------------------------
18
----------------------------------------------------------------
16
19
17
Anton Nefedov (1):
20
Paolo Bonzini (6):
18
mirror: do not increase offset during initial zero_or_discard phase
21
coroutine-sleep: use a stack-allocated timer
22
coroutine-sleep: disallow NULL QemuCoSleepState** argument
23
coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing
24
coroutine-sleep: move timer out of QemuCoSleepState
25
coroutine-sleep: replace QemuCoSleepState pointer with struct in the
26
API
27
coroutine-sleep: introduce qemu_co_sleep
19
28
20
Jeff Cody (1):
29
Philippe Mathieu-Daudé (1):
21
QAPI: Fix blockdev-add example documentation
30
bitops.h: Improve find_xxx_bit() documentation
22
31
23
Kevin Wolf (6):
32
Zenghui Yu (1):
24
iscsi: Split URL into individual options
33
multi-process: Initialize variables declared with g_auto*
25
iscsi: Handle -iscsi user/password in bdrv_parse_filename()
26
iscsi: Add initiator-name option
27
iscsi: Add header-digest option
28
iscsi: Add timeout option
29
iscsi: Add blockdev-add support
30
34
31
Thomas Huth (1):
35
include/qemu/bitops.h | 15 ++++++--
32
qemu-options: Fix broken sheepdog URL
36
include/qemu/coroutine.h | 27 ++++++++-----
33
37
block/block-copy.c | 10 ++---
34
block/iscsi.c | 353 +++++++++++++++++++++++++++++++--------------------
38
block/nbd.c | 14 +++----
35
block/mirror.c | 9 +-
39
hw/remote/memory.c | 5 +--
36
qapi/block-core.json | 125 +++++++++++++-----
40
hw/remote/proxy.c | 3 +-
37
qemu-options.hx | 2 +-
41
util/qemu-coroutine-sleep.c | 75 +++++++++++++++++++------------------
38
4 files changed, 317 insertions(+), 172 deletions(-)
42
7 files changed, 79 insertions(+), 70 deletions(-)
39
43
40
--
44
--
41
2.9.3
45
2.31.1
42
46
43
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Zenghui Yu <yuzenghui@huawei.com>
2
2
3
The sheepdog URL is broken twice: First it uses a duplicated
3
Quote docs/devel/style.rst (section "Automatic memory deallocation"):
4
http:// prefix, second the website seems to have moved to
5
https://sheepdog.github.io/sheepdog/ instead.
6
4
7
Signed-off-by: Thomas Huth <thuth@redhat.com>
5
* Variables declared with g_auto* MUST always be initialized,
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
6
otherwise the cleanup function will use uninitialized stack memory
7
8
Initialize @name properly to get rid of the compilation error (using
9
gcc-7.3.0 on CentOS):
10
11
../hw/remote/proxy.c: In function 'pci_proxy_dev_realize':
12
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized]
13
g_free (*pp);
14
^~~~~~~~~~~~
15
../hw/remote/proxy.c:350:30: note: 'name' was declared here
16
g_autofree char *name;
17
^~~~
18
19
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
20
Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>
21
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22
Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>
23
Message-id: 20210312112143.1369-1-yuzenghui@huawei.com
24
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
25
---
10
qemu-options.hx | 2 +-
26
hw/remote/memory.c | 5 ++---
11
1 file changed, 1 insertion(+), 1 deletion(-)
27
hw/remote/proxy.c | 3 +--
28
2 files changed, 3 insertions(+), 5 deletions(-)
12
29
13
diff --git a/qemu-options.hx b/qemu-options.hx
30
diff --git a/hw/remote/memory.c b/hw/remote/memory.c
14
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
15
--- a/qemu-options.hx
32
--- a/hw/remote/memory.c
16
+++ b/qemu-options.hx
33
+++ b/hw/remote/memory.c
17
@@ -XXX,XX +XXX,XX @@ Example
34
@@ -XXX,XX +XXX,XX @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
18
qemu-system-i386 --drive file=sheepdog://192.0.2.1:30000/MyVirtualMachine
35
19
@end example
36
remote_sysmem_reset();
20
37
21
-See also @url{http://http://www.osrg.net/sheepdog/}.
38
- for (region = 0; region < msg->num_fds; region++) {
22
+See also @url{https://sheepdog.github.io/sheepdog/}.
39
- g_autofree char *name;
23
40
+ for (region = 0; region < msg->num_fds; region++, suffix++) {
24
@item GlusterFS
41
+ g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
25
GlusterFS is a user space distributed file system.
42
subregion = g_new(MemoryRegion, 1);
43
- name = g_strdup_printf("remote-mem-%u", suffix++);
44
memory_region_init_ram_from_fd(subregion, NULL,
45
name, sysmem_info->sizes[region],
46
true, msg->fds[region],
47
diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/remote/proxy.c
50
+++ b/hw/remote/proxy.c
51
@@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp)
52
PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY;
53
54
if (size) {
55
- g_autofree char *name;
56
+ g_autofree char *name = g_strdup_printf("bar-region-%d", i);
57
pdev->region[i].dev = pdev;
58
pdev->region[i].present = true;
59
if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) {
60
pdev->region[i].memory = true;
61
}
62
- name = g_strdup_printf("bar-region-%d", i);
63
memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev),
64
&proxy_mr_ops, &pdev->region[i],
65
name, size);
26
--
66
--
27
2.9.3
67
2.31.1
28
68
29
diff view generated by jsdifflib
1
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
If explicit zeroing out before mirroring is required for the target image,
3
Document the following functions return the bitmap size
4
it moves the block job offset counter to EOF, then offset and len counters
4
if no matching bit is found:
5
count the image size twice. There is no harm but stats are confusing,
6
specifically the progress of the operation is always reported as 99% by
7
management tools.
8
5
9
The patch skips offset increase for the first "technical" pass over the
6
- find_first_bit
10
image. This should not cause any further harm.
7
- find_next_bit
8
- find_last_bit
9
- find_first_zero_bit
10
- find_next_zero_bit
11
11
12
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Signed-off-by: Denis V. Lunev <den@openvz.org>
13
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Reviewed-by: Eric Blake <eblake@redhat.com>
15
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
16
Message-id: 1486045515-8009-1-git-send-email-den@openvz.org
15
Message-id: 20210510200758.2623154-2-philmd@redhat.com
17
CC: Jeff Cody <jcody@redhat.com>
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
CC: Kevin Wolf <kwolf@redhat.com>
19
CC: Max Reitz <mreitz@redhat.com>
20
CC: Eric Blake <eblake@redhat.com>
21
Signed-off-by: Jeff Cody <jcody@redhat.com>
22
---
17
---
23
block/mirror.c | 9 +++++++--
18
include/qemu/bitops.h | 15 ++++++++++++---
24
1 file changed, 7 insertions(+), 2 deletions(-)
19
1 file changed, 12 insertions(+), 3 deletions(-)
25
20
26
diff --git a/block/mirror.c b/block/mirror.c
21
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
27
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
28
--- a/block/mirror.c
23
--- a/include/qemu/bitops.h
29
+++ b/block/mirror.c
24
+++ b/include/qemu/bitops.h
30
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorBlockJob {
25
@@ -XXX,XX +XXX,XX @@ static inline int test_bit(long nr, const unsigned long *addr)
31
bool waiting_for_io;
26
* @addr: The address to start the search at
32
int target_cluster_sectors;
27
* @size: The maximum size to search
33
int max_iov;
28
*
34
+ bool initial_zeroing_ongoing;
29
- * Returns the bit number of the first set bit, or size.
35
} MirrorBlockJob;
30
+ * Returns the bit number of the last set bit,
36
31
+ * or @size if there is no set bit in the bitmap.
37
typedef struct MirrorOp {
32
*/
38
@@ -XXX,XX +XXX,XX @@ static void mirror_iteration_done(MirrorOp *op, int ret)
33
unsigned long find_last_bit(const unsigned long *addr,
39
if (s->cow_bitmap) {
34
unsigned long size);
40
bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
35
@@ -XXX,XX +XXX,XX @@ unsigned long find_last_bit(const unsigned long *addr,
41
}
36
* @addr: The address to base the search on
42
- s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
37
* @offset: The bitnumber to start searching at
43
+ if (!s->initial_zeroing_ongoing) {
38
* @size: The bitmap size in bits
44
+ s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
39
+ *
45
+ }
40
+ * Returns the bit number of the next set bit,
46
}
41
+ * or @size if there are no further set bits in the bitmap.
47
-
42
*/
48
qemu_iovec_destroy(&op->qiov);
43
unsigned long find_next_bit(const unsigned long *addr,
49
g_free(op);
44
unsigned long size,
50
45
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_bit(const unsigned long *addr,
51
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
46
* @addr: The address to base the search on
52
return 0;
47
* @offset: The bitnumber to start searching at
53
}
48
* @size: The bitmap size in bits
54
49
+ *
55
+ s->initial_zeroing_ongoing = true;
50
+ * Returns the bit number of the next cleared bit,
56
for (sector_num = 0; sector_num < end; ) {
51
+ * or @size if there are no further clear bits in the bitmap.
57
int nb_sectors = MIN(end - sector_num,
52
*/
58
QEMU_ALIGN_DOWN(INT_MAX, s->granularity) >> BDRV_SECTOR_BITS);
53
59
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
54
unsigned long find_next_zero_bit(const unsigned long *addr,
60
mirror_throttle(s);
55
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_zero_bit(const unsigned long *addr,
61
56
* @addr: The address to start the search at
62
if (block_job_is_cancelled(&s->common)) {
57
* @size: The maximum size to search
63
+ s->initial_zeroing_ongoing = false;
58
*
64
return 0;
59
- * Returns the bit number of the first set bit.
65
}
60
+ * Returns the bit number of the first set bit,
66
61
+ * or @size if there is no set bit in the bitmap.
67
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
62
*/
68
}
63
static inline unsigned long find_first_bit(const unsigned long *addr,
69
64
unsigned long size)
70
mirror_wait_for_all_io(s);
65
@@ -XXX,XX +XXX,XX @@ static inline unsigned long find_first_bit(const unsigned long *addr,
71
+ s->initial_zeroing_ongoing = false;
66
* @addr: The address to start the search at
72
}
67
* @size: The maximum size to search
73
68
*
74
/* First part, loop on the sectors and initialize the dirty bitmap. */
69
- * Returns the bit number of the first cleared bit.
70
+ * Returns the bit number of the first cleared bit,
71
+ * or @size if there is no clear bit in the bitmap.
72
*/
73
static inline unsigned long find_first_zero_bit(const unsigned long *addr,
74
unsigned long size)
75
--
75
--
76
2.9.3
76
2.31.1
77
77
78
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This was previously only available with -iscsi. Again, after this patch,
3
The lifetime of the timer is well-known (it cannot outlive
4
the -iscsi option only takes effect if an URL is given. New users are
4
qemu_co_sleep_ns_wakeable, because it's deleted by the time the
5
supposed to use the new driver-specific option.
5
coroutine resumes), so it is not necessary to place it on the heap.
6
6
7
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: Fam Zheng <famz@redhat.com>
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Message-id: 20210517100548.28806-2-pbonzini@redhat.com
10
Signed-off-by: Jeff Cody <jcody@redhat.com>
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
11
---
12
block/iscsi.c | 32 +++++++++++++++-----------------
12
util/qemu-coroutine-sleep.c | 9 ++++-----
13
1 file changed, 15 insertions(+), 17 deletions(-)
13
1 file changed, 4 insertions(+), 5 deletions(-)
14
14
15
diff --git a/block/iscsi.c b/block/iscsi.c
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/iscsi.c
17
--- a/util/qemu-coroutine-sleep.c
18
+++ b/block/iscsi.c
18
+++ b/util/qemu-coroutine-sleep.c
19
@@ -XXX,XX +XXX,XX @@ static void parse_header_digest(struct iscsi_context *iscsi, const char *target,
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
20
21
struct QemuCoSleepState {
22
Coroutine *co;
23
- QEMUTimer *ts;
24
+ QEMUTimer ts;
25
QemuCoSleepState **user_state_pointer;
26
};
27
28
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
29
if (sleep_state->user_state_pointer) {
30
*sleep_state->user_state_pointer = NULL;
20
}
31
}
32
- timer_del(sleep_state->ts);
33
+ timer_del(&sleep_state->ts);
34
aio_co_wake(sleep_state->co);
21
}
35
}
22
36
23
-static char *parse_initiator_name(const char *target)
37
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
24
+static char *get_initiator_name(QemuOpts *opts)
38
AioContext *ctx = qemu_get_current_aio_context();
25
{
39
QemuCoSleepState state = {
26
- QemuOptsList *list;
40
.co = qemu_coroutine_self(),
27
- QemuOpts *opts;
41
- .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state),
28
const char *name;
42
.user_state_pointer = sleep_state,
29
char *iscsi_name;
43
};
30
UuidInfo *uuid_info;
44
31
45
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
32
- list = qemu_find_opts("iscsi");
46
abort();
33
- if (list) {
34
- opts = qemu_opts_find(list, target);
35
- if (!opts) {
36
- opts = QTAILQ_FIRST(&list->head);
37
- }
38
- if (opts) {
39
- name = qemu_opt_get(opts, "initiator-name");
40
- if (name) {
41
- return g_strdup(name);
42
- }
43
- }
44
+ name = qemu_opt_get(opts, "initiator-name");
45
+ if (name) {
46
+ return g_strdup(name);
47
}
47
}
48
48
49
uuid_info = qmp_query_uuid(NULL);
49
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
50
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
50
if (sleep_state) {
51
{
51
*sleep_state = &state;
52
QemuOptsList *list;
53
QemuOpts *opts;
54
- const char *user, *password, *password_secret;
55
+ const char *user, *password, *password_secret, *initiator_name;
56
57
list = qemu_find_opts("iscsi");
58
if (!list) {
59
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
60
if (password_secret) {
61
qdict_set_default_str(options, "password-secret", password_secret);
62
}
52
}
63
+
53
- timer_mod(state.ts, qemu_clock_get_ns(type) + ns);
64
+ initiator_name = qemu_opt_get(opts, "initiator-name");
54
+ timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
65
+ if (initiator_name) {
55
qemu_coroutine_yield();
66
+ qdict_set_default_str(options, "initiator-name", initiator_name);
56
if (sleep_state) {
67
+ }
57
/*
58
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
59
*/
60
assert(*sleep_state == NULL);
61
}
62
- timer_free(state.ts);
68
}
63
}
69
70
/*
71
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
72
.name = "lun",
73
.type = QEMU_OPT_NUMBER,
74
},
75
+ {
76
+ .name = "initiator-name",
77
+ .type = QEMU_OPT_STRING,
78
+ },
79
{ /* end of list */ }
80
},
81
};
82
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
83
84
memset(iscsilun, 0, sizeof(IscsiLun));
85
86
- initiator_name = parse_initiator_name(target);
87
+ initiator_name = get_initiator_name(opts);
88
89
iscsi = iscsi_create_context(initiator_name);
90
if (iscsi == NULL) {
91
--
64
--
92
2.9.3
65
2.31.1
93
66
94
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This adds blockdev-add support for iscsi devices.
3
Simplify the code by removing conditionals. qemu_co_sleep_ns
4
can simply point the argument to an on-stack temporary.
4
5
5
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
6
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Reviewed-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Message-id: 20210517100548.28806-3-pbonzini@redhat.com
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
10
---
10
block/iscsi.c | 14 ++++++----
11
include/qemu/coroutine.h | 5 +++--
11
qapi/block-core.json | 75 ++++++++++++++++++++++++++++++++++++++++++++++++----
12
util/qemu-coroutine-sleep.c | 18 +++++-------------
12
2 files changed, 79 insertions(+), 10 deletions(-)
13
2 files changed, 8 insertions(+), 15 deletions(-)
13
14
14
diff --git a/block/iscsi.c b/block/iscsi.c
15
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/block/iscsi.c
17
--- a/include/qemu/coroutine.h
17
+++ b/block/iscsi.c
18
+++ b/include/qemu/coroutine.h
18
@@ -XXX,XX +XXX,XX @@ static void apply_header_digest(struct iscsi_context *iscsi, QemuOpts *opts,
19
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleepState QemuCoSleepState;
19
digest = qemu_opt_get(opts, "header-digest");
20
20
if (!digest) {
21
/**
21
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
22
* Yield the coroutine for a given duration. During this yield, @sleep_state
22
- } else if (!strcmp(digest, "CRC32C")) {
23
- * (if not NULL) is set to an opaque pointer, which may be used for
23
+ } else if (!strcmp(digest, "crc32c")) {
24
+ * is set to an opaque pointer, which may be used for
24
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C);
25
* qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
25
- } else if (!strcmp(digest, "NONE")) {
26
* timer fires. Don't save the obtained value to other variables and don't call
26
+ } else if (!strcmp(digest, "none")) {
27
* qemu_co_sleep_wake from another aio context.
27
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE);
28
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
28
- } else if (!strcmp(digest, "CRC32C-NONE")) {
29
QemuCoSleepState **sleep_state);
29
+ } else if (!strcmp(digest, "crc32c-none")) {
30
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
30
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C_NONE);
31
{
31
- } else if (!strcmp(digest, "NONE-CRC32C")) {
32
- qemu_co_sleep_ns_wakeable(type, ns, NULL);
32
+ } else if (!strcmp(digest, "none-crc32c")) {
33
+ QemuCoSleepState *unused = NULL;
33
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
34
+ qemu_co_sleep_ns_wakeable(type, ns, &unused);
34
} else {
35
}
35
error_setg(errp, "Invalid header-digest setting : %s", digest);
36
36
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
37
/**
37
38
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
38
header_digest = qemu_opt_get(opts, "header-digest");
39
index XXXXXXX..XXXXXXX 100644
39
if (header_digest) {
40
--- a/util/qemu-coroutine-sleep.c
40
- qdict_set_default_str(options, "header-digest", header_digest);
41
+++ b/util/qemu-coroutine-sleep.c
41
+ /* -iscsi takes upper case values, but QAPI only supports lower case
42
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
42
+ * enum constant names, so we have to convert here. */
43
qemu_co_sleep_ns__scheduled, NULL);
43
+ char *qapi_value = g_ascii_strdown(header_digest, -1);
44
44
+ qdict_set_default_str(options, "header-digest", qapi_value);
45
assert(scheduled == qemu_co_sleep_ns__scheduled);
45
+ g_free(qapi_value);
46
- if (sleep_state->user_state_pointer) {
47
- *sleep_state->user_state_pointer = NULL;
48
- }
49
+ *sleep_state->user_state_pointer = NULL;
50
timer_del(&sleep_state->ts);
51
aio_co_wake(sleep_state->co);
52
}
53
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
46
}
54
}
47
55
48
timeout = qemu_opt_get(opts, "timeout");
56
aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
49
diff --git a/qapi/block-core.json b/qapi/block-core.json
57
- if (sleep_state) {
50
index XXXXXXX..XXXXXXX 100644
58
- *sleep_state = &state;
51
--- a/qapi/block-core.json
59
- }
52
+++ b/qapi/block-core.json
60
+ *sleep_state = &state;
53
@@ -XXX,XX +XXX,XX @@
61
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
54
# @nfs: Since 2.8
62
qemu_coroutine_yield();
55
# @replication: Since 2.8
63
- if (sleep_state) {
56
# @ssh: Since 2.8
64
- /*
57
+# @iscsi: Since 2.9
65
- * Note that *sleep_state is cleared during qemu_co_sleep_wake
58
#
66
- * before resuming this coroutine.
59
# Since: 2.0
67
- */
60
##
68
- assert(*sleep_state == NULL);
61
{ 'enum': 'BlockdevDriver',
69
- }
62
'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
63
'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom',
64
- 'host_device', 'http', 'https', 'luks', 'nbd', 'nfs', 'null-aio',
65
- 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw',
66
- 'replication', 'ssh', 'vdi', 'vhdx', 'vmdk', 'vpc',
67
- 'vvfat' ] }
68
+ 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs',
69
+ 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed',
70
+ 'quorum', 'raw', 'replication', 'ssh', 'vdi', 'vhdx', 'vmdk',
71
+ 'vpc', 'vvfat' ] }
72
73
##
74
# @BlockdevOptionsFile:
75
@@ -XXX,XX +XXX,XX @@
76
'*logfile': 'str' } }
77
78
##
79
+# @IscsiTransport:
80
+#
81
+# An enumeration of libiscsi transport types
82
+#
83
+# Since: 2.9
84
+##
85
+{ 'enum': 'IscsiTransport',
86
+ 'data': [ 'tcp', 'iser' ] }
87
+
70
+
88
+##
71
+ /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
89
+# @IscsiHeaderDigest:
72
+ assert(*sleep_state == NULL);
90
+#
73
}
91
+# An enumeration of header digests supported by libiscsi
92
+#
93
+# Since: 2.9
94
+##
95
+{ 'enum': 'IscsiHeaderDigest',
96
+ 'prefix': 'QAPI_ISCSI_HEADER_DIGEST',
97
+ 'data': [ 'crc32c', 'none', 'crc32c-none', 'none-crc32c' ] }
98
+
99
+##
100
+# @BlockdevOptionsIscsi:
101
+#
102
+# @transport The iscsi transport type
103
+#
104
+# @portal The address of the iscsi portal
105
+#
106
+# @target The target iqn name
107
+#
108
+# @lun #optional LUN to connect to. Defaults to 0.
109
+#
110
+# @user #optional User name to log in with. If omitted, no CHAP
111
+# authentication is performed.
112
+#
113
+# @password-secret #optional The ID of a QCryptoSecret object providing
114
+# the password for the login. This option is required if
115
+# @user is specified.
116
+#
117
+# @initiator-name #optional The iqn name we want to identify to the target
118
+# as. If this option is not specified, an initiator name is
119
+# generated automatically.
120
+#
121
+# @header-digest #optional The desired header digest. Defaults to
122
+# none-crc32c.
123
+#
124
+# @timeout #optional Timeout in seconds after which a request will
125
+# timeout. 0 means no timeout and is the default.
126
+#
127
+# Driver specific block device options for iscsi
128
+#
129
+# Since: 2.9
130
+##
131
+{ 'struct': 'BlockdevOptionsIscsi',
132
+ 'data': { 'transport': 'IscsiTransport',
133
+ 'portal': 'str',
134
+ 'target': 'str',
135
+ '*lun': 'int',
136
+ '*user': 'str',
137
+ '*password-secret': 'str',
138
+ '*initiator-name': 'str',
139
+ '*header-digest': 'IscsiHeaderDigest',
140
+ '*timeout': 'int' } }
141
+
142
+##
143
# @ReplicationMode:
144
#
145
# An enumeration of replication modes.
146
@@ -XXX,XX +XXX,XX @@
147
'host_device':'BlockdevOptionsFile',
148
'http': 'BlockdevOptionsCurl',
149
'https': 'BlockdevOptionsCurl',
150
-# TODO iscsi: Wait for structured options
151
+ 'iscsi': 'BlockdevOptionsIscsi',
152
'luks': 'BlockdevOptionsLUKS',
153
'nbd': 'BlockdevOptionsNbd',
154
'nfs': 'BlockdevOptionsNfs',
155
--
74
--
156
2.9.3
75
2.31.1
157
76
158
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This was previously only available with -iscsi. Again, after this patch,
3
All callers of qemu_co_sleep_wake are checking whether they are passing
4
the -iscsi option only takes effect if an URL is given. New users are
4
a NULL argument inside the pointer-to-pointer: do the check in
5
supposed to use the new driver-specific option.
5
qemu_co_sleep_wake itself.
6
6
7
All -iscsi options have a corresponding driver-specific option for the
7
As a side effect, qemu_co_sleep_wake can be called more than once and
8
iscsi block driver now.
8
it will only wake the coroutine once; after the first time, the argument
9
will be set to NULL via *sleep_state->user_state_pointer. However, this
10
would not be safe unless co_sleep_cb keeps using the QemuCoSleepState*
11
directly, so make it go through the pointer-to-pointer instead.
9
12
10
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
13
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11
Reviewed-by: Fam Zheng <famz@redhat.com>
14
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
Message-id: 20210517100548.28806-4-pbonzini@redhat.com
13
Signed-off-by: Jeff Cody <jcody@redhat.com>
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
---
17
---
15
block/iscsi.c | 37 +++++++++++--------------------------
18
block/block-copy.c | 4 +---
16
1 file changed, 11 insertions(+), 26 deletions(-)
19
block/nbd.c | 8 ++------
20
util/qemu-coroutine-sleep.c | 21 ++++++++++++---------
21
3 files changed, 15 insertions(+), 18 deletions(-)
17
22
18
diff --git a/block/iscsi.c b/block/iscsi.c
23
diff --git a/block/block-copy.c b/block/block-copy.c
19
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
20
--- a/block/iscsi.c
25
--- a/block/block-copy.c
21
+++ b/block/iscsi.c
26
+++ b/block/block-copy.c
22
@@ -XXX,XX +XXX,XX @@ static char *get_initiator_name(QemuOpts *opts)
27
@@ -XXX,XX +XXX,XX @@ out:
23
return iscsi_name;
28
29
void block_copy_kick(BlockCopyCallState *call_state)
30
{
31
- if (call_state->sleep_state) {
32
- qemu_co_sleep_wake(call_state->sleep_state);
33
- }
34
+ qemu_co_sleep_wake(call_state->sleep_state);
24
}
35
}
25
36
26
-static int parse_timeout(const char *target)
37
/*
27
-{
38
diff --git a/block/nbd.c b/block/nbd.c
28
- QemuOptsList *list;
39
index XXXXXXX..XXXXXXX 100644
29
- QemuOpts *opts;
40
--- a/block/nbd.c
30
- const char *timeout;
41
+++ b/block/nbd.c
31
-
42
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
32
- list = qemu_find_opts("iscsi");
43
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
33
- if (list) {
44
34
- opts = qemu_opts_find(list, target);
45
s->drained = true;
35
- if (!opts) {
46
- if (s->connection_co_sleep_ns_state) {
36
- opts = QTAILQ_FIRST(&list->head);
47
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
48
- }
49
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
50
51
nbd_co_establish_connection_cancel(bs, false);
52
53
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
54
55
s->state = NBD_CLIENT_QUIT;
56
if (s->connection_co) {
57
- if (s->connection_co_sleep_ns_state) {
58
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
37
- }
59
- }
38
- if (opts) {
60
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
39
- timeout = qemu_opt_get(opts, "timeout");
61
nbd_co_establish_connection_cancel(bs, true);
40
- if (timeout) {
62
}
41
- return atoi(timeout);
63
if (qemu_in_coroutine()) {
42
- }
64
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
43
- }
65
index XXXXXXX..XXXXXXX 100644
44
- }
66
--- a/util/qemu-coroutine-sleep.c
45
-
67
+++ b/util/qemu-coroutine-sleep.c
46
- return 0;
68
@@ -XXX,XX +XXX,XX @@ struct QemuCoSleepState {
47
-}
69
48
-
70
void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
49
static void iscsi_nop_timed_event(void *opaque)
50
{
71
{
51
IscsiLun *iscsilun = opaque;
72
- /* Write of schedule protected by barrier write in aio_co_schedule */
52
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
73
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
53
QemuOptsList *list;
74
- qemu_co_sleep_ns__scheduled, NULL);
54
QemuOpts *opts;
75
+ if (sleep_state) {
55
const char *user, *password, *password_secret, *initiator_name,
76
+ /* Write of schedule protected by barrier write in aio_co_schedule */
56
- *header_digest;
77
+ const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
57
+ *header_digest, *timeout;
78
+ qemu_co_sleep_ns__scheduled, NULL);
58
79
59
list = qemu_find_opts("iscsi");
80
- assert(scheduled == qemu_co_sleep_ns__scheduled);
60
if (!list) {
81
- *sleep_state->user_state_pointer = NULL;
61
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
82
- timer_del(&sleep_state->ts);
62
if (header_digest) {
83
- aio_co_wake(sleep_state->co);
63
qdict_set_default_str(options, "header-digest", header_digest);
84
+ assert(scheduled == qemu_co_sleep_ns__scheduled);
64
}
85
+ *sleep_state->user_state_pointer = NULL;
65
+
86
+ timer_del(&sleep_state->ts);
66
+ timeout = qemu_opt_get(opts, "timeout");
87
+ aio_co_wake(sleep_state->co);
67
+ if (timeout) {
68
+ qdict_set_default_str(options, "timeout", timeout);
69
+ }
88
+ }
70
}
89
}
71
90
72
/*
91
static void co_sleep_cb(void *opaque)
73
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_filename(const char *filename, QDict *options,
92
{
74
iscsi_destroy_url(iscsi_url);
93
- qemu_co_sleep_wake(opaque);
94
+ QemuCoSleepState **sleep_state = opaque;
95
+ qemu_co_sleep_wake(*sleep_state);
75
}
96
}
76
97
77
-/* TODO Add -iscsi options */
98
void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
78
static QemuOptsList runtime_opts = {
99
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
79
.name = "iscsi",
100
abort();
80
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
81
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
82
.name = "header-digest",
83
.type = QEMU_OPT_STRING,
84
},
85
+ {
86
+ .name = "timeout",
87
+ .type = QEMU_OPT_NUMBER,
88
+ },
89
{ /* end of list */ }
90
},
91
};
92
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
93
}
101
}
94
102
95
/* timeout handling is broken in libiscsi before 1.15.0 */
103
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
96
- timeout = parse_timeout(target);
104
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
97
+ timeout = qemu_opt_get_number(opts, "timeout", 0);
105
*sleep_state = &state;
98
#if LIBISCSI_API_VERSION >= 20150621
106
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
99
iscsi_set_timeout(iscsi, timeout);
107
qemu_coroutine_yield();
100
#else
101
--
108
--
102
2.9.3
109
2.31.1
103
110
104
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This introduces a .bdrv_parse_filename handler for iscsi which parses an
3
This simplification is enabled by the previous patch. Now aio_co_wake
4
URL if given and translates it to individual options.
4
will only be called once, therefore we do not care about a spurious
5
firing of the timer after a qemu_co_sleep_wake.
5
6
6
Reviewed-by: Fam Zheng <famz@redhat.com>
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9
Message-id: 20210517100548.28806-5-pbonzini@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
11
---
10
block/iscsi.c | 193 ++++++++++++++++++++++++++++++++++++++++++----------------
12
util/qemu-coroutine-sleep.c | 8 ++++----
11
1 file changed, 140 insertions(+), 53 deletions(-)
13
1 file changed, 4 insertions(+), 4 deletions(-)
12
14
13
diff --git a/block/iscsi.c b/block/iscsi.c
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/block/iscsi.c
17
--- a/util/qemu-coroutine-sleep.c
16
+++ b/block/iscsi.c
18
+++ b/util/qemu-coroutine-sleep.c
17
@@ -XXX,XX +XXX,XX @@ static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
20
21
struct QemuCoSleepState {
22
Coroutine *co;
23
- QEMUTimer ts;
24
QemuCoSleepState **user_state_pointer;
25
};
26
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
28
29
assert(scheduled == qemu_co_sleep_ns__scheduled);
30
*sleep_state->user_state_pointer = NULL;
31
- timer_del(&sleep_state->ts);
32
aio_co_wake(sleep_state->co);
18
}
33
}
19
}
34
}
20
35
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
21
-/* TODO Convert to fine grained options */
36
QemuCoSleepState **sleep_state)
22
-static QemuOptsList runtime_opts = {
23
- .name = "iscsi",
24
- .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
25
- .desc = {
26
- {
27
- .name = "filename",
28
- .type = QEMU_OPT_STRING,
29
- .help = "URL to the iscsi image",
30
- },
31
- { /* end of list */ }
32
- },
33
-};
34
-
35
static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,
36
int evpd, int pc, void **inq, Error **errp)
37
{
37
{
38
@@ -XXX,XX +XXX,XX @@ out:
38
AioContext *ctx = qemu_get_current_aio_context();
39
* We support iscsi url's on the form
39
+ QEMUTimer ts;
40
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
40
QemuCoSleepState state = {
41
*/
41
.co = qemu_coroutine_self(),
42
+static void iscsi_parse_filename(const char *filename, QDict *options,
42
.user_state_pointer = sleep_state,
43
+ Error **errp)
43
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
44
+{
44
abort();
45
+ struct iscsi_url *iscsi_url;
46
+ const char *transport_name;
47
+ char *lun_str;
48
+
49
+ iscsi_url = iscsi_parse_full_url(NULL, filename);
50
+ if (iscsi_url == NULL) {
51
+ error_setg(errp, "Failed to parse URL : %s", filename);
52
+ return;
53
+ }
54
+
55
+#if LIBISCSI_API_VERSION >= (20160603)
56
+ switch (iscsi_url->transport) {
57
+ case TCP_TRANSPORT:
58
+ transport_name = "tcp";
59
+ break;
60
+ case ISER_TRANSPORT:
61
+ transport_name = "iser";
62
+ break;
63
+ default:
64
+ error_setg(errp, "Unknown transport type (%d)",
65
+ iscsi_url->transport);
66
+ return;
67
+ }
68
+#else
69
+ transport_name = "tcp";
70
+#endif
71
+
72
+ qdict_set_default_str(options, "transport", transport_name);
73
+ qdict_set_default_str(options, "portal", iscsi_url->portal);
74
+ qdict_set_default_str(options, "target", iscsi_url->target);
75
+
76
+ lun_str = g_strdup_printf("%d", iscsi_url->lun);
77
+ qdict_set_default_str(options, "lun", lun_str);
78
+ g_free(lun_str);
79
+
80
+ if (iscsi_url->user[0] != '\0') {
81
+ qdict_set_default_str(options, "user", iscsi_url->user);
82
+ qdict_set_default_str(options, "password", iscsi_url->passwd);
83
+ }
84
+
85
+ iscsi_destroy_url(iscsi_url);
86
+}
87
+
88
+/* TODO Add -iscsi options */
89
+static QemuOptsList runtime_opts = {
90
+ .name = "iscsi",
91
+ .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
92
+ .desc = {
93
+ {
94
+ .name = "transport",
95
+ .type = QEMU_OPT_STRING,
96
+ },
97
+ {
98
+ .name = "portal",
99
+ .type = QEMU_OPT_STRING,
100
+ },
101
+ {
102
+ .name = "target",
103
+ .type = QEMU_OPT_STRING,
104
+ },
105
+ {
106
+ .name = "user",
107
+ .type = QEMU_OPT_STRING,
108
+ },
109
+ {
110
+ .name = "password",
111
+ .type = QEMU_OPT_STRING,
112
+ },
113
+ {
114
+ .name = "lun",
115
+ .type = QEMU_OPT_NUMBER,
116
+ },
117
+ { /* end of list */ }
118
+ },
119
+};
120
+
121
static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
122
Error **errp)
123
{
124
IscsiLun *iscsilun = bs->opaque;
125
struct iscsi_context *iscsi = NULL;
126
- struct iscsi_url *iscsi_url = NULL;
127
struct scsi_task *task = NULL;
128
struct scsi_inquiry_standard *inq = NULL;
129
struct scsi_inquiry_supported_pages *inq_vpd;
130
char *initiator_name = NULL;
131
QemuOpts *opts;
132
Error *local_err = NULL;
133
- const char *filename;
134
- int i, ret = 0, timeout = 0;
135
+ const char *transport_name, *portal, *target;
136
+ const char *user, *password;
137
+#if LIBISCSI_API_VERSION >= (20160603)
138
+ enum iscsi_transport_type transport;
139
+#endif
140
+ int i, ret = 0, timeout = 0, lun;
141
142
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
143
qemu_opts_absorb_qdict(opts, options, &local_err);
144
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
145
goto out;
146
}
45
}
147
46
148
- filename = qemu_opt_get(opts, "filename");
47
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
149
+ transport_name = qemu_opt_get(opts, "transport");
48
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
150
+ portal = qemu_opt_get(opts, "portal");
49
*sleep_state = &state;
151
+ target = qemu_opt_get(opts, "target");
50
- timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
152
+ user = qemu_opt_get(opts, "user");
51
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
153
+ password = qemu_opt_get(opts, "password");
52
qemu_coroutine_yield();
154
+ lun = qemu_opt_get_number(opts, "lun", 0);
53
+ timer_del(&ts);
155
54
156
- iscsi_url = iscsi_parse_full_url(iscsi, filename);
55
/* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
157
- if (iscsi_url == NULL) {
56
assert(*sleep_state == NULL);
158
- error_setg(errp, "Failed to parse URL : %s", filename);
159
+ if (!transport_name || !portal || !target) {
160
+ error_setg(errp, "Need all of transport, portal and target options");
161
+ ret = -EINVAL;
162
+ goto out;
163
+ }
164
+ if (user && !password) {
165
+ error_setg(errp, "If a user name is given, a password is required");
166
+ ret = -EINVAL;
167
+ goto out;
168
+ }
169
+
170
+ if (!strcmp(transport_name, "tcp")) {
171
+#if LIBISCSI_API_VERSION >= (20160603)
172
+ transport = TCP_TRANSPORT;
173
+ } else if (!strcmp(transport_name, "iser")) {
174
+ transport = ISER_TRANSPORT;
175
+#else
176
+ /* TCP is what older libiscsi versions always use */
177
+#endif
178
+ } else {
179
+ error_setg(errp, "Unknown transport: %s", transport_name);
180
ret = -EINVAL;
181
goto out;
182
}
183
184
memset(iscsilun, 0, sizeof(IscsiLun));
185
186
- initiator_name = parse_initiator_name(iscsi_url->target);
187
+ initiator_name = parse_initiator_name(target);
188
189
iscsi = iscsi_create_context(initiator_name);
190
if (iscsi == NULL) {
191
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
192
goto out;
193
}
194
#if LIBISCSI_API_VERSION >= (20160603)
195
- if (iscsi_init_transport(iscsi, iscsi_url->transport)) {
196
+ if (iscsi_init_transport(iscsi, transport)) {
197
error_setg(errp, ("Error initializing transport."));
198
ret = -EINVAL;
199
goto out;
200
}
201
#endif
202
- if (iscsi_set_targetname(iscsi, iscsi_url->target)) {
203
+ if (iscsi_set_targetname(iscsi, target)) {
204
error_setg(errp, "iSCSI: Failed to set target name.");
205
ret = -EINVAL;
206
goto out;
207
}
208
209
- if (iscsi_url->user[0] != '\0') {
210
- ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
211
- iscsi_url->passwd);
212
+ if (user) {
213
+ ret = iscsi_set_initiator_username_pwd(iscsi, user, password);
214
if (ret != 0) {
215
error_setg(errp, "Failed to set initiator username and password");
216
ret = -EINVAL;
217
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
218
}
219
220
/* check if we got CHAP username/password via the options */
221
- parse_chap(iscsi, iscsi_url->target, &local_err);
222
+ parse_chap(iscsi, target, &local_err);
223
if (local_err != NULL) {
224
error_propagate(errp, local_err);
225
ret = -EINVAL;
226
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
227
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
228
229
/* check if we got HEADER_DIGEST via the options */
230
- parse_header_digest(iscsi, iscsi_url->target, &local_err);
231
+ parse_header_digest(iscsi, target, &local_err);
232
if (local_err != NULL) {
233
error_propagate(errp, local_err);
234
ret = -EINVAL;
235
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
236
}
237
238
/* timeout handling is broken in libiscsi before 1.15.0 */
239
- timeout = parse_timeout(iscsi_url->target);
240
+ timeout = parse_timeout(target);
241
#if LIBISCSI_API_VERSION >= 20150621
242
iscsi_set_timeout(iscsi, timeout);
243
#else
244
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
245
}
246
#endif
247
248
- if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
249
+ if (iscsi_full_connect_sync(iscsi, portal, lun) != 0) {
250
error_setg(errp, "iSCSI: Failed to connect to LUN : %s",
251
iscsi_get_error(iscsi));
252
ret = -EINVAL;
253
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
254
255
iscsilun->iscsi = iscsi;
256
iscsilun->aio_context = bdrv_get_aio_context(bs);
257
- iscsilun->lun = iscsi_url->lun;
258
+ iscsilun->lun = lun;
259
iscsilun->has_write_same = true;
260
261
task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 0, 0,
262
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
263
out:
264
qemu_opts_del(opts);
265
g_free(initiator_name);
266
- if (iscsi_url != NULL) {
267
- iscsi_destroy_url(iscsi_url);
268
- }
269
if (task != NULL) {
270
scsi_free_scsi_task(task);
271
}
272
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_iscsi = {
273
.format_name = "iscsi",
274
.protocol_name = "iscsi",
275
276
- .instance_size = sizeof(IscsiLun),
277
- .bdrv_needs_filename = true,
278
- .bdrv_file_open = iscsi_open,
279
- .bdrv_close = iscsi_close,
280
- .bdrv_create = iscsi_create,
281
- .create_opts = &iscsi_create_opts,
282
- .bdrv_reopen_prepare = iscsi_reopen_prepare,
283
- .bdrv_reopen_commit = iscsi_reopen_commit,
284
- .bdrv_invalidate_cache = iscsi_invalidate_cache,
285
+ .instance_size = sizeof(IscsiLun),
286
+ .bdrv_parse_filename = iscsi_parse_filename,
287
+ .bdrv_file_open = iscsi_open,
288
+ .bdrv_close = iscsi_close,
289
+ .bdrv_create = iscsi_create,
290
+ .create_opts = &iscsi_create_opts,
291
+ .bdrv_reopen_prepare = iscsi_reopen_prepare,
292
+ .bdrv_reopen_commit = iscsi_reopen_commit,
293
+ .bdrv_invalidate_cache = iscsi_invalidate_cache,
294
295
.bdrv_getlength = iscsi_getlength,
296
.bdrv_get_info = iscsi_get_info,
297
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_iser = {
298
.format_name = "iser",
299
.protocol_name = "iser",
300
301
- .instance_size = sizeof(IscsiLun),
302
- .bdrv_needs_filename = true,
303
- .bdrv_file_open = iscsi_open,
304
- .bdrv_close = iscsi_close,
305
- .bdrv_create = iscsi_create,
306
- .create_opts = &iscsi_create_opts,
307
- .bdrv_reopen_prepare = iscsi_reopen_prepare,
308
- .bdrv_reopen_commit = iscsi_reopen_commit,
309
- .bdrv_invalidate_cache = iscsi_invalidate_cache,
310
+ .instance_size = sizeof(IscsiLun),
311
+ .bdrv_parse_filename = iscsi_parse_filename,
312
+ .bdrv_file_open = iscsi_open,
313
+ .bdrv_close = iscsi_close,
314
+ .bdrv_create = iscsi_create,
315
+ .create_opts = &iscsi_create_opts,
316
+ .bdrv_reopen_prepare = iscsi_reopen_prepare,
317
+ .bdrv_reopen_commit = iscsi_reopen_commit,
318
+ .bdrv_invalidate_cache = iscsi_invalidate_cache,
319
320
.bdrv_getlength = iscsi_getlength,
321
.bdrv_get_info = iscsi_get_info,
322
--
57
--
323
2.9.3
58
2.31.1
324
59
325
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This splits the logic in the old parse_chap() function into a part that
3
Right now, users of qemu_co_sleep_ns_wakeable are simply passing
4
parses the -iscsi options into the new driver-specific options, and
4
a pointer to QemuCoSleepState by reference to the function. But
5
another part that actually applies those options (called apply_chap()
5
QemuCoSleepState really is just a Coroutine*; making the
6
now).
6
content of the struct public is just as efficient and lets us
7
7
skip the user_state_pointer indirection.
8
Note that this means that username and password specified with -iscsi
8
9
only take effect when a URL is provided. This is intentional, -iscsi is
9
Since the usage is changed, take the occasion to rename the
10
a legacy interface only supported for compatibility, new users should
10
struct to QemuCoSleep.
11
use the proper driver-specific options.
11
12
12
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
Reviewed-by: Fam Zheng <famz@redhat.com>
13
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Message-id: 20210517100548.28806-6-pbonzini@redhat.com
15
Signed-off-by: Jeff Cody <jcody@redhat.com>
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
16
---
17
block/iscsi.c | 78 +++++++++++++++++++++++++++++++++--------------------------
17
include/qemu/coroutine.h | 23 +++++++++++----------
18
1 file changed, 44 insertions(+), 34 deletions(-)
18
block/block-copy.c | 8 ++++----
19
19
block/nbd.c | 10 ++++-----
20
diff --git a/block/iscsi.c b/block/iscsi.c
20
util/qemu-coroutine-sleep.c | 41 ++++++++++++++++---------------------
21
index XXXXXXX..XXXXXXX 100644
21
4 files changed, 39 insertions(+), 43 deletions(-)
22
--- a/block/iscsi.c
22
23
+++ b/block/iscsi.c
23
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
24
@@ -XXX,XX +XXX,XX @@ retry:
24
index XXXXXXX..XXXXXXX 100644
25
return 0;
25
--- a/include/qemu/coroutine.h
26
}
26
+++ b/include/qemu/coroutine.h
27
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_wrlock(CoRwlock *lock);
28
-static void parse_chap(struct iscsi_context *iscsi, const char *target,
28
*/
29
+static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts,
29
void qemu_co_rwlock_unlock(CoRwlock *lock);
30
Error **errp)
30
31
{
31
-typedef struct QemuCoSleepState QemuCoSleepState;
32
- QemuOptsList *list;
32
+typedef struct QemuCoSleep {
33
- QemuOpts *opts;
33
+ Coroutine *to_wake;
34
const char *user = NULL;
34
+} QemuCoSleep;
35
const char *password = NULL;
35
36
const char *secretid;
36
/**
37
char *secret = NULL;
37
- * Yield the coroutine for a given duration. During this yield, @sleep_state
38
38
- * is set to an opaque pointer, which may be used for
39
- list = qemu_find_opts("iscsi");
39
- * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
40
- if (!list) {
40
- * timer fires. Don't save the obtained value to other variables and don't call
41
- return;
41
- * qemu_co_sleep_wake from another aio context.
42
- }
42
+ * Yield the coroutine for a given duration. Initializes @w so that,
43
-
43
+ * during this yield, it can be passed to qemu_co_sleep_wake() to
44
- opts = qemu_opts_find(list, target);
44
+ * terminate the sleep.
45
- if (opts == NULL) {
45
*/
46
- opts = QTAILQ_FIRST(&list->head);
46
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
47
- if (!opts) {
47
- QemuCoSleepState **sleep_state);
48
- return;
48
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
49
- }
49
+ QEMUClockType type, int64_t ns);
50
- }
50
+
51
-
51
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
52
user = qemu_opt_get(opts, "user");
52
{
53
if (!user) {
53
- QemuCoSleepState *unused = NULL;
54
return;
54
- qemu_co_sleep_ns_wakeable(type, ns, &unused);
55
+ QemuCoSleep w = { 0 };
56
+ qemu_co_sleep_ns_wakeable(&w, type, ns);
57
}
58
59
/**
60
@@ -XXX,XX +XXX,XX @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
61
* qemu_co_sleep_ns() and should be checked to be non-NULL before calling
62
* qemu_co_sleep_wake().
63
*/
64
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state);
65
+void qemu_co_sleep_wake(QemuCoSleep *w);
66
67
/**
68
* Yield until a file descriptor becomes readable
69
diff --git a/block/block-copy.c b/block/block-copy.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/block/block-copy.c
72
+++ b/block/block-copy.c
73
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyCallState {
74
/* State */
75
int ret;
76
bool finished;
77
- QemuCoSleepState *sleep_state;
78
+ QemuCoSleep sleep;
79
bool cancelled;
80
81
/* OUT parameters */
82
@@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
83
if (ns > 0) {
84
block_copy_task_end(task, -EAGAIN);
85
g_free(task);
86
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns,
87
- &call_state->sleep_state);
88
+ qemu_co_sleep_ns_wakeable(&call_state->sleep,
89
+ QEMU_CLOCK_REALTIME, ns);
90
continue;
91
}
92
}
55
@@ -XXX,XX +XXX,XX @@ out:
93
@@ -XXX,XX +XXX,XX @@ out:
94
95
void block_copy_kick(BlockCopyCallState *call_state)
96
{
97
- qemu_co_sleep_wake(call_state->sleep_state);
98
+ qemu_co_sleep_wake(&call_state->sleep);
99
}
100
101
/*
102
diff --git a/block/nbd.c b/block/nbd.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/block/nbd.c
105
+++ b/block/nbd.c
106
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVNBDState {
107
CoQueue free_sema;
108
Coroutine *connection_co;
109
Coroutine *teardown_co;
110
- QemuCoSleepState *connection_co_sleep_ns_state;
111
+ QemuCoSleep reconnect_sleep;
112
bool drained;
113
bool wait_drained_end;
114
int in_flight;
115
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
116
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
117
118
s->drained = true;
119
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
120
+ qemu_co_sleep_wake(&s->reconnect_sleep);
121
122
nbd_co_establish_connection_cancel(bs, false);
123
124
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
125
126
s->state = NBD_CLIENT_QUIT;
127
if (s->connection_co) {
128
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
129
+ qemu_co_sleep_wake(&s->reconnect_sleep);
130
nbd_co_establish_connection_cancel(bs, true);
56
}
131
}
57
}
132
if (qemu_in_coroutine()) {
58
133
@@ -XXX,XX +XXX,XX @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s)
59
+static void iscsi_parse_iscsi_option(const char *target, QDict *options)
134
}
135
bdrv_inc_in_flight(s->bs);
136
} else {
137
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout,
138
- &s->connection_co_sleep_ns_state);
139
+ qemu_co_sleep_ns_wakeable(&s->reconnect_sleep,
140
+ QEMU_CLOCK_REALTIME, timeout);
141
if (s->drained) {
142
continue;
143
}
144
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
145
index XXXXXXX..XXXXXXX 100644
146
--- a/util/qemu-coroutine-sleep.c
147
+++ b/util/qemu-coroutine-sleep.c
148
@@ -XXX,XX +XXX,XX @@
149
150
static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
151
152
-struct QemuCoSleepState {
153
+void qemu_co_sleep_wake(QemuCoSleep *w)
60
+{
154
+{
61
+ QemuOptsList *list;
155
Coroutine *co;
62
+ QemuOpts *opts;
156
- QemuCoSleepState **user_state_pointer;
63
+ const char *user, *password, *password_secret;
157
-};
64
+
158
65
+ list = qemu_find_opts("iscsi");
159
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
66
+ if (!list) {
160
-{
67
+ return;
161
- if (sleep_state) {
68
+ }
162
+ co = w->to_wake;
69
+
163
+ w->to_wake = NULL;
70
+ opts = qemu_opts_find(list, target);
164
+ if (co) {
71
+ if (opts == NULL) {
165
/* Write of schedule protected by barrier write in aio_co_schedule */
72
+ opts = QTAILQ_FIRST(&list->head);
166
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
73
+ if (!opts) {
167
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled,
74
+ return;
168
qemu_co_sleep_ns__scheduled, NULL);
75
+ }
169
76
+ }
170
assert(scheduled == qemu_co_sleep_ns__scheduled);
77
+
171
- *sleep_state->user_state_pointer = NULL;
78
+ user = qemu_opt_get(opts, "user");
172
- aio_co_wake(sleep_state->co);
79
+ if (user) {
173
+ aio_co_wake(co);
80
+ qdict_set_default_str(options, "user", user);
81
+ }
82
+
83
+ password = qemu_opt_get(opts, "password");
84
+ if (password) {
85
+ qdict_set_default_str(options, "password", password);
86
+ }
87
+
88
+ password_secret = qemu_opt_get(opts, "password-secret");
89
+ if (password_secret) {
90
+ qdict_set_default_str(options, "password-secret", password_secret);
91
+ }
92
+}
93
+
94
/*
95
* We support iscsi url's on the form
96
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
97
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_filename(const char *filename, QDict *options,
98
qdict_set_default_str(options, "lun", lun_str);
99
g_free(lun_str);
100
101
+ /* User/password from -iscsi take precedence over those from the URL */
102
+ iscsi_parse_iscsi_option(iscsi_url->target, options);
103
+
104
if (iscsi_url->user[0] != '\0') {
105
qdict_set_default_str(options, "user", iscsi_url->user);
106
qdict_set_default_str(options, "password", iscsi_url->passwd);
107
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
108
.type = QEMU_OPT_STRING,
109
},
110
{
111
+ .name = "password-secret",
112
+ .type = QEMU_OPT_STRING,
113
+ },
114
+ {
115
.name = "lun",
116
.type = QEMU_OPT_NUMBER,
117
},
118
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
119
QemuOpts *opts;
120
Error *local_err = NULL;
121
const char *transport_name, *portal, *target;
122
- const char *user, *password;
123
#if LIBISCSI_API_VERSION >= (20160603)
124
enum iscsi_transport_type transport;
125
#endif
126
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
127
transport_name = qemu_opt_get(opts, "transport");
128
portal = qemu_opt_get(opts, "portal");
129
target = qemu_opt_get(opts, "target");
130
- user = qemu_opt_get(opts, "user");
131
- password = qemu_opt_get(opts, "password");
132
lun = qemu_opt_get_number(opts, "lun", 0);
133
134
if (!transport_name || !portal || !target) {
135
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
136
ret = -EINVAL;
137
goto out;
138
}
174
}
139
- if (user && !password) {
175
}
140
- error_setg(errp, "If a user name is given, a password is required");
176
141
- ret = -EINVAL;
177
static void co_sleep_cb(void *opaque)
142
- goto out;
178
{
143
- }
179
- QemuCoSleepState **sleep_state = opaque;
144
180
- qemu_co_sleep_wake(*sleep_state);
145
if (!strcmp(transport_name, "tcp")) {
181
+ QemuCoSleep *w = opaque;
146
#if LIBISCSI_API_VERSION >= (20160603)
182
+ qemu_co_sleep_wake(w);
147
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
183
}
148
goto out;
184
185
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
186
- QemuCoSleepState **sleep_state)
187
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
188
+ QEMUClockType type, int64_t ns)
189
{
190
+ Coroutine *co = qemu_coroutine_self();
191
AioContext *ctx = qemu_get_current_aio_context();
192
QEMUTimer ts;
193
- QemuCoSleepState state = {
194
- .co = qemu_coroutine_self(),
195
- .user_state_pointer = sleep_state,
196
- };
197
198
- const char *scheduled = qatomic_cmpxchg(&state.co->scheduled, NULL,
199
- qemu_co_sleep_ns__scheduled);
200
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
201
+ qemu_co_sleep_ns__scheduled);
202
if (scheduled) {
203
fprintf(stderr,
204
"%s: Co-routine was already scheduled in '%s'\n",
205
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
206
abort();
149
}
207
}
150
208
151
- if (user) {
209
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
152
- ret = iscsi_set_initiator_username_pwd(iscsi, user, password);
210
- *sleep_state = &state;
153
- if (ret != 0) {
211
+ w->to_wake = co;
154
- error_setg(errp, "Failed to set initiator username and password");
212
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
155
- ret = -EINVAL;
213
timer_mod(&ts, qemu_clock_get_ns(type) + ns);
156
- goto out;
214
qemu_coroutine_yield();
157
- }
215
timer_del(&ts);
158
- }
216
159
-
217
- /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
160
/* check if we got CHAP username/password via the options */
218
- assert(*sleep_state == NULL);
161
- parse_chap(iscsi, target, &local_err);
219
+ /* w->to_wake is cleared before resuming this coroutine. */
162
+ apply_chap(iscsi, opts, &local_err);
220
+ assert(w->to_wake == NULL);
163
if (local_err != NULL) {
221
}
164
error_propagate(errp, local_err);
165
ret = -EINVAL;
166
--
222
--
167
2.9.3
223
2.31.1
168
224
169
diff view generated by jsdifflib
1
From: Kevin Wolf <kwolf@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
This was previously only available with -iscsi. Again, after this patch,
3
Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake.
4
the -iscsi option only takes effect if an URL is given. New users are
4
This makes the logic of qemu_co_sleep_ns_wakeable easy to understand.
5
supposed to use the new driver-specific option.
6
5
7
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
6
In the future we will introduce an API that can work even if the
8
Reviewed-by: Fam Zheng <famz@redhat.com>
7
sleep and wake happen from different threads. For now, initializing
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
w->to_wake after timer_mod is fine because the timer can only fire in
10
Signed-off-by: Jeff Cody <jcody@redhat.com>
9
the same AioContext.
10
11
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
13
Message-id: 20210517100548.28806-7-pbonzini@redhat.com
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
15
---
12
block/iscsi.c | 39 +++++++++++++++------------------------
16
include/qemu/coroutine.h | 5 +++++
13
1 file changed, 15 insertions(+), 24 deletions(-)
17
util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++-------
18
2 files changed, 24 insertions(+), 7 deletions(-)
14
19
15
diff --git a/block/iscsi.c b/block/iscsi.c
20
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/block/iscsi.c
22
--- a/include/qemu/coroutine.h
18
+++ b/block/iscsi.c
23
+++ b/include/qemu/coroutine.h
19
@@ -XXX,XX +XXX,XX @@ static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts,
24
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleep {
20
g_free(secret);
25
void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
26
QEMUClockType type, int64_t ns);
27
28
+/**
29
+ * Yield the coroutine until the next call to qemu_co_sleep_wake.
30
+ */
31
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w);
32
+
33
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
34
{
35
QemuCoSleep w = { 0 };
36
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/util/qemu-coroutine-sleep.c
39
+++ b/util/qemu-coroutine-sleep.c
40
@@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque)
41
qemu_co_sleep_wake(w);
21
}
42
}
22
43
23
-static void parse_header_digest(struct iscsi_context *iscsi, const char *target,
44
-void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
24
+static void apply_header_digest(struct iscsi_context *iscsi, QemuOpts *opts,
45
- QEMUClockType type, int64_t ns)
25
Error **errp)
46
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w)
26
{
47
{
27
- QemuOptsList *list;
48
Coroutine *co = qemu_coroutine_self();
28
- QemuOpts *opts;
49
- AioContext *ctx = qemu_get_current_aio_context();
29
const char *digest = NULL;
50
- QEMUTimer ts;
30
51
31
- list = qemu_find_opts("iscsi");
52
const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
32
- if (!list) {
53
qemu_co_sleep_ns__scheduled);
33
- return;
54
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
34
- }
35
-
36
- opts = qemu_opts_find(list, target);
37
- if (opts == NULL) {
38
- opts = QTAILQ_FIRST(&list->head);
39
- if (!opts) {
40
- return;
41
- }
42
- }
43
-
44
digest = qemu_opt_get(opts, "header-digest");
45
if (!digest) {
46
- return;
47
- }
48
-
49
- if (!strcmp(digest, "CRC32C")) {
50
+ iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
51
+ } else if (!strcmp(digest, "CRC32C")) {
52
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C);
53
} else if (!strcmp(digest, "NONE")) {
54
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE);
55
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
56
{
57
QemuOptsList *list;
58
QemuOpts *opts;
59
- const char *user, *password, *password_secret, *initiator_name;
60
+ const char *user, *password, *password_secret, *initiator_name,
61
+ *header_digest;
62
63
list = qemu_find_opts("iscsi");
64
if (!list) {
65
@@ -XXX,XX +XXX,XX @@ static void iscsi_parse_iscsi_option(const char *target, QDict *options)
66
if (initiator_name) {
67
qdict_set_default_str(options, "initiator-name", initiator_name);
68
}
55
}
56
57
w->to_wake = co;
58
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
59
- timer_mod(&ts, qemu_clock_get_ns(type) + ns);
60
qemu_coroutine_yield();
61
- timer_del(&ts);
62
63
/* w->to_wake is cleared before resuming this coroutine. */
64
assert(w->to_wake == NULL);
65
}
69
+
66
+
70
+ header_digest = qemu_opt_get(opts, "header-digest");
67
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
71
+ if (header_digest) {
68
+ QEMUClockType type, int64_t ns)
72
+ qdict_set_default_str(options, "header-digest", header_digest);
69
+{
73
+ }
70
+ AioContext *ctx = qemu_get_current_aio_context();
74
}
71
+ QEMUTimer ts;
75
72
+
76
/*
73
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w);
77
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
74
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
78
.name = "initiator-name",
75
+
79
.type = QEMU_OPT_STRING,
76
+ /*
80
},
77
+ * The timer will fire in the current AiOContext, so the callback
81
+ {
78
+ * must happen after qemu_co_sleep yields and there is no race
82
+ .name = "header-digest",
79
+ * between timer_mod and qemu_co_sleep.
83
+ .type = QEMU_OPT_STRING,
80
+ */
84
+ },
81
+ qemu_co_sleep(w);
85
{ /* end of list */ }
82
+ timer_del(&ts);
86
},
83
+}
87
};
88
@@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
89
goto out;
90
}
91
92
- iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
93
-
94
/* check if we got HEADER_DIGEST via the options */
95
- parse_header_digest(iscsi, target, &local_err);
96
+ apply_header_digest(iscsi, opts, &local_err);
97
if (local_err != NULL) {
98
error_propagate(errp, local_err);
99
ret = -EINVAL;
100
--
84
--
101
2.9.3
85
2.31.1
102
86
103
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Jeff Cody <jcody@redhat.com>
2
---
3
qapi/block-core.json | 50 +++++++++++++++++++++++++-------------------------
4
1 file changed, 25 insertions(+), 25 deletions(-)
5
1
6
diff --git a/qapi/block-core.json b/qapi/block-core.json
7
index XXXXXXX..XXXXXXX 100644
8
--- a/qapi/block-core.json
9
+++ b/qapi/block-core.json
10
@@ -XXX,XX +XXX,XX @@
11
# 1.
12
# -> { "execute": "blockdev-add",
13
# "arguments": {
14
-# "options" : { "driver": "qcow2",
15
-# "file": { "driver": "file",
16
-# "filename": "test.qcow2" } } } }
17
+# "driver": "qcow2",
18
+# "node-name": "test1",
19
+# "file": {
20
+# "driver": "file",
21
+# "filename": "test.qcow2"
22
+# }
23
+# }
24
+# }
25
# <- { "return": {} }
26
#
27
# 2.
28
# -> { "execute": "blockdev-add",
29
# "arguments": {
30
-# "options": {
31
-# "driver": "qcow2",
32
-# "node-name": "node0",
33
-# "discard": "unmap",
34
-# "cache": {
35
-# "direct": true,
36
-# "writeback": true
37
+# "driver": "qcow2",
38
+# "node-name": "node0",
39
+# "discard": "unmap",
40
+# "cache": {
41
+# "direct": true
42
# },
43
# "file": {
44
-# "driver": "file",
45
-# "filename": "/tmp/test.qcow2"
46
+# "driver": "file",
47
+# "filename": "/tmp/test.qcow2"
48
# },
49
# "backing": {
50
-# "driver": "raw",
51
-# "file": {
52
-# "driver": "file",
53
-# "filename": "/dev/fdset/4"
54
+# "driver": "raw",
55
+# "file": {
56
+# "driver": "file",
57
+# "filename": "/dev/fdset/4"
58
# }
59
# }
60
-# }
61
# }
62
# }
63
#
64
@@ -XXX,XX +XXX,XX @@
65
#
66
# -> { "execute": "blockdev-add",
67
# "arguments": {
68
-# "options": {
69
-# "driver": "qcow2",
70
-# "node-name": "node0",
71
-# "file": {
72
-# "driver": "file",
73
-# "filename": "test.qcow2"
74
-# }
75
-# }
76
+# "driver": "qcow2",
77
+# "node-name": "node0",
78
+# "file": {
79
+# "driver": "file",
80
+# "filename": "test.qcow2"
81
+# }
82
# }
83
# }
84
# <- { "return": {} }
85
--
86
2.9.3
87
88
diff view generated by jsdifflib