Merge pull request #11060 from kata-containers/sprt/vfsd-metadata

runtime: virtio-fs: Support "metadata" cache mode
This commit is contained in:
Xuewei Niu
2025-08-08 11:13:57 +08:00
committed by GitHub
13 changed files with 58 additions and 7 deletions

View File

@@ -163,6 +163,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -212,6 +212,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -221,6 +221,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -205,6 +205,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -210,6 +210,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -196,6 +196,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -221,6 +221,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -206,6 +206,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -211,6 +211,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -144,6 +144,10 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# 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.
# #
# - metadata
# Metadata and pathname lookup are cached in guest and never expire.
# Data is never cached in guest.
#
# - auto # - auto
# Metadata and pathname lookup cache expires after a configured amount of # 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 # time (default is 1 second). Data is cached while the file is open (close

View File

@@ -877,10 +877,10 @@ 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 'never', the mount // directly map contents from the host. Otherwise, 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 != typeVirtioFSCacheModeNever { if sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeNever && sandbox.config.HypervisorConfig.VirtioFSCache != typeVirtioFSCacheModeMetadata {
// 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

@@ -39,6 +39,7 @@ var (
const ( const (
typeVirtioFSCacheModeNever = "never" typeVirtioFSCacheModeNever = "never"
typeVirtioFSCacheModeMetadata = "metadata"
typeVirtioFSCacheModeAlways = "always" typeVirtioFSCacheModeAlways = "always"
typeVirtioFSCacheModeAuto = "auto" typeVirtioFSCacheModeAuto = "auto"
) )
@@ -216,9 +217,16 @@ func (v *virtiofsd) valid() error {
return errVirtiofsdSourceNotAvailable return errVirtiofsdSourceNotAvailable
} }
if v.cache == "" { switch v.cache {
case "":
v.cache = typeVirtioFSCacheModeAuto 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) return errVirtiofsdInvalidVirtiofsCacheMode(v.cache)
} }

View File

@@ -133,6 +133,9 @@ func TestValid(t *testing.T) {
{"invalid cache mode", func(v *virtiofsd) { {"invalid cache mode", func(v *virtiofsd) {
v.cache = "foo" v.cache = "foo"
}, errVirtiofsdInvalidVirtiofsCacheMode("foo"), nil}, }, errVirtiofsdInvalidVirtiofsCacheMode("foo"), nil},
{"valid metadata cache mode", func(v *virtiofsd) {
v.cache = typeVirtioFSCacheModeMetadata
}, nil, nil},
} }
for _, tt := range tests { for _, tt := range tests {