Skip to content

Commit f23ae8c

Browse files
dwsuseigaw
authored andcommitted
tree: move dhchap and tls sysfs parser into separate functions
The nvme_configure_ctrl function gets a bit big, thus move the dhchap and tls part into separate function. Signed-off-by: Daniel Wagner <[email protected]>
1 parent e36b430 commit f23ae8c

1 file changed

Lines changed: 33 additions & 25 deletions

File tree

src/nvme/tree.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,34 +1931,10 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
19311931
return NULL;
19321932
}
19331933

1934-
static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
1935-
const char *name)
1934+
static void nvme_read_sysfs_dhchap(nvme_root_t r, nvme_ctrl_t c)
19361935
{
1937-
DIR *d;
19381936
char *host_key, *ctrl_key;
19391937

1940-
_cleanup_free_ char *tls_psk = NULL;
1941-
1942-
d = opendir(path);
1943-
if (!d) {
1944-
nvme_msg(r, LOG_ERR, "Failed to open ctrl dir %s, error %d\n",
1945-
path, errno);
1946-
errno = ENODEV;
1947-
return -1;
1948-
}
1949-
closedir(d);
1950-
1951-
c->fd = -1;
1952-
c->name = strdup(name);
1953-
c->sysfs_dir = (char *)path;
1954-
c->firmware = nvme_get_ctrl_attr(c, "firmware_rev");
1955-
c->model = nvme_get_ctrl_attr(c, "model");
1956-
c->state = nvme_get_ctrl_attr(c, "state");
1957-
c->numa_node = nvme_get_ctrl_attr(c, "numa_node");
1958-
c->queue_count = nvme_get_ctrl_attr(c, "queue_count");
1959-
c->serial = nvme_get_ctrl_attr(c, "serial");
1960-
c->sqsize = nvme_get_ctrl_attr(c, "sqsize");
1961-
19621938
host_key = nvme_get_ctrl_attr(c, "dhchap_secret");
19631939
if (host_key && c->s && c->s->h && c->s->h->dhchap_key &&
19641940
(!strcmp(c->s->h->dhchap_key, host_key) ||
@@ -1980,6 +1956,11 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
19801956
nvme_ctrl_set_dhchap_key(c, NULL);
19811957
c->dhchap_ctrl_key = ctrl_key;
19821958
}
1959+
}
1960+
1961+
static void nvme_read_sysfs_tls(nvme_root_t r, nvme_ctrl_t c)
1962+
{
1963+
char *tls_psk;
19831964

19841965
tls_psk = nvme_get_ctrl_attr(c, "tls_key");
19851966
if (tls_psk) {
@@ -1991,11 +1972,38 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
19911972
c->cfg.tls = true;
19921973
}
19931974
}
1975+
}
1976+
1977+
static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
1978+
const char *name)
1979+
{
1980+
DIR *d;
1981+
1982+
d = opendir(path);
1983+
if (!d) {
1984+
nvme_msg(r, LOG_ERR, "Failed to open ctrl dir %s, error %d\n",
1985+
path, errno);
1986+
errno = ENODEV;
1987+
return -1;
1988+
}
1989+
closedir(d);
19941990

1991+
c->fd = -1;
1992+
c->name = strdup(name);
1993+
c->sysfs_dir = (char *)path;
1994+
c->firmware = nvme_get_ctrl_attr(c, "firmware_rev");
1995+
c->model = nvme_get_ctrl_attr(c, "model");
1996+
c->state = nvme_get_ctrl_attr(c, "state");
1997+
c->numa_node = nvme_get_ctrl_attr(c, "numa_node");
1998+
c->queue_count = nvme_get_ctrl_attr(c, "queue_count");
1999+
c->serial = nvme_get_ctrl_attr(c, "serial");
2000+
c->sqsize = nvme_get_ctrl_attr(c, "sqsize");
19952001
c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype");
19962002
c->cntlid = nvme_get_ctrl_attr(c, "cntlid");
19972003
c->dctype = nvme_get_ctrl_attr(c, "dctype");
19982004
c->phy_slot = nvme_ctrl_lookup_phy_slot(r, c->address);
2005+
nvme_read_sysfs_dhchap(r, c);
2006+
nvme_read_sysfs_tls(r, c);
19992007

20002008
errno = 0; /* cleanup after nvme_get_ctrl_attr() */
20012009
return 0;

0 commit comments

Comments
 (0)