targ: fix compiling the example

The targ example program doesn't compile with current clang, and
probably hasn't for multiple releases.  Fix the build.  I don't have the
right hardware to test it, though.

MFC after:	2 weeks
Sponsored by:	Axcient
This commit is contained in:
Alan Somers 2024-06-18 18:17:31 -06:00
parent bb95fbf634
commit 873881b7db
4 changed files with 29 additions and 21 deletions

View file

@ -4,7 +4,11 @@ FILESDIR=${SHAREDIR}/examples/${PROG}
PROG= scsi_target PROG= scsi_target
SRCS= scsi_target.h scsi_target.c scsi_cmds.c SRCS= scsi_target.h scsi_target.c scsi_cmds.c
DPADD= ${LIBCAM} ${LIBSBUF} DPADD= ${LIBCAM} ${LIBSBUF}
LDADD= -lcam -lsbuf LIBADD+= cam
LIBADD+= sbuf
# cast-qual is triggered only in a code path where the volatile keyword doesn't
# matter
CFLAGS.scsi_cmds.c= -Wno-cast-qual
MAN= scsi_target.8 MAN= scsi_target.8

View file

@ -102,10 +102,6 @@ static struct targ_cdb_handlers cdb_handlers[] = {
static struct scsi_inquiry_data inq_data; static struct scsi_inquiry_data inq_data;
static struct initiator_state istates[MAX_INITIATORS]; static struct initiator_state istates[MAX_INITIATORS];
extern int debug;
extern off_t volume_size;
extern u_int sector_size;
extern size_t buf_size;
cam_status cam_status
tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags) tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags)
@ -553,7 +549,7 @@ tcmd_rdwr_decode(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
tcmd_illegal_req(atio, ctio); tcmd_illegal_req(atio, ctio);
return (0); return (0);
} }
if (blkno + count > volume_size) { if (((off_t)(blkno + count)) > volume_size) {
warnx("Attempt to access past end of volume"); warnx("Attempt to access past end of volume");
tcmd_sense(ctio->init_id, ctio, tcmd_sense(ctio->init_id, ctio,
SSD_KEY_ILLEGAL_REQUEST, 0x21, 0); SSD_KEY_ILLEGAL_REQUEST, 0x21, 0);

View file

@ -77,7 +77,9 @@ static struct ccb_queue work_queue;
static struct ioc_enable_lun ioc_enlun = { static struct ioc_enable_lun ioc_enlun = {
CAM_BUS_WILDCARD, CAM_BUS_WILDCARD,
CAM_TARGET_WILDCARD, CAM_TARGET_WILDCARD,
CAM_LUN_WILDCARD CAM_LUN_WILDCARD,
0,
0
}; };
/* Local functions */ /* Local functions */
@ -208,7 +210,7 @@ main(int argc, char *argv[])
if (argc != 2) if (argc != 2)
usage(); usage();
sscanf(argv[0], "%u:%u:%u", &ioc_enlun.path_id, &ioc_enlun.target_id, sscanf(argv[0], "%u:%u:%ju", &ioc_enlun.path_id, &ioc_enlun.target_id,
&ioc_enlun.lun_id); &ioc_enlun.lun_id);
file_name = argv[1]; file_name = argv[1];
@ -258,10 +260,12 @@ main(int argc, char *argv[])
if (notaio == 0) { if (notaio == 0) {
struct aiocb aio, *aiop; struct aiocb aio, *aiop;
void *aio_buf;
/* See if we have we have working AIO support */ /* See if we have we have working AIO support */
memset(&aio, 0, sizeof(aio)); memset(&aio, 0, sizeof(aio));
aio.aio_buf = malloc(sector_size); aio_buf = malloc(sector_size);
aio.aio_buf = aio_buf;
if (aio.aio_buf == NULL) if (aio.aio_buf == NULL)
err(1, "malloc"); err(1, "malloc");
aio.aio_fildes = file_fd; aio.aio_fildes = file_fd;
@ -278,7 +282,7 @@ main(int argc, char *argv[])
assert(aiop == &aio); assert(aiop == &aio);
signal(SIGSYS, SIG_DFL); signal(SIGSYS, SIG_DFL);
} }
free((void *)aio.aio_buf); free(aio_buf);
if (debug && notaio == 0) if (debug && notaio == 0)
warnx("aio support tested ok"); warnx("aio support tested ok");
} }
@ -331,7 +335,7 @@ main(int argc, char *argv[])
} }
static void static void
cleanup() cleanup(void)
{ {
struct ccb_hdr *ccb_h; struct ccb_hdr *ccb_h;
@ -358,7 +362,7 @@ cleanup()
/* Allocate ATIOs/INOTs and queue on HBA */ /* Allocate ATIOs/INOTs and queue on HBA */
static int static int
init_ccbs() init_ccbs(void)
{ {
int i; int i;
@ -395,7 +399,7 @@ init_ccbs()
} }
static void static void
request_loop() request_loop(void)
{ {
struct kevent events[MAX_EVENTS]; struct kevent events[MAX_EVENTS];
struct timespec ts, *tptr; struct timespec ts, *tptr;
@ -535,10 +539,10 @@ request_loop()
/* CCBs are ready from the kernel */ /* CCBs are ready from the kernel */
static void static void
handle_read() handle_read(void)
{ {
union ccb *ccb_array[MAX_INITIATORS], *ccb; union ccb *ccb_array[MAX_INITIATORS], *ccb;
int ccb_count, i, oo; int ccb_count, i;
ccb_count = read(targ_fd, ccb_array, sizeof(ccb_array)); ccb_count = read(targ_fd, ccb_array, sizeof(ccb_array));
if (ccb_count <= 0) { if (ccb_count <= 0) {
@ -590,7 +594,7 @@ handle_read()
/* Queue on the appropriate ATIO */ /* Queue on the appropriate ATIO */
queue_io(ctio); queue_io(ctio);
/* Process any queued completions. */ /* Process any queued completions. */
oo += run_queue(c_descr->atio); run_queue(c_descr->atio);
break; break;
} }
case XPT_IMMEDIATE_NOTIFY: case XPT_IMMEDIATE_NOTIFY:
@ -840,7 +844,7 @@ send_ccb(union ccb *ccb, int priority)
/* Return a CTIO/descr/buf combo from the freelist or malloc one */ /* Return a CTIO/descr/buf combo from the freelist or malloc one */
static struct ccb_scsiio * static struct ccb_scsiio *
get_ctio() get_ctio(void)
{ {
struct ccb_scsiio *ctio; struct ccb_scsiio *ctio;
struct ctio_descr *c_descr; struct ctio_descr *c_descr;
@ -938,7 +942,7 @@ get_sim_flags(u_int16_t *flags)
} }
static void static void
rel_simq() rel_simq(void)
{ {
struct ccb_relsim crs; struct ccb_relsim crs;
@ -953,7 +957,7 @@ rel_simq()
/* Cancel all pending CCBs. */ /* Cancel all pending CCBs. */
static void static void
abort_all_pending() abort_all_pending(void)
{ {
struct ccb_abort cab; struct ccb_abort cab;
struct ccb_hdr *ccb_h; struct ccb_hdr *ccb_h;
@ -976,7 +980,7 @@ abort_all_pending()
} }
static void static void
usage() usage(void)
{ {
fprintf(stderr, fprintf(stderr,
"Usage: scsi_target [-AdSTY] [-b bufsize] [-c sectorsize]\n" "Usage: scsi_target [-AdSTY] [-b bufsize] [-c sectorsize]\n"

View file

@ -115,7 +115,11 @@ extern void free_ccb(union ccb *ccb);
static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
/* Global Data */ /* Global Data */
extern int notaio; extern int notaio;
extern int debug;
extern off_t volume_size;
extern u_int sector_size;
extern size_t buf_size;
/* /*
* Compat Defines * Compat Defines