Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
csilvm: scrub first 512 blocks prior to mkfs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
James DeFelice authored and jdef committed Jun 28, 2019
1 parent 27f29dc commit f91368e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/csilvm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f91368e

Please sign in to comment.