qcow2: adjust qcow2_co_flush_to_os -> qcow2_co_flush_to_disk
PATCH 1/1 qcow2: adjust qcow2_co_flush_to_os -> qcow2_co_flush_to_disk
From: Zhi Yong Wu <[email protected]>
qcow2_co_flush_to_os() actually flush all cached data to the disk. To keep its name consistent with its actual function, adjust its name accordingly.
--- block/qcow2.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
block/qcow2.c +2 -2
@@ -1435,7 +1435,7 @@ fail:return ret; } -static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs) +static coroutine_fn int qcow2_co_flush_to_disk(BlockDriverState *bs) {BDRVQcowState *s = bs->opaque;int ret;
@@ -1580,7 +1580,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_co_readv = qcow2_co_readv, .bdrv_co_writev = qcow2_co_writev, - .bdrv_co_flush_to_os = qcow2_co_flush_to_os, + .bdrv_co_flush_to_disk = qcow2_co_flush_to_disk, .bdrv_co_write_zeroes = qcow2_co_write_zeroes, .bdrv_co_discard = qcow2_co_discard,
Signature · 1 line
1.7.6
Am 14.05.2012 15:51, schrieb [email protected]:
Quoted 5 lines
From: Zhi Yong Wu <[email protected]>
qcow2_co_flush_to_os()actually flush all cached data to the disk. To keep its name consistent with its actual function, adjust its name accordingly.Signed-off-by Zhi Yong Wu <[email protected]>
This patch is plain wrong.
You're aware that you're not changing a name, but functionality here? Have a look at block_int.h for the semantics of each function:
/*
* Flushes all data that was already written to the OS all the way
down to
* the disk (for example raw-posix calls fsync()).
*/
int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs);
/*
* Flushes all internal caches to the OS. The data may still sit in a
* writeback cache of the host OS, but it will survive a crash of
the qemu
* process.
*/
int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs);Apart from that, it's not even intentional that qcow2 does a bdrv_flush() even if it didn't write out any cache entries. If we optimise the cache code a bit, this might disappear in the future.
Kevin
Quoted 10 lines · Kevin Wolf
Am 14.05.2012 15:51, schrieb [email protected]:
Quoted 5 lines
From: Zhi Yong Wu <[email protected]>
qcow2_co_flush_to_os()actually flush all cached data to the disk. To keep its name consistent with its actual function, adjust its name accordingly.Signed-off-by Zhi Yong Wu <[email protected]>This patch is plain wrong.
You're aware that you're not changing a name, but functionality here?
Sure, i know this.
Quoted 17 lines
Have a look at
block_int.hfor the semantics of each function:/*
* Flushes all data that was already written to the OS all the way down to
* the disk (for example raw-posix callsfsync()).
*/
intcoroutine_fn(*bdrv_co_flush_to_disk)(BlockDriverState *bs);/*
* Flushes all internal caches to the OS. The data may still sit in a
* writeback cache of the host OS, but it will survive a crash of the qemu
* process.
*/
intcoroutine_fn(*bdrv_co_flush_to_os)(BlockDriverState *bs);
Quoted 2 lines
Apart from that, it's not even intentional that qcow2 does a
bdrv_flush()even if it didn't write out any cache entries. If we
Since bdrv_flush() is invoked now, qcow2_co_flush_to_os() is not strictly alligned to its expected semantics, but the semantics of 'int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs)', so i suggested adjusting its name.
Quoted 1 line
optimise the cache code a bit, this might disappear in the future.
You mean that bdrv_flush() will be not invoked here in the future?
Quoted 2 lines
Kevin
Signature · 3 lines
Regards, Zhi Yong Wu
Am 14.05.2012 16:27, schrieb Zhi Yong Wu:
Quoted 30 lines · Kevin Wolf
Quoted 10 lines
Am 14.05.2012 15:51, schrieb [email protected]:
Quoted 5 lines
From: Zhi Yong Wu <[email protected]>
qcow2_co_flush_to_os()actually flush all cached data to the disk. To keep its name consistent with its actual function, adjust its name accordingly.Signed-off-by Zhi Yong Wu <[email protected]>This patch is plain wrong.
You're aware that you're not changing a name, but functionality here?
Sure, i know this.
Quoted 17 lines
Have a look at
block_int.hfor the semantics of each function:/*
* Flushes all data that was already written to the OS all the way
down to
* the disk (for example raw-posix callsfsync()).
*/
intcoroutine_fn(*bdrv_co_flush_to_disk)(BlockDriverState *bs);/*
* Flushes all internal caches to the OS. The data may still sit in a
* writeback cache of the host OS, but it will survive a crash of
the qemu
* process.
*/
intcoroutine_fn(*bdrv_co_flush_to_os)(BlockDriverState *bs);
Quoted 6 lines
Quoted 2 lines
Apart from that, it's not even intentional that qcow2 does a
bdrv_flush()even if it didn't write out any cache entries. If weSince
bdrv_flush()is invoked now,qcow2_co_flush_to_os()is not strictly alligned to its expected semantics, but the semantics of 'intcoroutine_fn(*bdrv_co_flush_to_disk)(BlockDriverState *bs)', so i suggested adjusting its name.
Let me put it another way: When bdrv_co_flush_to_os() has been called, the promise is that the block driver has no more dirty caches inside qemu. You can SIGKILL qemu and the data would survive. If there is no bdrv_co_flush_to_os(), this means that the driver doesn't have any data that must be flushed.
Now you remove the bdrv_co_flush_to_os() callback, so qcow2 may still have dirty caches even though we promised that there are none. The result of this can be data loss.
In contrast, bdrv_co_flush_to_disk() doesn't promise to flush dirty cached to the OS. It merely says that anything that is already flushed to the OS will be written out to disk. This works without any code in qcow2, it's only raw-posix.c that has to do something for this function to work.
Quoted 2 lines
Quoted 1 line
optimise the cache code a bit, this might disappear in the future.
You mean that
bdrv_flush()will be not invoked here in the future?
Yes, possibly. It's not really required in this case, though it is in some other code paths. With some refactoring we can probably drop it in this case.
Kevin
Quoted 38 lines · Kevin Wolf
Am 14.05.2012 16:27, schrieb Zhi Yong Wu:
Quoted 30 lines · Kevin Wolf
Quoted 10 lines
Am 14.05.2012 15:51, schrieb [email protected]:
Quoted 5 lines
From: Zhi Yong Wu <[email protected]>
qcow2_co_flush_to_os()actually flush all cached data to the disk. To keep its name consistent with its actual function, adjust its name accordingly.Signed-off-by Zhi Yong Wu <[email protected]>This patch is plain wrong.
You're aware that you're not changing a name, but functionality here?
Sure, i know this.
Quoted 17 lines
Have a look at
block_int.hfor the semantics of each function:/*
* Flushes all data that was already written to the OS all the way down to
* the disk (for example raw-posix callsfsync()).
*/
intcoroutine_fn(*bdrv_co_flush_to_disk)(BlockDriverState *bs);/*
* Flushes all internal caches to the OS. The data may still sit in a
* writeback cache of the host OS, but it will survive a crash of the qemu
* process.
*/
intcoroutine_fn(*bdrv_co_flush_to_os)(BlockDriverState *bs);Quoted 6 lines
Quoted 2 lines
Apart from that, it's not even intentional that qcow2 does a
bdrv_flush()even if it didn't write out any cache entries. If weSince
bdrv_flush()is invoked now,qcow2_co_flush_to_os()is not strictly alligned to its expected semantics, but the semantics of 'intcoroutine_fn(*bdrv_co_flush_to_disk)(BlockDriverState *bs)', so i suggested adjusting its name.
Quoted 5 lines
Let me put it another way: When
bdrv_co_flush_to_os()has been called, the promise is that the block driver has no more dirty caches inside qemu. You can SIGKILL qemu and the data would survive. If there is nobdrv_co_flush_to_os(), this means that the driver doesn't have any data that must be flushed.
OK, it is the intention.
Quoted 4 lines
Now you remove the
bdrv_co_flush_to_os()callback, so qcow2 may still have dirty caches even though we promised that there are none. The result of this can be data loss.
Yeah, maybe.
Quoted 6 lines
In contrast,
bdrv_co_flush_to_disk()doesn't promise to flush dirty cached to the OS. It merely says that anything that is already flushed to the OS will be written out to disk. This works without any code in qcow2, it's onlyraw-posix.cthat has to do something for this function to work.
Got it. thanks
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
optimise the cache code a bit, this might disappear in the future.
You mean that
bdrv_flush()will be not invoked here in the future?Yes, possibly. It's not really required in this case, though it is in some other code paths. With some refactoring we can probably drop it in this case.
OK.
Anyway, thanks for your explain, please ignore this patch.
Quoted 2 lines
Kevin
Signature · 3 lines
Regards, Zhi Yong Wu