From 396d0beb1d3b496f850f108b967c09a2abe4fc41 Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Wed, 4 Oct 2023 21:40:52 +0800 Subject: [PATCH] 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 --- pkg/sentry/fsimpl/gofer/save_restore.go | 11 +---------- pkg/sentry/vfs/context.go | 5 +++++ runsc/boot/vfs.go | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/sentry/fsimpl/gofer/save_restore.go b/pkg/sentry/fsimpl/gofer/save_restore.go index 1ae976d4a..132a5f1a3 100644 --- a/pkg/sentry/fsimpl/gofer/save_restore.go +++ b/pkg/sentry/fsimpl/gofer/save_restore.go @@ -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") } diff --git a/pkg/sentry/vfs/context.go b/pkg/sentry/vfs/context.go index 70a78872c..ff1281023 100644 --- a/pkg/sentry/vfs/context.go +++ b/pkg/sentry/vfs/context.go @@ -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 diff --git a/runsc/boot/vfs.go b/runsc/boot/vfs.go index b1e5f5215..39bc3b435 100644 --- a/runsc/boot/vfs.go +++ b/runsc/boot/vfs.go @@ -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 {