IOR
aiori-CHFS.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <chfs.h>
4 #include "ior.h"
5 #include "aiori.h"
6 
8 
9 struct CHFS_File {
10  int fd;
11 };
12 
13 struct chfs_option {
14  size_t chunk_size;
15 };
16 
18 CHFS_options(aiori_mod_opt_t **init_backend_options,
19  aiori_mod_opt_t *init_values)
20 {
21  struct chfs_option *o = malloc(sizeof(*o));
22 
23  if (init_values != NULL)
24  memcpy(o, init_values, sizeof(*o));
25  else
26  memset(o, 0, sizeof(*o));
27 
28  if (o->chunk_size > 0)
29  chfs_set_chunk_size(o->chunk_size);
30 
31  *init_backend_options = (aiori_mod_opt_t *)o;
32 
33  option_help h[] = {
34  {0, "chfs.chunk_size", "chunk size", OPTION_FLAG, 'd',
35  &o->chunk_size},
37  };
38  option_help *help = malloc(sizeof(h));
39  memcpy(help, h, sizeof(h));
40 
41  return (help);
42 }
43 
44 void
46 {
47  hints = params;
48 }
49 
50 void
52 {
53  chfs_init(NULL);
54 }
55 
56 void
58 {
59  chfs_term();
60 }
61 
62 aiori_fd_t *
63 CHFS_create(char *fn, int flags, aiori_mod_opt_t *param)
64 {
65  struct CHFS_File *bf;
66  int fd;
67 
68  if (hints->dryRun)
69  return (NULL);
70 
71  fd = chfs_create(fn, flags, 0664);
72  if (fd < 0)
73  ERR("chfs_create failed");
74  bf = malloc(sizeof(*bf));
75  bf->fd = fd;
76 
77  return ((aiori_fd_t *)bf);
78 }
79 
80 aiori_fd_t *
81 CHFS_open(char *fn, int flags, aiori_mod_opt_t *param)
82 {
83  struct CHFS_File *bf;
84  int fd;
85 
86  if (hints->dryRun)
87  return (NULL);
88 
89  fd = chfs_open(fn, flags);
90  if (fd < 0)
91  ERR("chfs_open failed");
92  bf = malloc(sizeof(*bf));
93  bf->fd = fd;
94 
95  return ((aiori_fd_t *)bf);
96 }
97 
99 CHFS_xfer(int access, aiori_fd_t *fd, IOR_size_t *buffer,
100  IOR_offset_t len, IOR_offset_t offset, aiori_mod_opt_t *param)
101 {
102  struct CHFS_File *bf = (struct CHFS_File *)fd;
103  ssize_t r;
104 
105  if (hints->dryRun)
106  return (len);
107 
108  switch (access) {
109  case WRITE:
110  r = chfs_pwrite(bf->fd, buffer, len, offset);
111  break;
112  default:
113  r = chfs_pread(bf->fd, buffer, len, offset);
114  break;
115  }
116  return (r);
117 }
118 
119 void
121 {
122  struct CHFS_File *bf = (struct CHFS_File *)fd;
123 
124  if (hints->dryRun)
125  return;
126 
127  chfs_close(bf->fd);
128  free(bf);
129 }
130 
131 void
132 CHFS_delete(char *fn, aiori_mod_opt_t *param)
133 {
134  if (hints->dryRun)
135  return;
136 
137  chfs_unlink(fn);
138 }
139 
140 char *
142 {
143  return ((char *)chfs_version());
144 }
145 
146 void
148 {
149  struct CHFS_File *bf = (struct CHFS_File *)fd;
150 
151  if (hints->dryRun)
152  return;
153 
154  chfs_fsync(bf->fd);
155 }
156 
159 {
160  struct stat st;
161  int r;
162 
163  if (hints->dryRun)
164  return (0);
165 
166  r = chfs_stat(fn, &st);
167  if (r < 0)
168  return (r);
169 
170  return (st.st_size);
171 }
172 
173 int
174 CHFS_statfs(const char *fn, ior_aiori_statfs_t *st, aiori_mod_opt_t *param)
175 {
176  if (hints->dryRun)
177  return (0);
178 
179  return (0);
180 }
181 
182 int
183 CHFS_mkdir(const char *fn, mode_t mode, aiori_mod_opt_t *param)
184 {
185  if (hints->dryRun)
186  return (0);
187 
188  return (chfs_mkdir(fn, mode));
189 }
190 
191 int
192 CHFS_rmdir(const char *fn, aiori_mod_opt_t *param)
193 {
194  if (hints->dryRun)
195  return (0);
196 
197  return (chfs_rmdir(fn));
198 }
199 
200 int
201 CHFS_access(const char *fn, int mode, aiori_mod_opt_t *param)
202 {
203  struct stat sb;
204 
205  if (hints->dryRun)
206  return (0);
207 
208  return (chfs_stat(fn, &sb));
209 }
210 
211 int
212 CHFS_stat(const char *fn, struct stat *buf, aiori_mod_opt_t *param)
213 {
214  if (hints->dryRun)
215  return (0);
216 
217  return (chfs_stat(fn, buf));
218 }
219 
220 void
222 {
223  if (hints->dryRun)
224  return;
225 
226  return;
227 }
228 
230  .name = "CHFS",
231  .name_legacy = NULL,
232  .create = CHFS_create,
233  .open = CHFS_open,
234  .xfer_hints = CHFS_xfer_hints,
235  .xfer = CHFS_xfer,
236  .close = CHFS_close,
237  .delete = CHFS_delete,
238  .get_version = CHFS_version,
239  .fsync = CHFS_fsync,
240  .get_file_size = CHFS_get_file_size,
241  .statfs = CHFS_statfs,
242  .mkdir = CHFS_mkdir,
243  .rmdir = CHFS_rmdir,
244  .access = CHFS_access,
245  .stat = CHFS_stat,
246  .initialize = CHFS_initialize,
247  .finalize = CHFS_finalize,
248  .get_options = CHFS_options,
249  .sync = CHFS_sync,
250  .enable_mdtest = true,
251 };
#define LAST_OPTION
Definition: option.h:39
aiori_fd_t * CHFS_create(char *fn, int flags, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:63
void CHFS_delete(char *fn, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:132
struct benchmark_options o
Definition: md-workbench.c:133
aiori_fd_t * CHFS_open(char *fn, int flags, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:81
int CHFS_rmdir(const char *fn, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:192
int CHFS_statfs(const char *fn, ior_aiori_statfs_t *st, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:174
char * CHFS_version()
Definition: aiori-CHFS.c:141
void CHFS_sync(aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:221
#define WRITE
Definition: iordef.h:100
void CHFS_initialize()
Definition: aiori-CHFS.c:51
size_t chunk_size
Definition: aiori-CHFS.c:14
int CHFS_mkdir(const char *fn, mode_t mode, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:183
void CHFS_fsync(aiori_fd_t *fd, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:147
void CHFS_xfer_hints(aiori_xfer_hint_t *params)
Definition: aiori-CHFS.c:45
IOR_offset_t CHFS_xfer(int access, aiori_fd_t *fd, IOR_size_t *buffer, IOR_offset_t len, IOR_offset_t offset, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:99
ior_aiori_t chfs_aiori
Definition: aiori-CHFS.c:229
IOR_offset_t CHFS_get_file_size(aiori_mod_opt_t *param, char *fn)
Definition: aiori-CHFS.c:158
void CHFS_finalize()
Definition: aiori-CHFS.c:57
option_help * CHFS_options(aiori_mod_opt_t **init_backend_options, aiori_mod_opt_t *init_values)
Definition: aiori-CHFS.c:18
long long int IOR_size_t
Definition: iordef.h:124
void CHFS_close(aiori_fd_t *fd, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:120
int CHFS_access(const char *fn, int mode, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:201
#define ERR(MSG)
Definition: aiori-debug.h:75
char * name
Definition: aiori.h:88
long long int IOR_offset_t
Definition: iordef.h:123
static aiori_xfer_hint_t * hints
Definition: aiori-CHFS.c:7
int CHFS_stat(const char *fn, struct stat *buf, aiori_mod_opt_t *param)
Definition: aiori-CHFS.c:212
#define NULL
Definition: iordef.h:84