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 defaultPCIeRootPort = 0
const defaultEntropySource = "/dev/urandom" const defaultEntropySource = "/dev/urandom"
const defaultGuestHookPath string = "" const defaultGuestHookPath string = ""
const defaultVirtioFSCacheMode = "none" const defaultVirtioFSCacheMode = "never"
const defaultDisableImageNvdimm = false const defaultDisableImageNvdimm = false
const defaultVhostUserStorePath string = "/var/run/kata-containers/vhost-user/" const defaultVhostUserStorePath string = "/var/run/kata-containers/vhost-user/"
const defaultRxRateLimiterMaxRate = uint64(0) const defaultRxRateLimiterMaxRate = uint64(0)

View File

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

View File

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

View File

@ -88,7 +88,6 @@ var (
type9pFs = "9p" type9pFs = "9p"
typeVirtioFS = "virtiofs" typeVirtioFS = "virtiofs"
typeOverlayFS = "overlay" typeOverlayFS = "overlay"
typeVirtioFSNoCache = "never"
kata9pDevType = "9p" kata9pDevType = "9p"
kataMmioBlkDevType = "mmioblk" kataMmioBlkDevType = "mmioblk"
kataBlkDevType = "blk" 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 // 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 != typeVirtioFSCacheModeNever {
// If virtio_fs_cache_size = 0, dax should not be used. // If virtio_fs_cache_size = 0, dax should not be used.
if sandbox.config.HypervisorConfig.VirtioFSCacheSize != 0 { if sandbox.config.HypervisorConfig.VirtioFSCacheSize != 0 {
sharedDirVirtioFSOptions = append(sharedDirVirtioFSOptions, sharedDirVirtioFSDaxOptions) sharedDirVirtioFSOptions = append(sharedDirVirtioFSOptions, sharedDirVirtioFSDaxOptions)

View File

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