Skip to content

Commit

Permalink
Use UnsafeSetFileOwnership on virt-launcher code
Browse files Browse the repository at this point in the history
When code is executed inside virt-launcher, no special path
considerations are necessary. This can be refactored later to remove the
`Unsafe` trigger from these code paths.

Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Jul 27, 2022
1 parent b465bff commit d7e01de
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/cloud-init/cloud-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func GenerateEmptyIso(vmiName string, namespace string, data *CloudInitData, siz
return err
}

if err := diskutils.DefaultOwnershipManager.SetFileOwnership(isoStaging); err != nil {
if err := diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(isoStaging); err != nil {
return err
}
err = os.Rename(isoStaging, iso)
Expand Down Expand Up @@ -655,7 +655,7 @@ func GenerateLocalData(vmi *v1.VirtualMachineInstance, instanceType string, data
return err
}

if err := diskutils.DefaultOwnershipManager.SetFileOwnership(isoStaging); err != nil {
if err := diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(isoStaging); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config-map.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CreateConfigMapDisks(vmi *v1.VirtualMachineInstance, emptyIso bool) error {
return err
}

if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(disk); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(disk); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/downwardapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CreateDownwardAPIDisks(vmi *v1.VirtualMachineInstance, emptyIso bool) error
return err
}

if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(disk); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(disk); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CreateSecretDisks(vmi *v1.VirtualMachineInstance, emptyIso bool) error {
return err
}

if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(disk); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(disk); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/service-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func CreateServiceAccountDisk(vmi *v1.VirtualMachineInstance, emptyIso bool) err
return err
}

if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(disk); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(disk); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/sysprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func createIsoImageAndSetFileOwnership(volumeName string, filesPath []string, si
if err := createIsoConfigImage(disk, sysprepVolumeLabel, filesPath, size); err != nil {
return err
}
if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(disk); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(disk); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/emptydisk/emptydisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *emptyDiskCreator) CreateTemporaryDisks(vmi *v1.VirtualMachineInstance)
} else if err != nil {
return err
}
if err := ephemeraldiskutils.DefaultOwnershipManager.SetFileOwnership(file); err != nil {
if err := ephemeraldiskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(file); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func writeToCachedFile(fs cacheFS, obj interface{}, fileName string) error {
if err != nil {
return fmt.Errorf("error writing cached object: %v", err)
}
return dutils.DefaultOwnershipManager.SetFileOwnership(fileName)
return dutils.DefaultOwnershipManager.UnsafeSetFileOwnership(fileName)
}

func readFromCachedFile(fs cacheFS, obj interface{}, fileName string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-handler/migration-proxy/migration-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (m *migrationProxy) createUnixListener() error {
m.logger.Reason(err).Error("failed to create unix socket for proxy service")
return err
}
if err := diskutils.DefaultOwnershipManager.SetFileOwnership(m.unixSocketPath); err != nil {
if err := diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(m.unixSocketPath); err != nil {
log.Log.Reason(err).Error("failed to change ownership on migration unix socket")
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/virt-launcher/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func InitializePrivateDirectories(baseDir string) error {
if err := util.MkdirAllWithNosec(baseDir); err != nil {
return err
}
if err := diskutils.DefaultOwnershipManager.SetFileOwnership(baseDir); err != nil {
if err := diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(baseDir); err != nil {
return err
}
return nil
Expand All @@ -75,7 +75,7 @@ func InitializeDisksDirectories(baseDir string) error {
if err != nil {
return err
}
err = diskutils.DefaultOwnershipManager.SetFileOwnership(baseDir)
err = diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(baseDir)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/live-migration-target.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (l *LibvirtDomainManager) prepareMigrationTarget(
logger.Reason(err).Error("failed to create the migration sockets directory")
return err
}
if err := diskutils.DefaultOwnershipManager.SetFileOwnership(migrationSocketsPath); err != nil {
if err := diskutils.DefaultOwnershipManager.UnsafeSetFileOwnership(migrationSocketsPath); err != nil {
logger.Reason(err).Error("failed to change ownership on migration sockets directory")
return err
}
Expand Down

0 comments on commit d7e01de

Please sign in to comment.