libvirt/SOURCES/libvirt-qemu-block-Extract-formatting-of-cookie-string.patch
2021-10-08 13:11:20 +00:00

109 lines
3.4 KiB
Diff

From 41504cefb5ab3f473680bd7498fc940811cefc26 Mon Sep 17 00:00:00 2001
Message-Id: <41504cefb5ab3f473680bd7498fc940811cefc26@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 24 Mar 2020 16:26:06 +0100
Subject: [PATCH] qemu: block: Extract formatting of cookie string
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Introduce qemuBlockStorageSourceGetCookieString which does the
concatenation so that we can reuse it later.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit bafd2e94fabfe12bdc64c9972f56af536e6ad0eb)
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
Conflicts:
src/qemu/qemu_block.c
src/qemu/qemu_block.h
Context, a8bcbb42172 not backported
src/qemu/qemu_domain.c
virBufferTrim change not backported, the conflict is on a
previous conflict resolution
Message-Id: <bbc4bf3b1ebdc99aec680487c22d2a68c1cdda5f.1585063415.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/qemu/qemu_block.c | 25 +++++++++++++++++++++++++
src/qemu/qemu_block.h | 3 +++
src/qemu/qemu_domain.c | 13 +------------
3 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 73a424f7a8..1f48f559e3 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3306,3 +3306,28 @@ qemuBlockReopenReadOnly(virDomainObjPtr vm,
return 0;
}
+
+
+/**
+ * qemuBlockStorageSourceGetCookieString:
+ * @src: storage source
+ *
+ * Returns a properly formatted string representing cookies of @src in format
+ * accepted by qemu.
+ */
+char *
+qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ size_t i;
+
+ for (i = 0; i < src->ncookies; i++) {
+ virStorageNetCookieDefPtr cookie = src->cookies[i];
+
+ virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
+ }
+
+ virBufferTrim(&buf, "; ", -1);
+
+ return virBufferContentAndReset(&buf);
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 506957c3d5..4e7708ce74 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -255,3 +255,6 @@ int
qemuBlockReopenReadOnly(virDomainObjPtr vm,
virStorageSourcePtr src,
qemuDomainAsyncJob asyncJob);
+
+char *
+qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3d31e176d1..4007b4dbda 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1747,18 +1747,7 @@ qemuDomainSecretStorageSourcePrepareCookies(qemuDomainObjPrivatePtr priv,
const char *aliasprotocol)
{
g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
- g_autofree char *cookies = NULL;
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- size_t i;
-
- for (i = 0; i < src->ncookies; i++) {
- virStorageNetCookieDefPtr cookie = src->cookies[i];
-
- virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
- }
-
- virBufferTrim(&buf, "; ", -1);
- cookies = virBufferContentAndReset(&buf);
+ g_autofree char *cookies = qemuBlockStorageSourceGetCookieString(src);
return qemuDomainSecretAESSetup(priv, secretalias, NULL,
(uint8_t *) cookies, strlen(cookies));
--
2.26.0