diff mbox series

[v6,23/24] qcow2: Relax is_zero() assertion

Message ID 20171012034720.11947-24-eblake@redhat.com
State New
Headers show
Series make bdrv_get_block_status byte-based | expand

Commit Message

Eric Blake Oct. 12, 2017, 3:47 a.m. UTC
Now that bdrv_is_allocated accepts non-aligned inputs, we can
remove the TODO added in earlier refactoring.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v6: new patch [Kevin]
---
 block/qcow2.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Eric Blake Oct. 12, 2017, 1:20 p.m. UTC | #1
On 10/11/2017 10:47 PM, Eric Blake wrote:
> Now that bdrv_is_allocated accepts non-aligned inputs, we can
> remove the TODO added in earlier refactoring.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>

I was a bit too hasty in the copy-and-paste from 22/24 - there is no
assertion in this patch, so the subject would be better as:

qcow2: Reduce is_zero() rounding
Kevin Wolf Oct. 20, 2017, 3:11 p.m. UTC | #2
Am 12.10.2017 um 15:20 hat Eric Blake geschrieben:
> On 10/11/2017 10:47 PM, Eric Blake wrote:
> > Now that bdrv_is_allocated accepts non-aligned inputs, we can
> > remove the TODO added in earlier refactoring.
> > 
> > Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> I was a bit too hasty in the copy-and-paste from 22/24 - there is no
> assertion in this patch, so the subject would be better as:
> 
> qcow2: Reduce is_zero() rounding

In fact, I don't see any assertion being modified in patch 22 either.

Kevin
Eric Blake Oct. 20, 2017, 3:32 p.m. UTC | #3
On 10/20/2017 10:11 AM, Kevin Wolf wrote:
> Am 12.10.2017 um 15:20 hat Eric Blake geschrieben:
>> On 10/11/2017 10:47 PM, Eric Blake wrote:
>>> Now that bdrv_is_allocated accepts non-aligned inputs, we can
>>> remove the TODO added in earlier refactoring.
>>>
>>> Signed-off-by: Eric Blake <eblake@redhat.com>
>>
>> I was a bit too hasty in the copy-and-paste from 22/24 - there is no
>> assertion in this patch, so the subject would be better as:
>>
>> qcow2: Reduce is_zero() rounding
> 
> In fact, I don't see any assertion being modified in patch 22 either.

Oh, indeed.  Not sure what I was thinking; I guess it's because I added
22 at the same time I added several other TODO assertions to series 1 a
couple months ago, with the plans to relax rounding/assertions as
appropriate later in the series, and then got confused on which things
were being relaxed where ;)

If it's just the subject lines for 22 and 23 that need fixing, I trust
you can do that as maintainer.
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 092a3cabdb..92cb9f9bfa 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3003,22 +3003,16 @@  static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes)
 {
     int64_t nr;
     int res;
-    int64_t start;
-
-    /* TODO: Widening to sector boundaries should only be needed as
-     * long as we can't query finer granularity. */
-    start = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
-    bytes = QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE) - start;

     /* Clamp to image length, before checking status of underlying sectors */
-    if (start + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) {
-        bytes = bs->total_sectors * BDRV_SECTOR_SIZE - start;
+    if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) {
+        bytes = bs->total_sectors * BDRV_SECTOR_SIZE - offset;
     }

     if (!bytes) {
         return true;
     }
-    res = bdrv_block_status_above(bs, NULL, start, bytes, &nr, NULL, NULL);
+    res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL);
     return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes;
 }