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  &dfs_aiori,
47 #endif
48  & dummy_aiori,
49 #ifdef USE_HDF5_AIORI
50  &hdf5_aiori,
51 #endif
52 #ifdef USE_HDFS_AIORI
53  &hdfs_aiori,
54 #endif
55 #ifdef USE_IME_AIORI
56  &ime_aiori,
57 #endif
58 #ifdef USE_MPIIO_AIORI
59  &mpiio_aiori,
60 #endif
61 #ifdef USE_NCMPI_AIORI
62  &ncmpi_aiori,
63 #endif
64 #ifdef USE_MMAP_AIORI
65  &mmap_aiori,
66 #endif
67 #ifdef USE_S3_AIORI
68  &s3_aiori,
70  &s3_emc_aiori,
71 #endif
72 #ifdef USE_RADOS_AIORI
73  &rados_aiori,
74 #endif
75 #ifdef USE_CEPHFS_AIORI
76  &cephfs_aiori,
77 #endif
78 #ifdef USE_GFARM_AIORI
79  &gfarm_aiori,
80 #endif
81  NULL
82 };
83 
85  if (backend->get_options == NULL)
86  return NULL;
87  char * name = backend->name;
89  for (int i=1; *tmp != NULL; ++tmp, i++) {
90  if (strcmp(opt->modules[i].prefix, name) == 0){
91  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, opt->modules[i].defaults);
92  return opt->modules[i].defaults;
93  }
94  }
95  return NULL;
96 }
97 
99  int airoi_c = aiori_count();
100  options_all_t * opt = malloc(sizeof(options_all_t));
101  opt->module_count = airoi_c + 1;
102  opt->modules = malloc(sizeof(option_module) * (airoi_c + 1));
103  opt->modules[0].prefix = NULL;
104  opt->modules[0].options = global_options;
106  for (int i=1; *tmp != NULL; ++tmp, i++) {
107  opt->modules[i].prefix = (*tmp)->name;
108  if((*tmp)->get_options != NULL){
109  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, NULL);
110  }else{
111  opt->modules[i].options = NULL;
112  }
113  }
114  return opt;
115 }
116 
117 void aiori_supported_apis(char * APIs, char * APIs_legacy, enum bench_type type)
118 {
120  char delimiter = ' ';
121 
122  while (*tmp != NULL)
123  {
124  if ((type == MDTEST) && !(*tmp)->enable_mdtest)
125  {
126  tmp++;
127  continue;
128  }
129 
130  if (delimiter == ' ')
131  {
132  APIs += sprintf(APIs, "%s", (*tmp)->name);
133  delimiter = '|';
134  }
135  else
136  APIs += sprintf(APIs, "%c%s", delimiter, (*tmp)->name);
137 
138  if ((*tmp)->name_legacy != NULL)
139  APIs_legacy += sprintf(APIs_legacy, "%c%s",
140  delimiter, (*tmp)->name_legacy);
141  tmp++;
142  }
143 }
144 
154 int aiori_posix_statfs (const char *path, ior_aiori_statfs_t *stat_buf, IOR_param_t * param)
155 {
156  int ret;
157 #if defined(HAVE_STATVFS)
158  struct statvfs statfs_buf;
159 
160  ret = statvfs (path, &statfs_buf);
161 #else
162  struct statfs statfs_buf;
163 
164  ret = statfs (path, &statfs_buf);
165 #endif
166  if (-1 == ret) {
167  return -1;
168  }
169 
170  stat_buf->f_bsize = statfs_buf.f_bsize;
171  stat_buf->f_blocks = statfs_buf.f_blocks;
172  stat_buf->f_bfree = statfs_buf.f_bfree;
173  stat_buf->f_files = statfs_buf.f_files;
174  stat_buf->f_ffree = statfs_buf.f_ffree;
175 
176  return 0;
177 }
178 
179 int aiori_posix_mkdir (const char *path, mode_t mode, IOR_param_t * param)
180 {
181  return mkdir (path, mode);
182 }
183 
184 int aiori_posix_rmdir (const char *path, IOR_param_t * param)
185 {
186  return rmdir (path);
187 }
188 
189 int aiori_posix_access (const char *path, int mode, IOR_param_t * param)
190 {
191  return access (path, mode);
192 }
193 
194 int aiori_posix_stat (const char *path, struct stat *buf, IOR_param_t * param)
195 {
196  return stat (path, buf);
197 }
198 
200 {
201  return "";
202 }
203 
204 static bool is_initialized = false;
205 
206 static void init_or_fini_internal(const ior_aiori_t *test_backend,
207  const bool init)
208 {
209  if (init)
210  {
211  if (test_backend->initialize)
212  test_backend->initialize();
213  }
214  else
215  {
216  if (test_backend->finalize)
217  test_backend->finalize();
218  }
219 }
220 
221 static void init_or_fini(IOR_test_t *tests, const bool init)
222 {
223  /* Sanity check, we were compiled with SOME backend, right? */
224  if (0 == aiori_count ()) {
225  ERR("No IO backends compiled into aiori. "
226  "Run 'configure --with-<backend>', and recompile.");
227  }
228 
229  /* Pointer to the initialize of finalize function */
230 
231 
232  /* if tests is NULL, initialize or finalize all available backends */
233  if (tests == NULL)
234  {
235  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp)
236  init_or_fini_internal(*tmp, init);
237 
238  return;
239  }
240 
241  for (IOR_test_t *t = tests; t != NULL; t = t->next)
242  {
243  IOR_param_t *params = &t->params;
244  assert(params != NULL);
245 
246  const ior_aiori_t *test_backend = params->backend;
247  assert(test_backend != NULL);
248 
249  init_or_fini_internal(test_backend, init);
250  }
251 }
252 
253 
263 {
264  if (is_initialized)
265  return;
266 
267  init_or_fini(tests, true);
268 
269  is_initialized = true;
270 }
271 
281 {
282  if (!is_initialized)
283  return;
284 
285  is_initialized = false;
286 
287  init_or_fini(tests, false);
288 }
289 
290 const ior_aiori_t *aiori_select (const char *api)
291 {
292  char warn_str[256] = {0};
293  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
294  char *name_leg = (*tmp)->name_legacy;
295  if (NULL != api &&
296  (strcasecmp(api, (*tmp)->name) != 0) &&
297  (name_leg == NULL || strcasecmp(api, name_leg) != 0))
298  continue;
299 
300  if (name_leg != NULL && strcasecmp(api, name_leg) == 0)
301  {
302  snprintf(warn_str, 256, "%s backend is deprecated use %s"
303  " instead", api, (*tmp)->name);
304  WARN(warn_str);
305  }
306 
307  if (NULL == (*tmp)->statfs) {
308  (*tmp)->statfs = aiori_posix_statfs;
309  snprintf(warn_str, 256, "assuming POSIX-based backend for"
310  " %s statfs call", api);
311  WARN(warn_str);
312  }
313  if (NULL == (*tmp)->mkdir) {
314  (*tmp)->mkdir = aiori_posix_mkdir;
315  snprintf(warn_str, 256, "assuming POSIX-based backend for"
316  " %s mkdir call", api);
317  WARN(warn_str);
318  }
319  if (NULL == (*tmp)->rmdir) {
320  (*tmp)->rmdir = aiori_posix_rmdir;
321  snprintf(warn_str, 256, "assuming POSIX-based backend for"
322  " %s rmdir call", api);
323  WARN(warn_str);
324  }
325  if (NULL == (*tmp)->access) {
326  (*tmp)->access = aiori_posix_access;
327  snprintf(warn_str, 256, "assuming POSIX-based backend for"
328  " %s access call", api);
329  WARN(warn_str);
330  }
331  if (NULL == (*tmp)->stat) {
332  (*tmp)->stat = aiori_posix_stat;
333  snprintf(warn_str, 256, "assuming POSIX-based backend for"
334  " %s stat call", api);
335  WARN(warn_str);
336  }
337 
338  return *tmp;
339  }
340 
341  return NULL;
342 }
343 
344 int aiori_count (void)
345 {
346  return sizeof (available_aiori)/sizeof(available_aiori[0]) - 1;
347 }
348 
349 const char *aiori_default (void)
350 {
351  if (aiori_count () > 0) {
352  return available_aiori[0]->name;
353  }
354 
355  return NULL;
356 }
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:206
uint64_t f_bfree
Definition: aiori.h:60
#define ERR(MSG)
Definition: iordef.h:184
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:84
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:204
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:184
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:179
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:344
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:154
ior_aiori_t dummy_aiori
Definition: aiori-DUMMY.c:155
const ior_aiori_t * aiori_select(const char *api)
Definition: aiori.c:290
void aiori_initialize(IOR_test_t *tests)
Definition: aiori.c:262
void(* finalize)(void)
Definition: aiori.h:86
char * aiori_get_version()
Definition: aiori.c:199
uint64_t f_files
Definition: aiori.h:62
void aiori_finalize(IOR_test_t *tests)
Definition: aiori.c:280
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:98
void aiori_supported_apis(char *APIs, char *APIs_legacy, enum bench_type type)
Definition: aiori.c:117
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:221
ior_aiori_t dfs_aiori
Definition: aiori-DFS.c:125
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:349
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:194
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:189
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