IOR
aiori-Gfarm.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <sys/types.h>
4 #include <errno.h>
5 #include <gfarm/gfarm.h>
6 #undef PACKAGE_NAME
7 #undef PACKAGE_STRING
8 #undef PACKAGE_TARNAME
9 #undef PACKAGE_VERSION
10 #include "ior.h"
11 #include "aiori.h"
12 
13 struct gfarm_file {
14  GFS_File gf;
15 };
16 
17 void
19 {
20  gfarm_initialize(NULL, NULL);
21 }
22 
23 void
25 {
26  gfarm_terminate();
27 }
28 
29 void *
31 {
32  GFS_File gf;
33  struct gfarm_file *fp;
34  gfarm_error_t e;
35 
36  if (param->dryRun)
37  return (NULL);
38 
39  e = gfs_pio_create(fn, GFARM_FILE_RDWR, 0664, &gf);
40  if (e != GFARM_ERR_NO_ERROR)
41  ERR("gfs_pio_create failed");
42  GFARM_MALLOC(fp);
43  if (fp == NULL)
44  ERR("no memory");
45  fp->gf = gf;
46  return (fp);
47 }
48 
49 void *
51 {
52  GFS_File gf;
53  struct gfarm_file *fp;
54  gfarm_error_t e;
55 
56  if (param->dryRun)
57  return (NULL);
58 
59  e = gfs_pio_open(fn, GFARM_FILE_RDWR, &gf);
60  if (e != GFARM_ERR_NO_ERROR)
61  ERR("gfs_pio_open failed");
62  GFARM_MALLOC(fp);
63  if (fp == NULL)
64  ERR("no memory");
65  fp->gf = gf;
66  return (fp);
67 }
68 
70 Gfarm_xfer(int access, void *fd, IOR_size_t *buffer, IOR_offset_t len,
72 {
73  struct gfarm_file *fp = fd;
74  IOR_offset_t rem = len;
75  gfarm_off_t off;
76  gfarm_error_t e;
77 #define MAX_SZ (1024 * 1024 * 1024)
78  int sz, n;
79  char *buf = (char *)buffer;
80 
81  if (param->dryRun)
82  return (len);
83 
84  if (len > MAX_SZ)
85  sz = MAX_SZ;
86  else
87  sz = len;
88 
89  e = gfs_pio_seek(fp->gf, param->offset, GFARM_SEEK_SET, &off);
90  if (e != GFARM_ERR_NO_ERROR)
91  ERR("gfs_pio_seek failed");
92  while (rem > 0) {
93  if (access == WRITE)
94  e = gfs_pio_write(fp->gf, buf, sz, &n);
95  else
96  e = gfs_pio_read(fp->gf, buf, sz, &n);
97  if (e != GFARM_ERR_NO_ERROR)
98  ERR("xfer failed");
99  if (n == 0)
100  ERR("EOF encountered");
101  rem -= n;
102  buf += n;
103  }
104  return (len);
105 }
106 
107 void
109 {
110  struct gfarm_file *fp = fd;
111 
112  if (param->dryRun)
113  return;
114 
115  if (gfs_pio_close(fp->gf) != GFARM_ERR_NO_ERROR)
116  ERR("gfs_pio_close failed");
117  free(fp);
118 }
119 
120 void
122 {
123  gfarm_error_t e;
124 
125  if (param->dryRun)
126  return;
127 
128  e = gfs_unlink(fn);
129  if (e != GFARM_ERR_NO_ERROR)
130  errno = gfarm_error_to_errno(e);
131 }
132 
133 char *
135 {
136  return ((char *)gfarm_version());
137 }
138 
139 void
141 {
142  struct gfarm_file *fp = fd;
143 
144  if (param->dryRun)
145  return;
146 
147  if (gfs_pio_sync(fp->gf) != GFARM_ERR_NO_ERROR)
148  ERR("gfs_pio_sync failed");
149 }
150 
152 Gfarm_get_file_size(IOR_param_t *param, MPI_Comm comm, char *fn)
153 {
154  struct gfs_stat st;
155  IOR_offset_t size, sum, min, max;
156 
157  if (param->dryRun)
158  return (0);
159 
160  if (gfs_stat(fn, &st) != GFARM_ERR_NO_ERROR)
161  ERR("gfs_stat failed");
162  size = st.st_size;
163  gfs_stat_free(&st);
164 
165  if (param->filePerProc == TRUE) {
166  MPI_CHECK(MPI_Allreduce(&size, &sum, 1, MPI_LONG_LONG_INT,
167  MPI_SUM, comm), "cannot total data moved");
168  size = sum;
169  } else {
170  MPI_CHECK(MPI_Allreduce(&size, &min, 1, MPI_LONG_LONG_INT,
171  MPI_MIN, comm), "cannot total data moved");
172  MPI_CHECK(MPI_Allreduce(&size, &max, 1, MPI_LONG_LONG_INT,
173  MPI_MAX, comm), "cannot total data moved");
174  if (min != max) {
175  if (rank == 0)
176  WARN("inconsistent file size by different "
177  "tasks");
178  /* incorrect, but now consistent across tasks */
179  size = min;
180  }
181  }
182  return (size);
183 }
184 
185 int
187 {
188  gfarm_off_t used, avail, files;
189  gfarm_error_t e;
190  int bsize = 4096;
191 
192  if (param->dryRun)
193  return (0);
194 
195  e = gfs_statfs_by_path(fn, &used, &avail, &files);
196  if (e != GFARM_ERR_NO_ERROR) {
197  errno = gfarm_error_to_errno(e);
198  return (-1);
199  }
200  st->f_bsize = bsize;
201  st->f_blocks = (used + avail) / bsize;
202  st->f_bfree = avail / bsize;
203  st->f_files = 2 * files; /* XXX */
204  st->f_ffree = files; /* XXX */
205  return (0);
206 }
207 
208 int
209 Gfarm_mkdir(const char *fn, mode_t mode, IOR_param_t *param)
210 {
211  gfarm_error_t e;
212 
213  if (param->dryRun)
214  return (0);
215 
216  e = gfs_mkdir(fn, mode);
217  if (e == GFARM_ERR_NO_ERROR)
218  return (0);
219  errno = gfarm_error_to_errno(e);
220  return (-1);
221 }
222 
223 int
224 Gfarm_rmdir(const char *fn, IOR_param_t *param)
225 {
226  gfarm_error_t e;
227 
228  if (param->dryRun)
229  return (0);
230 
231  e = gfs_rmdir(fn);
232  if (e == GFARM_ERR_NO_ERROR)
233  return (0);
234  errno = gfarm_error_to_errno(e);
235  return (-1);
236 }
237 
238 int
239 Gfarm_access(const char *fn, int mode, IOR_param_t *param)
240 {
241  struct gfs_stat st;
242  gfarm_error_t e;
243 
244  if (param->dryRun)
245  return (0);
246 
247  e = gfs_stat(fn, &st);
248  if (e != GFARM_ERR_NO_ERROR) {
249  errno = gfarm_error_to_errno(e);
250  return (-1);
251  }
252  gfs_stat_free(&st);
253  return (0);
254 }
255 
256 /* XXX FIXME */
257 #define GFS_DEV ((dev_t)-1)
258 #define GFS_BLKSIZE 8192
259 #define STAT_BLKSIZ 512 /* for st_blocks */
260 
261 int
262 Gfarm_stat(const char *fn, struct stat *buf, IOR_param_t *param)
263 {
264  struct gfs_stat st;
265  gfarm_error_t e;
266 
267  if (param->dryRun)
268  return (0);
269 
270  e = gfs_stat(fn, &st);
271  if (e != GFARM_ERR_NO_ERROR) {
272  errno = gfarm_error_to_errno(e);
273  return (-1);
274  }
275  buf->st_dev = GFS_DEV;
276  buf->st_ino = st.st_ino;
277  buf->st_mode = st.st_mode;
278  buf->st_nlink = st.st_nlink;
279  buf->st_uid = getuid(); /* XXX */
280  buf->st_gid = getgid(); /* XXX */
281  buf->st_size = st.st_size;
282  buf->st_blksize = GFS_BLKSIZE;
283  buf->st_blocks = (st.st_size + STAT_BLKSIZ - 1) / STAT_BLKSIZ;
284  buf->st_atime = st.st_atimespec.tv_sec;
285  buf->st_mtime = st.st_mtimespec.tv_sec;
286  buf->st_ctime = st.st_ctimespec.tv_sec;
287 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
288  buf->st_atim.tv_nsec = st.st_atimespec.tv_nsec;
289  buf->st_mtim.tv_nsec = st.st_mtimespec.tv_nsec;
290  buf->st_ctim.tv_nsec = st.st_ctimespec.tv_nsec;
291 #endif
292  gfs_stat_free(&st);
293  return (0);
294 }
295 
297  .name = "Gfarm",
298  .name_legacy = NULL,
299  .create = Gfarm_create,
300  .open = Gfarm_open,
301  .xfer = Gfarm_xfer,
302  .close = Gfarm_close,
303  .delete = Gfarm_delete,
304  .get_version = Gfarm_version,
305  .fsync = Gfarm_fsync,
306  .get_file_size = Gfarm_get_file_size,
307  .statfs = Gfarm_statfs,
308  .mkdir = Gfarm_mkdir,
309  .rmdir = Gfarm_rmdir,
310  .access = Gfarm_access,
311  .stat = Gfarm_stat,
312  .initialize = Gfarm_initialize,
313  .finalize = Gfarm_finalize,
314  .get_options = NULL,
315  .enable_mdtest = true,
316 };
void Gfarm_initialize()
Definition: aiori-Gfarm.c:18
uint64_t f_blocks
Definition: aiori.h:59
void * Gfarm_open(char *fn, IOR_param_t *param)
Definition: aiori-Gfarm.c:50
uint64_t f_bfree
Definition: aiori.h:60
#define ERR(MSG)
Definition: iordef.h:184
void Gfarm_fsync(void *fd, IOR_param_t *param)
Definition: aiori-Gfarm.c:140
int filePerProc
Definition: ior.h:111
static int size
Definition: mdtest.c:91
#define GFS_BLKSIZE
Definition: aiori-Gfarm.c:258
void Gfarm_delete(char *fn, IOR_param_t *param)
Definition: aiori-Gfarm.c:121
#define MAX_SZ
void * Gfarm_create(char *fn, IOR_param_t *param)
Definition: aiori-Gfarm.c:30
GFS_File gf
Definition: aiori-Gfarm.c:14
uint64_t f_ffree
Definition: aiori.h:63
IOR_offset_t Gfarm_get_file_size(IOR_param_t *param, MPI_Comm comm, char *fn)
Definition: aiori-Gfarm.c:152
#define WRITE
Definition: iordef.h:95
int Gfarm_statfs(const char *fn, ior_aiori_statfs_t *st, IOR_param_t *param)
Definition: aiori-Gfarm.c:186
void Gfarm_finalize()
Definition: aiori-Gfarm.c:24
uint64_t f_files
Definition: aiori.h:62
uint64_t f_bsize
Definition: aiori.h:58
#define MPI_CHECK(MPI_STATUS, MSG)
Definition: iordef.h:224
int dryRun
Definition: ior.h:98
IOR_offset_t Gfarm_xfer(int access, void *fd, IOR_size_t *buffer, IOR_offset_t len, IOR_param_t *param)
Definition: aiori-Gfarm.c:70
int Gfarm_mkdir(const char *fn, mode_t mode, IOR_param_t *param)
Definition: aiori-Gfarm.c:209
static IOR_param_t param
Definition: mdtest.c:170
void Gfarm_close(void *fd, IOR_param_t *param)
Definition: aiori-Gfarm.c:108
long long int IOR_size_t
Definition: iordef.h:123
#define WARN(MSG)
Definition: iordef.h:144
char * Gfarm_version()
Definition: aiori-Gfarm.c:134
int Gfarm_rmdir(const char *fn, IOR_param_t *param)
Definition: aiori-Gfarm.c:224
IOR_offset_t offset
Definition: ior.h:126
#define GFS_DEV
Definition: aiori-Gfarm.c:257
int errno
int Gfarm_access(const char *fn, int mode, IOR_param_t *param)
Definition: aiori-Gfarm.c:239
char * name
Definition: aiori.h:68
int Gfarm_stat(const char *fn, struct stat *buf, IOR_param_t *param)
Definition: aiori-Gfarm.c:262
long long int IOR_offset_t
Definition: iordef.h:122
int rank
Definition: utilities.c:57
#define TRUE
Definition: iordef.h:75
ior_aiori_t gfarm_aiori
Definition: aiori-Gfarm.c:296
#define STAT_BLKSIZ
Definition: aiori-Gfarm.c:259
#define NULL
Definition: iordef.h:79