Skip to content

Commit ad8ac1c

Browse files
authored
Merge pull request #3524 from jonas-peter/diskinspect
removing qemu fallback for inspectDiskSize
2 parents 61bb7ef + 78274a8 commit ad8ac1c

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

pkg/store/disk.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"path/filepath"
1212

1313
"github.com/lima-vm/go-qcow2reader"
14-
"github.com/lima-vm/lima/pkg/qemu/imgutil"
1514
"github.com/lima-vm/lima/pkg/store/filenames"
1615
)
1716

@@ -61,35 +60,25 @@ func InspectDisk(diskName string) (*Disk, error) {
6160
return disk, nil
6261
}
6362

64-
// inspectDisk attempts to inspect the disk size and format by itself,
65-
// and falls back to inspectDiskWithQemuImg on an error.
63+
// inspectDisk attempts to inspect the disk size and format with qcow2reader.
6664
func inspectDisk(fName string) (size int64, format string, _ error) {
6765
f, err := os.Open(fName)
6866
if err != nil {
69-
return inspectDiskWithQemuImg(fName)
67+
return -1, "", err
7068
}
7169
defer f.Close()
7270
img, err := qcow2reader.Open(f)
7371
if err != nil {
74-
return inspectDiskWithQemuImg(fName)
72+
return -1, "", err
7573
}
7674
sz := img.Size()
7775
if sz < 0 {
78-
return inspectDiskWithQemuImg(fName)
76+
return -1, "", fmt.Errorf("cannot determine size of %q", fName)
7977
}
8078

8179
return sz, string(img.Type()), nil
8280
}
8381

84-
// inspectDiskSizeWithQemuImg invokes `qemu-img` binary to inspect the disk size and format.
85-
func inspectDiskWithQemuImg(fName string) (size int64, format string, _ error) {
86-
info, err := imgutil.GetInfo(fName)
87-
if err != nil {
88-
return -1, "", err
89-
}
90-
return info.VSize, info.Format, nil
91-
}
92-
9382
func (d *Disk) Lock(instanceDir string) error {
9483
inUseBy := filepath.Join(d.Dir, filenames.InUseBy)
9584
return os.Symlink(instanceDir, inUseBy)

0 commit comments

Comments
 (0)