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 #ifdef FIO_HAVE_FUSION_AW
27 #include <vsl_dp_experimental/vectored_write.h>
29 /* Fix sector size to 512 bytes independent of actual sector size, just like
30 * the linux kernel. */
31 #define SECTOR_SHIFT 9
32 #define SECTOR_SIZE (1U<<SECTOR_SHIFT)
34 struct acs_file_data {
35 struct vsl_iovec iov[IO_VECTOR_LIMIT];
38 static int queue(struct thread_data *td, struct io_u *io_u)
45 struct acs_file_data *d = io_u->file->file_data;
47 if (io_u->ddir != DDIR_WRITE) {
48 td_vmsg(td, -EIO, "only writes supported", "io_u->ddir");
52 if (io_u->xfer_buflen > IO_SIZE_MAX) {
53 td_vmsg(td, -EIO, "data too big", "io_u->xfer_buflen");
57 if (io_u->xfer_buflen & (SECTOR_SIZE - 1)) {
58 td_vmsg(td, -EIO, "unaligned data size", "io_u->xfer_buflen");
63 /* Chop up the write into minimal number of iovec's necessary */
65 offset = io_u->offset;
66 xfer_buf = io_u->xfer_buf;
67 xfer_buflen = io_u->xfer_buflen;
69 struct vsl_iovec *iov = &d->iov[iov_index++];
71 iov->iov_len = xfer_buflen > IO_VECTOR_MAX_SIZE ?
72 IO_VECTOR_MAX_SIZE : xfer_buflen;
73 iov->iov_base = (uint64_t) xfer_buf;
74 iov->sector = offset >> SECTOR_SHIFT;
75 iov->iov_flag = VSL_IOV_WRITE;
77 offset += iov->iov_len;
78 xfer_buf += iov->iov_len;
79 xfer_buflen -= iov->iov_len;
81 assert(xfer_buflen == 0);
82 assert(iov_index <= IO_VECTOR_LIMIT);
84 rc = vsl_vectored_write(io_u->file->fd, d->iov, iov_index, O_ATOMIC);
86 td_verror(td, -errno, "vsl_vectored_write");
91 io_u->file->file_pos = io_u->offset + rc;
102 static int open_file(struct thread_data *td, struct fio_file *f)
105 struct acs_file_data *d = NULL;
107 d = malloc(sizeof(*d));
109 td_verror(td, -ENOMEM, "malloc");
115 rc = generic_open_file(td, f);
129 static int close_file(struct thread_data *td, struct fio_file *f)
136 return generic_close_file(td, f);
139 static struct ioengine_ops ioengine = {
140 .name = "fusion-aw-sync",
141 .version = FIO_IOOPS_VERSION,
143 .open_file = open_file,
144 .close_file = close_file,
145 .get_file_size = generic_get_file_size,
146 .flags = FIO_SYNCIO | FIO_RAWIO | FIO_MEMALIGN
149 #else /* !FUSION_HAVE_FUSION_AW */
151 static int fio_fusion_aw_eng_init(struct thread_data fio_unused *td)
153 log_err("fio: fusion atomic write engine not available\n");
157 static struct ioengine_ops ioengine = {
158 .name = "fusion-aw-sync",
159 .version = FIO_IOOPS_VERSION,
160 .init = fio_fusion_aw_eng_init,
163 #endif /* FUSION_HAVE_FUSION_AW */
165 static void fio_init fio_fusion_aw_init(void)
167 register_ioengine(&ioengine);
170 static void fio_exit fio_fusion_aw_exit(void)
172 unregister_ioengine(&ioengine);