virtiofsd: change cache mod to const

Change cache mod from literal to const and place them in one place.

Also set default cache mode from `none` to `never` in
`pkg/katautils/config-settings.go.in`.

Fixes: #6151

Signed-off-by: Bin Liu <bin@hyper.sh>
This commit is contained in:
Bin Liu 2023-01-29 17:20:54 +08:00
parent 2752225360
commit 56071c6e7b
5 changed files with 14 additions and 9 deletions

View File

@ -80,7 +80,7 @@ const defaultHotplugVFIOOnRootBus bool = false
const defaultPCIeRootPort = 0
const defaultEntropySource = "/dev/urandom"
const defaultGuestHookPath string = ""
const defaultVirtioFSCacheMode = "none"
const defaultVirtioFSCacheMode = "never"
const defaultDisableImageNvdimm = false
const defaultVhostUserStorePath string = "/var/run/kata-containers/vhost-user/"
const defaultRxRateLimiterMaxRate = uint64(0)

View File

@ -80,7 +80,6 @@ const (
clhAPISocket = "clh-api.sock"
virtioFsSocket = "virtiofsd.sock"
defaultClhPath = "/usr/local/bin/cloud-hypervisor"
virtioFsCacheAlways = "always"
)
// Interface that hides the implementation of openAPI client

View File

@ -60,7 +60,7 @@ func newClhConfig() (HypervisorConfig, error) {
DefaultBridges: defaultBridges,
DefaultMaxVCPUs: uint32(64),
SharedFS: config.VirtioFS,
VirtioFSCache: virtioFsCacheAlways,
VirtioFSCache: typeVirtioFSCacheModeAlways,
VirtioFSDaemon: testVirtiofsdPath,
NetRateLimiterBwMaxRate: int64(0),
NetRateLimiterBwOneTimeBurst: int64(0),

View File

@ -88,7 +88,6 @@ var (
type9pFs = "9p"
typeVirtioFS = "virtiofs"
typeOverlayFS = "overlay"
typeVirtioFSNoCache = "never"
kata9pDevType = "9p"
kataMmioBlkDevType = "mmioblk"
kataBlkDevType = "blk"
@ -805,7 +804,7 @@ func setupStorages(ctx context.Context, sandbox *Sandbox) []*grpc.Storage {
// directly map contents from the host. When set to 'never', the mount
// options should not contain 'dax' lest the virtio-fs daemon crashing
// with an invalid address reference.
if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSNoCache {
if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeNever {
// If virtio_fs_cache_size = 0, dax should not be used.
if sandbox.config.HypervisorConfig.VirtioFSCacheSize != 0 {
sharedDirVirtioFSOptions = append(sharedDirVirtioFSOptions, sharedDirVirtioFSDaxOptions)

View File

@ -37,6 +37,13 @@ var (
errUnimplemented = errors.New("unimplemented")
)
const (
typeVirtioFSCacheModeNever = "never"
typeVirtioFSCacheModeNone = "none"
typeVirtioFSCacheModeAlways = "always"
typeVirtioFSCacheModeAuto = "auto"
)
type VirtiofsDaemon interface {
// Start virtiofs daemon, return pid of virtiofs daemon process
Start(context.Context, onQuitFunc) (pid int, err error)
@ -216,11 +223,11 @@ func (v *virtiofsd) valid() error {
}
if v.cache == "" {
v.cache = "auto"
} else if v.cache == "none" {
v.cache = typeVirtioFSCacheModeAuto
} else if v.cache == typeVirtioFSCacheModeNone {
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" {
v.cache = typeVirtioFSCacheModeNever
} else if v.cache != typeVirtioFSCacheModeAuto && v.cache != typeVirtioFSCacheModeAlways && v.cache != typeVirtioFSCacheModeNever {
return errVirtiofsdInvalidVirtiofsCacheMode(v.cache)
}