Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
d0001fa3
Commit
d0001fa3
authored
11 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up rmc_send_scsi_cmd() just a little bit
parent
a906baa9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
h/rmc_send_scsi_cmd.h
+44
-0
44 additions, 0 deletions
h/rmc_send_scsi_cmd.h
rmc/Imakefile
+1
-1
1 addition, 1 deletion
rmc/Imakefile
rmc/rmc_send_scsi_cmd.c
+35
-46
35 additions, 46 deletions
rmc/rmc_send_scsi_cmd.c
with
80 additions
and
47 deletions
h/rmc_send_scsi_cmd.h
0 → 100644
+
44
−
0
View file @
d0001fa3
/******************************************************************************
* rmc_send_scsi_cmd.h
*
* 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 Sebastien Ponce
*****************************************************************************/
#ifndef H_RMC_SEND_SCSI_CMD_H
#define H_RMC_SEND_SCSI_CMD_H 1
int
rmc_send_scsi_cmd
(
const
int
tapefd
,
const
char
*
const
path
,
const
int
do_not_open
,
const
unsigned
char
*
const
cdb
,
const
int
cdblen
,
unsigned
char
*
const
buffer
,
const
int
buflen
,
char
*
const
sense
,
const
int
senselen
,
const
int
timeout
,
/* in milliseconds */
const
int
flags
,
int
*
const
nb_sense_ret
,
char
**
const
msgaddr
);
#endif
/* H_RMC_SEND_SCSI_CMD_H */
This diff is collapsed.
Click to expand it.
rmc/Imakefile
+
1
−
1
View file @
d0001fa3
...
...
@@ -11,7 +11,7 @@ include $(CASTOR_ROOT)/tape/Makefile
RMCD_DEPLIBS = DepSharedLibraryTargetName(tape,castortape)
RMCD_LIBS = $(RMCD_DEPLIBS) BuildRPathcastortape
RMCD_OBJS = rmc_serv.o rmc_procreq.o rmc_logit.o rmc_sendrep.o rmc_smcsubr.o
RMCD_OBJS = rmc_serv.o rmc_procreq.o rmc_logit.o rmc_sendrep.o rmc_smcsubr.o
rmc_send_scsi_cmd.o
TapeProgramTarget(rmcd,$(RMCD_OBJS),$(RMCD_DEPLIBS),$(RMCD_LIBS),755)
ADMMANPAGE(rmcd)
TapeMakeDir($(LOGPATH),0755)
...
...
This diff is collapsed.
Click to expand it.
rmc/rmc_send_scsi_cmd.c
+
35
−
46
View file @
d0001fa3
...
...
@@ -3,7 +3,7 @@
* All rights reserved
*/
/* send_scsi_cmd - Send a SCSI command to a device */
/*
rmc_
send_scsi_cmd - Send a SCSI command to a device */
/* return -5 if not supported on this platform (serrno = SEOPNOTSUP)
* -4 if SCSI error (serrno = EIO)
* -3 if CAM error (serrno = EIO)
...
...
@@ -31,10 +31,10 @@
#endif
#include
"/usr/include/scsi/sg.h"
#include
<sys/stat.h>
#include
"scsictl.h"
#include
"serrno.h"
#include
"
Ctape
.h"
static
char
tp
_err_msgbuf
[
132
];
#include
"
h/
scsictl.h"
#include
"
h/
serrno.h"
#include
"
h/rmc_send_scsi_cmd
.h"
static
char
rmc
_err_msgbuf
[
132
];
static
char
*
sk_msg
[]
=
{
"No sense"
,
"Recovered error"
,
...
...
@@ -53,19 +53,8 @@ static char *sk_msg[] = {
"Miscompare"
,
"Reserved"
,
};
struct
scsi_info
{
int
status
;
char
*
text
;
};
struct
scsi_info
scsi_codmsg
[]
=
{
{
SCSI_STATUS_CHECK_CONDITION
,
"Check condition"
},
{
SCSI_STATUS_BUSY
,
"Target busy"
},
{
SCSI_STATUS_RESERVATION_CONFLICT
,
"Reservation conflict"
},
{
0xFF
,
NULL
}
};
#define PROCBUFSZ 80
static
void
find_sgpath
(
char
*
sgpath
,
int
maj
,
int
min
)
{
static
void
find_sgpath
(
char
*
const
sgpath
,
const
int
maj
,
const
int
min
)
{
/*
Find the sg device for a pair of major and minor device IDs
...
...
@@ -140,7 +129,7 @@ static void find_sgpath(char *sgpath, int maj, int min) {
}
int
send_scsi_cmd
(
int
rmc_
send_scsi_cmd
(
const
int
tapefd
,
const
char
*
const
path
,
const
int
do_not_open
,
...
...
@@ -168,14 +157,14 @@ int send_scsi_cmd (
int
timeout_in_jiffies
=
0
;
int
sg_big_buff_val
=
SG_BIG_BUFF
;
int
procfd
,
nbread
;
char
procbuf
[
PROCBUFSZ
];
char
procbuf
[
80
];
(
void
)
senselen
;
/* First the value in /proc of the max buffer size for the sg driver */
procfd
=
open
(
"/proc/scsi/sg/def_reserved_size"
,
O_RDONLY
);
if
(
procfd
>=
0
)
{
memset
(
procbuf
,
0
,
PROCBUFSZ
);
nbread
=
read
(
procfd
,
procbuf
,
PROCBUFSZ
-
1
);
memset
(
procbuf
,
0
,
sizeof
(
procbuf
)
);
nbread
=
read
(
procfd
,
procbuf
,
sizeof
(
procbuf
)
-
1
);
if
(
nbread
>
0
)
{
long
int
tmp
;
char
*
endptr
=
NULL
;
...
...
@@ -188,9 +177,9 @@ int send_scsi_cmd (
}
if
((
int
)
sizeof
(
struct
sg_header
)
+
cdblen
+
buflen
>
sg_big_buff_val
)
{
sprintf
(
tp
_err_msgbuf
,
"blocksize too large (max %zd)
\n
"
,
sprintf
(
rmc
_err_msgbuf
,
"blocksize too large (max %zd)
\n
"
,
sg_big_buff_val
-
sizeof
(
struct
sg_header
)
-
cdblen
);
*
msgaddr
=
tp
_err_msgbuf
;
*
msgaddr
=
rmc
_err_msgbuf
;
serrno
=
EINVAL
;
return
(
-
1
);
}
...
...
@@ -198,8 +187,8 @@ int send_scsi_cmd (
if
(
sg_bufsiz
>
0
)
free
(
sg_buffer
);
if
((
sg_buffer
=
malloc
(
sizeof
(
struct
sg_header
)
+
cdblen
+
buflen
))
==
NULL
)
{
serrno
=
errno
;
sprintf
(
tp
_err_msgbuf
,
TP005
);
*
msgaddr
=
tp
_err_msgbuf
;
sprintf
(
rmc
_err_msgbuf
,
"cannot get memory"
);
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
1
);
}
sg_bufsiz
=
sizeof
(
struct
sg_header
)
+
cdblen
+
buflen
;
...
...
@@ -210,18 +199,18 @@ int send_scsi_cmd (
}
else
{
if
(
stat
(
path
,
&
sbuf
)
<
0
)
{
serrno
=
errno
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
path
,
"st
at
"
,
strerror
(
errno
));
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : stat error : %s
\n
"
,
p
at
h
,
strerror
(
errno
));
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
1
);
}
/* get the major device ID of the sg devices ... */
if
(
stat
(
"/dev/sg0"
,
&
sbufa
)
<
0
)
{
serrno
=
errno
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
"/dev/sg0
"
,
"stat
"
,
strerror
(
errno
));
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"/dev/sg0
: stat error : %s
\n
"
,
strerror
(
errno
));
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
1
);
}
/* ... to detect links and use the path directly! */
...
...
@@ -233,9 +222,9 @@ int send_scsi_cmd (
if
((
fd
=
open
(
sgpath
,
O_RDWR
))
<
0
)
{
serrno
=
errno
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
sgpath
,
"open"
,
strerror
(
errno
));
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : open error : %s
\n
"
,
sgpath
,
strerror
(
errno
));
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
1
);
}
}
...
...
@@ -257,9 +246,9 @@ int send_scsi_cmd (
if
(
write
(
fd
,
sg_buffer
,
n
)
<
0
)
{
*
msgaddr
=
(
char
*
)
strerror
(
errno
);
serrno
=
errno
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
sgpath
,
"write"
,
*
msgaddr
);
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : write error : %s
\n
"
,
sgpath
,
*
msgaddr
);
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
if
(
!
do_not_open
)
close
(
fd
);
return
(
-
2
);
}
...
...
@@ -267,9 +256,9 @@ int send_scsi_cmd (
((
flags
&
SCSI_IN
)
?
buflen
:
0
)))
<
0
)
{
*
msgaddr
=
(
char
*
)
strerror
(
errno
);
serrno
=
errno
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
sgpath
,
"read"
,
*
msgaddr
);
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : read error : %s
\n
"
,
sgpath
,
*
msgaddr
);
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
if
(
!
do_not_open
)
close
(
fd
);
return
(
-
2
);
}
...
...
@@ -290,16 +279,16 @@ int send_scsi_cmd (
sk_msg
[
*
(
sense
+
2
)
&
0xF
],
*
(
sense
+
12
),
*
(
sense
+
13
));
tmp_msgbuf
[
sizeof
(
tmp_msgbuf
)
-
1
]
=
'\0'
;
serrno
=
EIO
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
sgpath
,
"scsi"
,
tmp_msgbuf
);
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : scsi error : %s
\n
"
,
sgpath
,
tmp_msgbuf
);
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
4
);
}
else
if
(
sg_hd
->
result
)
{
*
msgaddr
=
(
char
*
)
strerror
(
sg_hd
->
result
);
serrno
=
sg_hd
->
result
;
snprintf
(
tp
_err_msgbuf
,
sizeof
(
tp
_err_msgbuf
),
TP042
,
sgpath
,
"read"
,
*
msgaddr
);
tp
_err_msgbuf
[
sizeof
(
tp
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
tp
_err_msgbuf
;
snprintf
(
rmc
_err_msgbuf
,
sizeof
(
rmc
_err_msgbuf
),
"%s : read error : %s
\n
"
,
sgpath
,
*
msgaddr
);
rmc
_err_msgbuf
[
sizeof
(
rmc
_err_msgbuf
)
-
1
]
=
'\0'
;
*
msgaddr
=
rmc
_err_msgbuf
;
return
(
-
2
);
}
if
(
n
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment