42 #include <sys/param.h>
44 #include <sys/types.h>
46 #include <sys/vnode.h>
50 #include "XrdVersion.hh"
80 #define ENOATTR ENODATA
87 #define isNOSTAGE(_x_) !(XRDEXP_STAGE & XrdPssSys::XPList.Find(_x_))
89 #define isREADONLY(_x_) (XRDEXP_NOTRW & XrdPssSys::XPList.Find(_x_))
190 eDest.
Say(
"Copr. 2019, Stanford University, Pss Version " XrdVSTRING);
194 tmp = ((NoGo = Configure(cFN,
envP)) ?
"failed." :
"completed.");
195 eDest.
Say(
"------ Proxy storage system initialization ", tmp);
241 if (idMapper && client)
242 {
const char *fmt = (client->
ueid & 0xf0000000 ?
"%x" :
"U%x");
244 snprintf(uName,
sizeof(uName), fmt, client->
ueid);
290 if (idMapper && client)
291 {
const char *fmt = (client->
ueid & 0xf0000000 ?
"%x" :
"U%x");
293 snprintf(uName,
sizeof(uName), fmt, client->
ueid);
294 DEBUG(client->
tident,
"Unregistering as ID "<<uName);
320 if (theN2N)
return -(theN2N->
lfn2pfn(oldp, newp, blen));
321 if ((
int)strlen(oldp) >= blen)
return -ENAMETOOLONG;
328 if (!theN2N) {rc = 0;
return oldp;}
329 if ((rc = -(theN2N->
lfn2pfn(oldp, newp, blen))))
return 0;
392 const char *Cgi =
"";
463 DEBUG(uInfoOld.
Tident(),
"old url="<<oldNameObf <<
" new url=" <<newNameObf);
493 const char *Cgi =
"";
603 const char *Cgi =
"";
662 if (*dir_path !=
'/')
return -ENOTSUP;
684 if (!myDir)
return -errno;
712 {dirent *entP, myEnt;
715 if (!entP) *buff = 0;
716 else strlcpy(buff, myEnt.d_name, blen);
755 if ((theDir = myDir))
787 const char *Cgi =
"";
790 bool tpcMode = (Oflag & O_NOFOLLOW) != 0;
791 bool rwMode = (Oflag & (O_WRONLY | O_RDWR | O_APPEND)) != 0;
821 char *envcgi = (
char *)Env.
Env(elen);
823 if (envcgi && strstr(envcgi,
"only-if-cached"))
827 myData.
Arg1 =
"cached";
830 const char *myArgs[1];
832 myData.ArgP = myArgs;
848 {Oflag &= ~O_NOFOLLOW;
851 {tpcPath = strdup(path);
853 {
const char *rPath = Env.
Get(
"tpc.reproxy");
854 if (!rPath || *rPath !=
'/')
return -
ENOATTR;
855 if (!(rPath = rindex(rPath,
'/')) || *(rPath+1) == 0)
857 rpInfo =
new tprInfo(rPath+1);
896 {Env.
Put(
"FileURL",
Info.cacheURL);
897 return -EDESTADDRREQ;
900 if (
fd < 0)
return -errno;
924 if (retsz) *retsz = 0;
939 return (rc == 0 ?
XrdOssOK : -errno);
966 std::vector<uint32_t> vecCS;
981 return (ssize_t)-errno;
985 if (vecCS.size() && csvec)
986 memcpy(csvec, vecCS.data(), vecCS.size()*
sizeof(uint32_t));
1019 std::vector<uint32_t> vecCS;
1039 if (csvec) memcpy(csvec, vecCS.data(), vecCS.size()*
sizeof(uint32_t));
1044 memcpy(vecCS.data(), csvec, n*
sizeof(uint32_t));
1053 return (bytes < 0 ? (ssize_t)-errno : bytes);
1100 ? (ssize_t)-errno : retval;
1147 return Read(buff, offset, blen);
1172 ? (ssize_t)-errno : retval;
1210 if (rpInfo->dstURL == 0
1211 || !fstatat(
rpFD, rpInfo->tprPath, &
Stat, AT_SYMLINK_NOFOLLOW))
1212 {
char lnkbuff[2048];
int lnklen;
1213 lnklen = readlinkat(
rpFD, rpInfo->tprPath, lnkbuff,
sizeof(lnkbuff)-1);
1216 if (lnklen < 0) {
if (errno != ENOENT) rc = -errno;}
1219 {unlinkat(
rpFD, rpInfo->tprPath, 0);
1223 unlinkat(
rpFD, rpInfo->tprPath, 0);
1224 lnkbuff[lnklen] = 0;
1225 if (rpInfo->dstURL) free(rpInfo->dstURL);
1226 rpInfo->dstURL = strdup(lnkbuff);
1228 DEBUG(
tident,rpInfo->tprPath<<
" maps "<<tpcPath<<
" -> "<<lnkbuff);
1237 {
if (!(rpInfo->fSize = buff->st_size)) rpInfo->fSize = 1;
1240 free(rpInfo->dstURL);
1247 {memset(buff, 0,
sizeof(
struct stat));
1248 buff->st_size = rpInfo->fSize;
1258 memset(buff, 0,
sizeof(
struct stat));
1331 Slash = index(path,
'/');
1332 if (!Slash || (n = (Slash - path)) == 0) {retc = -EINVAL;
return 0;}
1333 if (n >= hBlen) {retc = -ENAMETOOLONG;
return 0;}
1334 strncpy(hBuff, path, n); hBuff[n] = 0;
1339 {retc = -EACCES;
return 0;}
1351 {
const char *theID = uInfo.
getID();
1352 const char *pname, *path, *thePath;
1358 thePath = path = uInfo.
thePath();
1362 if (*path ==
'/') path++;
1364 else {
if (!
hdrLen)
return -ENOTSUP;
1365 n = snprintf(pbuff, pblen,
hdrData, theID, thePath);
1366 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1367 return -ENAMETOOLONG;
1373 if (*thePath !=
'/')
1376 if (*path ==
'/') theID =
"";
1379 path+(*path ==
'/' ? 1:0)))
return 0;
1380 n = snprintf(pbuff, pblen,
"%s%s%s", pname, theID, path);
1381 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1382 return -ENAMETOOLONG;
1390 if (!(n =
P2DST(retc, hBuff,
sizeof(hBuff),
PolPath, path)))
return 0;
1397 if (index(hBuff,
'@')) theID=
"";
1398 n = snprintf(pbuff,pblen,
"%s%s%s/%s",pname,theID,hBuff,path);
1402 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1403 return -ENAMETOOLONG;
1423 const char *path = uInfo.
thePath();
1425 char Apath[MAXPATHLEN+1];
1436 {
if (retc > 0)
return -retc;}
1444 else pfxLen = snprintf(pbuff, pblen,
hdrData, uInfo.
getID(), path);
1445 if (pfxLen >= pblen)
return -ENAMETOOLONG;
1450 {
if (!uInfo.
addCGI(pbuff, pbuff+pfxLen, pblen-pfxLen))
1451 return -ENAMETOOLONG;
XrdAccAuthorize * Authorize
std::string obfuscateAuth(const std::string &input)
int stat(const char *path, struct stat *buf)
XrdVERSIONINFO(XrdOssGetStorageSystem2, XrdPss)
XrdOss * XrdOssGetStorageSystem2(XrdOss *native_oss, XrdSysLogger *Logger, const char *cFN, const char *parms, XrdOucEnv *envp)
const char * Arg1
PLUGINO, PLUGION, PLUGXC.
int Arg2Len
Length or -count of args in extension.
< SFS_FSCTL_PLUGIN/PLUGIO/PLUGXC parms
virtual int FSctl(const int cmd, int alen, const char *args, XrdSfsFile &file, XrdOucErrInfo &eInfo, const XrdSecEntity *client=0)=0
static const uint64_t doCalc
pgw: Calculate checksums
static const uint64_t Verify
all: Verify checksums
void * GetPtr(const char *varname)
char * Get(const char *varname)
const XrdSecEntity * secEnv() const
void Put(const char *varname, const char *value)
virtual int lfn2pfn(const char *lfn, char *buff, int blen)=0
unsigned long long Find(const char *pathname)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
static bool csVer(dataInfo &dInfo, off_t &bado, int &badc)
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
static bool OpenFC(const char *path, int oflag, mode_t mode, XrdPosixInfo &Info)
static int Stats(const char *theID, char *buff, int blen)
static void EnvInfo(XrdOucEnv &theEnv)
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
static void VRead(int fildes, const XrdOucIOVec *readV, int n, XrdPosixCallBackIO *cbp)
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static int QueryError(std::string &emsg, int fd=-1, bool reset=true)
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static int StatRet(DIR *dirp, struct stat *buf)
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()
int Close(long long *retsz=0)
int Opendir(const char *, XrdOucEnv &)
int Readdir(char *buff, int blen)
int StatRet(struct stat *buf)
ssize_t ReadRaw(void *, off_t, size_t)
virtual int Close(long long *retsz=0)
virtual int Open(const char *, int, mode_t, XrdOucEnv &)
ssize_t Read(off_t, size_t)
ssize_t Write(const void *, off_t, size_t)
ssize_t ReadV(XrdOucIOVec *readV, int n)
ssize_t pgRead(void *buffer, off_t offset, size_t rdlen, uint32_t *csvec, uint64_t opts)
int Ftruncate(unsigned long long)
ssize_t pgWrite(void *buffer, off_t offset, size_t wrlen, uint32_t *csvec, uint64_t opts)
int Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0) override
static int P2OUT(char *pbuff, int pblen, XrdPssUrlInfo &uInfo)
int Unlink(const char *, int Opts=0, XrdOucEnv *eP=0) override
virtual void Connect(XrdOucEnv &) override
int Truncate(const char *, unsigned long long, XrdOucEnv *eP=0) override
int Stats(char *bp, int bl) override
static const char * hdrData
int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *eP=0) override
int Init(XrdSysLogger *, const char *) override
static int P2DST(int &retc, char *hBuff, int hBlen, PolAct pType, const char *path)
int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0) override
void EnvInfo(XrdOucEnv *envP) override
static XrdNetSecurity * Police[PolNum]
static XrdOucPListAnchor XPList
static int P2URL(char *pbuff, int pblen, XrdPssUrlInfo &uInfo, bool doN2N=true)
int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0) override
int Lfn2Pfn(const char *Path, char *buff, int blen) override
virtual int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0) override
virtual void Disc(XrdOucEnv &) override
int Rename(const char *, const char *, XrdOucEnv *eP1=0, XrdOucEnv *eP2=0) override
void setID(const char *tid=0)
bool addCGI(const char *prot, char *buff, int blen)
static const char * valProt(const char *pname, int &plen, int adj=0)
const char * tident
Trace identifier always preset.
unsigned int ueid
Unique ID of entity instance.
bool Register(const char *lgnid, const XrdSecEntity *Ident, bool doReplace=false, bool defer=false)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
void SetLogger(XrdSysLogger *logp)
XrdOfsFSctl_PI * cacheFSctl
XrdSysTrace SysTrace("Pss", 0)
XrdSysError eDest(0, "pss_")
static const char * osslclCGI
thread_local XrdOucECMsg ecMsg("[pss]")
static XrdPssSys XrdProxySS
static const char * ofslclCGI