Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discovery log page optimizations #690

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 31 additions & 44 deletions src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,52 +1060,44 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
int max_retries)
{
nvme_root_t r = c->s && c->s->h ? c->s->h->r : NULL;
struct nvmf_discovery_log *log = NULL;
int ret, retries = 0;
struct nvmf_discovery_log *log;
int retries = 0;
const char *name = nvme_ctrl_get_name(c);
uint64_t genctr, numrec;
unsigned int size;
int fd = nvme_ctrl_get_fd(c);

args->fd = fd;

do {
size = sizeof(struct nvmf_discovery_log);
log = __nvme_alloc(sizeof(*log));
if (!log) {
nvme_msg(r, LOG_ERR,
"could not allocate memory for discovery log header\n");
errno = ENOMEM;
return NULL;
}

free(log);
log = __nvme_alloc(size);
if (!log) {
nvme_msg(r, LOG_ERR,
"could not allocate memory for discovery log header\n");
errno = ENOMEM;
return NULL;
}
nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n",
calebsander marked this conversation as resolved.
Show resolved Hide resolved
name, retries, max_retries);
args->lpo = 0;
args->log = log;
args->len = sizeof(*log);
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args)) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, max_retries, errno);
goto out_free_log;
}

nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n",
name, retries, max_retries);
args->rae = true;
args->lpo = 0;
args->len = size;
args->log = log;
ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
if (ret) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, max_retries, errno);
goto out_free_log;
}
do {
size_t entries_size;

numrec = le64_to_cpu(log->numrec);
genctr = le64_to_cpu(log->genctr);

if (numrec == 0)
break;

size = sizeof(struct nvmf_discovery_log) +
sizeof(struct nvmf_disc_log_entry) * numrec;

free(log);
log = __nvme_alloc(size);
entries_size = sizeof(*log->entries) * numrec;
log = __nvme_alloc(sizeof(*log) + entries_size);
if (!log) {
nvme_msg(r, LOG_ERR,
"could not alloc memory for discovery log page\n");
Expand All @@ -1114,16 +1106,13 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
}

nvme_msg(r, LOG_DEBUG,
"%s: get %" PRIu64
" records (length %d genctr %" PRIu64 ")\n",
name, numrec, size, genctr);
"%s: get %" PRIu64 " records (genctr %" PRIu64 ")\n",
name, numrec, genctr);

args->rae = true;
args->lpo = sizeof(struct nvmf_discovery_log);
args->len = size - sizeof(struct nvmf_discovery_log);
args->lpo = sizeof(*log);
args->log = log->entries;
ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
if (ret) {
args->len = entries_size;
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args)) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, max_retries, errno);
Expand All @@ -1136,12 +1125,10 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
*/
nvme_msg(r, LOG_DEBUG, "%s: get header again\n", name);

args->rae = false;
args->lpo = 0;
args->len = sizeof(struct nvmf_discovery_log);
args->log = log;
ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
if (ret) {
args->len = sizeof(*log);
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args)) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, max_retries, errno);
Expand Down
34 changes: 1 addition & 33 deletions test/ioctl/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static void test_no_entries(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header),
.cdw10 = (sizeof(header) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header,
},
Expand Down Expand Up @@ -92,15 +91,13 @@ static void test_four_entries(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header),
.cdw10 = (sizeof(header) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entries),
.cdw10 = (sizeof(entries) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header), /* LPOL */
.out_data = log_entries,
Expand Down Expand Up @@ -144,7 +141,6 @@ static void test_five_entries(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header),
.cdw10 = (sizeof(header) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header,
},
Expand All @@ -161,7 +157,6 @@ static void test_five_entries(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = second_data_len,
.cdw10 = (second_data_len / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header) + first_data_len, /* LPOL */
.out_data = log_entries + first_entries,
Expand Down Expand Up @@ -200,22 +195,20 @@ static void test_genctr_change(nvme_ctrl_t c)
};
/*
* genctr changes after the entries are fetched the first time,
* so the log page fetch is retried
* so the log page entries are refetched
*/
struct mock_cmd mock_admin_cmds[] = {
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header1),
.cdw10 = (sizeof(header1) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header1,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entries1),
.cdw10 = (sizeof(entries1) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* NUMDL */
.cdw12 = sizeof(header1), /* LPOL */
.out_data = entries1,
Expand All @@ -227,19 +220,10 @@ static void test_genctr_change(nvme_ctrl_t c)
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header2,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header2),
.cdw10 = (sizeof(header2) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header2,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entries2),
.cdw10 = (sizeof(entries2) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header2), /* LPOL */
.out_data = log_entries2,
Expand Down Expand Up @@ -282,15 +266,13 @@ static void test_max_retries(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header1),
.cdw10 = (sizeof(header1) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header1,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entry),
.cdw10 = (sizeof(entry) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header1), /* LPOL */
.out_data = &entry,
Expand All @@ -302,19 +284,10 @@ static void test_max_retries(nvme_ctrl_t c)
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header2,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header2),
.cdw10 = (sizeof(header2) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header2,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entry),
.cdw10 = (sizeof(entry) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header2), /* LPOL */
.out_data = &entry,
Expand Down Expand Up @@ -346,7 +319,6 @@ static void test_header_error(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = header_size,
.cdw10 = (header_size / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.err = NVME_SC_INVALID_OPCODE,
},
Expand All @@ -369,15 +341,13 @@ static void test_entries_error(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header),
.cdw10 = (sizeof(header) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = entry_size,
.cdw10 = (entry_size / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header), /* LPOL */
.err = -EIO,
Expand All @@ -402,15 +372,13 @@ static void test_genctr_error(nvme_ctrl_t c)
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(header),
.cdw10 = (sizeof(header) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.out_data = &header,
},
{
.opcode = nvme_admin_get_log_page,
.data_len = sizeof(entry),
.cdw10 = (sizeof(entry) / 4 - 1) << 16 /* NUMDL */
| 1 << 15 /* RAE */
| NVME_LOG_LID_DISCOVER, /* LID */
.cdw12 = sizeof(header), /* LPOL */
.out_data = &entry,
Expand Down