XRootD
Loading...
Searching...
No Matches
XrdOfsTPCInfo.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O f s T P C I n f o . c c */
4/* */
5/* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cstdio>
32#include <cstring>
33#include <strings.h>
34
35#include "XrdNet/XrdNetAddr.hh"
36#include "XrdOfs/XrdOfsStats.hh"
39#include "XrdOss/XrdOss.hh"
42#include "XrdSys/XrdSysError.hh"
43
44/******************************************************************************/
45/* G l o b a l O b j e c t s */
46/******************************************************************************/
47
50extern XrdOss *XrdOfsOss;
51
52namespace XrdOfsTPCParms
53{
54extern XrdOfsTPCConfig Cfg;
55}
56
57/******************************************************************************/
58/* D e s t r u c t o r */
59/******************************************************************************/
60
62{
63// Check if we should remove the file
64//
65 if (isDST && !isAOK && XrdOfsTPCParms::Cfg.autoRM && Lfn)
66 XrdOfsOss->Unlink(Lfn);
67
68// Delete all appendages
69//
70 if (Key) {free(Key); Key = 0;}
71 if (Org) {free(Org); Org = 0;}
72 if (Lfn) {free(Lfn); Lfn = 0;}
73 if (Dst) {free(Dst); Dst = 0;}
74 if (Spr) {free(Spr); Spr = 0;}
75 if (Tpr) {free(Tpr); Tpr = 0;}
76 if (Cks) {free(Cks); Cks = 0;}
77 if (Rpx) {free(Rpx); Rpx = 0;}
78 if (Crd) {free(Crd); Crd = 0; Csz = 0;}
79 if (cbP) delete cbP;
80}
81
82/******************************************************************************/
83/* F a i l */
84/******************************************************************************/
85
86int XrdOfsTPCInfo::Fail(XrdOucErrInfo *eRR, const char *eMsg, int eCode)
87{
88 char Buff[2048];
89
90// Format the error message
91//
92 snprintf(Buff, sizeof(Buff), "Unable to copy %s; %s", Lfn, eMsg);
93
94// Print it out if debugging is enabled
95//
96#ifndef NODEBUG
97 OfsEroute.Emsg("TPC", Org, Buff);
98#endif
99
100// Place the error message in the error object and return
101//
102 if (eRR) eRR->setErrInfo(eCode, Buff);
103 OfsStats.Add(OfsStats.Data.numTPCerrs);
104 return SFS_ERROR;
105}
106
107/******************************************************************************/
108/* M a t c h */
109/******************************************************************************/
110
111int XrdOfsTPCInfo::Match(const char *cKey, const char *cOrg,
112 const char *xLfn, const char *xDst)
113{
114 if (cKey) {if (!Key || strcmp(Key, cKey)) return 0;}
115 else if (Key) return 0;
116
117 if (cOrg) {if (!Org || strcmp(Org, cOrg)) return 0;}
118 else if (Org) return 0;
119
120 if (xLfn) {if (!Lfn || strcmp(Lfn, xLfn)) return 0;}
121 else if (Lfn) return 0;
122
123 if (xDst) {if (!Dst || strcmp(Dst, xDst)) return 0;}
124 else if (Dst) return 0;
125
126 return 1;
127}
128
129/******************************************************************************/
130/* R e p l y */
131/******************************************************************************/
132
133void XrdOfsTPCInfo:: Reply(int rC, int eC, const char *eMsg, XrdSysMutex *mP)
134{
135 XrdOucCallBack *myCB = cbP;
136
137// Clear pointer to call back prior to unlocking any locks
138//
139 cbP = 0;
140
141// Make sure a reply is valid here (i.e. client is in waitresop). If not,
142// then we need to scuttle the whole shebang (must be done with a lock).
143//
144 if (inWtR)
145 {inWtR = false;
146 if (mP) mP->UnLock();
147 if (myCB) myCB->Reply(rC, eC, eMsg, Lfn);
148 } else if (mP) mP->UnLock();
149 delete myCB;
150}
151
152/******************************************************************************/
153/* S e t */
154/******************************************************************************/
155
156const char *XrdOfsTPCInfo::Set(const char *cKey, const char *cOrg,
157 const char *xLfn, const char *xDst,
158 const char *xCks)
159{
160 const char *etext;
161
162// Set the key
163//
164 if (Key) free(Key);
165 Key = (cKey ? strdup(cKey) : 0);
166
167// Set the origin
168//
169 if (Org) free(Org);
170 Org = (cOrg ? strdup(cOrg) : 0);
171
172// Set the lfn
173//
174 if (Lfn) free(Lfn);
175 Lfn = (xLfn ? strdup(xLfn) : 0);
176
177// Set optional dst
178//
179 if (Dst) {free(Dst); Dst = 0;}
180 if (xDst)
181 {XrdNetAddr dAddr;
182 if (!(etext = dAddr.Set(xDst,0)))
183 Dst = strdup(dAddr.Name("0.0.0.0",&etext));
184 if (etext) return etext;
185 }
186
187// Set the cks
188//
189 if (Cks) free(Cks);
190 Cks = (xCks ? strdup(xCks) : 0);
191
192// All done
193//
194 return 0;
195}
196
197/******************************************************************************/
198/* S e t C B */
199/******************************************************************************/
200
202{
203 if (cbP) delete cbP;
204 cbP = new XrdOucCallBack();
205 if ((cbP->Init(eRR))) return 0;
206 delete cbP; cbP = 0;
207 return Fail(eRR, "tpc callback logic error", EPROTO);
208}
XrdSysError OfsEroute(0)
XrdOss * XrdOfsOss
Definition XrdOfs.cc:163
XrdOfsStats OfsStats
Definition XrdOfs.cc:113
#define eMsg(x)
#define SFS_ERROR
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
int Match(const char *cKey, const char *cOrg, const char *xLfn, const char *xDst)
XrdOucCallBack * cbP
int SetCB(XrdOucErrInfo *eRR)
const char * Set(const char *cKey, const char *cOrg, const char *xLfn, const char *xDst, const char *xCks=0)
void Reply(int rC, int eC, const char *eMsg, XrdSysMutex *mP=0)
int Fail(XrdOucErrInfo *eRR, const char *eMsg, int eCode)
int Reply(int retVal, int eValue, const char *eText, const char *Path=0)
int setErrInfo(int code, const char *emsg)
XrdOfsTPCConfig Cfg
Definition XrdOfsTPC.cc:85