Skip to content

Commit 3cc9a34

Browse files
hreineckeigaw
authored andcommitted
libnvme: clarify dhchap key usage
There are two dhchap keys, a 'host' and a 'ctrl' key. Additionally, the libnvme interface prefixes function calls with 'nvme_ctrl_XX' and 'nvme_host_XX', depending on whether the first argument is a controller or a host. But that means that the function 'nvme_ctrl_dhchap_key' does _not_ refer to the dhchap ctrl key, but in fact to the dhchap host key. So to avoid all confusion make the naming consistent, and use the '_host_key' suffix for all functions referring to the dhchap host key, and '_ctrl_key' to all functions referring to the dhchap ctrl key. Which, incidentally, uncovered quite a few mixups. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 292b573 commit 3cc9a34

13 files changed

Lines changed: 79 additions & 105 deletions

File tree

libnvme/libnvme/nvme.i

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ struct nvme_host {
369369
char *hostid;
370370
char *hostsymname;
371371
%extend {
372-
char *dhchap_key;
372+
char *dhchap_host_key;
373373
}
374374
};
375375

@@ -457,19 +457,18 @@ struct nvme_ctrl {
457457
char *tls_key_identity;
458458
char *tls_key;
459459

460+
char *dhchap_host_key;
461+
char *dhchap_ctrl_key;
462+
460463
/**
461464
* We are remapping the following members of the C code's
462465
* nvme_ctrl_t to different names in Python. Here's the mapping:
463466
*
464467
* C code Python (SWIG)
465468
* ===================== =====================
466469
* ctrl->s ctrl->subsystem
467-
* ctrl->dhchap_key ctrl->dhchap_host_key
468-
* ctrl->dhchap_ctrl_key ctrl->dhchap_key
469470
*/
470471
struct nvme_subsystem *subsystem; // Maps to "s" in the C code
471-
char *dhchap_host_key; // Maps to "dhchap_key" in the C code
472-
char *dhchap_key; // Maps to "dhchap_ctrl_key" in the C code
473472
}
474473
};
475474

@@ -562,7 +561,7 @@ struct nvme_ns {
562561
if (hostsymname)
563562
nvme_host_set_hostsymname(h, hostsymname);
564563
if (hostkey)
565-
nvme_host_set_dhchap_key(h, hostkey);
564+
nvme_host_set_dhchap_host_key(h, hostkey);
566565
return h;
567566
}
568567
~nvme_host() {
@@ -593,11 +592,11 @@ struct nvme_ns {
593592
}
594593

595594
%{
596-
const char *nvme_host_dhchap_key_get(struct nvme_host *h) {
597-
return nvme_host_get_dhchap_key(h);
595+
const char *nvme_host_dhchap_host_key_get(struct nvme_host *h) {
596+
return nvme_host_get_dhchap_host_key(h);
598597
}
599-
void nvme_host_dhchap_key_set(struct nvme_host *h, char *key) {
600-
nvme_host_set_dhchap_key(h, key);
598+
void nvme_host_dhchap_host_key_set(struct nvme_host *h, char *key) {
599+
nvme_host_set_dhchap_host_key(h, key);
601600
}
602601
%};
603602

@@ -880,11 +879,11 @@ struct nvme_ns {
880879
const char *nvme_ctrl_state_get(struct nvme_ctrl *c) {
881880
return nvme_ctrl_get_state(c);
882881
}
883-
const char *nvme_ctrl_dhchap_key_get(struct nvme_ctrl *c) {
884-
return nvme_ctrl_get_dhchap_key(c);
882+
const char *nvme_ctrl_dhchap_ctrl_key_get(struct nvme_ctrl *c) {
883+
return nvme_ctrl_get_dhchap_ctrl_key(c);
885884
}
886-
void nvme_ctrl_dhchap_key_set(struct nvme_ctrl *c, const char *key) {
887-
nvme_ctrl_set_dhchap_key(c, key);
885+
void nvme_ctrl_dhchap_ctrl_key_set(struct nvme_ctrl *c, const char *key) {
886+
nvme_ctrl_set_dhchap_ctrl_key(c, key);
888887
}
889888
const char *nvme_ctrl_dhchap_host_key_get(struct nvme_ctrl *c) {
890889
return nvme_ctrl_get_dhchap_host_key(c);

libnvme/src/accessors.ld

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ LIBNVME_ACCESSORS_3 {
5858
nvme_ctrl_set_traddr;
5959
nvme_ctrl_get_trsvcid;
6060
nvme_ctrl_set_trsvcid;
61-
nvme_ctrl_get_dhchap_key;
62-
nvme_ctrl_set_dhchap_key;
61+
nvme_ctrl_get_dhchap_host_key;
62+
nvme_ctrl_set_dhchap_host_key;
6363
nvme_ctrl_get_dhchap_ctrl_key;
6464
nvme_ctrl_set_dhchap_ctrl_key;
6565
nvme_ctrl_get_keyring;
@@ -108,8 +108,8 @@ LIBNVME_ACCESSORS_3 {
108108
nvme_host_set_hostnqn;
109109
nvme_host_get_hostid;
110110
nvme_host_set_hostid;
111-
nvme_host_get_dhchap_key;
112-
nvme_host_set_dhchap_key;
111+
nvme_host_get_dhchap_host_key;
112+
nvme_host_set_dhchap_host_key;
113113
nvme_host_get_hostsymname;
114114
nvme_host_set_hostsymname;
115115
nvme_host_get_pdc_enabled_valid;

libnvme/src/libnvme.ld

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ LIBNVME_3 {
1111
nvme_ctrl_first_path;
1212
nvme_ctrl_get_address;
1313
nvme_ctrl_get_config;
14-
nvme_ctrl_get_dhchap_host_key;
1514
nvme_ctrl_get_phy_slot;
1615
nvme_ctrl_get_src_addr;
1716
nvme_ctrl_get_state;
@@ -26,7 +25,6 @@ LIBNVME_3 {
2625
nvme_ctrl_next_path;
2726
nvme_ctrl_release_transport_handle;
2827
nvme_reset_ctrl;
29-
nvme_ctrl_set_dhchap_host_key;
3028
nvme_filter_ctrls;
3129
nvme_describe_key_serial;
3230
nvme_disconnect_ctrl;

libnvme/src/nvme/accessors.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,17 @@ const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p)
292292
return p->trsvcid;
293293
}
294294

295-
void nvme_ctrl_set_dhchap_key(struct nvme_ctrl *p, const char *dhchap_key)
295+
void nvme_ctrl_set_dhchap_host_key(
296+
struct nvme_ctrl *p,
297+
const char *dhchap_host_key)
296298
{
297-
free(p->dhchap_key);
298-
p->dhchap_key = dhchap_key ? strdup(dhchap_key) : NULL;
299+
free(p->dhchap_host_key);
300+
p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL;
299301
}
300302

301-
const char *nvme_ctrl_get_dhchap_key(const struct nvme_ctrl *p)
303+
const char *nvme_ctrl_get_dhchap_host_key(const struct nvme_ctrl *p)
302304
{
303-
return p->dhchap_key;
305+
return p->dhchap_host_key;
304306
}
305307

306308
void nvme_ctrl_set_dhchap_ctrl_key(
@@ -586,15 +588,17 @@ const char *nvme_host_get_hostid(const struct nvme_host *p)
586588
return p->hostid;
587589
}
588590

589-
void nvme_host_set_dhchap_key(struct nvme_host *p, const char *dhchap_key)
591+
void nvme_host_set_dhchap_host_key(
592+
struct nvme_host *p,
593+
const char *dhchap_host_key)
590594
{
591-
free(p->dhchap_key);
592-
p->dhchap_key = dhchap_key ? strdup(dhchap_key) : NULL;
595+
free(p->dhchap_host_key);
596+
p->dhchap_host_key = dhchap_host_key ? strdup(dhchap_host_key) : NULL;
593597
}
594598

595-
const char *nvme_host_get_dhchap_key(const struct nvme_host *p)
599+
const char *nvme_host_get_dhchap_host_key(const struct nvme_host *p)
596600
{
597-
return p->dhchap_key;
601+
return p->dhchap_host_key;
598602
}
599603

600604
void nvme_host_set_hostsymname(struct nvme_host *p, const char *hostsymname)

libnvme/src/nvme/accessors.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,21 @@ void nvme_ctrl_set_trsvcid(struct nvme_ctrl *p, const char *trsvcid);
407407
const char *nvme_ctrl_get_trsvcid(const struct nvme_ctrl *p);
408408

409409
/**
410-
* nvme_ctrl_set_dhchap_key() - Set dhchap_key.
410+
* nvme_ctrl_set_dhchap_host_key() - Set dhchap_host_key.
411411
* @p: The &struct nvme_ctrl instance to update.
412-
* @dhchap_key: New string; a copy is stored. Pass NULL to clear.
412+
* @dhchap_host_key: New string; a copy is stored. Pass NULL to clear.
413413
*/
414-
void nvme_ctrl_set_dhchap_key(struct nvme_ctrl *p, const char *dhchap_key);
414+
void nvme_ctrl_set_dhchap_host_key(
415+
struct nvme_ctrl *p,
416+
const char *dhchap_host_key);
415417

416418
/**
417-
* nvme_ctrl_get_dhchap_key() - Get dhchap_key.
419+
* nvme_ctrl_get_dhchap_host_key() - Get dhchap_host_key.
418420
* @p: The &struct nvme_ctrl instance to query.
419421
*
420-
* Return: The value of the dhchap_key field, or NULL if not set.
422+
* Return: The value of the dhchap_host_key field, or NULL if not set.
421423
*/
422-
const char *nvme_ctrl_get_dhchap_key(const struct nvme_ctrl *p);
424+
const char *nvme_ctrl_get_dhchap_host_key(const struct nvme_ctrl *p);
423425

424426
/**
425427
* nvme_ctrl_set_dhchap_ctrl_key() - Set dhchap_ctrl_key.
@@ -808,19 +810,21 @@ void nvme_host_set_hostid(struct nvme_host *p, const char *hostid);
808810
const char *nvme_host_get_hostid(const struct nvme_host *p);
809811

810812
/**
811-
* nvme_host_set_dhchap_key() - Set dhchap_key.
813+
* nvme_host_set_dhchap_host_key() - Set dhchap_host_key.
812814
* @p: The &struct nvme_host instance to update.
813-
* @dhchap_key: New string; a copy is stored. Pass NULL to clear.
815+
* @dhchap_host_key: New string; a copy is stored. Pass NULL to clear.
814816
*/
815-
void nvme_host_set_dhchap_key(struct nvme_host *p, const char *dhchap_key);
817+
void nvme_host_set_dhchap_host_key(
818+
struct nvme_host *p,
819+
const char *dhchap_host_key);
816820

817821
/**
818-
* nvme_host_get_dhchap_key() - Get dhchap_key.
822+
* nvme_host_get_dhchap_host_key() - Get dhchap_host_key.
819823
* @p: The &struct nvme_host instance to query.
820824
*
821-
* Return: The value of the dhchap_key field, or NULL if not set.
825+
* Return: The value of the dhchap_host_key field, or NULL if not set.
822826
*/
823-
const char *nvme_host_get_dhchap_key(const struct nvme_host *p);
827+
const char *nvme_host_get_dhchap_host_key(const struct nvme_host *p);
824828

825829
/**
826830
* nvme_host_set_hostsymname() - Set hostsymname.

libnvme/src/nvme/fabrics.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
672672
{
673673
struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c);
674674
const char *transport = nvme_ctrl_get_transport(c);
675-
const char *hostnqn, *hostid, *hostkey, *ctrlkey;
675+
const char *hostnqn, *hostid, *hostkey, *ctrlkey = NULL;
676676
bool discover = false, discovery_nqn = false;
677677
struct nvme_global_ctx *ctx = h->ctx;
678678
long keyring_id = 0;
@@ -708,11 +708,12 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
708708

709709
hostnqn = nvme_host_get_hostnqn(h);
710710
hostid = nvme_host_get_hostid(h);
711-
hostkey = nvme_host_get_dhchap_key(h);
711+
hostkey = nvme_host_get_dhchap_host_key(h);
712712
if (!hostkey)
713713
hostkey = nvme_ctrl_get_dhchap_host_key(c);
714714

715-
ctrlkey = nvme_ctrl_get_dhchap_key(c);
715+
if (hostkey)
716+
ctrlkey = nvme_ctrl_get_dhchap_ctrl_key(c);
716717

717718
if (cfg->tls && cfg->concat) {
718719
nvme_msg(h->ctx, LOG_ERR, "cannot specify --tls and --concat together\n");
@@ -1020,9 +1021,9 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
10201021
key = nvme_ctrl_get_dhchap_host_key(fc);
10211022
if (key)
10221023
nvme_ctrl_set_dhchap_host_key(c, key);
1023-
key = nvme_ctrl_get_dhchap_key(fc);
1024+
key = nvme_ctrl_get_dhchap_ctrl_key(fc);
10241025
if (key)
1025-
nvme_ctrl_set_dhchap_key(c, key);
1026+
nvme_ctrl_set_dhchap_ctrl_key(c, key);
10261027
key = nvme_ctrl_get_keyring(fc);
10271028
if (key)
10281029
nvme_ctrl_set_keyring(c, key);
@@ -1854,7 +1855,7 @@ static int setup_connection(struct nvmf_context *fctx, struct nvme_host *h,
18541855
bool discovery)
18551856
{
18561857
if (fctx->hostkey)
1857-
nvme_host_set_dhchap_key(h, fctx->hostkey);
1858+
nvme_host_set_dhchap_host_key(h, fctx->hostkey);
18581859

18591860
if (!fctx->trsvcid)
18601861
fctx->trsvcid = nvmf_get_default_trsvcid(fctx->transport,
@@ -2437,7 +2438,7 @@ int nvmf_config_modify(struct nvme_global_ctx *ctx,
24372438
}
24382439

24392440
if (fctx->hostkey)
2440-
nvme_host_set_dhchap_key(h, fctx->hostkey);
2441+
nvme_host_set_dhchap_host_key(h, fctx->hostkey);
24412442

24422443
s = nvme_lookup_subsystem(h, NULL, fctx->subsysnqn);
24432444
if (!s) {
@@ -2455,7 +2456,7 @@ int nvmf_config_modify(struct nvme_global_ctx *ctx,
24552456
}
24562457

24572458
if (fctx->ctrlkey)
2458-
nvme_ctrl_set_dhchap_key(c, fctx->ctrlkey);
2459+
nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey);
24592460

24602461
nvme_parse_tls_args(fctx->keyring, fctx->tls_key,
24612462
fctx->tls_key_identity, fctx->cfg, c);
@@ -3081,8 +3082,11 @@ int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx)
30813082
if (err)
30823083
return err;
30833084

3084-
if (fctx->ctrlkey)
3085-
nvme_ctrl_set_dhchap_key(c, fctx->ctrlkey);
3085+
if (fctx->hostkey) {
3086+
nvme_ctrl_set_dhchap_host_key(c, fctx->hostkey);
3087+
if (fctx->ctrlkey)
3088+
nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey);
3089+
}
30863090

30873091
nvme_parse_tls_args(fctx->keyring, fctx->tls_key,
30883092
fctx->tls_key_identity, fctx->cfg, c);

libnvme/src/nvme/json.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj)
112112
nvme_ctrl_set_dhchap_host_key(c, json_object_get_string(attr_obj));
113113
attr_obj = json_object_object_get(port_obj, "dhchap_ctrl_key");
114114
if (attr_obj)
115-
nvme_ctrl_set_dhchap_key(c, json_object_get_string(attr_obj));
115+
nvme_ctrl_set_dhchap_ctrl_key(c, json_object_get_string(attr_obj));
116116
attr_obj = json_object_object_get(port_obj, "keyring");
117117
if (attr_obj)
118118
nvme_ctrl_set_keyring(c, json_object_get_string(attr_obj));
@@ -175,7 +175,7 @@ static void json_parse_host(struct nvme_global_ctx *ctx, struct json_object *hos
175175
h = nvme_lookup_host(ctx, hostnqn, hostid);
176176
attr_obj = json_object_object_get(host_obj, "dhchap_key");
177177
if (attr_obj)
178-
nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));
178+
nvme_host_set_dhchap_host_key(h, json_object_get_string(attr_obj));
179179
attr_obj = json_object_object_get(host_obj, "hostsymname");
180180
if (attr_obj)
181181
nvme_host_set_hostsymname(h, json_object_get_string(attr_obj));
@@ -308,7 +308,7 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
308308
if (value)
309309
json_object_object_add(port_obj, "dhchap_key",
310310
json_object_new_string(value));
311-
value = nvme_ctrl_get_dhchap_key(c);
311+
value = nvme_ctrl_get_dhchap_ctrl_key(c);
312312
if (value)
313313
json_object_object_add(port_obj, "dhchap_ctrl_key",
314314
json_object_new_string(value));
@@ -405,7 +405,7 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd)
405405
if (hostid)
406406
json_object_object_add(host_obj, "hostid",
407407
json_object_new_string(hostid));
408-
dhchap_key = nvme_host_get_dhchap_key(h);
408+
dhchap_key = nvme_host_get_dhchap_host_key(h);
409409
if (dhchap_key)
410410
json_object_object_add(host_obj, "dhchap_key",
411411
json_object_new_string(dhchap_key));
@@ -475,7 +475,7 @@ static void json_dump_ctrl(struct json_object *ctrl_array, nvme_ctrl_t c)
475475
if (value)
476476
json_object_object_add(ctrl_obj, "dhchap_key",
477477
json_object_new_string(value));
478-
value = nvme_ctrl_get_dhchap_key(c);
478+
value = nvme_ctrl_get_dhchap_ctrl_key(c);
479479
if (value)
480480
json_object_object_add(ctrl_obj, "dhchap_ctrl_key",
481481
json_object_new_string(value));
@@ -635,7 +635,7 @@ int json_dump_tree(struct nvme_global_ctx *ctx)
635635
if (hostid)
636636
json_object_object_add(host_obj, "hostid",
637637
json_object_new_string(hostid));
638-
dhchap_key = nvme_host_get_dhchap_key(h);
638+
dhchap_key = nvme_host_get_dhchap_host_key(h);
639639
if (dhchap_key)
640640
json_object_object_add(host_obj, "dhchap_key",
641641
json_object_new_string(dhchap_key));

libnvme/src/nvme/private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct nvme_ctrl {
198198
char *subsysnqn;
199199
char *traddr;
200200
char *trsvcid;
201-
char *dhchap_key;
201+
char *dhchap_host_key;
202202
char *dhchap_ctrl_key;
203203
char *keyring;
204204
char *tls_key_identity;
@@ -240,7 +240,7 @@ struct nvme_host {
240240

241241
char *hostnqn;
242242
char *hostid;
243-
char *dhchap_key;
243+
char *dhchap_host_key;
244244
char *hostsymname;
245245
bool pdc_enabled;
246246
bool pdc_enabled_valid; /* set if pdc_enabled doesn't have an undefined

0 commit comments

Comments
 (0)