runv icon indicating copy to clipboard operation
runv copied to clipboard

add build os for file driver.go

Open allencloud opened this issue 7 years ago • 5 comments

First, let me illustrate without // +build linux, what will code report?

In Line https://github.com/hyperhq/runv/blob/master/hypervisor/driver.go#L67, we have code

var VsockCidManager vsock.VsockCidAllocator

And we can find VsockCidAllocator is an interface ONLY on Linux, since it is described in file https://github.com/hyperhq/runv/blob/master/lib/vsock/vsock.go#L1

// +build linux

package vsock

import (
	"fmt"
	"sync"

	"github.com/RoaringBitmap/roaring"
)

const hyperDefaultVsockCid = 1024
const hyperDefaultVsockBitmapSize = 16384

type VsockCidAllocator interface {
	sync.Locker
	GetCid() (uint32, error)
	MarkCidInuse(uint32) bool
	ReleaseCid(uint32)
}

So if the file is compiled on other OS types, it will throw a compile error.

So I add a build os for file driver.go.

Signed-off-by: Allen Sun [email protected]

allencloud avatar Sep 25 '17 11:09 allencloud

Or we can remove the // +build linux from https://github.com/hyperhq/runv/blob/master/lib/vsock/vsock.go#L1. And this action will work as well.

allencloud avatar Sep 25 '17 11:09 allencloud

The right fix is to add VsockCidAllocator to lib/vsock/vsock_unsupported.go. Would you like to update and fix it there?

bergwolf avatar Sep 26 '17 10:09 bergwolf

Yes, It is another solution to this. I will carry that in this PR. But maybe in a couple of days. Thanks for your advice and feedback. @bergwolf

allencloud avatar Sep 26 '17 10:09 allencloud

I just add the same interface definition into vsock_unsupported.go. And this will make darwin os report no compile error. PTAL @bergwolf

allencloud avatar Sep 26 '17 16:09 allencloud

@allencloud Thanks for the quick update. I'm afraid the fix is not completed yet, e.g, NewDefaultVsockCidAllocator() is called in driverloader/driverloader_linux.go.

Please add a dummy implementation of the interface in vsock_unsupported.go. We'd like to get proper errors other than runtime failures when vsock is not supported. The dummy implementation will include NewDefaultVsockCidAllocator() and all the methods declared in VsockCidAllocator.

bergwolf avatar Sep 27 '17 01:09 bergwolf