Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
5341d8a2
Commit
5341d8a2
authored
Jul 22, 2014
by
David COME
Browse files
Moved from File.[hc]pp all Disk stuff to DiskFile.[hc]pp
parent
4c0f496c
Changes
7
Hide whitespace changes
Inline
Side-by-side
castor/tape/tapeserver/daemon/Payload.hpp
View file @
5341d8a2
...
...
@@ -21,6 +21,8 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
<zlib.h>
#include
"castor/tape/tapeserver/file/DiskFile.hpp"
#include
"castor/tape/tapeserver/file/File.hpp"
#pragma once
...
...
castor/tape/tapeserver/file/CMakeLists.txt
View file @
5341d8a2
add_library
(
File File.cpp Structures.cpp
)
add_library
(
File File.cpp
DiskFile.cpp
Structures.cpp
)
target_link_libraries
(
File castorrfio
)
castor/tape/tapeserver/file/DiskFile.cpp
0 → 100644
View file @
5341d8a2
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
"castor/tape/tapeserver/file/DiskFile.hpp"
#include
"castor/exception/Errnum.hpp"
#include
"castor/exception/SErrnum.hpp"
#include
"castor/exception/Mismatch.hpp"
#include
"castor/exception/InvalidArgument.hpp"
#include
"castor/tape/tapegateway/FilesToMigrateList.hpp"
#include
<rfio_api.h>
namespace
castor
{
namespace
tape
{
namespace
diskFile
{
//toy example using rfio, will not use rfio in production probably xroot or ceph protocols
ReadFile
::
ReadFile
(
const
std
::
string
&
url
)
{
m_fd
=
rfio_open64
((
char
*
)
url
.
c_str
(),
O_RDONLY
);
castor
::
exception
::
SErrnum
::
throwOnMinusOne
(
m_fd
,
"Failed rfio_open64() in diskFile::ReadFile::ReadFile"
);
}
size_t
ReadFile
::
read
(
void
*
data
,
const
size_t
size
)
{
return
rfio_read
(
m_fd
,
data
,
size
);
}
ReadFile
::~
ReadFile
()
throw
()
{
rfio_close
(
m_fd
);
}
WriteFile
::
WriteFile
(
const
std
::
string
&
url
)
:
closeTried
(
false
){
m_fd
=
rfio_open64
((
char
*
)
url
.
c_str
(),
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0666
);
/*
* The O_TRUNC flag is here to prevent file corruption in case retrying to write a file to disk.
* In principle this should be totally safe as the filenames are generated using unique ids given by
* the database, so the protection is provided by the uniqueness of the filenames.
* As a side note, we tried to use the O_EXCL flag as well (which would provide additional safety)
* however this flag does not work with rfio_open64 as apparently it causes memory corruption.
*/
castor
::
exception
::
SErrnum
::
throwOnMinusOne
(
m_fd
,
"Failed rfio_open64() in diskFile::WriteFile::WriteFile"
);
}
void
WriteFile
::
write
(
const
void
*
data
,
const
size_t
size
)
{
rfio_write
(
m_fd
,
(
void
*
)
data
,
size
);
}
void
WriteFile
::
close
()
{
closeTried
=
true
;
castor
::
exception
::
Errnum
::
throwOnMinusOne
(
rfio_close
(
m_fd
),
"Failed rfio_close() in diskFile::WriteFile::close"
);
}
WriteFile
::~
WriteFile
()
throw
()
{
if
(
!
closeTried
){
rfio_close
(
m_fd
);
}
}
}
//end of namespace diskFile
}}
\ No newline at end of file
castor/tape/tapeserver/file/DiskFile.hpp
0 → 100644
View file @
5341d8a2
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include
"castor/tape/tapeserver/file/Structures.hpp"
#include
"castor/exception/Exception.hpp"
#include
"castor/tape/tapegateway/FileToRecallStruct.hpp"
#include
"castor/tape/tapegateway/FileToMigrateStruct.hpp"
#include
"castor/tape/tapeserver/client/ClientInterface.hpp"
namespace
castor
{
namespace
tape
{
/**
* Namespace managing the reading and writing of files to and from disk.
*/
namespace
diskFile
{
class
ReadFile
{
public:
/**
* Constructor of the ReadFile class. It opens the file for reading with the O_RDONLY flag.
* @param url: Uniform Resource Locator of the file we want to read
*/
ReadFile
(
const
std
::
string
&
url
)
;
/**
* Reads data from the file.
* @param data: pointer to the data buffer
* @param size: size of the buffer
* @return The amount of data actually copied. Zero at end of file.
*/
size_t
read
(
void
*
data
,
const
size_t
size
)
;
/**
* Destructor of the ReadFile class. It closes the corresponding file descriptor.
*/
~
ReadFile
()
throw
();
private:
int
m_fd
;
};
class
WriteFile
{
public:
/**
* Constructor of the WriteFile class. It opens the file for writing with the O_WRONLY, O_CREAT and O_EXCL flags.
* @param url: Uniform Resource Locator of the file we want to write
*/
WriteFile
(
const
std
::
string
&
url
)
;
/**
* Writes a block of data on disk
* @param data: buffer to copy the data from
* @param size: size of the buffer
*/
void
write
(
const
void
*
data
,
const
size_t
size
)
;
/**
* Closes the corresponding file descriptor, which may throw an exception.
*/
void
close
()
;
/**
* Destructor of the WriteFile class.
*/
~
WriteFile
()
throw
();
private:
int
m_fd
;
bool
closeTried
;
};
}
//end of namespace diskFile
}}
\ No newline at end of file
castor/tape/tapeserver/file/File.cpp
View file @
5341d8a2
...
...
@@ -504,47 +504,5 @@ namespace castor {
}
//end of namespace tapeFile
namespace
diskFile
{
//toy example using rfio, will not use rfio in production probably xroot or ceph protocols
ReadFile
::
ReadFile
(
const
std
::
string
&
url
)
{
m_fd
=
rfio_open64
((
char
*
)
url
.
c_str
(),
O_RDONLY
);
castor
::
exception
::
SErrnum
::
throwOnMinusOne
(
m_fd
,
"Failed rfio_open64() in diskFile::ReadFile::ReadFile"
);
}
size_t
ReadFile
::
read
(
void
*
data
,
const
size_t
size
)
{
return
rfio_read
(
m_fd
,
data
,
size
);
}
ReadFile
::~
ReadFile
()
throw
()
{
rfio_close
(
m_fd
);
}
WriteFile
::
WriteFile
(
const
std
::
string
&
url
)
:
closeTried
(
false
){
m_fd
=
rfio_open64
((
char
*
)
url
.
c_str
(),
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0666
);
/*
* The O_TRUNC flag is here to prevent file corruption in case retrying to write a file to disk.
* In principle this should be totally safe as the filenames are generated using unique ids given by
* the database, so the protection is provided by the uniqueness of the filenames.
* As a side note, we tried to use the O_EXCL flag as well (which would provide additional safety)
* however this flag does not work with rfio_open64 as apparently it causes memory corruption.
*/
castor
::
exception
::
SErrnum
::
throwOnMinusOne
(
m_fd
,
"Failed rfio_open64() in diskFile::WriteFile::WriteFile"
);
}
void
WriteFile
::
write
(
const
void
*
data
,
const
size_t
size
)
{
rfio_write
(
m_fd
,
(
void
*
)
data
,
size
);
}
void
WriteFile
::
close
()
{
closeTried
=
true
;
castor
::
exception
::
Errnum
::
throwOnMinusOne
(
rfio_close
(
m_fd
),
"Failed rfio_close() in diskFile::WriteFile::close"
);
}
WriteFile
::~
WriteFile
()
throw
()
{
if
(
!
closeTried
){
rfio_close
(
m_fd
);
}
}
}
//end of namespace diskFile
}
//end of namespace tape
}
//end of namespace castor
castor/tape/tapeserver/file/File.hpp
View file @
5341d8a2
...
...
@@ -45,52 +45,52 @@ namespace castor {
Trailer
};
class
TapeFormatError
:
public
Exception
{
class
TapeFormatError
:
public
castor
::
tape
::
Exception
{
public:
TapeFormatError
(
const
std
::
string
&
what
)
:
Exception
(
what
)
{}
};
class
TapeMediaError
:
public
Exception
{
class
TapeMediaError
:
public
castor
::
tape
::
Exception
{
public:
TapeMediaError
(
const
std
::
string
&
what
)
:
Exception
(
what
)
{}
};
class
EndOfFile
:
public
Exception
{
class
EndOfFile
:
public
castor
::
tape
::
Exception
{
public:
EndOfFile
()
:
Exception
(
"End Of File reached"
)
{}
};
class
SessionAlreadyInUse
:
public
Exception
{
class
SessionAlreadyInUse
:
public
castor
::
tape
::
Exception
{
public:
SessionAlreadyInUse
()
:
Exception
(
"Session already in use"
)
{}
};
class
SessionCorrupted
:
public
Exception
{
class
SessionCorrupted
:
public
castor
::
tape
::
Exception
{
public:
SessionCorrupted
()
:
Exception
(
"Session corrupted"
)
{}
};
class
FileClosedTwice
:
public
Exception
{
class
FileClosedTwice
:
public
castor
::
tape
::
Exception
{
public:
FileClosedTwice
()
:
Exception
(
"Trying to close a file twice"
)
{}
};
class
ZeroFileWritten
:
public
Exception
{
class
ZeroFileWritten
:
public
castor
::
tape
::
Exception
{
public:
ZeroFileWritten
()
:
Exception
(
"Trying to write a file with size 0"
)
{}
};
class
TapeNotEmpty
:
public
Exception
{
class
TapeNotEmpty
:
public
castor
::
tape
::
Exception
{
public:
TapeNotEmpty
()
:
Exception
(
"Trying to label a non-empty tape without the
\"
force
\"
setting"
)
{}
};
class
UnsupportedPositioningMode
:
public
Exception
{
class
UnsupportedPositioningMode
:
public
castor
::
tape
::
Exception
{
public:
UnsupportedPositioningMode
()
:
Exception
(
"Trying to use an unsupported positioning mode"
)
{}
};
class
WrongBlockSize
:
public
Exception
{
class
WrongBlockSize
:
public
castor
::
tape
::
Exception
{
public:
WrongBlockSize
()
:
Exception
(
"Trying to use a wrong block size"
)
{}
};
...
...
@@ -151,15 +151,12 @@ namespace castor {
};
/**
*
Class containign static
helper functions that turn block id byte
*
namespace containing
helper functions that turn block id byte
* collections from fileToRecallStruct into uint32_t
*/
class
BlockId
{
public:
static
uint32_t
extract
(
const
castor
::
tape
::
tapegateway
::
FileToRecallStruct
&
);
static
void
set
(
castor
::
tape
::
tapegateway
::
FileToRecallStruct
&
,
uint32_t
blockId
);
namespace
BlockId
{
uint32_t
extract
(
const
castor
::
tape
::
tapegateway
::
FileToRecallStruct
&
);
void
set
(
castor
::
tape
::
tapegateway
::
FileToRecallStruct
&
,
uint32_t
blockId
);
};
/**
* Class keeping track of a tape label session on a tape. The session will
...
...
@@ -533,68 +530,5 @@ namespace castor {
int
m_numberOfBlocks
;
};
}
/**
* Namespace managing the reading and writing of files to and from disk.
*/
namespace
diskFile
{
class
ReadFile
{
public:
/**
* Constructor of the ReadFile class. It opens the file for reading with the O_RDONLY flag.
* @param url: Uniform Resource Locator of the file we want to read
*/
ReadFile
(
const
std
::
string
&
url
)
;
/**
* Reads data from the file.
* @param data: pointer to the data buffer
* @param size: size of the buffer
* @return The amount of data actually copied. Zero at end of file.
*/
size_t
read
(
void
*
data
,
const
size_t
size
)
;
/**
* Destructor of the ReadFile class. It closes the corresponding file descriptor.
*/
~
ReadFile
()
throw
();
private:
int
m_fd
;
};
class
WriteFile
{
public:
/**
* Constructor of the WriteFile class. It opens the file for writing with the O_WRONLY, O_CREAT and O_EXCL flags.
* @param url: Uniform Resource Locator of the file we want to write
*/
WriteFile
(
const
std
::
string
&
url
)
;
/**
* Writes a block of data on disk
* @param data: buffer to copy the data from
* @param size: size of the buffer
*/
void
write
(
const
void
*
data
,
const
size_t
size
)
;
/**
* Closes the corresponding file descriptor, which may throw an exception.
*/
void
close
()
;
/**
* Destructor of the WriteFile class.
*/
~
WriteFile
()
throw
();
private:
int
m_fd
;
bool
closeTried
;
};
}
//end of namespace diskFile
}
//end of namespace tape
}
//end of namespace castor
castor/tape/tapeserver/file/FileTest.cpp
View file @
5341d8a2
...
...
@@ -25,6 +25,7 @@
#include
"castor/tape/tapeserver/SCSI/Device.hpp"
#include
"castor/tape/tapeserver/drive/Drive.hpp"
#include
"castor/tape/tapeserver/file/File.hpp"
#include
"castor/tape/tapeserver/file/DiskFile.hpp"
#include
"castor/tape/tapeserver/exception/Exception.hpp"
#include
"castor/exception/Errnum.hpp"
#include
"castor/tape/tapeserver/client/ClientInterface.hpp"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment