mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 04:34:27 +00:00
runtime: change cache mode from none to never
New Rust virtiofsd's `cache` mode doesn't support `none` mode, we should use `never` to replace it. Fixes: #6018 Signed-off-by: Bin Liu <bin@hyper.sh>
This commit is contained in:
parent
82c59efd65
commit
86a82cace9
@ -147,7 +147,7 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
|
|||||||
|
|
||||||
# Cache mode:
|
# Cache mode:
|
||||||
#
|
#
|
||||||
# - none
|
# - never
|
||||||
# Metadata, data, and pathname lookup are not cached in guest. They are
|
# Metadata, data, and pathname lookup are not cached in guest. They are
|
||||||
# always fetched from host and any changes are immediately pushed to host.
|
# always fetched from host and any changes are immediately pushed to host.
|
||||||
#
|
#
|
||||||
|
@ -205,7 +205,7 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
|
|||||||
|
|
||||||
# Cache mode:
|
# Cache mode:
|
||||||
#
|
#
|
||||||
# - none
|
# - never
|
||||||
# Metadata, data, and pathname lookup are not cached in guest. They are
|
# Metadata, data, and pathname lookup are not cached in guest. They are
|
||||||
# always fetched from host and any changes are immediately pushed to host.
|
# always fetched from host and any changes are immediately pushed to host.
|
||||||
#
|
#
|
||||||
|
@ -1242,9 +1242,9 @@ func TestDefaultVirtioFSCache(t *testing.T) {
|
|||||||
cache = h.defaultVirtioFSCache()
|
cache = h.defaultVirtioFSCache()
|
||||||
assert.Equal("always", cache)
|
assert.Equal("always", cache)
|
||||||
|
|
||||||
h.VirtioFSCache = "none"
|
h.VirtioFSCache = "never"
|
||||||
cache = h.defaultVirtioFSCache()
|
cache = h.defaultVirtioFSCache()
|
||||||
assert.Equal("none", cache)
|
assert.Equal("never", cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultFirmware(t *testing.T) {
|
func TestDefaultFirmware(t *testing.T) {
|
||||||
|
@ -650,7 +650,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
|
|||||||
ocispec.Annotations[vcAnnotations.BlockDeviceCacheNoflush] = "true"
|
ocispec.Annotations[vcAnnotations.BlockDeviceCacheNoflush] = "true"
|
||||||
ocispec.Annotations[vcAnnotations.SharedFS] = "virtio-fs"
|
ocispec.Annotations[vcAnnotations.SharedFS] = "virtio-fs"
|
||||||
ocispec.Annotations[vcAnnotations.VirtioFSDaemon] = "/bin/false"
|
ocispec.Annotations[vcAnnotations.VirtioFSDaemon] = "/bin/false"
|
||||||
ocispec.Annotations[vcAnnotations.VirtioFSCache] = "/home/cache"
|
ocispec.Annotations[vcAnnotations.VirtioFSCache] = "auto"
|
||||||
ocispec.Annotations[vcAnnotations.VirtioFSExtraArgs] = "[ \"arg0\", \"arg1\" ]"
|
ocispec.Annotations[vcAnnotations.VirtioFSExtraArgs] = "[ \"arg0\", \"arg1\" ]"
|
||||||
ocispec.Annotations[vcAnnotations.Msize9p] = "512"
|
ocispec.Annotations[vcAnnotations.Msize9p] = "512"
|
||||||
ocispec.Annotations[vcAnnotations.MachineType] = "q35"
|
ocispec.Annotations[vcAnnotations.MachineType] = "q35"
|
||||||
@ -688,7 +688,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
|
|||||||
assert.Equal(config.HypervisorConfig.BlockDeviceCacheNoflush, true)
|
assert.Equal(config.HypervisorConfig.BlockDeviceCacheNoflush, true)
|
||||||
assert.Equal(config.HypervisorConfig.SharedFS, "virtio-fs")
|
assert.Equal(config.HypervisorConfig.SharedFS, "virtio-fs")
|
||||||
assert.Equal(config.HypervisorConfig.VirtioFSDaemon, "/bin/false")
|
assert.Equal(config.HypervisorConfig.VirtioFSDaemon, "/bin/false")
|
||||||
assert.Equal(config.HypervisorConfig.VirtioFSCache, "/home/cache")
|
assert.Equal(config.HypervisorConfig.VirtioFSCache, "auto")
|
||||||
assert.ElementsMatch(config.HypervisorConfig.VirtioFSExtraArgs, [2]string{"arg0", "arg1"})
|
assert.ElementsMatch(config.HypervisorConfig.VirtioFSExtraArgs, [2]string{"arg0", "arg1"})
|
||||||
assert.Equal(config.HypervisorConfig.Msize9p, uint32(512))
|
assert.Equal(config.HypervisorConfig.Msize9p, uint32(512))
|
||||||
assert.Equal(config.HypervisorConfig.HypervisorMachineType, "q35")
|
assert.Equal(config.HypervisorConfig.HypervisorMachineType, "q35")
|
||||||
|
@ -219,7 +219,7 @@ type HypervisorConfig struct {
|
|||||||
// VirtioFSDaemonList is the list of valid virtiofs names for annotations
|
// VirtioFSDaemonList is the list of valid virtiofs names for annotations
|
||||||
VirtioFSDaemonList []string
|
VirtioFSDaemonList []string
|
||||||
|
|
||||||
// VirtioFSCache cache mode for fs version cache or "none"
|
// VirtioFSCache cache mode for fs version cache
|
||||||
VirtioFSCache string
|
VirtioFSCache string
|
||||||
|
|
||||||
// VirtioFSExtraArgs passes options to virtiofsd daemon
|
// VirtioFSExtraArgs passes options to virtiofsd daemon
|
||||||
|
@ -325,7 +325,7 @@ type HypervisorConfig struct {
|
|||||||
// VirtioFSDaemon is the virtio-fs vhost-user daemon path
|
// VirtioFSDaemon is the virtio-fs vhost-user daemon path
|
||||||
VirtioFSDaemon string
|
VirtioFSDaemon string
|
||||||
|
|
||||||
// VirtioFSCache cache mode for fs version cache or "none"
|
// VirtioFSCache cache mode for fs version cache
|
||||||
VirtioFSCache string
|
VirtioFSCache string
|
||||||
|
|
||||||
// File based memory backend root directory
|
// File based memory backend root directory
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
"github.com/opencontainers/selinux/go-selinux"
|
||||||
@ -87,7 +88,7 @@ var (
|
|||||||
type9pFs = "9p"
|
type9pFs = "9p"
|
||||||
typeVirtioFS = "virtiofs"
|
typeVirtioFS = "virtiofs"
|
||||||
typeOverlayFS = "overlay"
|
typeOverlayFS = "overlay"
|
||||||
typeVirtioFSNoCache = "none"
|
typeVirtioFSNoCache = "never"
|
||||||
kata9pDevType = "9p"
|
kata9pDevType = "9p"
|
||||||
kataMmioBlkDevType = "mmioblk"
|
kataMmioBlkDevType = "mmioblk"
|
||||||
kataBlkDevType = "blk"
|
kataBlkDevType = "blk"
|
||||||
@ -801,7 +802,7 @@ func setupStorages(ctx context.Context, sandbox *Sandbox) []*grpc.Storage {
|
|||||||
if sharedFS == config.VirtioFS || sharedFS == config.VirtioFSNydus {
|
if sharedFS == config.VirtioFS || sharedFS == config.VirtioFSNydus {
|
||||||
// If virtio-fs uses either of the two cache options 'auto, always',
|
// If virtio-fs uses either of the two cache options 'auto, always',
|
||||||
// the guest directory can be mounted with option 'dax' allowing it to
|
// the guest directory can be mounted with option 'dax' allowing it to
|
||||||
// directly map contents from the host. When set to 'none', the mount
|
// directly map contents from the host. When set to 'never', the mount
|
||||||
// options should not contain 'dax' lest the virtio-fs daemon crashing
|
// options should not contain 'dax' lest the virtio-fs daemon crashing
|
||||||
// with an invalid address reference.
|
// with an invalid address reference.
|
||||||
if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSNoCache {
|
if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSNoCache {
|
||||||
|
@ -70,7 +70,7 @@ type HypervisorConfig struct {
|
|||||||
// VirtioFSDaemon is the virtio-fs vhost-user daemon path
|
// VirtioFSDaemon is the virtio-fs vhost-user daemon path
|
||||||
VirtioFSDaemon string
|
VirtioFSDaemon string
|
||||||
|
|
||||||
// VirtioFSCache cache mode for fs version cache or "none"
|
// VirtioFSCache cache mode for fs version cache
|
||||||
VirtioFSCache string
|
VirtioFSCache string
|
||||||
|
|
||||||
// File based memory backend root directory
|
// File based memory backend root directory
|
||||||
|
@ -190,7 +190,7 @@ const (
|
|||||||
// VirtioFSDaemon is a sandbox annotations to specify virtio-fs vhost-user daemon path
|
// VirtioFSDaemon is a sandbox annotations to specify virtio-fs vhost-user daemon path
|
||||||
VirtioFSDaemon = kataAnnotHypervisorPrefix + "virtio_fs_daemon"
|
VirtioFSDaemon = kataAnnotHypervisorPrefix + "virtio_fs_daemon"
|
||||||
|
|
||||||
// VirtioFSCache is a sandbox annotation to specify the cache mode for fs version cache or "none"
|
// VirtioFSCache is a sandbox annotation to specify the cache mode for fs version cache
|
||||||
VirtioFSCache = kataAnnotHypervisorPrefix + "virtio_fs_cache"
|
VirtioFSCache = kataAnnotHypervisorPrefix + "virtio_fs_cache"
|
||||||
|
|
||||||
// VirtioFSCacheSize is a sandbox annotation to specify the DAX cache size in MiB
|
// VirtioFSCacheSize is a sandbox annotation to specify the DAX cache size in MiB
|
||||||
|
@ -29,11 +29,12 @@ var virtiofsdTracingTags = map[string]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errVirtiofsdDaemonPathEmpty = errors.New("virtiofsd daemon path is empty")
|
errVirtiofsdDaemonPathEmpty = errors.New("virtiofsd daemon path is empty")
|
||||||
errVirtiofsdSocketPathEmpty = errors.New("virtiofsd socket path is empty")
|
errVirtiofsdSocketPathEmpty = errors.New("virtiofsd socket path is empty")
|
||||||
errVirtiofsdSourcePathEmpty = errors.New("virtiofsd source path is empty")
|
errVirtiofsdSourcePathEmpty = errors.New("virtiofsd source path is empty")
|
||||||
errVirtiofsdSourceNotAvailable = errors.New("virtiofsd source path not available")
|
errVirtiofsdInvalidVirtiofsCacheMode = func(mode string) error { return errors.Errorf("Invalid virtio-fs cache mode: %s", mode) }
|
||||||
errUnimplemented = errors.New("unimplemented")
|
errVirtiofsdSourceNotAvailable = errors.New("virtiofsd source path not available")
|
||||||
|
errUnimplemented = errors.New("unimplemented")
|
||||||
)
|
)
|
||||||
|
|
||||||
type VirtiofsDaemon interface {
|
type VirtiofsDaemon interface {
|
||||||
@ -63,7 +64,7 @@ type virtiofsd struct {
|
|||||||
path string
|
path string
|
||||||
// socketPath where daemon will serve
|
// socketPath where daemon will serve
|
||||||
socketPath string
|
socketPath string
|
||||||
// cache size for virtiofsd
|
// cache mode for virtiofsd
|
||||||
cache string
|
cache string
|
||||||
// sourcePath path that daemon will help to share
|
// sourcePath path that daemon will help to share
|
||||||
sourcePath string
|
sourcePath string
|
||||||
@ -213,6 +214,16 @@ func (v *virtiofsd) valid() error {
|
|||||||
if _, err := os.Stat(v.sourcePath); err != nil {
|
if _, err := os.Stat(v.sourcePath); err != nil {
|
||||||
return errVirtiofsdSourceNotAvailable
|
return errVirtiofsdSourceNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.cache == "" {
|
||||||
|
v.cache = "auto"
|
||||||
|
} else if v.cache == "none" {
|
||||||
|
v.Logger().Warn("virtio-fs cache mode `none` is deprecated since Kata Containers 2.5.0 and will be removed in the future release, please use `never` instead. For more details please refer to https://github.com/kata-containers/kata-containers/issues/4234.")
|
||||||
|
v.cache = "never"
|
||||||
|
} else if v.cache != "auto" && v.cache != "always" && v.cache != "never" {
|
||||||
|
return errVirtiofsdInvalidVirtiofsCacheMode(v.cache)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func TestVirtiofsdArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestValid(t *testing.T) {
|
func TestValid(t *testing.T) {
|
||||||
assert := assert.New(t)
|
a := assert.New(t)
|
||||||
|
|
||||||
sourcePath := t.TempDir()
|
sourcePath := t.TempDir()
|
||||||
socketDir := t.TempDir()
|
socketDir := t.TempDir()
|
||||||
@ -103,31 +103,61 @@ func TestValid(t *testing.T) {
|
|||||||
path: "/usr/bin/virtiofsd",
|
path: "/usr/bin/virtiofsd",
|
||||||
sourcePath: sourcePath,
|
sourcePath: sourcePath,
|
||||||
socketPath: socketPath,
|
socketPath: socketPath,
|
||||||
|
cache: "auto",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// valid case
|
type fieldFunc func(v *virtiofsd)
|
||||||
v := newVirtiofsdFunc()
|
type assertFunc func(name string, assert *assert.Assertions, v *virtiofsd)
|
||||||
err := v.valid()
|
|
||||||
assert.NoError(err)
|
|
||||||
|
|
||||||
v = newVirtiofsdFunc()
|
// nolint: govet
|
||||||
v.path = ""
|
tests := []struct {
|
||||||
err = v.valid()
|
name string
|
||||||
assert.Equal(errVirtiofsdDaemonPathEmpty, err)
|
f fieldFunc
|
||||||
|
wantErr error
|
||||||
|
customAssert assertFunc
|
||||||
|
}{
|
||||||
|
{"valid case", nil, nil, nil},
|
||||||
|
{"no path", func(v *virtiofsd) {
|
||||||
|
v.path = ""
|
||||||
|
}, errVirtiofsdDaemonPathEmpty, nil},
|
||||||
|
{"no sourcePath", func(v *virtiofsd) {
|
||||||
|
v.sourcePath = ""
|
||||||
|
}, errVirtiofsdSourcePathEmpty, nil},
|
||||||
|
{"no socketPath", func(v *virtiofsd) {
|
||||||
|
v.socketPath = ""
|
||||||
|
}, errVirtiofsdSocketPathEmpty, nil},
|
||||||
|
{"source is not available", func(v *virtiofsd) {
|
||||||
|
v.sourcePath = "/foo/bar"
|
||||||
|
}, errVirtiofsdSourceNotAvailable, nil},
|
||||||
|
{"replace cache mode none by never", func(v *virtiofsd) {
|
||||||
|
v.cache = "none"
|
||||||
|
}, nil, func(name string, a *assert.Assertions, v *virtiofsd) {
|
||||||
|
a.Equal("never", v.cache, "test case %+s, cache mode none should be replaced by never", name)
|
||||||
|
}},
|
||||||
|
{"invald cache mode: replace none by never", func(v *virtiofsd) {
|
||||||
|
v.cache = "foo"
|
||||||
|
}, errVirtiofsdInvalidVirtiofsCacheMode("foo"), nil},
|
||||||
|
}
|
||||||
|
|
||||||
v = newVirtiofsdFunc()
|
for _, tt := range tests {
|
||||||
v.sourcePath = ""
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
err = v.valid()
|
v := newVirtiofsdFunc()
|
||||||
assert.Equal(errVirtiofsdSourcePathEmpty, err)
|
if tt.f != nil {
|
||||||
|
tt.f(v)
|
||||||
|
}
|
||||||
|
err := v.valid()
|
||||||
|
if tt.wantErr != nil && err == nil {
|
||||||
|
t.Errorf("test case %+s: virtiofsd.valid() should get error `%+v`, but got nil", tt.name, tt.wantErr)
|
||||||
|
} else if tt.wantErr == nil && err != nil {
|
||||||
|
t.Errorf("test case %+s: virtiofsd.valid() should get no erro, but got `%+v`", tt.name, err)
|
||||||
|
} else if tt.wantErr != nil && err != nil {
|
||||||
|
a.Equal(err.Error(), tt.wantErr.Error(), "test case %+s", tt.name)
|
||||||
|
}
|
||||||
|
|
||||||
v = newVirtiofsdFunc()
|
if tt.customAssert != nil {
|
||||||
v.socketPath = ""
|
tt.customAssert(tt.name, a, v)
|
||||||
err = v.valid()
|
}
|
||||||
assert.Equal(errVirtiofsdSocketPathEmpty, err)
|
})
|
||||||
|
}
|
||||||
v = newVirtiofsdFunc()
|
|
||||||
v.sourcePath = "/foo/bar"
|
|
||||||
err = v.valid()
|
|
||||||
assert.Equal(errVirtiofsdSourceNotAvailable, err)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user