From f91368e8fecd8845f627831b5c44116a2386c07e Mon Sep 17 00:00:00 2001 From: James DeFelice Date: Fri, 28 Jun 2019 17:12:39 +0000 Subject: [PATCH] csilvm: scrub first 512 blocks prior to mkfs mkfs subprograms (like mkfs.xfs) may run libblkid probes to avoid unintentionally overwriting pre-existing filesystems. csilvm has its own built-in detection for this. mkfs probe misfires cause intermittent problems at runtime and so this patch seeks to alleviate that by zeroing the first 512 sectors (256k) of the device. --- pkg/csilvm/server.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/csilvm/server.go b/pkg/csilvm/server.go index c8a2f8dd..ec37a1f4 100644 --- a/pkg/csilvm/server.go +++ b/pkg/csilvm/server.go @@ -1260,9 +1260,16 @@ func determineFilesystemType(devicePath string) (string, error) { } func formatDevice(devicePath, fstype string) error { - output, err := exec.Command("mkfs", "-t", fstype, devicePath).CombinedOutput() - if err != nil { - return errors.New("csilvm: formatDevice: " + string(output)) + // scrub the first 256k of the device to head off any mkfs probe misfires. + output, err := exec.Command( + "dd", "if=/dev/zero", "of="+devicePath, "bs=512", "count=512", "conv=notrunc", + ).CombinedOutput() + + if err == nil { + output, err = exec.Command("mkfs", "-t", fstype, devicePath).CombinedOutput() + if err != nil { + return errors.New("csilvm: formatDevice: " + string(output)) + } } return nil }