Skip to content

Commit

Permalink
Support for POSIX range locks using fcntl. (#423)
Browse files Browse the repository at this point in the history
Support for POSIX range locks using fcntl.
  • Loading branch information
JulianKunkel committed Jun 15, 2022
1 parent 202b69f commit b4d1d25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/aiori-POSIX.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif /* __linux__ */

#include <errno.h>
#include <unistd.h>
#include <fcntl.h> /* IO operations */
#include <sys/stat.h>
#include <assert.h>
Expand Down Expand Up @@ -131,6 +132,7 @@ option_help * POSIX_options(aiori_mod_opt_t ** init_backend_options, aiori_mod_o

option_help h [] = {
{0, "posix.odirect", "Direct I/O Mode", OPTION_FLAG, 'd', & o->direct_io},
{0, "posix.rangelocks", "Use range locks (read locks for read ops)", OPTION_FLAG, 'd', & o->range_locks},
#ifdef HAVE_BEEGFS_BEEGFS_H
{0, "posix.beegfs.NumTargets", "", OPTION_OPTIONAL_ARGUMENT, 'd', & o->beegfs_numTargets},
{0, "posix.beegfs.ChunkSize", "", OPTION_OPTIONAL_ARGUMENT, 'd', & o->beegfs_chunkSize},
Expand Down Expand Up @@ -691,6 +693,18 @@ static IOR_offset_t POSIX_Xfer(int access, aiori_fd_t *file, IOR_size_t * buffer
if (lseek64(fd, offset, SEEK_SET) == -1)
ERRF("lseek64(%d, %lld, SEEK_SET) failed", fd, offset);
off_t mem_offset = 0;

if(o->range_locks){
struct flock lck = {
.l_whence = SEEK_SET,
.l_start = offset,
.l_len = remaining,
.l_type = access == WRITE ? F_WRLCK : F_RDLCK,
};
if(fcntl(fd, F_SETLKW, &lck) != 0){
WARN("Error with F_SETLKW");
}
}
while (remaining > 0) {
/* write/read file */
if (access == WRITE) { /* WRITE */
Expand Down Expand Up @@ -757,6 +771,17 @@ static IOR_offset_t POSIX_Xfer(int access, aiori_fd_t *file, IOR_size_t * buffer
mem_offset += rc;
xferRetries++;
}
if(o->range_locks){
struct flock lck = {
.l_whence = SEEK_SET,
.l_start = offset,
.l_len = length,
.l_type = F_UNLCK,
};
if(fcntl(fd, F_SETLK, &lck) != 0){
WARN("Error with F_UNLCK");
}
}
#ifdef HAVE_GPFS_FCNTL_H
if (o->gpfs_hint_access) {
gpfs_access_end(fd, length, offset, access);
Expand Down
1 change: 1 addition & 0 deletions src/aiori-POSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct{
int beegfs_numTargets; /* number storage targets to use */
int beegfs_chunkSize; /* srtipe pattern for new files */
int gpuDirect;
int range_locks; /* use POSIX range locks for writes */
} posix_options_t;

void POSIX_Sync(aiori_mod_opt_t * param);
Expand Down

0 comments on commit b4d1d25

Please sign in to comment.