Received: from eggs.gnu.org ([2001:4830:134:3::10]:44269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjpSv-0007MX-Iy for qemu-devel@nongnu.org; Mon, 12 May 2014 08:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjpSo-0001tC-FP for qemu-devel@nongnu.org; Mon, 12 May 2014 08:36:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65129) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjpSo-0001sw-7b for qemu-devel@nongnu.org; Mon, 12 May 2014 08:36:14 -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 s4CCaCc7010955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 12 May 2014 08:36:13 -0400 From: Markus Armbruster References: <1399628898-3241-1-git-send-email-armbru@redhat.com> <1399628898-3241-3-git-send-email-armbru@redhat.com> <20140512111156.GB4371@noname.redhat.com> Date: Mon, 12 May 2014 14:36:09 +0200 In-Reply-To: <20140512111156.GB4371@noname.redhat.com> (Kevin Wolf's message of "Mon, 12 May 2014 13:11:56 +0200") Message-ID: <877g5rqime.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/5] block: New bdrv_nb_sectors() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, stefanha@redhat.com Kevin Wolf writes: > Am 09.05.2014 um 11:48 hat Markus Armbruster geschrieben: >> A call to retrieve the image size converts between bytes and sectors >> several times: >> >> * BlockDriver method bdrv_getlength() returns bytes. >> >> * refresh_total_sectors() converts to sectors, rounding up, and stores >> in total_sectors. >> >> * bdrv_getlength() converts total_sectors back to bytes (now rounded >> up to a multiple of the sector size). >> >> * Callers wanting sectors rather bytes convert it right back. >> Example: bdrv_get_geometry(). >> >> bdrv_nb_sectors() provides a way to omit the last two conversions. >> It's exactly bdrv_getlength() with the conversion to bytes omitted. >> It's functionally like bdrv_get_geometry() without its odd error >> handling. >> >> Reimplement bdrv_getlength() and bdrv_get_geometry() on top of >> bdrv_nb_sectors(). >> >> The next patches will convert some users of bdrv_getlength() to >> bdrv_nb_sectors(). >> >> Signed-off-by: Markus Armbruster > > Is this really the right direction to move? > > Generally I think we should be trying to move away from those arbitrary > units of 512 bytes (that are called sectors for some reason, but aren't > really related to either guest or host sector sizes), and towards > interfaces that use byte granularity. My patches neither move towards nor away from a byte-based interface. > So I would rather see bs->total_sectors becoming bs->total_bytes than > adding a new sector-based function. Doing away with BDRV_SECTOR_SIZE & friends is beyond my reach. My initial hope was to replace bdrv_get_geometry() by bdrv_nb_sectors(), but I ran out of steam reviewing whether and how the callers should handle errors. So yes, this adds another sector-based function. But I believe it makes the code a bit simpler, and won't make an eventual conversion to byte-based any harder.