Skip to content

Commit

Permalink
Merge pull request #56 from ecmwf/feature/FDB-330_lustreFS
Browse files Browse the repository at this point in the history
Feature/fdb 330 lustre fs
  • Loading branch information
danovaro authored Nov 28, 2024
2 parents 9d172bf + ffa93c2 commit c251373
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/fdb5/io/LustreFileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ class LustreFileHandle : public HANDLE {

void openForAppend(const eckit::Length& len) override {

std::string path = HANDLE::path_;
std::string pathStr = HANDLE::path_;
eckit::PathName path{pathStr};

if(eckit::PathName(path).exists()) return; //< Lustre API outputs ioctl error messages when called on files exist
if(path.exists()) return; //< Lustre API outputs ioctl error messages when called on files exist

/* From the docs: llapi_file_create closes the file descriptor. You must re-open the file afterwards */

LOG_DEBUG_LIB(LibFdb5) << "Creating Lustre file " << path
LOG_DEBUG_LIB(LibFdb5) << "Creating Lustre file " << pathStr
<< " with " << stripe_.count_ << " stripes "
<< "of " << eckit::Bytes(stripe_.size_)
<< std::endl;

int err = fdb5LustreapiFileCreate(path.c_str(), stripe_);
int err = fdb5LustreapiFileCreate(path, stripe_);

if(err == EINVAL) {

Expand Down
22 changes: 15 additions & 7 deletions src/fdb5/io/LustreSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#include "fdb5/fdb5_config.h"
#include "fdb5/LibFdb5.h"

#define LL_SUPER_MAGIC 0x0BD00BD0

#if defined(fdb5_HAVE_LUSTRE)
#include <sys/vfs.h>

extern "C" {
void fdb5_lustreapi_silence_msg();
int fdb5_lustreapi_file_create(const char* path, size_t stripesize, size_t stripecount);
Expand All @@ -35,19 +38,24 @@ bool fdb5LustreapiSupported() {
#endif
}

int fdb5LustreapiFileCreate(const char* path, LustreStripe stripe) {
int fdb5LustreapiFileCreate(const eckit::PathName& path, LustreStripe stripe) {

#if defined(fdb5_HAVE_LUSTRE)

static bool lustreapi_silence = false;
struct statfs buf;

if(not lustreapi_silence) {
fdb5_lustreapi_silence_msg();
lustreapi_silence = true;
}
statfs(path.dirName().localPath(), &buf);
if (buf.f_type == LL_SUPER_MAGIC) {

return fdb5_lustreapi_file_create(path, stripe.size_, stripe.count_);
static bool lustreapi_silence = false;

if(not lustreapi_silence) {
fdb5_lustreapi_silence_msg();
lustreapi_silence = true;
}

return fdb5_lustreapi_file_create(path.localPath(), stripe.size_, stripe.count_);
}
#endif

/// @note since fdb5LustreapiSupported() should be guarding all calls to this function,
Expand Down
3 changes: 2 additions & 1 deletion src/fdb5/io/LustreSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cstddef>

#include "eckit/filesystem/PathName.h"
namespace fdb5 {

//----------------------------------------------------------------------------------------------------------------------
Expand All @@ -42,7 +43,7 @@ LustreStripe stripeDataLustreSettings();

//----------------------------------------------------------------------------------------------------------------------

int fdb5LustreapiFileCreate(const char* path, LustreStripe stripe);
int fdb5LustreapiFileCreate(const eckit::PathName& path, LustreStripe stripe);

bool fdb5LustreapiSupported();

Expand Down
4 changes: 2 additions & 2 deletions src/fdb5/toc/TocCatalogueWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool TocCatalogueWriter::selectIndex(const Key& idxKey) {

// Enforce lustre striping if requested
if (stripeLustre()) {
fdb5LustreapiFileCreate(indexPath.localPath(), stripeIndexLustreSettings());
fdb5LustreapiFileCreate(indexPath, stripeIndexLustreSettings());
}

indexes_[idxKey] = Index(new TocIndex(idxKey, *this, indexPath, 0, TocIndex::WRITE));
Expand All @@ -81,7 +81,7 @@ bool TocCatalogueWriter::selectIndex(const Key& idxKey) {

// Enforce lustre striping if requested
if (stripeLustre()) {
fdb5LustreapiFileCreate(indexPath.localPath(), stripeIndexLustreSettings());
fdb5LustreapiFileCreate(indexPath, stripeIndexLustreSettings());
}

fullIndexes_[idxKey] = Index(new TocIndex(idxKey, *this, indexPath, 0, TocIndex::WRITE));
Expand Down
9 changes: 4 additions & 5 deletions src/fdb5/toc/TocHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ class SubtocPreloader {
int fd;
SYSCALL2((fd = ::open(path.localPath(), iomode)), path);
closers.emplace_back(AutoFDCloser{fd});
eckit::Length tocSize = 2*1024*1024;
eckit::Length tocSize = path.size();

aiocb& aio(aiocbs[i]);
zero(aio);
Expand Down Expand Up @@ -801,9 +801,8 @@ class SubtocPreloader {
}
}
#else
NOTIMP
NOTIMP;
#endif // eckit_HAVE_AIO

return std::move(subTocReadCache_);
}

Expand Down Expand Up @@ -938,7 +937,7 @@ void TocHandler::writeInitRecord(const Key& key) {

// enforce lustre striping if requested
if (stripeLustre() && !tocPath_.exists()) {
fdb5LustreapiFileCreate(tocPath_.localPath(), stripeIndexLustreSettings());
fdb5LustreapiFileCreate(tocPath_, stripeIndexLustreSettings());
}

ASSERT(fd_ == -1);
Expand Down Expand Up @@ -976,7 +975,7 @@ void TocHandler::writeInitRecord(const Key& key) {
// LustreFileHandle<eckit::FileHandle> out(tmp, stripeIndexLustreSettings());

if (stripeLustre()) {
fdb5LustreapiFileCreate(tmp.localPath(), stripeIndexLustreSettings());
fdb5LustreapiFileCreate(tmp, stripeIndexLustreSettings());
}
eckit::FileHandle out(tmp);
in.copyTo(out);
Expand Down

0 comments on commit c251373

Please sign in to comment.