virtiofsd: refactor qemu.go to use code in virtiofsd.go

CloudHypervisor is using virtiofsd.go to manage virtiofsd process,
but qemu has its code in qemu.go. This commit let qemu to re-use
code in virtiofsd.go to reduce code and improve maintenanceability.

Fixes: #1933

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin
2021-05-28 11:01:29 +08:00
parent c455d84571
commit 72cd8f5ef6
5 changed files with 131 additions and 199 deletions

View File

@@ -11,7 +11,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
govmmQemu "github.com/kata-containers/govmm/qemu"
@@ -550,35 +549,6 @@ func createQemuSandboxConfig() (*Sandbox, error) {
return &sandbox, nil
}
func TestQemuVirtiofsdArgs(t *testing.T) {
assert := assert.New(t)
q := &qemu{
id: "foo",
config: HypervisorConfig{
VirtioFSCache: "none",
Debug: true,
},
}
savedKataHostSharedDir := kataHostSharedDir
kataHostSharedDir = func() string {
return "test-share-dir"
}
defer func() {
kataHostSharedDir = savedKataHostSharedDir
}()
result := "--fd=123 -o source=test-share-dir/foo/shared -o cache=none --syslog -o no_posix_lock -d"
args := q.virtiofsdArgs(123)
assert.Equal(strings.Join(args, " "), result)
q.config.Debug = false
result = "--fd=123 -o source=test-share-dir/foo/shared -o cache=none --syslog -o no_posix_lock -f"
args = q.virtiofsdArgs(123)
assert.Equal(strings.Join(args, " "), result)
}
func TestQemuGetpids(t *testing.T) {
assert := assert.New(t)