scsi_target.c (109345) | scsi_target.c (120428) |
---|---|
1/* 2 * SCSI Disk Emulator 3 * 4 * Copyright (c) 2002 Nate Lawson. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * | 1/* 2 * SCSI Disk Emulator 3 * 4 * Copyright (c) 2002 Nate Lawson. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/share/examples/scsi_target/scsi_target.c 109345 2003-01-16 00:24:29Z njl $ | 28 * $FreeBSD: head/share/examples/scsi_target/scsi_target.c 120428 2003-09-25 05:43:26Z simokawa $ |
29 */ 30 31#include <sys/types.h> 32#include <errno.h> 33#include <err.h> 34#include <fcntl.h> 35#include <signal.h> 36#include <stddef.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sysexits.h> 41#include <unistd.h> 42#include <aio.h> 43#include <assert.h> 44#include <sys/stat.h> 45#include <sys/queue.h> 46#include <sys/event.h> 47#include <sys/param.h> | 29 */ 30 31#include <sys/types.h> 32#include <errno.h> 33#include <err.h> 34#include <fcntl.h> 35#include <signal.h> 36#include <stddef.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sysexits.h> 41#include <unistd.h> 42#include <aio.h> 43#include <assert.h> 44#include <sys/stat.h> 45#include <sys/queue.h> 46#include <sys/event.h> 47#include <sys/param.h> |
48#include <sys/disk.h> |
|
48#include <cam/cam_queue.h> 49#include <cam/scsi/scsi_all.h> 50#include <cam/scsi/scsi_targetio.h> 51#include <cam/scsi/scsi_message.h> 52#include "scsi_target.h" 53 54/* Maximum amount to transfer per CTIO */ 55#define MAX_XFER MAXPHYS --- 138 unchanged lines hidden (view full) --- 194 err(1, "open backing store file"); 195 196 /* Check backing store size or use the size user gave us */ 197 if (user_size == 0) { 198 struct stat st; 199 200 if (fstat(file_fd, &st) < 0) 201 err(1, "fstat file"); | 49#include <cam/cam_queue.h> 50#include <cam/scsi/scsi_all.h> 51#include <cam/scsi/scsi_targetio.h> 52#include <cam/scsi/scsi_message.h> 53#include "scsi_target.h" 54 55/* Maximum amount to transfer per CTIO */ 56#define MAX_XFER MAXPHYS --- 138 unchanged lines hidden (view full) --- 195 err(1, "open backing store file"); 196 197 /* Check backing store size or use the size user gave us */ 198 if (user_size == 0) { 199 struct stat st; 200 201 if (fstat(file_fd, &st) < 0) 202 err(1, "fstat file"); |
202 volume_size = st.st_size / sector_size; | 203#if __FreeBSD_version >= 500000 204 if ((st.st_mode & S_IFCHR) != 0) { 205 /* raw device */ 206 off_t mediasize; 207 if (ioctl(file_fd, DIOCGMEDIASIZE, &mediasize) < 0) 208 err(1, "DIOCGMEDIASIZE"); 209 210 /* XXX get sector size by ioctl()?? */ 211 volume_size = mediasize / sector_size; 212 } else 213#endif 214 volume_size = st.st_size / sector_size; |
203 } else { 204 volume_size = user_size / sector_size; 205 } 206 if (volume_size <= 0) 207 errx(1, "volume must be larger than %d", sector_size); 208 209 { 210 struct aiocb aio, *aiop; --- 366 unchanged lines hidden (view full) --- 577 ctio->init_id = atio->init_id; 578 /* XXX priority needs to be added to a_descr */ 579 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; 580 c_descr->atio = atio; 581 if ((a_descr->flags & CAM_DIR_IN) != 0) 582 c_descr->offset = a_descr->base_off + a_descr->targ_req; 583 else if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) 584 c_descr->offset = a_descr->base_off + a_descr->init_req; | 215 } else { 216 volume_size = user_size / sector_size; 217 } 218 if (volume_size <= 0) 219 errx(1, "volume must be larger than %d", sector_size); 220 221 { 222 struct aiocb aio, *aiop; --- 366 unchanged lines hidden (view full) --- 589 ctio->init_id = atio->init_id; 590 /* XXX priority needs to be added to a_descr */ 591 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; 592 c_descr->atio = atio; 593 if ((a_descr->flags & CAM_DIR_IN) != 0) 594 c_descr->offset = a_descr->base_off + a_descr->targ_req; 595 else if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) 596 c_descr->offset = a_descr->base_off + a_descr->init_req; |
597 else 598 c_descr->offset = a_descr->base_off; |
|
585 586 /* 587 * Return a check condition if there was an error while 588 * receiving this ATIO. 589 */ 590 if (atio->sense_len != 0) { 591 struct scsi_sense_data *sense; 592 --- 86 unchanged lines hidden (view full) --- 679 680 while ((ccb_h = TAILQ_FIRST(&a_descr->cmplt_io)) != NULL) { 681 struct ccb_scsiio *ctio; 682 struct ctio_descr *c_descr; 683 684 ctio = (struct ccb_scsiio *)ccb_h; 685 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; 686 | 599 600 /* 601 * Return a check condition if there was an error while 602 * receiving this ATIO. 603 */ 604 if (atio->sense_len != 0) { 605 struct scsi_sense_data *sense; 606 --- 86 unchanged lines hidden (view full) --- 693 694 while ((ccb_h = TAILQ_FIRST(&a_descr->cmplt_io)) != NULL) { 695 struct ccb_scsiio *ctio; 696 struct ctio_descr *c_descr; 697 698 ctio = (struct ccb_scsiio *)ccb_h; 699 c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr; 700 |
701 if (ctio->ccb_h.status == CAM_REQ_ABORTED) { 702 TAILQ_REMOVE(&a_descr->cmplt_io, ccb_h, 703 periph_links.tqe); 704 free_ccb((union ccb *)ctio); 705 send_ccb((union ccb *)atio, /*priority*/1); 706 continue; 707 } 708 |
|
687 /* If completed item is in range, call handler */ 688 if ((c_descr->event == AIO_DONE && 689 c_descr->offset == a_descr->base_off + a_descr->targ_ack) 690 || (c_descr->event == CTIO_DONE && 691 c_descr->offset == a_descr->base_off + a_descr->init_ack)) { 692 sent_status = (ccb_h->flags & CAM_SEND_STATUS) != 0; 693 event = c_descr->event; 694 --- 240 unchanged lines hidden --- | 709 /* If completed item is in range, call handler */ 710 if ((c_descr->event == AIO_DONE && 711 c_descr->offset == a_descr->base_off + a_descr->targ_ack) 712 || (c_descr->event == CTIO_DONE && 713 c_descr->offset == a_descr->base_off + a_descr->init_ack)) { 714 sent_status = (ccb_h->flags & CAM_SEND_STATUS) != 0; 715 event = c_descr->event; 716 --- 240 unchanged lines hidden --- |