mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-20 12:11:26 +00:00
an external module. When applying the SCST kernel patch to the mainstream kernel tree with debugging and/or tracing enabled however, the resulting code triggers a compiler error. This is because the symbols DEBUG and TRACING conflict with symbols with the same named defined in unrelated kernel headers. The patch below resolves these conflicts by renaming the following preprocessor symbols: - DEBUG into CONFIG_SCST_DEBUG. - DEBUG_DIGEST_FAILURES into CONFIG_SCST_ISCSI_DEBUG_DIGEST_FAILURES. - DEBUG_OOM into CONFIG_SCST_DEBUG_OOM. - DEBUG_RETRY into CONFIG_SCST_DEBUG_RETRY. - DEBUG_SN into CONFIG_SCST_DEBUG_SN. - DEBUG_TM into CONFIG_SCST_DEBUG_TM. - EXTRACHECKS into CONFIG_SCST_EXTRACHECKS. - SCST_HIGHMEM into CONFIG_SCST_HIGHMEM. - STRICT_SERIALIZING into CONFIG_SCST_STRICT_SERIALIZING. - TM_DBG_GO_OFFLINE into CONFIG_SCST_TM_DBG_GO_OFFLINE. Mapped 0/1 values into macro undefined / macro defined. - TRACING into CONFIG_SCST_TRACING. - USE_EXPECTED_VALUES into CONFIG_SCST_USE_EXPECTED_VALUES. - In qla_isp/linux/isp_scst.c, renamed DEBUG into DEBUG_ISP_SCST. - In qla_isp/..., renamed SCSI_TARGET in SCST_SCSI_TARGET. - In qla_isp/..., renamed SCSI_TARGET_DEV in SCST_SCSI_TARGET_DEV. Additionally, all CONFIG_SCSI_TARGET* macro's are renamed into CONFIG_SCST* in order to avoid confusion between the STGT CONFIG-symbols and the SCST CONFIG- symbols. The following additional options are now configurable through Kconfig: - CONFIG_SCST_ISCSI_DEBUG_DIGEST_FAILURES - CONFIG_SCST_STRICT_SERIALIZING - CONFIG_SCST_STRICT_SECURITY - CONFIG_SCST_ALLOW_PASSTHROUGH_IO_SUBMIT_IN_SIRQ - CONFIG_SCST_ABORT_CONSIDER_FINISHED_TASKS_AS_NOT_EXISTING - CONFIG_SCST_USE_EXPECTED_VALUES - CONFIG_SCST_DEBUG_OOM - CONFIG_SCST_DEBUG_RETRY - CONFIG_SCST_DEBUG_SN - CONFIG_SCST_DEBUG_TM - CONFIG_SCST_TM_DBG_GO_OFFLINE The patch below has been verified as follows: - Verified that the following command does not print any new warning messages: make -s clean && make -C srpt -s clean && make -s scst iscsi-scst && make -C srpt -s - Verified as follows that the internal SCST patches still apply cleanly: for p in *patch; do patch -p0 --dry-run -f -s <$p; done - Checked that the patch generated by generate-kernel-patch still applies cleanly to the 2.6.25.7 kernel, and that the patched kernel tree still compiles, installs and boots fine, that the iscsi-scst, ib_srpt, scst_disk and scst_vdisk modules still load, and that iSCSI communication still works fine. All SCST kernel configuration options that could be enabled have been enabled during this test. Signed-off-by: Bart Van Assche <bart.vanassche@gmail.com> git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@453 d57e44dd-8a1f-0410-8b47-8ef2f437770f
220 lines
5.1 KiB
C
220 lines
5.1 KiB
C
/*
|
|
* iSCSI digest handling.
|
|
*
|
|
* Copyright (C) 2004 - 2006 Xiranet Communications GmbH <arne.redlich@xiranet.com>
|
|
* Copyright (C) 2007 - 2008 Vladislav Bolkhovitin
|
|
* Copyright (C) 2007 - 2008 CMS Distribution Limited
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include "iscsi.h"
|
|
#include "digest.h"
|
|
#include <linux/crc32c.h>
|
|
|
|
void digest_alg_available(unsigned int *val)
|
|
{
|
|
#if defined(CONFIG_LIBCRC32C_MODULE) || defined(CONFIG_LIBCRC32C)
|
|
int crc32c = 1;
|
|
#else
|
|
int crc32c = 0;
|
|
#endif
|
|
|
|
if ((*val & DIGEST_CRC32C) && !crc32c) {
|
|
PRINT_ERROR("%s", "CRC32C digest algorithm not available "
|
|
"in kernel");
|
|
*val |= ~DIGEST_CRC32C;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* initialize support for digest calculation.
|
|
*
|
|
* digest_init -
|
|
* @conn: ptr to connection to make use of digests
|
|
*
|
|
* @return: 0 on success, < 0 on error
|
|
*/
|
|
int digest_init(struct iscsi_conn *conn)
|
|
{
|
|
if (!(conn->hdigest_type & DIGEST_ALL))
|
|
conn->hdigest_type = DIGEST_NONE;
|
|
|
|
if (!(conn->ddigest_type & DIGEST_ALL))
|
|
conn->ddigest_type = DIGEST_NONE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static u32 evaluate_crc32_from_sg(struct scatterlist *sg, int total,
|
|
int pad_bytes)
|
|
{
|
|
u32 crc = ~0;
|
|
|
|
#ifdef CONFIG_SCST_ISCSI_DEBUG_DIGEST_FAILURES
|
|
if (((scst_random() % 100000) == 752)) {
|
|
PRINT_INFO("%s", "Simulating digest failure");
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#if defined(CONFIG_LIBCRC32C_MODULE) || defined(CONFIG_LIBCRC32C)
|
|
while (total > 0) {
|
|
int d = min(min(total, (int)(sg->length)),
|
|
(int)(PAGE_SIZE - sg->offset));
|
|
|
|
crc = crc32c(crc, sg_virt(sg), d);
|
|
total -= d;
|
|
sg++;
|
|
}
|
|
|
|
if (pad_bytes) {
|
|
u32 padding = 0;
|
|
/*
|
|
* Digest includes also padding for aligned pdu length, hopefully
|
|
* it is always filled with 0s in pdu (according to crypto/crc32c.c
|
|
*/
|
|
crc = crc32c(crc, (u8 *)&padding, pad_bytes);
|
|
}
|
|
#endif
|
|
|
|
return ~cpu_to_le32(crc);
|
|
}
|
|
|
|
static u32 digest_header(struct iscsi_pdu *pdu)
|
|
{
|
|
struct scatterlist sg[2];
|
|
unsigned int nbytes = sizeof(struct iscsi_hdr);
|
|
|
|
sg_init_table(sg, 2);
|
|
|
|
sg_set_buf(&sg[0], &pdu->bhs, nbytes);
|
|
if (pdu->ahssize) {
|
|
sg_set_buf(&sg[1], pdu->ahs, pdu->ahssize);
|
|
nbytes += pdu->ahssize;
|
|
}
|
|
return evaluate_crc32_from_sg(sg, nbytes, 0);
|
|
}
|
|
|
|
static u32 digest_data(struct iscsi_cmnd *cmd, u32 osize, u32 offset)
|
|
{
|
|
struct scatterlist *sg = cmd->sg;
|
|
int idx, count;
|
|
struct scatterlist saved_sg;
|
|
u32 size = (osize + 3) & ~3;
|
|
u32 crc;
|
|
|
|
offset += sg[0].offset;
|
|
idx = offset >> PAGE_SHIFT;
|
|
offset &= ~PAGE_MASK;
|
|
|
|
count = get_pgcnt(size, offset);
|
|
|
|
TRACE_DBG("req %p, idx %d, count %d, sg_cnt %d, size %d, "
|
|
"offset %d", cmd, idx, count, cmd->sg_cnt, size, offset);
|
|
sBUG_ON(idx + count > cmd->sg_cnt);
|
|
sBUG_ON(count > ISCSI_CONN_IOV_MAX);
|
|
|
|
saved_sg = sg[idx];
|
|
sg[idx].offset = offset;
|
|
sg[idx].length -= offset - saved_sg.offset;
|
|
|
|
crc = evaluate_crc32_from_sg(sg + idx, osize, size - osize);
|
|
|
|
sg[idx] = saved_sg;
|
|
return crc;
|
|
}
|
|
|
|
int digest_rx_header(struct iscsi_cmnd *cmnd)
|
|
{
|
|
u32 crc;
|
|
|
|
crc = digest_header(&cmnd->pdu);
|
|
if (unlikely(crc != cmnd->hdigest)) {
|
|
PRINT_ERROR("%s", "RX header digest failed");
|
|
return -EIO;
|
|
} else
|
|
TRACE_DBG("RX header digest OK for cmd %p", cmnd);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void digest_tx_header(struct iscsi_cmnd *cmnd)
|
|
{
|
|
cmnd->hdigest = digest_header(&cmnd->pdu);
|
|
TRACE_DBG("TX header digest for cmd %p: %x", cmnd, cmnd->hdigest);
|
|
}
|
|
|
|
int digest_rx_data(struct iscsi_cmnd *cmnd)
|
|
{
|
|
struct iscsi_cmnd *req;
|
|
struct iscsi_data_out_hdr *req_hdr;
|
|
u32 offset, crc;
|
|
int res = 0;
|
|
|
|
if (unlikely(cmnd->rejected))
|
|
goto out;
|
|
|
|
switch (cmnd_opcode(cmnd)) {
|
|
case ISCSI_OP_SCSI_DATA_OUT:
|
|
req = cmnd->cmd_req;
|
|
req_hdr = (struct iscsi_data_out_hdr *)&cmnd->pdu.bhs;
|
|
offset = be32_to_cpu(req_hdr->buffer_offset);
|
|
break;
|
|
|
|
default:
|
|
req = cmnd;
|
|
offset = 0;
|
|
}
|
|
|
|
crc = digest_data(req, cmnd->pdu.datasize, offset);
|
|
|
|
if (unlikely(crc != cmnd->ddigest)) {
|
|
PRINT_ERROR("%s", "RX data digest failed");
|
|
res = -EIO;
|
|
} else
|
|
TRACE_DBG("RX data digest OK for cmd %p", cmnd);
|
|
|
|
out:
|
|
return res;
|
|
}
|
|
|
|
void digest_tx_data(struct iscsi_cmnd *cmnd)
|
|
{
|
|
struct iscsi_data_in_hdr *hdr;
|
|
u32 offset;
|
|
|
|
TRACE_DBG("%s:%d req %p, own_sg %d, sg %p, sgcnt %d cmnd %p, "
|
|
"own_sg %d, sg %p, sgcnt %d", __func__, __LINE__,
|
|
cmnd->parent_req, cmnd->parent_req->own_sg,
|
|
cmnd->parent_req->sg, cmnd->parent_req->sg_cnt,
|
|
cmnd, cmnd->own_sg, cmnd->sg, cmnd->sg_cnt);
|
|
|
|
switch (cmnd_opcode(cmnd)) {
|
|
case ISCSI_OP_SCSI_DATA_IN:
|
|
hdr = (struct iscsi_data_in_hdr *)&cmnd->pdu.bhs;
|
|
offset = be32_to_cpu(hdr->buffer_offset);
|
|
break;
|
|
default:
|
|
offset = 0;
|
|
}
|
|
|
|
/*
|
|
* cmnd is used here regardless of its sg comes from parent or was
|
|
* allocated for this cmnd only, see cmnd_send_pdu()
|
|
*/
|
|
cmnd->ddigest = digest_data(cmnd, cmnd->pdu.datasize, offset);
|
|
TRACE_DBG("TX data digest for cmd %p: %x (offset %d, opcode %x)", cmnd,
|
|
cmnd->ddigest, offset, cmnd_opcode(cmnd));
|
|
}
|