From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC v2 qemu 01/10] block/rbd: support selected key-value-pairs via QAPI
Date: Fri, 23 May 2025 15:31:47 +0200 [thread overview]
Message-ID: <20250523133156.617227-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250523133156.617227-1-f.ebner@proxmox.com>
Currently, most Ceph configuration options are not exposed via QAPI.
While it is possible to specify a dedicated Ceph configuration file,
specialized options are often only required for a selection of images
on the RBD storage, not all of them. To avoid the need to generate a
dedicated Ceph configuration file for each image (or for each required
combination of options), support a selection of key-value pairs via
QAPI.
Initially, this is just 'rbd_cache_policy'. For example, this is
useful with small images used as a pflash for EFI variables. Setting
the 'rbd_cache_policy' to 'writeback' yields a substantial improvement
there [0].
The function qemu_rbd_extract_key_value_pairs() was copied/adapted
from the existing qemu_rbd_extract_encryption_create_options().
[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=3329#c9
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
New in v2.
block/rbd.c | 73 ++++++++++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 37 ++++++++++++++++++++++
2 files changed, 110 insertions(+)
diff --git a/block/rbd.c b/block/rbd.c
index 24e820d056..3928d8fee4 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -293,6 +293,27 @@ static int qemu_rbd_set_auth(rados_t cluster, BlockdevOptionsRbd *opts,
return 0;
}
+static int qemu_rbd_set_key_value_pairs(rados_t cluster,
+ RbdKeyValuePairs *key_value_pairs,
+ Error **errp)
+{
+ if (!key_value_pairs) {
+ return 0;
+ }
+
+ if (key_value_pairs->has_rbd_cache_policy) {
+ RbdCachePolicy value = key_value_pairs->rbd_cache_policy;
+ int r = rados_conf_set(cluster, "rbd_cache_policy",
+ RbdCachePolicy_str(value));
+ if (r < 0) {
+ error_setg_errno(errp, -r, "could not set 'rbd_cache_policy'");
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json,
Error **errp)
{
@@ -786,6 +807,44 @@ exit:
return ret;
}
+static int qemu_rbd_extract_key_value_pairs(
+ QemuOpts *opts,
+ RbdKeyValuePairs **key_value_pairs,
+ Error **errp)
+{
+ QDict *opts_qdict;
+ QDict *key_value_pairs_qdict;
+ Visitor *v;
+ int ret = 0;
+
+ opts_qdict = qemu_opts_to_qdict(opts, NULL);
+ qdict_extract_subqdict(opts_qdict, &key_value_pairs_qdict,
+ "key-value-pairs.");
+ qobject_unref(opts_qdict);
+ if (!qdict_size(key_value_pairs_qdict)) {
+ *key_value_pairs = NULL;
+ goto exit;
+ }
+
+ /* Convert options into a QAPI object */
+ v = qobject_input_visitor_new_flat_confused(key_value_pairs_qdict, errp);
+ if (!v) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ visit_type_RbdKeyValuePairs(v, NULL, key_value_pairs, errp);
+ visit_free(v);
+ if (!*key_value_pairs) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+exit:
+ qobject_unref(key_value_pairs_qdict);
+ return ret;
+}
+
static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv,
const char *filename,
QemuOpts *opts,
@@ -795,6 +854,7 @@ static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv,
BlockdevCreateOptionsRbd *rbd_opts;
BlockdevOptionsRbd *loc;
RbdEncryptionCreateOptions *encrypt = NULL;
+ RbdKeyValuePairs *key_value_pairs = NULL;
Error *local_err = NULL;
const char *keypairs, *password_secret;
QDict *options = NULL;
@@ -843,6 +903,13 @@ static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv,
loc->image = g_strdup(qdict_get_try_str(options, "image"));
keypairs = qdict_get_try_str(options, "=keyvalue-pairs");
+ /* These are the key-value pairs coming in via the QAPI. */
+ ret = qemu_rbd_extract_key_value_pairs(opts, &key_value_pairs, errp);
+ if (ret < 0) {
+ goto exit;
+ }
+ loc->key_value_pairs = key_value_pairs;
+
ret = qemu_rbd_do_create(create_options, keypairs, password_secret, errp);
if (ret < 0) {
goto exit;
@@ -932,6 +999,12 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
goto failed_shutdown;
}
+ /* For the key-value pairs coming via QAPI. */
+ r = qemu_rbd_set_key_value_pairs(*cluster, opts->key_value_pairs, errp);
+ if (r < 0) {
+ goto failed_shutdown;
+ }
+
if (mon_host) {
r = rados_conf_set(*cluster, "mon_host", mon_host);
if (r < 0) {
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 02c043f0f7..360f467f6e 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4645,6 +4645,39 @@
'data': { 'luks': 'RbdEncryptionCreateOptionsLUKS',
'luks2': 'RbdEncryptionCreateOptionsLUKS2' } }
+##
+# @RbdCachePolicy:
+#
+# An enumeration of values for the 'rbd_cache_policy' Ceph
+# configuration setting. See the Ceph documentation for details.
+#
+# @writearound: cachable writes return immediately, reads are not
+# served from the cache.
+#
+# @writeback: cachable writes return immediately, reads are served
+# from the cache.
+#
+# @writethrough: writes return only when the data is on disk for all
+# replicas, reads are served from the cache.
+#
+# Since 10.1
+##
+{ 'enum' : 'RbdCachePolicy',
+ 'data' : [ 'writearound', 'writeback', 'writethrough' ] }
+
+
+##
+# @RbdKeyValuePairs:
+#
+# Key-value pairs for Ceph configuration.
+#
+# @rbd-cache-policy: Ceph configuration option 'rbd_cache_policy'.
+#
+# Since 10.1
+##
+{ 'struct': 'RbdKeyValuePairs',
+ 'data': { '*rbd-cache-policy': 'RbdCachePolicy' } }
+
##
# @BlockdevOptionsRbd:
#
@@ -4671,6 +4704,9 @@
# authentication. This maps to Ceph configuration option "key".
# (Since 3.0)
#
+# @key-value-pairs: Key-value pairs for additional Ceph configuraton.
+# (Since 10.1)
+#
# @server: Monitor host address and port. This maps to the "mon_host"
# Ceph option.
#
@@ -4686,6 +4722,7 @@
'*user': 'str',
'*auth-client-required': ['RbdAuthMode'],
'*key-secret': 'str',
+ '*key-value-pairs' : 'RbdKeyValuePairs',
'*server': ['InetSocketAddressBase'] } }
##
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-05-23 13:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 13:31 [pve-devel] [RFC v2 qemu/storage 00/10] storage plugin method to get qemu blockdevice options for volume Fiona Ebner
2025-05-23 13:31 ` Fiona Ebner [this message]
2025-05-23 13:31 ` [pve-devel] [RFC v2 qemu 02/10] block/rbd: support keyring option via QAPI Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 03/10] plugin: add method to get qemu blockdevice options for volume Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 04/10] iscsi direct plugin: implement method to get qemu blockdevice options Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 05/10] zfs iscsi plugin: implement new " Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 06/10] zfs pool plugin: implement " Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 07/10] rbd plugin: implement new " Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 08/10] plugin: qemu block device: add hints option and EFI disk hint Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 09/10] plugin: qemu block device: add support for snapshot option Fiona Ebner
2025-05-23 13:31 ` [pve-devel] [RFC v2 storage 10/10] plugin api: bump api version and age Fiona Ebner
2025-06-02 16:12 ` [pve-devel] [RFC v2 qemu/storage 00/10] storage plugin method to get qemu blockdevice options for volume DERUMIER, Alexandre via pve-devel
[not found] ` <9d08a1aab040d04a6f3096dfd1b3dabd30fa9315.camel@groupe-cyllene.com>
2025-06-02 16:24 ` DERUMIER, Alexandre via pve-devel
2025-06-03 8:02 ` Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250523133156.617227-2-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.