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 #include "aiori.h"
16 
17 #if defined(HAVE_SYS_STATVFS_H)
18 #include <sys/statvfs.h>
19 #endif
20 
21 #if defined(HAVE_SYS_STATFS_H)
22 #include <sys/statfs.h>
23 #endif
24 
25 /*
26  * Bind the global "backend" pointer to the requested backend AIORI's
27  * function table.
28  */
29 
31 #ifdef USE_POSIX_AIORI
32  &posix_aiori,
33 #endif
34  & dummy_aiori,
35 #ifdef USE_HDF5_AIORI
36  &hdf5_aiori,
37 #endif
38 #ifdef USE_HDFS_AIORI
39  &hdfs_aiori,
40 #endif
41 #ifdef USE_IME_AIORI
42  &ime_aiori,
43 #endif
44 #ifdef USE_MPIIO_AIORI
45  &mpiio_aiori,
46 #endif
47 #ifdef USE_NCMPI_AIORI
48  &ncmpi_aiori,
49 #endif
50 #ifdef USE_MMAP_AIORI
51  &mmap_aiori,
52 #endif
53 #ifdef USE_S3_AIORI
54  &s3_aiori,
56  &s3_emc_aiori,
57 #endif
58 #ifdef USE_RADOS_AIORI
59  &rados_aiori,
60 #endif
61  NULL
62 };
63 
64 void airoi_parse_options(int argc, char ** argv, option_help * global_options){
65  int airoi_c = aiori_count();
66  options_all opt;
67  opt.module_count = airoi_c + 1;
68  opt.modules = malloc(sizeof(option_module) * (airoi_c + 1));
69  opt.modules[0].prefix = NULL;
70  opt.modules[0].options = global_options;
72  for (int i=1; *tmp != NULL; ++tmp, i++) {
73  opt.modules[i].prefix = (*tmp)->name;
74  if((*tmp)->get_options != NULL){
75  opt.modules[i].options = (*tmp)->get_options();
76  }else{
77  opt.modules[i].options = NULL;
78  }
79  }
80  option_parse(argc, argv, &opt);
81  free(opt.modules);
82 }
83 
84 void aiori_supported_apis(char * APIs){
86  if(*tmp != NULL){
87  APIs += sprintf(APIs, "%s", (*tmp)->name);
88  tmp++;
89  for (; *tmp != NULL; ++tmp) {
90  APIs += sprintf(APIs, "|%s", (*tmp)->name);
91  }
92  }
93 }
94 
104 int aiori_posix_statfs (const char *path, ior_aiori_statfs_t *stat_buf, IOR_param_t * param)
105 {
106  int ret;
107 #if defined(HAVE_STATVFS)
108  struct statvfs statfs_buf;
109 
110  ret = statvfs (path, &statfs_buf);
111 #else
112  struct statfs statfs_buf;
113 
114  ret = statfs (path, &statfs_buf);
115 #endif
116  if (-1 == ret) {
117  return -1;
118  }
119 
120  stat_buf->f_bsize = statfs_buf.f_bsize;
121  stat_buf->f_blocks = statfs_buf.f_blocks;
122  stat_buf->f_bfree = statfs_buf.f_bfree;
123  stat_buf->f_files = statfs_buf.f_files;
124  stat_buf->f_ffree = statfs_buf.f_ffree;
125 
126  return 0;
127 }
128 
129 int aiori_posix_mkdir (const char *path, mode_t mode, IOR_param_t * param)
130 {
131  return mkdir (path, mode);
132 }
133 
134 int aiori_posix_rmdir (const char *path, IOR_param_t * param)
135 {
136  return rmdir (path);
137 }
138 
139 int aiori_posix_access (const char *path, int mode, IOR_param_t * param)
140 {
141  return access (path, mode);
142 }
143 
144 int aiori_posix_stat (const char *path, struct stat *buf, IOR_param_t * param)
145 {
146  return stat (path, buf);
147 }
148 
150 {
151  return "";
152 }
153 
154 static int is_initialized = FALSE;
155 
157  if (is_initialized) return;
159 
160  /* Sanity check, we were compiled with SOME backend, right? */
161  if (0 == aiori_count ()) {
162  ERR("No IO backends compiled into aiori. "
163  "Run 'configure --with-<backend>', and recompile.");
164  }
165 
166  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
167  if((*tmp)->initialize){
168  (*tmp)->initialize();
169  }
170  }
171 }
172 
174  if (! is_initialized) return;
176 
177  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
178  if((*tmp)->finalize){
179  (*tmp)->finalize();
180  }
181  }
182 }
183 
184 const ior_aiori_t *aiori_select (const char *api)
185 {
186  char warn_str[256] = {0};
187  for (ior_aiori_t **tmp = available_aiori ; *tmp != NULL; ++tmp) {
188  if (NULL == api || strcasecmp(api, (*tmp)->name) == 0) {
189  if (NULL == (*tmp)->statfs) {
190  (*tmp)->statfs = aiori_posix_statfs;
191  snprintf(warn_str, 256, "assuming POSIX-based backend for"
192  " %s statfs call", api);
193  WARN(warn_str);
194  }
195  if (NULL == (*tmp)->mkdir) {
196  (*tmp)->mkdir = aiori_posix_mkdir;
197  snprintf(warn_str, 256, "assuming POSIX-based backend for"
198  " %s mkdir call", api);
199  WARN(warn_str);
200  }
201  if (NULL == (*tmp)->rmdir) {
202  (*tmp)->rmdir = aiori_posix_rmdir;
203  snprintf(warn_str, 256, "assuming POSIX-based backend for"
204  " %s rmdir call", api);
205  WARN(warn_str);
206  }
207  if (NULL == (*tmp)->access) {
208  (*tmp)->access = aiori_posix_access;
209  snprintf(warn_str, 256, "assuming POSIX-based backend for"
210  " %s access call", api);
211  WARN(warn_str);
212  }
213  if (NULL == (*tmp)->stat) {
214  (*tmp)->stat = aiori_posix_stat;
215  snprintf(warn_str, 256, "assuming POSIX-based backend for"
216  " %s stat call", api);
217  WARN(warn_str);
218  }
219  return *tmp;
220  }
221  }
222 
223  return NULL;
224 }
225 
226 int aiori_count (void)
227 {
228  return sizeof (available_aiori)/sizeof(available_aiori[0]) - 1;
229 }
230 
231 const char *aiori_default (void)
232 {
233  if (aiori_count () > 0) {
234  return available_aiori[0]->name;
235  }
236 
237  return NULL;
238 }
uint64_t f_blocks
Definition: aiori.h:58
uint64_t f_bfree
Definition: aiori.h:59
#define ERR(MSG)
Definition: iordef.h:169
ior_aiori_t mmap_aiori
Definition: aiori-MMAP.c:38
ior_aiori_t hdfs_aiori
Definition: aiori-HDFS.c:116
static int is_initialized
Definition: aiori.c:154
ior_aiori_t hdf5_aiori
Definition: aiori-HDF5.c:99
int aiori_posix_rmdir(const char *path, IOR_param_t *param)
Definition: aiori.c:134
ior_aiori_t posix_aiori
Definition: aiori-POSIX.c:77
ior_aiori_t s3_aiori
Definition: aiori-S3.c:168
option_module * modules
Definition: option.h:33
ior_aiori_t rados_aiori
Definition: aiori-RADOS.c:68
uint64_t f_ffree
Definition: aiori.h:62
int option_parse(int argc, char **argv, options_all *opt_all)
Definition: option.c:223
int aiori_posix_mkdir(const char *path, mode_t mode, IOR_param_t *param)
Definition: aiori.c:129
ior_aiori_t ncmpi_aiori
Definition: aiori-NCMPI.c:63
ior_aiori_t * available_aiori[]
Definition: aiori.c:30
int aiori_count(void)
Definition: aiori.c:226
void aiori_supported_apis(char *APIs)
Definition: aiori.c:84
ior_aiori_t s3_emc_aiori
Definition: aiori-S3.c:202
int aiori_posix_statfs(const char *path, ior_aiori_statfs_t *stat_buf, IOR_param_t *param)
Definition: aiori.c:104
ior_aiori_t dummy_aiori
Definition: aiori-DUMMY.c:137
const ior_aiori_t * aiori_select(const char *api)
Definition: aiori.c:184
int module_count
Definition: option.h:32
char * aiori_get_version()
Definition: aiori.c:149
uint64_t f_files
Definition: aiori.h:61
uint64_t f_bsize
Definition: aiori.h:57
static IOR_param_t param
Definition: mdtest.c:153
#define FALSE
Definition: iordef.h:71
#define WARN(MSG)
Definition: iordef.h:145
void aiori_finalize()
Definition: aiori.c:173
void aiori_initialize()
Definition: aiori.c:156
const char * aiori_default(void)
Definition: aiori.c:231
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:144
char * prefix
Definition: option.h:27
int(* statfs)(const char *, ior_aiori_statfs_t *, IOR_param_t *param)
Definition: aiori.h:77
int aiori_posix_access(const char *path, int mode, IOR_param_t *param)
Definition: aiori.c:139
char * name
Definition: aiori.h:67
ior_aiori_t ime_aiori
Definition: aiori-IME.c:64
#define TRUE
Definition: iordef.h:75
void airoi_parse_options(int argc, char **argv, option_help *global_options)
Definition: aiori.c:64
ior_aiori_t s3_plus_aiori
Definition: aiori-S3.c:185
#define NULL
Definition: iordef.h:79