Skip to content
GitLab
Menu
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
b265af99
Commit
b265af99
authored
Dec 05, 2013
by
Eric Cano
Browse files
Moved the tape server's classes into castor::tape.
parent
53260ec4
Changes
31
Expand all
Show whitespace changes
Inline
Side-by-side
castor/tape/tapeserver/Daemon/tapeserverd.cpp
View file @
b265af99
...
...
@@ -35,7 +35,7 @@
int
main
(
int
argc
,
char
**
argv
)
{
try
{
T
ape
::
Server
::
Daemon
daemon
(
argc
,
argv
);
castor
::
t
ape
::
Server
::
Daemon
daemon
(
argc
,
argv
);
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"Uncaught standard exception in tapeserverd:"
<<
std
::
endl
<<
e
.
what
()
<<
std
::
endl
;
...
...
@@ -46,13 +46,13 @@ int main(int argc, char ** argv) {
}
}
T
ape
::
Server
::
Daemon
::
Daemon
(
int
argc
,
char
**
argv
)
throw
(
T
ape
::
Exception
)
{
castor
::
t
ape
::
Server
::
Daemon
::
Daemon
(
int
argc
,
char
**
argv
)
throw
(
castor
::
t
ape
::
Exception
)
{
m_options
=
getCommandLineOptions
(
argc
,
argv
);
if
(
m_options
.
daemonize
)
daemonize
();
}
T
ape
::
Server
::
Daemon
::
options
T
ape
::
Server
::
Daemon
::
getCommandLineOptions
(
int
argc
,
char
**
argv
)
throw
(
T
ape
::
Exception
)
castor
::
t
ape
::
Server
::
Daemon
::
options
castor
::
t
ape
::
Server
::
Daemon
::
getCommandLineOptions
(
int
argc
,
char
**
argv
)
throw
(
castor
::
t
ape
::
Exception
)
{
options
ret
;
/* Expect -f or --foreground */
...
...
@@ -68,14 +68,14 @@ throw (Tape::Exception)
break
;
case
':'
:
{
T
ape
::
Exceptions
::
InvalidArgument
ex
(
std
::
string
(
"The -"
)
+
(
char
)
optopt
+
" option requires a parameter"
);
castor
::
t
ape
::
Exceptions
::
InvalidArgument
ex
(
std
::
string
(
"The -"
)
+
(
char
)
optopt
+
" option requires a parameter"
);
throw
ex
;
}
case
'?'
:
{
std
::
stringstream
err
(
"Unknown command-line option"
);
if
(
optopt
)
err
<<
std
::
string
(
": -"
)
<<
optopt
;
T
ape
::
Exceptions
::
InvalidArgument
ex
(
err
.
str
().
c_str
());
castor
::
t
ape
::
Exceptions
::
InvalidArgument
ex
(
err
.
str
().
c_str
());
throw
ex
;
}
default:
...
...
@@ -83,7 +83,7 @@ throw (Tape::Exception)
std
::
stringstream
err
;
err
<<
"getopt_long returned the following unknown value: 0x"
<<
std
::
hex
<<
(
int
)
c
;
T
ape
::
Exceptions
::
InvalidArgument
ex
(
err
.
str
().
c_str
());
castor
::
t
ape
::
Exceptions
::
InvalidArgument
ex
(
err
.
str
().
c_str
());
throw
ex
;
}
}
...
...
@@ -91,7 +91,7 @@ throw (Tape::Exception)
return
ret
;
}
void
T
ape
::
Server
::
Daemon
::
daemonize
()
void
castor
::
t
ape
::
Server
::
Daemon
::
daemonize
()
{
pid_t
pid
,
sid
;
...
...
@@ -101,7 +101,7 @@ void Tape::Server::Daemon::daemonize()
/* Fork off the parent process */
pid
=
fork
();
if
(
pid
<
0
)
{
T
ape
::
Exceptions
::
Errnum
e
(
"Failed to fork in
T
ape::Server::Daemon::daemonize"
);
castor
::
t
ape
::
Exceptions
::
Errnum
e
(
"Failed to fork in
castor::t
ape::Server::Daemon::daemonize"
);
throw
e
;
}
/* If we got a good PID, then we can exit the parent process. */
...
...
@@ -115,22 +115,22 @@ void Tape::Server::Daemon::daemonize()
/* Create a new session for the child process */
sid
=
setsid
();
if
(
sid
<
0
)
{
T
ape
::
Exceptions
::
Errnum
e
(
"Failed to create new session in
T
ape::Server::Daemon::daemonize"
);
castor
::
t
ape
::
Exceptions
::
Errnum
e
(
"Failed to create new session in
castor::t
ape::Server::Daemon::daemonize"
);
throw
e
;
}
/* At this point we are executing as the child process, and parent process should be init */
if
(
getppid
()
!=
1
)
{
T
ape
::
Exception
e
(
"Failed to detach from parent process in
T
ape::Server::Daemon::daemonize"
);
castor
::
t
ape
::
Exception
e
(
"Failed to detach from parent process in
castor::t
ape::Server::Daemon::daemonize"
);
throw
e
;
}
/* Change the current working directory. This prevents the current
directory from being locked; hence not being able to remove it. */
if
((
chdir
(
m_options
.
runDirectory
.
c_str
()))
<
0
)
{
std
::
stringstream
err
(
"Failed to chdir in
T
ape::Server::Daemon::daemonize"
);
std
::
stringstream
err
(
"Failed to chdir in
castor::t
ape::Server::Daemon::daemonize"
);
err
<<
" ( destination directory: "
<<
m_options
.
runDirectory
<<
")"
;
T
ape
::
Exceptions
::
Errnum
e
(
err
.
str
());
castor
::
t
ape
::
Exceptions
::
Errnum
e
(
err
.
str
());
throw
e
;
}
...
...
castor/tape/tapeserver/Daemon/tapeserverd.hpp
View file @
b265af99
...
...
@@ -25,11 +25,12 @@
#pragma once
#include
"../Exception/Exception.hpp"
namespace
Tape
{
namespace
castor
{
namespace
tape
{
namespace
Server
{
class
Daemon
{
public:
Daemon
(
int
argc
,
char
**
argv
)
throw
(
T
ape
::
Exception
);
Daemon
(
int
argc
,
char
**
argv
)
throw
(
castor
::
t
ape
::
Exception
);
class
options
{
public:
options
()
:
daemonize
(
true
),
runDirectory
(
"/var/log/castor"
)
{}
...
...
@@ -37,9 +38,10 @@ namespace Tape {
std
::
string
runDirectory
;
};
private:
options
getCommandLineOptions
(
int
argc
,
char
**
argv
)
throw
(
T
ape
::
Exception
);
options
getCommandLineOptions
(
int
argc
,
char
**
argv
)
throw
(
castor
::
t
ape
::
Exception
);
void
daemonize
();
options
m_options
;
};
}
}
}
castor/tape/tapeserver/Documentation/.gitignore
0 → 100644
View file @
b265af99
*.aux
*.idx
*.out
*.toc
*converted-to.pdf
*.synctex.gz
*.log
castor/tape/tapeserver/Documentation/ProgrammersManual.tex
View file @
b265af99
...
...
@@ -229,7 +229,9 @@ The SCSI commands can be found in the SCSI section of Hackipedia.org
{
http://hackipedia.org/Hardware/SCSI/Stream
\%
20Commands/SCSI
\%
20Stream
\%
20Commands
\%
20-
\%
203.pdf
}
}
)
and the SCSI primary commands (SPC-4
\footnote
{
\href
{
http://hackipedia.org/Hardware/SCSI/Primary
\%
20Commands/SCSI
\%
20Primary
\%
20Commands
\%
20-
\%
204.pdf
}
{
http://hackipedia.org/Hardware/SCSI/Primary
\%
20Commands/SCSI
\%
20Primary
\%
20Commands
\%
20-
\%
204.pdf
}
}
).
{
http://hackipedia.org/Hardware/SCSI/Primary
\%
20Commands/SCSI
\%
20Primary
\%
20Commands
\%
20-
\%
204.pdf
}
}
\footnote
{
Latest drafts can be downloaded from
\href
{
http://www.t10.org/members/w
_
spc4.htm
}
{
http://www.t10.org/members/w
_
spc4.htm
}
}
).
\subsubsection
{
Manufacturer's specificities
}
\label
{
Manufacturer's specificities
}
...
...
castor/tape/tapeserver/Drive/Drive.cpp
View file @
b265af99
This diff is collapsed.
Click to expand it.
castor/tape/tapeserver/Drive/Drive.hpp
View file @
b265af99
...
...
@@ -36,7 +36,9 @@
* Class wrapping the tape server. Has to be templated (and hence fully in .hh)
* to allow unit testing against system wrapper.
*/
namespace
Tape
{
namespace
castor
{
namespace
tape
{
namespace
drives
{
/**
* Compressions statistics container, returned by Drive::getCompression()
...
...
@@ -320,7 +322,7 @@ namespace Tape {
protected:
SCSI
::
DeviceInfo
m_SCSIInfo
;
int
m_tapeFD
;
T
ape
::
System
::
virtualWrapper
&
m_sysWrapper
;
castor
::
t
ape
::
System
::
virtualWrapper
&
m_sysWrapper
;
struct
mtget
m_mtInfo
;
private:
/**
...
...
@@ -370,7 +372,7 @@ namespace Tape {
}
else
if
(
di
.
product
.
find
(
"03592"
))
{
m_drive
=
new
DriveIBM3592
(
di
,
sw
);
}
else
{
throw
Tape
::
Exception
(
std
::
string
(
"Unsupported drive type: "
)
+
di
.
product
);
throw
Exception
(
std
::
string
(
"Unsupported drive type: "
)
+
di
.
product
);
}
}
~
Drive
()
{
...
...
@@ -383,4 +385,6 @@ namespace Tape {
DriveGeneric
*
m_drive
;
};
}
}
// namespace drives
}
// namespace tape
}
// namespace castor
castor/tape/tapeserver/Drive/DriveTest.cpp
View file @
b265af99
...
...
@@ -37,7 +37,7 @@ namespace UnitTests {
TEST
(
TapeDrive
,
OpensCorrectly
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -55,18 +55,18 @@ TEST(TapeDrive, OpensCorrectly) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
drive
(
*
i
,
sysWrapper
);
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
drive
(
*
i
,
sysWrapper
);
}
}
}
TEST
(
TapeDrive
,
getPositionInfoAndPositionToLogicalObject
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -84,15 +84,15 @@ TEST(TapeDrive, getPositionInfoAndPositionToLogicalObject) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
dContainer
(
*
i
,
sysWrapper
);
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
*
i
,
sysWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
Tape
::
positionInfo
posInfo
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
positionInfo
posInfo
;
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
1
);
posInfo
=
drive
.
getPositionInfo
();
...
...
@@ -117,7 +117,7 @@ TEST(TapeDrive, getPositionInfoAndPositionToLogicalObject) {
}
TEST
(
TapeDrive
,
setDensityAndCompression
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -135,14 +135,14 @@ TEST(TapeDrive, setDensityAndCompression) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
dContainer
(
*
i
,
sysWrapper
);
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
*
i
,
sysWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
2
);
drive
.
setDensityAndCompression
();
...
...
@@ -164,7 +164,7 @@ TEST(TapeDrive, setDensityAndCompression) {
TEST
(
TapeDrive
,
setStDriverOptions
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -182,13 +182,13 @@ TEST(TapeDrive, setStDriverOptions) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
dContainer
(
*
i
,
sysWrapper
);
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
*
i
,
sysWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
struct
mtop
*>
())).
Times
(
1
);
drive
.
setSTBufferWrite
(
true
);
...
...
@@ -201,7 +201,7 @@ TEST(TapeDrive, setStDriverOptions) {
TEST
(
TapeDrive
,
getDeviceInfo
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -219,15 +219,15 @@ TEST(TapeDrive, getDeviceInfo) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
dContainer
(
*
i
,
sysWrapper
);
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
*
i
,
sysWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
Tape
::
deviceInfo
devInfo
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
deviceInfo
devInfo
;
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
2
);
devInfo
=
drive
.
getDeviceInfo
();
...
...
@@ -242,7 +242,7 @@ TEST(TapeDrive, getDeviceInfo) {
TEST
(
TapeDrive
,
getCompressionAndClearCompressionStats
)
{
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapper
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapper
;
sysWrapper
.
fake
.
setupSLC5
();
sysWrapper
.
delegateToFake
();
...
...
@@ -260,15 +260,15 @@ TEST(TapeDrive, getCompressionAndClearCompressionStats) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
7
);
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
DriveGeneric
*
drive
;
Tape
::
compressionStats
comp
;
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
DriveGeneric
*
drive
;
castor
::
tape
::
drives
::
compressionStats
comp
;
{
drive
=
new
Tape
::
DriveT10000
(
*
i
,
sysWrapper
);
drive
=
new
castor
::
tape
::
drives
::
DriveT10000
(
*
i
,
sysWrapper
);
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
1
);
comp
=
drive
->
getCompression
();
...
...
@@ -290,7 +290,7 @@ TEST(TapeDrive, getCompressionAndClearCompressionStats) {
delete
drive
;
}
{
drive
=
new
Tape
::
DriveIBM3592
(
*
i
,
sysWrapper
);
drive
=
new
castor
::
tape
::
drives
::
DriveIBM3592
(
*
i
,
sysWrapper
);
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
1
);
comp
=
drive
->
getCompression
();
...
...
@@ -312,7 +312,7 @@ TEST(TapeDrive, getCompressionAndClearCompressionStats) {
delete
drive
;
}
{
drive
=
new
Tape
::
DriveLTO
(
*
i
,
sysWrapper
);
drive
=
new
castor
::
tape
::
drives
::
DriveLTO
(
*
i
,
sysWrapper
);
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
1
);
comp
=
drive
->
getCompression
();
...
...
@@ -344,7 +344,7 @@ TEST(TapeDrive, getTapeAlerts) {
* SLC6).
*/
struct
{
void
operator
()
(
T
ape
::
System
::
mockWrapper
&
sysWrapper
)
{
void
operator
()
(
castor
::
t
ape
::
System
::
mockWrapper
&
sysWrapper
)
{
/* We expect the following calls: */
EXPECT_CALL
(
sysWrapper
,
opendir
(
_
)).
Times
(
AtLeast
(
3
));
EXPECT_CALL
(
sysWrapper
,
readdir
(
_
)).
Times
(
AtLeast
(
30
));
...
...
@@ -359,14 +359,14 @@ TEST(TapeDrive, getTapeAlerts) {
EXPECT_CALL
(
sysWrapper
,
stat
(
_
,
_
)).
Times
(
AtLeast
(
7
));
/* Test: detect devices, then open the device files */
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sysWrapper
);
for
(
std
::
vector
<
castor
::
tape
::
SCSI
::
DeviceInfo
>::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
if
(
SCSI
::
Types
::
tape
==
i
->
type
)
{
Tape
::
Drive
dContainer
(
*
i
,
sysWrapper
);
if
(
castor
::
tape
::
SCSI
::
Types
::
tape
==
i
->
type
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
*
i
,
sysWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
EXPECT_CALL
(
sysWrapper
,
ioctl
(
_
,
_
,
An
<
sg_io_hdr_t
*>
())).
Times
(
1
);
std
::
vector
<
std
::
string
>
alerts
=
drive
.
getTapeAlerts
();
ASSERT_EQ
(
3U
,
alerts
.
size
());
...
...
@@ -384,8 +384,8 @@ TEST(TapeDrive, getTapeAlerts) {
/* Prepare the test harness */
T
ape
::
System
::
mockWrapper
sysWrapperSLC5
;
T
ape
::
System
::
mockWrapper
sysWrapperSLC6
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapperSLC5
;
castor
::
t
ape
::
System
::
mockWrapper
sysWrapperSLC6
;
sysWrapperSLC5
.
fake
.
setupSLC5
();
sysWrapperSLC6
.
fake
.
setupSLC6
();
sysWrapperSLC5
.
delegateToFake
();
...
...
castor/tape/tapeserver/Drive/TapeDriveReadWriteTest.cpp
View file @
b265af99
...
...
@@ -38,7 +38,7 @@
* assertion and exits.
* @param expected_position expected position
*/
void
print_and_assert_position
(
Tape
::
DriveGeneric
&
drive
,
int
expected_position
)
void
print_and_assert_position
(
castor
::
tape
::
drives
::
DriveGeneric
&
drive
,
int
expected_position
)
{
int
curPos
=
(
int
)
drive
.
getPositionInfo
().
currentPosition
;
std
::
cout
<<
"CurrentPosition: "
<<
curPos
<<
" (Expected: "
<<
expected_position
<<
")"
<<
std
::
endl
;
...
...
@@ -62,19 +62,19 @@ void print_and_assert_data(const char * expected_data, const char * actual_data)
int
main
()
{
int
fail
=
0
;
T
ape
::
System
::
realWrapper
sWrapper
;
SCSI
::
DeviceVector
dl
(
sWrapper
);
for
(
SCSI
::
DeviceVector
::
iterator
i
=
dl
.
begin
();
castor
::
t
ape
::
System
::
realWrapper
sWrapper
;
castor
::
tape
::
SCSI
::
DeviceVector
dl
(
sWrapper
);
for
(
castor
::
tape
::
SCSI
::
DeviceVector
::
iterator
i
=
dl
.
begin
();
i
!=
dl
.
end
();
i
++
)
{
SCSI
::
DeviceInfo
&
dev
=
(
*
i
);
castor
::
tape
::
SCSI
::
DeviceInfo
&
dev
=
(
*
i
);
std
::
cout
<<
std
::
endl
<<
"-- SCSI device: "
<<
dev
.
sg_dev
<<
" ("
<<
dev
.
nst_dev
<<
")"
<<
std
::
endl
;
if
(
dev
.
type
==
SCSI
::
Types
::
tape
)
{
Tape
::
Drive
dContainer
(
dev
,
sWrapper
);
if
(
dev
.
type
==
castor
::
tape
::
SCSI
::
Types
::
tape
)
{
castor
::
tape
::
drives
::
Drive
dContainer
(
dev
,
sWrapper
);
/* Compiler cannot implicitly use the conversion operator. Create an
* intermediate reference*/
Tape
::
DriveGeneric
&
drive
=
dContainer
;
Tape
::
deviceInfo
devInfo
;
castor
::
tape
::
drives
::
DriveGeneric
&
drive
=
dContainer
;
castor
::
tape
::
drives
::
deviceInfo
devInfo
;
try
{
devInfo
=
drive
.
getDeviceInfo
();
...
...
@@ -115,7 +115,7 @@ int main ()
}
try
{
Tape
::
positionInfo
posInfo
=
drive
.
getPositionInfo
();
castor
::
tape
::
drives
::
positionInfo
posInfo
=
drive
.
getPositionInfo
();
std
::
cout
<<
"-- INFO --------------------------------------"
<<
std
::
endl
<<
" posInfo.currentPosition : "
<<
posInfo
.
currentPosition
<<
std
::
endl
<<
" posInfo.oldestDirtyObject : "
<<
posInfo
.
oldestDirtyObject
<<
std
::
endl
...
...
@@ -146,7 +146,7 @@ int main ()
* Trying to get compression from the drive. Read or write should be
* done before to have something in the data fields.
*/
Tape
::
compressionStats
comp
=
drive
.
getCompression
();
castor
::
tape
::
drives
::
compressionStats
comp
=
drive
.
getCompression
();
std
::
cout
<<
"-- INFO --------------------------------------"
<<
std
::
endl
<<
" fromHost : "
<<
comp
.
fromHost
<<
std
::
endl
<<
" toHost : "
<<
comp
.
toHost
<<
std
::
endl
...
...
castor/tape/tapeserver/Exception/Exception.cpp
View file @
b265af99
...
...
@@ -38,22 +38,24 @@
/* TODO remove me: it should be temporary */
#include
<iostream>
const
char
*
Tape
::
Exception
::
what
()
const
throw
()
{
using
namespace
castor
::
tape
;
const
char
*
Exception
::
what
()
const
throw
()
{
return
m_what
.
c_str
();
}
const
char
*
Tape
::
Exception
::
shortWhat
()
const
throw
()
{
const
char
*
Exception
::
shortWhat
()
const
throw
()
{
return
m_shortWhat
.
c_str
();
}
void
Tape
::
Exception
::
setWhat
(
const
std
::
string
&
what
)
{
void
Exception
::
setWhat
(
const
std
::
string
&
what
)
{
std
::
stringstream
w
;
w
<<
what
<<
std
::
endl
<<
std
::
string
(
backtrace
);
m_what
=
w
.
str
();
m_shortWhat
=
what
;
}
Tape
::
Exceptions
::
Errnum
::
Errnum
(
std
::
string
what
)
:
Exception
(
""
)
{
Exceptions
::
Errnum
::
Errnum
(
std
::
string
what
)
:
Exception
(
""
)
{
m_errnum
=
errno
;
char
s
[
1000
];
/* _XOPEN_SOURCE seems not to work. */
...
...
@@ -74,7 +76,7 @@ Tape::Exceptions::Errnum::Errnum(std::string what):Exception("") {
setWhat
(
w2
.
str
());
}
Tape
::
Exceptions
::
Backtrace
::
Backtrace
()
{
Exceptions
::
Backtrace
::
Backtrace
()
{
void
*
array
[
200
];
size_t
depth
=
::
backtrace
(
array
,
sizeof
(
array
)
/
sizeof
(
void
*
));
char
**
strings
=
::
backtrace_symbols
(
array
,
depth
);
...
...
castor/tape/tapeserver/Exception/Exception.hpp
View file @
b265af99
...
...
@@ -26,7 +26,8 @@
#include
<exception>
#include
<string>
namespace
Tape
{
namespace
castor
{
namespace
tape
{
namespace
Exceptions
{
class
Backtrace
{
...
...
@@ -44,7 +45,7 @@ namespace Tape {
virtual
~
Exception
()
throw
()
{};
virtual
const
char
*
what
()
const
throw
();
virtual
const
char
*
shortWhat
()
const
throw
();
Tape
::
Exceptions
::
Backtrace
backtrace
;
Exceptions
::
Backtrace
backtrace
;
protected:
void
setWhat
(
const
std
::
string
&
w
);
private:
...
...
@@ -53,7 +54,7 @@ namespace Tape {
};
namespace
Exceptions
{
class
Errnum
:
public
Tape
::
Exception
{
class
Errnum
:
public
Exception
{
public:
Errnum
(
std
::
string
what
=
""
);
virtual
~
Errnum
()
throw
()
{};
...
...
@@ -66,8 +67,9 @@ namespace Tape {
std
::
string
m_strerror
;
};
class
InvalidArgument
:
public
Tape
::
Exception
{
public:
InvalidArgument
(
std
::
string
what
=
""
)
:
Tape
::
Exception
(
what
)
{};
class
InvalidArgument
:
public
Exception
{
public:
InvalidArgument
(
std
::
string
what
=
""
)
:
Exception
(
what
)
{};
};
}
}
}
//namespace tape
}
//namespace castor
castor/tape/tapeserver/Exception/ExceptionTest.cpp
View file @
b265af99
...
...
@@ -38,7 +38,7 @@ namespace UnitTests {
/* Prevent inlining: it makes this test fail! */
void
__attribute__
((
noinline
))
Nested
::
f1
()
{
throw
T
ape
::
Exception
(
""
);
throw
castor
::
t
ape
::
Exception
(
""
);
}
/* Prevent inlining: it makes this test fail!
...
...
@@ -55,10 +55,10 @@ namespace UnitTests {
TEST
(
Exceptions
,
stacktrace_with_demangling
)
{
try
{
Nested
x
;
}
catch
(
T
ape
::
Exception
&
e
)
{
}
catch
(
castor
::
t
ape
::
Exception
&
e
)
{
std
::
string
bt
=
e
.
backtrace
;
ASSERT_NE
(
std
::
string
::
npos
,
bt
.
find
(
"Nested::f1"
));
ASSERT_NE
(
std
::
string
::
npos
,
bt
.
find
(
"
T
ape::Exceptions::Backtrace::Backtrace"
));
ASSERT_NE
(
std
::
string
::
npos
,
bt
.
find
(
"
castor::t
ape::Exceptions::Backtrace::Backtrace"
));
ASSERT_EQ
(
""
,
std
::
string
(
e
.
shortWhat
()));
std
::
string
fullWhat
(
e
.
what
());
ASSERT_NE
(
std
::
string
::
npos
,
fullWhat
.
find
(
"Nested::f1"
));
...
...
@@ -69,7 +69,7 @@ namespace UnitTests {
/* Mickey Mouse test as we had trouble which throwing Errnum (with errno=ENOENT)*/
errno
=
ENOENT
;
try
{
throw
T
ape
::
Exceptions
::
Errnum
(
"Test ENOENT"
);
throw
castor
::
t
ape
::
Exceptions
::
Errnum
(
"Test ENOENT"
);
}
catch
(
std
::
exception
&
e
)
{
std
::
string
temp
=
e
.
what
();
temp
+=
" "
;
...
...
castor/tape/tapeserver/File/Structures.cpp
View file @
b265af99
...
...
@@ -27,41 +27,43 @@
#include
<time.h>
#include
<stdio.h>
void
Tape
::
AULFile
::
VOL1
::
fill
(
std
::
string
vsn
)
{
using
namespace
castor
::
tape
;
void
AULFile
::
VOL1
::
fill
(
std
::
string
vsn
)
{
setString
(
label
,
"VOL1"
);
setString
(
VSN
,
vsn
);