2012-01-09 00:51:04 +04:00
|
|
|
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
|
|
|
|
* vim:expandtab:shiftwidth=8:tabstop=8:
|
|
|
|
*/
|
2011-06-17 23:20:43 +04:00
|
|
|
/******************************************************************************\
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2003, The Regents of the University of California *
|
|
|
|
* See the file COPYRIGHT for a complete copyright notice and license. *
|
|
|
|
* *
|
|
|
|
********************************************************************************
|
|
|
|
*
|
2011-10-28 01:12:26 +04:00
|
|
|
* Implement of abstract I/O interface for POSIX.
|
2011-06-17 23:20:43 +04:00
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2011-11-12 04:40:45 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-09-18 21:20:37 +04:00
|
|
|
# include "config.h"
|
2011-11-12 04:40:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-09-18 21:20:37 +04:00
|
|
|
|
2011-06-17 23:20:43 +04:00
|
|
|
#ifdef __linux__
|
2014-09-18 21:20:37 +04:00
|
|
|
# include <sys/ioctl.h> /* necessary for: */
|
|
|
|
# define __USE_GNU /* O_DIRECT and */
|
|
|
|
# include <fcntl.h> /* IO operations */
|
|
|
|
# undef __USE_GNU
|
2011-11-12 02:22:17 +04:00
|
|
|
#endif /* __linux__ */
|
2014-09-18 21:20:37 +04:00
|
|
|
|
2011-11-12 04:40:45 +04:00
|
|
|
#include <errno.h>
|
2011-11-12 02:22:17 +04:00
|
|
|
#include <fcntl.h> /* IO operations */
|
2011-06-17 23:20:43 +04:00
|
|
|
#include <sys/stat.h>
|
2011-11-11 07:01:34 +04:00
|
|
|
#include <assert.h>
|
2014-09-18 21:20:37 +04:00
|
|
|
|
2011-11-10 02:14:14 +04:00
|
|
|
#ifdef HAVE_LUSTRE_LUSTRE_USER_H
|
2014-09-18 21:20:37 +04:00
|
|
|
# include <lustre/lustre_user.h>
|
2011-11-12 04:40:45 +04:00
|
|
|
#endif
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_H
|
2014-09-18 21:20:37 +04:00
|
|
|
# include <gpfs.h>
|
2013-09-26 17:48:50 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
2014-09-18 21:20:37 +04:00
|
|
|
# include <gpfs_fcntl.h>
|
2013-09-26 17:48:50 +04:00
|
|
|
#endif
|
|
|
|
|
2017-09-21 18:12:31 +03:00
|
|
|
#ifdef HAVE_BEEGFS_BEEGFS_H
|
|
|
|
#include <beegfs/beegfs.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-12 04:40:45 +04:00
|
|
|
#include "ior.h"
|
|
|
|
#include "aiori.h"
|
|
|
|
#include "iordef.h"
|
2014-09-18 21:20:37 +04:00
|
|
|
#include "utilities.h"
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
#ifndef open64 /* necessary for TRU64 -- */
|
2014-09-18 21:20:37 +04:00
|
|
|
# define open64 open /* unlikely, but may pose */
|
2011-11-12 02:22:17 +04:00
|
|
|
#endif /* not open64 */ /* conflicting prototypes */
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
#ifndef lseek64 /* necessary for TRU64 -- */
|
2014-09-18 21:20:37 +04:00
|
|
|
# define lseek64 lseek /* unlikely, but may pose */
|
2011-11-12 02:22:17 +04:00
|
|
|
#endif /* not lseek64 */ /* conflicting prototypes */
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
#ifndef O_BINARY /* Required on Windows */
|
2014-09-18 21:20:37 +04:00
|
|
|
# define O_BINARY 0
|
2011-06-17 23:20:43 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**************************** P R O T O T Y P E S *****************************/
|
2011-11-12 04:40:45 +04:00
|
|
|
static IOR_offset_t POSIX_Xfer(int, void *, IOR_size_t *,
|
|
|
|
IOR_offset_t, IOR_param_t *);
|
|
|
|
static void POSIX_Fsync(void *, IOR_param_t *);
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/************************** D E C L A R A T I O N S ***************************/
|
|
|
|
|
2011-10-28 03:50:05 +04:00
|
|
|
ior_aiori_t posix_aiori = {
|
2017-10-20 00:26:52 +03:00
|
|
|
.name = "POSIX",
|
|
|
|
.create = POSIX_Create,
|
|
|
|
.open = POSIX_Open,
|
|
|
|
.xfer = POSIX_Xfer,
|
|
|
|
.close = POSIX_Close,
|
|
|
|
.delete = POSIX_Delete,
|
2018-07-14 10:41:35 +03:00
|
|
|
.get_version = aiori_get_version,
|
2017-10-20 00:26:52 +03:00
|
|
|
.fsync = POSIX_Fsync,
|
|
|
|
.get_file_size = POSIX_GetFileSize,
|
2018-04-26 01:34:25 +03:00
|
|
|
.statfs = aiori_posix_statfs,
|
|
|
|
.mkdir = aiori_posix_mkdir,
|
|
|
|
.rmdir = aiori_posix_rmdir,
|
|
|
|
.access = aiori_posix_access,
|
|
|
|
.stat = aiori_posix_stat,
|
2011-10-28 03:50:05 +04:00
|
|
|
};
|
|
|
|
|
2011-06-17 23:20:43 +04:00
|
|
|
/***************************** F U N C T I O N S ******************************/
|
|
|
|
|
2011-11-11 07:02:19 +04:00
|
|
|
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
|
|
|
void gpfs_free_all_locks(int fd)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct {
|
|
|
|
gpfsFcntlHeader_t header;
|
|
|
|
gpfsFreeRange_t release;
|
|
|
|
} release_all;
|
|
|
|
release_all.header.totalLength = sizeof(release_all);
|
|
|
|
release_all.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
|
|
|
|
release_all.header.fcntlReserved = 0;
|
|
|
|
|
|
|
|
release_all.release.structLen = sizeof(release_all.release);
|
|
|
|
release_all.release.structType = GPFS_FREE_RANGE;
|
|
|
|
release_all.release.start = 0;
|
|
|
|
release_all.release.length = 0;
|
|
|
|
|
|
|
|
rc = gpfs_fcntl(fd, &release_all);
|
|
|
|
if (verbose >= VERBOSE_0 && rc != 0) {
|
|
|
|
EWARN("gpfs_fcntl release all locks hint failed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void gpfs_access_start(int fd, IOR_offset_t length, IOR_param_t *param, int access)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct {
|
|
|
|
gpfsFcntlHeader_t header;
|
|
|
|
gpfsAccessRange_t access;
|
|
|
|
} take_locks;
|
|
|
|
|
|
|
|
take_locks.header.totalLength = sizeof(take_locks);
|
|
|
|
take_locks.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
|
|
|
|
take_locks.header.fcntlReserved = 0;
|
|
|
|
|
|
|
|
take_locks.access.structLen = sizeof(take_locks.access);
|
|
|
|
take_locks.access.structType = GPFS_ACCESS_RANGE;
|
|
|
|
take_locks.access.start = param->offset;
|
|
|
|
take_locks.access.length = length;
|
|
|
|
take_locks.access.isWrite = (access == WRITE);
|
|
|
|
|
|
|
|
rc = gpfs_fcntl(fd, &take_locks);
|
|
|
|
if (verbose >= VERBOSE_2 && rc != 0) {
|
|
|
|
EWARN("gpfs_fcntl access range hint failed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpfs_access_end(int fd, IOR_offset_t length, IOR_param_t *param, int access)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct {
|
|
|
|
gpfsFcntlHeader_t header;
|
|
|
|
gpfsFreeRange_t free;
|
|
|
|
} free_locks;
|
|
|
|
|
|
|
|
|
|
|
|
free_locks.header.totalLength = sizeof(free_locks);
|
|
|
|
free_locks.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
|
|
|
|
free_locks.header.fcntlReserved = 0;
|
|
|
|
|
|
|
|
free_locks.free.structLen = sizeof(free_locks.free);
|
|
|
|
free_locks.free.structType = GPFS_FREE_RANGE;
|
|
|
|
free_locks.free.start = param->offset;
|
|
|
|
free_locks.free.length = length;
|
|
|
|
|
|
|
|
rc = gpfs_fcntl(fd, &free_locks);
|
|
|
|
if (verbose >= VERBOSE_2 && rc != 0) {
|
|
|
|
EWARN("gpfs_fcntl free range hint failed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-09-21 18:12:31 +03:00
|
|
|
#ifdef HAVE_BEEGFS_BEEGFS_H
|
|
|
|
|
|
|
|
int mkTempInDir(char* dirPath)
|
|
|
|
{
|
|
|
|
unsigned long len = strlen(dirPath) + 8;
|
|
|
|
char* tmpfilename = (char*)malloc(sizeof (char)*len+1);
|
|
|
|
snprintf(tmpfilename, len, "%s/XXXXXX", dirPath);
|
|
|
|
|
|
|
|
int fd = mkstemp(tmpfilename);
|
|
|
|
unlink(tmpfilename);
|
|
|
|
free(tmpfilename);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool beegfs_getStriping(char* dirPath, u_int16_t* numTargetsOut, unsigned* chunkSizeOut)
|
|
|
|
{
|
|
|
|
bool retVal = false;
|
|
|
|
|
|
|
|
int fd = mkTempInDir(dirPath);
|
|
|
|
if (fd) {
|
|
|
|
unsigned stripePattern = 0;
|
|
|
|
retVal = beegfs_getStripeInfo(fd, &stripePattern, chunkSizeOut, numTargetsOut);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool beegfs_isOptionSet(int opt) {
|
|
|
|
return opt != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a file on a BeeGFS file system with striping parameters
|
|
|
|
*/
|
|
|
|
bool beegfs_createFilePath(char* filepath, mode_t mode, int numTargets, int chunkSize)
|
|
|
|
{
|
|
|
|
bool retVal = false;
|
|
|
|
char* dirTmp = strdup(filepath);
|
|
|
|
char* dir = dirname(dirTmp);
|
|
|
|
DIR* parentDirS = opendir(dir);
|
|
|
|
if (!parentDirS) {
|
|
|
|
ERR("Failed to get directory");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int parentDirFd = dirfd(parentDirS);
|
|
|
|
if (parentDirFd < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get directory descriptor");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool isBeegfs = beegfs_testIsBeeGFS(parentDirFd);
|
|
|
|
if (!isBeegfs)
|
|
|
|
{
|
|
|
|
WARN("Not a BeeGFS file system");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !beegfs_isOptionSet(numTargets)
|
|
|
|
|| !beegfs_isOptionSet(chunkSize)) {
|
|
|
|
u_int16_t defaultNumTargets = 0;
|
|
|
|
unsigned defaultChunkSize = 0;
|
|
|
|
bool haveDefaults = beegfs_getStriping(dir,
|
|
|
|
&defaultNumTargets,
|
|
|
|
&defaultChunkSize);
|
|
|
|
if (!haveDefaults)
|
|
|
|
ERR("Failed to get default BeeGFS striping values");
|
|
|
|
|
|
|
|
numTargets = beegfs_isOptionSet(numTargets) ?
|
|
|
|
numTargets : defaultNumTargets;
|
|
|
|
chunkSize = beegfs_isOptionSet(chunkSize) ?
|
|
|
|
chunkSize : defaultChunkSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* filenameTmp = strdup(filepath);
|
|
|
|
char* filename = basename(filepath);
|
|
|
|
bool isFileCreated = beegfs_createFile(parentDirFd, filename,
|
|
|
|
mode, numTargets, chunkSize);
|
|
|
|
if (!isFileCreated)
|
|
|
|
ERR("Could not create file");
|
|
|
|
retVal = true;
|
|
|
|
free(filenameTmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(parentDirS);
|
|
|
|
}
|
|
|
|
free(dirTmp);
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_BEEGFS_BEEGFS_H */
|
|
|
|
|
|
|
|
|
2011-06-17 23:20:43 +04:00
|
|
|
/*
|
|
|
|
* Creat and open a file through the POSIX interface.
|
|
|
|
*/
|
2018-05-08 14:08:29 +03:00
|
|
|
void *POSIX_Create(char *testFileName, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
int fd_oflag = O_BINARY;
|
|
|
|
int *fd;
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
fd = (int *)malloc(sizeof(int));
|
|
|
|
if (fd == NULL)
|
|
|
|
ERR("Unable to malloc file descriptor");
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
if (param->useO_DIRECT == TRUE)
|
|
|
|
set_o_direct_flag(&fd_oflag);
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-10 02:30:21 +04:00
|
|
|
#ifdef HAVE_LUSTRE_LUSTRE_USER_H
|
2011-11-12 02:22:17 +04:00
|
|
|
if (param->lustre_set_striping) {
|
|
|
|
/* In the single-shared-file case, task 0 has to creat the
|
|
|
|
file with the Lustre striping options before any other processes
|
|
|
|
open the file */
|
|
|
|
if (!param->filePerProc && rank != 0) {
|
|
|
|
MPI_CHECK(MPI_Barrier(testComm), "barrier error");
|
|
|
|
fd_oflag |= O_RDWR;
|
|
|
|
*fd = open64(testFileName, fd_oflag, 0664);
|
|
|
|
if (*fd < 0)
|
|
|
|
ERR("open64() failed");
|
|
|
|
} else {
|
|
|
|
struct lov_user_md opts = { 0 };
|
|
|
|
|
|
|
|
/* Setup Lustre IOCTL striping pattern structure */
|
|
|
|
opts.lmm_magic = LOV_USER_MAGIC;
|
|
|
|
opts.lmm_stripe_size = param->lustre_stripe_size;
|
|
|
|
opts.lmm_stripe_offset = param->lustre_start_ost;
|
|
|
|
opts.lmm_stripe_count = param->lustre_stripe_count;
|
|
|
|
|
|
|
|
/* File needs to be opened O_EXCL because we cannot set
|
|
|
|
Lustre striping information on a pre-existing file. */
|
|
|
|
fd_oflag |=
|
|
|
|
O_CREAT | O_EXCL | O_RDWR | O_LOV_DELAY_CREATE;
|
|
|
|
*fd = open64(testFileName, fd_oflag, 0664);
|
|
|
|
if (*fd < 0) {
|
|
|
|
fprintf(stdout, "\nUnable to open '%s': %s\n",
|
|
|
|
testFileName, strerror(errno));
|
|
|
|
MPI_CHECK(MPI_Abort(MPI_COMM_WORLD, -1),
|
|
|
|
"MPI_Abort() error");
|
|
|
|
} else if (ioctl(*fd, LL_IOC_LOV_SETSTRIPE, &opts)) {
|
|
|
|
char *errmsg = "stripe already set";
|
|
|
|
if (errno != EEXIST && errno != EALREADY)
|
|
|
|
errmsg = strerror(errno);
|
|
|
|
fprintf(stdout,
|
|
|
|
"\nError on ioctl for '%s' (%d): %s\n",
|
|
|
|
testFileName, *fd, errmsg);
|
|
|
|
MPI_CHECK(MPI_Abort(MPI_COMM_WORLD, -1),
|
|
|
|
"MPI_Abort() error");
|
|
|
|
}
|
|
|
|
if (!param->filePerProc)
|
|
|
|
MPI_CHECK(MPI_Barrier(testComm),
|
|
|
|
"barrier error");
|
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
} else {
|
2011-11-12 02:22:17 +04:00
|
|
|
#endif /* HAVE_LUSTRE_LUSTRE_USER_H */
|
2017-09-21 18:12:31 +03:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
fd_oflag |= O_CREAT | O_RDWR;
|
2017-09-21 18:12:31 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_BEEGFS_BEEGFS_H
|
|
|
|
if (beegfs_isOptionSet(param->beegfs_chunkSize)
|
|
|
|
|| beegfs_isOptionSet(param->beegfs_numTargets)) {
|
|
|
|
bool result = beegfs_createFilePath(testFileName,
|
|
|
|
0664,
|
|
|
|
param->beegfs_numTargets,
|
|
|
|
param->beegfs_chunkSize);
|
|
|
|
if (result) {
|
|
|
|
fd_oflag &= ~O_CREAT;
|
|
|
|
} else {
|
|
|
|
EWARN("BeeGFS tuning failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_BEEGFS_BEEGFS_H */
|
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
*fd = open64(testFileName, fd_oflag, 0664);
|
|
|
|
if (*fd < 0)
|
|
|
|
ERR("open64() failed");
|
2017-09-21 18:12:31 +03:00
|
|
|
|
2011-11-10 02:30:21 +04:00
|
|
|
#ifdef HAVE_LUSTRE_LUSTRE_USER_H
|
2011-11-12 02:22:17 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
if (param->lustre_ignore_locks) {
|
|
|
|
int lustre_ioctl_flags = LL_FILE_IGNORE_LOCK;
|
|
|
|
if (ioctl(*fd, LL_IOC_SETFLAGS, &lustre_ioctl_flags) == -1)
|
|
|
|
ERR("ioctl(LL_IOC_SETFLAGS) failed");
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LUSTRE_LUSTRE_USER_H */
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
|
|
|
/* in the single shared file case, immediately release all locks, with
|
|
|
|
* the intent that we can avoid some byte range lock revocation:
|
|
|
|
* everyone will be writing/reading from individual regions */
|
|
|
|
if (param->gpfs_release_token ) {
|
|
|
|
gpfs_free_all_locks(*fd);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-12 02:22:17 +04:00
|
|
|
return ((void *)fd);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a file through the POSIX interface.
|
|
|
|
*/
|
2018-05-08 14:08:29 +03:00
|
|
|
void *POSIX_Open(char *testFileName, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
int fd_oflag = O_BINARY;
|
|
|
|
int *fd;
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
fd = (int *)malloc(sizeof(int));
|
|
|
|
if (fd == NULL)
|
|
|
|
ERR("Unable to malloc file descriptor");
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
if (param->useO_DIRECT == TRUE)
|
|
|
|
set_o_direct_flag(&fd_oflag);
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
fd_oflag |= O_RDWR;
|
|
|
|
*fd = open64(testFileName, fd_oflag);
|
|
|
|
if (*fd < 0)
|
|
|
|
ERR("open64 failed");
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2011-11-10 02:14:14 +04:00
|
|
|
#ifdef HAVE_LUSTRE_LUSTRE_USER_H
|
2011-11-12 02:22:17 +04:00
|
|
|
if (param->lustre_ignore_locks) {
|
|
|
|
int lustre_ioctl_flags = LL_FILE_IGNORE_LOCK;
|
|
|
|
if (verbose >= VERBOSE_1) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"** Disabling lustre range locking **\n");
|
|
|
|
}
|
|
|
|
if (ioctl(*fd, LL_IOC_SETFLAGS, &lustre_ioctl_flags) == -1)
|
|
|
|
ERR("ioctl(LL_IOC_SETFLAGS) failed");
|
2011-06-17 23:20:43 +04:00
|
|
|
}
|
2011-11-12 02:22:17 +04:00
|
|
|
#endif /* HAVE_LUSTRE_LUSTRE_USER_H */
|
2011-06-17 23:20:43 +04:00
|
|
|
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
|
|
|
if(param->gpfs_release_token) {
|
|
|
|
gpfs_free_all_locks(*fd);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-12 02:22:17 +04:00
|
|
|
return ((void *)fd);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write or read access to file using the POSIX interface.
|
|
|
|
*/
|
2011-11-12 04:40:45 +04:00
|
|
|
static IOR_offset_t POSIX_Xfer(int access, void *file, IOR_size_t * buffer,
|
|
|
|
IOR_offset_t length, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
int xferRetries = 0;
|
|
|
|
long long remaining = (long long)length;
|
|
|
|
char *ptr = (char *)buffer;
|
|
|
|
long long rc;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = *(int *)file;
|
|
|
|
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
|
|
|
if (param->gpfs_hint_access) {
|
|
|
|
gpfs_access_start(fd, length, param, access);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
/* seek to offset */
|
|
|
|
if (lseek64(fd, param->offset, SEEK_SET) == -1)
|
|
|
|
ERR("lseek64() failed");
|
|
|
|
|
|
|
|
while (remaining > 0) {
|
|
|
|
/* write/read file */
|
|
|
|
if (access == WRITE) { /* WRITE */
|
|
|
|
if (verbose >= VERBOSE_4) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"task %d writing to offset %lld\n",
|
|
|
|
rank,
|
|
|
|
param->offset + length - remaining);
|
|
|
|
}
|
|
|
|
rc = write(fd, ptr, remaining);
|
|
|
|
if (rc == -1)
|
|
|
|
ERR("write() failed");
|
2011-11-22 07:54:02 +04:00
|
|
|
if (param->fsyncPerWrite == TRUE)
|
|
|
|
POSIX_Fsync(&fd, param);
|
2011-11-12 02:22:17 +04:00
|
|
|
} else { /* READ or CHECK */
|
|
|
|
if (verbose >= VERBOSE_4) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"task %d reading from offset %lld\n",
|
|
|
|
rank,
|
|
|
|
param->offset + length - remaining);
|
|
|
|
}
|
|
|
|
rc = read(fd, ptr, remaining);
|
|
|
|
if (rc == 0)
|
|
|
|
ERR("read() returned EOF prematurely");
|
|
|
|
if (rc == -1)
|
|
|
|
ERR("read() failed");
|
|
|
|
}
|
|
|
|
if (rc < remaining) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"WARNING: Task %d, partial %s, %lld of %lld bytes at offset %lld\n",
|
|
|
|
rank,
|
|
|
|
access == WRITE ? "write()" : "read()",
|
|
|
|
rc, remaining,
|
|
|
|
param->offset + length - remaining);
|
|
|
|
if (param->singleXferAttempt == TRUE)
|
|
|
|
MPI_CHECK(MPI_Abort(MPI_COMM_WORLD, -1),
|
|
|
|
"barrier error");
|
|
|
|
if (xferRetries > MAX_RETRY)
|
|
|
|
ERR("too many retries -- aborting");
|
|
|
|
}
|
|
|
|
assert(rc >= 0);
|
|
|
|
assert(rc <= remaining);
|
|
|
|
remaining -= rc;
|
|
|
|
ptr += rc;
|
|
|
|
xferRetries++;
|
2011-06-17 23:20:43 +04:00
|
|
|
}
|
2013-09-26 17:48:50 +04:00
|
|
|
#ifdef HAVE_GPFS_FCNTL_H
|
|
|
|
if (param->gpfs_hint_access) {
|
|
|
|
gpfs_access_end(fd, length, param, access);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-12 02:22:17 +04:00
|
|
|
return (length);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform fsync().
|
|
|
|
*/
|
2011-11-12 04:40:45 +04:00
|
|
|
static void POSIX_Fsync(void *fd, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
if (fsync(*(int *)fd) != 0)
|
2011-12-15 01:40:25 +04:00
|
|
|
EWARN("fsync() failed");
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Close a file through the POSIX interface.
|
|
|
|
*/
|
2018-05-08 14:08:29 +03:00
|
|
|
void POSIX_Close(void *fd, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
if (close(*(int *)fd) != 0)
|
|
|
|
ERR("close() failed");
|
|
|
|
free(fd);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a file through the POSIX interface.
|
|
|
|
*/
|
2018-05-08 14:08:29 +03:00
|
|
|
void POSIX_Delete(char *testFileName, IOR_param_t * param)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
char errmsg[256];
|
|
|
|
sprintf(errmsg, "[RANK %03d]: unlink() of file \"%s\" failed\n",
|
|
|
|
rank, testFileName);
|
|
|
|
if (unlink(testFileName) != 0)
|
2011-12-15 01:40:25 +04:00
|
|
|
EWARN(errmsg);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use POSIX stat() to return aggregate file size.
|
|
|
|
*/
|
2018-05-08 14:08:29 +03:00
|
|
|
IOR_offset_t POSIX_GetFileSize(IOR_param_t * test, MPI_Comm testComm,
|
2011-11-12 04:40:45 +04:00
|
|
|
char *testFileName)
|
2011-06-17 23:20:43 +04:00
|
|
|
{
|
2011-11-12 02:22:17 +04:00
|
|
|
struct stat stat_buf;
|
|
|
|
IOR_offset_t aggFileSizeFromStat, tmpMin, tmpMax, tmpSum;
|
|
|
|
|
|
|
|
if (stat(testFileName, &stat_buf) != 0) {
|
|
|
|
ERR("stat() failed");
|
|
|
|
}
|
|
|
|
aggFileSizeFromStat = stat_buf.st_size;
|
|
|
|
|
|
|
|
if (test->filePerProc == TRUE) {
|
|
|
|
MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpSum, 1,
|
|
|
|
MPI_LONG_LONG_INT, MPI_SUM, testComm),
|
|
|
|
"cannot total data moved");
|
|
|
|
aggFileSizeFromStat = tmpSum;
|
|
|
|
} else {
|
|
|
|
MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpMin, 1,
|
|
|
|
MPI_LONG_LONG_INT, MPI_MIN, testComm),
|
|
|
|
"cannot total data moved");
|
|
|
|
MPI_CHECK(MPI_Allreduce(&aggFileSizeFromStat, &tmpMax, 1,
|
|
|
|
MPI_LONG_LONG_INT, MPI_MAX, testComm),
|
|
|
|
"cannot total data moved");
|
|
|
|
if (tmpMin != tmpMax) {
|
|
|
|
if (rank == 0) {
|
|
|
|
WARN("inconsistent file size by different tasks");
|
|
|
|
}
|
|
|
|
/* incorrect, but now consistent across tasks */
|
|
|
|
aggFileSizeFromStat = tmpMin;
|
|
|
|
}
|
2011-06-17 23:20:43 +04:00
|
|
|
}
|
|
|
|
|
2011-11-12 02:22:17 +04:00
|
|
|
return (aggFileSizeFromStat);
|
2011-11-12 03:11:28 +04:00
|
|
|
}
|