Received: from eggs.gnu.org ([2001:4830:134:3::10]:39345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9FMZ-0001DG-Pa for qemu-devel@nongnu.org; Wed, 16 Dec 2015 11:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9FMT-0006Aj-SO for qemu-devel@nongnu.org; Wed, 16 Dec 2015 11:55:39 -0500 Received: from mx0.arrikto.com ([212.71.252.59]:58935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9FMT-0006AI-Hb for qemu-devel@nongnu.org; Wed, 16 Dec 2015 11:55:33 -0500 From: Alex Pyrgiotis Date: Wed, 16 Dec 2015 18:55:11 +0200 Message-Id: <1450284917-10508-4-git-send-email-apyrgio@arrikto.com> In-Reply-To: <1450284917-10508-1-git-send-email-apyrgio@arrikto.com> References: <1450284917-10508-1-git-send-email-apyrgio@arrikto.com> Subject: [Qemu-devel] [PATCH 3/9] dma-helpers: Do not truncate small qiovs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com If the size of the qiov is smaller than the sector size, do not truncate the qiov, which would effectively make it empty. Instead, allow it to pass as is. This is necessary for SCSI requests like READ CAPACITY which have small buffers, e.g. 32 bytes. Signed-off-by: Alex Pyrgiotis Signed-off-by: Dimitris Aragiorgis diff --git a/dma-helpers.c b/dma-helpers.c index e1ea7b3..b8f2ae0 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -162,7 +162,16 @@ static void dma_map_sg(DMAAIOCB *dbs) return; } - if (dbs->iov.size & ~BDRV_SECTOR_MASK) { + /* + * If the size of the qiov is not a multiple of the sector size, truncate + * the qiov. + * + * NOTE: If the qiov is less than a sector, we can assume that there is a + * reason for it, e.g., a SCSI request such as READ CAPACITY, and we should + * not truncate it. + */ + if (dbs->iov.size & ~BDRV_SECTOR_MASK && + dbs->iov.size > BDRV_SECTOR_SIZE) { qemu_iovec_discard_back(&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK); } } -- 2.6.2