65#include <stager_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
84extern int tStageHostKey;
85extern int tStagePortKey;
86extern int tSvcClassKey;
87extern int tCastorVersionKey;
88extern "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");
186 if (opt ==
"NEW" || opt ==
"CREATE")
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;
int rfio_HsmIf_reqtoput(char *)
#define RFIO_USE_CASTOR_V2
static const char * GetAuthProto(TString &url)
Determine the authentication protocol to be tried first from the url string or from defaults.
int rfio_parse(char *, char **, char **)
static int UseCastor2API()
int rfio_HsmIf_IsHsmFile(const char *)
char * getconfent(char *, char *, int)
void Warning(const char *location, const char *msgfmt,...)
char * StrDup(const char *str)
Duplicate the string str.
R__EXTERN TSystem * gSystem
A TNetFile interfaced to the Castor storage backend.
Bool_t fWrittenTo
true if data has been written to file
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Bool_t fIsCastor
true if internal path is valid
Int_t SysClose(Int_t fd)
Close currently open file.
TString fInternalPath
CASTOR internal path.
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.
TString fDiskServer
CASTOR remote disk server.
void FindServerAndPath()
Find the CASTOR disk server and internal file path.
TString fAuthProto
Used to specific the auth protocol.
TString fOption
File options.
This class represents an Internet Protocol (IP) address.
const char * GetHostName() const
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
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.
Int_t SysClose(Int_t fd)
Close currently open file.
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
const char * Data() const
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
TString & ReplaceAll(const TString &s1, const TString &s2)
void ToUpper()
Change string to upper case.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(Ssiz_t pos)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
This class represents a WWW compatible URL.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
const char * GetFile() const
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
const char * GetOptions() const
const char * GetProtocol() const