/*******************************************************************************
* This file contains error recovery level one used by the iSCSI Target driver.
*
* \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
*
* Licensed to the Linux Foundation under the General Public License (GPL) version 2.
*
* Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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/list.h>
#include <scsi/iscsi_proto.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric.h>
#include <target/iscsi/iscsi_transport.h>
#include "iscsi_target_core.h"
#include "iscsi_target_seq_pdu_list.h"
#include "iscsi_target_datain_values.h"
#include "iscsi_target_device.h"
#include "iscsi_target_tpg.h"
#include "iscsi_target_util.h"
#include "iscsi_target_erl0.h"
#include "iscsi_target_erl1.h"
#include "iscsi_target_erl2.h"
#include "iscsi_target.h"
#define OFFLOAD_BUF_SIZE 32768
/*
* Used to dump excess datain payload for certain error recovery
* situations. Receive in OFFLOAD_BUF_SIZE max of datain per rx_data().
*
* dump_padding_digest denotes if padding and data digests need
* to be dumped.
*/
int iscsit_dump_data_payload(
struct iscsi_conn *conn,
u32 buf_len,
int dump_padding_digest)
{
char *buf, pad_bytes[4];
int ret = DATAOUT_WITHIN_COMMAND_RECOVERY, rx_got;
u32 length, padding, offset = 0, size;
struct kvec iov;
if (conn->sess->sess_ops->RDMAExtensions)
return 0;
length = (buf_len > OFFLOAD_BUF_SIZE) ? OFFLOAD_BUF_SIZE : buf_len;
buf = kzalloc(length, GFP_ATOMIC);
if (!buf) {
pr_err("Unable to allocate %u bytes for offload"
" buffer.\n", length);
return -1;
}
memset(&iov, 0, sizeof(struct kvec));
while (offset < buf_len) {
size = ((offset + length) > buf_len) ?
(buf_len - offset) : length;
iov.iov_len = size;
iov.iov_base = buf;
rx_got = rx_data(conn, &iov, 1, size);
if (rx_got != size) {
ret = DATAOUT_CANNOT_RECOVER;
goto out;
}
offset += size;
}
if (!dump_padding_digest)
goto out;
padding = ((-buf_len) & 3);
if (padding != 0) {
iov.iov_len