Skip to content

Commit

Permalink
Revert "Toolkit: Add missing flock calls. (#10804)"
Browse files Browse the repository at this point in the history
This reverts commit e4e12d0.
  • Loading branch information
cwize1 committed Nov 1, 2024
1 parent 977ae86 commit 3853fbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 8 additions & 9 deletions toolkit/tools/imagegen/diskutils/diskutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func CreatePartitions(diskDevPath string, disk configuration.Disk, rootEncryptio
return partDevPathMap, partIDToFsTypeMap, encryptedRoot, readOnlyRoot, err
}

partFsType, err := formatSinglePartition(diskDevPath, partDevPath, partition)
partFsType, err := FormatSinglePartition(partDevPath, partition)
if err != nil {
err = fmt.Errorf("failed to format partition:\n%w", err)
return partDevPathMap, partIDToFsTypeMap, encryptedRoot, readOnlyRoot, err
Expand Down Expand Up @@ -792,13 +792,12 @@ func setGptPartitionType(partition configuration.Partition, timeoutInSeconds, di
return
}

// formatSinglePartition formats the given partition to the type specified in the partition configuration
func formatSinglePartition(diskDevPath string, partDevPath string, partition configuration.Partition,
// FormatSinglePartition formats the given partition to the type specified in the partition configuration
func FormatSinglePartition(partDevPath string, partition configuration.Partition,
) (fsType string, err error) {
const (
totalAttempts = 5
retryDuration = time.Second
timeoutInSeconds = "5"
totalAttempts = 5
retryDuration = time.Second
)

fsType = partition.FsType
Expand All @@ -814,14 +813,14 @@ func formatSinglePartition(diskDevPath string, partDevPath string, partition con
fsType = "vfat"
}

mkfsArgs := []string{"--timeout", timeoutInSeconds, diskDevPath, "mkfs", "-t", fsType}
mkfsArgs := []string{"-t", fsType}
mkfsArgs = append(mkfsArgs, mkfsOptions...)
mkfsArgs = append(mkfsArgs, partDevPath)

err = retry.Run(func() error {
_, stderr, err := shell.Execute("flock", mkfsArgs...)
_, stderr, err := shell.Execute("mkfs", mkfsArgs...)
if err != nil {
logger.Log.Warnf("Failed to format partition using mkfs (and flock): %v", stderr)
logger.Log.Warnf("Failed to format partition using mkfs: %v", stderr)
return err
}

Expand Down
12 changes: 5 additions & 7 deletions toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func shrinkFilesystems(imageLoopDevice string, verity []imagecustomizerapi.Verit
}

// Shrink the file system with resize2fs -M
stdout, stderr, err := shell.Execute("flock", "--timeout", "5", imageLoopDevice,
"resize2fs", "-M", partitionLoopDevice)
stdout, stderr, err := shell.Execute("resize2fs", "-M", partitionLoopDevice)
if err != nil {
return fmt.Errorf("failed to resize %s with resize2fs (and flock):\n%v", partitionLoopDevice, stderr)
return fmt.Errorf("failed to resize %s with resize2fs:\n%v", partitionLoopDevice, stderr)
}

// Find the new partition end value
Expand All @@ -100,11 +99,10 @@ func shrinkFilesystems(imageLoopDevice string, verity []imagecustomizerapi.Verit
}

// Resize the partition with parted resizepart
_, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "flock", "--timeout", "5", imageLoopDevice,
"parted", "---pretend-input-tty", imageLoopDevice, "resizepart",
strconv.Itoa(partitionNumber), end)
_, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "parted", "---pretend-input-tty",
imageLoopDevice, "resizepart", strconv.Itoa(partitionNumber), end)
if err != nil {
return fmt.Errorf("failed to resizepart %s with parted (and flock):\n%v", partitionLoopDevice, stderr)
return fmt.Errorf("failed to resizepart %s with parted:\n%v", partitionLoopDevice, stderr)
}

// Re-read the partition table
Expand Down

0 comments on commit 3853fbd

Please sign in to comment.