Repository: lima-vm/lima
Pull request #2161 (2024-01-24 07:30:16)

fix state when create disk fails
**User story:**
lima is built from source code. qemu not installed.

The user wants to run some vm with an additional disk:
```
$ limactl disk create --size=1G --format=qcow2 test
INFO[0000] Creating qcow2 disk "test" with size 1GiB
FATA[0000] Failed to create qcow2 disk in "/Users/testuser/.lima/_disks/test"
```
There are no details about qemu-img in the log. Let's assume he guessed the reason and installed the qemu package.

Now any actions with this disk will result in an error.:
```
$ limactl disk create --size=1G --format=qcow2 test
FATA[0000] disk "test" already exists ("/Users/testuser/.lima/_disks/test")
$ limactl disk rm test
WARN[0000] Ignoring non-existent disk "test"
```
Manual removing the directory helps, but it's not user friendly.

**PR:**
 - remove created directory if disk creation error occurs
 - add child error to error message 


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 366ba4ca..19eab934 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -64,7 +64,7 @@ linters:
   # - maligned
   # - nestif
   # - nlreturn
-  - noctx
+  # - noctx
   - nolintlint
   # - rowserrcheck
   # - scopelint
diff --git a/cmd/limactl/completion.go b/cmd/limactl/completion.go
index 54d42ddf..3da038c1 100644
--- a/cmd/limactl/completion.go
+++ b/cmd/limactl/completion.go
@@ -23,11 +23,3 @@ func bashCompleteTemplateNames(_ *cobra.Command) ([]string, cobra.ShellCompDirec
 	}
 	return comp, cobra.ShellCompDirectiveDefault
 }
-
-func bashCompleteDiskNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
-	disks, err := store.Disks()
-	if err != nil {
-		return nil, cobra.ShellCompDirectiveDefault
-	}
-	return disks, cobra.ShellCompDirectiveNoFileComp
-}
diff --git a/cmd/limactl/disk.go b/cmd/limactl/disk.go
index 189b739f..fff762b5 100644
--- a/cmd/limactl/disk.go
+++ b/cmd/limactl/disk.go
@@ -101,7 +101,11 @@ func diskCreateAction(cmd *cobra.Command, args []string) error {
 	}
 
 	if err := qemu.CreateDataDisk(diskDir, format, int(diskSize)); err != nil {
-		return fmt.Errorf("Failed to create %s disk in %q", format, diskDir)
+		rerr := os.RemoveAll(diskDir)
+		if rerr != nil {
+			err = errors.Join(err, fmt.Errorf("failed to remove a directory %q: %w", diskDir, rerr))
+		}
+		return fmt.Errorf("Failed to create %s disk in %q: %w", format, diskDir, err)
 	}
 
 	return nil
@@ -203,11 +207,10 @@ $ limactl disk delete DISK
 To delete multiple disks:
 $ limactl disk delete DISK1 DISK2 ...
 `,
-		Aliases:           []string{"remove", "rm"},
-		Short:             "Delete one or more Lima disks",
-		Args:              WrapArgsError(cobra.MinimumNArgs(1)),
-		RunE:              diskDeleteAction,
-		ValidArgsFunction: diskBashComplete,
+		Aliases: []string{"remove", "rm"},
+		Short:   "Delete one or more Lima disks",
+		Args:    WrapArgsError(cobra.MinimumNArgs(1)),
+		RunE:    diskDeleteAction,
 	}
 	diskDeleteCommand.Flags().BoolP("force", "f", false, "force delete")
 	return diskDeleteCommand
@@ -295,10 +298,9 @@ $ limactl disk unlock DISK
 To unlock multiple disks:
 $ limactl disk unlock DISK1 DISK2 ...
 `,
-		Short:             "Unlock one or more Lima disks",
-		Args:              WrapArgsError(cobra.MinimumNArgs(1)),
-		RunE:              diskUnlockAction,
-		ValidArgsFunction: diskBashComplete,
+		Short: "Unlock one or more Lima disks",
+		Args:  WrapArgsError(cobra.MinimumNArgs(1)),
+		RunE:  diskUnlockAction,
 	}
 	return diskUnlockCommand
 }
@@ -344,10 +346,9 @@ func newDiskResizeCommand() *cobra.Command {
 		Example: `
 Resize a disk:
 $ limactl disk resize DISK --size SIZE`,
-		Short:             "Resize existing Lima disk",
-		Args:              WrapArgsError(cobra.ExactArgs(1)),
-		RunE:              diskResizeAction,
-		ValidArgsFunction: diskBashComplete,
+		Short: "Resize existing Lima disk",
+		Args:  WrapArgsError(cobra.ExactArgs(1)),
+		RunE:  diskResizeAction,
 	}
 	diskResizeCommand.Flags().String("size", "", "Disk size")
 	_ = diskResizeCommand.MarkFlagRequired("size")
@@ -393,7 +394,3 @@ func diskResizeAction(cmd *cobra.Command, args []string) error {
 	logrus.Infof("Resized disk %q (%q)", diskName, disk.Dir)
 	return nil
 }
-
-func diskBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
-	return bashCompleteDiskNames(cmd)
-}
diff --git a/cmd/limactl/start.go b/cmd/limactl/start.go
index 1eb0b561..e8614acc 100644
--- a/cmd/limactl/start.go
+++ b/cmd/limactl/start.go
@@ -146,11 +146,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
 			}
 		}
 		logrus.Debugf("interpreting argument %q as a http url for instance %q", arg, st.instName)
-		req, err := http.NewRequestWithContext(cmd.Context(), http.MethodGet, arg, http.NoBody)
-		if err != nil {
-			return nil, err
-		}
-		resp, err := http.DefaultClient.Do(req)
+		resp, err := http.Get(arg)
 		if err != nil {
 			return nil, err
 		}
diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go
index 016698d6..609263fb 100644
--- a/pkg/downloader/downloader.go
+++ b/pkg/downloader/downloader.go
@@ -2,7 +2,6 @@ package downloader
 
 import (
 	"bytes"
-	"context"
 	"crypto/sha256"
 	"errors"
 	"fmt"
@@ -16,7 +15,6 @@ import (
 
 	"github.com/cheggaaa/pb/v3"
 	"github.com/containerd/continuity/fs"
-	"github.com/lima-vm/lima/pkg/httpclientutil"
 	"github.com/lima-vm/lima/pkg/localpathutil"
 	"github.com/lima-vm/lima/pkg/progressbar"
 	"github.com/opencontainers/go-digest"
@@ -127,7 +125,7 @@ func WithExpectedDigest(expectedDigest digest.Digest) Opt {
 // (So, the local path cannot be set to /dev/null for "caching only" mode.)
 //
 // The local path can be an empty string for "caching only" mode.
-func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result, error) {
+func Download(local, remote string, opts ...Opt) (*Result, error) {
 	var o options
 	for _, f := range opts {
 		if err := f(&o); err != nil {
@@ -175,7 +173,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
 	}
 
 	if o.cacheDir == "" {
-		if err := downloadHTTP(ctx, localPath, remote, o.description, o.expectedDigest); err != nil {
+		if err := downloadHTTP(localPath, remote, o.description, o.expectedDigest); err != nil {
 			return nil, err
 		}
 		res := &Result{
@@ -224,7 +222,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
 	if err := os.WriteFile(shadURL, []byte(remote), 0o644); err != nil {
 		return nil, err
 	}
-	if err := downloadHTTP(ctx, shadData, remote, o.description, o.expectedDigest); err != nil {
+	if err := downloadHTTP(shadData, remote, o.description, o.expectedDigest); err != nil {
 		return nil, err
 	}
 	// no need to pass the digest to copyLocal(), as we already verified the digest
@@ -474,7 +472,7 @@ func validateLocalFileDigest(localPath string, expectedDigest digest.Digest) err
 	return nil
 }
 
-func downloadHTTP(ctx context.Context, localPath, url, description string, expectedDigest digest.Digest) error {
+func downloadHTTP(localPath, url, description string, expectedDigest digest.Digest) error {
 	if localPath == "" {
 		return fmt.Errorf("downloadHTTP: got empty localPath")
 	}
@@ -489,11 +487,14 @@ func downloadHTTP(ctx context.Context, localPath, url, description string, expec
 	}
 	defer fileWriter.Close()
 
-	resp, err := httpclientutil.Get(ctx, http.DefaultClient, url)
+	resp, err := http.Get(url)
 	if err != nil {
 		return err
 	}
 	defer resp.Body.Close()
+	if resp.StatusCode != http.StatusOK {
+		return fmt.Errorf("expected HTTP status %d, got %s", http.StatusOK, resp.Status)
+	}
 	bar, err := progressbar.New(resp.ContentLength)
 	if err != nil {
 		return err
diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go
index 086ca6e8..d6049c7f 100644
--- a/pkg/driver/driver.go
+++ b/pkg/driver/driver.go
@@ -26,7 +26,7 @@ type Driver interface {
 	Initialize(_ context.Context) error
 
 	// CreateDisk returns error if the current driver fails in creating disk
-	CreateDisk(_ context.Context) error
+	CreateDisk() error
 
 	// Start is used for booting the vm using driver instance
 	// It returns a chan error on successful boot
@@ -90,7 +90,7 @@ func (d *BaseDriver) Initialize(_ context.Context) error {
 	return nil
 }
 
-func (d *BaseDriver) CreateDisk(_ context.Context) error {
+func (d *BaseDriver) CreateDisk() error {
 	return nil
 }
 
diff --git a/pkg/fileutils/download.go b/pkg/fileutils/download.go
index 97bf6d30..07a9ece0 100644
--- a/pkg/fileutils/download.go
+++ b/pkg/fileutils/download.go
@@ -1,7 +1,6 @@
 package fileutils
 
 import (
-	"context"
 	"errors"
 	"fmt"
 	"path"
@@ -15,13 +14,13 @@ import (
 var ErrSkipped = errors.New("skipped to download")
 
 // DownloadFile downloads a file to the cache, optionally copying it to the destination. Returns path in cache.
-func DownloadFile(ctx context.Context, dest string, f limayaml.File, decompress bool, description string, expectedArch limayaml.Arch) (string, error) {
+func DownloadFile(dest string, f limayaml.File, decompress bool, description string, expectedArch limayaml.Arch) (string, error) {
 	if f.Arch != expectedArch {
 		return "", fmt.Errorf("%w: %q: unsupported arch: %q", ErrSkipped, f.Location, f.Arch)
 	}
 	fields := logrus.Fields{"location": f.Location, "arch": f.Arch, "digest": f.Digest}
 	logrus.WithFields(fields).Infof("Attempting to download %s", description)
-	res, err := downloader.Download(ctx, dest, f.Location,
+	res, err := downloader.Download(dest, f.Location,
 		downloader.WithCache(),
 		downloader.WithDecompress(decompress),
 		downloader.WithDescription(fmt.Sprintf("%s (%s)", description, path.Base(f.Location))),
diff --git a/pkg/networks/reconcile/reconcile.go b/pkg/networks/reconcile/reconcile.go
index 47b20c69..5f069326 100644
--- a/pkg/networks/reconcile/reconcile.go
+++ b/pkg/networks/reconcile/reconcile.go
@@ -54,7 +54,7 @@ func Reconcile(ctx context.Context, newInst string) error {
 		if activeNetwork[name] {
 			err = startNetwork(ctx, &config, name)
 		} else {
-			err = stopNetwork(ctx, &config, name)
+			err = stopNetwork(&config, name)
 		}
 		if err != nil {
 			return err
@@ -218,7 +218,7 @@ func startNetwork(ctx context.Context, config *networks.YAML, name string) error
 	return nil
 }
 
-func stopNetwork(ctx context.Context, config *networks.YAML, name string) error {
+func stopNetwork(config *networks.YAML, name string) error {
 	logrus.Debugf("Make sure %q network is stopped", name)
 	// Handle usernet first without sudo requirements
 	isUsernet, err := config.Usernet(name)
@@ -226,7 +226,7 @@ func stopNetwork(ctx context.Context, config *networks.YAML, name string) error
 		return err
 	}
 	if isUsernet {
-		if err := usernet.Stop(ctx, name); err != nil {
+		if err := usernet.Stop(name); err != nil {
 			return fmt.Errorf("failed to stop usernet %q: %w", name, err)
 		}
 		return nil
diff --git a/pkg/networks/usernet/client.go b/pkg/networks/usernet/client.go
index 695c9ca1..1036bd44 100644
--- a/pkg/networks/usernet/client.go
+++ b/pkg/networks/usernet/client.go
@@ -12,7 +12,6 @@ import (
 	gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client"
 	"github.com/containers/gvisor-tap-vsock/pkg/types"
 	"github.com/lima-vm/lima/pkg/driver"
-	"github.com/lima-vm/lima/pkg/httpclientutil"
 	"github.com/lima-vm/lima/pkg/limayaml"
 	"github.com/lima-vm/lima/pkg/networks/usernet/dnshosts"
 )
@@ -26,9 +25,9 @@ type Client struct {
 	subnet   net.IP
 }
 
-func (c *Client) ConfigureDriver(ctx context.Context, driver *driver.BaseDriver) error {
+func (c *Client) ConfigureDriver(driver *driver.BaseDriver) error {
 	macAddress := limayaml.MACAddress(driver.Instance.Dir)
-	ipAddress, err := c.ResolveIPAddress(ctx, macAddress)
+	ipAddress, err := c.ResolveIPAddress(macAddress)
 	if err != nil {
 		return err
 	}
@@ -73,7 +72,7 @@ func (c *Client) ResolveAndForwardSSH(ipAddr string, sshPort int) error {
 	return nil
 }
 
-func (c *Client) ResolveIPAddress(ctx context.Context, vmMacAddr string) (string, error) {
+func (c *Client) ResolveIPAddress(vmMacAddr string) (string, error) {
 	timeout := time.After(2 * time.Minute)
 	ticker := time.NewTicker(500 * time.Millisecond)
 	for {
@@ -81,7 +80,7 @@ func (c *Client) ResolveIPAddress(ctx context.Context, vmMacAddr string) (string
 		case <-timeout:
 			return "", errors.New("usernet unable to resolve IP for SSH forwarding")
 		case <-ticker.C:
-			leases, err := c.Leases(ctx)
+			leases, err := c.Leases()
 			if err != nil {
 				return "", err
 			}
@@ -95,13 +94,15 @@ func (c *Client) ResolveIPAddress(ctx context.Context, vmMacAddr string) (string
 	}
 }
 
-func (c *Client) Leases(ctx context.Context) (map[string]string, error) {
-	u := fmt.Sprintf("%s%s", c.base, "/services/dhcp/leases")
-	res, err := httpclientutil.Get(ctx, c.client, u)
+func (c *Client) Leases() (map[string]string, error) {
+	res, err := c.client.Get(fmt.Sprintf("%s%s", c.base, "/services/dhcp/leases"))
 	if err != nil {
 		return nil, err
 	}
 	defer res.Body.Close()
+	if res.StatusCode != http.StatusOK {
+		return nil, fmt.Errorf("unexpected status: %d", res.StatusCode)
+	}
 	dec := json.NewDecoder(res.Body)
 	var leases map[string]string
 	if err := dec.Decode(&leases); err != nil {
diff --git a/pkg/networks/usernet/recoincile.go b/pkg/networks/usernet/recoincile.go
index 0dca3ba7..d3fef01d 100644
--- a/pkg/networks/usernet/recoincile.go
+++ b/pkg/networks/usernet/recoincile.go
@@ -121,7 +121,7 @@ func Start(ctx context.Context, name string) error {
 
 // Stop stops running instance a usernet network with the given name.
 // The name parameter must point to a valid network configuration name under <LIMA_HOME>/_config/networks.yaml with `mode: user-v2`
-func Stop(ctx context.Context, name string) error {
+func Stop(name string) error {
 	logrus.Debugf("Make sure usernet network is stopped")
 	pidFile, err := PIDFile(name)
 	if err != nil {
@@ -132,7 +132,7 @@ func Stop(ctx context.Context, name string) error {
 	if pid != 0 {
 		logrus.Debugf("Stopping usernet daemon")
 
-		err = writeLeases(ctx, name)
+		err = writeLeases(name)
 		if err != nil {
 			return err
 		}
@@ -190,9 +190,9 @@ func readLeases(name string) (map[string]string, error) {
 	return leases, err
 }
 
-func writeLeases(ctx context.Context, nwName string) error {
+func writeLeases(nwName string) error {
 	client := NewClientByName(nwName)
-	leases, err := client.Leases(ctx)
+	leases, err := client.Leases()
 	if err != nil {
 		return err
 	}
diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go
index 0c7710a2..bd33df46 100644
--- a/pkg/qemu/qemu.go
+++ b/pkg/qemu/qemu.go
@@ -2,7 +2,6 @@ package qemu
 
 import (
 	"bytes"
-	"context"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -49,7 +48,7 @@ const (
 )
 
 // EnsureDisk also ensures the kernel and the initrd
-func EnsureDisk(ctx context.Context, cfg Config) error {
+func EnsureDisk(cfg Config) error {
 	diffDisk := filepath.Join(cfg.InstanceDir, filenames.DiffDisk)
 	if _, err := os.Stat(diffDisk); err == nil || !errors.Is(err, os.ErrNotExist) {
 		// disk is already ensured
@@ -64,12 +63,12 @@ func EnsureDisk(ctx context.Context, cfg Config) error {
 		var ensuredBaseDisk bool
 		errs := make([]error, len(cfg.LimaYAML.Images))
 		for i, f := range cfg.LimaYAML.Images {
-			if _, err := fileutils.DownloadFile(ctx, baseDisk, f.File, true, "the image", *cfg.LimaYAML.Arch); err != nil {
+			if _, err := fileutils.DownloadFile(baseDisk, f.File, true, "the image", *cfg.LimaYAML.Arch); err != nil {
 				errs[i] = err
 				continue
 			}
 			if f.Kernel != nil {
-				if _, err := fileutils.DownloadFile(ctx, kernel, f.Kernel.File, false, "the kernel", *cfg.LimaYAML.Arch); err != nil {
+				if _, err := fileutils.DownloadFile(kernel, f.Kernel.File, false, "the kernel", *cfg.LimaYAML.Arch); err != nil {
 					errs[i] = err
 					continue
 				}
@@ -81,7 +80,7 @@ func EnsureDisk(ctx context.Context, cfg Config) error {
 				}
 			}
 			if f.Initrd != nil {
-				if _, err := fileutils.DownloadFile(ctx, initrd, *f.Initrd, false, "the initrd", *cfg.LimaYAML.Arch); err != nil {
+				if _, err := fileutils.DownloadFile(initrd, *f.Initrd, false, "the initrd", *cfg.LimaYAML.Arch); err != nil {
 					errs[i] = err
 					continue
 				}
@@ -463,7 +462,7 @@ func qemuMachine(arch limayaml.Arch) string {
 	return "virt"
 }
 
-func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err error) {
+func Cmdline(cfg Config) (exe string, args []string, err error) {
 	y := cfg.LimaYAML
 	exe, args, err = Exe(*y.Arch)
 	if err != nil {
@@ -579,7 +578,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
 				switch f.VMType {
 				case "", limayaml.QEMU:
 					if f.Arch == *y.Arch {
-						if _, err = fileutils.DownloadFile(ctx, downloadedFirmware, f.File, true, "UEFI code "+f.Location, *y.Arch); err != nil {
+						if _, err = fileutils.DownloadFile(downloadedFirmware, f.File, true, "UEFI code "+f.Location, *y.Arch); err != nil {
 							logrus.WithError(err).Warnf("failed to download %q", f.Location)
 							continue loop
 						}
diff --git a/pkg/qemu/qemu_driver.go b/pkg/qemu/qemu_driver.go
index d4306a92..c500721e 100644
--- a/pkg/qemu/qemu_driver.go
+++ b/pkg/qemu/qemu_driver.go
@@ -50,13 +50,13 @@ func (l *LimaQemuDriver) Validate() error {
 	return nil
 }
 
-func (l *LimaQemuDriver) CreateDisk(ctx context.Context) error {
+func (l *LimaQemuDriver) CreateDisk() error {
 	qCfg := Config{
 		Name:        l.Instance.Name,
 		InstanceDir: l.Instance.Dir,
 		LimaYAML:    l.Yaml,
 	}
-	return EnsureDisk(ctx, qCfg)
+	return EnsureDisk(qCfg)
 }
 
 func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
@@ -73,7 +73,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
 		LimaYAML:     l.Yaml,
 		SSHLocalPort: l.SSHLocalPort,
 	}
-	qExe, qArgs, err := Cmdline(ctx, qCfg)
+	qExe, qArgs, err := Cmdline(qCfg)
 	if err != nil {
 		return nil, err
 	}
@@ -191,7 +191,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
 	go func() {
 		if usernetIndex := limayaml.FirstUsernetIndex(l.Yaml); usernetIndex != -1 {
 			client := usernet.NewClientByName(l.Yaml.Networks[usernetIndex].Lima)
-			err := client.ConfigureDriver(ctx, l.BaseDriver)
+			err := client.ConfigureDriver(l.BaseDriver)
 			if err != nil {
 				l.qWaitCh <- err
 			}
diff --git a/pkg/start/start.go b/pkg/start/start.go
index 33c8a7c8..0cc4fdd7 100644
--- a/pkg/start/start.go
+++ b/pkg/start/start.go
@@ -38,7 +38,7 @@ const DefaultWatchHostAgentEventsTimeout = 10 * time.Minute
 // ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-GOOS-GOARCH.tar.gz archive
 // into the cache before launching the hostagent process, so that we can show the progress in tty.
 // https://github.com/lima-vm/lima/issues/326
-func ensureNerdctlArchiveCache(ctx context.Context, y *limayaml.LimaYAML, created bool) (string, error) {
+func ensureNerdctlArchiveCache(y *limayaml.LimaYAML, created bool) (string, error) {
 	if !*y.Containerd.System && !*y.Containerd.User {
 		// nerdctl archive is not needed
 		return "", nil
@@ -53,7 +53,7 @@ func ensureNerdctlArchiveCache(ctx context.Context, y *limayaml.LimaYAML, create
 				return path, nil
 			}
 		}
-		path, err := fileutils.DownloadFile(ctx, "", f, false, "the nerdctl archive", *y.Arch)
+		path, err := fileutils.DownloadFile("", f, false, "the nerdctl archive", *y.Arch)
 		if err != nil {
 			errs[i] = err
 			continue
@@ -101,10 +101,10 @@ func Prepare(ctx context.Context, inst *store.Instance) (*Prepared, error) {
 	if _, err := os.Stat(baseDisk); err == nil {
 		created = true
 	}
-	if err := limaDriver.CreateDisk(ctx); err != nil {
+	if err := limaDriver.CreateDisk(); err != nil {
 		return nil, err
 	}
-	nerdctlArchiveCache, err := ensureNerdctlArchiveCache(ctx, y, created)
+	nerdctlArchiveCache, err := ensureNerdctlArchiveCache(y, created)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/vz/disk.go b/pkg/vz/disk.go
index 0ee62d38..c4b9f01f 100644
--- a/pkg/vz/disk.go
+++ b/pkg/vz/disk.go
@@ -1,7 +1,6 @@
 package vz
 
 import (
-	"context"
 	"errors"
 	"fmt"
 	"os"
@@ -15,7 +14,7 @@ import (
 	"github.com/lima-vm/lima/pkg/store/filenames"
 )
 
-func EnsureDisk(ctx context.Context, driver *driver.BaseDriver) error {
+func EnsureDisk(driver *driver.BaseDriver) error {
 	diffDisk := filepath.Join(driver.Instance.Dir, filenames.DiffDisk)
 	if _, err := os.Stat(diffDisk); err == nil || !errors.Is(err, os.ErrNotExist) {
 		// disk is already ensured
@@ -27,7 +26,7 @@ func EnsureDisk(ctx context.Context, driver *driver.BaseDriver) error {
 		var ensuredBaseDisk bool
 		errs := make([]error, len(driver.Yaml.Images))
 		for i, f := range driver.Yaml.Images {
-			if _, err := fileutils.DownloadFile(ctx, baseDisk, f.File, true, "the image", *driver.Yaml.Arch); err != nil {
+			if _, err := fileutils.DownloadFile(baseDisk, f.File, true, "the image", *driver.Yaml.Arch); err != nil {
 				errs[i] = err
 				continue
 			}
diff --git a/pkg/vz/vm_darwin.go b/pkg/vz/vm_darwin.go
index 8d686678..0b1e20dc 100644
--- a/pkg/vz/vm_darwin.go
+++ b/pkg/vz/vm_darwin.go
@@ -102,7 +102,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*virtualMachineWra
 					filesToRemove[pidFile] = struct{}{}
 					logrus.Info("[VZ] - vm state change: running")
 
-					err := usernetClient.ConfigureDriver(ctx, driver)
+					err := usernetClient.ConfigureDriver(driver)
 					if err != nil {
 						errCh <- err
 					}
diff --git a/pkg/vz/vz_driver_darwin.go b/pkg/vz/vz_driver_darwin.go
index d4aea761..ce496d6b 100644
--- a/pkg/vz/vz_driver_darwin.go
+++ b/pkg/vz/vz_driver_darwin.go
@@ -147,8 +147,8 @@ func (l *LimaVzDriver) Initialize(_ context.Context) error {
 	return err
 }
 
-func (l *LimaVzDriver) CreateDisk(ctx context.Context) error {
-	return EnsureDisk(ctx, l.BaseDriver)
+func (l *LimaVzDriver) CreateDisk() error {
+	return EnsureDisk(l.BaseDriver)
 }
 
 func (l *LimaVzDriver) Start(ctx context.Context) (chan error, error) {
diff --git a/pkg/vz/vz_driver_others.go b/pkg/vz/vz_driver_others.go
index b8e414e1..67ccd9fd 100644
--- a/pkg/vz/vz_driver_others.go
+++ b/pkg/vz/vz_driver_others.go
@@ -27,7 +27,7 @@ func (l *LimaVzDriver) Validate() error {
 	return ErrUnsupported
 }
 
-func (l *LimaVzDriver) CreateDisk(_ context.Context) error {
+func (l *LimaVzDriver) CreateDisk() error {
 	return ErrUnsupported
 }
 
diff --git a/pkg/wsl2/fs.go b/pkg/wsl2/fs.go
index 93c08fef..7500985e 100644
--- a/pkg/wsl2/fs.go
+++ b/pkg/wsl2/fs.go
@@ -1,7 +1,6 @@
 package wsl2
 
 import (
-	"context"
 	"errors"
 	"os"
 	"path/filepath"
@@ -13,13 +12,13 @@ import (
 )
 
 // EnsureFs downloads the root fs.
-func EnsureFs(ctx context.Context, driver *driver.BaseDriver) error {
+func EnsureFs(driver *driver.BaseDriver) error {
 	baseDisk := filepath.Join(driver.Instance.Dir, filenames.BaseDisk)
 	if _, err := os.Stat(baseDisk); errors.Is(err, os.ErrNotExist) {
 		var ensuredBaseDisk bool
 		errs := make([]error, len(driver.Yaml.Images))
 		for i, f := range driver.Yaml.Images {
-			if _, err := fileutils.DownloadFile(ctx, baseDisk, f.File, true, "the image", *driver.Yaml.Arch); err != nil {
+			if _, err := fileutils.DownloadFile(baseDisk, f.File, true, "the image", *driver.Yaml.Arch); err != nil {
 				errs[i] = err
 				continue
 			}
diff --git a/pkg/wsl2/wsl_driver_others.go b/pkg/wsl2/wsl_driver_others.go
index 7a116e5e..5e348406 100644
--- a/pkg/wsl2/wsl_driver_others.go
+++ b/pkg/wsl2/wsl_driver_others.go
@@ -27,7 +27,7 @@ func (l *LimaWslDriver) Validate() error {
 	return ErrUnsupported
 }
 
-func (l *LimaWslDriver) CreateDisk(_ context.Context) error {
+func (l *LimaWslDriver) CreateDisk() error {
 	return ErrUnsupported
 }
 
diff --git a/pkg/wsl2/wsl_driver_windows.go b/pkg/wsl2/wsl_driver_windows.go
index 13b2c4b9..8d508e70 100644
--- a/pkg/wsl2/wsl_driver_windows.go
+++ b/pkg/wsl2/wsl_driver_windows.go
@@ -114,7 +114,7 @@ func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
 	distroName := "lima-" + l.Instance.Name
 
 	if status == store.StatusUninitialized {
-		if err := EnsureFs(ctx, l.BaseDriver); err != nil {
+		if err := EnsureFs(l.BaseDriver); err != nil {
 			return nil, err
 		}
 		if err := initVM(ctx, l.BaseDriver.Instance.Dir, distroName); err != nil {


Test patch:
diff --git a/pkg/downloader/downloader_test.go b/pkg/downloader/downloader_test.go
index 1ac66bb9..1ff29266 100644
--- a/pkg/downloader/downloader_test.go
+++ b/pkg/downloader/downloader_test.go
@@ -1,7 +1,6 @@
 package downloader
 
 import (
-	"context"
 	"net/http"
 	"net/http/httptest"
 	"os"
@@ -29,26 +28,26 @@ func TestDownloadRemote(t *testing.T) {
 	t.Run("without cache", func(t *testing.T) {
 		t.Run("without digest", func(t *testing.T) {
 			localPath := filepath.Join(t.TempDir(), t.Name())
-			r, err := Download(context.Background(), localPath, dummyRemoteFileURL)
+			r, err := Download(localPath, dummyRemoteFileURL)
 			assert.NilError(t, err)
 			assert.Equal(t, StatusDownloaded, r.Status)
 
 			// download again, make sure StatusSkippedIsReturned
-			r, err = Download(context.Background(), localPath, dummyRemoteFileURL)
+			r, err = Download(localPath, dummyRemoteFileURL)
 			assert.NilError(t, err)
 			assert.Equal(t, StatusSkipped, r.Status)
 		})
 		t.Run("with digest", func(t *testing.T) {
 			wrongDigest := digest.Digest("sha256:8313944efb4f38570c689813f288058b674ea6c487017a5a4738dc674b65f9d9")
 			localPath := filepath.Join(t.TempDir(), t.Name())
-			_, err := Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(wrongDigest))
+			_, err := Download(localPath, dummyRemoteFileURL, WithExpectedDigest(wrongDigest))
 			assert.ErrorContains(t, err, "expected digest")
 
-			r, err := Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
+			r, err := Download(localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
 			assert.NilError(t, err)
 			assert.Equal(t, StatusDownloaded, r.Status)
 
-			r, err = Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
+			r, err = Download(localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
 			assert.NilError(t, err)
 			assert.Equal(t, StatusSkipped, r.Status)
 		})
@@ -56,34 +55,34 @@ func TestDownloadRemote(t *testing.T) {
 	t.Run("with cache", func(t *testing.T) {
 		cacheDir := filepath.Join(t.TempDir(), "cache")
 		localPath := filepath.Join(t.TempDir(), t.Name())
-		r, err := Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err := Download(localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)
 
-		r, err = Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err = Download(localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusSkipped, r.Status)
 
 		localPath2 := localPath + "-2"
-		r, err = Download(context.Background(), localPath2, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err = Download(localPath2, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusUsedCache, r.Status)
 	})
 	t.Run("caching-only mode", func(t *testing.T) {
-		_, err := Download(context.Background(), "", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
+		_, err := Download("", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest))
 		assert.ErrorContains(t, err, "cache directory to be specified")
 
 		cacheDir := filepath.Join(t.TempDir(), "cache")
-		r, err := Download(context.Background(), "", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err := Download("", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)
 
-		r, err = Download(context.Background(), "", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err = Download("", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusUsedCache, r.Status)
 
 		localPath := filepath.Join(t.TempDir(), t.Name())
-		r, err = Download(context.Background(), localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err = Download(localPath, dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusUsedCache, r.Status)
 	})
@@ -92,7 +91,7 @@ func TestDownloadRemote(t *testing.T) {
 		assert.ErrorContains(t, err, "cache directory to be specified")
 
 		cacheDir := filepath.Join(t.TempDir(), "cache")
-		r, err := Download(context.Background(), "", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
+		r, err := Download("", dummyRemoteFileURL, WithExpectedDigest(dummyRemoteFileDigest), WithCacheDir(cacheDir))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)
 
@@ -119,7 +118,7 @@ func TestDownloadLocal(t *testing.T) {
 		t.Cleanup(func() { _ = f.Close() })
 		testLocalFileURL := "file://" + localFile
 
-		r, err := Download(context.Background(), localPath, testLocalFileURL)
+		r, err := Download(localPath, testLocalFileURL)
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)
 	})
@@ -133,10 +132,10 @@ func TestDownloadLocal(t *testing.T) {
 		testLocalFileURL := "file://" + localTestFile
 		wrongDigest := digest.Digest(emptyFileDigest)
 
-		_, err := Download(context.Background(), localPath, testLocalFileURL, WithExpectedDigest(wrongDigest))
+		_, err := Download(localPath, testLocalFileURL, WithExpectedDigest(wrongDigest))
 		assert.ErrorContains(t, err, "expected digest")
 
-		r, err := Download(context.Background(), localPath, testLocalFileURL, WithExpectedDigest(testDownloadLocalDigest))
+		r, err := Download(localPath, testLocalFileURL, WithExpectedDigest(testDownloadLocalDigest))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)
 
@@ -171,7 +170,7 @@ func TestDownloadCompressed(t *testing.T) {
 		localFile += ".gz"
 		testLocalFileURL := "file://" + localFile
 
-		r, err := Download(context.Background(), localPath, testLocalFileURL, WithDecompress(true))
+		r, err := Download(localPath, testLocalFileURL, WithDecompress(true))
 		assert.NilError(t, err)
 		assert.Equal(t, StatusDownloaded, r.Status)