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_AIO_AIORI
46  &aio_aiori,
47 #endif
48 #ifdef USE_PMDK_AIORI
49  &pmdk_aiori,
50 #endif
51 #ifdef USE_DAOS_AIORI
52  &dfs_aiori,
53 #endif
54  & dummy_aiori,
55 #ifdef USE_HDF5_AIORI
56  &hdf5_aiori,
57 #endif
58 #ifdef USE_HDFS_AIORI
59  &hdfs_aiori,
60 #endif
61 #ifdef USE_IME_AIORI
62  &ime_aiori,
63 #endif
64 #ifdef USE_MPIIO_AIORI
65  &mpiio_aiori,
66 #endif
67 #ifdef USE_NCMPI_AIORI
68  &ncmpi_aiori,
69 #endif
70 #ifdef USE_MMAP_AIORI
71  &mmap_aiori,
72 #endif
73 #ifdef USE_S3_LIBS3_AIORI
75 #endif
76 #ifdef USE_S3_4C_AIORI
77  &s3_4c_aiori,
79  &s3_emc_aiori,
80 #endif
81 #ifdef USE_RADOS_AIORI
82  &rados_aiori,
83 #endif
84 #ifdef USE_CEPHFS_AIORI
85  &cephfs_aiori,
86 #endif
87 #ifdef USE_GFARM_AIORI
88  &gfarm_aiori,
89 #endif
90  NULL
91 };
92 
94  if (backend->get_options == NULL)
95  return NULL;
96  char * name = backend->name;
98  for (int i=1; *tmp != NULL; ++tmp, i++) {
99  if (strcmp(opt->modules[i].prefix, name) == 0){
100  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, opt->modules[i].defaults);
101  return opt->modules[i].defaults;
102  }
103  }
104  return NULL;
105 }
106 
108  if(! out_logfile) out_logfile = stdout;
109  int airoi_c = aiori_count();
110  options_all_t * opt = malloc(sizeof(options_all_t));
111  opt->module_count = airoi_c + 1;
112  opt->modules = malloc(sizeof(option_module) * (airoi_c + 1));
113  opt->modules[0].prefix = NULL;
114  opt->modules[0].options = global_options;
116  for (int i=1; *tmp != NULL; ++tmp, i++) {
117  opt->modules[i].prefix = (*tmp)->name;
118  if((*tmp)->get_options != NULL){
119  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, NULL);
120  }else{
121  opt->modules[i].options = NULL;
122  }
123  }
124  return opt;
125 }
126 
127 void aiori_supported_apis(char * APIs, char * APIs_legacy, enum bench_type type)
128 {
130  char delimiter = ' ';
131  *APIs = 0;
132  *APIs_legacy = 0;
133 
134  while (*tmp != NULL)
135  {
136  if ((type == MDTEST) && !(*tmp)->enable_mdtest)
137  {
138  tmp++;
139  continue;
140  }
141  if (delimiter == ' ')
142  {
143  APIs += sprintf(APIs, "%s", (*tmp)->name);
144  delimiter = '|';
145  }
146  else
147  APIs += sprintf(APIs, "%c%s", delimiter, (*tmp)->name);
148 
149  if ((*tmp)->name_legacy != NULL)
150  APIs_legacy += sprintf(APIs_legacy, "%c%s",
151  delimiter, (*tmp)->name_legacy);
152 
153  tmp++;
154  }
155 }
156 
166 int aiori_posix_statfs (const char *path, ior_aiori_statfs_t *stat_buf, aiori_mod_opt_t * module_options)
167 {
168  // find the parent directory
169  char * fileName = strdup(path);
170  int i;
171  int directoryFound = FALSE;
172 
173  /* get directory for outfile */
174  i = strlen(fileName);
175  while (i-- > 0) {
176  if (fileName[i] == '/') {
177  fileName[i] = '\0';
178  directoryFound = TRUE;
179  break;
180  }
181  }
182  /* if no directory/, use '.' */
183  if (directoryFound == FALSE) {
184  strcpy(fileName, ".");
185  }
186 
187  int ret;
188 #if defined(HAVE_STATVFS)
189  struct statvfs statfs_buf;
190 
191  ret = statvfs (fileName, &statfs_buf);
192 #else
193  struct statfs statfs_buf;
194 
195  ret = statfs (fileName, &statfs_buf);
196 #endif
197  if (-1 == ret) {
198  perror("POSIX couldn't call statvfs");
199  return -1;
200  }
201 
202  stat_buf->f_bsize = statfs_buf.f_bsize;
203  stat_buf->f_blocks = statfs_buf.f_blocks;
204  stat_buf->f_bfree = statfs_buf.f_bfree;
205  stat_buf->f_files = statfs_buf.f_files;
206  stat_buf->f_ffree = statfs_buf.f_ffree;
207 
208  free(fileName);
209  return 0;
210 }
211 
212 int aiori_posix_mkdir (const char *path, mode_t mode, aiori_mod_opt_t * module_options)
213 {
214  return mkdir (path, mode);
215 }
216 
217 int aiori_posix_rmdir (const char *path, aiori_mod_opt_t * module_options)
218 {
219  return rmdir (path);
220 }
221 
222 int aiori_posix_access (const char *path, int mode, aiori_mod_opt_t * module_options)
223 {
224  return access (path, mode);
225 }
226 
227 int aiori_posix_stat (const char *path, struct stat *buf, aiori_mod_opt_t * module_options)
228 {
229  return stat (path, buf);
230 }
231 
233 {
234  return "";
235 }
236 
237 const ior_aiori_t *aiori_select (const char *api)
238 {
239  char warn_str[256] = {0};
240  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
241  char *name_leg = (*tmp)->name_legacy;
242  if (NULL != api &&
243  (strcasecmp(api, (*tmp)->name) != 0) &&
244  (name_leg == NULL || strcasecmp(api, name_leg) != 0))
245  continue;
246 
247  if (name_leg != NULL && strcasecmp(api, name_leg) == 0)
248  {
249  snprintf(warn_str, 256, "%s backend is deprecated use %s"
250  " instead", api, (*tmp)->name);
251  WARN(warn_str);
252  }
253 
254  if (NULL == (*tmp)->statfs) {
255  (*tmp)->statfs = aiori_posix_statfs;
256  snprintf(warn_str, 256, "assuming POSIX-based backend for"
257  " %s statfs call", api);
258  WARN(warn_str);
259  }
260  if (NULL == (*tmp)->mkdir) {
261  (*tmp)->mkdir = aiori_posix_mkdir;
262  snprintf(warn_str, 256, "assuming POSIX-based backend for"
263  " %s mkdir call", api);
264  WARN(warn_str);
265  }
266  if (NULL == (*tmp)->rmdir) {
267  (*tmp)->rmdir = aiori_posix_rmdir;
268  snprintf(warn_str, 256, "assuming POSIX-based backend for"
269  " %s rmdir call", api);
270  WARN(warn_str);
271  }
272  if (NULL == (*tmp)->access) {
273  (*tmp)->access = aiori_posix_access;
274  snprintf(warn_str, 256, "assuming POSIX-based backend for"
275  " %s access call", api);
276  WARN(warn_str);
277  }
278  if (NULL == (*tmp)->stat) {
279  (*tmp)->stat = aiori_posix_stat;
280  snprintf(warn_str, 256, "assuming POSIX-based backend for"
281  " %s stat call", api);
282  WARN(warn_str);
283  }
284 
285  return *tmp;
286  }
287 
288  return NULL;
289 }
290 
291 int aiori_count (void)
292 {
293  return sizeof (available_aiori)/sizeof(available_aiori[0]) - 1;
294 }
295 
296 const char *aiori_default (void)
297 {
298  if (aiori_count () > 0) {
299  return available_aiori[0]->name;
300  }
301 
302  return NULL;
303 }
option_module * modules
Definition: option.h:36
Definition: aiori.h:120
ior_aiori_t s3_emc_aiori
Definition: aiori-S3-4c.c:217
uint64_t f_blocks
Definition: aiori.h:53
uint64_t f_bfree
Definition: aiori.h:54
ior_aiori_t mmap_aiori
Definition: aiori-MMAP.c:41
void * airoi_update_module_options(const ior_aiori_t *backend, options_all_t *opt)
Definition: aiori.c:93
FILE * out_logfile
Definition: utilities.c:72
bench_type
Definition: aiori.h:118
ior_aiori_t hdfs_aiori
Definition: aiori-HDFS.c:123
ior_aiori_t hdf5_aiori
Definition: aiori-HDF5.c:141
ior_aiori_t cephfs_aiori
Definition: aiori-CEPHFS.c:83
aiori_mod_opt_t * defaults
Definition: option.h:31
ior_aiori_t posix_aiori
Definition: aiori-POSIX.c:160
ior_aiori_t rados_aiori
Definition: aiori-RADOS.c:68
uint64_t f_ffree
Definition: aiori.h:57
ior_aiori_t ncmpi_aiori
Definition: aiori-NCMPI.c:100
ior_aiori_t s3_4c_aiori
Definition: aiori-S3-4c.c:178
ior_aiori_t * available_aiori[]
Definition: aiori.c:41
int aiori_count(void)
Definition: aiori.c:291
int aiori_posix_stat(const char *path, struct stat *buf, aiori_mod_opt_t *module_options)
Definition: aiori.c:227
ior_aiori_t dummy_aiori
Definition: aiori-DUMMY.c:182
const ior_aiori_t * aiori_select(const char *api)
Definition: aiori.c:237
char * aiori_get_version()
Definition: aiori.c:232
ior_aiori_t aio_aiori
Definition: aiori-aio.c:234
uint64_t f_files
Definition: aiori.h:56
uint64_t f_bsize
Definition: aiori.h:52
#define WARN(MSG)
Definition: aiori-debug.h:32
char * name_legacy
Definition: aiori.h:89
options_all_t * airoi_create_all_module_options(option_help *global_options)
Definition: aiori.c:107
void aiori_supported_apis(char *APIs, char *APIs_legacy, enum bench_type type)
Definition: aiori.c:127
static const ior_aiori_t * backend
Definition: ior.c:53
int aiori_posix_access(const char *path, int mode, aiori_mod_opt_t *module_options)
Definition: aiori.c:222
#define FALSE
Definition: iordef.h:62
ior_aiori_t dfs_aiori
Definition: aiori-DFS.c:133
static options_all_t * global_options
Definition: parse_options.c:41
int aiori_posix_rmdir(const char *path, aiori_mod_opt_t *module_options)
Definition: aiori.c:217
const char * aiori_default(void)
Definition: aiori.c:296
int aiori_posix_mkdir(const char *path, mode_t mode, aiori_mod_opt_t *module_options)
Definition: aiori.c:212
ior_aiori_t mpiio_aiori
Definition: aiori-MPIIO.c:87
option_help * options
Definition: option.h:30
ior_aiori_t s3_plus_aiori
Definition: aiori-S3-4c.c:200
char * prefix
Definition: option.h:29
int aiori_posix_statfs(const char *path, ior_aiori_statfs_t *stat_buf, aiori_mod_opt_t *module_options)
Definition: aiori.c:166
int module_count
Definition: option.h:35
option_help *(* get_options)(aiori_mod_opt_t **init_backend_options, aiori_mod_opt_t *init_values)
Definition: aiori.h:112
char * name
Definition: aiori.h:88
ior_aiori_t ime_aiori
Definition: aiori-IME.c:102
#define TRUE
Definition: iordef.h:66
ior_aiori_t S3_libS3_aiori
ior_aiori_t pmdk_aiori
Definition: aiori-PMDK.c:53
ior_aiori_t gfarm_aiori
Definition: aiori-Gfarm.c:297
#define NULL
Definition: iordef.h:70