EnsureUserDataDisk checks the current disk configuration and fixes it if needed.
()
| 31 | |
| 32 | // EnsureUserDataDisk checks the current disk configuration and fixes it if needed. |
| 33 | func (m *userDataDiskManager) EnsureUserDataDisk() error { |
| 34 | if m.limaDiskExists() { |
| 35 | diskPath := m.finch.UserDataDiskPath(m.rootDir) |
| 36 | |
| 37 | if *m.config.VMType == "vz" { |
| 38 | info, err := m.getDiskInfo(diskPath) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | |
| 43 | // Convert the persistent disk file to RAW before Lima starts. |
| 44 | // Lima also does this, but since Finch uses a symlink to this file, lima won't create the new RAW file |
| 45 | // in the persistent location, but in its own _disks directory. |
| 46 | if info.Format != "raw" { |
| 47 | if err := m.convertToRaw(diskPath); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | // since convertToRaw moves the disk, the symlink needs to be recreated |
| 52 | if err := m.attachPersistentDiskToLimaDisk(); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // if the file is not a symlink, loc will be an empty string |
| 59 | // both os.Readlink() and UserDataDiskPath return absolute paths, so they will be equal if equivalent |
| 60 | limaPath := fmt.Sprintf("%s/_disks/%s/datadisk", m.finch.LimaHomePath(), diskName) |
| 61 | loc, err := m.fs.ReadlinkIfPossible(limaPath) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | |
| 66 | if loc != diskPath { |
| 67 | if err := m.attachPersistentDiskToLimaDisk(); err != nil { |
| 68 | return err |
| 69 | } |
| 70 | } |
| 71 | } else { |
| 72 | if err := m.createLimaDisk(); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | if err := m.attachPersistentDiskToLimaDisk(); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if err := m.resizeDiskIfNeeded(); err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | if m.limaDiskIsLocked() { |
| 85 | err := m.unlockLimaDisk() |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | } |
| 90 |
nothing calls this directly
no test coverage detected