(ctx context.Context, inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration)
| 545 | } |
| 546 | |
| 547 | func attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration) error { |
| 548 | diskPath := filepath.Join(inst.Dir, filenames.Disk) |
| 549 | isoPath := filepath.Join(inst.Dir, filenames.ISO) |
| 550 | ciDataPath := filepath.Join(inst.Dir, filenames.CIDataISO) |
| 551 | var configurations []vz.StorageDeviceConfiguration |
| 552 | |
| 553 | if osutil.FileExists(diskPath) { |
| 554 | if err := validateDiskFormat(diskPath); err != nil { |
| 555 | return err |
| 556 | } |
| 557 | diskAttachment, err := vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync(diskPath, false, diskImageCachingMode, vz.DiskImageSynchronizationModeFsync) |
| 558 | if err != nil { |
| 559 | return err |
| 560 | } |
| 561 | diskDev, err := vz.NewVirtioBlockDeviceConfiguration(diskAttachment) |
| 562 | if err != nil { |
| 563 | return err |
| 564 | } |
| 565 | configurations = append(configurations, diskDev) |
| 566 | } |
| 567 | if osutil.FileExists(isoPath) { |
| 568 | if err := validateDiskFormat(isoPath); err != nil { |
| 569 | return err |
| 570 | } |
| 571 | isoAttachment, err := vz.NewDiskImageStorageDeviceAttachment(isoPath, true) |
| 572 | if err != nil { |
| 573 | return err |
| 574 | } |
| 575 | isoDev, err := vz.NewUSBMassStorageDeviceConfiguration(isoAttachment) |
| 576 | if err != nil { |
| 577 | return err |
| 578 | } |
| 579 | configurations = append(configurations, isoDev) |
| 580 | } |
| 581 | |
| 582 | diskUtil := proxyimgutil.NewDiskUtil(ctx) |
| 583 | |
| 584 | for _, d := range inst.Config.AdditionalDisks { |
| 585 | diskName := d.Name |
| 586 | disk, err := store.InspectDisk(diskName, d.FSType) |
| 587 | if err != nil { |
| 588 | return fmt.Errorf("failed to run load disk %#q: %w", diskName, err) |
| 589 | } |
| 590 | |
| 591 | logrus.Infof("Mounting disk %#q on %#q", diskName, disk.MountPoint) |
| 592 | if err = disk.LockForInstance(inst.Dir); err != nil { |
| 593 | return fmt.Errorf("failed to attach disk %#q: %w", diskName, err) |
| 594 | } |
| 595 | extraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk) |
| 596 | // ConvertToRaw is a NOP if no conversion is needed |
| 597 | logrus.Debugf("Converting extra disk %#q to a raw disk (if it is not a raw)", extraDiskPath) |
| 598 | |
| 599 | if err = diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); err != nil { |
| 600 | return fmt.Errorf("failed to convert extra disk %#q to a raw disk: %w", extraDiskPath, err) |
| 601 | } |
| 602 | extraDiskPathAttachment, err := vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync(extraDiskPath, false, diskImageCachingMode, vz.DiskImageSynchronizationModeFsync) |
| 603 | if err != nil { |
| 604 | return fmt.Errorf("failed to create disk attachment for extra disk %#q: %w", extraDiskPath, err) |
no test coverage detected