From dd1e0082cf6d18c9e996dbe1809098c51f3619d7 Mon Sep 17 00:00:00 2001
From: John Snow <jsnow@redhat.com>
Date: Fri, 14 Nov 2014 22:07:34 +0100
Subject: [PATCH 46/48] ahci: Fix byte count regression for ATAPI/PIO

Message-id: <1416002855-4964-20-git-send-email-jsnow@redhat.com>
Patchwork-id: 62404
O-Subject: [RHEV-7.1 qemu-kvm-rhev PATCH v2 19/20] ahci: Fix byte count regression for ATAPI/PIO
Bugzilla: 1024599
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

This patch fixes a regression caused by commit
659142ecf71a0da240ab0ff7cf929ee25c32b9bc.
The problem occurs when we wish to return early
from the ahci_start_transfer function, but are now
updating the transferred byte count in the AHCI
command header via ahci_commit_buf.

This will cause problems in the Windows 8 installer.

Don't update the byte count in the command header
for the transmission of ATAPI packets: These commands
will distort the final byte count of the actual data
payload.

The call to ahci_commit_buf remains in the "out"
portion of the call in order to clean up the sglist.
The byte count is maintained by forcing size to be 0.

Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit a395f3fa2f26c94dac03b37e3dfb1074bfe2ddea)
Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 4b94d51..f64f9b6 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1084,6 +1084,7 @@ static void ahci_start_transfer(IDEDMA *dma)
     if (is_atapi && !ad->done_atapi_packet) {
         /* already prepopulated iobuffer */
         ad->done_atapi_packet = true;
+        size = 0;
         goto out;
     }
 
-- 
1.8.3.1

