Ejemplo n.º 1
0
static int
reservation_ns_report(struct nvme_controller *ctrlr, uint16_t ns_id)
{
	int ret, i;
	uint8_t *payload;
	struct nvme_reservation_status_data *status;
	struct nvme_reservation_controller_data *cdata;
	struct nvme_namespace *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	payload = rte_zmalloc(NULL, 0x1000, 0x1000);

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_report(ns, payload, 0x1000,
					     reservation_ns_completion, NULL);
	if (ret) {
		fprintf(stderr, "Reservation Report Failed\n");
		rte_free(payload);
		return -1;
	}

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result) {
		fprintf(stderr, "Reservation Report Failed\n");
		rte_free(payload);
		return 0;
	}

	status = (struct nvme_reservation_status_data *)payload;
	fprintf(stdout, "Reservation Generation Counter                  %u\n", status->generation);
	fprintf(stdout, "Reservation type                                %u\n", status->type);
	fprintf(stdout, "Reservation Number of Registered Controllers    %u\n", status->nr_regctl);
	fprintf(stdout, "Reservation Persist Through Power Loss State    %u\n", status->ptpl_state);
	for (i = 0; i < status->nr_regctl; i++) {
		cdata = (struct nvme_reservation_controller_data *)(payload + sizeof(struct
				nvme_reservation_status_data) * (i + 1));
		fprintf(stdout, "Controller ID                           %u\n", cdata->ctrlr_id);
		fprintf(stdout, "Controller Reservation Status           %u\n", cdata->rcsts.status);
		fprintf(stdout, "Controller Host ID                      0x%"PRIx64"\n", cdata->host_id);
		fprintf(stdout, "Controller Reservation Key              0x%"PRIx64"\n", cdata->key);
	}

	rte_free(payload);
	return 0;
}
Ejemplo n.º 2
0
static void
register_ctrlr(struct nvme_controller *ctrlr, struct pci_device *pci_dev)
{
	int nsid, num_ns;
	struct ctrlr_entry *entry = malloc(sizeof(struct ctrlr_entry));

	entry->ctrlr = ctrlr;
	entry->next = g_controllers;
	g_controllers = entry;

	num_ns = nvme_ctrlr_get_num_ns(ctrlr);
	for (nsid = 1; nsid <= num_ns; nsid++) {
		register_ns(ctrlr, pci_dev, nvme_ctrlr_get_ns(ctrlr, nsid));
	}

}
Ejemplo n.º 3
0
static int
reservation_ns_register(struct nvme_controller *ctrlr, uint16_t ns_id)
{
	int ret;
	struct nvme_reservation_register_data *rr_data;
	struct nvme_namespace *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);

	rr_data = rte_zmalloc(NULL, sizeof(struct nvme_reservation_register_data), 0);
	rr_data->crkey = CR_KEY;
	rr_data->nrkey = CR_KEY;

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_register(ns, rr_data, 1,
					       NVME_RESERVE_REGISTER_KEY,
					       NVME_RESERVE_PTPL_NO_CHANGES,
					       reservation_ns_completion, NULL);
	if (ret) {
		fprintf(stderr, "Reservation Register Failed\n");
		rte_free(rr_data);
		return -1;
	}

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result)
		fprintf(stderr, "Reservation Register Failed\n");

	rte_free(rr_data);
	return 0;
}
Ejemplo n.º 4
0
static int
reservation_ns_release(struct nvme_controller *ctrlr, uint16_t ns_id)
{
	int ret;
	struct nvme_reservation_key_data *cdata;
	struct nvme_namespace *ns;

	ns = nvme_ctrlr_get_ns(ctrlr, ns_id);
	cdata = rte_zmalloc(NULL, sizeof(struct nvme_reservation_key_data), 0);
	cdata->crkey = CR_KEY;

	outstanding_commands = 0;
	reserve_command_result = -1;

	ret = nvme_ns_cmd_reservation_release(ns, cdata,
					      0,
					      NVME_RESERVE_RELEASE,
					      NVME_RESERVE_WRITE_EXCLUSIVE,
					      reservation_ns_completion, NULL);
	if (ret) {
		fprintf(stderr, "Reservation Release Failed\n");
		rte_free(cdata);
		return -1;
	}

	outstanding_commands++;
	while (outstanding_commands) {
		nvme_ctrlr_process_io_completions(ctrlr, 100);
	}

	if (reserve_command_result)
		fprintf(stderr, "Reservation Release Failed\n");

	rte_free(cdata);
	return 0;
}