diff options
Diffstat (limited to 'src/nvme/json.c')
-rw-r--r-- | src/nvme/json.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nvme/json.c b/src/nvme/json.c index 072b622..a74b5a4 100644 --- a/src/nvme/json.c +++ b/src/nvme/json.c @@ -17,6 +17,7 @@ #include "fabrics.h" #include "log.h" #include "private.h" +#include "linux.h" #define JSON_UPDATE_INT_OPTION(c, k, a, o) \ if (!strcmp(# a, k ) && !c->a) c->a = json_object_get_int(o); @@ -64,6 +65,27 @@ static void json_update_attributes(nvme_ctrl_t c, if (!strcmp("discovery", key_str) && !nvme_ctrl_is_discovery_ctrl(c)) nvme_ctrl_set_discovery_ctrl(c, true); + /* + * The JSON configuration holds the keyring description + * which needs to be converted into the keyring serial number. + */ + if (!strcmp("keyring", key_str) && cfg->keyring == 0) { + long keyring; + + keyring = nvme_lookup_keyring(json_object_get_string(val_obj)); + if (keyring) { + cfg->keyring = keyring; + nvme_set_keyring(cfg->keyring); + } + } + if (!strcmp("tls_key", key_str) && cfg->tls_key == 0) { + long key; + + key = nvme_lookup_key("psk", + json_object_get_string(val_obj)); + if (key) + cfg->tls_key = key; + } } } @@ -299,6 +321,28 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) if (nvme_ctrl_is_discovery_ctrl(c)) json_object_object_add(port_obj, "discovery", json_object_new_boolean(true)); + /* + * Store the keyring description in the JSON config file. + */ + if (cfg->keyring) { + char *desc = nvme_describe_key_serial(cfg->keyring); + + if (desc) { + json_object_object_add(port_obj, "keyring", + json_object_new_string(desc)); + free(desc); + } + } + if (cfg->tls_key) { + char *desc = nvme_describe_key_serial(cfg->tls_key); + + if (desc) { + json_object_object_add(port_obj, "tls_key", + json_object_new_string(desc)); + free(desc); + } + } + json_object_array_add(ctrl_array, port_obj); } |