Merge pull request #310 from fidencio/wip/forward_port_c3d_and_ted_yu_patches

[forward port] Bring to the development branch fixes provided by Christophe De Dinechin and Ted Yu.
This commit is contained in:
Peng Tao 2020-06-25 04:57:48 +08:00 committed by GitHub
commit bee02d47ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 17 deletions

View File

@ -96,6 +96,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
pcieRootPort := uint32(2) pcieRootPort := uint32(2)
disableNewNetNs := false disableNewNetNs := false
sharedFS := "virtio-9p" sharedFS := "virtio-9p"
virtioFSdaemon := filepath.Join(prefixDir, "virtiofsd")
filesToCreate := []string{ filesToCreate := []string{
hypervisorPath, hypervisorPath,
@ -168,6 +169,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
AgentDebug: agentDebug, AgentDebug: agentDebug,
AgentTrace: agentTrace, AgentTrace: agentTrace,
SharedFS: sharedFS, SharedFS: sharedFS,
VirtioFSDaemon: virtioFSdaemon,
} }
runtimeConfig := katatestutils.MakeRuntimeConfigFileData(configFileOptions) runtimeConfig := katatestutils.MakeRuntimeConfigFileData(configFileOptions)

View File

@ -401,6 +401,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
pcieRootPort := uint32(2) pcieRootPort := uint32(2)
disableNewNetNs := false disableNewNetNs := false
sharedFS := "virtio-9p" sharedFS := "virtio-9p"
virtioFSdaemon := path.Join(dir, "virtiofsd")
configFileOptions := ktu.RuntimeConfigOptions{ configFileOptions := ktu.RuntimeConfigOptions{
Hypervisor: "qemu", Hypervisor: "qemu",
@ -420,6 +421,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config string, err err
PCIeRootPort: pcieRootPort, PCIeRootPort: pcieRootPort,
DisableNewNetNs: disableNewNetNs, DisableNewNetNs: disableNewNetNs,
SharedFS: sharedFS, SharedFS: sharedFS,
VirtioFSDaemon: virtioFSdaemon,
} }
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions) runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)

View File

@ -211,10 +211,10 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
// make sure to wait after start // make sure to wait after start
go cmd.Wait() go cmd.Wait()
if err := cdshim.WritePidFile("shim.pid", cmd.Process.Pid); err != nil { if err = cdshim.WritePidFile("shim.pid", cmd.Process.Pid); err != nil {
return "", err return "", err
} }
if err := cdshim.WriteAddress("address", address); err != nil { if err = cdshim.WriteAddress("address", address); err != nil {
return "", err return "", err
} }
return address, nil return address, nil

View File

@ -28,6 +28,7 @@ type RuntimeConfigOptions struct {
AgentTraceMode string AgentTraceMode string
AgentTraceType string AgentTraceType string
SharedFS string SharedFS string
VirtioFSDaemon string
PCIeRootPort uint32 PCIeRootPort uint32
DisableBlock bool DisableBlock bool
EnableIOThreads bool EnableIOThreads bool
@ -65,7 +66,7 @@ func MakeRuntimeConfigFileData(config RuntimeConfigOptions) string {
enable_debug = ` + strconv.FormatBool(config.HypervisorDebug) + ` enable_debug = ` + strconv.FormatBool(config.HypervisorDebug) + `
guest_hook_path = "` + config.DefaultGuestHookPath + `" guest_hook_path = "` + config.DefaultGuestHookPath + `"
shared_fs = "` + config.SharedFS + `" shared_fs = "` + config.SharedFS + `"
virtio_fs_daemon = "/path/to/virtiofsd" virtio_fs_daemon = "` + config.VirtioFSDaemon + `"
[proxy.kata] [proxy.kata]
enable_debug = ` + strconv.FormatBool(config.ProxyDebug) + ` enable_debug = ` + strconv.FormatBool(config.ProxyDebug) + `

View File

@ -85,6 +85,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
pcieRootPort := uint32(2) pcieRootPort := uint32(2)
disableNewNetNs := false disableNewNetNs := false
sharedFS := "virtio-9p" sharedFS := "virtio-9p"
virtioFSdaemon := path.Join(dir, "virtiofsd")
configFileOptions := ktu.RuntimeConfigOptions{ configFileOptions := ktu.RuntimeConfigOptions{
Hypervisor: "qemu", Hypervisor: "qemu",
@ -117,6 +118,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
AgentDebug: agentDebug, AgentDebug: agentDebug,
AgentTrace: agentTrace, AgentTrace: agentTrace,
SharedFS: sharedFS, SharedFS: sharedFS,
VirtioFSDaemon: virtioFSdaemon,
} }
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions) runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
@ -167,7 +169,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
GuestHookPath: defaultGuestHookPath, GuestHookPath: defaultGuestHookPath,
VhostUserStorePath: defaultVhostUserStorePath, VhostUserStorePath: defaultVhostUserStorePath,
SharedFS: sharedFS, SharedFS: sharedFS,
VirtioFSDaemon: "/path/to/virtiofsd", VirtioFSDaemon: virtioFSdaemon,
VirtioFSCache: defaultVirtioFSCacheMode, VirtioFSCache: defaultVirtioFSCacheMode,
} }

View File

@ -235,7 +235,9 @@ func (a *Acrn) appendImage(devices []Device, imagePath string) ([]Device, error)
if sandbox == nil && err != nil { if sandbox == nil && err != nil {
return nil, err return nil, err
} }
sandbox.GetAndSetSandboxBlockIndex() if _, err = sandbox.GetAndSetSandboxBlockIndex(); err != nil {
return nil, err
}
devices, err = a.arch.appendImage(devices, imagePath) devices, err = a.arch.appendImage(devices, imagePath)
if err != nil { if err != nil {

View File

@ -646,10 +646,6 @@ func (q *qemu) setupVirtiofsd() (err error) {
var listener *net.UnixListener var listener *net.UnixListener
var fd *os.File var fd *os.File
if _, err = os.Stat(q.config.VirtioFSDaemon); os.IsNotExist(err) {
return fmt.Errorf("virtiofsd path (%s) does not exist", q.config.VirtioFSDaemon)
}
sockPath, err := q.vhostFSSocketPath(q.id) sockPath, err := q.vhostFSSocketPath(q.id)
if err != nil { if err != nil {
return err return err
@ -680,9 +676,10 @@ func (q *qemu) setupVirtiofsd() (err error) {
} }
err = cmd.Start() err = cmd.Start()
if err == nil { if err != nil {
q.state.VirtiofsdPid = cmd.Process.Pid return fmt.Errorf("virtiofs daemon %v returned with error: %v", q.config.VirtioFSDaemon, err)
} }
q.state.VirtiofsdPid = cmd.Process.Pid
fd.Close() fd.Close()
// Monitor virtiofsd's stderr and stop sandbox if virtiofsd quits // Monitor virtiofsd's stderr and stop sandbox if virtiofsd quits

View File

@ -1606,7 +1606,6 @@ const maxBlockIndex = 65535
// the BlockIndexMap and marks it as used. This index is used to maintain the // the BlockIndexMap and marks it as used. This index is used to maintain the
// index at which a block device is assigned to a container in the sandbox. // index at which a block device is assigned to a container in the sandbox.
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) { func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
var err error
currentIndex := -1 currentIndex := -1
for i := 0; i < maxBlockIndex; i++ { for i := 0; i < maxBlockIndex; i++ {
if _, ok := s.state.BlockIndexMap[i]; !ok { if _, ok := s.state.BlockIndexMap[i]; !ok {
@ -1618,11 +1617,6 @@ func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
return -1, errors.New("no available block index") return -1, errors.New("no available block index")
} }
s.state.BlockIndexMap[currentIndex] = struct{}{} s.state.BlockIndexMap[currentIndex] = struct{}{}
defer func() {
if err != nil {
delete(s.state.BlockIndexMap, currentIndex)
}
}()
return currentIndex, nil return currentIndex, nil
} }