diff options
| author | joerg <joerg@NetBSD.org> | 2015-05-30 16:12:33 +0000 |
|---|---|---|
| committer | joerg <joerg@NetBSD.org> | 2015-05-30 16:12:33 +0000 |
| commit | a0a3713d07ce4fcb0a160a25301042fa5910c449 (patch) | |
| tree | 9bd6224407eb5173c248abb98578c5735a53e4be /sys/dev | |
| parent | d4d3ab147733ec995c044cd835d464738ac45301 (diff) | |
Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/iscsi/Makefile | 2 | ||||
| -rw-r--r-- | sys/dev/iscsi/files.iscsi | 4 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_globals.h | 31 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_ioctl.c | 32 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_rcv.c | 19 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_send.c | 28 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_test.c | 1093 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_test.h | 264 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_testlocal.h | 105 | ||||
| -rw-r--r-- | sys/dev/iscsi/iscsi_text.c | 60 |
10 files changed, 15 insertions, 1623 deletions
diff --git a/sys/dev/iscsi/Makefile b/sys/dev/iscsi/Makefile index 85b2a2032ce..c149e04cdc9 100644 --- a/sys/dev/iscsi/Makefile +++ b/sys/dev/iscsi/Makefile @@ -2,6 +2,6 @@ INCSDIR= /usr/include/dev/iscsi -INCS= iscsi.h iscsi_ioctl.h iscsi_test.h iscsi_perf.h +INCS= iscsi.h iscsi_ioctl.h iscsi_perf.h .include <bsd.kinc.mk> diff --git a/sys/dev/iscsi/files.iscsi b/sys/dev/iscsi/files.iscsi index 9fcda2e5a96..d5939c8568b 100644 --- a/sys/dev/iscsi/files.iscsi +++ b/sys/dev/iscsi/files.iscsi @@ -1,4 +1,4 @@ -# $NetBSD: files.iscsi,v 1.3 2015/04/12 14:48:32 joerg Exp $ +# $NetBSD: files.iscsi,v 1.4 2015/05/30 16:12:34 joerg Exp $ # # Configuration file for iSCSI initiator @@ -6,7 +6,6 @@ defpseudodev iscsi : scsi defparam ISCSI_DEBUG defflag ISCSI_PERFTEST -defflag ISCSI_TEST_MODE file dev/iscsi/base64.c iscsi file dev/iscsi/iscsi_ioctl.c iscsi @@ -14,6 +13,5 @@ file dev/iscsi/iscsi_main.c iscsi file dev/iscsi/iscsi_profile.c iscsi file dev/iscsi/iscsi_rcv.c iscsi file dev/iscsi/iscsi_send.c iscsi -file dev/iscsi/iscsi_test.c iscsi file dev/iscsi/iscsi_text.c iscsi file dev/iscsi/iscsi_utils.c iscsi diff --git a/sys/dev/iscsi/iscsi_globals.h b/sys/dev/iscsi/iscsi_globals.h index 9f9e3afd6a2..abbe8e7098f 100644 --- a/sys/dev/iscsi/iscsi_globals.h +++ b/sys/dev/iscsi/iscsi_globals.h @@ -1,4 +1,4 @@ -/* $NetBSD: iscsi_globals.h,v 1.8 2015/05/15 16:24:30 joerg Exp $ */ +/* $NetBSD: iscsi_globals.h,v 1.9 2015/05/30 16:12:34 joerg Exp $ */ /*- * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc. @@ -61,7 +61,6 @@ /* #define ISCSI_DEBUG 1 */ #include "iscsi_perf.h" -#include "iscsi_test.h" /* ------------------------- Global Constants ----------------------------- */ @@ -195,10 +194,6 @@ typedef struct session_s session_t; typedef struct ccb_s ccb_t; typedef struct pdu_s pdu_t; - -#include "iscsi_testlocal.h" - - /* the serial number management structure (a circular buffer) */ typedef struct { @@ -240,11 +235,6 @@ struct pdu_s { connection_t *connection; /* the connection this PDU belongs to */ -#ifdef ISCSI_TEST_MODE - pdu_header_t mod_pdu; - /* Buffer for modified PDU header (test mode) */ -#endif - #ifdef ISCSI_PERFTEST int perf_index; /* performance counter index */ @@ -398,11 +388,6 @@ struct connection_s { /* only valid during login */ pdu_t pdu[PDUS_PER_CONNECTION]; /* PDUs */ - -#ifdef ISCSI_TEST_MODE - test_pars_t *test_pars; - /* connection in test mode if non-NULL */ -#endif }; /* the connection list type */ @@ -674,21 +659,9 @@ sn_a_le_b(uint32_t a, uint32_t b) /* Version dependencies */ -#ifdef ISCSI_TEST_MODE -#define SET_CCB_TIMEOUT(conn, ccb, tout) do { \ - if (test_ccb_timeout (conn)) { \ - callout_schedule(&ccb->timeout, tout); \ - } \ -} while (/*CONSTCOND*/ 0) -#define SET_CONN_TIMEOUT(conn, tout) do { \ - if (test_conn_timeout (conn)) { \ - callout_schedule(&conn->timeout, tout); \ - } \ -} while (/*CONSTCOND*/ 0) -#else +/* XXX */ #define SET_CCB_TIMEOUT(conn, ccb, tout) callout_schedule(&ccb->timeout, tout) #define SET_CONN_TIMEOUT(conn, tout) callout_schedule(&conn->timeout, tout) -#endif /* in iscsi_ioctl.c */ diff --git a/sys/dev/iscsi/iscsi_ioctl.c b/sys/dev/iscsi/iscsi_ioctl.c index 6c33039746a..a357a98d332 100644 --- a/sys/dev/iscsi/iscsi_ioctl.c +++ b/sys/dev/iscsi/iscsi_ioctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: iscsi_ioctl.c,v 1.8 2015/05/15 16:24:30 joerg Exp $ */ +/* $NetBSD: iscsi_ioctl.c,v 1.9 2015/05/30 16:12:34 joerg Exp $ */ /*- * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc. @@ -499,10 +499,6 @@ kill_connection(connection_t *conn, uint32_t status, int logout, bool recover) } } -#ifdef ISCSI_TEST_MODE - test_remove_connection(conn); -#endif - conn->terminating = status; conn->state = ST_SETTLING; @@ -720,10 +716,6 @@ create_connection(iscsi_login_parameters_t *par, session_t *session, * increments performed in get_socket(). */ -#ifdef ISCSI_TEST_MODE - test_assign_connection(connection); -#endif - if ((rc = send_login(connection)) != 0) { DEBC(connection, 0, ("Login failed (rc %d)\n", rc)); /* Don't attempt to recover, there seems to be something amiss */ @@ -1679,28 +1671,6 @@ iscsiioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l) break; #endif -#ifdef ISCSI_TEST_MODE - case ISCSI_TEST_DEFINE: - test_define((iscsi_test_define_parameters_t *) addr); - break; - - case ISCSI_TEST_ADD_NEGOTIATION: - test_add_neg((iscsi_test_add_negotiation_parameters_t *) addr); - break; - - case ISCSI_TEST_ADD_MODIFICATION: - test_add_mod(l->l_proc, (iscsi_test_add_modification_parameters_t *) addr); - break; - - case ISCSI_TEST_SEND_PDU: - test_send_pdu(l->l_proc, (iscsi_test_send_pdu_parameters_t *) addr); - break; - - case ISCSI_TEST_CANCEL: - test_cancel((iscsi_test_cancel_parameters_t *) addr); - break; -#endif - default: DEBOUT(("Invalid IO-Control Code\n")); return ENOTTY; diff --git a/sys/dev/iscsi/iscsi_rcv.c b/sys/dev/iscsi/iscsi_rcv.c index e905ad46fe8..5e86fa16291 100644 --- a/sys/dev/iscsi/iscsi_rcv.c +++ b/sys/dev/iscsi/iscsi_rcv.c @@ -1,4 +1,4 @@ -/* $NetBSD: iscsi_rcv.c,v 1.7 2015/05/15 16:24:30 joerg Exp $ */ +/* $NetBSD: iscsi_rcv.c,v 1.8 2015/05/30 16:12:34 joerg Exp $ */ /*- * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc. @@ -210,11 +210,6 @@ read_pdu_data(pdu_t *pdu, uint8_t *data, uint32_t offset) pdu->io_vec[i].iov_len = 4; uio->uio_resid += 4; } -#ifdef ISCSI_TEST_MODE - /* save data pointer and size */ - pdu->save_uio.uio_iov = (struct iovec *) data; - pdu->save_uio.uio_resid = len; -#endif /* get the data */ if (my_soo_read(conn, &pdu->uio, MSG_WAITALL) != 0) { @@ -546,9 +541,6 @@ receive_logout_pdu(connection_t *conn, pdu_t *pdu, ccb_t *req_ccb) callout_stop(&conn->timeout); -#ifdef ISCSI_TEST_MODE - test_remove_connection(conn); -#endif /* let send thread take over next step of cleanup */ wakeup(&conn->pdus_to_send); } @@ -1009,9 +1001,6 @@ receive_pdu(connection_t *conn, pdu_t *pdu) if (digest != pdu->pdu.HeaderDigest) { DEBOUT(("Header Digest Error: comp = %08x, rx = %08x\n", digest, pdu->pdu.HeaderDigest)); -#ifdef ISCSI_TEST_MODE - test_mode_rx(conn, pdu, TEST_INVALID_HEADER_CRC); -#endif /* try to skip to next PDU */ try_resynch_receive(conn); free_pdu(pdu); @@ -1044,12 +1033,6 @@ receive_pdu(connection_t *conn, pdu_t *pdu) } else { rc = read_pdu_data(pdu, NULL, 0); } -#ifdef ISCSI_TEST_MODE - if (test_mode_rx(conn, pdu, rc)) { - free_pdu(pdu); - return rc; - } -#endif if (!rc && (conn->state <= ST_WINDING_DOWN || (pdu->pdu.Opcode & OPCODE_MASK) == TOP_Logout_Response)) { diff --git a/sys/dev/iscsi/iscsi_send.c b/sys/dev/iscsi/iscsi_send.c index 78009d9e606..22427d670aa 100644 --- a/sys/dev/iscsi/iscsi_send.c +++ b/sys/dev/iscsi/iscsi_send.c @@ -1,4 +1,4 @@ -/* $NetBSD: iscsi_send.c,v 1.11 2015/05/15 16:24:30 joerg Exp $ */ +/* $NetBSD: iscsi_send.c,v 1.12 2015/05/30 16:12:34 joerg Exp $ */ /*- * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc. @@ -311,25 +311,13 @@ iscsi_send_thread(void *par) #endif /*DEB (99,("Send thread woke up, pdu = %x)\n", (int)pdu)); */ -#ifdef ISCSI_TEST_MODE - if (!test_mode_tx(conn, pdu)) { - if (!(pdu->flags & PDUF_NOUPDATE)) { -#endif - /* update ExpStatSN here to avoid discontinuities */ - /* and delays in updating target */ - pdu->pdu.p.command.ExpStatSN = - htonl(conn->StatSN_buf.ExpSN); - - if (conn->HeaderDigest) - pdu->pdu.HeaderDigest = - gen_digest(&pdu->pdu, BHS_SIZE); -#ifdef ISCSI_TEST_MODE - } -#endif - my_soo_write(conn, &pdu->uio); -#ifdef ISCSI_TEST_MODE - } -#endif + /* update ExpStatSN here to avoid discontinuities */ + /* and delays in updating target */ + pdu->pdu.p.command.ExpStatSN = htonl(conn->StatSN_buf.ExpSN); + + if (conn->HeaderDigest) + pdu->pdu.HeaderDigest = gen_digest(&pdu->pdu, BHS_SIZE); + my_soo_write(conn, &pdu->uio); PERF_PDUSNAPE(pdu); if (pdu->disp <= PDUDISP_FREE) { diff --git a/sys/dev/iscsi/iscsi_test.c b/sys/dev/iscsi/iscsi_test.c deleted file mode 100644 index 91c3eac7dd6..00000000000 --- a/sys/dev/iscsi/iscsi_test.c +++ /dev/null @@ -1,1093 +0,0 @@ -/* $NetBSD: iscsi_test.c,v 1.4 2015/04/13 16:33:24 riastradh Exp $ */ - -/*- - * Copyright (c) 2006,2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/cprng.h> - -#include "iscsi_globals.h" - -#ifdef ISCSI_TEST_MODE - -STATIC test_pars_list_t test_list = TAILQ_HEAD_INITIALIZER(test_list); - -/* ------------------- Local Stuff for PDU modifications -------------------- */ - -/* - * find_pdu_offset: - * Return pointer to PDU location to be modified, based on io vector. - * Also return maximum size of field. - * - * Parameter: - * pdu the PDU to modify - * offset the offset into the PDU - * ptr OUT: The pointer to the data - * maxlen OUT: Maximum length of field - * - * Returns 0 on success, nonzero if offset exceeds PDU size. - */ - -STATIC int -find_pdu_offset(pdu_t *pdu, int offset, uint8_t **ptr, int *maxlen) -{ - uint8_t *pt = NULL; - int i, maxl = 0; - - for (i = 0; i < pdu->uio.uio_iovcnt; i++) { - pt = pdu->io_vec[i].iov_base; - maxl = pdu->io_vec[i].iov_len; - - if (offset >= maxl) { - offset -= maxl; - } else { - maxl -= offset; - pt += offset; - offset = -1; - break; - } - } - DEB(1, ("Find pdu offset: offs=%d, ptr=%x, maxl=%d\n", - offset, (int) pt, maxl)); - - if (offset >= 0 || !maxl) - return 1; - - *ptr = pt; - *maxlen = maxl; - return 0; -} - - -/* - * mod_pdu: - * Modify given PDU according to modification descriptor. - * - * Parameter: - * pdu the PDU to modify - * mp the modification descriptor - */ - -STATIC void -mod_pdu(pdu_t *pdu, iscsi_pdu_mod_t *mp) -{ - int add = mp->flags & ISCSITEST_MOD_FLAG_ADD_VAL; - int64_t val = *((int64_t *) mp->value); - uint8_t *ptr; - int len; - - switch (mp->offset) { - case ISCSITEST_OFFSET_DATADIGEST: - ptr = (uint8_t *) &pdu->data_digest; - len = sizeof(pdu->data_digest); - break; - - case ISCSITEST_OFFSET_HEADERDIGEST: - ptr = (uint8_t *) &pdu->pdu.HeaderDigest; - len = sizeof(pdu->pdu.HeaderDigest); - break; - - case ISCSITEST_OFFSET_DATA: - if ((len = pdu->io_vec[1].iov_len) == 0) - return; - ptr = pdu->io_vec[1].iov_base; - break; - - case ISCSITEST_OFFSET_DRV_CMDSN: - ptr = (uint8_t *) &pdu->connection->session->CmdSN; - len = sizeof(pdu->connection->session->CmdSN); - break; - - default: - if (find_pdu_offset(pdu, mp->offset, &ptr, &len)) - return; - break; - } - - len = min(len, mp->size); - - DEB(1, ("mod_pdu: mpoff=%d, size=%d, len=%d, val=%qx, *ptr=%qx\n", - mp->offset, mp->size, len, val, *((uint64_t *) ptr))); - - if (!add) { - if (mp->flags & ISCSITEST_MOD_FLAG_REORDER) - val = htonq(val); - memcpy(ptr, &val, len); - } else if (len == mp->size) { - switch (len) { - case 1: - *ptr += *mp->value; - break; - case 2: - val += (int64_t) (ntohs(*((uint16_t *) ptr))); - *((uint16_t *) ptr) = htons((uint16_t) val); - break; - case 3: - val += (int64_t) (ntoh3(ptr)); - hton3((uint32_t) val, ptr); - break; - case 4: - val += (int64_t) (ntohl(*((uint32_t *) ptr))); - *((uint32_t *) ptr) = htonl((uint32_t) val); - break; - case 8: - val += ntohq(*((uint64_t *) ptr)); - *((uint64_t *) ptr) = htonq(val); - break; - - default: - break; - } - } - DEB(1, ("mod_pdu: *ptr=%qx\n", *((uint64_t *) ptr))); -} - - -/* - * update_options: - * Update test options from current mod record. - * - * Parameter: - * tp the test parameters - * mod the mod descriptor - */ - -STATIC void -update_options(test_pars_t *tp, mod_desc_t *mod) -{ - if ((tp->options & ISCSITEST_OPT_DISABLE_CCB_TIMEOUT) && - (mod->pars.options & ISCSITEST_OPT_ENABLE_CCB_TIMEOUT)) - tp->options &= ~ISCSITEST_OPT_DISABLE_CCB_TIMEOUT; - else if (!(tp->options & ISCSITEST_OPT_DISABLE_CCB_TIMEOUT) && - (mod->pars.options & ISCSITEST_OPT_DISABLE_CCB_TIMEOUT)) - tp->options |= ISCSITEST_OPT_DISABLE_CCB_TIMEOUT; - - if ((tp->options & ISCSITEST_OPT_DISABLE_CONN_TIMEOUT) && - (mod->pars.options & ISCSITEST_OPT_ENABLE_CONN_TIMEOUT)) - tp->options &= ~ISCSITEST_OPT_DISABLE_CONN_TIMEOUT; - else if (!(tp->options & ISCSITEST_OPT_DISABLE_CONN_TIMEOUT) && - (mod->pars.options & ISCSITEST_OPT_DISABLE_CONN_TIMEOUT)) - tp->options |= ISCSITEST_OPT_DISABLE_CONN_TIMEOUT; - - if (mod->pars.options & ISCSITEST_OPT_USE_RANDOM_TX) - tp->lose_random[CNT_TX] = mod->pars.lose_random_tx; - if (mod->pars.options & ISCSITEST_OPT_USE_RANDOM_RX) - tp->lose_random[CNT_RX] = mod->pars.lose_random_rx; -} - - -/* - * test_get: - * Copy PDU to app - * - * Parameter: - * pdu the PDU to modify - * mod the modification descriptor - * error the PDU error indication - */ - -STATIC void -test_get(pdu_t *pdu, mod_desc_t *mod, int error) -{ - uint32_t size, cpy, dlen; - uint8_t *pptr; - - pptr = mod->pdu_ptr; - size = mod->pars.pdu_size; - - cpy = min(size, BHS_SIZE); - memcpy(pptr, &pdu->pdu, cpy); - size -= cpy; - pptr += cpy; - dlen = pdu->save_uio.uio_resid; - - if (size && dlen) { - cpy = min(size, dlen); - memcpy(pptr, (char *) pdu->save_uio.uio_iov, cpy); - size -= cpy; - } - mod->pars.pdu_actual_size = BHS_SIZE + dlen; - - switch (error) { - case 0: - mod->pars.status = ISCSI_STATUS_SUCCESS; - break; - - case TEST_INVALID_HEADER_CRC: - mod->pars.status = ISCSI_STATUS_TEST_HEADER_CRC_ERROR; - break; - - case TEST_INVALID_DATA_CRC: - mod->pars.status = ISCSI_STATUS_TEST_DATA_CRC_ERROR; - break; - - case TEST_READ_ERROR: - mod->pars.status = ISCSI_STATUS_TEST_DATA_READ_ERROR; - break; - - default: - mod->pars.status = ISCSI_STATUS_GENERAL_ERROR; - break; - } -} - - -/* - * check_loss: - * Check whether PDU is to be discarded randomly. - * - * Parameter: - * tp the test parameters - * rxtx whether this is a recieve or send PDU (CNT_TX or CNT_RX) - * - * Returns nonzero if the PDU is to be discarded, 0 for normal processing. - */ - -STATIC int -check_loss(test_pars_t *tp, int rxtx) -{ - return (tp->lose_random[rxtx]) ? - (cprng_fast32() % tp->lose_random[rxtx]) : 0; -} - - -/* - * test_mod: - * Check whether PDU is to be modified - calculate offset, modify PDU - * on match. - * - * Parameter: - * tp the test parameters - * pdu the PDU to modify - * kind the PDU kind - * rxtx whether this is a recieve or send PDU (CNT_TX or CNT_RX) - * err the PDU error indicator (set on digest/read errors, rx only) - * - * Returns nonzero if the PDU is to be discarded, 0 for normal processing. - */ - -STATIC int -test_mod(test_pars_t *tp, pdu_t *pdu, iscsi_pdu_kind_t kind, int rxtx, int err) -{ - mod_desc_t *mod; - uint32_t mpoff, off; - int i, rc = 0, s; - - tp->pdu_count[kind][rxtx]++; - tp->pdu_count[ANY_PDU][rxtx]++; - - do { - if ((mod = TAILQ_FIRST(&tp->mods)) == NULL) { - return check_loss(tp, rxtx); - } - if (mod->pars.which_pdu != ANY_PDU && - mod->pars.which_pdu != kind) { - return check_loss(tp, rxtx); - } - mpoff = mod->pars.pdu_offset; - - switch (mod->pars.which_offset) { - case ABSOLUTE_ANY: - off = tp->pdu_count[ANY_PDU][CNT_TX] + - tp->pdu_count[ANY_PDU][CNT_RX]; - break; - case RELATIVE_ANY: - off = (tp->pdu_count[ANY_PDU][CNT_TX] + - tp->pdu_count[ANY_PDU][CNT_RX]) - - (tp->pdu_last[ANY_PDU][CNT_TX] + tp->pdu_last[ANY_PDU][CNT_RX]); - break; - - case ABSOLUTE_PDUKIND: - off = tp->pdu_count[kind][rxtx]; - break; - case RELATIVE_PDUKIND: - off = tp->pdu_count[kind][rxtx] - tp->pdu_last[kind][rxtx]; - break; - - case ABSOLUTE_TX: - if (rxtx != CNT_TX) - return check_loss(tp, rxtx); - off = tp->pdu_count[ANY_PDU][CNT_TX]; - break; - case RELATIVE_TX: - if (rxtx != CNT_TX) - return check_loss(tp, rxtx); - off = tp->pdu_count[ANY_PDU][CNT_TX] - - tp->pdu_last[ANY_PDU][CNT_TX]; - break; - - case ABSOLUTE_RX: - if (rxtx != CNT_RX) - return check_loss(tp, rxtx); - off = tp->pdu_count[ANY_PDU][CNT_RX]; - break; - case RELATIVE_RX: - if (rxtx != CNT_RX) - return check_loss(tp, rxtx); - off = tp->pdu_count[ANY_PDU][CNT_RX] - - tp->pdu_last[ANY_PDU][CNT_RX]; - break; - - default: - /* bad offset - skip this entry */ - mpoff = off = 0; - break; - } - - DEB(1, ("test_mod: kind=%d, rxtx=%d, pdukind=%d, mpoff=%d, " - "whichoff=%d, off=%d\n", kind, rxtx, mod->pars.which_pdu, - mpoff, mod->pars.which_offset, off)); - - if (!off || (mpoff != 0 && mpoff < off)) { - /* This might happen in some cases. Just discard the modification. */ - s = splbio(); - TAILQ_REMOVE(&tp->mods, mod, link); - splx(s); - - update_options(tp, mod); - - if (mod->pars.options & ISCSITEST_OPT_WAIT_FOR_COMPLETION) { - mod->pars.status = ISCSI_STATUS_TEST_MODIFICATION_SKIPPED; - wakeup(mod); - } - free(mod, M_TEMP); - } - } while (mpoff && mpoff < off); - - if (mpoff > off) - return check_loss(tp, rxtx); - - DEB(1, ("test_mod: opt=%x, pdu_ptr=%x, num_mods=%d\n", mod->pars.options, - (int) mod->pdu_ptr, mod->pars.num_pdu_mods)); - - if (mod->pdu_ptr) - test_get(pdu, mod, err); - - if (mod->pars.options & ISCSITEST_OPT_DISCARD_PDU) - rc = 1; - else if (check_loss(tp, rxtx)) - rc = 1; - else if (mod->pars.num_pdu_mods) { - if (!(mod->pars.options & ISCSITEST_OPT_MOD_PERMANENT)) { - /* - * Note: if the PDU is later resent, the unmodified one will be - * used as resend_pdu restores the original io vector. - */ - pdu->mod_pdu = pdu->pdu; - pdu->io_vec[0].iov_base = &pdu->mod_pdu; - } - for (i = 0; i < mod->pars.num_pdu_mods; i++) { - mod_pdu(pdu, &mod->mods[i]); - } - } - - if (rxtx == CNT_TX) { - if (mod->pars.options & ISCSITEST_OPT_NO_RESPONSE_PDU) { - ccb_t *ccb = pdu->owner; - - DEB(1, ("test_mod: No response expected, completing CCB %x\n", - (int)ccb)); - - if (ccb != NULL && - (ccb->disp == CCBDISP_WAIT || ccb->disp == CCBDISP_SCSIPI)) { - /* simulate timeout */ - wake_ccb(ccb, ISCSI_STATUS_TIMEOUT); - } - } - - if ((mod->pars.options & ISCSITEST_SFLAG_UPDATE_FIELDS) && - mod->pars.num_pdu_mods) { - connection_t *conn = pdu->connection; - - if (conn->HeaderDigest && - !(mod->pars.options & ISCSITEST_SFLAG_NO_HEADER_DIGEST)) - pdu->pdu.HeaderDigest = gen_digest(&pdu->pdu, BHS_SIZE); - - if (pdu->uio.uio_iovcnt > 1 && conn->DataDigest && - !(mod->pars.options & ISCSITEST_SFLAG_NO_DATA_DIGEST)) - pdu->data_digest = gen_digest_2( - pdu->io_vec[1].iov_base, - pdu->io_vec[1].iov_len, - pdu->io_vec[2].iov_base, - pdu->io_vec[2].iov_len); - } - } - - s = splbio(); - TAILQ_REMOVE(&tp->mods, mod, link); - update_options(tp, mod); - /* we've modified a PDU - copy current count into last count */ - memcpy(tp->pdu_last, tp->pdu_count, sizeof(tp->pdu_last)); - splx(s); - - if (mod->pars.options & ISCSITEST_OPT_WAIT_FOR_COMPLETION) { - wakeup(mod); - } - if (mod->pars.options & ISCSITEST_KILL_CONNECTION) { - kill_connection(tp->connection, - ISCSI_STATUS_TEST_CONNECTION_CLOSED, - NO_LOGOUT, TRUE); - } - free(mod, M_TEMP); - - return rc; -} - - -/* - * free_negs: - * Free all negotiation elements attached to test parameter. - * - * Parameter: - * tp The test parameter - */ - -STATIC void -free_negs(test_pars_t *tp) -{ - neg_desc_t *np; - - while ((np = TAILQ_FIRST(&tp->negs)) != NULL) { - TAILQ_REMOVE(&tp->negs, np, link); - free(np, M_TEMP); - } -} - - -/* - * free_mods: - * Free all modification elements attached to test parameter. - * - * Parameter: - * tp The test parameter - * status The status code to return for clients waiting on completion - */ - -STATIC void -free_mods(test_pars_t *tp, uint32_t status) -{ - mod_desc_t *mp; - - while ((mp = TAILQ_FIRST(&tp->mods)) != NULL) { - TAILQ_REMOVE(&tp->mods, mp, link); - if (mp->pars.options & ISCSITEST_OPT_WAIT_FOR_COMPLETION) { - mp->pars.status = status; - wakeup(mp); - } - free(mp, M_TEMP); - } -} - - -/* ---------------- Global functions for PDU modifications ------------------ */ - -/* - * test_mode_rx: - * Check whether received PDU is to be modified - determine PDU kind, - * then call test_mod for further processing. - * - * Parameter: - * conn the connection - * pdu the PDU to modify - * error invalid frame if nonzero: don't do mods, frame will be - * discarded anyway. - * - * Returns nonzero if the PDU is to be discarded, 0 for normal processing. - */ - -int -test_mode_rx(connection_t *conn, pdu_t *pdu, int error) -{ - test_pars_t *tp; - iscsi_pdu_kind_t kind; - - if ((tp = conn->test_pars) == NULL) { - return 0; - } - switch (pdu->pdu.Opcode & OPCODE_MASK) { - case TOP_NOP_In: - kind = NOP_IN_PDU; - break; - - case TOP_SCSI_Response: - kind = RESPONSE_PDU; - break; - - case TOP_SCSI_Task_Management: - kind = TASK_RSP_PDU; - break; - - case TOP_Login_Response: - kind = LOGIN_RSP_PDU; - break; - - case TOP_Text_Response: - kind = TEXT_RSP_PDU; - break; - - case TOP_SCSI_Data_in: - kind = DATA_IN_PDU; - break; - - case TOP_Logout_Response: - kind = LOGOUT_RSP_PDU; - break; - - case TOP_R2T: - kind = R2T_PDU; - break; - - case TOP_Asynchronous_Message: - kind = ASYNCH_PDU; - break; - - case TOP_Reject: - kind = REJECT_PDU; - break; - - default: - kind = INVALID_PDU; - break; - } - - return test_mod(tp, pdu, kind, CNT_RX, error); -} - - -/* - * test_mode_tx: - * Check whether PDU to be sent is to be modified - determine PDU kind, - * then call test_mod for further processing. - * - * Parameter: - * conn the connection - * pdu the PDU to modify - * - * Returns nonzero if the PDU is to be discarded, 0 for normal processing. - */ - -int -test_mode_tx(connection_t *conn, pdu_t *pdu) -{ - test_pars_t *tp; - iscsi_pdu_kind_t kind; - - if ((tp = conn->test_pars) == NULL) - return 0; - - switch (pdu->pdu.Opcode & OPCODE_MASK) { - case IOP_NOP_Out: - kind = NOP_OUT_PDU; - break; - - case IOP_SCSI_Command: - kind = COMMAND_PDU; - break; - - case IOP_SCSI_Task_Management: - kind = TASK_REQ_PDU; - break; - - case IOP_Login_Request: - kind = LOGIN_REQ_PDU; - break; - - case IOP_Text_Request: - kind = TEXT_REQ_PDU; - break; - - case IOP_SCSI_Data_out: - kind = DATA_OUT_PDU; - break; - - case IOP_Logout_Request: - kind = LOGOUT_REQ_PDU; - break; - - case IOP_SNACK_Request: - kind = SNACK_PDU; - break; - - default: - kind = INVALID_PDU; - break; - } - - return test_mod(tp, pdu, kind, CNT_TX, 0); -} - - -/* - * test_assign_connection: - * Check whether there is an unassigned test parameter, and assign it to the - * given connection. - * Note: The number of concurrent tests at any time is assumed to be - * very small (usually 1-2). The algorithm used therefore can be very - * very simple minded. - * - * Parameter: - * conn the connection - */ - -void -test_assign_connection(connection_t *conn) -{ - test_pars_t *tp; - - for (tp = TAILQ_FIRST(&test_list); tp != NULL; tp = TAILQ_NEXT(tp, link)) { - if (tp->connection == NULL) { - tp->connection = conn; - conn->test_pars = tp; - DEB(1, ("Assigning session %d, connection %d to test %d\n", - conn->session->id, conn->id, tp->test_id)); - return; - } - } -} - -/* - * test_remove_connection: - * If the connection has test parameters assigned, remove and free those - * parameters. - * - * Parameter: - * conn the connection - */ - -void -test_remove_connection(connection_t *conn) -{ - test_pars_t *tp; - int s; - - s = splbio(); - if ((tp = conn->test_pars) != NULL) { - conn->test_pars = NULL; - TAILQ_REMOVE(&test_list, tp, link); - splx(s); - DEB(9, ("Remove test %d from connection %d\n", tp->test_id, conn->id)); - free_negs(tp); - free_mods(tp, ISCSI_STATUS_TEST_CONNECTION_CLOSED); - free(tp, M_TEMP); - } else { - splx(s); - } -} - - -/* ----------------------- Local Stuff for IOCTLs --------------------------- */ - -/* - * find_test_id: - * Search the given test ID in the test list. - * - * Parameter: - * id The test ID - * - * Returns a pointer to the test pars is found, else NULL. - */ - -STATIC test_pars_t * -find_test_id(uint32_t id) -{ - test_pars_t *curr; - - for (curr = TAILQ_FIRST(&test_list); - curr && curr->test_id != id; - curr = TAILQ_NEXT(curr, link)) { - } - return curr; -} - - -/* - * add_neg: - * Add negotiation element to test parameter. - * Helper for test_define and test_add_neg. - * - * Parameter: - * tp The test parameter - * addr The pointer to the descriptor - * len The descriptor size - * - * Returns 0 on success, else an ISCSI status code. - */ - -STATIC uint32_t -add_neg(test_pars_t *tp, void *addr, uint32_t len) -{ - neg_desc_t *negp; - uint32_t size; - - /* len already includes the size of iscsi_test_negotiation_descriptor_t */ - size = len + sizeof(neg_desc_t) - - sizeof(iscsi_test_negotiation_descriptor_t); - if ((negp = malloc(size, M_TEMP, M_WAITOK)) == NULL) { - return ISCSI_STATUS_NO_RESOURCES; - } - copyin(addr, &negp->entry, len); - TAILQ_INSERT_TAIL(&tp->negs, negp, link); - DEB(1, ("add_neg: size %d, phase %d, flags %x, data %02x...\n", - negp->entry.size, negp->entry.state, negp->entry.flags, - negp->entry.value[0])); - return 0; -} - - - -/* ----------------- Global functions for IOCTLs --------------------------- */ - -/* - * test_define: - * Implements ISCSI_TEST_DEFINE ioctl. - * - * Parameter: - * par The IOCTL parameter. - */ - -void -test_define(iscsi_test_define_parameters_t *par) -{ - test_pars_t *tp; - session_t *sess = NULL; - connection_t *conn = NULL; - - if (!par->test_id) { - par->status = ISCSI_STATUS_INVALID_ID; - return; - } - if (find_test_id(par->test_id) != NULL) { - par->status = ISCSI_STATUS_DUPLICATE_ID; - return; - } - if (par->session_id && - (sess = find_session(par->session_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_SESSION_ID; - return; - } - if (sess != NULL) { - if (par->connection_id && - (conn = find_connection(sess, par->connection_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_CONNECTION_ID; - return; - } else if (!par->connection_id) { - conn = TAILQ_FIRST(&sess->conn_list); - } - if (conn->test_pars != NULL) { - par->status = ISCSI_STATUS_TEST_ALREADY_ASSIGNED; - return; - } - } - - if ((tp = malloc(sizeof(*tp), M_TEMP, M_WAITOK | M_ZERO)) == NULL) { - par->status = ISCSI_STATUS_NO_RESOURCES; - return; - } - TAILQ_INIT(&tp->negs); - TAILQ_INIT(&tp->mods); - - if (par->neg_descriptor_size && - (par->status = add_neg(tp, par->neg_descriptor_ptr, - par->neg_descriptor_size)) != 0) { - free(tp, M_TEMP); - return; - } - - tp->test_id = par->test_id; - tp->options = par->options; - tp->lose_random[CNT_RX] = par->lose_random_rx; - tp->lose_random[CNT_TX] = par->lose_random_tx; - tp->connection = conn; - tp->firstburst_val = par->firstburst_val; - tp->maxburst_val = par->maxburst_val; - tp->r2t_val = par->r2t_val; - - DEB(1, ("TestDefine: id=%d, opt=%x, negsize=%d, conn=%x\n", - tp->test_id, tp->options, par->neg_descriptor_size, (int)conn)); - - TAILQ_INSERT_TAIL(&test_list, tp, link); - - if (conn != NULL) { - tp->connection = conn; - conn->test_pars = tp; - DEB(1, ("Assigning session %d, connection %d to test %d\n", - conn->session->id, conn->id, tp->test_id)); - } - - par->status = ISCSI_STATUS_SUCCESS; -} - - -/* - * test_add_neg: - * Implements ISCSI_TEST_ADD_NEGOTIATION ioctl. - * - * Parameter: - * par The IOCTL parameter. - */ - -void -test_add_neg(iscsi_test_add_negotiation_parameters_t *par) -{ - test_pars_t *tp; - - if ((tp = find_test_id(par->test_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_ID; - return; - } - if (par->neg_descriptor_size < - sizeof(iscsi_test_negotiation_descriptor_t)) { - par->status = ISCSI_STATUS_PARAMETER_INVALID; - return; - } - par->status = - add_neg(tp, par->neg_descriptor_ptr, par->neg_descriptor_size); -} - - -/* - * test_add_mod: - * Implements ISCSI_TEST_ADD_MODIFICATION ioctl. - * - * Parameter: - * par The IOCTL parameter. - */ - -void -test_add_mod(struct proc *p, iscsi_test_add_modification_parameters_t *par) -{ - test_pars_t *tp; - mod_desc_t *modp; - uint32_t len; - uint32_t psize = par->pdu_size; - void *pdu_ptr = par->pdu_ptr; - - if ((tp = find_test_id(par->test_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_ID; - return; - } - - len = par->num_pdu_mods * sizeof(iscsi_pdu_mod_t); - - if ((modp = malloc(len + sizeof(mod_desc_t), - M_TEMP, M_WAITOK | M_ZERO)) == NULL) { - par->status = ISCSI_STATUS_NO_RESOURCES; - return; - } - - par->status = ISCSI_STATUS_SUCCESS; - - modp->pars = *par; - if (len) - copyin(par->mod_ptr, modp->mods, len); - - if (psize) { - if (pdu_ptr == NULL) { - free(modp, M_TEMP); - par->status = ISCSI_STATUS_PARAMETER_INVALID; - return; - } - - if (pdu_ptr == NULL || - (par->status = map_databuf(p, &pdu_ptr, psize)) != 0) { - free(modp, M_TEMP); - return; - } - - modp->pdu_ptr = pdu_ptr; - /* force wait */ - modp->pars.options |= ISCSITEST_OPT_WAIT_FOR_COMPLETION; - } - TAILQ_INSERT_TAIL(&tp->mods, modp, link); - - if (modp->pars.options & ISCSITEST_OPT_WAIT_FOR_COMPLETION) - tsleep(modp, PWAIT, "test_completion", 0); -} - - -/* - * test_cancel: - * Implements ISCSI_TEST_CANCEL ioctl. - * - * Parameter: - * par The IOCTL parameter. - */ - -void -test_cancel(iscsi_test_cancel_parameters_t *par) -{ - test_pars_t *tp; - int s; - - if ((tp = find_test_id(par->test_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_ID; - return; - } - DEB(1, ("Test Cancel, id %d\n", par->test_id)); - - s = splbio(); - if (tp->connection) - tp->connection->test_pars = NULL; - TAILQ_REMOVE(&test_list, tp, link); - splx(s); - - free_negs(tp); - free_mods(tp, ISCSI_STATUS_TEST_CANCELED); - free(tp, M_TEMP); - par->status = ISCSI_STATUS_SUCCESS; -} - - -/* - * test_send_pdu: - * Implements ISCSI_TEST_SEND_PDU ioctl. - * - * Parameter: - * p The caller's context. - * par The IOCTL parameter. - */ - -void -test_send_pdu(struct proc *p, iscsi_test_send_pdu_parameters_t *par) -{ - static uint8_t pad_bytes[4] = { 0 }; - test_pars_t *tp; - connection_t *conn; - pdu_t *pdu; - uint32_t psize = par->pdu_size; - void *pdu_ptr = par->pdu_ptr; - struct uio *uio; - uint32_t i, pad, dsl, size; - int s; - - if ((tp = find_test_id(par->test_id)) == NULL) { - par->status = ISCSI_STATUS_INVALID_ID; - return; - } - if (!psize || pdu_ptr == NULL || - ((par->options & ISCSITEST_SFLAG_UPDATE_FIELDS) && psize < BHS_SIZE)) { - par->status = ISCSI_STATUS_PARAMETER_INVALID; - return; - } - if ((conn = tp->connection) == NULL) { - par->status = ISCSI_STATUS_TEST_INACTIVE; - return; - } - if ((pdu = get_pdu(conn, TRUE)) == NULL) { - par->status = ISCSI_STATUS_TEST_CONNECTION_CLOSED; - return; - } - DEB(1, ("Test Send PDU, id %d\n", par->test_id)); - - if ((par->status = map_databuf(p, &pdu_ptr, psize)) != 0) { - free_pdu(pdu); - return; - } - - i = 1; - if (!par->options) { - pdu->io_vec[0].iov_base = pdu_ptr; - pdu->io_vec[0].iov_len = size = psize; - } else { - memcpy(&pdu->pdu, pdu_ptr, BHS_SIZE); - - if (!(pdu->pdu.Opcode & OP_IMMEDIATE)) - conn->session->CmdSN++; - pdu->pdu.p.command.CmdSN = htonl(conn->session->CmdSN); - - dsl = psize - BHS_SIZE; - size = BHS_SIZE; - - hton3(dsl, pdu->pdu.DataSegmentLength); - - if (conn->HeaderDigest && - !(par->options & ISCSITEST_SFLAG_NO_HEADER_DIGEST)) { - pdu->pdu.HeaderDigest = gen_digest(&pdu->pdu, BHS_SIZE); - size += 4; - } - - pdu->io_vec[0].iov_base = &pdu->pdu; - pdu->io_vec[0].iov_len = size; - - if (dsl) { - pdu->io_vec[1].iov_base = &pdu_ptr[BHS_SIZE]; - pdu->io_vec[1].iov_len = dsl; - i++; - size += dsl; - - /* Pad to next multiple of 4 */ - pad = (par->options & ISCSITEST_SFLAG_NO_PADDING) ? 0 : size & 0x03; - - if (pad) { - pad = 4 - pad; - pdu->io_vec[i].iov_base = pad_bytes; - pdu->io_vec[i].iov_len = pad; - i++; - size += pad; - } - - if (conn->DataDigest && - !(par->options & ISCSITEST_SFLAG_NO_DATA_DIGEST)) { - pdu->data_digest = gen_digest_2(&pdu_ptr[BHS_SIZE], dsl, - pad_bytes, pad); - pdu->io_vec[i].iov_base = &pdu->data_digest; - pdu->io_vec[i].iov_len = 4; - i++; - size += 4; - } - } - } - uio = &pdu->uio; - uio->uio_iov = pdu->io_vec; - UIO_SETUP_SYSSPACE(uio); - uio->uio_rw = UIO_WRITE; - uio->uio_iovcnt = i; - uio->uio_resid = size; - - pdu->disp = PDUDISP_SIGNAL; - pdu->flags = PDUF_BUSY | PDUF_NOUPDATE; - - s = splbio(); - /* Enqueue for sending */ - if (pdu->pdu.Opcode & OP_IMMEDIATE) - TAILQ_INSERT_HEAD(&conn->pdus_to_send, pdu, send_chain); - else - TAILQ_INSERT_TAIL(&conn->pdus_to_send, pdu, send_chain); - - wakeup(&conn->pdus_to_send); - tsleep(pdu, PINOD, "test_send_pdu", 0); - splx(s); - - unmap_databuf(p, pdu_ptr, psize); - par->status = ISCSI_STATUS_SUCCESS; - if (par->options & ISCSITEST_KILL_CONNECTION) - kill_connection(conn, ISCSI_STATUS_TEST_CONNECTION_CLOSED, NO_LOGOUT, - TRUE); -} - -#endif diff --git a/sys/dev/iscsi/iscsi_test.h b/sys/dev/iscsi/iscsi_test.h deleted file mode 100644 index b848e84c680..00000000000 --- a/sys/dev/iscsi/iscsi_test.h +++ /dev/null @@ -1,264 +0,0 @@ -/* $NetBSD: iscsi_test.h,v 1.1 2011/10/23 21:15:02 agc Exp $ */ - -/*- - * Copyright (c) 2006,2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _ISCSI_TEST_H -#define _ISCSI_TEST_H - -#ifdef ISCSI_TEST_MODE - -/* Status codes returned in test mode only */ - -#define ISCSI_STATUS_TEST_INACTIVE 5001 /* Test not assigned to connection */ -#define ISCSI_STATUS_TEST_CANCELED 5002 /* Test was cancelled */ -#define ISCSI_STATUS_TEST_CONNECTION_CLOSED 5003 /* Connection closed */ -#define ISCSI_STATUS_TEST_MODIFICATION_SKIPPED 5004 /* Modification skipped due to bad offset */ -#define ISCSI_STATUS_TEST_HEADER_CRC_ERROR 5005 /* Received PDU had bad header CRC */ -#define ISCSI_STATUS_TEST_DATA_CRC_ERROR 5006 /* Received PDU had bad data CRC */ -#define ISCSI_STATUS_TEST_DATA_READ_ERROR 5007 /* Error while receiving PDU */ -#define ISCSI_STATUS_TEST_ALREADY_ASSIGNED 5008 /* Different test already assigned */ - -/* - PDU modification descriptor. -*/ - -#define ISCSITEST_MOD_FLAG_ADD_VAL 0x01 /* Add value to field */ - /* (default is replace) */ -#define ISCSITEST_MOD_FLAG_REORDER 0x02 /* Put bytes in network order */ - -/* Special values for offset field */ - -#define ISCSITEST_OFFSET_HEADERDIGEST (-1) /* offset is header digest */ -#define ISCSITEST_OFFSET_DATA (-2) /* offset is start of data */ -#define ISCSITEST_OFFSET_DATADIGEST (-3) /* offset is data digest */ -#define ISCSITEST_OFFSET_DRV_CMDSN (-4) /* offset is driver's CmdSN */ - - -typedef struct -{ - uint16_t flags; /* flags */ - uint16_t size; /* size of field in bytes (1..8) */ - int32_t offset; /* offset into PDU */ - uint8_t value[8]; /* value to use */ -} iscsi_pdu_mod_t; - -/* PDU kinds */ - -typedef enum -{ - ANY_PDU, /* don't care */ - COMMAND_PDU, - RESPONSE_PDU, - TASK_REQ_PDU, - TASK_RSP_PDU, - DATA_OUT_PDU, - DATA_IN_PDU, - R2T_PDU, - ASYNCH_PDU, - TEXT_REQ_PDU, - TEXT_RSP_PDU, - LOGIN_REQ_PDU, - LOGIN_RSP_PDU, - LOGOUT_REQ_PDU, - LOGOUT_RSP_PDU, - SNACK_PDU, - REJECT_PDU, - NOP_OUT_PDU, - NOP_IN_PDU, - INVALID_PDU -} iscsi_pdu_kind_t; - -/* types of offsets supported for determining PDU offset */ - -typedef enum -{ - ABSOLUTE_ANY, /* absolute to beginning of connection, any kind */ - RELATIVE_ANY, /* relative to last modified PDU, any kind */ - ABSOLUTE_PDUKIND, /* absolute to beginning of connection, same kind */ - RELATIVE_PDUKIND, /* relative to last modified PDU, same kind */ - ABSOLUTE_TX, /* absolute to beginning of connection, send only */ - RELATIVE_TX, /* relative to last modified PDU, send only */ - ABSOLUTE_RX, /* absolute to beginning of connection, receive only */ - RELATIVE_RX /* relative to last modified PDU, receive only */ -} iscsi_pdu_offset_t; - - -/* - Negotiation parameters -*/ - -/* Negotiation states */ - -typedef enum -{ - NEG_SECURITY, /* First security negotiation PDU (method) */ - NEG_CHAP_ALG, /* CHAP: Algorithm specification */ - NEG_CHAP_NAME_RESPONSE, /* CHAP: Name and Response */ - NEG_OP_NEG /* in Operational negotiation stage */ -} iscsi_neg_state_t; - -#define ISCSITEST_NEGOPT_REPLACE 0x01 /* Replace existing parameters */ - /* (default is append) */ - -typedef struct -{ - iscsi_neg_state_t state; /* which negotiation stage */ - uint16_t flags; /* flags */ - uint16_t size; /* size of value in bytes */ - uint8_t value[0]; /* value to use */ -} iscsi_test_negotiation_descriptor_t; - - -/* - Define and add test parameters - The calling application defines the test ID. Duplicate IDs are rejected. -*/ - -/* Options for define_parameters only */ - -#define ISCSITEST_NEGOTIATE_R2T 0x00000100 /* Negotiate MaxOutstandingR2T */ -#define ISCSITEST_NEGOTIATE_MAXBURST 0x00000200 /* Negotiate MaxBurstLength */ -#define ISCSITEST_NEGOTIATE_FIRSTBURST 0x00000400 /* Negotiate FirstBurstLength */ -#define ISCSITEST_OVERRIDE_INITIALR2T 0x00001000 /* Override default InitialR2T (set to TRUE) */ -#define ISCSITEST_OVERRIDE_IMMDATA 0x00002000 /* Override default ImmediateData (set to FALSE) */ - -/* options for both define and add_modification parameters */ - -#define ISCSITEST_OPT_DISABLE_CCB_TIMEOUT 0x00020000 /* Disable CCB timeout */ -#define ISCSITEST_OPT_ENABLE_CCB_TIMEOUT 0x00040000 /* Enable CCB timeout */ -#define ISCSITEST_OPT_DISABLE_CONN_TIMEOUT 0x00080000 /* Disable connection timeout */ -#define ISCSITEST_OPT_ENABLE_CONN_TIMEOUT 0x00100000 /* Enable connection timeout */ -#define ISCSITEST_OPT_USE_RANDOM_TX 0x00200000 /* Use random tx loss parameter */ -#define ISCSITEST_OPT_USE_RANDOM_RX 0x00400000 /* Use random rx loss parameter */ - -/* options for add_modification parameters only */ - -#define ISCSITEST_OPT_WAIT_FOR_COMPLETION 0x00000001 /* Wait until processing done */ - -#define ISCSITEST_OPT_MOD_PERMANENT 0x20000000 /* PDU header mods are permanent */ -#define ISCSITEST_OPT_NO_RESPONSE_PDU 0x40000000 /* Do not expect response to this PDU */ -#define ISCSITEST_OPT_DISCARD_PDU 0x80000000 /* Don't send PDU/process PDU in driver */ - -/* options for add_modification and send_pdu */ - -#define ISCSITEST_KILL_CONNECTION 0x08000000 /* Kill connection when done */ - -#define ISCSITEST_SFLAG_NO_HEADER_DIGEST 0x00000020 /* Do not update header digest */ -#define ISCSITEST_SFLAG_NO_DATA_DIGEST 0x00000040 /* Do not update data digest */ - -/* options for send_pdu only */ - -#define ISCSITEST_SFLAG_UPDATE_FIELDS 0x00000010 /* Update fields in PDU */ -#define ISCSITEST_SFLAG_NO_PADDING 0x00000080 /* Do not add padding */ - -/* The parameter for TEST_DEFINE ioctl */ - -typedef struct -{ - uint32_t test_id; /* Test ID */ - uint32_t options; /* Test options */ - uint32_t session_id; /* Session to attach to (may be 0) */ - uint32_t connection_id; /* Connection to attach to (may be 0) */ - uint8_t lose_random_tx; /* 0 disables, else mod value */ - uint8_t lose_random_rx; /* 0 disables, else mod value */ - uint32_t r2t_val; /* Used only if NEGOTIATE_R2T */ - uint32_t maxburst_val; /* Used only if NEGOTIATE_MAXBURST */ - uint32_t firstburst_val; /* Used only if NEGOTIATE_FIRSTBURST */ - uint32_t neg_descriptor_size; /* Size of negotiation descriptor (may be 0) */ - void *neg_descriptor_ptr; /* pointer to negotiation descriptor */ - uint32_t status; /* Out: Status */ -} iscsi_test_define_parameters_t; - - -/* The parameter for TEST_ADD_MODIFICATION ioctl */ - -typedef struct -{ - uint32_t test_id; /* Test ID */ - uint32_t options; /* Test options */ - uint8_t lose_random_tx; /* 0 disables, else mod value */ - uint8_t lose_random_rx; /* 0 disables, else mod value */ - iscsi_pdu_kind_t which_pdu; /* Which kind of PDU to act on */ - iscsi_pdu_offset_t which_offset; /* Which offset to use */ - uint32_t pdu_offset; /* Offset of PDU to act on (0 means next) */ - uint32_t num_pdu_mods; /* How many PDU modifications */ - iscsi_pdu_mod_t *mod_ptr; /* pointer to modifications */ - uint32_t pdu_size; /* size of PDU buffer for get */ - void *pdu_ptr; /* pointer to PDU buffer */ - uint32_t pdu_actual_size; /* Out: actual size of PDU */ - uint32_t status; /* Out: Status */ -} iscsi_test_add_modification_parameters_t; - - -/* The parameter for TEST_ADD_NEGOTIATION ioctl */ - -typedef struct -{ - uint32_t test_id; /* Test ID */ - uint32_t neg_descriptor_size; /* Size of negotiation descriptor (may be 0) */ - void *neg_descriptor_ptr; /* pointer to negotiation descriptor */ - uint32_t status; /* Out: Status */ -} iscsi_test_add_negotiation_parameters_t; - - -/* - Cancel test parameters -*/ - -typedef struct -{ - uint32_t test_id; /* Test ID */ - uint32_t status; /* Out: Status */ -} iscsi_test_cancel_parameters_t; - -/* - Send PDU parameters -*/ - -typedef struct -{ - uint32_t test_id; /* Test ID */ - uint32_t options; /* Test options */ - uint32_t pdu_size; /* size of PDU */ - void *pdu_ptr; /* pointer to PDU */ - uint32_t status; /* Out: Status */ -} iscsi_test_send_pdu_parameters_t; - - -/* IOCTL codes */ - -#define ISCSI_TEST_DEFINE _IOWR(0, 100, iscsi_test_define_parameters_t) -#define ISCSI_TEST_ADD_NEGOTIATION _IOWR(0, 101, iscsi_test_add_negotiation_parameters_t) -#define ISCSI_TEST_ADD_MODIFICATION _IOWR(0, 102, iscsi_test_add_modification_parameters_t) -#define ISCSI_TEST_SEND_PDU _IOWR(0, 103, iscsi_test_send_pdu_parameters_t) -#define ISCSI_TEST_CANCEL _IOWR(0, 109, iscsi_test_cancel_parameters_t) - -#endif -#endif diff --git a/sys/dev/iscsi/iscsi_testlocal.h b/sys/dev/iscsi/iscsi_testlocal.h deleted file mode 100644 index 554e249923e..00000000000 --- a/sys/dev/iscsi/iscsi_testlocal.h +++ /dev/null @@ -1,105 +0,0 @@ -/* $wasabi: iscsi_testlocal.h,v 1.5 2006/05/30 23:22:20 twagner Exp $ */ -/* $NetBSD: iscsi_testlocal.h,v 1.1 2011/10/23 21:15:02 agc Exp $ */ - -/*- - * Copyright (c) 2006,2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef _ISCSI_TESTLOCAL_H -#define _ISCSI_TESTLOCAL_H - -#ifdef ISCSI_TEST_MODE - -typedef struct mod_desc_s -{ - TAILQ_ENTRY(mod_desc_s) link; - void *pdu_ptr; /* get only */ - iscsi_test_add_modification_parameters_t pars; - iscsi_pdu_mod_t mods[0]; -} mod_desc_t; - - -typedef struct neg_desc_s -{ - TAILQ_ENTRY(neg_desc_s) link; - iscsi_test_negotiation_descriptor_t entry; -} neg_desc_t; - - -TAILQ_HEAD(mod_list_s, mod_desc_s); -typedef struct mod_list_s mod_list_t; - -TAILQ_HEAD(neg_list_s, neg_desc_s); -typedef struct neg_list_s neg_list_t; - -#define CNT_TX 0 -#define CNT_RX 1 - -typedef struct test_pars_s -{ - TAILQ_ENTRY(test_pars_s) link; /* links tests to be assigned */ - uint32_t test_id; /* Test ID */ - connection_t *connection; /* Attached Connection */ - uint16_t options; /* Test options */ - uint8_t lose_random[2]; /* 0 disables, else mod value */ - uint32_t r2t_val; /* Used only if NEGOTIATE_R2T */ - uint32_t maxburst_val; /* Used only if NEGOTIATE_MAXBURST */ - uint32_t firstburst_val; /* Used only if NEGOTIATE_FIRSTBURST */ - neg_list_t negs; /* list of negotiation descriptors */ - mod_list_t mods; /* list of modification decriptors */ - uint32_t pdu_count[INVALID_PDU + 1][2]; /* PDU counter */ - uint32_t pdu_last[INVALID_PDU + 1][2]; /* last PDU counter */ -} test_pars_t; - - -TAILQ_HEAD(test_pars_list_s, test_pars_s); -typedef struct test_pars_list_s test_pars_list_t; - -void test_assign_connection(connection_t *); -void test_remove_connection(connection_t *); - -#define TEST_INVALID_HEADER_CRC -99 -#define TEST_READ_ERROR 1 -#define TEST_INVALID_DATA_CRC -1 - -int test_mode_rx(connection_t *, pdu_t *, int); -int test_mode_tx(connection_t *, pdu_t *); - -void test_define(iscsi_test_define_parameters_t *); -void test_add_neg(iscsi_test_add_negotiation_parameters_t *); -void test_add_mod(struct proc *, iscsi_test_add_modification_parameters_t *); -void test_send_pdu(struct proc *, iscsi_test_send_pdu_parameters_t *); -void test_cancel(iscsi_test_cancel_parameters_t *); - -#define test_ccb_timeout(conn) ((conn->test_pars == NULL) ? 1 \ - : !(conn->test_pars->options & ISCSITEST_OPT_DISABLE_CCB_TIMEOUT)) - -#define test_conn_timeout(conn) ((conn->test_pars == NULL) ? 1 \ - : !(conn->test_pars->options & ISCSITEST_OPT_DISABLE_CONN_TIMEOUT)) - -#endif /* TEST_MODE */ -#endif /* TESTLOCAL_H */ diff --git a/sys/dev/iscsi/iscsi_text.c b/sys/dev/iscsi/iscsi_text.c index cbb2cb2f9f6..3063147abdd 100644 --- a/sys/dev/iscsi/iscsi_text.c +++ b/sys/dev/iscsi/iscsi_text.c @@ -1,4 +1,4 @@ -/* $NetBSD: iscsi_text.c,v 1.8 2015/05/15 16:25:50 joerg Exp $ */ +/* $NetBSD: iscsi_text.c,v 1.9 2015/05/30 16:12:34 joerg Exp $ */ /*- * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc. @@ -908,29 +908,9 @@ complete_pars(negotiation_state_t *state, pdu_t *pdu) { int len; uint8_t *bp; -#ifdef ISCSI_TEST_MODE - test_pars_t *tp = pdu->connection->test_pars; - neg_desc_t *nd = NULL; -#endif len = total_size(state->pars, state->num_pars); -#ifdef ISCSI_TEST_MODE - if (tp != NULL) { - while ((nd = TAILQ_FIRST(&pdu->connection->test_pars->negs)) != NULL && - nd->entry.state < state->auth_state) { - TAILQ_REMOVE(&tp->negs, nd, link); - free(nd, M_TEMP); - } - if (nd != NULL && nd->entry.state == state->auth_state) { - if (nd->entry.flags & ISCSITEST_NEGOPT_REPLACE) - len = 0; - len += nd->entry.size; - } else - nd = NULL; - } -#endif - DEB(10, ("complete_pars: n=%d, len=%d\n", state->num_pars, len)); if ((bp = malloc(len, M_TEMP, M_WAITOK)) == NULL) { @@ -939,25 +919,11 @@ complete_pars(negotiation_state_t *state, pdu_t *pdu) } pdu->temp_data = bp; -#ifdef ISCSI_TEST_MODE - if (nd == NULL || !(nd->entry.flags & ISCSITEST_NEGOPT_REPLACE)) - if ((bp = put_par_block(pdu->temp_data, len, - state->pars, state->num_pars)) == NULL) { - DEBOUT(("Bad parameter in complete_pars\n")); - return ISCSI_STATUS_PARAMETER_INVALID; - } - if (nd != NULL) { - memcpy(bp, nd->entry.value, nd->entry.size); - TAILQ_REMOVE(&tp->negs, nd, link); - free(nd, M_TEMP); - } -#else if (put_par_block(pdu->temp_data, len, state->pars, state->num_pars) == 0) { DEBOUT(("Bad parameter in complete_pars\n")); return ISCSI_STATUS_PARAMETER_INVALID; } -#endif pdu->temp_data_len = len; return 0; @@ -1590,30 +1556,6 @@ set_first_opnegs(connection_t *conn, negotiation_state_t *state) state->FirstBurstLength = entries[K_FirstBurstLength].defval; state->MaxOutstandingR2T = entries[K_MaxOutstandingR2T].defval; -#ifdef ISCSI_TEST_MODE - if (conn->test_pars != NULL) { - test_pars_t *tp = conn->test_pars; - - if (tp->options & ISCSITEST_OVERRIDE_INITIALR2T) - state->InitialR2T = TRUE; - if (tp->options & ISCSITEST_OVERRIDE_IMMDATA) - state->ImmediateData = FALSE; - - if (tp->options & ISCSITEST_NEGOTIATE_MAXBURST) { - state->MaxBurstLength = tp->maxburst_val; - set_key_n(state, K_MaxBurstLength, state->MaxBurstLength); - } - if (tp->options & ISCSITEST_NEGOTIATE_FIRSTBURST) { - state->FirstBurstLength = tp->firstburst_val; - set_key_n(state, K_FirstBurstLength, state->FirstBurstLength); - } - if (tp->options & ISCSITEST_NEGOTIATE_R2T) { - state->MaxOutstandingR2T = tp->r2t_val; - set_key_n(state, K_MaxOutstandingR2T, state->MaxOutstandingR2T); - } - } -#endif - set_key_n(state, K_ErrorRecoveryLevel, state->ErrorRecoveryLevel); set_key_n(state, K_InitialR2T, state->InitialR2T); set_key_n(state, K_ImmediateData, state->ImmediateData); |
