4 * common Glusterfs's gfapi interface
10 struct fio_option gfapi_options[] = {
13 .lname = "Glusterfs volume",
14 .type = FIO_OPT_STR_STORE,
15 .help = "Name of the Glusterfs volume",
16 .off1 = offsetof(struct gf_options, gf_vol),
17 .category = FIO_OPT_C_ENGINE,
18 .group = FIO_OPT_G_GFAPI,
22 .lname = "Glusterfs brick name",
23 .type = FIO_OPT_STR_STORE,
24 .help = "Name of the Glusterfs brick to connect",
25 .off1 = offsetof(struct gf_options, gf_brick),
26 .category = FIO_OPT_C_ENGINE,
27 .group = FIO_OPT_G_GFAPI,
34 int fio_gf_setup(struct thread_data *td)
37 struct gf_data *g = NULL;
38 struct gf_options *opt = td->eo;
39 struct stat sb = { 0, };
41 dprint(FD_IO, "fio setup\n");
46 g = malloc(sizeof(struct gf_data));
48 log_err("malloc failed.\n");
55 g->fs = glfs_new(opt->gf_vol);
57 log_err("glfs_new failed.\n");
60 glfs_set_logging(g->fs, "/tmp/fio_gfapi.log", 7);
62 r = glfs_set_volfile_server(g->fs, "tcp", opt->gf_brick, 0);
64 log_err("glfs_set_volfile_server failed.\n");
69 log_err("glfs_init failed. Is glusterd running on brick?\n");
73 r = glfs_lstat(g->fs, ".", &sb);
75 log_err("glfs_lstat failed.\n");
78 dprint(FD_FILE, "fio setup %p\n", g->fs);
87 td->io_ops->data = NULL;
93 void fio_gf_cleanup(struct thread_data *td)
95 struct gf_data *g = td->io_ops->data;
105 td->io_ops->data = NULL;
109 int fio_gf_get_file_size(struct thread_data *td, struct fio_file *f)
113 struct gf_data *g = td->io_ops->data;
115 dprint(FD_FILE, "get file size %s\n", f->file_name);
120 if (fio_file_size_known(f))
123 ret = glfs_lstat(g->fs, f->file_name, &buf);
125 log_err("glfs_lstat failed.\n");
129 f->real_file_size = buf.st_size;
130 fio_file_set_size_known(f);
136 int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
141 struct gf_data *g = td->io_ops->data;
142 struct stat sb = { 0, };
147 } else if (td_read(td)) {
153 dprint(FD_FILE, "fio file %s open mode %s td rw %s\n", f->file_name,
154 flags == O_RDONLY ? "ro" : "rw", td_read(td) ? "read" : "write");
155 g->fd = glfs_creat(g->fs, f->file_name, flags, 0644);
157 log_err("glfs_creat failed.\n");
160 /* file for read doesn't exist or shorter than required, create/extend it */
162 if (glfs_lstat(g->fs, f->file_name, &sb)
163 || sb.st_size < f->real_file_size) {
164 dprint(FD_FILE, "fio extend file %s from %ld to %ld\n",
165 f->file_name, sb.st_size, f->real_file_size);
166 ret = glfs_ftruncate(g->fd, f->real_file_size);
168 log_err("failed fio extend file %s to %ld\n",
169 f->file_name, f->real_file_size);
171 unsigned long long left;
176 /* fill the file, copied from extend_file */
177 b = malloc(td->o.max_bs[DDIR_WRITE]);
179 left = f->real_file_size;
180 while (left && !td->terminate) {
181 bs = td->o.max_bs[DDIR_WRITE];
185 fill_io_buffer(td, b, bs, bs);
187 r = glfs_write(g->fd, b, bs, 0);
189 "fio write %d of %ld file %s\n",
190 r, f->real_file_size,
205 ("fio: ENOSPC on laying out "
221 glfs_lseek(g->fd, 0, SEEK_SET);
224 dprint(FD_FILE, "terminate unlink %s\n",
226 unlink(f->file_name);
227 } else if (td->o.create_fsync) {
228 if (glfs_fsync(g->fd) < 0) {
230 "failed to sync, close %s\n",
232 td_verror(td, errno, "fsync");
241 #if defined(GFAPI_USE_FADVISE)
245 r = glfs_fadvise(g->fd, 0, f->real_file_size,
248 r = glfs_fadvise(g->fd, 0, f->real_file_size,
249 POSIX_FADV_SEQUENTIAL);
252 dprint(FD_FILE, "fio %p fadvise %s status %d\n", g->fs,
257 dprint(FD_FILE, "fio %p created %s\n", g->fs, f->file_name);
264 int fio_gf_close_file(struct thread_data *td, struct fio_file *f)
267 struct gf_data *g = td->io_ops->data;
269 dprint(FD_FILE, "fd close %s\n", f->file_name);
272 if (g->fd && glfs_close(g->fd) < 0)
281 td->io_ops->data = NULL;