Commit 46a1ebde authored by Elvin Sindrilaru's avatar Elvin Sindrilaru
Browse files

XROOTD: Fix formatting, add more comments and simplify code logic

parent 9a6c7f13
......@@ -18,16 +18,17 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
*
******************************************************************************/
#pragma once
#define XCASTOR2FS_MAXFILESYSTEMS 8192
#define XCASTOR2FS_MAXDISTINCTUSERS 8192
//! Constants dealing with async requests for the stager
#define XCASTOR2FS_RESP_TIMEOUT 600 ///< timeout for async responses
#define XCASTOR2FS_MAX_REQUESTS 2000 ///< max no. of requests on-the-fly
#define XCASTOR2FS_MAXFILESYSTEMS 8192
#define XCASTOR2FS_MAXDISTINCTUSERS 8192
//! Constants dealing with async requests for the stager
//! Timeout during which we received the response for an async request from
//! stager and the client need to show up to collect it
#define XCASTOR2FS_RESP_TIMEOUT 600
//! Maximum number of async requests in-fligth
#define XCASTOR2FS_MAX_REQUESTS 2000
......@@ -18,7 +18,6 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
......@@ -41,9 +40,7 @@ XrdxCastor2FsDirectory::XrdxCastor2FsDirectory(const char* user, int MonID) :
d_pnt(0),
ds_ptn(0),
mAutoStat(0)
{
// empty
}
{ }
//------------------------------------------------------------------------------
......@@ -66,9 +63,9 @@ XrdxCastor2FsDirectory::~XrdxCastor2FsDirectory()
// Open directory
//------------------------------------------------------------------------------
int
XrdxCastor2FsDirectory::open(const char* dir_path,
XrdxCastor2FsDirectory::open(const char* dir_path,
const XrdSecEntity* client,
const char* info)
const char* info)
{
EPNAME("opendir");
uid_t client_uid;
......@@ -90,7 +87,7 @@ XrdxCastor2FsDirectory::open(const char* dir_path,
if (dh)
return gMgr->Emsg(epname, error, EADDRINUSE, "open directory", map_dir.c_str());
// Open the directory and get it's id
// Open the directory and get its id
if (!(dh = XrdxCastor2FsUFS::OpenDir(map_dir.c_str())))
return gMgr->Emsg(epname, error, serrno, "open directory", map_dir.c_str());
......@@ -141,7 +138,6 @@ XrdxCastor2FsDirectory::nextEntry()
mAutoStat->st_atime = ds_ptn->atime;
mAutoStat->st_mtime = ds_ptn->mtime;
mAutoStat->st_ctime = ds_ptn->ctime;
xcastor_debug("dir next stat entry: %s", ds_ptn->d_name);
return static_cast<const char*>(ds_ptn->d_name);
}
......@@ -166,7 +162,7 @@ XrdxCastor2FsDirectory::nextEntry()
// Set stat buffer to automaticaly return stat information
//------------------------------------------------------------------------------
int
XrdxCastor2FsDirectory::autoStat(struct stat *buf)
XrdxCastor2FsDirectory::autoStat(struct stat* buf)
{
EPNAME("autostat");
......
......@@ -36,19 +36,19 @@
//------------------------------------------------------------------------------
class XrdxCastor2FsDirectory : public XrdSfsDirectory, public LogId
{
public:
public:
//----------------------------------------------------------------------------
//! Constructor
//----------------------------------------------------------------------------
XrdxCastor2FsDirectory(const char* user=0, int MonID=0);
XrdxCastor2FsDirectory(const char* user = 0, int MonID = 0);
//----------------------------------------------------------------------------
//! Destructor
//----------------------------------------------------------------------------
virtual ~XrdxCastor2FsDirectory();
//----------------------------------------------------------------------------
//! Open the directory `path' and prepare for reading
......@@ -61,9 +61,9 @@ public:
//----------------------------------------------------------------------------
int open(const char* dirName,
const XrdSecEntity* client = 0,
const char* opaque = 0 );
const char* opaque = 0);
//----------------------------------------------------------------------------
//! Read the next directory entry
//!
......@@ -78,8 +78,8 @@ public:
//----------------------------------------------------------------------------
//! Function: Set stat buffer to automaticaly return stat information
//! Input: Pointer to stat buffer which will be filled in on each
//! nextEntry() and represent stat information for that entry.
//! Output: Upon success, returns zero. Upon error returns SFS_ERROR and sets
//! nextEntry() and represent stat information for that entry.
//! Output: Upon success, returns zero. Upon error returns SFS_ERROR and sets
//! the error object to contain the reason.
//!
//! Notes: 1. If autoStat() is not supported he caller will need to follow up
......@@ -87,9 +87,9 @@ public:
//! process. The autoStat function significantly reduces overhead by
//! automatically providing stat information for the entry read.
//----------------------------------------------------------------------------
int autoStat(struct stat *buf);
int autoStat(struct stat* buf);
//----------------------------------------------------------------------------
//! Close the directory object
//!
......@@ -98,22 +98,21 @@ public:
//! @return SFS_OK upon success and SFS_ERROR upon failure
//----------------------------------------------------------------------------
int close();
//----------------------------------------------------------------------------
//! Get directory name
//! Get directory name
//----------------------------------------------------------------------------
const char* FName()
const char* FName()
{
return (const char*)fname;
return const_cast<const char*>(fname);
}
private:
Cns_DIR* dh; ///< directory stream handle
char* fname; ///< directory name
struct dirent* d_pnt; ///< ptr to dir entry
private:
Cns_DIR* dh; ///< directory stream handle
char* fname; ///< directory name
struct dirent* d_pnt; ///< ptr to dir entry
struct Cns_direnstatc* ds_ptn; ///< ptr dir entry with stat info
struct stat* mAutoStat; ///< stat buffer used for bulk dir listing
};
......@@ -18,24 +18,23 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
*
*
******************************************************************************/
#pragma once
#include "XrdAcc/XrdAccAuthorize.hh"
#define AUTHORIZE(usr, env, optype, action, pathp, edata) \
if (usr && gMgr->mAuthorization \
&& !gMgr->mAuthorization->Access(usr, pathp, optype, env)) \
{gMgr->Emsg(epname, edata, EACCES, action, pathp); return SFS_ERROR;}
#define AUTHORIZE(usr, env, optype, action, pathp, edata) \
if (usr && gMgr->mAuthorization \
&& !gMgr->mAuthorization->Access(usr, pathp, optype, env)) \
{ gMgr->Emsg(epname, edata, EACCES, action, pathp); return SFS_ERROR; }
#define AUTHORIZE2(usr,edata,opt1,act1,path1,env1,opt2,act2,path2,env2) \
{AUTHORIZE(usr, env1, opt1, act1, path1, edata); \
AUTHORIZE(usr, env2, opt2, act2, path2, edata); \
{ AUTHORIZE(usr, env1, opt1, act1, path1, edata); \
AUTHORIZE(usr, env2, opt2, act2, path2, edata); \
}
#define OOIDENTENV(usr, env) \
if (usr) {if (usr->name) env.Put(SEC_USER, usr->name); \
if (usr->host) env.Put(SEC_HOST, usr->host);}
#define OOIDENTENV(usr, env) \
if (usr) { if (usr->name) env.Put(SEC_USER, usr->name); \
if (usr->host) env.Put(SEC_HOST, usr->host); }
......@@ -18,7 +18,6 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
......@@ -73,7 +72,7 @@ XrdxCastor2FsStats::XrdxCastor2FsStats(XrdxCastor2Proc* proc)
XrdxCastor2FsStats::~XrdxCastor2FsStats()
{
if (ServerTable) delete ServerTable;
if (UserTable) delete UserTable;
if (UserTable) delete UserTable;
}
......@@ -183,12 +182,14 @@ XrdxCastor2FsStats::IncCmd(bool lock)
{
time_t now = time(NULL);
if (lock) statmutex.Lock();
if (lock)
statmutex.Lock();
cmd300s[(now + 1) % 300] = 0;
cmd300s[now % 300]++;
if (lock) statmutex.UnLock();
if (lock)
statmutex.UnLock();
}
......@@ -224,9 +225,7 @@ XrdxCastor2FsStats::IncServerRead(const char* server)
ServerTable->Insert(new XrdOucString(server), server);
}
else
{
rc->Inc();
}
statmutex.UnLock();
}
......@@ -251,9 +250,7 @@ XrdxCastor2FsStats::IncServerWrite(const char* server)
ServerTable->Insert(new XrdOucString(server), server);
}
else
{
rc->Inc();
}
statmutex.UnLock();
}
......@@ -289,9 +286,7 @@ XrdxCastor2FsStats::IncUserRead(const char* user)
UserTable->Insert(new XrdOucString(user), user);
}
else
{
rc->Inc();
}
statmutex.UnLock();
}
......@@ -314,9 +309,7 @@ XrdxCastor2FsStats::IncUserWrite(const char* user)
UserTable->Insert(new XrdOucString(user), user);
}
else
{
rc->Inc();
}
statmutex.UnLock();
}
......@@ -437,7 +430,6 @@ XrdxCastor2FsStats::CmdRate(int nbins)
for (int i = 0 ; i < nbins; i++)
sum += (cmd300s[(now - 1 - i) % 300]);
sum /= nbins;
return sum;
}
......@@ -575,7 +567,7 @@ XrdxCastor2FsStats::Update()
errno = 0;
char* end;
log_level = (int) strtol(slog_level.c_str(), &end, 10);
if ((errno == ERANGE && ((log_level == LONG_MIN) || (log_level == LONG_MAX))) ||
((errno != 0) && (log_level == 0)) ||
(end == slog_level.c_str()))
......@@ -589,9 +581,7 @@ XrdxCastor2FsStats::Update()
}
}
}
statmutex.UnLock();
{
XrdxCastor2ProcFile* pf = Proc->Handle("serverread");
......
......@@ -18,7 +18,6 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
......@@ -37,41 +36,39 @@
//------------------------------------------------------------------------------
class XrdxCastor2StatULongLong
{
private:
private:
unsigned long long cnt;
public:
public:
//----------------------------------------------------------------------------
//! Constructor
//! Constructor
//----------------------------------------------------------------------------
XrdxCastor2StatULongLong()
{
Reset();
};
}
//----------------------------------------------------------------------------
//! Destructor
//----------------------------------------------------------------------------
virtual ~XrdxCastor2StatULongLong() {};
void Inc()
{
cnt++;
}
unsigned long long Get()
{
return cnt;
}
void Reset()
{
cnt = 0;
}
};
......@@ -80,65 +77,64 @@ public:
//------------------------------------------------------------------------------
class XrdxCastor2FsStats
{
private:
private:
long long read300s[300];
long long write300s[300];
long long stat300s[300];
long long readd300s[300];
long long rm300s[300];
long long cmd300s[300];
double readrate1s;
double readrate60s;
double readrate300s;
double writerate1s;
double writerate60s;
double writerate300s;
double statrate1s;
double statrate60s;
double statrate300s;
double readdrate1s;
double readdrate60s;
double readdrate300s;
double rmrate1s;
double rmrate60s;
double rmrate300s;
double cmdrate1s;
double cmdrate60s;
double cmdrate300s;
XrdOucHash<XrdxCastor2StatULongLong> ServerRead;
XrdOucHash<XrdxCastor2StatULongLong> ServerWrite;
XrdOucTable<XrdOucString>* ServerTable;
XrdOucHash<XrdxCastor2StatULongLong> UserRead;
XrdOucHash<XrdxCastor2StatULongLong> UserWrite;
XrdOucTable<XrdOucString>* UserTable;
XrdSysMutex statmutex;
XrdxCastor2Proc* Proc;
public:
public:
//----------------------------------------------------------------------------
//! Constructor
//----------------------------------------------------------------------------
XrdxCastor2FsStats(XrdxCastor2Proc* proc = NULL);
//----------------------------------------------------------------------------
//! Destructor
//----------------------------------------------------------------------------
virtual ~XrdxCastor2FsStats();
void SetProc(XrdxCastor2Proc* proc) ;
void IncRdWr(bool isRW);
void IncRead() ;
......@@ -161,8 +157,6 @@ public:
double CmdRate(int nbins);
void Update();
void UpdateLoop();
};
extern void* XrdxCastor2FsStatsStart(void* pp);
......@@ -18,12 +18,10 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
#ifndef __XCASTOR_FSUFS_HH__
#define __XCASTOR_FSUFS_HH__
#pragma once
/*-----------------------------------------------------------------------------*/
#include "serrno.h"
......@@ -150,5 +148,3 @@ class XrdxCastor2FsUFS
return Cns_closedir(dp);
}
};
#endif // __XCASTOR_FSUFS_HH__
......@@ -18,11 +18,9 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
/*-----------------------------------------------------------------------------*/
#include "XrdxCastor2Proc.hpp"
/*-----------------------------------------------------------------------------*/
......@@ -53,15 +51,13 @@ XrdxCastor2Proc::Open()
system(doit.c_str());
DIR* pd = opendir(mProcDirectory.c_str());
if (!pd)
{
return false;
}
else
if (pd)
{
closedir(pd);
return true;
}
else
return false;
}
......@@ -130,15 +126,12 @@ bool
XrdxCastor2ProcFile::Open()
{
if (mProcSync)
fd = open(fname.c_str(), O_CREAT | O_SYNC | O_RDWR, S_IRWXU | S_IROTH | S_IRGRP);
fd = open(fname.c_str(), O_CREAT | O_SYNC | O_RDWR,
S_IRWXU | S_IROTH | S_IRGRP);
else
fd = open(fname.c_str(), O_CREAT | O_RDWR, S_IRWXU | S_IROTH | S_IRGRP);
if (fd < 0)
return false;
return true;
return (fd >= 0);
}
......@@ -148,7 +141,8 @@ XrdxCastor2ProcFile::Open()
bool
XrdxCastor2ProcFile::Close()
{
if (fd >= 0) close(fd);
if (fd >= 0)
close(fd);
return true;
}
......@@ -192,18 +186,13 @@ XrdxCastor2ProcFile::Write(const char* pbuf, int writedelay)
return true;
}
int result;
mLastWrite = now;
lseek(fd, 0, SEEK_SET);
while ((result =::ftruncate(fd, 0)) && (errno == EINTR)) {}
while (::ftruncate(fd, 0) && (errno == EINTR)) { }
mLastWrite = now;
if ((write(fd, pbuf, strlen(pbuf))) == (ssize_t)(strlen(pbuf)))
return true;
else
return false;
}
return (write(fd, pbuf, strlen(pbuf)) == (ssize_t)(strlen(pbuf)));
}
//------------------------------------------------------------------------------
......@@ -213,9 +202,9 @@ bool
XrdxCastor2ProcFile::WriteKeyVal(const char* key,
unsigned long long value,
int writedelay,
bool dotruncate)
bool do_truncate)
{
if (dotruncate)
if (do_truncate)
{
time_t now = time(NULL);
......@@ -225,21 +214,15 @@ XrdxCastor2ProcFile::WriteKeyVal(const char* key,
return false;
}
// printf("Truncating FD %d for %s\n",fd,key);
mLastWrite = now;
lseek(fd, 0, SEEK_SET);
while ((::ftruncate(fd, 0)) && (errno == EINTR)) {}
mLastWrite = now;
while ((::ftruncate(fd, 0)) && (errno == EINTR)) { }
}
char pbuf[1024];
sprintf(pbuf, "%lu %-32s %lld\n", (unsigned long)time(NULL), key, value);
if ((write(fd, pbuf, strlen(pbuf))) == (ssize_t)(strlen(pbuf)))
return true;
else
return false;
return (write(fd, pbuf, strlen(pbuf)) == (ssize_t)(strlen(pbuf)));
}
......@@ -271,9 +254,5 @@ XrdxCastor2ProcFile::Read(XrdOucString& str)
lseek(fd, 0, SEEK_SET);
ssize_t rb = read(fd, pbuf, sizeof(pbuf));
str = pbuf;
if (rb <= 0)
return false;
else
return true;
return (rb > 0);
}
......@@ -18,7 +18,6 @@
*
*
* @author Castor Dev team, castor-dev@cern.ch
* @author Castor Dev team, castor-dev@cern.ch
*
******************************************************************************/
......@@ -39,8 +38,8 @@
//------------------------------------------------------------------------------
class XrdxCastor2ProcFile
{
public:
public:
//----------------------------------------------------------------------------
//! Constructor
//!
......@@ -49,44 +48,44 @@ public:
//!
//----------------------------------------------------------------------------
XrdxCastor2ProcFile(const char* name, bool syncit = false);
//----------------------------------------------------------------------------
//! Destructor
//----------------------------------------------------------------------------
virtual ~XrdxCastor2ProcFile();