Skip to content

Commit

Permalink
add namespace info to proto response
Browse files Browse the repository at this point in the history
Required-githooks: true

Signed-off-by: Tom Nabarro <[email protected]>
  • Loading branch information
tanabarr committed Nov 21, 2023
1 parent 23311fe commit 4ee62f9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/bio/bio_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ bio_decode_bdev_params(struct bio_dev_info *b_info, const void *json, int json_s
if (ctx == NULL)
return -DER_NOMEM;

/* Calculate number of values in tree. */
/* Calculate number of values in tree before mem alloc. */
rc = spdk_json_parse(json_data, strnlen(json_data, json_size), NULL, 0, &end,
SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS);
if (rc < 0) {
Expand All @@ -1016,7 +1016,7 @@ bio_decode_bdev_params(struct bio_dev_info *b_info, const void *json, int json_s
if (ctx->values == NULL)
D_GOTO(free_ctx, rc = -DER_NOMEM);

/* Populate JSON tree keys and values. */
/* Populate tree of keys and values from JSON. */
rc = spdk_json_parse(json_data, strnlen(json_data, json_size), ctx->values, ctx->values_cnt,
&end, SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS);
if (rc < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/control/server/instance_storage_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func scanEngineBdevsOverDrpc(ctx context.Context, ei *EngineInstance, pbReq *ctl

for _, sd := range scanSmdResp.Devices {
if sd.Ctrlr == nil {
return nil, errors.Errorf("smd %q has no ctrlr ref", sd.Uuid)
return nil, errors.Errorf("smd %+v has no ctrlr ref", sd)
}

addr := sd.Ctrlr.PciAddr
Expand Down
26 changes: 9 additions & 17 deletions src/mgmt/srv_drpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,14 @@ ds_mgmt_smd_free_dev(Ctl__SmdDevice *dev)
D_FREE(dev->ctrlr->pci_addr);
if (dev->ctrlr->fw_rev != NULL)
D_FREE(dev->ctrlr->fw_rev);
if (dev->ctrlr->vendor_id != NULL)
D_FREE(dev->ctrlr->vendor_id);
if (dev->ctrlr->pci_dev_type != NULL)
D_FREE(dev->ctrlr->pci_dev_type);
if (dev->ctrlr->namespaces != NULL) {
if (dev->ctrlr->namespaces[0] != NULL)
D_FREE(dev->ctrlr->namespaces[0]);
}
}
}

Expand Down Expand Up @@ -2035,23 +2043,7 @@ ds_mgmt_drpc_smd_list_devs(Drpc__Call *drpc_req, Drpc__Response *drpc_resp)

for (i = 0; i < resp->n_devices; i++) {
if (resp->devices[i] != NULL) {
if (resp->devices[i]->uuid != NULL)
D_FREE(resp->devices[i]->uuid);
if (resp->devices[i]->tgt_ids != NULL)
D_FREE(resp->devices[i]->tgt_ids);
if (resp->devices[i]->ctrlr != NULL) {
if (resp->devices[i]->ctrlr->pci_addr != NULL)
D_FREE(resp->devices[i]->ctrlr->pci_addr);
// if (resp->devices[i]->ctrlr->model
//!=
// NULL)
// D_FREE(resp->devices[i]->ctrlr->model);
// if (resp->devices[i]->ctrlr->serial != NULL)
// D_FREE(resp->devices[i]->ctrlr->serial);
// if (resp->devices[i]->ctrlr->fw_rev
//!= NULL)
// D_FREE(resp->devices[i]->ctrlr->fw_rev);
}
ds_mgmt_smd_free_dev(resp->devices[i]);
D_FREE(resp->devices[i]);
}
}
Expand Down
89 changes: 54 additions & 35 deletions src/mgmt/srv_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,8 @@ ds_mgmt_smd_list_devs(Ctl__SmdDevResp *resp)
{
struct bio_dev_info *dev_info = NULL, *tmp;
struct bio_list_devs_info list_devs_info = { 0 };
struct bio_led_manage_info led_info = { 0 };
Ctl__LedState led_state;
Ctl__NvmeController *ctrlr = NULL;
struct bio_led_manage_info led_info = {0};
Ctl__LedState led_state;
int rc = 0;
int i = 0, j;

Expand Down Expand Up @@ -384,7 +383,6 @@ ds_mgmt_smd_list_devs(Ctl__SmdDevResp *resp)

if (dev_info->bdi_ctrlr == NULL) {
D_ERROR("ctrlr not initialized in bio_dev_info");
resp->devices[i]->ctrlr = NULL;
rc = -DER_INVAL;
break;
}
Expand All @@ -394,50 +392,85 @@ ds_mgmt_smd_list_devs(Ctl__SmdDevResp *resp)
rc = -DER_NOMEM;
break;
}
ctrlr = resp->devices[i]->ctrlr;
ctl__nvme_controller__init(ctrlr);
ctl__nvme_controller__init(resp->devices[i]->ctrlr);

rc = copy_str2ctrlr(&ctrlr->pci_addr, dev_info->bdi_traddr);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->pci_addr, dev_info->bdi_traddr);
if (rc != 0) {
break;
}
rc = copy_str2ctrlr(&ctrlr->model, dev_info->bdi_ctrlr->model);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->model, dev_info->bdi_ctrlr->model);
if (rc != 0) {
break;
}
rc = copy_str2ctrlr(&ctrlr->serial, dev_info->bdi_ctrlr->serial);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->serial, dev_info->bdi_ctrlr->serial);
if (rc != 0) {
break;
}
rc = copy_str2ctrlr(&ctrlr->fw_rev, dev_info->bdi_ctrlr->fw_rev);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->fw_rev, dev_info->bdi_ctrlr->fw_rev);
if (rc != 0) {
break;
}
rc = copy_str2ctrlr(&ctrlr->vendor_id, dev_info->bdi_ctrlr->vendor_id);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->vendor_id,
dev_info->bdi_ctrlr->vendor_id);
if (rc != 0) {
break;
}
rc = copy_str2ctrlr(&ctrlr->pci_dev_type, dev_info->bdi_ctrlr->pci_type);
rc = copy_str2ctrlr(&resp->devices[i]->ctrlr->pci_dev_type,
dev_info->bdi_ctrlr->pci_type);
if (rc != 0) {
break;
}
ctrlr->socket_id = dev_info->bdi_ctrlr->socket_id;
resp->devices[i]->ctrlr->socket_id = dev_info->bdi_ctrlr->socket_id;

D_DEBUG(DB_MGMT, "ctrlr details: '%s' '%s' '%s' '%s' '%s' '%s' '%d'\n",
ctrlr->pci_addr, ctrlr->model, ctrlr->serial, ctrlr->fw_rev,
ctrlr->vendor_id, ctrlr->pci_dev_type, ctrlr->socket_id);
resp->devices[i]->ctrlr->pci_addr, resp->devices[i]->ctrlr->model,
resp->devices[i]->ctrlr->serial, resp->devices[i]->ctrlr->fw_rev,
resp->devices[i]->ctrlr->vendor_id, resp->devices[i]->ctrlr->pci_dev_type,
resp->devices[i]->ctrlr->socket_id);

/* Populate NVMe namespace id and capacity */

if (dev_info->bdi_ctrlr->nss == NULL) {
D_ERROR("nss not initialized in bio_dev_info");
rc = -DER_INVAL;
break;
}
D_ASSERT(dev_info->bdi_ctrlr->nss->next == NULL);

/* When describing a SMD, only one NVMe namespace is relevant */
D_ALLOC_ARRAY(resp->devices[i]->ctrlr->namespaces, 1);
if (resp->devices[i]->ctrlr->namespaces == NULL) {
rc = -DER_NOMEM;
break;
}
D_ALLOC_PTR(resp->devices[i]->ctrlr->namespaces[0]);
if (resp->devices[i]->ctrlr->namespaces[0] == NULL) {
rc = -DER_NOMEM;
break;
}
resp->devices[i]->ctrlr->n_namespaces = 1;
ctl__nvme_controller__namespace__init(resp->devices[i]->ctrlr->namespaces[0]);

resp->devices[i]->ctrlr->namespaces[0]->id = dev_info->bdi_ctrlr->nss->id;
resp->devices[i]->ctrlr->namespaces[0]->size = dev_info->bdi_ctrlr->nss->size;

D_DEBUG(DB_MGMT, "ns id/size: '%d' '%ld'\n",
resp->devices[i]->ctrlr->namespaces[0]->id,
resp->devices[i]->ctrlr->namespaces[0]->size);

/* Populate NVMe device state */

if ((dev_info->bdi_flags & NVME_DEV_FL_PLUGGED) == 0) {
ctrlr->dev_state = CTL__NVME_DEV_STATE__UNPLUGGED;
resp->devices[i]->ctrlr->dev_state = CTL__NVME_DEV_STATE__UNPLUGGED;
goto next_dev;
}

if ((dev_info->bdi_flags & NVME_DEV_FL_FAULTY) != 0)
ctrlr->dev_state = CTL__NVME_DEV_STATE__EVICTED;
resp->devices[i]->ctrlr->dev_state = CTL__NVME_DEV_STATE__EVICTED;
else if ((dev_info->bdi_flags & NVME_DEV_FL_INUSE) == 0)
ctrlr->dev_state = CTL__NVME_DEV_STATE__NEW;
resp->devices[i]->ctrlr->dev_state = CTL__NVME_DEV_STATE__NEW;
else
ctrlr->dev_state = CTL__NVME_DEV_STATE__NORMAL;
resp->devices[i]->ctrlr->dev_state = CTL__NVME_DEV_STATE__NORMAL;

if (strncmp(dev_info->bdi_ctrlr->pci_type, NVME_PCI_DEV_TYPE_VMD,
strlen(NVME_PCI_DEV_TYPE_VMD)) != 0)
Expand All @@ -461,7 +494,7 @@ ds_mgmt_smd_list_devs(Ctl__SmdDevResp *resp)
break;
}
}
ctrlr->led_state = led_state;
resp->devices[i]->ctrlr->led_state = led_state;

next_dev:
d_list_del(&dev_info->bdi_link);
Expand All @@ -480,21 +513,7 @@ ds_mgmt_smd_list_devs(Ctl__SmdDevResp *resp)
}
for (; i >= 0; i--) {
if (resp->devices[i] != NULL) {
if (resp->devices[i]->uuid != NULL)
D_FREE(resp->devices[i]->uuid);
if (resp->devices[i]->tgt_ids != NULL)
D_FREE(resp->devices[i]->tgt_ids);
ctrlr = resp->devices[i]->ctrlr;
if (ctrlr != NULL) {
if (ctrlr->pci_addr != NULL)
D_FREE(ctrlr->pci_addr);
if (ctrlr->model != NULL)
D_FREE(ctrlr->model);
if (ctrlr->serial != NULL)
D_FREE(ctrlr->serial);
if (ctrlr->fw_rev != NULL)
D_FREE(ctrlr->fw_rev);
}
ds_mgmt_smd_free_dev(resp->devices[i]);
D_FREE(resp->devices[i]);
}
}
Expand Down

0 comments on commit 4ee62f9

Please sign in to comment.