Loading...
Searching...
No Matches
XrdClFileSystemUtils.cc
Go to the documentation of this file.
//------------------------------------------------------------------------------
// Copyright (c) 2014 by European Organization for Nuclear Research (CERN)
// Author: Lukasz Janyst <ljanyst@cern.ch>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------
#include "XrdCl/XrdClFileSystemUtils.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClURL.hh"
#include <vector>
#include <utility>
#include <memory>
namespace XrdCl
{
//----------------------------------------------------------------------------
// The data holder implementation
//----------------------------------------------------------------------------
struct FileSystemUtils::SpaceInfoImpl
{
SpaceInfoImpl( uint64_t total, uint64_t free, uint64_t used,
uint64_t largestChunk ):
pTotal( total ),
pFree( free ),
pUsed( used ),
pLargestChunk( largestChunk )
{
}
uint64_t pTotal;
uint64_t pFree;
uint64_t pUsed;
uint64_t pLargestChunk;
};
//----------------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------------
FileSystemUtils::SpaceInfo::SpaceInfo( uint64_t total, uint64_t free, uint64_t used,
uint64_t largestChunk ):
pImpl( new SpaceInfoImpl( total, free, used, largestChunk ) )
{
}
//---------------------------------------------------------------------------
// Destructor (needs to be here due to the unique_ptr guarding PIMPL)
//---------------------------------------------------------------------------
FileSystemUtils::SpaceInfo::~SpaceInfo()
{
}
//----------------------------------------------------------------------------
// Amount of total space in MB
//----------------------------------------------------------------------------
uint64_t FileSystemUtils::SpaceInfo::GetTotal() const { return pImpl->pTotal; }
//----------------------------------------------------------------------------
// Amount of free space in MB
//----------------------------------------------------------------------------
uint64_t FileSystemUtils::SpaceInfo::GetFree() const { return pImpl->pFree; }
//----------------------------------------------------------------------------
// Amount of used space in MB
//----------------------------------------------------------------------------
uint64_t FileSystemUtils::SpaceInfo::GetUsed() const { return pImpl->pUsed; }
//----------------------------------------------------------------------------
// Largest single chunk of free space
//----------------------------------------------------------------------------
uint64_t FileSystemUtils::SpaceInfo::GetLargestFreeChunk() const
{
return pImpl->pLargestChunk;
}
//----------------------------------------------------------------------------
// Recursively get space information for given path
//----------------------------------------------------------------------------
XRootDStatus FileSystemUtils::GetSpaceInfo( SpaceInfo *&result,
FileSystem *fs,
const std::string &path )
{
//--------------------------------------------------------------------------
// Locate all the disk servers containing the space
//--------------------------------------------------------------------------
LocationInfo *locationInfo = 0;
OpenFlags::Flags flags = OpenFlags::Compress | OpenFlags::PrefName;
XRootDStatus st = fs->DeepLocate( path, flags, locationInfo );
if( !st.IsOK() )
return st;
std::unique_ptr<LocationInfo> locationInfoPtr( locationInfo );
bool partial = st.code == suPartial ? true : false;
std::vector<std::pair<std::string, uint64_t> > resp;
resp.push_back( std::make_pair( std::string("oss.space"), (uint64_t)0 ) );
resp.push_back( std::make_pair( std::string("oss.free"), (uint64_t)0 ) );
resp.push_back( std::make_pair( std::string("oss.used"), (uint64_t)0 ) );
resp.push_back( std::make_pair( std::string("oss.maxf"), (uint64_t)0 ) );
//--------------------------------------------------------------------------
// Loop over the file servers and get the space info from each of them
//--------------------------------------------------------------------------
LocationInfo::Iterator it;
Buffer pathArg; pathArg.FromString( path );
for( it = locationInfo->Begin(); it != locationInfo->End(); ++it )
{
//------------------------------------------------------------------------
// Query the server
//------------------------------------------------------------------------
Buffer *spaceInfo = 0;
FileSystem fs1( it->GetAddress() );
st = fs1.Query( QueryCode::Space, pathArg, spaceInfo );
if( !st.IsOK() )
return st;
std::unique_ptr<Buffer> spaceInfoPtr( spaceInfo );
//------------------------------------------------------------------------
// Parse the cgi
//------------------------------------------------------------------------
std::string fakeUrl = "root://fake/fake?" + spaceInfo->ToString();
URL url( fakeUrl );
if( !url.IsValid() )
return XRootDStatus( stError, errInvalidResponse );
URL::ParamsMap params = url.GetParams();
//------------------------------------------------------------------------
// Convert and add up the params
//------------------------------------------------------------------------
st = XRootDStatus( stError, errInvalidResponse );
for( size_t i = 0; i < resp.size(); ++i )
{
URL::ParamsMap::iterator paramIt = params.find( resp[i].first );
if( paramIt == params.end() ) return st;
char *res;
uint64_t num = ::strtoll( paramIt->second.c_str(), &res, 0 );
if( *res != 0 ) return st;
if( resp[i].first == "oss.maxf" )
{ if( num > resp[i].second ) resp[i].second = num; }
else
resp[i].second += num;
}
}
result = new SpaceInfo( resp[0].second, resp[1].second, resp[2].second,
resp[3].second );
st = XRootDStatus(); if( partial ) st.code = suPartial;
return st;
}
}
XrdClFileSystemUtils.hh
XrdClFileSystem.hh
XrdClURL.hh
XrdCl::Buffer
Binary blob representation.
Definition XrdClBuffer.hh:34
XrdCl::Buffer::FromString
void FromString(const std::string str)
Fill the buffer from a string.
Definition XrdClBuffer.hh:205
XrdCl::Buffer::ToString
std::string ToString() const
Convert the buffer to a string.
Definition XrdClBuffer.hh:215
XrdCl::FileSystemUtils::SpaceInfo
Container for space information.
Definition XrdClFileSystemUtils.hh:54
XrdCl::FileSystemUtils::SpaceInfo::~SpaceInfo
~SpaceInfo()
Definition XrdClFileSystemUtils.cc:68
XrdCl::FileSystemUtils::SpaceInfo::GetUsed
uint64_t GetUsed() const
Amount of used space in MB.
Definition XrdClFileSystemUtils.cc:85
XrdCl::FileSystemUtils::SpaceInfo::GetLargestFreeChunk
uint64_t GetLargestFreeChunk() const
Largest single chunk of free space.
Definition XrdClFileSystemUtils.cc:90
XrdCl::FileSystemUtils::SpaceInfo::GetTotal
uint64_t GetTotal() const
Amount of total space in MB.
Definition XrdClFileSystemUtils.cc:75
XrdCl::FileSystemUtils::SpaceInfo::GetFree
uint64_t GetFree() const
Amount of free space in MB.
Definition XrdClFileSystemUtils.cc:80
XrdCl::FileSystemUtils::SpaceInfo::SpaceInfo
SpaceInfo(uint64_t total, uint64_t free, uint64_t used, uint64_t largestChunk)
Definition XrdClFileSystemUtils.cc:59
XrdCl::FileSystemUtils::GetSpaceInfo
static XRootDStatus GetSpaceInfo(SpaceInfo *&result, FileSystem *fs, const std::string &path)
Recursively get space information for given path.
Definition XrdClFileSystemUtils.cc:98
XrdCl::FileSystem
Send file/filesystem queries to an XRootD cluster.
Definition XrdClFileSystem.hh:203
XrdCl::FileSystem::Query
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFileSystem.cc:1255
XrdCl::FileSystem::DeepLocate
XRootDStatus DeepLocate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFileSystem.cc:1180
XrdCl::LocationInfo
Path location info.
Definition XrdClXRootDResponses.hh:44
XrdCl::LocationInfo::Begin
Iterator Begin()
Get the location begin iterator.
Definition XrdClXRootDResponses.hh:168
XrdCl::LocationInfo::Iterator
LocationList::iterator Iterator
Iterator over locations.
Definition XrdClXRootDResponses.hh:137
XrdCl::LocationInfo::End
Iterator End()
Get the location end iterator.
Definition XrdClXRootDResponses.hh:184
XrdCl::URL
URL representation.
Definition XrdClURL.hh:31
XrdCl::URL::ParamsMap
std::map< std::string, std::string > ParamsMap
Definition XrdClURL.hh:33
XrdCl::URL::GetParams
const ParamsMap & GetParams() const
Get the URL params.
Definition XrdClURL.hh:244
XrdCl::URL::IsValid
bool IsValid() const
Is the url valid.
Definition XrdClURL.cc:452
XrdCl::XRootDStatus
Request status.
Definition XrdClXRootDResponses.hh:219
XrdCl
Definition XrdClAction.hh:34
XrdCl::suPartial
const uint16_t suPartial
Definition XrdClStatus.hh:41
XrdCl::stError
const uint16_t stError
An error occurred that could potentially be retried.
Definition XrdClStatus.hh:32
XrdCl::errInvalidResponse
const uint16_t errInvalidResponse
Definition XrdClStatus.hh:99
XrdCl::FileSystemUtils::SpaceInfoImpl
Definition XrdClFileSystemUtils.cc:40
XrdCl::FileSystemUtils::SpaceInfoImpl::pUsed
uint64_t pUsed
Definition XrdClFileSystemUtils.cc:52
XrdCl::FileSystemUtils::SpaceInfoImpl::pFree
uint64_t pFree
Definition XrdClFileSystemUtils.cc:51
XrdCl::FileSystemUtils::SpaceInfoImpl::pTotal
uint64_t pTotal
Definition XrdClFileSystemUtils.cc:50
XrdCl::FileSystemUtils::SpaceInfoImpl::SpaceInfoImpl
SpaceInfoImpl(uint64_t total, uint64_t free, uint64_t used, uint64_t largestChunk)
Definition XrdClFileSystemUtils.cc:41
XrdCl::FileSystemUtils::SpaceInfoImpl::pLargestChunk
uint64_t pLargestChunk
Definition XrdClFileSystemUtils.cc:53
XrdCl::OpenFlags::Flags
Flags
Open flags, may be or'd when appropriate.
Definition XrdClFileSystem.hh:76
XrdCl::OpenFlags::Compress
@ Compress
Definition XrdClFileSystem.hh:78
XrdCl::OpenFlags::PrefName
@ PrefName
Definition XrdClFileSystem.hh:105
XrdCl::QueryCode::Space
@ Space
Query logical space stats.
Definition XrdClFileSystem.hh:60
XrdCl::Status::code
uint16_t code
Error type, or additional hints on what to do.
Definition XrdClStatus.hh:147
XrdCl::Status::IsOK
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124