IOR
aiori.c
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 /******************************************************************************\
5 * *
6 * Copyright (c) 2003, The Regents of the University of California *
7 * See the file COPYRIGHT for a complete copyright notice and license. *
8 * *
9 ********************************************************************************
10 *
11 * Definitions and prototypes of abstract I/O interface
12 *
13 \******************************************************************************/
14 
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18 
19 #include <assert.h>
20 #include <stdbool.h>
21 
22 #if defined(HAVE_STRINGS_H)
23 #include <strings.h>
24 #endif
25 
26 #include "aiori.h"
27 
28 #if defined(HAVE_SYS_STATVFS_H)
29 #include <sys/statvfs.h>
30 #endif
31 
32 #if defined(HAVE_SYS_STATFS_H)
33 #include <sys/statfs.h>
34 #endif
35 
36 /*
37  * Bind the global "backend" pointer to the requested backend AIORI's
38  * function table.
39  */
40 
42 #ifdef USE_POSIX_AIORI
43  &posix_aiori,
44 #endif
45 #ifdef USE_DAOS_AIORI
46  &daos_aiori,
47  &dfs_aiori,
48 #endif
49  & dummy_aiori,
50 #ifdef USE_HDF5_AIORI
51  &hdf5_aiori,
52 #endif
53 #ifdef USE_HDFS_AIORI
54  &hdfs_aiori,
55 #endif
56 #ifdef USE_IME_AIORI
57  &ime_aiori,
58 #endif
59 #ifdef USE_MPIIO_AIORI
60  &mpiio_aiori,
61 #endif
62 #ifdef USE_NCMPI_AIORI
63  &ncmpi_aiori,
64 #endif
65 #ifdef USE_MMAP_AIORI
66  &mmap_aiori,
67 #endif
68 #ifdef USE_S3_AIORI
69  &s3_aiori,
71  &s3_emc_aiori,
72 #endif
73 #ifdef USE_RADOS_AIORI
74  &rados_aiori,
75 #endif
76 #ifdef USE_CEPHFS_AIORI
77  &cephfs_aiori,
78 #endif
79 #ifdef USE_GFARM_AIORI
80  &gfarm_aiori,
81 #endif
82  NULL
83 };
84 
86  if (backend->get_options == NULL)
87  return NULL;
88  char * name = backend->name;
90  for (int i=1; *tmp != NULL; ++tmp, i++) {
91  if (strcmp(opt->modules[i].prefix, name) == 0){
92  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, opt->modules[i].defaults);
93  return opt->modules[i].defaults;
94  }
95  }
96  return NULL;
97 }
98 
100  int airoi_c = aiori_count();
101  options_all_t * opt = malloc(sizeof(options_all_t));
102  opt->module_count = airoi_c + 1;
103  opt->modules = malloc(sizeof(option_module) * (airoi_c + 1));
104  opt->modules[0].prefix = NULL;
105  opt->modules[0].options = global_options;
107  for (int i=1; *tmp != NULL; ++tmp, i++) {
108  opt->modules[i].prefix = (*tmp)->name;
109  if((*tmp)->get_options != NULL){
110  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, NULL);
111  }else{
112  opt->modules[i].options = NULL;
113  }
114  }
115  return opt;
116 }
117 
118 void aiori_supported_apis(char * APIs, char * APIs_legacy, enum bench_type type)
119 {
121  char delimiter = ' ';
122 
123  while (*tmp != NULL)
124  {
125  if ((type == MDTEST) && !(*tmp)->enable_mdtest)
126  {
127  tmp++;
128  continue;
129  }
130 
131  if (delimiter == ' ')
132  {
133  APIs += sprintf(APIs, "%s", (*tmp)->name);
134  delimiter = '|';
135  }
136  else
137  APIs += sprintf(APIs, "%c%s", delimiter, (*tmp)->name);
138 
139  if ((*tmp)->name_legacy != NULL)
140  APIs_legacy += sprintf(APIs_legacy, "%c%s",
141  delimiter, (*tmp)->name_legacy);
142  tmp++;
143  }
144 }
145 
155 int aiori_posix_statfs (const char *path, ior_aiori_statfs_t *stat_buf, IOR_param_t * param)
156 {
157  int ret;
158 #if defined(HAVE_STATVFS)
159  struct statvfs statfs_buf;
160 
161  ret = statvfs (path, &statfs_buf);
162 #else
163  struct statfs statfs_buf;
164 
165  ret = statfs (path, &statfs_buf);
166 #endif
167  if (-1 == ret) {
168  return -1;
169  }
170 
171  stat_buf->f_bsize = statfs_buf.f_bsize;
172  stat_buf->f_blocks = statfs_buf.f_blocks;
173  stat_buf->f_bfree = statfs_buf.f_bfree;
174  stat_buf->f_files = statfs_buf.f_files;
175  stat_buf->f_ffree = statfs_buf.f_ffree;
176 
177  return 0;
178 }
179 
180 int aiori_posix_mkdir (const char *path, mode_t mode, IOR_param_t * param)
181 {
182  return mkdir (path, mode);
183 }
184 
185 int aiori_posix_rmdir (const char *path, IOR_param_t * param)
186 {
187  return rmdir (path);
188 }
189 
190 int aiori_posix_access (const char *path, int mode, IOR_param_t * param)
191 {
192  return access (path, mode);
193 }
194 
195 int aiori_posix_stat (const char *path, struct stat *buf, IOR_param_t * param)
196 {
197  return stat (path, buf);
198 }
199 
201 {
202  return "";
203 }
204 
205 static bool is_initialized = false;
206 
207 static void init_or_fini_internal(const ior_aiori_t *test_backend,
208  const bool init)
209 {
210  if (init)
211  {
212  if (test_backend->initialize)
213  test_backend->initialize();
214  }
215  else
216  {
217  if (test_backend->finalize)
218  test_backend->finalize();
219  }
220 }
221 
222 static void init_or_fini(IOR_test_t *tests, const bool init)
223 {
224  /* Sanity check, we were compiled with SOME backend, right? */
225  if (0 == aiori_count ()) {
226  ERR("No IO backends compiled into aiori. "
227  "Run 'configure --with-<backend>', and recompile.");
228  }
229 
230  /* Pointer to the initialize of finalize function */
231 
232 
233  /* if tests is NULL, initialize or finalize all available backends */
234  if (tests == NULL)
235  {
236  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp)
237  init_or_fini_internal(*tmp, init);
238 
239  return;
240  }
241 
242  for (IOR_test_t *t = tests; t != NULL; t = t->next)
243  {
244  IOR_param_t *params = &t->params;
245  assert(params != NULL);
246 
247  const ior_aiori_t *test_backend = params->backend;
248  assert(test_backend != NULL);
249 
250  init_or_fini_internal(test_backend, init);
251  }
252 }
253 
254 
264 {
265  if (is_initialized)
266  return;
267 
268  init_or_fini(tests, true);
269 
270  is_initialized = true;
271 }
272 
282 {
283  if (!is_initialized)
284  return;
285 
286  is_initialized = false;
287 
288  init_or_fini(tests, false);
289 }
290 
291 const ior_aiori_t *aiori_select (const char *api)
292 {
293  char warn_str[256] = {0};
294  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
295  char *name_leg = (*tmp)->name_legacy;
296  if (NULL != api &&
297  (strcasecmp(api, (*tmp)->name) != 0) &&
298  (name_leg == NULL || strcasecmp(api, name_leg) != 0))
299  continue;
300 
301  if (name_leg != NULL && strcasecmp(api, name_leg) == 0)
302  {
303  snprintf(warn_str, 256, "%s backend is deprecated use %s"
304  " instead", api, (*tmp)->name);
305  WARN(warn_str);
306  }
307 
308  if (NULL == (*tmp)->statfs) {
309  (*tmp)->statfs = aiori_posix_statfs;
310  snprintf(warn_str, 256, "assuming POSIX-based backend for"
311  " %s statfs call", api);
312  WARN(warn_str);
313  }
314  if (NULL == (*tmp)->mkdir) {
315  (*tmp)->mkdir = aiori_posix_mkdir;
316  snprintf(warn_str, 256, "assuming POSIX-based backend for"
317  " %s mkdir call", api);
318  WARN(warn_str);
319  }
320  if (NULL == (*tmp)->rmdir) {
321  (*tmp)->rmdir = aiori_posix_rmdir;
322  snprintf(warn_str, 256, "assuming POSIX-based backend for"
323  " %s rmdir call", api);
324  WARN(warn_str);
325  }
326  if (NULL == (*tmp)->access) {
327  (*tmp)->access = aiori_posix_access;
328  snprintf(warn_str, 256, "assuming POSIX-based backend for"
329  " %s access call", api);
330  WARN(warn_str);
331  }
332  if (NULL == (*tmp)->stat) {
333  (*tmp)->stat = aiori_posix_stat;
334  snprintf(warn_str, 256, "assuming POSIX-based backend for"
335  " %s stat call", api);
336  WARN(warn_str);
337  }
338 
339  return *tmp;
340  }
341 
342  return NULL;
343 }
344 
345 int aiori_count (void)
346 {
347  return sizeof (available_aiori)/sizeof(available_aiori[0]) - 1;
348 }
349 
350 const char *aiori_default (void)
351 {
352  if (aiori_count () > 0) {
353  return available_aiori[0]->name;
354  }
355 
356  return NULL;
357 }
option_module * modules
Definition: option.h:34
Definition: aiori.h:95
uint64_t f_blocks
Definition: aiori.h:59
static void init_or_fini_internal(const ior_aiori_t *test_backend, const bool init)
Definition: aiori.c:207
uint64_t f_bfree
Definition: aiori.h:60
#define ERR(MSG)
Definition: iordef.h:184
ior_aiori_t daos_aiori
Definition: aiori-DAOS.c:84
ior_aiori_t mmap_aiori
Definition: aiori-MMAP.c:39
void * airoi_update_module_options(const ior_aiori_t *backend, options_all_t *opt)
Definition: aiori.c:85
option_help *(* get_options)(void **init_backend_options, void *init_values)
Definition: aiori.h:87
void * defaults
Definition: option.h:29
bench_type
Definition: aiori.h:93
ior_aiori_t hdfs_aiori
Definition: aiori-HDFS.c:116
static bool is_initialized
Definition: aiori.c:205
ior_aiori_t hdf5_aiori
Definition: aiori-HDF5.c:127
ior_aiori_t cephfs_aiori
Definition: aiori-CEPHFS.c:83
int aiori_posix_rmdir(const char *path, IOR_param_t *param)
Definition: aiori.c:185
ior_aiori_t posix_aiori
Definition: aiori-POSIX.c:107
ior_aiori_t s3_aiori
Definition: aiori-S3.c:170
ior_aiori_t rados_aiori
Definition: aiori-RADOS.c:68
uint64_t f_ffree
Definition: aiori.h:63
int aiori_posix_mkdir(const char *path, mode_t mode, IOR_param_t *param)
Definition: aiori.c:180
ior_aiori_t ncmpi_aiori
Definition: aiori-NCMPI.c:63
ior_aiori_t * available_aiori[]
Definition: aiori.c:41
int aiori_count(void)
Definition: aiori.c:345
ior_aiori_t s3_emc_aiori
Definition: aiori-S3.c:206
int aiori_posix_statfs(const char *path, ior_aiori_statfs_t *stat_buf, IOR_param_t *param)
Definition: aiori.c:155
ior_aiori_t dummy_aiori
Definition: aiori-DUMMY.c:155
const ior_aiori_t * aiori_select(const char *api)
Definition: aiori.c:291
void aiori_initialize(IOR_test_t *tests)
Definition: aiori.c:263
void(* finalize)(void)
Definition: aiori.h:86
char * aiori_get_version()
Definition: aiori.c:200
uint64_t f_files
Definition: aiori.h:62
void aiori_finalize(IOR_test_t *tests)
Definition: aiori.c:281
uint64_t f_bsize
Definition: aiori.h:58
void(* initialize)(void)
Definition: aiori.h:85
char * name_legacy
Definition: aiori.h:69
options_all_t * airoi_create_all_module_options(option_help *global_options)
Definition: aiori.c:99
void aiori_supported_apis(char *APIs, char *APIs_legacy, enum bench_type type)
Definition: aiori.c:118
static const ior_aiori_t * backend
Definition: ior.c:49
static IOR_param_t param
Definition: mdtest.c:170
static void init_or_fini(IOR_test_t *tests, const bool init)
Definition: aiori.c:222
ior_aiori_t dfs_aiori
Definition: aiori-DFS.c:119
static options_all_t * global_options
Definition: parse_options.c:43
#define WARN(MSG)
Definition: iordef.h:144
const char * aiori_default(void)
Definition: aiori.c:350
ior_aiori_t mpiio_aiori
Definition: aiori-MPIIO.c:47
option_help * options
Definition: option.h:28
int aiori_posix_stat(const char *path, struct stat *buf, IOR_param_t *param)
Definition: aiori.c:195
const struct ior_aiori * backend
Definition: ior.h:85
char * prefix
Definition: option.h:27
int aiori_posix_access(const char *path, int mode, IOR_param_t *param)
Definition: aiori.c:190
int module_count
Definition: option.h:33
char * name
Definition: aiori.h:68
ior_aiori_t ime_aiori
Definition: aiori-IME.c:97
ior_aiori_t gfarm_aiori
Definition: aiori-Gfarm.c:296
ior_aiori_t s3_plus_aiori
Definition: aiori-S3.c:189
#define NULL
Definition: iordef.h:79