XRootD
Loading...
Searching...
No Matches
XrdPosixPrepIO.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P o s i x P r e p I O . 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
35
36/******************************************************************************/
37/* G l o b a l s */
38/******************************************************************************/
39
40namespace XrdPosixGlobals
41{
42extern XrdOucCache *theCache;
43extern XrdPosixStats Stats;
44};
45
46/******************************************************************************/
47/* D i s a b l e */
48/******************************************************************************/
49
51{
52 EPNAME("PrepIODisable");
53 XrdPosixObjGuard objGuard(fileP);
54
55 DEBUG("Disabling deferred open "<<fileP->Origin());
56
57 openRC = -ESHUTDOWN;
58}
59
60/******************************************************************************/
61/* I n i t */
62/******************************************************************************/
63
64bool XrdPosixPrepIO::Init(XrdOucCacheIOCB *iocbP)
65{
66 EPNAME("PrepIOInit");
67 XrdPosixObjGuard objGuard(fileP);
69 static int maxCalls = 64;
70
71// Count the number of entries here. We want to catch someone ignoring the
72// Update() call and using this object as it is very ineffecient.
73//
74 if (iCalls++ >= maxCalls)
75 {maxCalls = maxCalls*2;
76 DMSG("Init", iCalls <<" unexpected PrepIO calls!");
77 }
78
79// Do not try to open the file if there was previous error
80//
81 if (openRC) return false;
82
83// Check if the file is already opened. This caller may be vestigial
84//
85 if (fileP->clFile.IsOpen()) return true;
86
87// Count number of opens after the open was deferred (successful or not)
88//
91 (XrdPosixGlobals::theCache->Statistics.X.OpenDefers));
92
93// Open the file. It is too difficult to do an async open here as there is a
94// possible pending async request and doing both is not easy at all.
95//
96 Status = fileP->clFile.Open((std::string)fileP->Origin(), clFlags, clMode);
98
99// Make sure all went well. If so, do a Stat() call on the underlying file
100//
101 if (Status.IsOK()) fileP->Stat(Status);
102 else {openRC = XrdPosixMap::Result(Status, fileP->ecMsg, false);
103 if (DEBUGON && errno != ENOENT && errno != ELOOP)
104 {std::string eTxt = Status.ToString();
105 DEBUG(eTxt<<" deferred open "<<fileP->Origin());
106 }
108 return false;
109 }
110
111// Inform the cache that we have now have a new I/O object
112//
113 fileP->XCio->Update(*fileP);
114 return true;
115}
#define DEBUG(x)
#define EPNAME(x)
#define DMSG(x, y)
#define DEBUGON
bool IsOpen() const
Check if the file is open.
Definition XrdClFile.cc:846
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:99
virtual void Update(XrdOucCacheIO &iocp)
void Count(long long &Dest)
XrdOucCacheStats Statistics
const char * Origin()
bool Stat(XrdCl::XRootDStatus &Status, bool force=false)
XrdCl::File clFile
XrdOucCacheIO * XCio
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
XrdOucECMsg ecMsg
void Count(long long &Dest)
XrdPosixStats Stats
XrdOucCache * theCache
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.