Skip to content

Commit

Permalink
[Proxy/Posix] Allow Name2Name to populate cache using the LFN.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed May 11, 2017
1 parent 194d04a commit 04c06cf
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 75 deletions.
26 changes: 18 additions & 8 deletions src/XrdPosix/XrdPosixFile.cc
Expand Up @@ -38,10 +38,12 @@
#include <sys/uio.h>
#include <sys/stat.h>

#include "XrdOuc/XrdOucName2Name.hh"
#include "XrdPosix/XrdPosixCallBack.hh"
#include "XrdPosix/XrdPosixFile.hh"
#include "XrdPosix/XrdPosixFileRH.hh"
#include "XrdPosix/XrdPosixPrepIO.hh"
#include "XrdPosix/XrdPosixXrootdPath.hh"

#include "XrdSys/XrdSysTimer.hh"

Expand All @@ -51,8 +53,9 @@

namespace XrdPosixGlobals
{
extern XrdOucCache2 *theCache;
extern bool psxDBG;
extern XrdOucCache2 *theCache;
extern XrdOucName2Name *theN2N;
extern bool psxDBG;
};

namespace
Expand Down Expand Up @@ -81,14 +84,20 @@ int XrdPosixFile::ddNum = 0;
/* C o n s t r u c t o r */
/******************************************************************************/

XrdPosixFile::XrdPosixFile(const char *path, XrdPosixCallBack *cbP, int Opts)
XrdPosixFile::XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP,
int Opts)
: XCio((XrdOucCacheIO2 *)this), PrepIO(0),
mySize(0), myMtime(0), myInode(0), myMode(0),
theCB(cbP),
fPath(strdup(path)), fLoc(0),
cOpt(0),
theCB(cbP), fLoc(0), cOpt(0),
isStream(Opts & isStrm ? 1 : 0)
{
// Handle path generation. This is trickt as we may have two namespaces. One
// for the origin and one for the cache.
//
fOpen = strdup(path); aOK = true;
if (!XrdPosixGlobals::theN2N || !XrdPosixGlobals::theCache) fPath = fOpen;
else if (!XrdPosixXrootPath::P2L("new file",path,fPath)) aOK = false;
else if (!fPath) fPath = fOpen;

// Check for structured file check
//
Expand Down Expand Up @@ -124,6 +133,7 @@ XrdPosixFile::~XrdPosixFile()
// Free the path and location information
//
if (fPath) free(fPath);
if (fOpen != fPath) free(fOpen);
if (fLoc) free(fLoc);
}

Expand Down Expand Up @@ -188,7 +198,7 @@ do{if (doWait)
{numLost++; ddCount--;
snprintf(eBuff, sizeof(eBuff),
"PosixFile: %s timeout closing %s; %d objects lost!\n",
eTxt, fCurr->Path(), numLost);
eTxt, fCurr->Origin(), numLost);
std::cerr <<eBuff <<std::flush;
fCurr->nextFile = ddLost;
ddLost = fCurr;
Expand Down Expand Up @@ -237,7 +247,7 @@ void XrdPosixFile::DelayedDestroy(XrdPosixFile *fp)
{char eBuff[2048];
snprintf(eBuff, sizeof(eBuff),
"PosixFile: DLY destory %s %d objects; added %s.\n",
(doPost ? "post" : "has "), ddCount, fp->Path());
(doPost ? "post" : "has "), ddCount, fp->Origin());
std::cerr <<eBuff <<std::flush;
}

Expand Down
6 changes: 5 additions & 1 deletion src/XrdPosix/XrdPosixFile.hh
Expand Up @@ -107,6 +107,8 @@ static void DelayedDestroy(XrdPosixFile *fp);

long long Offset() {AtomicRet(updMutex, currOffset);}

const char *Origin() {return fOpen;}

const char *Path() {return fPath;}

int Read (char *Buff, long long Offs, int Len);
Expand Down Expand Up @@ -173,7 +175,8 @@ static const int realFD = 1;
static const int isStrm = 2;
static const int isUpdt = 4;

XrdPosixFile(const char *path, XrdPosixCallBack *cbP=0, int Opts=0);
XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
int Opts=0);
~XrdPosixFile();

private:
Expand All @@ -184,6 +187,7 @@ union {long long currOffset;
};

char *fPath;
char *fOpen;
char *fLoc;
union {int cOpt; int numTries;};
char isStream;
Expand Down
4 changes: 2 additions & 2 deletions src/XrdPosix/XrdPosixPrepIO.cc
Expand Up @@ -73,7 +73,7 @@ bool XrdPosixPrepIO::Init(XrdOucCacheIOCB *iocbP)
// Open the file. It is too difficult to do an async open here as there is a
// possible pending async request and doing both is not easy at all.
//
Status = fileP->clFile.Open((std::string)fileP->Path(), clFlags, clMode);
Status = fileP->clFile.Open((std::string)fileP->Origin(), clFlags, clMode);

// If all went well, then we need to do a Stat() call on the underlying file
//
Expand All @@ -87,7 +87,7 @@ bool XrdPosixPrepIO::Init(XrdOucCacheIOCB *iocbP)
if (XrdPosixGlobals::psxDBG && errno != ENOENT && errno != ELOOP)
{char eBuff[2048];
snprintf(eBuff, sizeof(eBuff), "%s deferred open %s\n",
Status.ToString().c_str(), fileP->Path());
Status.ToString().c_str(), fileP->Origin());
std::cerr <<eBuff <<std::flush;
}
return false;
Expand Down
133 changes: 94 additions & 39 deletions src/XrdPosix/XrdPosixXrootd.cc
Expand Up @@ -50,6 +50,7 @@
#include "XrdOuc/XrdOucCache2.hh"
#include "XrdOuc/XrdOucCacheDram.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucName2Name.hh"

#include "XrdPosix/XrdPosixAdmin.hh"
#include "XrdPosix/XrdPosixCacheBC.hh"
Expand All @@ -60,6 +61,7 @@
#include "XrdPosix/XrdPosixMap.hh"
#include "XrdPosix/XrdPosixPrepIO.hh"
#include "XrdPosix/XrdPosixXrootd.hh"
#include "XrdPosix/XrdPosixXrootdPath.hh"

/******************************************************************************/
/* S t a t i c M e m b e r s */
Expand All @@ -69,6 +71,7 @@ namespace XrdPosixGlobals
{
XrdScheduler *schedP = 0;
XrdOucCache2 *theCache = 0;
XrdOucName2Name *theN2N = 0;
XrdCl::DirListFlags::Flags dlFlag = XrdCl::DirListFlags::None;
bool psxDBG = (getenv("XRDPOSIX_DEBUG") != 0);
};
Expand All @@ -79,12 +82,37 @@ int XrdPosixXrootd::baseFD = 0;
int XrdPosixXrootd::initDone = 0;

/******************************************************************************/
/* L o c a l F u n c t i o n s */
/* L o c a l C l a s s e s */
/******************************************************************************/
/******************************************************************************/
/* L f n P a t h */
/******************************************************************************/


namespace
{
class LfnPath
{
public:
const char *path;

LfnPath(const char *who, const char *pURL, bool ponly=true)
{path = XrdPosixXrootPath::P2L(who, pURL, relURL, ponly);}

~LfnPath() {if (relURL) free(relURL);}

private:
char *relURL;
};
}

/******************************************************************************/
/* L o c a l F u n c t i o n s */
/******************************************************************************/

namespace
{

/******************************************************************************/
/* O p e n D e f e r */
/******************************************************************************/
Expand Down Expand Up @@ -214,7 +242,7 @@ int XrdPosixXrootd::Close(int fildes)
else if (XrdPosixGlobals::psxDBG)
{char eBuff[2048];
snprintf(eBuff, sizeof(eBuff), "Posix: %s closing %s\n",
Status.ToString().c_str(), fP->Path());
Status.ToString().c_str(), fP->Origin());
std::cerr <<eBuff <<std::flush;
}
} else ret = true;
Expand Down Expand Up @@ -482,6 +510,7 @@ int XrdPosixXrootd::Open(const char *path, int oflags, mode_t mode,
XrdCl::Access::Mode XOmode = XrdCl::Access::None;
XrdCl::OpenFlags::Flags XOflags;
int Opts;
bool aOK;

// Translate R/W and R/O flags
//
Expand Down Expand Up @@ -513,11 +542,15 @@ int XrdPosixXrootd::Open(const char *path, int oflags, mode_t mode,

// Allocate the new file object
//
if (!(fp = new XrdPosixFile(path, cbP, Opts)))
if (!(fp = new XrdPosixFile(aOK, path, cbP, Opts)))
{errno = EMFILE;
return -1;
}

// Check if all went well during allocation
//
if (!aOK) {delete fp; return -1;}

// If we have a cache, then issue a prepare as the cache may want to defer the
// open request ans we have a lot more work to do.
//
Expand All @@ -541,7 +574,7 @@ int XrdPosixXrootd::Open(const char *path, int oflags, mode_t mode,
if (XrdPosixGlobals::psxDBG && rc != ENOENT && rc != ELOOP)
{char eBuff[2048];
snprintf(eBuff, sizeof(eBuff), "%s open %s\n",
Status.ToString().c_str(), fp->Path());
Status.ToString().c_str(), fp->Origin());
std::cerr <<eBuff <<std::flush;
}
delete fp;
Expand Down Expand Up @@ -931,17 +964,21 @@ int XrdPosixXrootd::Rename(const char *oldpath, const char *newpath)

// Make sure the admin is OK and the new url is valid
//
if (!admin.isOK() || !newUrl.IsValid()) {errno = EINVAL; return -1;}
if (!admin.isOK() || !newUrl.IsValid()) {errno = EINVAL; return -1;}

// Issue the rename
// Issue rename to he cache (it really should just deep-six both files)
//
std::string urlp = admin.Url.GetPathWithParams();
std::string nurlp = newUrl.GetPathWithParams();
int res = XrdPosixMap::Result(admin.Xrd.Mv(urlp, nurlp));
if (!res && XrdPosixGlobals::theCache)
XrdPosixGlobals::theCache->Rename(urlp.c_str(), nurlp.c_str());
if (XrdPosixGlobals::theCache)
{LfnPath oldF("rename", oldpath);
LfnPath newF("rename", newpath);
if (!oldF.path || !newF.path) return -1;
XrdPosixGlobals::theCache->Rename(oldF.path, newF.path);
}

return res;
// Issue the rename
//
return XrdPosixMap::Result(admin.Xrd.Mv(admin.Url.GetPathWithParams(),
newUrl.GetPathWithParams()));
}

/******************************************************************************/
Expand All @@ -967,20 +1004,23 @@ void XrdPosixXrootd::Rewinddir(DIR *dirp)

int XrdPosixXrootd::Rmdir(const char *path)
{
XrdPosixAdmin admin(path);
XrdPosixAdmin admin(path);

// Make sure the admin is OK
//
if (!admin.isOK()) return -1;
if (!admin.isOK()) return -1;

// Issue the rmdir
// Remove directory from the cache first
//
std::string urlp = admin.Url.GetPathWithParams();
int res = XrdPosixMap::Result(admin.Xrd.RmDir(urlp));
if (!res && XrdPosixGlobals::theCache)
XrdPosixGlobals::theCache->Rmdir(urlp.c_str());
if (XrdPosixGlobals::theCache)
{LfnPath rmd("rmdir", path);
if (!rmd.path) return -1;
XrdPosixGlobals::theCache->Rmdir(rmd.path);
}

return res;
// Issue the rmdir
//
return XrdPosixMap::Result(admin.Xrd.RmDir(admin.Url.GetPathWithParams()));
}

/******************************************************************************/
Expand Down Expand Up @@ -1030,8 +1070,9 @@ int XrdPosixXrootd::Stat(const char *path, struct stat *buf)
// Check if we can get the stat informatation from the cache
//
if (myCache2)
{std::string urlp = admin.Url.GetPathWithParams();
int rc = myCache2->Stat(urlp.c_str(), *buf);
{LfnPath statX("stat", path, false);
if (!statX.path) return -1;
int rc = myCache2->Stat(statX.path, *buf);
if (!rc) return 0;
if (rc < 0) {errno = -rc; return -1;}
}
Expand Down Expand Up @@ -1186,18 +1227,20 @@ int XrdPosixXrootd::Truncate(const char *path, off_t Size)

// Make sure the admin is OK
//
if (!admin.isOK()) return -1;
if (!admin.isOK()) return -1;

// Issue the truncate
// Truncate in the cache first
//
std::string urlp = admin.Url.GetPathWithParams();
int res = XrdPosixMap::Result(admin.Xrd.Truncate(urlp,tSize));

if (!res && XrdPosixGlobals::theCache) {
XrdPosixGlobals::theCache->Truncate(urlp.c_str(), tSize);
}
if (XrdPosixGlobals::theCache)
{LfnPath trunc("truncate", path);
if (!trunc.path) return -1;
XrdPosixGlobals::theCache->Truncate(trunc.path, tSize);
}

return res;
// Issue the truncate to the origin
//
std::string urlp = admin.Url.GetPathWithParams();
return XrdPosixMap::Result(admin.Xrd.Truncate(urlp,tSize));
}

/******************************************************************************/
Expand All @@ -1206,20 +1249,23 @@ int XrdPosixXrootd::Truncate(const char *path, off_t Size)

int XrdPosixXrootd::Unlink(const char *path)
{
XrdPosixAdmin admin(path);
XrdPosixAdmin admin(path);

// Make sure the admin is OK
//
if (!admin.isOK()) return -1;
if (!admin.isOK()) return -1;

// Issue the UnLink
// Unlink the cache first
//
std::string urlp = admin.Url.GetPathWithParams();
int res = XrdPosixMap::Result(admin.Xrd.Rm(urlp));
if (!res && XrdPosixGlobals::theCache)
XrdPosixGlobals::theCache->Unlink(urlp.c_str());
if (XrdPosixGlobals::theCache)
{LfnPath remf("unlink", path);
if (!remf.path) return -1;
XrdPosixGlobals::theCache->Unlink(remf.path);
}

return res;
// Issue the UnLink
//
return XrdPosixMap::Result(admin.Xrd.Rm(admin.Url.GetPathWithParams()));
}

/******************************************************************************/
Expand Down Expand Up @@ -1556,6 +1602,15 @@ void XrdPosixXrootd::setNumCB(int numcb)
if (numcb >= 0) XrdPosixFileRH::SetMax(numcb);
}

/******************************************************************************/
/* S e t N 2 N */
/******************************************************************************/

void XrdPosixXrootd::setN2N(XrdOucName2Name *pN2N, int opts)
{
XrdPosixGlobals::theN2N = pN2N;
}

/******************************************************************************/
/* s e t S c h e d */
/******************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/XrdPosix/XrdPosixXrootd.hh
Expand Up @@ -53,6 +53,7 @@ class XrdScheduler;
class XrdOucCache;
class XrdOucCache2;
class XrdOucEnv;
class XrdOucName2Name;
class XrdPosixCallBack;
class XrdPosixCallBackIO;
class XrdPosixFile;
Expand Down Expand Up @@ -367,6 +368,8 @@ static void setIPV4(bool userv4);

static void setNumCB(int numcb);

static void setN2N(XrdOucName2Name *pN2N, int opts=0);

static void setSched(XrdScheduler *sP);

/* There must be one instance of this object per executable image. Typically,
Expand Down

0 comments on commit 04c06cf

Please sign in to comment.