qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] How to discard one range which overlap with backing file and its children img?
@ 2018-08-07  7:06 lampahome
  2018-08-07 12:34 ` Kevin Wolf
  0 siblings, 1 reply; 3+ messages in thread
From: lampahome @ 2018-08-07  7:06 UTC (permalink / raw)
  To: QEMU Developers

I have image A & B, and A is backing file of B.

After I mount A to /dev/nbd0 and I write from position 0~999 in nbd0.

Then create B and set A as backing file of B.

I mount B on /dev/nbd1 and I can saw the data from pos:0~999 because A is
B's backing file. That's reasonable.


But I want to discard range 0~500 in B. I expect there's no data in 0~500
after discard and re-mount B next time.

But the data is still in A.

How can I discard range 0~500?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] How to discard one range which overlap with backing file and its children img?
  2018-08-07  7:06 [Qemu-devel] How to discard one range which overlap with backing file and its children img? lampahome
@ 2018-08-07 12:34 ` Kevin Wolf
  2018-08-07 14:02   ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Wolf @ 2018-08-07 12:34 UTC (permalink / raw)
  To: lampahome; +Cc: QEMU Developers

Am 07.08.2018 um 09:06 hat lampahome geschrieben:
> I have image A & B, and A is backing file of B.
> 
> After I mount A to /dev/nbd0 and I write from position 0~999 in nbd0.
> 
> Then create B and set A as backing file of B.
> 
> I mount B on /dev/nbd1 and I can saw the data from pos:0~999 because A is
> B's backing file. That's reasonable.
> 
> 
> But I want to discard range 0~500 in B. I expect there's no data in 0~500
> after discard and re-mount B next time.
> 
> But the data is still in A.
> 
> How can I discard range 0~500?

Note that discard simply means that you don't care about the content any
more. This doesn't guarantee that the old data can't be read any more.
If you want to make the data invisible, you need a zero write operation
instead. For a Linux guest, have a look at the "fallocate -z" command
line tool.

Kevin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] How to discard one range which overlap with backing file and its children img?
  2018-08-07 12:34 ` Kevin Wolf
@ 2018-08-07 14:02   ` Eric Blake
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Blake @ 2018-08-07 14:02 UTC (permalink / raw)
  To: Kevin Wolf, lampahome; +Cc: QEMU Developers

On 08/07/2018 07:34 AM, Kevin Wolf wrote:
> Am 07.08.2018 um 09:06 hat lampahome geschrieben:
>> I have image A & B, and A is backing file of B.
>>
>> After I mount A to /dev/nbd0 and I write from position 0~999 in nbd0.
>>
>> Then create B and set A as backing file of B.
>>
>> I mount B on /dev/nbd1 and I can saw the data from pos:0~999 because A is
>> B's backing file. That's reasonable.
>>
>>
>> But I want to discard range 0~500 in B. I expect there's no data in 0~500
>> after discard and re-mount B next time.
>>
>> But the data is still in A.
>>
>> How can I discard range 0~500?
> 
> Note that discard simply means that you don't care about the content any
> more. This doesn't guarantee that the old data can't be read any more.
> If you want to make the data invisible, you need a zero write operation
> instead. For a Linux guest, have a look at the "fallocate -z" command
> line tool.

What's more, once you make A the backing file to B, then all actions you 
perform through qemu operate only on B (A is treated as read-only).  So, 
writing zeroes (or discarding) changes the contents of B, but does NOT 
change the content of A.

Furthermore, both discard and write zeroes tend to have alignment 
constraints. If you are actually working on bytes 0-999 (which is 
unaligned to sector boundaries of 512, let alone qcow2 cluster 
boundaries that default to 64k but can be even larger), the discard is 
likely to be a no-op (since discard tends to be a no-op if it does not 
meet larger alignment boundaries), while the write zeroes will work but 
will result in a slower read-modify-write if it is targetting a block 
device.  If you are instead working on sectors 0-999 (bytes 0-511999), 
you have more of a chance of seeing discard in action, as well as write 
zeroes being more efficient.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-07 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-07  7:06 [Qemu-devel] How to discard one range which overlap with backing file and its children img? lampahome
2018-08-07 12:34 ` Kevin Wolf
2018-08-07 14:02   ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).