From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrToT-0006BX-AP for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:06:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrToL-0003OH-R2 for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:06:13 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38638 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrToL-0003O6-Af for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:06:05 -0400 Date: Mon, 2 Jun 2014 17:06:04 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140602150604.GG8181@irqsave.net> References: <1401473631-10724-1-git-send-email-armbru@redhat.com> <1401473631-10724-8-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1401473631-10724-8-git-send-email-armbru@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 07/10] block: Use bdrv_nb_sectors() where sectors, not bytes are wanted List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com The Friday 30 May 2014 =E0 20:13:48 (+0200), Markus Armbruster wrote : > Instead of bdrv_getlength(). >=20 > Aside: a few of these callers don't handle errors. I didn't > investigate whether they should. >=20 > Signed-off-by: Markus Armbruster > Reviewed-by: Eric Blake > --- > block-migration.c | 9 ++++----- > block.c | 3 +-- > block/qcow2.c | 2 +- > block/vmdk.c | 5 ++--- > 4 files changed, 8 insertions(+), 11 deletions(-) >=20 > diff --git a/block-migration.c b/block-migration.c > index 1656270..1c7b7be 100644 > --- a/block-migration.c > +++ b/block-migration.c > @@ -186,7 +186,7 @@ static int bmds_aio_inflight(BlkMigDevState *bmds, = int64_t sector) > { > int64_t chunk =3D sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK; > =20 > - if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) { > + if (sector < bdrv_nb_sectors(bmds->bs)) { > return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)= ] & > (1UL << (chunk % (sizeof(unsigned long) * 8)))); > } else { > @@ -223,8 +223,7 @@ static void alloc_aio_bitmap(BlkMigDevState *bmds) > BlockDriverState *bs =3D bmds->bs; > int64_t bitmap_size; > =20 > - bitmap_size =3D (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) + > - BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1; > + bitmap_size =3D bdrv_nb_sectors(bs) + BDRV_SECTORS_PER_DIRTY_CHUNK= * 8 - 1; > bitmap_size /=3D BDRV_SECTORS_PER_DIRTY_CHUNK * 8; > =20 > bmds->aio_bitmap =3D g_malloc0(bitmap_size); > @@ -350,7 +349,7 @@ static void init_blk_migration_it(void *opaque, Blo= ckDriverState *bs) > int64_t sectors; > =20 > if (!bdrv_is_read_only(bs)) { > - sectors =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; > + sectors =3D bdrv_nb_sectors(bs); > if (sectors <=3D 0) { > return; > } > @@ -800,7 +799,7 @@ static int block_load(QEMUFile *f, void *opaque, in= t version_id) > =20 > if (bs !=3D bs_prev) { > bs_prev =3D bs; > - total_sectors =3D bdrv_getlength(bs) >> BDRV_SECTOR_BI= TS; > + total_sectors =3D bdrv_nb_sectors(bs); > if (total_sectors <=3D 0) { > error_report("Error getting length of block device= %s", > device_name); > diff --git a/block.c b/block.c > index cfeb497..8ebfb79 100644 > --- a/block.c > +++ b/block.c > @@ -5258,13 +5258,12 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(Block= DriverState *bs, int granularity, > =20 > granularity >>=3D BDRV_SECTOR_BITS; > assert(granularity); > - bitmap_size =3D bdrv_getlength(bs); > + bitmap_size =3D bdrv_nb_sectors(bs); The name bitmap_size seems to imply the unit is byte. > if (bitmap_size < 0) { > error_setg_errno(errp, -bitmap_size, "could not get length of = device"); > errno =3D -bitmap_size; > return NULL; > } > - bitmap_size >>=3D BDRV_SECTOR_BITS; > bitmap =3D g_malloc0(sizeof(BdrvDirtyBitmap)); > bitmap->bitmap =3D hbitmap_alloc(bitmap_size, ffs(granularity) - 1= ); > QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list); > diff --git a/block/qcow2.c b/block/qcow2.c > index a4b97e8..98f624c 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1539,7 +1539,7 @@ static int preallocate(BlockDriverState *bs) > int ret; > QCowL2Meta *meta; > =20 > - nb_sectors =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; > + nb_sectors =3D bdrv_nb_sectors(bs); > offset =3D 0; > =20 > while (nb_sectors) { > diff --git a/block/vmdk.c b/block/vmdk.c > index 480ea37..5c5e73b 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -669,8 +669,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, > if (le32_to_cpu(header.flags) & VMDK4_FLAG_RGD) { > l1_backup_offset =3D le64_to_cpu(header.rgd_offset) << 9; > } > - if (bdrv_getlength(file) < > - le64_to_cpu(header.grain_offset) * BDRV_SECTOR_SIZE) { > + if (bdrv_nb_sectors(file) < le64_to_cpu(header.grain_offset)) { > error_setg(errp, "File truncated, expecting at least %" PRId64= " bytes", > (int64_t)(le64_to_cpu(header.grain_offset) > * BDRV_SECTOR_SIZE)); > @@ -2004,7 +2003,7 @@ static int vmdk_check(BlockDriverState *bs, BdrvC= heckResult *result, > BDRVVmdkState *s =3D bs->opaque; > VmdkExtent *extent =3D NULL; > int64_t sector_num =3D 0; > - int64_t total_sectors =3D bdrv_getlength(bs) / BDRV_SECTOR_SIZE; > + int64_t total_sectors =3D bdrv_nb_sectors(bs); > int ret; > uint64_t cluster_offset; > =20 > --=20 > 1.9.3 >=20 >=20