summaryrefslogtreecommitdiffstats
path: root/nvme-topology.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-08-12 12:01:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-08-12 12:01:05 +0000
commitec3ece1465351c6208395b7f506728e9b918b05a (patch)
tree70c498b99e795bb0abafc7eb4207c515188025ff /nvme-topology.c
parentAdding upstream version 1.14. (diff)
downloadnvme-cli-ec3ece1465351c6208395b7f506728e9b918b05a.tar.xz
nvme-cli-ec3ece1465351c6208395b7f506728e9b918b05a.zip
Adding upstream version 1.15.upstream/1.15
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'nvme-topology.c')
-rw-r--r--nvme-topology.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/nvme-topology.c b/nvme-topology.c
index 31cf7f9..0a22f6b 100644
--- a/nvme-topology.c
+++ b/nvme-topology.c
@@ -155,23 +155,23 @@ static int scan_namespace(struct nvme_namespace *n)
return ret;
fd = open(path, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ ret = fd;
goto free;
-
+ }
if (!n->nsid) {
- n->nsid = nvme_get_nsid(fd);
- if (n->nsid < 0)
+ ret = nvme_get_nsid(fd);
+ if (ret < 0)
goto close_fd;
+ n->nsid = ret;
}
ret = nvme_identify_ns(fd, n->nsid, 0, &n->ns);
- if (ret < 0)
- goto close_fd;
close_fd:
close(fd);
free:
free(path);
- return 0;
+ return ret;
}
static char *get_nvme_ctrl_path_ana_state(char *path, int nsid)
@@ -319,10 +319,8 @@ static int scan_ctrl(struct nvme_ctrl *c, char *p, __u32 ns_instance)
return ret;
fd = open(path, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Failed to open %s\n", path);
+ if (fd < 0)
goto free;
- }
ret = nvme_identify_ctrl(fd, &c->id);
if (ret < 0)
@@ -384,8 +382,12 @@ static int scan_subsystem(struct nvme_subsystem *s, __u32 ns_instance, int nsid)
for (i = 0; i < s->nr_namespaces; i++) {
n = &s->namespaces[i];
n->name = strdup(ns[i]->d_name);
- n->ctrl = &s->ctrls[0];
- scan_namespace(n);
+ for (j = 0; j < s->nr_ctrls; j++) {
+ n->ctrl = &s->ctrls[j];
+ if (!strcmp(n->ctrl->state, "live") &&
+ !scan_namespace(n))
+ break;
+ }
}
} else {
i = s->nr_namespaces;
@@ -666,6 +668,30 @@ char *nvme_char_from_block(char *dev)
return path;
}
+int nvme_logical_block_size_from_ns_char(const char *dev)
+{
+ int ret;
+ int id, nsid;
+ char *path = NULL;
+ char *s;
+
+ ret = sscanf(dev, "ng%dn%d", &id, &nsid);
+ if (ret != 2)
+ return -EINVAL;
+
+ if (asprintf(&path, "/sys/block/nvme%dn%d/queue", id, nsid) < 0)
+ path = NULL;
+
+ if (!path)
+ return -EINVAL;
+
+ s = nvme_get_ctrl_attr(path, "logical_block_size");
+ if (!s)
+ return -EINVAL;
+
+ return atoi(s);
+}
+
void *mmap_registers(const char *dev)
{
int fd;