65 #include <stager_api.h> 67 #define RFIO_KERNEL // Get access to extra symbols in the headers 68 #include <stage_api.h> 72 #include <rfio_constants.h> 74 #define RFIO_USE_CASTOR_V2 "RFIO_USE_CASTOR_V2" 75 #define RFIO_HSM_BASETYPE 0x0 76 #define RFIO_HSM_CNS RFIO_HSM_BASETYPE+1 79 extern "C" {
int rfio_parse(
char *,
char **,
char **); }
81 extern "C" {
char *
getconfent(
char *,
char *,
int); }
84 extern int tStageHostKey;
85 extern int tStagePortKey;
86 extern int tSvcClassKey;
87 extern int tCastorVersionKey;
88 extern "C" {
int use_castor2_api(); }
94 int version = use_castor2_api();
106 ((p =
getconfent(
"RFIO",
"USE_CASTOR_V2",0)) == 0)) {
110 if ((strcmp(p,
"YES") == 0) || (strcmp(p,
"yes") == 0) || (atoi(p) == 1)) {
114 ::Warning(
"UseCastor2API",
"asked to use CASTOR 2, but linked with CASTOR 1");
129 const Int_t rootNumSec = 6;
130 const char *protoSec[rootNumSec] = {
"rootup",
"roots",
"rootk",
131 "rootg",
"rooth",
"rootug" };
144 p = getenv(
"ROOTCASTORAUTH");
149 if (sec < 0 || sec > (rootNumSec - 1))
154 return ((sec > -1 && sec < rootNumSec) ? protoSec[sec] :
"root");
180 Info(
"TCastorFile",
"fAuthProto = %s, u: %s", fAuthProto.Data(), u.
Data());
186 if (opt ==
"NEW" || opt ==
"CREATE")
189 Create(url, opt, netopt);
213 castorturl.
Form(
"%s",(!name || !strstr(name,
"/castor"))?fname.Data():
name);
214 fname = castorturl.
Data();
223 struct stgcat_entry *stcp_output = 0;
226 int flags = O_RDONLY;
227 struct Cns_filestat st;
229 char stageoutbuf[1025];
230 char stageerrbuf[1025];
233 if (strlen(
fUrl.
GetFile()) > STAGE_MAX_HSMLENGTH) {
234 serrno = ENAMETOOLONG;
235 Error(
"FindServerAndPath",
"can't open %s, error %d (%s)",
fUrl.
GetFile(), serrno, sstrerror(serrno));
243 flags |= O_CREAT | O_TRUNC;
246 memset(&st, 0,
sizeof(st));
251 if (rc == -1 || ((flags & O_TRUNC) != 0))
255 if (stage_setoutbuf(stageoutbuf, 1024) != 0) {
256 Error(
"FindServerAndPath",
"can't open %s, stage_setoutbuf, error %d (%s)",
260 if (stage_seterrbuf(stageerrbuf, 1024) != 0) {
261 Error(
"FindServerAndPath",
"can't open %s, stage_seterrbuf, error %d (%s)",
266 struct stgcat_entry stcp_input;
269 memset(&stcp_input, 0,
sizeof(
struct stgcat_entry));
270 strlcpy(stcp_input.u1.h.xfile,
fUrl.
GetFile(),
sizeof(stcp_input.u1.h.xfile));
271 if (flags == O_RDONLY || st.filesize > 0) {
273 if (stage_in_hsm((u_signed64) 0,
278 (
struct stgcat_entry *) &stcp_input,
279 (
int *) &nstcp_output,
280 (
struct stgcat_entry **) &stcp_output,
282 (
struct stgpath_entry *) 0
284 Error(
"FindServerAndPath",
"can't open %s, stage_in_hsm error %d (%s)",
290 if (stage_out_hsm((u_signed64) 0,
297 (
struct stgcat_entry *) &stcp_input,
298 (
int *) &nstcp_output,
299 (
struct stgcat_entry **) &stcp_output,
301 (
struct stgpath_entry *) 0
303 Error(
"FindServerAndPath",
"can't open %s, stage_out_hsm error %d (%s)",
308 if ((nstcp_output != 1) || (stcp_output == 0) ||
309 (*(stcp_output->ipath) ==
'\0')) {
312 if (stcp_output != 0)
free(stcp_output);
313 Error(
"FindServerAndPath",
"can't open %s, error %d (%s)",
322 rfio_parse(stcp_output->ipath, &realhost, &filename);
325 Error(
"FindServerAndPath",
"can't open %s, get disk server hostname from %s error %d (%s)",
326 fUrl.
GetFile(), stcp_output->ipath, errno, sstrerror(serrno));
332 if (filename[0] !=
'/') {
340 if (st.filesize == 0) {
389 int flags = O_RDONLY;
391 struct stage_io_fileresp *response = 0;
392 char *requestId = 0, *url = 0;
393 char stageerrbuf[1025];
399 flags |= O_CREAT | O_TRUNC;
401 stage_seterrbuf(stageerrbuf, 1024);
405 struct stage_options opts;
408 opts.service_class=0;
409 opts.stage_version=0;
411 void *ptrPoint = &auxPoint;
412 void *ptrVal = &auxVal;
413 int ret=Cglobals_get(& tStageHostKey, (
void**)ptrPoint,
sizeof(
void*));
415 opts.stage_host=*auxPoint;
417 ret=Cglobals_get(& tStagePortKey, (
void**)ptrVal,
sizeof(
int));
419 opts.stage_port=*auxVal;
421 opts.stage_version=2;
422 ret=Cglobals_get(& tSvcClassKey, (
void**)ptrPoint,
sizeof(
void*));
424 opts.service_class=*auxPoint;
430 (
char *)fname.Data(),
439 Error(
"FindServerAndPath",
"stage_open failed: %s (%s)",
440 sstrerror(serrno), stageerrbuf);
441 if (response)
free(response);
442 if (requestId)
free(requestId);
447 Error(
"FindServerAndPath",
"response was null for %s (Request %s) %d/%s",
448 fname.Data(), requestId,
449 serrno, sstrerror(serrno));
450 if (requestId)
free(requestId);
454 if (response->errorCode != 0) {
455 serrno = response->errorCode;
456 Error(
"FindServerAndPath",
"error getting file %s (Request %s) %d/%s",
457 fname.Data(), requestId,
458 serrno, sstrerror(serrno));
460 if (requestId)
free(requestId);
464 url = stage_geturl(response);
467 Error(
"FindServerAndPath",
"error getting file %s (Request %s) %d/%s",
468 fname.Data(), requestId,
469 serrno, sstrerror(serrno));
471 if (requestId)
free(requestId);
492 if (response)
free(response);
494 if (requestId)
free(requestId);
538 memset(&hsmfile, 0,
sizeof(hsmfile));
540 if (stage_updc_filchg(0, &hsmfile) < 0) {
541 Error(
"WriteBuffer",
"error calling stage_updc_filchg");
542 delete [] hsmfile.upath;
545 delete [] hsmfile.upath;
virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)
Connect to remote rootd server.
#define RFIO_USE_CASTOR_V2
Int_t SysClose(Int_t fd)
Close currently open file.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
const char * GetHostName() const
This class represents a WWW compatible URL.
TString & ReplaceAll(const TString &s1, const TString &s2)
const char * GetProtocol() const
This class represents an Internet Protocol (IP) address.
void ToUpper()
Change string to upper case.
char * getconfent(char *, char *, int)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Bool_t fIsCastor
true if internal path is valid
const char * GetOptions() const
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Int_t SysClose(Int_t fd)
Close currently open file.
void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)
Connect to remote rootd server on CASTOR disk server.
const char * GetFile() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
int rfio_HsmIf_reqtoput(char *)
void Info(const char *location, const char *msgfmt,...)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
void FindServerAndPath()
Find the CASTOR disk server and internal file path.
A TNetFile interfaced to the Castor storage backend.
R__EXTERN TSystem * gSystem
Bool_t fWrittenTo
true if data has been written to file
static const char * GetAuthProto(TString &url)
Determine the authentication protocol to be tried first from the url string or from defaults...
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString fAuthProto
Used to specific the auth protocol.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
int rfio_HsmIf_IsHsmFile(const char *)
void Warning(const char *location, const char *msgfmt,...)
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
char * StrDup(const char *str)
Duplicate the string str.
TString & Remove(Ssiz_t pos)
static int UseCastor2API()
TString fOption
File options.
TString fDiskServer
CASTOR remote disk server.
int rfio_parse(char *, char **, char **)
TString fInternalPath
CASTOR internal path.
Int_t Atoi() const
Return integer value of string.
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
const char * Data() const