vfs: introduce CtxRestoreFilesystemFDMap

This patch introduces CtxRestoreFilesystemFDMap in vfs to replace
the CtxRestoreServerFDMap defined in gofer, which is a preparation
for adding the checkpoint/restore support in EROFS. It allows the
configureRestore() in boot/vfs.go to be agnostic to the filesystems
that will be used in the sentry when configuring restore.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
This commit is contained in:
Tiwei Bie
2023-10-23 22:02:41 +08:00
parent 57606c7aa1
commit 396d0beb1d
3 changed files with 7 additions and 11 deletions
+1 -10
View File
@@ -29,15 +29,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/vfs"
)
type saveRestoreContextID int
const (
// CtxRestoreServerFDMap is a Context.Value key for a map[string]int
// mapping filesystem unique IDs (cf. InternalFilesystemOptions.UniqueID)
// to host FDs.
CtxRestoreServerFDMap saveRestoreContextID = iota
)
// +stateify savable
type savedDentryRW struct {
read bool
@@ -181,7 +172,7 @@ func (d *dentry) loadParent(parent *dentry) {
// CompleteRestore implements
// vfs.FilesystemImplSaveRestoreExtension.CompleteRestore.
func (fs *filesystem) CompleteRestore(ctx context.Context, opts vfs.CompleteRestoreOptions) error {
fdmapv := ctx.Value(CtxRestoreServerFDMap)
fdmapv := ctx.Value(vfs.CtxRestoreFilesystemFDMap)
if fdmapv == nil {
return fmt.Errorf("no server FD map available")
}
+5
View File
@@ -27,6 +27,11 @@ const (
// CtxRoot is a Context.Value key for a VFS root.
CtxRoot
// CtxRestoreFilesystemFDMap is a Context.Value key for a map[string]int
// mapping filesystem unique IDs (cf. gofer.InternalFilesystemOptions.UniqueID)
// to host FDs.
CtxRestoreFilesystemFDMap
)
// MountNamespaceFromContext returns the MountNamespace used by ctx. If ctx is
+1 -1
View File
@@ -1087,7 +1087,7 @@ func (c *containerMounter) configureRestore(ctx context.Context) (context.Contex
fdmap[submount.mount.Destination] = submount.goferFD.Release()
}
}
return context.WithValue(ctx, gofer.CtxRestoreServerFDMap, fdmap), nil
return context.WithValue(ctx, vfs.CtxRestoreFilesystemFDMap, fdmap), nil
}
func createDeviceFiles(ctx context.Context, creds *auth.Credentials, info *containerInfo, vfsObj *vfs.VirtualFilesystem, root vfs.VirtualDentry) error {