Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ linters:
- revive
- funcorder
- noinlineerr
- godoclint
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if new public APIs have godoc comments

echo "=== Checking ExtractSourceCodeDisk in pkg/machine/disk/disk.go ==="
rg -A 5 -B 1 'func ExtractSourceCodeDisk' pkg/machine/disk/disk.go || echo "File or function not found"

echo -e "\n=== Checking GetSourceDiskPath in pkg/machine/vmconfig/vmconfig.go ==="
rg -A 5 -B 1 'func.*GetSourceDiskPath' pkg/machine/vmconfig/vmconfig.go || echo "Function not found"

echo -e "\n=== Checking file structure of pkg/machine/disk/disk.go ==="
if [ -f "pkg/machine/disk/disk.go" ]; then
  head -50 pkg/machine/disk/disk.go | tail -30
else
  echo "File does not exist"
fi

echo -e "\n=== Checking file structure of pkg/machine/vmconfig/vmconfig.go ==="
if [ -f "pkg/machine/vmconfig/vmconfig.go" ]; then
  head -50 pkg/machine/vmconfig/vmconfig.go | tail -30
else
  echo "File does not exist"
fi

Repository: oomol-lab/ovm-mac

Length of output: 2432


Add godoc comments to new public APIs before disabling godoclint.

The following public functions lack documentation:

  • ExtractSourceCodeDisk in pkg/machine/disk/disk.go
  • GetSourceDiskPath in pkg/machine/vmconfig/vmconfig.go

Add godoc comments for these exported APIs or keep godoclint enabled to enforce documentation standards.

🤖 Prompt for AI Agents
In @.golangci.yml at line 56, Add proper godoc comments for the two exported
functions so godoclint can remain disabled or be re-enabled: write a one- or
two-sentence comment starting with the function name for ExtractSourceCodeDisk
(in pkg/machine/disk/disk.go) describing what it does, its inputs and returned
values/errors; do the same for GetSourceDiskPath (in
pkg/machine/vmconfig/vmconfig.go), describing its purpose, parameters and return
value; ensure comments begin with the exact exported identifier and mention any
important behavior or error conditions.

settings:
errcheck:
check-blank: false
Expand Down
1 change: 0 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ var initCmd = cli.Command{
Value: "v1.0",
Required: true,
},

&cli.StringFlag{
Name: "vmm",
Usage: "vm provider, support: krunkit, vfkit",
Expand Down
43 changes: 43 additions & 0 deletions pkg/machine/disk/disk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2024-2026 OOMOL, Inc. <https://www.oomol.com>
// SPDX-License-Identifier: MPL-2.0

package disk

import (
"bytes"
"context"
_ "embed"
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/sirupsen/logrus"
)

//go:embed source.ext4.tar
var sourceCodeExt4Disk []byte

func ExtractSourceCodeDisk(ctx context.Context, targetDirPath string, overwrite bool) error {
_, err := os.Stat(filepath.Join(targetDirPath, "source.ext4"))
if err == nil && !overwrite {
logrus.Infof("source code disk already exists, skip extraction")
return nil
}

if err := os.MkdirAll(targetDirPath, 0755); err != nil {
return fmt.Errorf("failed to create target directory: %w", err)
}
cmd := exec.CommandContext(ctx, "tar", "-xaS", "-C", targetDirPath, "-f", "-", "source.ext4")
cmd.Stdin = bytes.NewReader(sourceCodeExt4Disk)

var stderr bytes.Buffer
cmd.Stderr = &stderr

logrus.Infof("cmdline: %q", cmd.Args)
if err := cmd.Run(); err != nil {
return fmt.Errorf("tar extraction failed: %w, stderr: %s", err, stderr.String())
}

return nil
}
Binary file added pkg/machine/disk/source.ext4.tar
Binary file not shown.
12 changes: 9 additions & 3 deletions pkg/machine/machine_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ const applehvMACAddress = "5a:94:ef:e4:0c:ee"
func SetupDevices(mc *vmconfig.MachineConfig) ([]vfConfig.VirtioDevice, error) {
var devices []vfConfig.VirtioDevice

disk, err := vfConfig.VirtioBlkNew(mc.Bootable.Path)
bootableDisk, err := vfConfig.VirtioBlkNew(mc.Bootable.Path)
if err != nil {
return nil, fmt.Errorf("failed to create bootable disk device: %w", err)
}

rng, err := vfConfig.VirtioRngNew()
if err != nil {
return nil, fmt.Errorf("failed to create rng device: %w", err)
Expand All @@ -125,6 +126,11 @@ func SetupDevices(mc *vmconfig.MachineConfig) ([]vfConfig.VirtioDevice, error) {
return nil, fmt.Errorf("failed to create externalDisk device: %w", err)
}

sourceDisk, err := vfConfig.VirtioBlkNew(mc.GetSourceDiskPath())
if err != nil {
return nil, fmt.Errorf("failed to create source disk device: %w", err)
}

// using gvproxy as network backend
netDevice, err := vfConfig.VirtioNetNew(applehvMACAddress)
if err != nil {
Expand All @@ -133,8 +139,8 @@ func SetupDevices(mc *vmconfig.MachineConfig) ([]vfConfig.VirtioDevice, error) {

netDevice.SetUnixSocketPath(mc.GetNetworkStackEndpoint())

// externalDisk **must** be at the end of the device
devices = append(devices, disk, rng, netDevice, externalDisk)
// The externalDisk must be added to the devices queue after the bootableDisk
devices = append(devices, bootableDisk, rng, netDevice, externalDisk, sourceDisk)

VirtIOMounts, err := VirtIOFsToVFKitVirtIODevice(mc.Mounts)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pkg/machine/shim/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"context"
"fmt"
"os/exec"
"path/filepath"

"bauklotze/pkg/decompress"
"bauklotze/pkg/machine"
"bauklotze/pkg/machine/define"
"bauklotze/pkg/machine/disk"
"bauklotze/pkg/machine/events"
"bauklotze/pkg/machine/krunkit"
"bauklotze/pkg/machine/ssh/service"
Expand Down Expand Up @@ -95,14 +97,20 @@ func Start(parentCtx context.Context, mc *vmconfig.MachineConfig, vmp vmconfig.V

cancel(context.Cause(parentCtx))
})

// 1. Start the network stack
if err := vmp.StartNetworkProvider(ctx, mc); err != nil {
return fmt.Errorf("failed to start network stack: %w", err)
}

// 2. Start the VM provider
// 2. extract the source code disk
if err := disk.ExtractSourceCodeDisk(ctx, filepath.Dir(mc.GetSourceDiskPath()), false); err != nil {
return fmt.Errorf("failed to extract source code disk: %w", err)
}

// 3. Start the VM provider
if err := vmp.StartVMProvider(ctx, mc); err != nil {
return fmt.Errorf("failed to start network stack: %w", err)
return fmt.Errorf("failed to start vm provider: %w", err)
}

// Optional services are placed in separation go routines, these services will not crash the VM even if they fail
Expand Down
4 changes: 4 additions & 0 deletions pkg/machine/vmconfig/vmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ func (mc *MachineConfig) getBinDir() (string, error) {
return binDir, nil
}

func (mc *MachineConfig) GetSourceDiskPath() string {
return filepath.Join(mc.Dirs.DataDir, "source.ext4")
}

func (mc *MachineConfig) GetKrunkitBin() (string, error) {
dir, err := mc.getBinDir()
if err != nil {
Expand Down
Loading