From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcuGZ-0003tW-0N for qemu-devel@nongnu.org; Thu, 16 May 2013 05:14:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcuGW-00051B-Dk for qemu-devel@nongnu.org; Thu, 16 May 2013 05:14:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12237) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcuGW-000516-5X for qemu-devel@nongnu.org; Thu, 16 May 2013 05:14:24 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4G9ENOx026621 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 16 May 2013 05:14:23 -0400 Date: Thu, 16 May 2013 11:14:21 +0200 From: Stefan Hajnoczi Message-ID: <20130516091421.GJ1597@stefanha-thinkpad.redhat.com> References: <1368618432-4431-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1368618432-4431-1-git-send-email-kwolf@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qemu-io: Fix 'map' output List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Wed, May 15, 2013 at 01:47:12PM +0200, Kevin Wolf wrote: > +static int map_is_allocated(int64_t sector_num, int64_t nb_sectors, int64_t *pnum) > +{ > + int num, num_checked; > + int ret, firstret; > + > + num_checked = MIN(nb_sectors, INT_MAX); > + ret = bdrv_is_allocated(bs, sector_num, num_checked, &num); > + if (ret < 0) { > + return ret; > + } > + > + firstret = ret; > + *pnum = num; > + > + while (nb_sectors > 0 && ret == firstret) { > + sector_num += num; > + nb_sectors -= num; > + > + num_checked = MIN(nb_sectors, INT_MAX); > + ret = bdrv_is_allocated(bs, sector_num, num_checked, &num); > + if (ret == firstret) { > + *pnum += num; > + } else { > + break; > + } The break makes && ret == firstret redundant above. I suggest just while (nb_sectors > 0) { ... } which is easier to read. Also, if you respin the patch please tweak the commit message. "Coalesce 'map' output" is more specific than "Fix 'map' output" - unless this really fixes a bug which you didn't mention in the commit description.