ctl_frontend_iscsi.c (274962) | ctl_frontend_iscsi.c (275058) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 274962 2014-11-24 11:37:27Z mav $ | 29 * $FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 275058 2014-11-25 17:53:35Z mav $ |
30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> | 30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 274962 2014-11-24 11:37:27Z mav $"); | 37__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 275058 2014-11-25 17:53:35Z mav $"); |
38 39#include <sys/param.h> 40#include <sys/capsicum.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 316 unchanged lines hidden (view full) --- 362 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_NOP_IN && 363 bhssr->bhssr_initiator_task_tag == 0xffffffff) 364 advance_statsn = false; 365 366 /* 367 * See the comment below - StatSN is not meaningful and must 368 * not be advanced. 369 */ | 38 39#include <sys/param.h> 40#include <sys/capsicum.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 316 unchanged lines hidden (view full) --- 362 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_NOP_IN && 363 bhssr->bhssr_initiator_task_tag == 0xffffffff) 364 advance_statsn = false; 365 366 /* 367 * See the comment below - StatSN is not meaningful and must 368 * not be advanced. 369 */ |
370 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_SCSI_DATA_IN) | 370 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_SCSI_DATA_IN && 371 (bhssr->bhssr_flags & BHSDI_FLAGS_S) == 0) |
371 advance_statsn = false; 372 373 /* 374 * 10.7.3: "The fields StatSN, Status, and Residual Count 375 * only have meaningful content if the S bit is set to 1." 376 */ | 372 advance_statsn = false; 373 374 /* 375 * 10.7.3: "The fields StatSN, Status, and Residual Count 376 * only have meaningful content if the S bit is set to 1." 377 */ |
377 if (bhssr->bhssr_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_IN) | 378 if (bhssr->bhssr_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_IN || 379 (bhssr->bhssr_flags & BHSDI_FLAGS_S)) |
378 bhssr->bhssr_statsn = htonl(cs->cs_statsn); 379 bhssr->bhssr_expcmdsn = htonl(cs->cs_cmdsn); 380 bhssr->bhssr_maxcmdsn = htonl(cs->cs_cmdsn + maxcmdsn_delta); 381 382 if (advance_statsn) 383 cs->cs_statsn++; 384 385 return (0); --- 2157 unchanged lines hidden (view full) --- 2543 * queue it. Note that's not enough to check 2544 * for kern_data_resid == 0 instead; there 2545 * may be several Data-In PDUs for the final 2546 * call to cfiscsi_datamove(), and we want 2547 * to set the F flag only on the last of them. 2548 */ 2549 buffer_offset += response->ip_data_len; 2550 if (buffer_offset == io->scsiio.kern_total_len || | 380 bhssr->bhssr_statsn = htonl(cs->cs_statsn); 381 bhssr->bhssr_expcmdsn = htonl(cs->cs_cmdsn); 382 bhssr->bhssr_maxcmdsn = htonl(cs->cs_cmdsn + maxcmdsn_delta); 383 384 if (advance_statsn) 385 cs->cs_statsn++; 386 387 return (0); --- 2157 unchanged lines hidden (view full) --- 2545 * queue it. Note that's not enough to check 2546 * for kern_data_resid == 0 instead; there 2547 * may be several Data-In PDUs for the final 2548 * call to cfiscsi_datamove(), and we want 2549 * to set the F flag only on the last of them. 2550 */ 2551 buffer_offset += response->ip_data_len; 2552 if (buffer_offset == io->scsiio.kern_total_len || |
2551 buffer_offset == expected_len) 2552 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; | 2553 buffer_offset == expected_len) { 2554 buffer_offset -= response->ip_data_len; 2555 break; 2556 } |
2553 cfiscsi_pdu_queue(response); 2554 response = NULL; 2555 bhsdi = NULL; 2556 } 2557 } 2558 if (response != NULL) { 2559 buffer_offset += response->ip_data_len; 2560 if (buffer_offset == io->scsiio.kern_total_len || | 2557 cfiscsi_pdu_queue(response); 2558 response = NULL; 2559 bhsdi = NULL; 2560 } 2561 } 2562 if (response != NULL) { 2563 buffer_offset += response->ip_data_len; 2564 if (buffer_offset == io->scsiio.kern_total_len || |
2561 buffer_offset == expected_len) | 2565 buffer_offset == expected_len) { |
2562 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; | 2566 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; |
2567 if (io->io_hdr.status == CTL_SUCCESS) { 2568 bhsdi->bhsdi_flags |= BHSDI_FLAGS_S; 2569 if (PDU_TOTAL_TRANSFER_LEN(request) < 2570 ntohl(bhssc->bhssc_expected_data_transfer_length)) { 2571 bhsdi->bhsdi_flags |= BHSSR_FLAGS_RESIDUAL_UNDERFLOW; 2572 bhsdi->bhsdi_residual_count = 2573 htonl(ntohl(bhssc->bhssc_expected_data_transfer_length) - 2574 PDU_TOTAL_TRANSFER_LEN(request)); 2575 } else if (PDU_TOTAL_TRANSFER_LEN(request) > 2576 ntohl(bhssc->bhssc_expected_data_transfer_length)) { 2577 bhsdi->bhsdi_flags |= BHSSR_FLAGS_RESIDUAL_OVERFLOW; 2578 bhsdi->bhsdi_residual_count = 2579 htonl(PDU_TOTAL_TRANSFER_LEN(request) - 2580 ntohl(bhssc->bhssc_expected_data_transfer_length)); 2581 } 2582 bhsdi->bhsdi_status = io->scsiio.scsi_status; 2583 io->io_hdr.flags |= CTL_FLAG_STATUS_SENT; 2584 } 2585 } |
|
2563 KASSERT(response->ip_data_len > 0, ("sending empty Data-In")); 2564 cfiscsi_pdu_queue(response); 2565 } 2566 2567 io->scsiio.be_move_done(io); 2568} 2569 2570static void --- 189 unchanged lines hidden (view full) --- 2760 cdw->cdw_initiator_task_tag, ("dangling cdw")); 2761 CFISCSI_SESSION_UNLOCK(cs); 2762#endif 2763 2764 /* 2765 * Do not return status for aborted commands. 2766 * There are exceptions, but none supported by CTL yet. 2767 */ | 2586 KASSERT(response->ip_data_len > 0, ("sending empty Data-In")); 2587 cfiscsi_pdu_queue(response); 2588 } 2589 2590 io->scsiio.be_move_done(io); 2591} 2592 2593static void --- 189 unchanged lines hidden (view full) --- 2783 cdw->cdw_initiator_task_tag, ("dangling cdw")); 2784 CFISCSI_SESSION_UNLOCK(cs); 2785#endif 2786 2787 /* 2788 * Do not return status for aborted commands. 2789 * There are exceptions, but none supported by CTL yet. 2790 */ |
2768 if ((io->io_hdr.flags & CTL_FLAG_ABORT) && 2769 (io->io_hdr.flags & CTL_FLAG_ABORT_STATUS) == 0) { | 2791 if (((io->io_hdr.flags & CTL_FLAG_ABORT) && 2792 (io->io_hdr.flags & CTL_FLAG_ABORT_STATUS) == 0) || 2793 (io->io_hdr.flags & CTL_FLAG_STATUS_SENT)) { |
2770 ctl_free_io(io); 2771 icl_pdu_free(request); 2772 return; 2773 } 2774 2775 response = cfiscsi_pdu_new_response(request, M_WAITOK); 2776 bhssr = (struct iscsi_bhs_scsi_response *)response->ip_bhs; 2777 bhssr->bhssr_opcode = ISCSI_BHS_OPCODE_SCSI_RESPONSE; --- 152 unchanged lines hidden --- | 2794 ctl_free_io(io); 2795 icl_pdu_free(request); 2796 return; 2797 } 2798 2799 response = cfiscsi_pdu_new_response(request, M_WAITOK); 2800 bhssr = (struct iscsi_bhs_scsi_response *)response->ip_bhs; 2801 bhssr->bhssr_opcode = ISCSI_BHS_OPCODE_SCSI_RESPONSE; --- 152 unchanged lines hidden --- |