qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Re: [PATCH 2/2] block: Cache total_sectors to reduce bd


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] Re: [PATCH 2/2] block: Cache total_sectors to reduce bdrv_getlength calls
Date: Mon, 19 Apr 2010 15:26:06 +0100

On Mon, Apr 19, 2010 at 3:10 PM, Kevin Wolf <address@hidden> wrote:
>> @@ -416,9 +417,7 @@ static int bdrv_open_common(BlockDriverState *bs, const 
>> char *filename,
>>      }
>>
>>      bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
>> -    if (drv->bdrv_getlength) {
>> -        bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
>> -    }
>> +    bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
>
> Does this hunk make a difference? If drv->bdrv_getlength == NULL, we'll
> just get back the current value.

The if statement could be left as is.  I removed it to reduce the
number of places where if (drv->bdrv_getlength) is explicitly checked.
 If callers don't know the internals of bdrv_getlength() then it is
easier to extend it without auditing and changing callers.

Having said that, I did add an if (drv->bdrv_getlength) check into
bdrv_truncate...

> But now that you sent this hunk for review, one thing about the existing
> code: We should probably check the return value of bdrv_getlength.

You're right.

I'll clean this up and send a v2.

Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]