From a79af5e7a5f9dc68ea72bbde9c01d5833ceee854 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Tue, 14 Dec 2021 23:31:29 -0500 Subject: [PATCH] bdev/rbd: Support config_param and config_file simultaneously for rbd_register_cluster config_param and config_file are not conflict to specify rados configurations, support specify both of them is more reasonable. Therefore, After this patch, users can choose the one from the three ways: config_param, config_file + key_file or config_param + config_file + key_file. Signed-off-by: Tan Long Change-Id: Ide17af72c4965df1e6541f4f50d4fa5309865486 Signed-off-by: Tan Long Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10679 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: GangCao Reviewed-by: Changpeng Liu Reviewed-by: Xiaodong Liu Reviewed-by: Dong Yi Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- module/bdev/rbd/bdev_rbd.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/module/bdev/rbd/bdev_rbd.c b/module/bdev/rbd/bdev_rbd.c index ac22462f6..0045f34cf 100644 --- a/module/bdev/rbd/bdev_rbd.c +++ b/module/bdev/rbd/bdev_rbd.c @@ -802,7 +802,8 @@ bdev_rbd_cluster_dump_entry(const char *cluster_name, struct spdk_json_write_ctx config_entry += 2; } spdk_json_write_object_end(w); - } else if (entry->config_file) { + } + if (entry->config_file) { spdk_json_write_named_string(w, "config_file", entry->config_file); } if (entry->key_file) { @@ -912,7 +913,8 @@ dump_single_cluster_entry(struct bdev_rbd_cluster *entry, struct spdk_json_write config_entry += 2; } spdk_json_write_object_end(w); - } else if (entry->config_file) { + } + if (entry->config_file) { spdk_json_write_named_string(w, "config_file", entry->config_file); } if (entry->key_file) { @@ -1010,14 +1012,16 @@ rbd_register_cluster(const char *name, const char *user_id, const char *const *c } } - /* The first priority is the config_param, then we use the config_file */ + /* Support specify config_param or config_file separately, or both of them. */ if (config_param) { entry->config_param = bdev_rbd_dup_config(config_param); if (entry->config_param == NULL) { SPDK_ERRLOG("Failed to save the config_param=%p on entry = %p\n", config_param, entry); goto err_handle; } - } else if (config_file) { + } + + if (config_file) { entry->config_file = strdup(config_file); if (entry->config_file == NULL) { SPDK_ERRLOG("Failed to save the config_file=%s on entry = %p\n", config_file, entry); @@ -1039,6 +1043,14 @@ rbd_register_cluster(const char *name, const char *user_id, const char *const *c goto err_handle; } + /* Try default location when entry->config_file is NULL, but ignore failure when it is NULL */ + rc = rados_conf_read_file(entry->cluster, entry->config_file); + if (entry->config_file && rc < 0) { + SPDK_ERRLOG("Failed to read conf file %s\n", entry->config_file); + rados_shutdown(entry->cluster); + goto err_handle; + } + if (config_param) { const char *const *config_entry = config_param; while (*config_entry) { @@ -1050,13 +1062,6 @@ rbd_register_cluster(const char *name, const char *user_id, const char *const *c } config_entry += 2; } - } else { - rc = rados_conf_read_file(entry->cluster, entry->config_file); - if (rc < 0) { - SPDK_ERRLOG("Failed to read conf file\n"); - rados_shutdown(entry->cluster); - goto err_handle; - } } if (key_file) {