Skip to content

Commit babb066

Browse files
authored
Merge pull request #14 from xyan264/nsid-fix
Remove NSID field from switchtec device name
2 parents 515c260 + 9598163 commit babb066

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

nvme.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,24 @@ int open_global_device(char *dev)
153153
int err, fd;
154154
char device_str[64];
155155
char pdfid_str[64];
156-
uint16_t pdfid;
157-
uint32_t ns_id;
156+
long pdfid;
157+
char *end;
158158
struct pax_nvme_device *pax;
159159
struct rc_nvme_device *rc;
160-
int n;
161160

162161
devicename = basename(dev);
163162

164163
if (sscanf(dev, "%2049[^@]@%s", pdfid_str, device_str) == 2) {
165-
n = sscanf(pdfid_str, "%hxn%d", &pdfid, &ns_id);
166-
if (!n) {
167-
return -1;
164+
errno = 0;
165+
pdfid = strtol(pdfid_str, &end, 0);
166+
if(*end || errno || (pdfid < 0 || pdfid > 0xffff)) {
167+
fprintf(stderr, "Invalid device %s\n", dev);
168+
return -ENODEV;
168169
}
170+
169171
pax = malloc(sizeof(struct pax_nvme_device));
170172
pax->pdfid = pdfid;
171173
pax->device.ops = &pax_ops;
172-
if (n == 2) {
173-
pax->is_blk = 1;
174-
pax->ns_id = ns_id;
175-
}
176174

177175
pax->dev = switchtec_open(device_str);
178176
if (!pax->dev) {

plugins/microchip/switchtec-nvme-device.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,13 @@ int pax_nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd)
221221

222222
int pax_is_blk(void)
223223
{
224-
struct pax_nvme_device *pax;
225-
pax = to_pax_nvme_device(global_device);
226-
227-
return pax->is_blk;
224+
return 0;
228225
}
229226

230227
int pax_nvme_get_nsid(int fd)
231228
{
232-
struct pax_nvme_device *pax;
233-
pax = to_pax_nvme_device(global_device);
234-
235-
return pax->ns_id;
229+
errno = -ENOTBLK;
230+
return -1;
236231
}
237232

238233
struct nvme_device_ops pax_ops = {

plugins/microchip/switchtec-nvme-device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
struct pax_nvme_device {
3434
struct switchtec_dev *dev;
3535
uint16_t pdfid;
36-
int is_blk;
3736
uint32_t ns_id;
3837
uint32_t channel_status;
3938
struct nvme_device device;

plugins/microchip/switchtec-nvme.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ int get_nvme_info(int fd, struct list_item *item, const char *node)
7575
err = nvme_identify_ctrl(fd, &item->ctrl);
7676
if (err)
7777
return err;
78-
item->nsid = nvme_get_nsid(fd);
7978
if (item->nsid <= 0)
8079
return item->nsid;
8180
err = nvme_identify_ns(fd, item->nsid,
@@ -336,9 +335,10 @@ static int pax_build_nvme_pf_list(struct pax_nvme_device *pax,
336335
if (!ret) {
337336
for (k = 0; k < 1024; k++)
338337
if (ns_list[k]) {
339-
sprintf(node, "0x%04hxn%d@%s",
340-
pax->pdfid, ns_list[k], path);
338+
sprintf(node, "0x%04hx@%s",
339+
pax->pdfid, path);
341340
pax->ns_id = ns_list[k];
341+
list_items[idx].nsid = ns_list[k];
342342
ret = get_nvme_info(0,
343343
&list_items[idx++],
344344
node);

0 commit comments

Comments
 (0)