examples/nvme/reserve: simplify buffer allocation
Now that the NVMe library handles physically contiguous buffer allocation for reservation functions, the example can just use normal local variables. Change-Id: Ieaafc3affbc2e05541041579d330e26151375366 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
03cbd9aa72
commit
c747375988
@ -36,7 +36,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <rte_config.h>
|
#include <rte_config.h>
|
||||||
#include <rte_malloc.h>
|
|
||||||
#include <rte_mempool.h>
|
#include <rte_mempool.h>
|
||||||
#include <rte_lcore.h>
|
#include <rte_lcore.h>
|
||||||
|
|
||||||
@ -107,24 +106,17 @@ static int
|
|||||||
get_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
get_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint64_t *host_id;
|
uint64_t host_id;
|
||||||
struct spdk_nvme_cmd cmd = {};
|
struct spdk_nvme_cmd cmd = {};
|
||||||
|
|
||||||
cmd.opc = SPDK_NVME_OPC_GET_FEATURES;
|
cmd.opc = SPDK_NVME_OPC_GET_FEATURES;
|
||||||
cmd.cdw10 = SPDK_NVME_FEAT_HOST_IDENTIFIER;
|
cmd.cdw10 = SPDK_NVME_FEAT_HOST_IDENTIFIER;
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
|
ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, &host_id, sizeof(host_id),
|
||||||
host_id = rte_malloc(NULL, 8, 0);
|
|
||||||
if (host_id == NULL) {
|
|
||||||
fprintf(stderr, "host_id allocation failed\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
|
|
||||||
get_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
|
get_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stdout, "Get Feature: Failed\n");
|
fprintf(stdout, "Get Feature: Failed\n");
|
||||||
rte_free(host_id);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,10 +127,9 @@ get_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (features[SPDK_NVME_FEAT_HOST_IDENTIFIER].valid) {
|
if (features[SPDK_NVME_FEAT_HOST_IDENTIFIER].valid) {
|
||||||
fprintf(stdout, "Get Feature: Host Identifier 0x%"PRIx64"\n", *host_id);
|
fprintf(stdout, "Get Feature: Host Identifier 0x%" PRIx64 "\n", host_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
rte_free(host_id);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,28 +137,22 @@ static int
|
|||||||
set_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
set_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint64_t *host_id;
|
uint64_t host_id;
|
||||||
struct spdk_nvme_cmd cmd = {};
|
struct spdk_nvme_cmd cmd = {};
|
||||||
|
|
||||||
cmd.opc = SPDK_NVME_OPC_SET_FEATURES;
|
cmd.opc = SPDK_NVME_OPC_SET_FEATURES;
|
||||||
cmd.cdw10 = SPDK_NVME_FEAT_HOST_IDENTIFIER;
|
cmd.cdw10 = SPDK_NVME_FEAT_HOST_IDENTIFIER;
|
||||||
|
|
||||||
host_id = rte_malloc(NULL, 8, 0);
|
host_id = HOST_ID;
|
||||||
if (host_id == NULL) {
|
|
||||||
fprintf(stderr, "host_id allocation failed\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*host_id = HOST_ID;
|
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
set_feature_result = -1;
|
set_feature_result = -1;
|
||||||
|
|
||||||
fprintf(stdout, "Set Feature: Host Identifier 0x%"PRIx64"\n", *host_id);
|
fprintf(stdout, "Set Feature: Host Identifier 0x%" PRIx64 "\n", host_id);
|
||||||
ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8,
|
ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, &host_id, sizeof(host_id),
|
||||||
set_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
|
set_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stdout, "Set Feature: Failed\n");
|
fprintf(stdout, "Set Feature: Failed\n");
|
||||||
rte_free(host_id);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +165,6 @@ set_host_identifier(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
if (set_feature_result)
|
if (set_feature_result)
|
||||||
fprintf(stdout, "Set Feature: Host Identifier Failed\n");
|
fprintf(stdout, "Set Feature: Host Identifier Failed\n");
|
||||||
|
|
||||||
rte_free(host_id);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,25 +185,23 @@ reservation_ns_register(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *q
|
|||||||
uint16_t ns_id)
|
uint16_t ns_id)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct spdk_nvme_reservation_register_data *rr_data;
|
struct spdk_nvme_reservation_register_data rr_data;
|
||||||
struct spdk_nvme_ns *ns;
|
struct spdk_nvme_ns *ns;
|
||||||
|
|
||||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
||||||
|
|
||||||
rr_data = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_register_data), 0);
|
rr_data.crkey = CR_KEY;
|
||||||
rr_data->crkey = CR_KEY;
|
rr_data.nrkey = CR_KEY;
|
||||||
rr_data->nrkey = CR_KEY;
|
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
reserve_command_result = -1;
|
reserve_command_result = -1;
|
||||||
|
|
||||||
ret = spdk_nvme_ns_cmd_reservation_register(ns, qpair, rr_data, 1,
|
ret = spdk_nvme_ns_cmd_reservation_register(ns, qpair, &rr_data, true,
|
||||||
SPDK_NVME_RESERVE_REGISTER_KEY,
|
SPDK_NVME_RESERVE_REGISTER_KEY,
|
||||||
SPDK_NVME_RESERVE_PTPL_NO_CHANGES,
|
SPDK_NVME_RESERVE_PTPL_NO_CHANGES,
|
||||||
reservation_ns_completion, NULL);
|
reservation_ns_completion, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "Reservation Register Failed\n");
|
fprintf(stderr, "Reservation Register Failed\n");
|
||||||
rte_free(rr_data);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +213,6 @@ reservation_ns_register(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *q
|
|||||||
if (reserve_command_result)
|
if (reserve_command_result)
|
||||||
fprintf(stderr, "Reservation Register Failed\n");
|
fprintf(stderr, "Reservation Register Failed\n");
|
||||||
|
|
||||||
rte_free(rr_data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,13 +220,12 @@ static int
|
|||||||
reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
||||||
{
|
{
|
||||||
int ret, i;
|
int ret, i;
|
||||||
uint8_t *payload;
|
uint8_t payload[0x1000];
|
||||||
struct spdk_nvme_reservation_status_data *status;
|
struct spdk_nvme_reservation_status_data *status;
|
||||||
struct spdk_nvme_reservation_ctrlr_data *cdata;
|
struct spdk_nvme_reservation_ctrlr_data *cdata;
|
||||||
struct spdk_nvme_ns *ns;
|
struct spdk_nvme_ns *ns;
|
||||||
|
|
||||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
||||||
payload = rte_zmalloc(NULL, 0x1000, 0x1000);
|
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
reserve_command_result = -1;
|
reserve_command_result = -1;
|
||||||
@ -254,7 +234,6 @@ reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpa
|
|||||||
reservation_ns_completion, NULL);
|
reservation_ns_completion, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "Reservation Report Failed\n");
|
fprintf(stderr, "Reservation Report Failed\n");
|
||||||
rte_free(payload);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +244,6 @@ reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpa
|
|||||||
|
|
||||||
if (reserve_command_result) {
|
if (reserve_command_result) {
|
||||||
fprintf(stderr, "Reservation Report Failed\n");
|
fprintf(stderr, "Reservation Report Failed\n");
|
||||||
rte_free(payload);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +261,6 @@ reservation_ns_report(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpa
|
|||||||
fprintf(stdout, "Controller Reservation Key 0x%"PRIx64"\n", cdata->key);
|
fprintf(stdout, "Controller Reservation Key 0x%"PRIx64"\n", cdata->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
rte_free(payload);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,24 +268,23 @@ static int
|
|||||||
reservation_ns_acquire(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
reservation_ns_acquire(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct spdk_nvme_reservation_acquire_data *cdata;
|
struct spdk_nvme_reservation_acquire_data cdata;
|
||||||
struct spdk_nvme_ns *ns;
|
struct spdk_nvme_ns *ns;
|
||||||
|
|
||||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
||||||
cdata = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_acquire_data), 0);
|
cdata.crkey = CR_KEY;
|
||||||
cdata->crkey = CR_KEY;
|
cdata.prkey = 0;
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
reserve_command_result = -1;
|
reserve_command_result = -1;
|
||||||
|
|
||||||
ret = spdk_nvme_ns_cmd_reservation_acquire(ns, qpair, cdata,
|
ret = spdk_nvme_ns_cmd_reservation_acquire(ns, qpair, &cdata,
|
||||||
0,
|
false,
|
||||||
SPDK_NVME_RESERVE_ACQUIRE,
|
SPDK_NVME_RESERVE_ACQUIRE,
|
||||||
SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
|
SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
|
||||||
reservation_ns_completion, NULL);
|
reservation_ns_completion, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "Reservation Acquire Failed\n");
|
fprintf(stderr, "Reservation Acquire Failed\n");
|
||||||
rte_free(cdata);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +296,6 @@ reservation_ns_acquire(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qp
|
|||||||
if (reserve_command_result)
|
if (reserve_command_result)
|
||||||
fprintf(stderr, "Reservation Acquire Failed\n");
|
fprintf(stderr, "Reservation Acquire Failed\n");
|
||||||
|
|
||||||
rte_free(cdata);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,24 +303,22 @@ static int
|
|||||||
reservation_ns_release(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
reservation_ns_release(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, uint16_t ns_id)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct spdk_nvme_reservation_key_data *cdata;
|
struct spdk_nvme_reservation_key_data cdata;
|
||||||
struct spdk_nvme_ns *ns;
|
struct spdk_nvme_ns *ns;
|
||||||
|
|
||||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, ns_id);
|
||||||
cdata = rte_zmalloc(NULL, sizeof(struct spdk_nvme_reservation_key_data), 0);
|
cdata.crkey = CR_KEY;
|
||||||
cdata->crkey = CR_KEY;
|
|
||||||
|
|
||||||
outstanding_commands = 0;
|
outstanding_commands = 0;
|
||||||
reserve_command_result = -1;
|
reserve_command_result = -1;
|
||||||
|
|
||||||
ret = spdk_nvme_ns_cmd_reservation_release(ns, qpair, cdata,
|
ret = spdk_nvme_ns_cmd_reservation_release(ns, qpair, &cdata,
|
||||||
0,
|
false,
|
||||||
SPDK_NVME_RESERVE_RELEASE,
|
SPDK_NVME_RESERVE_RELEASE,
|
||||||
SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
|
SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
|
||||||
reservation_ns_completion, NULL);
|
reservation_ns_completion, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "Reservation Release Failed\n");
|
fprintf(stderr, "Reservation Release Failed\n");
|
||||||
rte_free(cdata);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +330,6 @@ reservation_ns_release(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qp
|
|||||||
if (reserve_command_result)
|
if (reserve_command_result)
|
||||||
fprintf(stderr, "Reservation Release Failed\n");
|
fprintf(stderr, "Reservation Release Failed\n");
|
||||||
|
|
||||||
rte_free(cdata);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user