nvstore
COMMAND_SET(nvstore, "nvstore", "manage non-volatile data", command_nvstore);
STAILQ_REMOVE(&stores, st, nvstore, nvs_next);
STAILQ_ENTRY(nvstore) nvs_next;
typedef STAILQ_HEAD(store_list, nvstore) nvstore_list_t;
if (sc->nvstore.type == NVME_STOR_RAM) {
if (sc->nvstore.ctx)
free(sc->nvstore.ctx);
sc->nvstore.ctx = calloc(1, sc->nvstore.size);
req->io_req.br_resid = sc->nvstore.size;
err = blockif_delete(sc->nvstore.ctx, &req->io_req);
pci_nvme_out_of_range(struct pci_nvme_blockstore *nvstore, uint64_t slba,
if (slba >> (64 - nvstore->sectsz_bits))
offset = slba << nvstore->sectsz_bits;
bytes = nblocks << nvstore->sectsz_bits;
if ((nvstore->size <= offset) || ((nvstore->size - offset) < bytes))
struct pci_nvme_blockstore *nvstore,
if (nvstore->type == NVME_STOR_RAM) {
err = blockif_flush(nvstore->ctx, &req->io_req);
struct pci_nvme_blockstore *nvstore,
uint8_t *buf = nvstore->ctx;
struct pci_nvme_blockstore *nvstore,
err = blockif_write(nvstore->ctx, &req->io_req);
err = blockif_read(nvstore->ctx, &req->io_req);
struct pci_nvme_blockstore *nvstore,
bytes = nblocks << nvstore->sectsz_bits;
if (pci_nvme_out_of_range(nvstore, lba, nblocks)) {
offset = lba << nvstore->sectsz_bits;
if (nvstore->type == NVME_STOR_RAM) {
*status = nvme_write_read_ram(sc, nvstore, cmd->prp1,
*status = nvme_write_read_blockif(sc, nvstore, req,
if (blockif_delete(sc->nvstore.ctx, &req->io_req)) {
struct pci_nvme_blockstore *nvstore,
if (pci_nvme_out_of_range(nvstore,
int sectsz_bits = sc->nvstore.sectsz_bits;
if (!nvstore->deallocate) {
if ((nvstore->size - offset) < bytes) {
err = blockif_delete(nvstore->ctx, &req->io_req);
pending = nvme_opc_flush(sc, cmd, &sc->nvstore,
pending = nvme_opc_write_read(sc, cmd, &sc->nvstore,
pending = nvme_opc_dataset_mgmt(sc, cmd, &sc->nvstore,
sc->nvstore.eui64 = htobe64(strtoull(value, NULL, 0));
sc->nvstore.type = NVME_STOR_RAM;
sc->nvstore.size = sz * 1024 * 1024;
sc->nvstore.ctx = calloc(1, sc->nvstore.size);
sc->nvstore.sectsz = 4096;
sc->nvstore.sectsz_bits = 12;
if (sc->nvstore.ctx == NULL) {
sc->nvstore.ctx = blockif_open(nvl, bident);
if (sc->nvstore.ctx == NULL) {
sc->nvstore.type = NVME_STOR_BLOCKIF;
sc->nvstore.size = blockif_size(sc->nvstore.ctx);
sc->nvstore.sectsz = sectsz;
else if (sc->nvstore.type != NVME_STOR_RAM)
sc->nvstore.sectsz = blockif_sectsz(sc->nvstore.ctx);
for (sc->nvstore.sectsz_bits = 9;
(1U << sc->nvstore.sectsz_bits) < sc->nvstore.sectsz;
sc->nvstore.sectsz_bits++);
struct pci_nvme_blockstore nvstore;
struct pci_nvme_blockstore *nvstore;
nvstore = &sc->nvstore;
nvstore->size = new_size;
pci_nvme_init_nsdata_size(nvstore, nd);
blockif_register_resize_callback(sc->nvstore.ctx, pci_nvme_resized, sc);
pci_nvme_init_nsdata(sc, &sc->nsdata, 1, &sc->nvstore);
if (sc->nvstore.deallocate)
pci_nvme_init_nsdata_size(struct pci_nvme_blockstore *nvstore,
nd->nsze = nvstore->size / nvstore->sectsz;
struct pci_nvme_blockstore *nvstore)
pci_nvme_init_nsdata_size(nvstore, nd);
if (nvstore->type == NVME_STOR_BLOCKIF)
nvstore->deallocate = blockif_candelete(nvstore->ctx);
if (nvstore->eui64 == 0) {
uint64_t eui64 = nvstore->eui64;
nvstore->eui64 = (eui64 << 16) | (nsid & 0xffff);
be64enc(nd->eui64, nvstore->eui64);
nd->lbaf[0] = NVMEF(NVME_NS_DATA_LBAF_LBADS, nvstore->sectsz_bits);