Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolkit: Add missing flock calls. #10804

Open
wants to merge 1 commit into
base: 3.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 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(partDevPath, partition)
partFsType, err := formatSinglePartition(diskDevPath, 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 @@ -782,12 +782,13 @@ func setGptPartitionType(partition configuration.Partition, timeoutInSeconds, di
return
}

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

fsType = partition.FsType
Expand All @@ -803,12 +804,12 @@ func FormatSinglePartition(partDevPath string, partition configuration.Partition
fsType = "vfat"
}

mkfsArgs := []string{"-t", fsType}
mkfsArgs := []string{"--timeout", timeoutInSeconds, diskDevPath, "mkfs", "-t", fsType}
cwize1 marked this conversation as resolved.
Show resolved Hide resolved
mkfsArgs = append(mkfsArgs, mkfsOptions...)
mkfsArgs = append(mkfsArgs, partDevPath)

err = retry.Run(func() error {
_, stderr, err := shell.Execute("mkfs", mkfsArgs...)
_, stderr, err := shell.Execute("flock", mkfsArgs...)
if err != nil {
logger.Log.Warnf("Failed to format partition using mkfs: %v", stderr)
cwize1 marked this conversation as resolved.
Show resolved Hide resolved
return err
Expand Down
8 changes: 5 additions & 3 deletions toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
}

// Shrink the file system with resize2fs -M
stdout, stderr, err := shell.Execute("resize2fs", "-M", partitionLoopDevice)
stdout, stderr, err := shell.Execute("flock", "--timeout", "5", imageLoopDevice,
cwize1 marked this conversation as resolved.
Show resolved Hide resolved
"resize2fs", "-M", partitionLoopDevice)
if err != nil {
return fmt.Errorf("failed to resize %s with resize2fs:\n%v", partitionLoopDevice, stderr)
}
Expand All @@ -103,8 +104,9 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi
}

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