ctl_frontend_iscsi.c (275878) | ctl_frontend_iscsi.c (275881) |
---|---|
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: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 275878 2014-12-18 08:22:16Z mav $ | 29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 275881 2014-12-18 08:25:00Z 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: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 275878 2014-12-18 08:22:16Z mav $"); | 37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 275881 2014-12-18 08:25:00Z mav $"); |
38 39#include <sys/param.h> 40#include <sys/capability.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> --- 320 unchanged lines hidden (view full) --- 366 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_NOP_IN && 367 bhssr->bhssr_initiator_task_tag == 0xffffffff) 368 advance_statsn = false; 369 370 /* 371 * See the comment below - StatSN is not meaningful and must 372 * not be advanced. 373 */ | 38 39#include <sys/param.h> 40#include <sys/capability.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> --- 320 unchanged lines hidden (view full) --- 366 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_NOP_IN && 367 bhssr->bhssr_initiator_task_tag == 0xffffffff) 368 advance_statsn = false; 369 370 /* 371 * See the comment below - StatSN is not meaningful and must 372 * not be advanced. 373 */ |
374 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_SCSI_DATA_IN) | 374 if (bhssr->bhssr_opcode == ISCSI_BHS_OPCODE_SCSI_DATA_IN && 375 (bhssr->bhssr_flags & BHSDI_FLAGS_S) == 0) |
375 advance_statsn = false; 376 377 /* 378 * 10.7.3: "The fields StatSN, Status, and Residual Count 379 * only have meaningful content if the S bit is set to 1." 380 */ | 376 advance_statsn = false; 377 378 /* 379 * 10.7.3: "The fields StatSN, Status, and Residual Count 380 * only have meaningful content if the S bit is set to 1." 381 */ |
381 if (bhssr->bhssr_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_IN) | 382 if (bhssr->bhssr_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_IN || 383 (bhssr->bhssr_flags & BHSDI_FLAGS_S)) |
382 bhssr->bhssr_statsn = htonl(cs->cs_statsn); 383 bhssr->bhssr_expcmdsn = htonl(cs->cs_cmdsn); 384 bhssr->bhssr_maxcmdsn = htonl(cs->cs_cmdsn + maxcmdsn_delta); 385 386 if (advance_statsn) 387 cs->cs_statsn++; 388 389 return (0); --- 2157 unchanged lines hidden (view full) --- 2547 * queue it. Note that's not enough to check 2548 * for kern_data_resid == 0 instead; there 2549 * may be several Data-In PDUs for the final 2550 * call to cfiscsi_datamove(), and we want 2551 * to set the F flag only on the last of them. 2552 */ 2553 buffer_offset += response->ip_data_len; 2554 if (buffer_offset == io->scsiio.kern_total_len || | 384 bhssr->bhssr_statsn = htonl(cs->cs_statsn); 385 bhssr->bhssr_expcmdsn = htonl(cs->cs_cmdsn); 386 bhssr->bhssr_maxcmdsn = htonl(cs->cs_cmdsn + maxcmdsn_delta); 387 388 if (advance_statsn) 389 cs->cs_statsn++; 390 391 return (0); --- 2157 unchanged lines hidden (view full) --- 2549 * queue it. Note that's not enough to check 2550 * for kern_data_resid == 0 instead; there 2551 * may be several Data-In PDUs for the final 2552 * call to cfiscsi_datamove(), and we want 2553 * to set the F flag only on the last of them. 2554 */ 2555 buffer_offset += response->ip_data_len; 2556 if (buffer_offset == io->scsiio.kern_total_len || |
2555 buffer_offset == expected_len) 2556 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; | 2557 buffer_offset == expected_len) { 2558 buffer_offset -= response->ip_data_len; 2559 break; 2560 } |
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 cfiscsi_pdu_queue(response); 2562 response = NULL; 2563 bhsdi = NULL; 2564 } 2565 } 2566 if (response != NULL) { 2567 buffer_offset += response->ip_data_len; 2568 if (buffer_offset == io->scsiio.kern_total_len || |
2565 buffer_offset == expected_len) | 2569 buffer_offset == expected_len) { |
2566 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; | 2570 bhsdi->bhsdi_flags |= BHSDI_FLAGS_F; |
2571 if (io->io_hdr.status == CTL_SUCCESS) { 2572 bhsdi->bhsdi_flags |= BHSDI_FLAGS_S; 2573 if (PDU_TOTAL_TRANSFER_LEN(request) < 2574 ntohl(bhssc->bhssc_expected_data_transfer_length)) { 2575 bhsdi->bhsdi_flags |= BHSSR_FLAGS_RESIDUAL_UNDERFLOW; 2576 bhsdi->bhsdi_residual_count = 2577 htonl(ntohl(bhssc->bhssc_expected_data_transfer_length) - 2578 PDU_TOTAL_TRANSFER_LEN(request)); 2579 } else if (PDU_TOTAL_TRANSFER_LEN(request) > 2580 ntohl(bhssc->bhssc_expected_data_transfer_length)) { 2581 bhsdi->bhsdi_flags |= BHSSR_FLAGS_RESIDUAL_OVERFLOW; 2582 bhsdi->bhsdi_residual_count = 2583 htonl(PDU_TOTAL_TRANSFER_LEN(request) - 2584 ntohl(bhssc->bhssc_expected_data_transfer_length)); 2585 } 2586 bhsdi->bhsdi_status = io->scsiio.scsi_status; 2587 io->io_hdr.flags |= CTL_FLAG_STATUS_SENT; 2588 } 2589 } |
|
2567 KASSERT(response->ip_data_len > 0, ("sending empty Data-In")); 2568 cfiscsi_pdu_queue(response); 2569 } 2570 2571 io->scsiio.be_move_done(io); 2572} 2573 2574static void --- 189 unchanged lines hidden (view full) --- 2764 cdw->cdw_initiator_task_tag, ("dangling cdw")); 2765 CFISCSI_SESSION_UNLOCK(cs); 2766#endif 2767 2768 /* 2769 * Do not return status for aborted commands. 2770 * There are exceptions, but none supported by CTL yet. 2771 */ | 2590 KASSERT(response->ip_data_len > 0, ("sending empty Data-In")); 2591 cfiscsi_pdu_queue(response); 2592 } 2593 2594 io->scsiio.be_move_done(io); 2595} 2596 2597static void --- 189 unchanged lines hidden (view full) --- 2787 cdw->cdw_initiator_task_tag, ("dangling cdw")); 2788 CFISCSI_SESSION_UNLOCK(cs); 2789#endif 2790 2791 /* 2792 * Do not return status for aborted commands. 2793 * There are exceptions, but none supported by CTL yet. 2794 */ |
2772 if ((io->io_hdr.flags & CTL_FLAG_ABORT) && 2773 (io->io_hdr.flags & CTL_FLAG_ABORT_STATUS) == 0) { | 2795 if (((io->io_hdr.flags & CTL_FLAG_ABORT) && 2796 (io->io_hdr.flags & CTL_FLAG_ABORT_STATUS) == 0) || 2797 (io->io_hdr.flags & CTL_FLAG_STATUS_SENT)) { |
2774 ctl_free_io(io); 2775 icl_pdu_free(request); 2776 return; 2777 } 2778 2779 response = cfiscsi_pdu_new_response(request, M_WAITOK); 2780 bhssr = (struct iscsi_bhs_scsi_response *)response->ip_bhs; 2781 bhssr->bhssr_opcode = ISCSI_BHS_OPCODE_SCSI_RESPONSE; --- 152 unchanged lines hidden --- | 2798 ctl_free_io(io); 2799 icl_pdu_free(request); 2800 return; 2801 } 2802 2803 response = cfiscsi_pdu_new_response(request, M_WAITOK); 2804 bhssr = (struct iscsi_bhs_scsi_response *)response->ip_bhs; 2805 bhssr->bhssr_opcode = ISCSI_BHS_OPCODE_SCSI_RESPONSE; --- 152 unchanged lines hidden --- |