summaryrefslogtreecommitdiffstats
path: root/src/nvme/fabrics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvme/fabrics.c')
-rw-r--r--src/nvme/fabrics.c67
1 files changed, 56 insertions, 11 deletions
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index 4e042d8..1f50229 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -260,6 +260,7 @@ static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,
MERGE_CFG_OPTION(ctrl_cfg, cfg, hdr_digest, false);
MERGE_CFG_OPTION(ctrl_cfg, cfg, data_digest, false);
MERGE_CFG_OPTION(ctrl_cfg, cfg, tls, false);
+ MERGE_CFG_OPTION(ctrl_cfg, cfg, concat, false);
return ctrl_cfg;
}
@@ -289,6 +290,7 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg)
UPDATE_CFG_OPTION(ctrl_cfg, cfg, hdr_digest, false);
UPDATE_CFG_OPTION(ctrl_cfg, cfg, data_digest, false);
UPDATE_CFG_OPTION(ctrl_cfg, cfg, tls, false);
+ UPDATE_CFG_OPTION(ctrl_cfg, cfg, concat, false);
}
static int __add_bool_argument(char **argstr, char *tok, bool arg)
@@ -637,7 +639,9 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
(!strcmp(transport, "tcp") &&
add_bool_argument(r, argstr, data_digest, cfg->data_digest)) ||
(!strcmp(transport, "tcp") &&
- add_bool_argument(r, argstr, tls, cfg->tls))) {
+ add_bool_argument(r, argstr, tls, cfg->tls)) ||
+ (!strcmp(transport, "tcp") &&
+ add_bool_argument(r, argstr, concat, cfg->concat))) {
free(*argstr);
return -1;
}
@@ -705,6 +709,7 @@ static int __nvmf_supported_options(nvme_root_t r)
nvme_msg(r, LOG_DEBUG, "%s ", v);
parse_option(r, v, cntlid);
+ parse_option(r, v, concat);
parse_option(r, v, ctrl_loss_tmo);
parse_option(r, v, data_digest);
parse_option(r, v, dhchap_ctrl_secret);
@@ -740,7 +745,7 @@ static int __nvmf_supported_options(nvme_root_t r)
static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
{
- _cleanup_fd_ int fd;
+ _cleanup_fd_ int fd = -1;
int ret, len = strlen(argstr);
char buf[0x1000], *options, *p;
@@ -1183,12 +1188,27 @@ struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_ar
#define PATH_UUID_IBM "/proc/device-tree/ibm,partition-uuid"
+static char *uuid_ibm_filename(void)
+{
+ char *basepath = getenv("LIBNVME_SYSFS_PATH");
+ char *str;
+
+ if (!basepath)
+ return strdup(PATH_UUID_IBM);
+
+ if (!asprintf(&str, "%s" PATH_UUID_IBM, basepath))
+ return NULL;
+
+ return str;
+}
+
static int uuid_from_device_tree(char *system_uuid)
{
+ _cleanup_free_ char *filename = uuid_ibm_filename();
+ _cleanup_fd_ int f = -1;
ssize_t len;
- _cleanup_fd_ int f;
- f = open(PATH_UUID_IBM, O_RDONLY);
+ f = open(filename, O_RDONLY);
if (f < 0)
return -ENXIO;
@@ -1202,6 +1222,20 @@ static int uuid_from_device_tree(char *system_uuid)
#define PATH_DMI_ENTRIES "/sys/firmware/dmi/entries"
+static char *dmi_entries_dir(void)
+{
+ char *basepath = getenv("LIBNVME_SYSFS_PATH");
+ char *str;
+
+ if (!basepath)
+ return strdup(PATH_DMI_ENTRIES);
+
+ if (!asprintf(&str, "%s" PATH_DMI_ENTRIES, basepath))
+ return NULL;
+
+ return str;
+}
+
/*
* See System Management BIOS (SMBIOS) Reference Specification
* https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.2.0.pdf
@@ -1229,13 +1263,14 @@ static bool is_dmi_uuid_valid(const char *buf, size_t len)
static int uuid_from_dmi_entries(char *system_uuid)
{
+ _cleanup_dir_ DIR *d = NULL;
+ _cleanup_free_ char *entries_dir = dmi_entries_dir();
int f;
- _cleanup_dir_ DIR *d;
struct dirent *de;
char buf[512] = {0};
system_uuid[0] = '\0';
- d = opendir(PATH_DMI_ENTRIES);
+ d = opendir(entries_dir);
if (!d)
return -ENXIO;
while ((de = readdir(d))) {
@@ -1244,7 +1279,7 @@ static int uuid_from_dmi_entries(char *system_uuid)
if (de->d_name[0] == '.')
continue;
- sprintf(filename, "%s/%s/type", PATH_DMI_ENTRIES, de->d_name);
+ sprintf(filename, "%s/%s/type", entries_dir, de->d_name);
f = open(filename, O_RDONLY);
if (f < 0)
continue;
@@ -1256,7 +1291,7 @@ static int uuid_from_dmi_entries(char *system_uuid)
continue;
if (type != DMI_SYSTEM_INFORMATION)
continue;
- sprintf(filename, "%s/%s/raw", PATH_DMI_ENTRIES, de->d_name);
+ sprintf(filename, "%s/%s/raw", entries_dir, de->d_name);
f = open(filename, O_RDONLY);
if (f < 0)
continue;
@@ -1294,7 +1329,7 @@ static int uuid_from_dmi_entries(char *system_uuid)
*/
static int uuid_from_product_uuid(char *system_uuid)
{
- _cleanup_file_ FILE *stream;
+ _cleanup_file_ FILE *stream = NULL;
ssize_t nread;
_cleanup_free_ char *line = NULL;
size_t len = 0;
@@ -1364,7 +1399,7 @@ char *nvmf_hostnqn_generate()
static char *nvmf_read_file(const char *f, int len)
{
char buf[len];
- _cleanup_fd_ int fd;
+ _cleanup_fd_ int fd = -1;
int ret;
fd = open(f, O_RDONLY);
@@ -1381,11 +1416,21 @@ static char *nvmf_read_file(const char *f, int len)
char *nvmf_hostnqn_from_file()
{
+ char *hostnqn = getenv("LIBNVME_HOSTNQN");
+
+ if (hostnqn)
+ return strdup(hostnqn);
+
return nvmf_read_file(NVMF_HOSTNQN_FILE, NVMF_NQN_SIZE);
}
char *nvmf_hostid_from_file()
{
+ char *hostid = getenv("LIBNVME_HOSTID");
+
+ if (hostid)
+ return strdup(hostid);
+
return nvmf_read_file(NVMF_HOSTID_FILE, NVMF_HOSTID_SIZE);
}
@@ -1637,7 +1682,7 @@ static const char *dctype_str[] = {
*/
static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c)
{
- _cleanup_free_ struct nvme_id_ctrl *id;
+ _cleanup_free_ struct nvme_id_ctrl *id = NULL;
int ret;
id = __nvme_alloc(sizeof(*id));