Skip to content

Commit 24e6196

Browse files
committed
switch to struct of void (*fp)(void) within collfs internals
1 parent 6a45e08 commit 24e6196

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

collfs.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int collfs_fxstat64(int vers, int fd, struct stat64 *buf)
134134
if (link->fd == fd) {
135135
int rank,xerr = 0;
136136
err = MPI_Comm_rank(link->comm, &rank); if (err) return -1;
137-
if (!rank) xerr = unwrap.fxstat64(vers, fd, buf);
137+
if (!rank) xerr = ((collfs_fxstat64_fp) unwrap.fxstat64)(vers, fd, buf);
138138
#if DEBUG
139139
err = MPI_Bcast(&xerr, 1, MPI_INT, 0, link->comm);
140140
if (err < 0) {
@@ -151,7 +151,7 @@ static int collfs_fxstat64(int vers, int fd, struct stat64 *buf)
151151
} else return 0;
152152
}
153153
}
154-
return unwrap.fxstat64(vers, fd, buf);
154+
return ((collfs_fxstat64_fp) unwrap.fxstat64)(vers, fd, buf);
155155
}
156156

157157
/* Collective on the communicator at the top of the collfs stack */
@@ -161,7 +161,7 @@ static int collfs_xstat64(int vers, const char *file, struct stat64 *buf)
161161
if (CommStack) {
162162
int err,rank,xerr;
163163
err = MPI_Comm_rank(CommStack->comm, &rank); if (err) return -1;
164-
if (!rank) xerr = unwrap.xstat64(vers, file, buf);
164+
if (!rank) xerr = ((collfs_xstat64_fp) unwrap.xstat64)(vers, file, buf);
165165
#if DEBUG
166166
err = MPI_Bcast(&xerr, 1, MPI_INT, 0, CommStack->comm);
167167
if (err < 0) {
@@ -177,7 +177,7 @@ static int collfs_xstat64(int vers, const char *file, struct stat64 *buf)
177177
return -1;
178178
} else return 0;
179179
}
180-
return unwrap.xstat64(vers, file, buf);
180+
return ((collfs_xstat64_fp) unwrap.xstat64)(vers, file, buf);
181181
}
182182

183183
static int collfs_open(const char *pathname, int flags, mode_t mode)
@@ -188,7 +188,7 @@ static int collfs_open(const char *pathname, int flags, mode_t mode)
188188
// pass through to libc __open if no communicator has been pushed
189189
if (!CommStack) {
190190
debug_printf(2, "%s(\"%s\", x%x, o%o) independent", __func__, pathname, flags, mode);
191-
return unwrap.open(pathname, flags, mode);
191+
return ((collfs_open_fp) unwrap.open)(pathname, flags, mode);
192192
}
193193

194194
err = MPI_Comm_rank(CommStack->comm, &rank);
@@ -205,18 +205,18 @@ static int collfs_open(const char *pathname, int flags, mode_t mode)
205205
debug_printf(2, "%s(\"%s\", x%x, o%o) collective", __func__, pathname, flags, mode);
206206
if (!rank) {
207207
len = -1;
208-
fd = unwrap.open(pathname, flags, mode);
208+
fd = ((collfs_open_fp) unwrap.open)(pathname, flags, mode);
209209
if (fd >= 0) {
210210
struct stat fdst;
211-
if (fstat(fd, &fdst) < 0) unwrap.close(fd); /* fail cleanly */
211+
if (fstat(fd, &fdst) < 0) ((collfs_close_fp) unwrap.close)(fd); /* fail cleanly */
212212
else len = (int)fdst.st_size; /* Cast prevents using large files, but MPI would need workarounds too */
213213
}
214214
}
215215
err = MPI_Bcast(&len, 1,MPI_INT, 0, CommStack->comm); if (err) return -1;
216216
if (len < 0) return -1;
217217
mem = NULL;
218218
if (!rank) {
219-
mem = unwrap.mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
219+
mem = ((collfs_mmap_fp) unwrap.mmap)(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
220220
} else {
221221
/* Don't use shm_open() here because the shared memory segment is fixed at boot time. */
222222
fd = NextFD++;
@@ -229,7 +229,7 @@ static int collfs_open(const char *pathname, int flags, mode_t mode)
229229
err = MPI_Allreduce(MPI_IN_PLACE, &gotmem, 1, MPI_INT, MPI_LAND, CommStack->comm);
230230
if (!gotmem) {
231231
if (!rank) {
232-
if (mem) unwrap.munmap(mem, len);
232+
if (mem) ((collfs_munmap_fp) unwrap.munmap)(mem, len);
233233
} else free(mem);
234234
set_error(ECOLLFS, "Could not find memory: mmap() on rank 0, malloc otherwise");
235235
return -1;
@@ -256,7 +256,7 @@ static int collfs_open(const char *pathname, int flags, mode_t mode)
256256
}
257257
/* more than read access needed, fall back to independent access */
258258
debug_printf(2, "%s(\"%s\", x%x, o%o)", __func__, pathname, flags, mode);
259-
return unwrap.open(pathname, flags, mode);
259+
return ((collfs_open_fp) unwrap.open)(pathname, flags, mode);
260260
}
261261

262262
/* Collective on the communicator used when the fd was created */
@@ -275,8 +275,8 @@ static int collfs_close(int fd)
275275
if (--link->refct > 0) return 0;
276276
err = MPI_Comm_rank(CommStack ? CommStack->comm : MPI_COMM_WORLD, &rank); if (err) return -1;
277277
if (!rank) {
278-
unwrap.munmap(link->mem, link->len);
279-
xerr = unwrap.close(fd);
278+
((collfs_munmap_fp) unwrap.munmap)(link->mem, link->len);
279+
xerr = ((collfs_close_fp) unwrap.close)(fd);
280280
} else {
281281
free(link->mem);
282282
}
@@ -286,7 +286,7 @@ static int collfs_close(int fd)
286286
}
287287
}
288288
debug_printf(2, "%s(%d) independent", __func__, fd);
289-
return unwrap.close(fd);
289+
return ((collfs_close_fp) unwrap.close)(fd);
290290
}
291291

292292
/* Collective on the communicator used when the fd was created */
@@ -301,7 +301,7 @@ static ssize_t collfs_read(int fd, void *buf, size_t count)
301301
if (initialized) {err = MPI_Comm_rank(link->comm, &rank); if (err) return -1;}
302302
if (fd == link->fd) {
303303
debug_printf(2, "%s(%d, %p, %zu) collective", __func__, fd, buf, count);
304-
if (!rank) return unwrap.read(fd, buf, count);
304+
if (!rank) return ((collfs_read_fp) unwrap.read)(fd, buf, count);
305305
else {
306306
if ((link->len - link->offset) < count) count = link->len - link->offset;
307307
memcpy(buf, link->mem+link->offset, count);
@@ -311,7 +311,7 @@ static ssize_t collfs_read(int fd, void *buf, size_t count)
311311
}
312312
}
313313
debug_printf(2, "%s(%d, %p, %zu) independent", __func__, fd, buf, count);
314-
return unwrap.read(fd, buf, count);
314+
return ((collfs_read_fp) unwrap.read)(fd, buf, count);
315315
}
316316

317317
static off_t collfs_lseek(int fildes, off_t offset, int whence)
@@ -323,7 +323,7 @@ static off_t collfs_lseek(int fildes, off_t offset, int whence)
323323
int rank = 0;
324324
MPI_Comm_rank(link->comm,&rank);
325325
debug_printf(2, "%s(%d, %lld, %d) collective", __func__, fildes, (long long)offset, whence);
326-
if (!rank) return unwrap.lseek(fildes, offset, whence); /* Rank 0 has a normal fd */
326+
if (!rank) return ((collfs_lseek_fp) unwrap.lseek)(fildes, offset, whence); /* Rank 0 has a normal fd */
327327
switch (whence) {
328328
case SEEK_SET:
329329
link->offset = offset;
@@ -339,7 +339,7 @@ static off_t collfs_lseek(int fildes, off_t offset, int whence)
339339
}
340340
}
341341
debug_printf(2, "%s(%d, %lld, %d) independent", __func__, fildes, (long long)offset, whence);
342-
return unwrap.lseek(fildes, offset, whence);
342+
return ((collfs_lseek_fp) unwrap.lseek)(fildes, offset, whence);
343343
}
344344

345345
/* Collective on the communicator used when fildes was created */
@@ -383,7 +383,7 @@ static void *collfs_mmap(void *addr, size_t len, int prot, int flags, int fildes
383383
}
384384
}
385385
debug_printf(2, "%s(%p, %zu, %d, %d, %d, %lld) independent", __func__, addr, len, prot, flags, fildes, (long long)off);
386-
return unwrap.mmap(addr, len, prot, flags, fildes, off);
386+
return ((collfs_mmap_fp) unwrap.mmap)(addr, len, prot, flags, fildes, off);
387387
}
388388

389389
/* This implementation is not actually collective, but it relies on the fd being opened collectively */
@@ -406,7 +406,7 @@ static int collfs_munmap(__ptr_t addr, size_t len)
406406
set_error(EINVAL, "Address not mapped: %p", addr);
407407
}
408408
debug_printf(2, "%s(%p, %zu) independent", __func__, addr, len);
409-
return unwrap.munmap(addr, len);
409+
return ((collfs_munmap_fp) unwrap.munmap)(addr, len);
410410
}
411411

412412

@@ -427,14 +427,16 @@ int collfs_initialize(int level, void (*errhandler)(void))
427427
return -1;
428428
}
429429

430-
api.fxstat64 = collfs_fxstat64;
431-
api.xstat64 = collfs_xstat64;
432-
api.open = collfs_open;
433-
api.close = collfs_close;
434-
api.read = collfs_read;
435-
api.lseek = collfs_lseek;
436-
api.mmap = collfs_mmap;
437-
api.munmap = collfs_munmap;
430+
typedef void (*void_fp)(void);
431+
432+
api.fxstat64 = (void_fp) collfs_fxstat64;
433+
api.xstat64 = (void_fp) collfs_xstat64;
434+
api.open = (void_fp) collfs_open;
435+
api.close = (void_fp) collfs_close;
436+
api.read = (void_fp) collfs_read;
437+
api.lseek = (void_fp) collfs_lseek;
438+
api.mmap = (void_fp) collfs_mmap;
439+
api.munmap = (void_fp) collfs_munmap;
438440

439441
/* Make API visible to libc-rtld (ld.so) */
440442
memcpy(&_dl_collfs_api, &api, sizeof(api));

libc-collfs.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ typedef void *(*collfs_mmap_fp)(void *addr, size_t len, int prot, int flags, int
2121
typedef int (*collfs_munmap_fp)(__ptr_t addr, size_t len);
2222

2323
struct libc_collfs_api {
24-
collfs_fxstat64_fp fxstat64;
25-
collfs_xstat64_fp xstat64;
26-
collfs_open_fp open;
27-
collfs_close_fp close;
28-
collfs_read_fp read;
29-
collfs_lseek_fp lseek;
30-
collfs_mmap_fp mmap;
31-
collfs_munmap_fp munmap;
24+
void (*fxstat64)(void);
25+
void (*xstat64)(void);
26+
void (*open)(void);
27+
void (*close)(void);
28+
void (*read)(void);
29+
void (*lseek)(void);
30+
void (*mmap)(void);
31+
void (*munmap)(void);
3232
};
3333

34+
3435
#endif

0 commit comments

Comments
 (0)