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