Repository navigation
Commit 5e64472
committed
btrfs-progs: enhance device preparation for discard=ignore cases
[BUG]
For qemu/KVM guests where the storage has 'discard=ignore' set,
mkfs.btrfs won't properly wipe out any existing super blocks from other
filesystems:
# mkfs.ext4 -F /dev/vdc
# mkfs.btrfs -f /dev/vdc
# wipefs /dev/vdc
DEVICE OFFSET TYPE UUID LABEL
vdc 0x438 ext4 19b84ba1-e783-406d-a2f0-269aca433892
vdc 0x10040 btrfs 8ab186d0-9f11-4132-a815-5397b99fcd1f
Note that the ext4 super block is still there.
[CAUSE]
With 'discard=ignore' setting, the discard operation is accepted but no
data will be wiped out.
Furthermore, mkfs.btrfs do the zero write before discard, but that zero
write itself is buffered write, and discard will drop any page cache of
the block device, so such zero write never reaches the storage.
[FIX]
Fix the problem and hardening the data wipe out by:
- Re-order the device preparation
Instead of zero-write then discard, change it to discard then
zero-write.
So even if discard did nothing, the zero writes won't be discarded.
- Use BLKZEROOUT ioctl when possible
This ioctl will ensure the content is zeroed out.
If the device supports WRITE_ZEROS and can do it cheaply, this will
not take up extra space.
Although this ioctl is only supported on block device.
So the zero-buffered write is still needed as a fallback
- Sync after the zero writes
Although the zero writes are already after discard, be extra safe to
make sure the zeros reach the storage.
Issue: #1198
Signed-off-by: Qu Wenruo <wqu@suse.com>1 parent 2b80ee1 commit 5e64472
1 file changed
Lines changed: 32 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
| |||
135 | 148 | | |
136 | 149 | | |
137 | 150 | | |
| 151 | + | |
138 | 152 | | |
139 | 153 | | |
140 | 154 | | |
| |||
148 | 162 | | |
149 | 163 | | |
150 | 164 | | |
151 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
152 | 176 | | |
153 | 177 | | |
154 | 178 | | |
| |||
279 | 303 | | |
280 | 304 | | |
281 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
282 | 313 | | |
283 | 314 | | |
284 | 315 | | |
| |||
293 | 324 | | |
294 | 325 | | |
295 | 326 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | 327 | | |
300 | 328 | | |
301 | 329 | | |
| |||
0 commit comments