From e3afdb5ed55aa27d5cfffa4d2f0163d577274855 Mon Sep 17 00:00:00 2001 From: Oliver Steffen Date: Mon, 29 Apr 2019 15:49:57 +0200 Subject: [PATCH] beegfs: don't fail if output exists Use existing output file if it has the desired stripe settings (number of targets, chunk size) --- src/aiori-POSIX.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/aiori-POSIX.c b/src/aiori-POSIX.c index ca7c4a29..7c8c9ea7 100755 --- a/src/aiori-POSIX.c +++ b/src/aiori-POSIX.c @@ -201,6 +201,24 @@ bool beegfs_isOptionSet(int opt) { return opt != -1; } +bool beegfs_compatibleFileExists(char* filepath, int numTargets, int chunkSize) +{ + int fd = open(filepath, O_RDWR); + + if (fd == -1) + return false; + + unsigned read_stripePattern = 0; + u_int16_t read_numTargets = 0; + int read_chunkSize = 0; + + bool retVal = beegfs_getStripeInfo(fd, &read_stripePattern, &read_chunkSize, &read_numTargets); + + close(fd); + + return retVal && read_numTargets == numTargets && read_chunkSize == chunkSize; +} + /* * Create a file on a BeeGFS file system with striping parameters */ @@ -247,8 +265,9 @@ bool beegfs_createFilePath(char* filepath, mode_t mode, int numTargets, int chun char* filenameTmp = strdup(filepath); char* filename = basename(filepath); - bool isFileCreated = beegfs_createFile(parentDirFd, filename, - mode, numTargets, chunkSize); + bool isFileCreated = beegfs_compatibleFileExists(filepath, numTargets, chunkSize) + || beegfs_createFile(parentDirFd, filename, + mode, numTargets, chunkSize); if (!isFileCreated) ERR("Could not create file"); retVal = true;