XRootD
XrdOfsPoscq Class Reference

#include <XrdOfsPoscq.hh>

+ Collaboration diagram for XrdOfsPoscq:

Classes

struct  recEnt
 
struct  Request
 

Public Member Functions

 XrdOfsPoscq (XrdSysError *erp, XrdOss *oss, const char *fn, int sv=1)
 
 ~XrdOfsPoscq ()
 
int Add (const char *Tident, const char *Lfn, bool isNew)
 
int Commit (const char *Lfn, int Offset)
 
int Del (const char *Lfn, int Offset, int Unlink=0)
 
recEntInit (int &Ok)
 
int Num ()
 

Static Public Member Functions

static recEntList (XrdSysError *Say, const char *theFN)
 

Static Public Attributes

static const int ReqOffs = 64
 
static const int ReqSize = sizeof(Request)
 

Detailed Description

Definition at line 41 of file XrdOfsPoscq.hh.


Class Documentation

◆ XrdOfsPoscq::Request

struct XrdOfsPoscq::Request

Definition at line 45 of file XrdOfsPoscq.hh.

+ Collaboration diagram for XrdOfsPoscq::Request:
Class Members
long long addT
char LFN[1024]
char Reserved[24]
char User[288]

Constructor & Destructor Documentation

◆ XrdOfsPoscq()

XrdOfsPoscq::XrdOfsPoscq ( XrdSysError erp,
XrdOss oss,
const char *  fn,
int  sv = 1 
)

Definition at line 53 of file XrdOfsPoscq.cc.

54 {
55  eDest = erp;
56  ossFS = oss;
57  pocFN = strdup(fn);
58  pocFD = -1;
59  pocSZ = 0;
60  pocIQ = 0;
61  SlotList = SlotLust = 0;
62 
63  if (sv > 32767) sv = 32767;
64  else if (sv < 0) sv = 0;
65  pocWS = pocSV = sv-1;
66 }

◆ ~XrdOfsPoscq()

XrdOfsPoscq::~XrdOfsPoscq ( )
inline

Definition at line 80 of file XrdOfsPoscq.hh.

80 {}

Member Function Documentation

◆ Add()

int XrdOfsPoscq::Add ( const char *  Tident,
const char *  Lfn,
bool  isNew 
)

Definition at line 72 of file XrdOfsPoscq.cc.

73 {
74  XrdSysMutexHelper myHelp(myMutex);
75  std::map<std::string,int>::iterator it = pqMap.end();
76  XrdOfsPoscq::Request tmpReq;
77  struct stat Stat;
78  FileSlot *freeSlot;
79  int fP;
80 
81 // Add is only called when file is to be created. Therefore, it must not exist
82 // unless it is being replaced typically due to a retry. If not being replaced
83 // then We need to check this to avoid deleting already created files.
84 // Otherwise, we need to see if the file is already in the queue to avoid it
85 // being deleted after the fact because it would be in the queue twice.
86 //
87  if (!ossFS->Stat(Lfn, &Stat))
88  {if (isNew) return -EEXIST;
89  it = pqMap.find(std::string(Lfn));
90  if (it != pqMap.end() && VerOffset(Lfn, it->second)) return it->second;
91  }
92 
93 // Construct the request
94 //
95  tmpReq.addT = 0;
96  strlcpy(tmpReq.LFN, Lfn, sizeof(tmpReq.LFN));
97  strlcpy(tmpReq.User, Tident, sizeof(tmpReq.User));
98  memset(tmpReq.Reserved, 0, sizeof(tmpReq.Reserved));
99 
100 // Obtain a free slot
101 //
102  if ((freeSlot = SlotList))
103  {fP = freeSlot->Offset;
104  SlotList = freeSlot->Next;
105  freeSlot->Next = SlotLust;
106  SlotLust = freeSlot;
107  } else {fP = pocSZ; pocSZ += ReqSize;}
108  pocIQ++;
109 
110 // Write out the record
111 //
112  if (!reqWrite((void *)&tmpReq, sizeof(tmpReq), fP))
113  {eDest->Emsg("Add", Lfn, "not added to the persist queue.");
114  myMutex.Lock(); pocIQ--; myMutex.UnLock();
115  return -EIO;
116  }
117 
118 // Check if we update the map or simply add it to the map
119 //
120  if (it != pqMap.end()) it->second = fP;
121  else pqMap[std::string(Lfn)] = fP;
122 
123 // Return the record offset
124 //
125  return fP;
126 }
struct stat Stat
Definition: XrdCks.cc:49
static XrdSysError eDest(0,"crypto_")
int stat(const char *path, struct stat *buf)
size_t strlcpy(char *dst, const char *src, size_t sz)
static const int ReqSize
Definition: XrdOfsPoscq.hh:54
virtual int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *envP=0)=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdOfsPoscq::Request::addT, eDest, XrdSysError::Emsg(), XrdOfsPoscq::Request::LFN, XrdSysMutex::Lock(), ReqSize, XrdOfsPoscq::Request::Reserved, Stat, stat(), XrdOss::Stat(), strlcpy(), XrdSysMutex::UnLock(), and XrdOfsPoscq::Request::User.

Referenced by XrdOfsFile::open().

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

◆ Commit()

int XrdOfsPoscq::Commit ( const char *  Lfn,
int  Offset 
)

Definition at line 132 of file XrdOfsPoscq.cc.

133 {
134  long long addT = static_cast<long long>(time(0));
135 
136 // Verify the offset it must be correct
137 //
138  if (!VerOffset(Lfn, Offset)) return -EINVAL;
139 
140 // Indicate the record is free
141 //
142  if (!reqWrite((void *)&addT, sizeof(addT), Offset))
143  {eDest->Emsg("Commit", Lfn, "not committed to the persist queue.");
144  return -EIO;
145  }
146 
147 // Remove entry from the map and return
148 //
149  myMutex.Lock();
150  pqMap.erase(std::string(Lfn));
151  myMutex.UnLock();
152  return 0;
153 }

References eDest, XrdSysError::Emsg(), XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdOfsFile::open().

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

◆ Del()

int XrdOfsPoscq::Del ( const char *  Lfn,
int  Offset,
int  Unlink = 0 
)

Definition at line 159 of file XrdOfsPoscq.cc.

160 {
161  static int Zero = 0;
162  FileSlot *freeSlot;
163  int retc;
164 
165 // Verify the offset it must be correct
166 //
167  if (!VerOffset(Lfn, Offset)) return -EINVAL;
168 
169 // Unlink the file if need be
170 //
171  if (Unlink && (retc = ossFS->Unlink(Lfn)) && retc != -ENOENT)
172  {eDest->Emsg("Del", retc, "remove", Lfn);
173  return (retc < 0 ? retc : -retc);
174  }
175 
176 // Indicate the record is free
177 //
178  if (!reqWrite((void *)&Zero, sizeof(Zero), Offset+offsetof(Request,LFN)))
179  {eDest->Emsg("Del", Lfn, "not removed from the persist queue.");
180  return -EIO;
181  }
182 
183 // Serialize and place this on the free queue
184 //
185  myMutex.Lock();
186  if ((freeSlot = SlotLust)) SlotLust = freeSlot->Next;
187  else freeSlot = new FileSlot;
188  freeSlot->Offset = Offset;
189  freeSlot->Next = SlotList;
190  SlotList = freeSlot;
191  if (pocIQ > 0) pocIQ--;
192 
193 // Remove item from the map
194 //
195  pqMap.erase(std::string(Lfn));
196  myMutex.UnLock();
197 
198 // All done
199 //
200  return 0;
201 }
virtual int Unlink(const char *path, int Opts=0, XrdOucEnv *envP=0)=0
XRootDStatus Unlink(Davix::DavPosix &davix_client, const std::string &url, uint16_t timeout)

References eDest, XrdSysError::Emsg(), XrdSysMutex::Lock(), XrdOss::Unlink(), Posix::Unlink(), and XrdSysMutex::UnLock().

Referenced by XrdOfsFile::close(), XrdOfsFile::open(), and XrdOfs::Unpersist().

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

◆ Init()

XrdOfsPoscq::recEnt * XrdOfsPoscq::Init ( int &  Ok)

Definition at line 207 of file XrdOfsPoscq.cc.

208 {
209  static const int Mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
210  Request tmpReq;
211  struct stat buf, Stat;
212  recEnt *First = 0;
213  char Buff[80];
214  int rc, Offs, numreq = 0;
215 
216 // Assume we will fail
217 //
218  Ok = 0;
219 
220 // Open the file first in r/w mode
221 //
222  if ((pocFD = XrdSysFD_Open(pocFN, O_RDWR|O_CREAT, Mode)) < 0)
223  {eDest->Emsg("Init",errno,"open",pocFN);
224  return 0;
225  }
226 
227 // Get file status
228 //
229  if (fstat(pocFD, &buf)) {FailIni("stat"); return 0;}
230 
231 // Check for a new file here
232 //
233  if (buf.st_size < ReqSize)
234  {pocSZ = ReqOffs;
235  if (ftruncate(pocFD, ReqOffs)) FailIni("trunc");
236  else Ok = 1;
237  return 0;
238  }
239 
240 // Read the full file
241 //
242  for (Offs = ReqOffs; Offs < buf.st_size; Offs += ReqSize)
243  {do {rc = pread(pocFD, (void *)&tmpReq, ReqSize, Offs);}
244  while(rc < 0 && errno == EINTR);
245  if (rc < 0) {eDest->Emsg("Init",errno,"read",pocFN); return First;}
246  if (*tmpReq.LFN == '\0'
247  || ossFS->Stat(tmpReq.LFN, &Stat)
248  || !(S_ISREG(Stat.st_mode) || !(Stat.st_mode & XRDSFS_POSCPEND))) continue;
249  First = new recEnt(tmpReq, Stat.st_mode & S_IAMB, First); numreq++;
250  }
251 
252 // Now write out the file and return
253 //
254  sprintf(Buff, " %d pending create%s", numreq, (numreq != 1 ? "s" : ""));
255  eDest->Say("Init", Buff, " recovered from ", pocFN);
256  if (ReWrite(First)) Ok = 1;
257  return First;
258 }
#define S_IAMB
Definition: XrdConfig.cc:159
int ftruncate(int fildes, off_t offset)
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
int fstat(int fildes, struct stat *buf)
int Mode
#define XRDSFS_POSCPEND
Definition: XrdSfsFlags.hh:89
static const int ReqOffs
Definition: XrdOfsPoscq.hh:53
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
Definition: XrdSysError.cc:141

References eDest, XrdSysError::Emsg(), fstat(), ftruncate(), XrdOfsPoscq::Request::LFN, Mode, pread(), ReqOffs, ReqSize, S_IAMB, XrdSysError::Say(), Stat, stat(), XrdOss::Stat(), and XRDSFS_POSCPEND.

+ Here is the call graph for this function:

◆ List()

XrdOfsPoscq::recEnt * XrdOfsPoscq::List ( XrdSysError Say,
const char *  theFN 
)
static

Definition at line 264 of file XrdOfsPoscq.cc.

265 {
266  XrdOfsPoscq::Request tmpReq;
267  struct stat buf;
268  recEnt *First = 0;
269  int rc, theFD, Offs;
270 
271 // Open the file first in r/o mode
272 //
273  if ((theFD = XrdSysFD_Open(theFN, O_RDONLY)) < 0)
274  {Say->Emsg("Init",errno,"open",theFN);
275  return 0;
276  }
277 
278 // Get file status
279 //
280  if (fstat(theFD, &buf))
281  {Say->Emsg("Init",errno,"stat",theFN);
282  close(theFD);
283  return 0;
284  }
285  if (buf.st_size < ReqSize) buf.st_size = 0;
286 
287 // Read the full file
288 //
289  for (Offs = ReqOffs; Offs < buf.st_size; Offs += ReqSize)
290  {do {rc = pread(theFD, (void *)&tmpReq, ReqSize, Offs);}
291  while(rc < 0 && errno == EINTR);
292  if (rc < 0) {Say->Emsg("List",errno,"read",theFN);
293  close(theFD); return First;
294  }
295  if (*tmpReq.LFN != '\0') First = new recEnt(tmpReq, 0, First);
296  }
297 
298 // All done
299 //
300  close(theFD);
301  return First;
302 }
#define close(a)
Definition: XrdPosix.hh:43
XrdSysError Say

References close, XrdSysError::Emsg(), fstat(), XrdOfsPoscq::Request::LFN, pread(), ReqOffs, ReqSize, XrdCms::Say, and stat().

+ Here is the call graph for this function:

◆ Num()

int XrdOfsPoscq::Num ( )
inline

Definition at line 76 of file XrdOfsPoscq.hh.

76 {return pocIQ;}

Member Data Documentation

◆ ReqOffs

const int XrdOfsPoscq::ReqOffs = 64
static

Definition at line 53 of file XrdOfsPoscq.hh.

Referenced by Init(), and List().

◆ ReqSize

const int XrdOfsPoscq::ReqSize = sizeof(Request)
static

Definition at line 54 of file XrdOfsPoscq.hh.

Referenced by Add(), Init(), and List().


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