XRootD
XrdCl::FileSystemUtils Class Reference

#include <XrdClFileSystemUtils.hh>

+ Collaboration diagram for XrdCl::FileSystemUtils:

Classes

class  SpaceInfo
 Container for space information. More...
 
struct  SpaceInfoImpl
 

Static Public Member Functions

static XRootDStatus GetSpaceInfo (SpaceInfo *&result, FileSystem *fs, const std::string &path)
 Recursively get space information for given path. More...
 

Detailed Description

A container for file system utility functions that do not belong in FileSystem

Definition at line 42 of file XrdClFileSystemUtils.hh.

Member Function Documentation

◆ GetSpaceInfo()

XRootDStatus XrdCl::FileSystemUtils::GetSpaceInfo ( SpaceInfo *&  result,
FileSystem fs,
const std::string &  path 
)
static

Recursively get space information for given path.

Definition at line 98 of file XrdClFileSystemUtils.cc.

101  {
102  //--------------------------------------------------------------------------
103  // Locate all the disk servers containing the space
104  //--------------------------------------------------------------------------
105  LocationInfo *locationInfo = 0;
106  XRootDStatus st = fs->DeepLocate( path, OpenFlags::Compress, locationInfo );
107  if( !st.IsOK() )
108  return st;
109 
110  std::unique_ptr<LocationInfo> locationInfoPtr( locationInfo );
111 
112  bool partial = st.code == suPartial ? true : false;
113 
114  std::vector<std::pair<std::string, uint64_t> > resp;
115  resp.push_back( std::make_pair( std::string("oss.space"), (uint64_t)0 ) );
116  resp.push_back( std::make_pair( std::string("oss.free"), (uint64_t)0 ) );
117  resp.push_back( std::make_pair( std::string("oss.used"), (uint64_t)0 ) );
118  resp.push_back( std::make_pair( std::string("oss.maxf"), (uint64_t)0 ) );
119 
120  //--------------------------------------------------------------------------
121  // Loop over the file servers and get the space info from each of them
122  //--------------------------------------------------------------------------
124  Buffer pathArg; pathArg.FromString( path );
125  for( it = locationInfo->Begin(); it != locationInfo->End(); ++it )
126  {
127  //------------------------------------------------------------------------
128  // Query the server
129  //------------------------------------------------------------------------
130  Buffer *spaceInfo = 0;
131  FileSystem fs1( it->GetAddress() );
132  st = fs1.Query( QueryCode::Space, pathArg, spaceInfo );
133  if( !st.IsOK() )
134  return st;
135 
136  std::unique_ptr<Buffer> spaceInfoPtr( spaceInfo );
137 
138  //------------------------------------------------------------------------
139  // Parse the cgi
140  //------------------------------------------------------------------------
141  std::string fakeUrl = "root://fake/fake?" + spaceInfo->ToString();
142  URL url( fakeUrl );
143 
144  if( !url.IsValid() )
145  return XRootDStatus( stError, errInvalidResponse );
146 
147  URL::ParamsMap params = url.GetParams();
148 
149  //------------------------------------------------------------------------
150  // Convert and add up the params
151  //------------------------------------------------------------------------
152  st = XRootDStatus( stError, errInvalidResponse );
153  for( size_t i = 0; i < resp.size(); ++i )
154  {
155  URL::ParamsMap::iterator paramIt = params.find( resp[i].first );
156  if( paramIt == params.end() ) return st;
157  char *res;
158  uint64_t num = ::strtoll( paramIt->second.c_str(), &res, 0 );
159  if( *res != 0 ) return st;
160  if( resp[i].first == "oss.maxf" )
161  { if( num > resp[i].second ) resp[i].second = num; }
162  else
163  resp[i].second += num;
164  }
165  }
166 
167  result = new SpaceInfo( resp[0].second, resp[1].second, resp[2].second,
168  resp[3].second );
169 
170  st = XRootDStatus(); if( partial ) st.code = suPartial;
171  return st;
172  }
LocationList::iterator Iterator
Iterator over locations.
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
const uint16_t suPartial
Definition: XrdClStatus.hh:41
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errInvalidResponse
Definition: XrdClStatus.hh:99
@ Space
Query logical space stats.

References XrdCl::LocationInfo::Begin(), XrdCl::Status::code, XrdCl::OpenFlags::Compress, XrdCl::FileSystem::DeepLocate(), XrdCl::LocationInfo::End(), XrdCl::errInvalidResponse, XrdCl::Buffer::FromString(), XrdCl::URL::GetParams(), XrdCl::Status::IsOK(), XrdCl::URL::IsValid(), XrdCl::FileSystem::Query(), XrdCl::QueryCode::Space, XrdCl::stError, XrdCl::suPartial, and XrdCl::Buffer::ToString().

Referenced by DoSpaceInfo().

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

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