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