diff --git a/src/runtime/config/configuration-clh.toml.in b/src/runtime/config/configuration-clh.toml.in index 883c7a9ef6..326b931759 100644 --- a/src/runtime/config/configuration-clh.toml.in +++ b/src/runtime/config/configuration-clh.toml.in @@ -163,6 +163,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-coco-dev.toml.in b/src/runtime/config/configuration-qemu-coco-dev.toml.in index 71fad0f928..79de271708 100644 --- a/src/runtime/config/configuration-qemu-coco-dev.toml.in +++ b/src/runtime/config/configuration-qemu-coco-dev.toml.in @@ -212,6 +212,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-nvidia-gpu-snp.toml.in b/src/runtime/config/configuration-qemu-nvidia-gpu-snp.toml.in index be48fc0942..f56a287d9e 100644 --- a/src/runtime/config/configuration-qemu-nvidia-gpu-snp.toml.in +++ b/src/runtime/config/configuration-qemu-nvidia-gpu-snp.toml.in @@ -221,6 +221,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-nvidia-gpu-tdx.toml.in b/src/runtime/config/configuration-qemu-nvidia-gpu-tdx.toml.in index a4cfd26fdc..123b2a2be7 100644 --- a/src/runtime/config/configuration-qemu-nvidia-gpu-tdx.toml.in +++ b/src/runtime/config/configuration-qemu-nvidia-gpu-tdx.toml.in @@ -205,6 +205,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-nvidia-gpu.toml.in b/src/runtime/config/configuration-qemu-nvidia-gpu.toml.in index 330c0fca28..8f92987f96 100644 --- a/src/runtime/config/configuration-qemu-nvidia-gpu.toml.in +++ b/src/runtime/config/configuration-qemu-nvidia-gpu.toml.in @@ -210,6 +210,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-se.toml.in b/src/runtime/config/configuration-qemu-se.toml.in index 87800a20bb..9f3c258dc8 100644 --- a/src/runtime/config/configuration-qemu-se.toml.in +++ b/src/runtime/config/configuration-qemu-se.toml.in @@ -196,6 +196,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-snp.toml.in b/src/runtime/config/configuration-qemu-snp.toml.in index 1390870fdb..0c2a55021a 100644 --- a/src/runtime/config/configuration-qemu-snp.toml.in +++ b/src/runtime/config/configuration-qemu-snp.toml.in @@ -221,6 +221,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu-tdx.toml.in b/src/runtime/config/configuration-qemu-tdx.toml.in index e92f1ff0a9..1c810e8cd6 100644 --- a/src/runtime/config/configuration-qemu-tdx.toml.in +++ b/src/runtime/config/configuration-qemu-tdx.toml.in @@ -206,6 +206,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-qemu.toml.in b/src/runtime/config/configuration-qemu.toml.in index 623fa74848..4afb3291ed 100644 --- a/src/runtime/config/configuration-qemu.toml.in +++ b/src/runtime/config/configuration-qemu.toml.in @@ -211,6 +211,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/config/configuration-stratovirt.toml.in b/src/runtime/config/configuration-stratovirt.toml.in index 47a8a245b5..b3de5c71ff 100644 --- a/src/runtime/config/configuration-stratovirt.toml.in +++ b/src/runtime/config/configuration-stratovirt.toml.in @@ -144,6 +144,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@ # Metadata, data, and pathname lookup are not cached in guest. They are # always fetched from host and any changes are immediately pushed to host. # +# - metadata +# Metadata and pathname lookup are cached in guest and never expire. +# Data is never cached in guest. +# # - auto # Metadata and pathname lookup cache expires after a configured amount of # time (default is 1 second). Data is cached while the file is open (close diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 7c22373e4d..fef95c4737 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -877,10 +877,10 @@ func setupStorages(ctx context.Context, sandbox *Sandbox) []*grpc.Storage { if sharedFS == config.VirtioFS || sharedFS == config.VirtioFSNydus { // If virtio-fs uses either of the two cache options 'auto, always', // the guest directory can be mounted with option 'dax' allowing it to - // directly map contents from the host. When set to 'never', the mount + // directly map contents from the host. Otherwise, the mount // options should not contain 'dax' lest the virtio-fs daemon crashing // with an invalid address reference. - if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeNever { + if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeNever && sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeMetadata { // If virtio_fs_cache_size = 0, dax should not be used. if sandbox.config.HypervisorConfig.VirtioFSCacheSize != 0 { sharedDirVirtioFSOptions = append(sharedDirVirtioFSOptions, sharedDirVirtioFSDaxOptions) diff --git a/src/runtime/virtcontainers/virtiofsd.go b/src/runtime/virtcontainers/virtiofsd.go index 0a62646847..3abc20a495 100644 --- a/src/runtime/virtcontainers/virtiofsd.go +++ b/src/runtime/virtcontainers/virtiofsd.go @@ -38,9 +38,10 @@ var ( ) const ( - typeVirtioFSCacheModeNever = "never" - typeVirtioFSCacheModeAlways = "always" - typeVirtioFSCacheModeAuto = "auto" + typeVirtioFSCacheModeNever = "never" + typeVirtioFSCacheModeMetadata = "metadata" + typeVirtioFSCacheModeAlways = "always" + typeVirtioFSCacheModeAuto = "auto" ) type VirtiofsDaemon interface { @@ -216,9 +217,16 @@ func (v *virtiofsd) valid() error { return errVirtiofsdSourceNotAvailable } - if v.cache == "" { + switch v.cache { + case "": v.cache = typeVirtioFSCacheModeAuto - } else if v.cache != typeVirtioFSCacheModeAuto && v.cache != typeVirtioFSCacheModeAlways && v.cache != typeVirtioFSCacheModeNever { + case + typeVirtioFSCacheModeAuto, + typeVirtioFSCacheModeAlways, + typeVirtioFSCacheModeMetadata, + typeVirtioFSCacheModeNever: + // No-op, accepted + default: return errVirtiofsdInvalidVirtiofsCacheMode(v.cache) } diff --git a/src/runtime/virtcontainers/virtiofsd_test.go b/src/runtime/virtcontainers/virtiofsd_test.go index d44a523e6e..9546d79240 100644 --- a/src/runtime/virtcontainers/virtiofsd_test.go +++ b/src/runtime/virtcontainers/virtiofsd_test.go @@ -133,6 +133,9 @@ func TestValid(t *testing.T) { {"invalid cache mode", func(v *virtiofsd) { v.cache = "foo" }, errVirtiofsdInvalidVirtiofsCacheMode("foo"), nil}, + {"valid metadata cache mode", func(v *virtiofsd) { + v.cache = typeVirtioFSCacheModeMetadata + }, nil, nil}, } for _, tt := range tests {