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 #ifdef USE_CHFS_AIORI
91  &chfs_aiori,
92 #endif
93  NULL
94 };
95 
97  if (backend->get_options == NULL)
98  return NULL;
99  char * name = backend->name;
101  for (int i=1; *tmp != NULL; ++tmp, i++) {
102  if (strcmp(opt->modules[i].prefix, name) == 0){
103  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, opt->modules[i].defaults);
104  return opt->modules[i].defaults;
105  }
106  }
107  return NULL;
108 }
109 
111  if(! out_logfile) out_logfile = stdout;
112  int airoi_c = aiori_count();
113  options_all_t * opt = malloc(sizeof(options_all_t));
114  opt->module_count = airoi_c + 1;
115  opt->modules = malloc(sizeof(option_module) * (airoi_c + 1));
116  opt->modules[0].prefix = NULL;
117  opt->modules[0].options = global_options;
119  for (int i=1; *tmp != NULL; ++tmp, i++) {
120  opt->modules[i].prefix = (*tmp)->name;
121  if((*tmp)->get_options != NULL){
122  opt->modules[i].options = (*tmp)->get_options(& opt->modules[i].defaults, NULL);
123  }else{
124  opt->modules[i].options = NULL;
125  }
126  }
127  return opt;
128 }
129 
130 void aiori_supported_apis(char * APIs, char * APIs_legacy, enum bench_type type)
131 {
133  char delimiter = ' ';
134  *APIs = 0;
135  *APIs_legacy = 0;
136 
137  while (*tmp != NULL)
138  {
139  if ((type == MDTEST) && !(*tmp)->enable_mdtest)
140  {
141  tmp++;
142  continue;
143  }
144  if (delimiter == ' ')
145  {
146  APIs += sprintf(APIs, "%s", (*tmp)->name);
147  delimiter = '|';
148  }
149  else
150  APIs += sprintf(APIs, "%c%s", delimiter, (*tmp)->name);
151 
152  if ((*tmp)->name_legacy != NULL)
153  APIs_legacy += sprintf(APIs_legacy, "%c%s",
154  delimiter, (*tmp)->name_legacy);
155 
156  tmp++;
157  }
158 }
159 
169 int aiori_posix_statfs (const char *path, ior_aiori_statfs_t *stat_buf, aiori_mod_opt_t * module_options)
170 {
171  // find the parent directory
172  char * fileName = strdup(path);
173  int i;
174  int directoryFound = FALSE;
175 
176  /* get directory for outfile */
177  i = strlen(fileName);
178  while (i-- > 0) {
179  if (fileName[i] == '/') {
180  fileName[i] = '\0';
181  directoryFound = TRUE;
182  break;
183  }
184  }
185  /* if no directory/, use '.' */
186  if (directoryFound == FALSE) {
187  strcpy(fileName, ".");
188  }
189 
190  int ret;
191 #if defined(HAVE_STATVFS)
192  struct statvfs statfs_buf;
193 
194  ret = statvfs (fileName, &statfs_buf);
195 #else
196  struct statfs statfs_buf;
197 
198  ret = statfs (fileName, &statfs_buf);
199 #endif
200  if (-1 == ret) {
201  perror("POSIX couldn't call statvfs");
202  return -1;
203  }
204 
205  stat_buf->f_bsize = statfs_buf.f_bsize;
206  stat_buf->f_blocks = statfs_buf.f_blocks;
207  stat_buf->f_bfree = statfs_buf.f_bfree;
208  stat_buf->f_files = statfs_buf.f_files;
209  stat_buf->f_ffree = statfs_buf.f_ffree;
210 
211  free(fileName);
212  return 0;
213 }
214 
215 int aiori_posix_mkdir (const char *path, mode_t mode, aiori_mod_opt_t * module_options)
216 {
217  return mkdir (path, mode);
218 }
219 
220 int aiori_posix_rmdir (const char *path, aiori_mod_opt_t * module_options)
221 {
222  return rmdir (path);
223 }
224 
225 int aiori_posix_access (const char *path, int mode, aiori_mod_opt_t * module_options)
226 {
227  return access (path, mode);
228 }
229 
230 int aiori_posix_stat (const char *path, struct stat *buf, aiori_mod_opt_t * module_options)
231 {
232  return stat (path, buf);
233 }
234 
236 {
237  return "";
238 }
239 
240 const ior_aiori_t *aiori_select (const char *api)
241 {
242  char warn_str[256] = {0};
243  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
244  char *name_leg = (*tmp)->name_legacy;
245  if (NULL != api &&
246  (strcasecmp(api, (*tmp)->name) != 0) &&
247  (name_leg == NULL || strcasecmp(api, name_leg) != 0))
248  continue;
249 
250  if (name_leg != NULL && strcasecmp(api, name_leg) == 0)
251  {
252  snprintf(warn_str, 256, "%s backend is deprecated use %s"
253  " instead", api, (*tmp)->name);
254  WARN(warn_str);
255  }
256 
257  if (NULL == (*tmp)->statfs) {
258  (*tmp)->statfs = aiori_posix_statfs;
259  snprintf(warn_str, 256, "assuming POSIX-based backend for"
260  " %s statfs call", api);
261  WARN(warn_str);
262  }
263  if (NULL == (*tmp)->mkdir) {
264  (*tmp)->mkdir = aiori_posix_mkdir;
265  snprintf(warn_str, 256, "assuming POSIX-based backend for"
266  " %s mkdir call", api);
267  WARN(warn_str);
268  }
269  if (NULL == (*tmp)->rmdir) {
270  (*tmp)->rmdir = aiori_posix_rmdir;
271  snprintf(warn_str, 256, "assuming POSIX-based backend for"
272  " %s rmdir call", api);
273  WARN(warn_str);
274  }
275  if (NULL == (*tmp)->access) {
276  (*tmp)->access = aiori_posix_access;
277  snprintf(warn_str, 256, "assuming POSIX-based backend for"
278  " %s access call", api);
279  WARN(warn_str);
280  }
281  if (NULL == (*tmp)->stat) {
282  (*tmp)->stat = aiori_posix_stat;
283  snprintf(warn_str, 256, "assuming POSIX-based backend for"
284  " %s stat call", api);
285  WARN(warn_str);
286  }
287 
288  return *tmp;
289  }
290 
291  return NULL;
292 }
293 
294 int aiori_count (void)
295 {
296  return sizeof (available_aiori)/sizeof(available_aiori[0]) - 1;
297 }
298 
299 const char *aiori_default (void)
300 {
301  if (aiori_count () > 0) {
302  return available_aiori[0]->name;
303  }
304 
305  return NULL;
306 }
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:96
FILE * out_logfile
Definition: utilities.c:74
bench_type
Definition: aiori.h:118
ior_aiori_t hdfs_aiori
Definition: aiori-HDFS.c:127
ior_aiori_t hdf5_aiori
Definition: aiori-HDF5.c:153
ior_aiori_t cephfs_aiori
Definition: aiori-CEPHFS.c:93
aiori_mod_opt_t * defaults
Definition: option.h:31
ior_aiori_t posix_aiori
Definition: aiori-POSIX.c:171
ior_aiori_t rados_aiori
Definition: aiori-RADOS.c:90
uint64_t f_ffree
Definition: aiori.h:57
ior_aiori_t ncmpi_aiori
Definition: aiori-NCMPI.c:103
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:294
int aiori_posix_stat(const char *path, struct stat *buf, aiori_mod_opt_t *module_options)
Definition: aiori.c:230
ior_aiori_t dummy_aiori
Definition: aiori-DUMMY.c:201
const ior_aiori_t * aiori_select(const char *api)
Definition: aiori.c:240
char * aiori_get_version()
Definition: aiori.c:235
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
ior_aiori_t chfs_aiori
Definition: aiori-CHFS.c:229
#define WARN(MSG)
Definition: aiori-debug.h:45
char * name_legacy
Definition: aiori.h:89
options_all_t * airoi_create_all_module_options(option_help *global_options)
Definition: aiori.c:110
void aiori_supported_apis(char *APIs, char *APIs_legacy, enum bench_type type)
Definition: aiori.c:130
static const ior_aiori_t * backend
Definition: ior.c:61
int aiori_posix_access(const char *path, int mode, aiori_mod_opt_t *module_options)
Definition: aiori.c:225
#define FALSE
Definition: iordef.h:76
ior_aiori_t dfs_aiori
Definition: aiori-DFS.c:134
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:220
const char * aiori_default(void)
Definition: aiori.c:299
int aiori_posix_mkdir(const char *path, mode_t mode, aiori_mod_opt_t *module_options)
Definition: aiori.c:215
ior_aiori_t mpiio_aiori
Definition: aiori-MPIIO.c:78
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:169
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:80
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:84