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");
101 static int open_file(struct thread_data *td, struct fio_file *f)
104 struct acs_file_data *d = NULL;
106 d = malloc(sizeof(*d));
108 td_verror(td, -ENOMEM, "malloc");
114 rc = generic_open_file(td, f);
128 static int close_file(struct thread_data *td, struct fio_file *f)
135 return generic_close_file(td, f);
138 static struct ioengine_ops ioengine = {
139 .name = "fusion-aw-sync",
140 .version = FIO_IOOPS_VERSION,
142 .open_file = open_file,
143 .close_file = close_file,
144 .get_file_size = generic_get_file_size,
145 .flags = FIO_SYNCIO | FIO_RAWIO | FIO_MEMALIGN
148 #else /* !FUSION_HAVE_FUSION_AW */
150 static int fio_fusion_aw_eng_init(struct thread_data fio_unused *td)
152 log_err("fio: fusion atomic write engine not available\n");
156 static struct ioengine_ops ioengine = {
157 .name = "fusion-aw-sync",
158 .version = FIO_IOOPS_VERSION,
159 .init = fio_fusion_aw_eng_init,
162 #endif /* FUSION_HAVE_FUSION_AW */
164 static void fio_init fio_fusion_aw_init(void)
166 register_ioengine(&ioengine);
169 static void fio_exit fio_fusion_aw_exit(void)
171 unregister_ioengine(&ioengine);