From b324040f0f87d2c4c891a8062fbac7bbe85dbef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Fri, 28 Jan 2022 11:43:32 +0100 Subject: [PATCH] Prevent ext[234] filesystems corruption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some underlying device driver, e.g. the UML UBD driver, may manage holes incorrectly which will prevent to retrieve all usefull zero ranges in filesystem, e.g. when using 'bmaptool create' Assigning UNIX_IO_NOZEROOUT environment variable prevent mkfs.ext[234] utilities to create zero range spaces using fallocate with FALLOC_FL_ZERO_RANGE or FALLOC_FL_PUNCH_HOLE Signed-off-by: Frédéric Danis --- actions/image_partition_action.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index 442168bd..be160009 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -350,6 +350,19 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC cmdline = append(cmdline, path) cmd := debos.Command{} + + /* Some underlying device driver, e.g. the UML UBD driver, may manage holes + * incorrectly which will prevent to retrieve all usefull zero ranges in + * filesystem, e.g. when using 'bmaptool create', see patch + * http://lists.infradead.org/pipermail/linux-um/2022-January/002074.html + * + * Adding UNIX_IO_NOZEROOUT environment variable prevent mkfs.ext[234] + * utilities to create zero range spaces using fallocate with + * FALLOC_FL_ZERO_RANGE or FALLOC_FL_PUNCH_HOLE */ + if p.FS == "ext2" || p.FS == "ext3" || p.FS == "ext4" { + cmd.AddEnv("UNIX_IO_NOZEROOUT=1") + } + if err := cmd.Run(label, cmdline...); err != nil { return err }