Skip to content

Commit 92479af

Browse files
hreineckeigaw
authored andcommitted
fabrics: add configuration option 'keyring'
Add a fabrics configuation option 'keyring' to set the keyring for storing and looking up keys. As the keyring serial number is ephemeral we cannot store it in the JSON configuration file, so store the keyring description instead. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 2cb1ed6 commit 92479af

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

doc/config-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
"description": "Controller DH-HMAC-CHAP key",
9595
"type": "string"
9696
},
97+
"keyring": {
98+
"description": "Keyring to store and lookup keys",
99+
"type": "string",
100+
},
97101
"nr_io_queues": {
98102
"description": "Number of I/O queues",
99103
"type": "integer"

doc/rst/fabrics.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Fabrics-specific definitions.
2727
int nr_write_queues;
2828
int nr_poll_queues;
2929
int tos;
30+
int keyring;
3031
bool duplicate_connect;
3132
bool disable_sqflow;
3233
bool hdr_digest;
@@ -69,6 +70,9 @@ Fabrics-specific definitions.
6970
``tos``
7071
Type of service
7172

73+
``keyring``
74+
Serial number of the keyring to store and lookup keys
75+
7276
``duplicate_connect``
7377
Allow multiple connections to the same target
7478

src/nvme/fabrics.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,
216216
NVMF_DEF_CTRL_LOSS_TMO);
217217
MERGE_CFG_OPTION(ctrl_cfg, cfg, fast_io_fail_tmo, 0);
218218
MERGE_CFG_OPTION(ctrl_cfg, cfg, tos, -1);
219+
MERGE_CFG_OPTION(ctrl_cfg, cfg, keyring, 0);
219220
MERGE_CFG_OPTION(ctrl_cfg, cfg, duplicate_connect, false);
220221
MERGE_CFG_OPTION(ctrl_cfg, cfg, disable_sqflow, false);
221222
MERGE_CFG_OPTION(ctrl_cfg, cfg, hdr_digest, false);
@@ -243,6 +244,7 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg)
243244
NVMF_DEF_CTRL_LOSS_TMO);
244245
UPDATE_CFG_OPTION(ctrl_cfg, cfg, fast_io_fail_tmo, 0);
245246
UPDATE_CFG_OPTION(ctrl_cfg, cfg, tos, -1);
247+
UPDATE_CFG_OPTION(ctrl_cfg, cfg, keyring, 0);
246248
UPDATE_CFG_OPTION(ctrl_cfg, cfg, duplicate_connect, false);
247249
UPDATE_CFG_OPTION(ctrl_cfg, cfg, disable_sqflow, false);
248250
UPDATE_CFG_OPTION(ctrl_cfg, cfg, hdr_digest, false);
@@ -517,6 +519,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
517519
cfg->fast_io_fail_tmo, false)) ||
518520
(strcmp(transport, "loop") &&
519521
add_int_argument(argstr, "tos", cfg->tos, true)) ||
522+
add_int_argument(argstr, "keyring", cfg->keyring, false) ||
520523
add_bool_argument(argstr, "duplicate_connect",
521524
cfg->duplicate_connect) ||
522525
add_bool_argument(argstr, "disable_sqflow",

src/nvme/fabrics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @nr_write_queues: Number of queues to use for exclusively for writing
3636
* @nr_poll_queues: Number of queues to reserve for polling completions
3737
* @tos: Type of service
38+
* @keyring: Keyring to store and lookup keys
3839
* @duplicate_connect: Allow multiple connections to the same target
3940
* @disable_sqflow: Disable controller sq flow control
4041
* @hdr_digest: Generate/verify header digest (TCP)
@@ -53,6 +54,7 @@ struct nvme_fabrics_config {
5354
int nr_write_queues;
5455
int nr_poll_queues;
5556
int tos;
57+
int keyring;
5658

5759
bool duplicate_connect;
5860
bool disable_sqflow;

src/nvme/json.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "fabrics.h"
1818
#include "log.h"
1919
#include "private.h"
20+
#include "linux.h"
2021

2122
#define JSON_UPDATE_INT_OPTION(c, k, a, o) \
2223
if (!strcmp(# a, k ) && !c->a) c->a = json_object_get_int(o);
@@ -64,6 +65,19 @@ static void json_update_attributes(nvme_ctrl_t c,
6465
if (!strcmp("discovery", key_str) &&
6566
!nvme_ctrl_is_discovery_ctrl(c))
6667
nvme_ctrl_set_discovery_ctrl(c, true);
68+
/*
69+
* The JSON configuration holds the keyring description
70+
* which needs to be converted into the keyring serial number.
71+
*/
72+
if (!strcmp("keyring", key_str) && cfg->keyring == 0) {
73+
long keyring;
74+
75+
keyring = nvme_lookup_keyring(json_object_get_string(val_obj));
76+
if (keyring) {
77+
cfg->keyring = keyring;
78+
nvme_set_keyring(cfg->keyring);
79+
}
80+
}
6781
}
6882
}
6983

@@ -299,6 +313,19 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
299313
if (nvme_ctrl_is_discovery_ctrl(c))
300314
json_object_object_add(port_obj, "discovery",
301315
json_object_new_boolean(true));
316+
/*
317+
* Store the keyring description in the JSON config file.
318+
*/
319+
if (cfg->keyring) {
320+
char *desc = nvme_describe_key_serial(cfg->keyring);
321+
322+
if (desc) {
323+
json_object_object_add(port_obj, "keyring",
324+
json_object_new_string(desc));
325+
free(desc);
326+
}
327+
}
328+
302329
json_object_array_add(ctrl_array, port_obj);
303330
}
304331

0 commit comments

Comments
 (0)