Ignore padding when an iovector is supplied

The iSCSI protocol adds padding to a data packet if the data size is not
a multiple of four.  The iovector provided by QEMU does not include such
padding, and libiscsi then complains that there was a protocol error.
This patch fixes this by reading the padding in a separate "recv"
system call.  These packets anyway do not happen in the data path,
where the packet size is a multiple of 512.

This fixes QEMU's scsi-generic backend, which triggered the problem when
the target sent a 66-byte INQUIRY response.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini
2013-08-26 17:54:47 +02:00
parent daac72a8f9
commit 73b0d4777f
3 changed files with 51 additions and 11 deletions

View File

@@ -230,11 +230,22 @@ iscsi_get_pdu_data_size(const unsigned char *hdr)
int size;
size = scsi_get_uint32(&hdr[4]) & 0x00ffffff;
size = (size+3) & 0xfffffffc;
return size;
}
int
iscsi_get_pdu_padding_size(const unsigned char *hdr)
{
int data_size, padded_size;
data_size = scsi_get_uint32(&hdr[4]) & 0x00ffffff;
padded_size = (data_size+3) & 0xfffffffc;
return padded_size - data_size;
}
enum iscsi_reject_reason {
ISCSI_REJECT_RESERVED = 0x01,
ISCSI_REJECT_DATA_DIGEST_ERROR = 0x02,