2 * Custom fio(1) engine that submits synchronous atomic writes to file.
4 * Copyright (C) 2012 Fusion-io, Inc.
5 * Author: Santhosh Kumar Koundinya.
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/vectored_write.h>
27 /* Fix sector size to 512 bytes independent of actual sector size, just like
28 * the linux kernel. */
29 #define SECTOR_SHIFT 9
30 #define SECTOR_SIZE (1U<<SECTOR_SHIFT)
32 struct acs_engine_data {
33 struct vsl_iovec iov[IO_VECTOR_LIMIT];
36 static int queue(struct thread_data *td, struct io_u *io_u)
43 struct acs_engine_data *d =
44 (struct acs_engine_data *) io_u->file->engine_data;
46 if (io_u->ddir != DDIR_WRITE) {
47 td_vmsg(td, -EIO, "only writes supported", "io_u->ddir");
51 if (io_u->xfer_buflen > IO_SIZE_MAX) {
52 td_vmsg(td, -EIO, "data too big", "io_u->xfer_buflen");
56 if (io_u->xfer_buflen & (SECTOR_SIZE - 1)) {
57 td_vmsg(td, -EIO, "unaligned data size", "io_u->xfer_buflen");
62 /* Chop up the write into minimal number of iovec's necessary */
64 offset = io_u->offset;
65 xfer_buf = io_u->xfer_buf;
66 xfer_buflen = io_u->xfer_buflen;
68 struct vsl_iovec *iov = &d->iov[iov_index++];
70 iov->iov_len = xfer_buflen > IO_VECTOR_MAX_SIZE ?
71 IO_VECTOR_MAX_SIZE : xfer_buflen;
72 iov->iov_base = (uint64_t) xfer_buf;
73 iov->sector = offset >> SECTOR_SHIFT;
74 iov->iov_flag = VSL_IOV_WRITE;
76 offset += iov->iov_len;
77 xfer_buf += iov->iov_len;
78 xfer_buflen -= iov->iov_len;
80 assert(xfer_buflen == 0);
81 assert(iov_index <= IO_VECTOR_LIMIT);
83 rc = vsl_vectored_write(io_u->file->fd, d->iov, iov_index, O_ATOMIC);
85 td_verror(td, -errno, "vsl_vectored_write");
100 static int open_file(struct thread_data *td, struct fio_file *f)
103 struct acs_engine_data *d = NULL;
105 d = malloc(sizeof(*d));
107 td_verror(td, -ENOMEM, "malloc");
111 f->engine_data = (uintptr_t) d;
113 rc = generic_open_file(td, f);
127 static int close_file(struct thread_data *td, struct fio_file *f)
129 if (f->engine_data) {
130 free((void *) f->engine_data);
134 return generic_close_file(td, f);
137 static struct ioengine_ops ioengine = {
138 .name = "fusion-aw-sync",
139 .version = FIO_IOOPS_VERSION,
141 .open_file = open_file,
142 .close_file = close_file,
143 .get_file_size = generic_get_file_size,
144 .flags = FIO_SYNCIO | FIO_RAWIO | FIO_MEMALIGN
147 static void fio_init fio_fusion_aw_init(void)
149 register_ioengine(&ioengine);
152 static void fio_exit fio_fusion_aw_exit(void)
154 unregister_ioengine(&ioengine);