From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xocxz-0003NH-AY for qemu-devel@nongnu.org; Wed, 12 Nov 2014 13:48:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xocxr-0004z9-BG for qemu-devel@nongnu.org; Wed, 12 Nov 2014 13:48:30 -0500 Received: from mail-by2on0139.outbound.protection.outlook.com ([207.46.100.139]:8160 helo=na01-by2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xocxr-0004z5-0t for qemu-devel@nongnu.org; Wed, 12 Nov 2014 13:48:23 -0500 From: Gary Hook Date: Wed, 12 Nov 2014 18:48:18 +0000 Message-ID: Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_D08907903A5Agaryhooknimboxxcom_" MIME-Version: 1.0 Subject: [Qemu-devel] [PATCH 1/1] block migration: fix return value mismatch List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" --_000_D08907903A5Agaryhooknimboxxcom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable The function uses a ternary return value (<, >, =3D=3D 0) defined as an int= . The code in in this function uses int64_t types to collect ftell() return= values and use their difference as the return value. Unfortunately, narrow= ing of integer types results in the disposal of the left-most bits that won= 't fit in the target type. Here, for values larger than 2GB, the resulting = value will be randomly negative or positive, based on total number of block= s. The patch ensures that only +1, -1, or 0 are returned to properly report= status. diff -u -r a/block-migration.c b/block-migration.c --- a/block-migration.c 2014-04-17 08:30:59.000000000 -0500 +++ b/block-migration.c 2014-11-10 12:39:10.727431187 -0600 @@ -628,6 +628,7 @@ { int ret; int64_t last_ftell =3D qemu_ftell(f); + int64_t delta_ftell; DPRINTF("Enter save live iterate submitted %d transferred %d\n", block_mig_state.submitted, block_mig_state.transferred); @@ -677,7 +678,8 @@ } qemu_put_be64(f, BLK_MIG_FLAG_EOS); - return qemu_ftell(f) - last_ftell; + delta_ftell =3D qemu_ftell(f) - last_ftell; + return( (delta_ftell > 0) ? 1 : (delta_ftell < 0) ? -1 : 0 ); } /* Called with iothread lock taken. */ --_000_D08907903A5Agaryhooknimboxxcom_ Content-Type: text/html; charset="iso-8859-1" Content-ID: <2E4AF8A15CD85C49B573A3B49C8EE071@namprd02.prod.outlook.com> Content-Transfer-Encoding: quoted-printable
The function uses a ternary return value (<, >, =3D=3D 0) define= d as an int. The code in in this function uses int64_t types to collect fte= ll() return values and use their difference as the return value. Unfortunat= ely, narrowing of integer types results in the disposal of the left-most bits that won’t fit in the target type= . Here, for values larger than 2GB, the resulting value will be randomly ne= gative or positive, based on total number of blocks. The patch ensures that= only +1, -1, or 0 are returned to properly report status.



diff -u -r a/block-migration.c b/block-migration.c

--- a/block-migration.c 2014-04-17 08:30:59.000000000 -0500

+++ b/block-migration.c 2014-11-10 12:39:10.727431187 -0600

@@ -628,6 +628,7 @@

 {

     int ret;

     int64_t last_ftell =3D qemu_ftell(f);

+    int64_t delta_ftell;

 

     DPRINTF("Enter save live iterate submitted %= d transferred %d\n",

             block_mig_state.submi= tted, block_mig_state.transferred);

@@ -677,7 +678,8 @@

     }

 

     qemu_put_be64(f, BLK_MIG_FLAG_EOS);

-    return qemu_ftell(f) - last_ftell;

+    delta_ftell =3D qemu_ftell(f) - last_ftell;

+    return( (delta_ftell > 0) ? 1 : (delta_ftell &l= t; 0) ? -1 : 0 );

 }

 

 /* Called with iothread lock taken.  */


--_000_D08907903A5Agaryhooknimboxxcom_--