XRootD
Loading...
Searching...
No Matches
XrdPosixFileRH.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P o x F i l e R H . c c */
4/* */
5/* (c) 2016 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 <utility>
32#include <vector>
33
34#include "Xrd/XrdScheduler.hh"
35
36#include "XrdOuc/XrdOucCache.hh"
37#include "XrdOuc/XrdOucCRC.hh"
39
43
44/******************************************************************************/
45/* S t a t i c M e m b e r s */
46/******************************************************************************/
47
48namespace XrdPosixGlobals
49{
51};
52
53XrdSysMutex XrdPosixFileRH::myMutex;
54XrdPosixFileRH *XrdPosixFileRH::freeRH = 0;
55int XrdPosixFileRH::numFree = 0;
56int XrdPosixFileRH::maxFree = 100;
57
58/******************************************************************************/
59/* E x t e r n a l L i n k a g e s */
60/******************************************************************************/
61
62namespace
63{
64void *callDoIt(void *pp)
65{
66 XrdPosixFileRH *rhp = (XrdPosixFileRH *)pp;
67 rhp->DoIt();
68 return (void *)0;
69}
70};
71
72/******************************************************************************/
73/* A l l o c */
74/******************************************************************************/
75
77 XrdPosixFile *fp,
78 long long offs,
79 int xResult,
80 ioType typeIO)
81{
82 XrdPosixFileRH *newCB;
83
84// Try to allocate an prexisting object otherwise get a new one
85//
86 myMutex.Lock();
87 if ((newCB = freeRH)) {freeRH = newCB->next; numFree--;}
88 else newCB = new XrdPosixFileRH;
89 myMutex.UnLock();
90
91// Initialize the callback and return it
92//
93 newCB->theCB = cbp;
94 newCB->theFile = fp;
95 newCB->csVec = 0;
96 newCB->csfix = 0;
97 newCB->offset = offs;
98 newCB->result = xResult;
99 newCB->typeIO = typeIO;
100 newCB->csFrc = false;
101 return newCB;
102}
103
104/******************************************************************************/
105/* H a n d l e R e s p o n s e */
106/******************************************************************************/
107
109 XrdCl::AnyObject *response)
110{
111
112// Determine ending status. Note: error indicated as result set to -errno.
113//
114 if (!(status->IsOK()))
115 result = XrdPosixMap::Result(*status, theFile->ecMsg, false);
116 else if (typeIO == nonIO) result = 0;
117 else if (typeIO == isRead)
118 {XrdCl::ChunkInfo *cInfo = 0;
119 union {uint32_t ubRead; int ibRead;};
120 response->Get(cInfo);
121 ubRead = (cInfo ? cInfo->length : 0);
122 result = ibRead;
123 }
124 else if (typeIO == isReadP)
125 {XrdCl::PageInfo *pInfo = 0;
126 union {uint32_t ubRead; int ibRead;};
127 response->Get(pInfo);
128 if (pInfo)
129 {ubRead = pInfo->GetLength();
130 result = ibRead;
131 if (csVec)
132 {if (!csFrc || pInfo->GetCksums().size() != 0 || result <= 0)
133 *csVec = std::move(pInfo->GetCksums() );
134 else {uint64_t offs = pInfo->GetOffset();
135 void *buff = pInfo->GetBuffer();
136 XrdOucPgrwUtils::csCalc((const char *)buff,
137 (ssize_t)offs, ubRead,
138 *csVec);
139 }
140 csVec = 0;
141 }
142 if (csfix) *csfix = pInfo->GetNbRepair();
143 } else {
144 result = 0;
145 if (csVec) {csVec->clear(); csVec = 0;}
146 }
147 }
148 else if (typeIO == isWrite) theFile->UpdtSize(offset+result);
149
150// Get rid of things we don't need
151//
152 delete status;
153 delete response;
154
155// Now schedule our XrdOucCacheIOCB callback
156//
157 theFile->unRef();
159 else {pthread_t tid;
160 XrdSysThread::Run(&tid, callDoIt, this, 0, "PosixFileRH");
161 }
162}
163
164/******************************************************************************/
165/* R e c y c l e */
166/******************************************************************************/
167
169{
170// Perform recycling
171//
172 myMutex.Lock();
173 if (numFree >= maxFree) delete this;
174 else {next = freeRH;
175 freeRH = this;
176 numFree++;
177 }
178 myMutex.UnLock();
179}
180
181/******************************************************************************/
182/* S c h e d */
183/******************************************************************************/
184
186{
187// Set result
188//
189 result = rval;
190
191// Now schedule this callback
192//
194 else {pthread_t tid;
195 XrdSysThread::Run(&tid, callDoIt, this, 0, "PosixFileRH");
196 }
197}
void Get(Type &object)
Retrieve the object being held.
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
void Sched(int result)
static XrdPosixFileRH * Alloc(XrdOucCacheIOCB *cbp, XrdPosixFile *fp, long long offs, int xResult, ioType typeIO)
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
XrdScheduler * schedP
Describe a data chunk for vector read.
uint32_t length
offset in the file
size_t GetNbRepair()
Get number of repaired pages.
std::vector< uint32_t > & GetCksums()
Get the checksums.
uint32_t GetLength() const
Get the data length.
uint64_t GetOffset() const
Get the offset.
void * GetBuffer()
Get the buffer.
bool IsOK() const
We're fine.