2 * Custom fio(1) engine that submits synchronous atomic writes to file.
4 * Copyright (C) 2013 Fusion-io, Inc.
5 * Author: Santhosh Kumar Koundinya (skoundinya@fusionio.com).
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; under version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version
16 * You should have received a copy of the GNU General Public License Version 2
17 * along with this program; if not see <http://www.gnu.org/licenses/>
25 #include <nvm/nvm_primitives.h>
28 nvm_handle_t nvm_handle;
29 size_t xfer_buf_align;
30 size_t xfer_buflen_align;
31 size_t xfer_buflen_max;
35 static int queue(struct thread_data *td, struct io_u *io_u)
38 struct fas_data *d = (struct fas_data *) io_u->file->engine_data;
40 if (io_u->ddir != DDIR_WRITE) {
41 td_vmsg(td, EINVAL, "only writes supported", "io_u->ddir");
46 if ((size_t) io_u->xfer_buf % d->xfer_buf_align) {
47 td_vmsg(td, EINVAL, "unaligned data buffer", "io_u->xfer_buf");
52 if (io_u->xfer_buflen % d->xfer_buflen_align) {
53 td_vmsg(td, EINVAL, "unaligned data size", "io_u->xfer_buflen");
58 if (io_u->xfer_buflen > d->xfer_buflen_max) {
59 td_vmsg(td, EINVAL, "data too big", "io_u->xfer_buflen");
64 rc = nvm_atomic_write(d->nvm_handle, (uint64_t) io_u->xfer_buf,
65 io_u->xfer_buflen, io_u->offset / d->sector_size);
67 td_verror(td, errno, "nvm_atomic_write");
79 static int open_file(struct thread_data *td, struct fio_file *f)
82 int fio_unused close_file_rc;
84 nvm_version_t nvm_version;
85 nvm_capability_t nvm_capability[4];
88 d = malloc(sizeof(*d));
90 td_verror(td, ENOMEM, "malloc");
95 f->engine_data = (uintptr_t) d;
97 rc = generic_open_file(td, f);
100 goto free_engine_data;
102 /* Set the version of the library as seen when engine is compiled */
103 nvm_version.major = NVM_PRIMITIVES_API_MAJOR;
104 nvm_version.minor = NVM_PRIMITIVES_API_MINOR;
105 nvm_version.micro = NVM_PRIMITIVES_API_MICRO;
107 d->nvm_handle = nvm_get_handle(f->fd, &nvm_version);
108 if (d->nvm_handle == -1) {
109 td_vmsg(td, errno, "nvm_get_handle failed", "nvm_get_handle");
114 nvm_capability[0].cap_id = NVM_CAP_ATOMIC_WRITE_START_ALIGN_ID;
115 nvm_capability[1].cap_id = NVM_CAP_ATOMIC_WRITE_MULTIPLICITY_ID;
116 nvm_capability[2].cap_id = NVM_CAP_ATOMIC_WRITE_MAX_VECTOR_SIZE_ID;
117 nvm_capability[3].cap_id = NVM_CAP_SECTOR_SIZE_ID;
118 rc = nvm_get_capabilities(d->nvm_handle, nvm_capability, 4, 0);
120 td_vmsg(td, errno, "error in getting atomic write capabilities", "nvm_get_capabilities");
124 td_vmsg(td, EINVAL, "couldn't get all the atomic write capabilities" , "nvm_get_capabilities");
128 /* Reset rc to 0 because we got all capabilities we needed */
130 d->xfer_buf_align = nvm_capability[0].cap_value;
131 d->xfer_buflen_align = nvm_capability[1].cap_value;
132 d->xfer_buflen_max = d->xfer_buflen_align * nvm_capability[2].cap_value;
133 d->sector_size = nvm_capability[3].cap_value;
138 close_file_rc = generic_close_file(td, f);
147 static int close_file(struct thread_data *td, struct fio_file *f)
149 struct fas_data *d = (struct fas_data *) f->engine_data;
152 if (d->nvm_handle != -1)
153 nvm_release_handle(d->nvm_handle);
158 return generic_close_file(td, f);
161 static struct ioengine_ops ioengine = {
162 .name = "fusion-aw-sync",
163 .version = FIO_IOOPS_VERSION,
165 .open_file = open_file,
166 .close_file = close_file,
167 .get_file_size = generic_get_file_size,
168 .flags = FIO_SYNCIO | FIO_RAWIO | FIO_MEMALIGN
171 static void fio_init fio_fusion_aw_init(void)
173 register_ioengine(&ioengine);
176 static void fio_exit fio_fusion_aw_exit(void)
178 unregister_ioengine(&ioengine);