nvm_vblk - Virtual Block

nvm_vblk

struct nvm_vblk

Virtual block abstraction.

Facilitates a libc-like read/write and a system-like pread/pwrite interface to perform I/O on a virtual block spanning multiple blocks of physical NVM.

Consult the nvm_vblk_alloc, nvm_vblk_alloc_line for the different spans

See
nvm_vblk_alloc
See
nvm_vblk_alloc_line

nvm_vblk_copy

ssize_t nvm_vblk_copy(struct nvm_vblk * src, struct nvm_vblk * dst, int flags)

Copy the virtual block ‘src’ to the virtual block ‘dst’.

Return
On success, the number of bytes copied is returned. On error, -1 is returned and errno set to indicate the error.

nvm_vblk_erase

ssize_t nvm_vblk_erase(struct nvm_vblk * vblk)

Erase a virtual block.

Note
Erasing a vblk will reset internal position pointers
Return
On success, the number of bytes erased is returned. On error, -1 is returned and errno set to indicate the error.
Parameters
  • vblk: The virtual block to erase

nvm_vblk_pread

ssize_t nvm_vblk_pread(struct nvm_vblk * vblk, void * buf, size_t count, size_t offset)

Read from a virtual block at given offset.

nvm_vblk_read

ssize_t nvm_vblk_read(struct nvm_vblk * vblk, void * buf, size_t count)

Read from a virtual block.

nvm_vblk_pwrite

ssize_t nvm_vblk_pwrite(struct nvm_vblk * vblk, const void * buf, size_t count, size_t offset)

Write to a virtual block at a given offset.

Note
buf must be aligned to device geometry, see struct nvm_geo and nvm_buf_alloc count must be a multiple of min-size, see struct nvm_geo offset must be a multiple of min-size, see struct nvm_geo do not mix use of nvm_vblk_pwrite with nvm_vblk_write on the same virtual block
Return
On success, the number of bytes written is returned. On error, -1 is returned and errno set to indicate the error.
Parameters
  • vblk: The virtual block to write to
  • buf: Write content starting at buf
  • count: The number of bytes to write
  • offset: Start writing offset bytes within virtual block

nvm_vblk_write

ssize_t nvm_vblk_write(struct nvm_vblk * vblk, const void * buf, size_t count)

Write to a virtual block.

Note
buf must be aligned to device geometry, see struct nvm_geo and nvm_buf_alloc count must be a multiple of min-size, see struct nvm_geo do not mix use of nvm_vblk_pwrite with nvm_vblk_write on the same virtual block
Return
On success, the number of bytes written is returned and vblk internal position is updated. On error, -1 is returned and errno set to indicate the error.
Parameters
  • vblk: The virtual block to write to
  • buf: Write content starting at buf
  • count: The number of bytes to write

nvm_vblk_pad

ssize_t nvm_vblk_pad(struct nvm_vblk * vblk)

Pad the virtual block with synthetic data.

Note
Assumes that you have used nvm_vblk_write and now want to fill the remaining virtual block in order to meet block write-before-read constraints
Return
On success, the number of bytes padded is returned and internal position is updated. On error, -1 is returned and errno set to indicate the error.
Parameters
  • vblk: The virtual block to pad

nvm_vblk_alloc

struct nvm_vblk* nvm_vblk_alloc(struct nvm_dev * dev, struct nvm_addr addrs[], int naddrs)

Allocate a virtual block, spanning a given set of physical blocks.

Return
On success, an opaque pointer to the initialized virtual block is returned. On error, NULL and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • addrs: Set of block-addresses forming the virtual block
  • naddrs: The number of addresses in the address-set

nvm_vblk_alloc_line

struct nvm_vblk* nvm_vblk_alloc_line(struct nvm_dev * dev, int ch_bgn, int ch_end, int lun_bgn, int lun_end, int blk)

Allocate a virtual block (spanning planes, channels, and LUNs)

Return
On success, an opaque pointer to the initialized virtual block is returned. On error, NULL and errno set to indicate the error.
Parameters
  • dev: Device handle obtained with nvm_dev_open
  • ch_bgn: Beginning of the channel span, as inclusive index
  • ch_end: End of the channel span, as inclusive index
  • lun_bgn: Beginning of the LUN span, as inclusive index
  • lun_end: End of the LUN span, as inclusive index
  • blk: Block index

nvm_vblk_free

void nvm_vblk_free(struct nvm_vblk * vblk)

Destroy a virtual block.

Parameters
  • vblk: The virtual block to destroy

nvm_vblk_pr

void nvm_vblk_pr(struct nvm_vblk * vblk)

Print the virtual block in a humanly readable form.

Parameters
  • vblk: The entity to print information about

nvm_vblk_get_addrs

struct nvm_addr* nvm_vblk_get_addrs(struct nvm_vblk * vblk)

Retrieve the set of addresses defining the virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_get_dev

struct nvm_dev* nvm_vblk_get_dev(struct nvm_vblk * vblk)

Retrieve the device associated with the given virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_get_naddrs

int nvm_vblk_get_naddrs(struct nvm_vblk * vblk)

Retrieve the number of addresses in the address set of the virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_get_nbytes

size_t nvm_vblk_get_nbytes(struct nvm_vblk * vblk)

Retrieve the size, in bytes, of a given virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_get_pos_read

size_t nvm_vblk_get_pos_read(struct nvm_vblk * vblk)

Retrieve the read cursor position for the given virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_get_pos_write

size_t nvm_vblk_get_pos_write(struct nvm_vblk * vblk)

Retrieve the write cursor position for the given virtual block.

Parameters
  • vblk: The entity to retrieve information from

nvm_vblk_set_async

int nvm_vblk_set_async(struct nvm_vblk * vblk, uint32_t depth)

Set the command mode for the virtual block to async.

nvm_vblk_set_pos_read

int nvm_vblk_set_pos_read(struct nvm_vblk * vblk, size_t pos)

Set the read cursor position for the given virtual block.

Return
On success, 0 is returned. On error, -1 is returned and errno set to indicate the error
Parameters
  • vblk: The vblk to change
  • pos: The new read cursor

nvm_vblk_set_pos_write

int nvm_vblk_set_pos_write(struct nvm_vblk * vblk, size_t pos)

Set the write cursor position for the given virtual block.

Return
On success, 0 is returned. On error, -1 is returned and errno set to indicate the error
Parameters
  • vblk: The vblk to change
  • pos: The new write cursor

nvm_vblk_set_scalar

int nvm_vblk_set_scalar(struct nvm_vblk * vblk)

Set the command mode for the virtual block to scalar.