XRootD
XrdOssCsiFileAio.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d O s s C s i F i l e A i o . c c */
4 /* */
5 /* (C) Copyright 2021 CERN. */
6 /* */
7 /* This file is part of the XRootD software suite. */
8 /* */
9 /* XRootD is free software: you can redistribute it and/or modify it under */
10 /* the terms of the GNU Lesser General Public License as published by the */
11 /* Free Software Foundation, either version 3 of the License, or (at your */
12 /* option) any later version. */
13 /* */
14 /* In applying this licence, CERN does not waive the privileges and */
15 /* immunities granted to it by virtue of its status as an Intergovernmental */
16 /* Organization or submit itself to any jurisdiction. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include "XrdOssCsiTrace.hh"
33 #include "XrdOssCsi.hh"
34 #include "XrdOssCsiPages.hh"
35 #include "XrdOssCsiFileAio.hh"
36 #include "XrdOuc/XrdOucCRC.hh"
37 
38 #include <string>
39 #include <algorithm>
40 #include <mutex>
41 
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45 #include <limits.h>
46 
48 
50 {
52  while((p=list_))
53  {
54  list_ = list_->next_;
55  delete p;
56  }
57 }
58 
60 {
61  if (!pmi_) return -EBADF;
62 
63  XrdOssCsiFileAio *nio = XrdOssCsiFileAio::Alloc(&aiostore_);
64  nio->Init(aiop, this, false, 0, true);
65  nio->SchedReadJob();
66  return 0;
67 }
68 
70 {
71  if (!pmi_) return -EBADF;
72  if (rdonly_) return -EBADF;
73 
74  XrdOssCsiFileAio *nio = XrdOssCsiFileAio::Alloc(&aiostore_);
75  nio->Init(aiop, this, false, 0, false);
76  // pages will be locked when write is scheduled
77  nio->SchedWriteJob();
78  return 0;
79 }
80 
81 int XrdOssCsiFile::pgRead(XrdSfsAio *aioparm, uint64_t opts)
82 {
83  if (!pmi_) return -EBADF;
84 
85  XrdOssCsiFileAio *nio = XrdOssCsiFileAio::Alloc(&aiostore_);
86  nio->Init(aioparm, this, true, opts, true);
87  nio->SchedReadJob();
88  return 0;
89 }
90 
91 int XrdOssCsiFile::pgWrite(XrdSfsAio *aioparm, uint64_t opts)
92 {
93  if (!pmi_) return -EBADF;
94  if (rdonly_) return -EBADF;
95  uint64_t pgopts = opts;
96 
97  const int prec = XrdOssCsiPages::pgWritePrelockCheck(
98  (void *)aioparm->sfsAio.aio_buf,
99  (off_t)aioparm->sfsAio.aio_offset,
100  (size_t)aioparm->sfsAio.aio_nbytes,
101  aioparm->cksVec,
102  opts);
103  if (prec < 0)
104  {
105  return prec;
106  }
107 
108  XrdOssCsiFileAio *nio = XrdOssCsiFileAio::Alloc(&aiostore_);
109  nio->Init(aioparm, this, true, pgopts, false);
110  // pages will be locked when write is scheduled
111  nio->SchedWriteJob();
112  return 0;
113 }
114 
116 {
117  aioWait();
118  aiop->Result = this->Fsync();
119  aiop->doneWrite();
120  return 0;
121 }
XrdOucTrace OssCsiTrace
struct myOpts opts
off_t aio_offset
Definition: XrdSfsAio.hh:49
size_t aio_nbytes
Definition: XrdSfsAio.hh:48
void * aio_buf
Definition: XrdSfsAio.hh:47
XrdOssCsiFileAio * list_
Definition: XrdOssCsi.hh:53
static XrdOssCsiFileAio * Alloc(XrdOssCsiFileAioStore *store)
void Init(XrdSfsAio *aiop, XrdOssCsiFile *file, bool isPgOp, uint64_t opts, bool isread)
virtual ssize_t pgWrite(void *, off_t, size_t, uint32_t *, uint64_t)
virtual int Fsync()
virtual ssize_t Write(const void *, off_t, size_t)
virtual ssize_t pgRead(void *, off_t, size_t, uint32_t *, uint64_t)
virtual ssize_t Read(off_t, size_t)
void aioWait()
Definition: XrdOssCsi.hh:126
static int pgWritePrelockCheck(const void *, off_t, size_t, const uint32_t *, uint64_t)
uint32_t * cksVec
Definition: XrdSfsAio.hh:63
ssize_t Result
Definition: XrdSfsAio.hh:65
struct aiocb sfsAio
Definition: XrdSfsAio.hh:62
virtual void doneWrite()=0