qemu-patch-raspberry4/include/block
Kevin Wolf b94a261057 block: Avoid unecessary drv->bdrv_getlength() calls
The block layer generally keeps the size of an image cached in
bs->total_sectors so that it doesn't have to perform expensive
operations to get the size whenever it needs it.

This doesn't work however when using a backend that can change its size
without qemu being aware of it, i.e. passthrough of removable media like
CD-ROMs or floppy disks. For this reason, the caching is disabled when a
removable device is used.

It is obvious that checking whether the _guest_ device has removable
media isn't the right thing to do when we want to know whether the size
of the host backend can change. To make things worse, non-top-level
BlockDriverStates never have any device attached, which makes qemu
assume they are removable, so drv->bdrv_getlength() is always called on
the protocol layer. In the case of raw-posix, this causes unnecessary
lseek() system calls, which turned out to be rather expensive.

This patch completely changes the logic and disables bs->total_sectors
caching only for certain block driver types, for which a size change is
expected: host_cdrom and host_floppy on POSIX, host_device on win32; also
the raw format in case it sits on top of one of these protocols, but in
the common case the nested bdrv_getlength() call on the protocol driver
will use the cache again and avoid an expensive drv->bdrv_getlength()
call.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
2013-10-29 13:10:26 +01:00
..
aio.h aio / timers: Add aio_timer_init & aio_timer_new wrappers 2013-08-22 19:10:28 +02:00
block.h block: Add BlockDriver.bdrv_check_ext_snapshot. 2013-10-11 16:49:59 +02:00
block_int.h block: Avoid unecessary drv->bdrv_getlength() calls 2013-10-29 13:10:26 +01:00
blockjob.h qapi: make use of new BlockJobType 2013-10-11 10:52:54 +02:00
coroutine.h aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API 2013-08-22 19:14:24 +02:00
coroutine_int.h coroutine: stop using AioContext in CoQueue 2013-05-24 16:17:56 +02:00
nbd.h nbd: support large NBD requests 2013-05-03 13:05:49 +02:00
qapi.h block/qapi: Human-readable ImageInfoSpecific dump 2013-10-11 10:52:54 +02:00
scsi.h hw: move headers to include/ 2013-04-08 18:13:10 +02:00
snapshot.h snapshot: distinguish id and name in snapshot delete 2013-09-12 10:12:47 +02:00
thread-pool.h threadpool: drop global thread pool 2013-03-15 16:07:51 +01:00