+ if (rc)
+ goto free_engine_data;
+
+ /* Set the version of the library as seen when engine is compiled */
+ nvm_version.major = NVM_PRIMITIVES_API_MAJOR;
+ nvm_version.minor = NVM_PRIMITIVES_API_MINOR;
+ nvm_version.micro = NVM_PRIMITIVES_API_MICRO;
+
+ d->nvm_handle = nvm_get_handle(f->fd, &nvm_version);
+ if (d->nvm_handle == -1) {
+ td_vmsg(td, errno, "nvm_get_handle failed", "nvm_get_handle");
+ rc = errno;
+ goto close_file;
+ }
+
+ nvm_capability[0].cap_id = NVM_CAP_ATOMIC_WRITE_START_ALIGN_ID;
+ nvm_capability[1].cap_id = NVM_CAP_ATOMIC_WRITE_MULTIPLICITY_ID;
+ nvm_capability[2].cap_id = NVM_CAP_ATOMIC_WRITE_MAX_VECTOR_SIZE_ID;
+ nvm_capability[3].cap_id = NVM_CAP_SECTOR_SIZE_ID;
+ nvm_capability[4].cap_id = NVM_CAP_ATOMIC_MAX_IOV_ID;
+ rc = nvm_get_capabilities(d->nvm_handle, nvm_capability,
+ NUM_ATOMIC_CAPABILITIES, false);
+ if (rc == -1) {
+ td_vmsg(td, errno, "error in getting atomic write capabilities", "nvm_get_capabilities");
+ rc = errno;
+ goto close_file;
+ } else if (rc < NUM_ATOMIC_CAPABILITIES) {
+ td_vmsg(td, EINVAL, "couldn't get all the atomic write capabilities" , "nvm_get_capabilities");
+ rc = ECANCELED;
+ goto close_file;
+ }
+ /* Reset rc to 0 because we got all capabilities we needed */
+ rc = 0;
+ d->xfer_buf_align = nvm_capability[0].cap_value;
+ d->xfer_buflen_align = nvm_capability[1].cap_value;
+ d->xfer_buflen_max = d->xfer_buflen_align * nvm_capability[2].cap_value * nvm_capability[4].cap_value;
+ d->sector_size = nvm_capability[3].cap_value;
+