-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdFileCacheIOEntireFile.cc
124 lines (98 loc) · 3.52 KB
/
XrdFileCacheIOEntireFile.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//----------------------------------------------------------------------------------
// Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
// Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
//----------------------------------------------------------------------------------
// 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/>.
//----------------------------------------------------------------------------------
#include <stdio.h>
//#include "XrdClient/XrdClientConst.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSfs/XrdSfsInterface.hh"
#include "XrdSys/XrdSysPthread.hh"
#include "XrdFileCacheIOEntireFile.hh"
#include "XrdFileCacheStats.hh"
#include "XrdFileCacheFactory.hh"
using namespace XrdFileCache;
//______________________________________________________________________________
IOEntireFile::IOEntireFile(XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache & cache)
: IO(io, stats, cache),
m_file(0)
{
clLog()->Info(XrdCl::AppMsg, "IO::IO() [%p] %s", this, m_io.Path());
XrdCl::URL url(io.Path());
std::string fname = Factory::GetInstance().RefConfiguration().m_cache_dir + url.GetPath();
m_file = new File(io, fname, 0, io.FSize());
}
IOEntireFile::~IOEntireFile()
{}
bool IOEntireFile::ioActive()
{
printf("called ioActive ...\n");
return m_file->InitiateClose();
}
XrdOucCacheIO *IOEntireFile::Detach()
{
m_statsGlobal.Add(m_file->GetStats());
XrdOucCacheIO * io = &m_io;
delete m_file;
m_file = 0;
// This will delete us!
m_cache.Detach(this);
return io;
}
int IOEntireFile::Read (char *buff, long long off, int size)
{
clLog()->Debug(XrdCl::AppMsg, "IOEntireFile::Read() [%p] %lld@%d %s", this, off, size, m_io.Path());
// protect from reads over the file size
if (off >= m_io.FSize())
return 0;
if (off < 0)
{
errno = EINVAL;
return -1;
}
if (off + size > m_io.FSize())
size = m_io.FSize() - off;
ssize_t bytes_read = 0;
ssize_t retval = 0;
retval = m_file->Read(buff, off, size);
clLog()->Debug(XrdCl::AppMsg, "IOEntireFile::Read() read from File retval = %d %s", retval, m_io.Path());
if (retval > 0)
{
bytes_read += retval;
buff += retval;
size -= retval;
// XXXX MT: the logick here is strange, see versions in
// alja/pfc-async-prefetch and in master.
// Also, what if retval == 0?
}
if (retval < 0)
{
clLog()->Error(XrdCl::AppMsg, "IOEntireFile::Read(), origin bytes read %d %s", retval, m_io.Path());
}
else if ((size > 0))
{
clLog()->Error(XrdCl::AppMsg, "IOEntireFile::Read() missed %d bytes %s", size, m_io.Path());
bytes_read += retval;
}
return (retval < 0) ? retval : bytes_read;
}
/*
* Perform a readv from the cache
*/
int IOEntireFile::ReadV (const XrdOucIOVec *readV, int n)
{
clLog()->Warning(XrdCl::AppMsg, "IOEntireFile::ReadV(), get %d requests %s", n, m_io.Path());
return m_file->ReadV(readV, n);
}