Skip to content

Commit abec8eb

Browse files
Robert-Paul Pascaesindril
authored andcommitted
FST: Fix deletion of xattr files, fileOpen flags and gContext
1 parent 3738e98 commit abec8eb

2 files changed

Lines changed: 49 additions & 27 deletions

File tree

fst/io/nfs/NfsIo.cc

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ EOSFSTNAMESPACE_BEGIN
3636

3737
#define NFS_QUOTA_FILE ".nfs.quota"
3838

39-
struct nfs_context* NfsIo::gContext = nullptr;
40-
std::mutex NfsIo::gContextMutex;
41-
std::string NfsIo::gMountedPath = "";
42-
4339
namespace
4440
{
4541
std::string getAttrPath(std::string path)
@@ -64,30 +60,17 @@ NfsIo::NfsIo(std::string path, XrdFstOfsFile* file, const XrdSecEntity* client)
6460
{
6561
eos_debug("NfsIo::NfsIo called with path=%s", path.c_str());
6662

67-
// Initialize NFS context
68-
std::lock_guard<std::mutex> guard(gContextMutex);
69-
if (gContext == nullptr) {
70-
gContext = nfs_init_context();
71-
if (gContext == nullptr) {
72-
eos_err("msg=\"failed to initialize NFS context\"");
73-
} else {
74-
eos_info("msg=\"NFS context initialized successfully\"");
75-
}
76-
}
77-
7863
//............................................................................
7964
// Prepare the file path
8065
//............................................................................
81-
if (path.find("nfs:") == 0) {
82-
mFilePath = path.substr(4); // Remove "nfs:" prefix
83-
} else if (path.find("/nfs") == 0) {
84-
mFilePath = path;
66+
if (path.find("nfs:/") == 0) {
67+
mFilePath = path.substr(5); // Remove "nfs:/" prefix
8568
} else {
8669
eos_warning("msg=\"NFS path does not start with 'nfs:' or '/nfs'\" path=\"%s\"", path.c_str());
8770
mFilePath = path;
8871
}
8972

90-
eos_info("msg=\"NfsIo initialized\" original_path=%s, parsed_path=%s", path.c_str(), mFilePath.c_str());
73+
eos_debug("msg=\"NfsIo initialized\" original_path=%s, parsed_path=%s", path.c_str(), mFilePath.c_str());
9174

9275
// Standard initialization
9376
mFd = -1;
@@ -133,6 +116,19 @@ NfsIo::fileOpen(XrdSfsFileOpenMode flags, mode_t mode, const std::string& opaque
133116

134117
int pflags = 0;
135118

119+
XrdOucEnv openEnv(opaque.c_str());
120+
const char *val;
121+
122+
if ((val = openEnv.Get("mgm.ioflag"))) {
123+
if (!strcmp(val, "direct")) {
124+
pflags |= O_DIRECT;
125+
} else if (!strcmp(val, "sync")) {
126+
pflags |= O_SYNC;
127+
} else if (!strcmp(val, "dsync")) {
128+
pflags |= O_DSYNC;
129+
}
130+
}
131+
136132
if (flags & SFS_O_CREAT) {
137133
pflags |= (O_CREAT | O_RDWR);
138134
}
@@ -193,6 +189,7 @@ NfsIo::fileOpen(XrdSfsFileOpenMode flags, mode_t mode, const std::string& opaque
193189
std::future<XrdCl::XRootDStatus>
194190
NfsIo::fileOpenAsync(XrdSfsFileOpenMode flags, mode_t mode, const std::string& opaque, uint16_t timeout)
195191
{
192+
eos_info("msg=\"opening file asynchronously\" path=\"%s\"", mFilePath.c_str());
196193
std::promise<XrdCl::XRootDStatus> open_promise;
197194
std::future<XrdCl::XRootDStatus> open_future = open_promise.get_future();
198195

@@ -435,9 +432,15 @@ int
435432
NfsIo::fileRemove(uint16_t timeout)
436433
{
437434
eos_debug("");
435+
eos_info("msg=\"fileRemove called\" path=\"%s\"", mFilePath.c_str());
438436

439437
std::string attrPath = xattrPath();
440-
unlink(attrPath.c_str());
438+
int attr_rc = unlink(attrPath.c_str());
439+
if (attr_rc == 0) {
440+
eos_info("msg=\"deleted attribute file\" path=\"%s\"", attrPath.c_str());
441+
} else if (errno != ENOENT) {
442+
eos_warning("msg=\"failed to delete attribute file\" path=\"%s\" errno=%d error=\"%s\"", attrPath.c_str(), errno, strerror(errno));
443+
}
441444

442445
int rc = unlink(mFilePath.c_str());
443446
if (-1 == rc) {
@@ -473,7 +476,17 @@ int
473476
NfsIo::fileDelete(const char* path)
474477
{
475478
eos_debug("");
476-
eos_info("path=\"%s\"", path);
479+
480+
// Delete xattr file
481+
std::string attrPath = getAttrPath(std::string(path));
482+
int attr_rc = unlink(attrPath.c_str());
483+
if (attr_rc == 0) {
484+
eos_info("msg=\"deleted attribute file\" path=\"%s\"", attrPath.c_str());
485+
} else if (errno != ENOENT) {
486+
eos_warning("msg=\"failed to delete attribute file\" path=\"%s\" errno=%d error=\"%s\"", attrPath.c_str(), errno, strerror(errno));
487+
}
488+
489+
// Delete the main file
477490
int rc = unlink(path);
478491

479492
if (-1 == rc) {
@@ -639,6 +652,14 @@ NfsIo::flushAttrFile()
639652
return 0;
640653
}
641654

655+
// Skip flush if main file is missing
656+
struct stat stMain;
657+
if (stat(mFilePath.c_str(), &stMain) != 0 && errno == ENOENT) {
658+
mAttrDirty = false;
659+
mAttrLoaded = false;
660+
return 0;
661+
}
662+
642663
std::string attrPath = xattrPath();
643664
std::string content = mFileMap.Trim();
644665

fst/io/nfs/NfsIo.hh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#pragma once
2626

2727
#ifdef HAVE_NFS
28-
#include <string>
29-
#include <mutex>
3028
#include "fst/io/FileIo.hh"
3129
#include "common/FileMap.hh"
30+
#include <string>
31+
#include <mutex>
3232
#include <nfsc/libnfs.h>
3333

3434
EOSFSTNAMESPACE_BEGIN
@@ -435,9 +435,10 @@ public:
435435

436436
int Statfs(struct statfs* statFs);
437437

438-
static struct nfs_context* gContext;
439-
static std::mutex gContextMutex; ///< mutex for thread-safe context initialization
440-
static std::string gMountedPath; ///< path where NFS is mounted
438+
// NFS context used when you have a NFS Server configuration - not supported
439+
// static struct nfs_context* gContext;
440+
// static std::mutex gContextMutex; ///< mutex for thread-safe context initialization
441+
// static std::string gMountedPath; ///< path where NFS is mounted
441442

442443
private:
443444
std::string xattrPath() const; //< path to xattr file

0 commit comments

Comments
 (0)