XRootD
XrdOssCsiTagstoreFile Class Reference

#include <XrdOssCsiTagstoreFile.hh>

+ Inheritance diagram for XrdOssCsiTagstoreFile:
+ Collaboration diagram for XrdOssCsiTagstoreFile:

Public Member Functions

 XrdOssCsiTagstoreFile (const std::string &fn, std::unique_ptr< XrdOssDF > fd, const char *tid)
 
virtual ~XrdOssCsiTagstoreFile ()
 
virtual int Close ()
 
virtual void Flush ()
 
virtual int Fsync ()
 
virtual off_t GetTrackedDataSize () const
 
virtual off_t GetTrackedTagSize () const
 
virtual bool IsVerified () const
 
virtual int Open (const char *, off_t, int, XrdOucEnv &)
 
virtual ssize_t ReadTags (uint32_t *, off_t, size_t)
 
virtual int ResetSizes (const off_t size)
 
virtual int SetTrackedSize (const off_t size)
 
virtual int SetUnverified ()
 
virtual int Truncate (off_t, bool)
 
virtual ssize_t WriteTags (const uint32_t *, off_t, size_t)
 
- Public Member Functions inherited from XrdOssCsiTagstore
virtual ~XrdOssCsiTagstore ()
 

Static Public Member Functions

static ssize_t fullread (XrdOssDF &fd, void *buff, const off_t off, const size_t sz)
 
static ssize_t fullwrite (XrdOssDF &fd, const void *buff, const off_t off, const size_t sz)
 

Additional Inherited Members

- Static Public Attributes inherited from XrdOssCsiTagstore
static const uint32_t csVer = 0x00000001
 

Detailed Description

Definition at line 42 of file XrdOssCsiTagstoreFile.hh.

Constructor & Destructor Documentation

◆ XrdOssCsiTagstoreFile()

XrdOssCsiTagstoreFile::XrdOssCsiTagstoreFile ( const std::string &  fn,
std::unique_ptr< XrdOssDF fd,
const char *  tid 
)
inline

Definition at line 45 of file XrdOssCsiTagstoreFile.hh.

45 : fn_(fn), fd_(std::move(fd)), trackinglen_(0), isOpen(false), tident_(tid), tident(tident_.c_str()) { }

◆ ~XrdOssCsiTagstoreFile()

virtual XrdOssCsiTagstoreFile::~XrdOssCsiTagstoreFile ( )
inlinevirtual

Definition at line 46 of file XrdOssCsiTagstoreFile.hh.

46 { if (isOpen) { (void)Close(); } }

References Close().

+ Here is the call graph for this function:

Member Function Documentation

◆ Close()

int XrdOssCsiTagstoreFile::Close ( )
virtual

Implements XrdOssCsiTagstore.

Definition at line 176 of file XrdOssCsiTagstoreFile.cc.

177 {
178  if (!isOpen) return -EBADF;
179  isOpen = false;
180  return fd_->Close();
181 }

Referenced by ~XrdOssCsiTagstoreFile().

+ Here is the caller graph for this function:

◆ Flush()

void XrdOssCsiTagstoreFile::Flush ( )
virtual

Implements XrdOssCsiTagstore.

Definition at line 170 of file XrdOssCsiTagstoreFile.cc.

171 {
172  if (!isOpen) return;
173  fd_->Flush();
174 }

◆ Fsync()

int XrdOssCsiTagstoreFile::Fsync ( void  )
virtual

Implements XrdOssCsiTagstore.

Definition at line 164 of file XrdOssCsiTagstoreFile.cc.

165 {
166  if (!isOpen) return -EBADF;
167  return fd_->Fsync();
168 }

◆ fullread()

static ssize_t XrdOssCsiTagstoreFile::fullread ( XrdOssDF fd,
void *  buff,
const off_t  off,
const size_t  sz 
)
inlinestatic

Definition at line 106 of file XrdOssCsiTagstoreFile.hh.

107  {
108  size_t toread = sz, nread = 0;
109  uint8_t *p = (uint8_t*)buff;
110  while(toread>0)
111  {
112  const ssize_t rret = fd.Read(&p[nread], off+nread, toread);
113  if (rret<0) return rret;
114  if (rret==0) break;
115  toread -= rret;
116  nread += rret;
117  }
118  if (nread != sz) return -EDOM;
119  return nread;
120  }
virtual ssize_t Read(off_t offset, size_t size)
Definition: XrdOss.hh:281

References XrdOssDF::Read().

Referenced by Open(), and ReadTags().

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

◆ fullwrite()

static ssize_t XrdOssCsiTagstoreFile::fullwrite ( XrdOssDF fd,
const void *  buff,
const off_t  off,
const size_t  sz 
)
inlinestatic

Definition at line 122 of file XrdOssCsiTagstoreFile.hh.

123  {
124  size_t towrite = sz, nwritten = 0;
125  const uint8_t *p = (const uint8_t*)buff;
126  while(towrite>0)
127  {
128  const ssize_t wret = fd.Write(&p[nwritten], off+nwritten, towrite);
129  if (wret<0) return wret;
130  towrite -= wret;
131  nwritten += wret;
132  }
133  return nwritten;
134  }
virtual ssize_t Write(const void *buffer, off_t offset, size_t size)
Definition: XrdOss.hh:345

References XrdOssDF::Write().

Referenced by WriteTags().

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

◆ GetTrackedDataSize()

virtual off_t XrdOssCsiTagstoreFile::GetTrackedDataSize ( ) const
inlinevirtual

Implements XrdOssCsiTagstore.

Definition at line 65 of file XrdOssCsiTagstoreFile.hh.

66  {
67  if (!isOpen) return 0;
68  return actualsize_;
69  }

◆ GetTrackedTagSize()

virtual off_t XrdOssCsiTagstoreFile::GetTrackedTagSize ( ) const
inlinevirtual

Implements XrdOssCsiTagstore.

Definition at line 59 of file XrdOssCsiTagstoreFile.hh.

60  {
61  if (!isOpen) return 0;
62  return trackinglen_;
63  }

◆ IsVerified()

virtual bool XrdOssCsiTagstoreFile::IsVerified ( ) const
inlinevirtual

Implements XrdOssCsiTagstore.

Definition at line 88 of file XrdOssCsiTagstoreFile.hh.

89  {
90  if (!isOpen) return false;
91  if ((hflags_ & XrdOssCsiTagstore::csVer)) return true;
92  return false;
93  }
static const uint32_t csVer

References XrdOssCsiTagstore::csVer.

◆ Open()

int XrdOssCsiTagstoreFile::Open ( const char *  path,
off_t  dsize,
int  Oflag,
XrdOucEnv Env 
)
virtual

Implements XrdOssCsiTagstore.

Definition at line 41 of file XrdOssCsiTagstoreFile.cc.

42 {
43  EPNAME("TagstoreFile::Open");
44 
45  const int ret = fd_->Open(path, Oflag, 0666, Env);
46  if (ret<0)
47  {
48  return ret;
49  }
50  isOpen = true;
51 
52  struct guard_s
53  {
54  guard_s(XrdOssDF *fd, bool &isopen) : fd_(fd), isopen_(isopen) { }
55  ~guard_s() { if (fd_) { fd_->Close(); isopen_ = false; } }
56  void disarm() { fd_ = NULL; }
57 
58  XrdOssDF *fd_;
59  bool &isopen_;
60  } fdguard(fd_.get(),isOpen);
61 
62  const static int little = 1;
63  if (*(char const *)&little)
64  {
65  machineIsBige_ = false;
66  }
67  else
68  {
69  machineIsBige_ = true;
70  }
71 
72  uint32_t magic;
73 
74  const ssize_t mread = XrdOssCsiTagstoreFile::fullread(*fd_, header_, 0, 20);
75  bool mok = false;
76  if (mread >= 0)
77  {
78  memcpy(&magic, header_, 4);
79  if (magic == cmagic_)
80  {
81  fileIsBige_ = machineIsBige_;
82  mok = true;
83  }
84  else if (magic == bswap_32(cmagic_))
85  {
86  fileIsBige_ = !machineIsBige_;
87  mok = true;
88  }
89  }
90 
91  if (!mok)
92  {
93  fileIsBige_ = machineIsBige_;
94  hflags_ = (dsize==0) ? XrdOssCsiTagstore::csVer : 0;
95  trackinglen_ = 0;
96  const int stret = MarshallAndWriteHeader();
97  if (stret<0) return stret;
98  }
99  else
100  {
101  memcpy(&trackinglen_, &header_[4], 8);
102  if (fileIsBige_ != machineIsBige_)
103  {
104  trackinglen_ = bswap_64(trackinglen_);
105  }
106  memcpy(&hflags_,&header_[12], 4);
107  if (fileIsBige_ != machineIsBige_)
108  {
109  hflags_ = bswap_32(hflags_);
110  }
111  const uint32_t cv = XrdOucCRC::Calc32C(header_, 16, 0U);
112  uint32_t rv;
113  memcpy(&rv, &header_[16], 4);
114  if (fileIsBige_ != machineIsBige_) rv = bswap_32(rv);
115  if (rv != cv)
116  {
117  return -EDOM;
118  }
119  }
120 
121  if (trackinglen_ != dsize)
122  {
123  TRACE(Warn, "Tagfile disagrees with actual filelength for " << fn_ << " expected " << trackinglen_ << " actual " << dsize);
124  }
125 
126  const int rsret = ResetSizes(dsize);
127  if (rsret<0) return rsret;
128 
129  fdguard.disarm();
130  return 0;
131 }
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
#define TRACE(act, x)
Definition: XrdTrace.hh:63
virtual int ResetSizes(const off_t size)
static ssize_t fullread(XrdOssDF &fd, void *buff, const off_t off, const size_t sz)
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
Definition: XrdOucCRC.cc:190

References XrdOucCRC::Calc32C(), XrdOssCsiTagstore::csVer, EPNAME, fullread(), ResetSizes(), and TRACE.

+ Here is the call graph for this function:

◆ ReadTags()

ssize_t XrdOssCsiTagstoreFile::ReadTags ( uint32_t *  buf,
off_t  off,
size_t  n 
)
virtual

Implements XrdOssCsiTagstore.

Definition at line 193 of file XrdOssCsiTagstoreFile.cc.

194 {
195  if (!isOpen) return -EBADF;
196  if (machineIsBige_ != fileIsBige_) return ReadTags_swap(buf, off, n);
197 
198  const ssize_t nread = XrdOssCsiTagstoreFile::fullread(*fd_, buf, 20LL+4*off, 4*n);
199  if (nread<0) return nread;
200  return nread/4;
201 }

References fullread().

+ Here is the call graph for this function:

◆ ResetSizes()

int XrdOssCsiTagstoreFile::ResetSizes ( const off_t  size)
virtual

Implements XrdOssCsiTagstore.

Definition at line 133 of file XrdOssCsiTagstoreFile.cc.

134 {
135  EPNAME("ResetSizes");
136  if (!isOpen) return -EBADF;
137  actualsize_ = size;
138  struct stat sb;
139  const int ssret = fd_->Fstat(&sb);
140  if (ssret<0) return ssret;
141  const off_t expected_tagfile_size = 20LL + 4*((trackinglen_+XrdSys::PageSize-1)/XrdSys::PageSize);
142  // truncate can be relatively slow
143  if (expected_tagfile_size < sb.st_size)
144  {
145  TRACE(Warn, "Truncating tagfile to " << expected_tagfile_size <<
146  ", from current size " << sb.st_size << " for " << fn_);
147  const int tret = fd_->Ftruncate(expected_tagfile_size);
148  if (tret<0) return tret;
149  }
150  else if (expected_tagfile_size > sb.st_size)
151  {
152  off_t nb = 0;
153  if (sb.st_size>20) nb = (sb.st_size - 20)/4;
154  TRACE(Warn, "Reducing tracked size to " << (nb*XrdSys::PageSize) <<
155  " instead of " << trackinglen_ << ", because of short tagfile for " << fn_);
156  const int stret = WriteTrackedTagSize(nb*XrdSys::PageSize);
157  if (stret<0) return stret;
158  const int tret = fd_->Ftruncate(20LL + 4*nb);
159  if (tret<0) return tret;
160  }
161  return 0;
162 }
int stat(const char *path, struct stat *buf)
static const int PageSize

References EPNAME, XrdSys::PageSize, stat(), and TRACE.

Referenced by Open().

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

◆ SetTrackedSize()

virtual int XrdOssCsiTagstoreFile::SetTrackedSize ( const off_t  size)
inlinevirtual

Implements XrdOssCsiTagstore.

Definition at line 73 of file XrdOssCsiTagstoreFile.hh.

74  {
75  if (!isOpen) return -EBADF;
76  if (size > actualsize_)
77  {
78  actualsize_ = size;
79  }
80  if (size != trackinglen_)
81  {
82  const int wtt = WriteTrackedTagSize(size);
83  if (wtt<0) return wtt;
84  }
85  return 0;
86  }

◆ SetUnverified()

virtual int XrdOssCsiTagstoreFile::SetUnverified ( )
inlinevirtual

Implements XrdOssCsiTagstore.

Definition at line 95 of file XrdOssCsiTagstoreFile.hh.

96  {
97  if (!isOpen) return -EBADF;
98  if ((hflags_ & XrdOssCsiTagstore::csVer))
99  {
100  hflags_ &= ~XrdOssCsiTagstore::csVer;
101  return MarshallAndWriteHeader();
102  }
103  return 0;
104  }
virtual ~XrdOssCsiTagstore()

References XrdOssCsiTagstore::~XrdOssCsiTagstore(), and XrdOssCsiTagstore::csVer.

+ Here is the call graph for this function:

◆ Truncate()

int XrdOssCsiTagstoreFile::Truncate ( off_t  size,
bool  datatoo 
)
virtual

Implements XrdOssCsiTagstore.

Definition at line 203 of file XrdOssCsiTagstoreFile.cc.

204 {
205  if (!isOpen)
206  {
207  return -EBADF;
208  }
209 
210  // set tag file to correct length for value of size
211  const off_t expected_tagfile_size = 20LL + 4*((size+XrdSys::PageSize-1)/XrdSys::PageSize);
212  const int tret = fd_->Ftruncate(expected_tagfile_size);
213 
214  // if failed to set the tagfile length return error before updating header
215  if (tret != XrdOssOK) return tret;
216 
217  // truncating down to zero, so reset to content verified
218  if (datatoo && size==0) hflags_ |= XrdOssCsiTagstore::csVer;
219 
220  int wtt = WriteTrackedTagSize(size);
221  if (wtt<0) return wtt;
222 
223  if (datatoo) actualsize_ = size;
224  return 0;
225 }
#define XrdOssOK
Definition: XrdOss.hh:50

References XrdOssCsiTagstore::csVer, XrdSys::PageSize, and XrdOssOK.

◆ WriteTags()

ssize_t XrdOssCsiTagstoreFile::WriteTags ( const uint32_t *  buf,
off_t  off,
size_t  n 
)
virtual

Implements XrdOssCsiTagstore.

Definition at line 183 of file XrdOssCsiTagstoreFile.cc.

184 {
185  if (!isOpen) return -EBADF;
186  if (machineIsBige_ != fileIsBige_) return WriteTags_swap(buf, off, n);
187 
188  const ssize_t nwritten = XrdOssCsiTagstoreFile::fullwrite(*fd_, buf, 20LL+4*off, 4*n);
189  if (nwritten<0) return nwritten;
190  return nwritten/4;
191 }
static ssize_t fullwrite(XrdOssDF &fd, const void *buff, const off_t off, const size_t sz)

References fullwrite().

+ Here is the call graph for this function:

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