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. You may obtain a copy
10 * of the source code for DirectFS by sending a request to Fusion-io, Inc.,
11 * 2855 E. Cottonwood Parkway, Suite 100, Salt Lake City, UT 84121; Attention:
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version
19 * You should have received a copy of the GNU General Public License Version 2
20 * along with this program; if not see <http://www.gnu.org/licenses/>
28 #ifdef FIO_HAVE_FUSION_AW
30 #include <vsl_dp_experimental/vectored_write.h>
32 /* Fix sector size to 512 bytes independent of actual sector size, just like
33 * the linux kernel. */
34 #define SECTOR_SHIFT 9
35 #define SECTOR_SIZE (1U<<SECTOR_SHIFT)
37 struct acs_file_data {
38 struct vsl_iovec iov[IO_VECTOR_LIMIT];
41 static int queue(struct thread_data *td, struct io_u *io_u)
48 struct acs_file_data *d = io_u->file->file_data;
50 if (io_u->ddir != DDIR_WRITE) {
51 td_vmsg(td, -EIO, "only writes supported", "io_u->ddir");
55 if (io_u->xfer_buflen > IO_SIZE_MAX) {
56 td_vmsg(td, -EIO, "data too big", "io_u->xfer_buflen");
60 if (io_u->xfer_buflen & (SECTOR_SIZE - 1)) {
61 td_vmsg(td, -EIO, "unaligned data size", "io_u->xfer_buflen");
66 /* Chop up the write into minimal number of iovec's necessary */
68 offset = io_u->offset;
69 xfer_buf = io_u->xfer_buf;
70 xfer_buflen = io_u->xfer_buflen;
72 struct vsl_iovec *iov = &d->iov[iov_index++];
74 iov->iov_len = xfer_buflen > IO_VECTOR_MAX_SIZE ?
75 IO_VECTOR_MAX_SIZE : xfer_buflen;
76 iov->iov_base = (uint64_t) xfer_buf;
77 iov->sector = offset >> SECTOR_SHIFT;
78 iov->iov_flag = VSL_IOV_WRITE;
80 offset += iov->iov_len;
81 xfer_buf += iov->iov_len;
82 xfer_buflen -= iov->iov_len;
84 assert(xfer_buflen == 0);
85 assert(iov_index <= IO_VECTOR_LIMIT);
87 rc = vsl_vectored_write(io_u->file->fd, d->iov, iov_index, O_ATOMIC);
89 td_verror(td, -errno, "vsl_vectored_write");
94 io_u->file->file_pos = io_u->offset + rc;
105 static int open_file(struct thread_data *td, struct fio_file *f)
108 struct acs_file_data *d = NULL;
110 d = malloc(sizeof(*d));
112 td_verror(td, -ENOMEM, "malloc");
118 rc = generic_open_file(td, f);
132 static int close_file(struct thread_data *td, struct fio_file *f)
139 return generic_close_file(td, f);
142 static struct ioengine_ops ioengine = {
143 .name = "fusion-aw-sync",
144 .version = FIO_IOOPS_VERSION,
146 .open_file = open_file,
147 .close_file = close_file,
148 .get_file_size = generic_get_file_size,
149 .flags = FIO_SYNCIO | FIO_RAWIO | FIO_MEMALIGN
152 #else /* !FUSION_HAVE_FUSION_AW */
154 static int fio_fusion_aw_eng_init(struct thread_data fio_unused *td)
156 log_err("fio: fusion atomic write engine not available\n");
160 static struct ioengine_ops ioengine = {
161 .name = "fusion-aw-sync",
162 .version = FIO_IOOPS_VERSION,
163 .init = fio_fusion_aw_eng_init,
166 #endif /* FUSION_HAVE_FUSION_AW */
168 static void fio_init fio_fusion_aw_init(void)
170 register_ioengine(&ioengine);
173 static void fio_exit fio_fusion_aw_exit(void)
175 unregister_ioengine(&ioengine);