XRootD
Loading...
Searching...
No Matches
XrdOssArcCompose Class Reference

#include <XrdOssArcCompose.hh>

Collaboration diagram for XrdOssArcCompose:

Public Types

enum  pType {
  isARC =0 ,
  isBKP
}

Public Member Functions

 XrdOssArcCompose (const char *path, XrdOucEnv *env, int &retc, bool isW=true, bool optfn=false)
 ~XrdOssArcCompose ()
int ArcMember (char *buff, int blen)
int ArcPath (char *buff, int blen, bool addafn=false)

Static Public Member Functions

static std::string Dir2DSN (const char *dir)
static std::string DSN2Dir (const char *dsn)
static bool isArcFile (const char *path)
static bool isArcPath (const char *path)
static bool isBkpPath (const char *path)
static bool isMine (const char *path)
static int Stat (const char *Scope, const char *Name, struct stat *Stat)

Public Attributes

std::string arName
pType didType
std::string dsName
std::string dsScope
std::string flName
std::string flScope

Detailed Description

Definition at line 39 of file XrdOssArcCompose.hh.

Member Enumeration Documentation

◆ pType

Enumerator
isARC 
isBKP 

Definition at line 50 of file XrdOssArcCompose.hh.

Constructor & Destructor Documentation

◆ XrdOssArcCompose()

XrdOssArcCompose::XrdOssArcCompose ( const char * path,
XrdOucEnv * env,
int & retc,
bool isW = true,
bool optfn = false )

Definition at line 73 of file XrdOssArcCompose.cc.

75{
76 TraceInfo("Compose",0);
77
78// By conventioon, the env["ossarc.fn"] holds the file did and the path is
79// the dataset did both represented as paths. We only support two path
80// prefixes: 1) the archive prefix, and 2) the backup prefix. These are
81// removed but we track which one it was as they have different semantics.
82//
83
84// Determine the path type being referenced
85//
86 if (!strncmp(Config.arcvPathLFN, path, Config.arcvPathLEN))
87 {didType = isARC;
88 path += Config.arcvPathLEN;
89 }
90 else if (!strncmp(Config.arcvPathLFN, path, Config.arcvPathLEN-1)
91 && strlen(path) < (size_t)Config.arcvPathLEN)
92 {didType = isARC;
93 path += Config.arcvPathLEN-1;
94 }
95 else if (!strncmp(Config.bkupPathLFN, path, Config.bkupPathLEN))
96 {didType = isBKP;
97 path += Config.bkupPathLEN;
98 optfn = false; // ossarc.fn is required for /backup
99 }
100 else {rc = EDOM; return;} // This will forward the request
101
102// Get the dataset name and if there is no ENV, we can return as this is
103// only a construction for datasets.
104//
105 if ((rc = getDSN(path))) return;
106 if (!env) {rc = 0; return;}
107
108// Prepare for full construction (note: we know we have an env pointer)
109//
110 const char* theFN = 0;
111 bool fl2arc = false;
112 bool fscpDS = false;
113
114// This is our domain and that domain is strictly read/only
115//
116 if (isW) {rc = EROFS; return;}
117
118// Make sure we have an env file name to work with. This must come from the CGI
119// if /backup and from either the CGI path for /archive. We support optional
120// path specification to allow recursive copies of all dataset archive files.
121// Noe that we ignore the CGI if specified via the path.
122//
123 if (didType == isARC && isArcFile(path))
124 {const char* fn = rindex(path, '/');
125 if (fn && fn != path)
126 {theFN = fn + 1;
127 dsName.erase(dsName.find_last_of("/"));
128 }
129 }
130
131 if (!theFN && !(theFN = env->Get("ossarc.fn")))
132 {if (optfn) rc = 0;
133 else {rc = EINVAL;
134 ecMsg.Msg("Compose","CGI ossarc.fn=<target_fname> not specified");
135 }
136 return;
137 }
138
139// If the archive if the target then env filename may refer to a specific
140// archive or be a file that is to be used to determine the target archive.
141// Otherwise, it should refer to a single file backups so an arc file suffix
142// is disallowed as it makes to sense.
143//
144 if (isArcFile(theFN))
145 {if (didType == isBKP)
146 {rc = EINVAL;
147 ecMsg.Msg("Compose","Backup filename cannot refer to an archive");
148 return;
149 }
150 arName = theFN;
151 } else fl2arc = true;
152
153
154// Pick apart the filename if this is a backup reference or an indirect
155// archive reference as we will need the scope and file.
156//
157 if ((didType == isBKP) || fl2arc)
158 {const char* colon = index(theFN, ':');
159 if (!colon)
160 {flScope = dsScope;
161 flName = theFN;
162 fscpDS = true; // For tracing purposes
163 } else {
164 if (*theFN == ':')
165 {rc = EINVAL;
166 ecMsg.Msg("Compose","File scope not specified though implied");
167 return;
168 }
169 flScope.assign(theFN, colon - theFN);
170 flName = colon+1;
171 }
172 if ((int)flName.length() < minLenDSN)
173 {rc = EINVAL;
174 ecMsg.Msg("Compose", "Dataset name is too short");
175 return;
176 }
177 }
178
179// Do some debugging
180//
181 const char* atName[] = {"Archive", "Backup"};
182
183 DEBUG("Type="<<atName[didType]<<" f2a="<<fl2arc<<" fscpDF="<<fscpDS
184 <<" dsScope="<<dsScope<<" dsName="<<dsName
185 <<" flScope="<<flScope<<" flName="<<flName<<" arName="<<arName);
186
187// Set the archive name if we need to
188//
189 rc = (fl2arc ? SetarName() : 0);
190}
#define DEBUG(x)
#define TraceInfo(x, y)
static bool isArcFile(const char *path)
std::string Msg()
char * Get(const char *varname)
Definition XrdOucEnv.hh:69
XrdOssArcConfig Config
Definition XrdOssArc.cc:68

References arName, XrdOssArcGlobals::Config, DEBUG, didType, dsName, dsScope, XrdOssArcGlobals::ecMsg, flName, flScope, XrdOucEnv::Get(), isARC, isArcFile(), isBKP, and TraceInfo.

Here is the call graph for this function:

◆ ~XrdOssArcCompose()

XrdOssArcCompose::~XrdOssArcCompose ( )
inline

Definition at line 73 of file XrdOssArcCompose.hh.

73{}

Member Function Documentation

◆ ArcMember()

int XrdOssArcCompose::ArcMember ( char * buff,
int blen )

Definition at line 196 of file XrdOssArcCompose.cc.

197{
198 if (snprintf(buff, blen, "%s:%s", flScope.c_str(), flName.c_str()) >= blen)
199 {std::string fn = flScope + ":" + flName;
200 Elog.Emsg("Compose", ENAMETOOLONG, "generate archive member name "
201 "in dataset", dsName.c_str());
202 ecMsg.Msg("Compose", "Archive member name", fn.c_str(), "is too long");
203 return ENAMETOOLONG;
204 }
205 return 0;
206}
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysError Elog(0, "OssArc_")

References dsName, XrdOssArcGlobals::ecMsg, XrdOssArcGlobals::Elog, flName, and flScope.

Referenced by XrdOssArcFile::Open().

Here is the caller graph for this function:

◆ ArcPath()

int XrdOssArcCompose::ArcPath ( char * buff,
int blen,
bool addafn = false )

Definition at line 212 of file XrdOssArcCompose.cc.

213{
214 int n;
215
216// The path to the archive is <tape_path>/<scope>/<dataset_did>/<arc_fname>
217//
218 if (addafn) n = snprintf(buff, blen, "%s/%s/%s/%s", Config.tapePath,
219 dsScope.c_str(), dsName.c_str(), arName.c_str());
220 else n = snprintf(buff, blen, "%s/%s/%s", Config.tapePath,
221 dsScope.c_str(), dsName.c_str());
222
223// Verify that we did not truncate the path
224//
225 if (n >= blen)
226 {std::string dsn = dsScope + ":" + dsName;
227 Elog.Emsg("Compose", ENAMETOOLONG, "generate archive path for dataset",
228 dsn.c_str());
229 return ENAMETOOLONG;
230 }
231
232// All done
233//
234 return 0;
235}

References arName, XrdOssArcGlobals::Config, dsName, dsScope, and XrdOssArcGlobals::Elog.

Referenced by XrdOssArcFile::Open(), XrdOssArcDir::Opendir(), and XrdOssArc::Stat().

Here is the caller graph for this function:

◆ Dir2DSN()

std::string XrdOssArcCompose::Dir2DSN ( const char * dir)
static

Definition at line 255 of file XrdOssArcCompose.cc.

256{
257 std::string retdsn(dir);
258 int n = retdsn.length();
259
260 for (int i = 0; i < n; i++) if (retdsn[i] == '%') retdsn[i] = '/';
261
262 return retdsn;
263}

◆ DSN2Dir()

std::string XrdOssArcCompose::DSN2Dir ( const char * dsn)
static

Definition at line 241 of file XrdOssArcCompose.cc.

242{
243 std::string retdir(dsn);
244 int n = retdir.length();
245
246 for (int i = 0; i < n; i++) if (retdir[i] == '/') retdir[i] = '%';
247
248 return retdir;
249}

Referenced by XrdOssArcBackupTask::BkpXeq().

Here is the caller graph for this function:

◆ isArcFile()

bool XrdOssArcCompose::isArcFile ( const char * path)
static

Definition at line 305 of file XrdOssArcCompose.cc.

306{
307 int n = strlen(path);
308
309// Is it's too short, it cannot end with ".zip" (or what it the suffix is)
310//
311 if (n <= Config.arfSfxLen) return false;
312
313// Verify the ending
314//
315 return !strcmp(Config.arfSfx, path+n-Config.arfSfxLen);
316}

References XrdOssArcGlobals::Config.

Referenced by XrdOssArcCompose().

Here is the caller graph for this function:

◆ isArcPath()

bool XrdOssArcCompose::isArcPath ( const char * path)
static

Definition at line 322 of file XrdOssArcCompose.cc.

323{
324 return !strncmp(Config.arcvPathLFN, path, Config.arcvPathLEN);
325}

References XrdOssArcGlobals::Config.

◆ isBkpPath()

bool XrdOssArcCompose::isBkpPath ( const char * path)
static

Definition at line 331 of file XrdOssArcCompose.cc.

332{
333 return !strncmp(Config.bkupPathLFN, path, Config.bkupPathLEN);
334}

References XrdOssArcGlobals::Config.

◆ isMine()

bool XrdOssArcCompose::isMine ( const char * path)
static

Definition at line 340 of file XrdOssArcCompose.cc.

341{
342 return !strncmp(Config.arcvPathLFN, path, Config.arcvPathLEN) ||
343 !strncmp(Config.bkupPathLFN, path, Config.bkupPathLEN);
344}

References XrdOssArcGlobals::Config.

Referenced by XrdOssArc::Chmod(), XrdOssArc::Create(), XrdOssArc::Lfn2Pfn(), XrdOssArc::Mkdir(), XrdOssArc::Remdir(), XrdOssArc::Rename(), XrdOssArc::Truncate(), and XrdOssArc::Unlink().

Here is the caller graph for this function:

◆ Stat()

int XrdOssArcCompose::Stat ( const char * Scope,
const char * Name,
struct stat * Stat )
static

Definition at line 407 of file XrdOssArcCompose.cc.

409{
410 TraceInfo("Stat", 0);
411
412// Setup argument list for a stat call
413//
414 const char* argV[] = {"stat", "cgi", Scope, Name};
415 int argC = sizeof(argV)/sizeof(char*);
416 int rc, rc2 = 0;
417
418// Do some tracing
419//
420 DEBUG("Running "<<Config.BkpUtilName<<' '<<argV[0]<<' '
421 <<argV[1]<<' '<<argV[2]<<' '<<argV[3]);
422
423// Execute command, it should return a single line of output
424//
425 XrdOucStream cmdSup;
426 bool aOK = false;
427
428 if (!(rc = Config.BkpUtilProg->Run(&cmdSup, argV, argC)))
429 {char* resp;
430 if (cmdSup.GetLine() && (resp = cmdSup.GetToken()) && *resp)
431 {if (*resp != '!')
432 {if (!(rc = StatDecode(*Stat, resp))) aOK = true;
433 else if (!strcmp("!ENOENT", resp)) rc = ENOENT;
434 else rc = EINVAL;
435 }
436 }
437 rc2 = Config.BkpUtilProg->RunDone(cmdSup);
438 }
439
440// Check if we have a result, that implies all went well enough
441//
442 if (aOK) return 0;
443 if (rc) return rc;
444 if (rc2) return rc2;
445 return EPROTO;
446}
static int Stat(const char *Scope, const char *Name, struct stat *Stat)
const char * BkpUtilName
XrdOucProg * BkpUtilProg
int RunDone(XrdOucStream &cmd) const
int Run(XrdOucStream *Sp, const char *argV[], int argc=0, const char *envV[]=0) const
char * GetLine()
char * GetToken(int lowcase=0)

References XrdOssArcGlobals::Config, DEBUG, XrdOucStream::GetLine(), XrdOucStream::GetToken(), Stat(), stat, and TraceInfo.

Referenced by XrdOssArc::Stat(), and Stat().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ arName

std::string XrdOssArcCompose::arName

Definition at line 48 of file XrdOssArcCompose.hh.

Referenced by XrdOssArcCompose(), and ArcPath().

◆ didType

pType XrdOssArcCompose::didType

◆ dsName

std::string XrdOssArcCompose::dsName

Definition at line 45 of file XrdOssArcCompose.hh.

Referenced by XrdOssArcCompose(), ArcMember(), and ArcPath().

◆ dsScope

std::string XrdOssArcCompose::dsScope

Definition at line 44 of file XrdOssArcCompose.hh.

Referenced by XrdOssArcCompose(), and ArcPath().

◆ flName

std::string XrdOssArcCompose::flName

Definition at line 47 of file XrdOssArcCompose.hh.

Referenced by XrdOssArcCompose(), ArcMember(), and XrdOssArc::Stat().

◆ flScope

std::string XrdOssArcCompose::flScope

Definition at line 46 of file XrdOssArcCompose.hh.

Referenced by XrdOssArcCompose(), ArcMember(), and XrdOssArc::Stat().


The documentation for this class was generated from the following files: